@preprio/toolkit 0.6.0-alpha.9 → 1.0.0-rc.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 +111 -1363
- package/dist/astro/index.cjs +1555 -182
- package/dist/astro/index.d.cts +201 -1
- package/dist/astro/index.d.ts +201 -1
- package/dist/astro/index.js +1557 -29
- package/dist/{chunk-5QIWVDP2.js → chunk-33GWVTRJ.js} +1 -1
- package/dist/chunk-A2J7R4LR.js +256 -0
- package/dist/{chunk-WQBKQG4R.js → chunk-DSJ22P6J.js} +6 -1
- package/dist/chunk-KM2GME62.js +1255 -0
- package/dist/chunk-UTKH7DOI.js +58 -0
- package/dist/chunk-V7MCHPE7.js +85 -0
- package/dist/{chunk-J66UOCK6.js → chunk-WBMN4L7G.js} +1680 -579
- package/dist/chunk-Y7JWV7WV.js +374 -0
- package/dist/codegen/index.cjs +82 -0
- package/dist/codegen/index.d.cts +70 -0
- package/dist/codegen/index.d.ts +70 -0
- package/dist/codegen/index.js +64 -0
- package/dist/index.cjs +3729 -553
- package/dist/index.d.cts +403 -19
- package/dist/index.d.ts +403 -19
- package/dist/index.js +345 -24
- package/dist/live-preview-HCBNBC6C.js +19 -0
- package/dist/nextjs/components.cjs +1872 -754
- package/dist/nextjs/components.d.cts +5 -51
- package/dist/nextjs/components.d.ts +5 -51
- package/dist/nextjs/components.js +8 -299
- package/dist/nextjs/index.cjs +1228 -181
- package/dist/nextjs/index.d.cts +247 -92
- package/dist/nextjs/index.d.ts +247 -92
- package/dist/nextjs/index.js +1629 -111
- package/dist/nextjs/live-action.cjs +298 -0
- package/dist/nextjs/live-action.d.cts +12 -0
- package/dist/nextjs/live-action.d.ts +12 -0
- package/dist/nextjs/live-action.js +68 -0
- package/dist/nextjs/live.cjs +2010 -0
- package/dist/nextjs/live.d.cts +54 -0
- package/dist/nextjs/live.d.ts +54 -0
- package/dist/nextjs/live.js +287 -0
- package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
- package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
- package/dist/nuxt/index.cjs +15 -16
- package/dist/nuxt/index.d.cts +167 -6
- package/dist/nuxt/index.d.ts +167 -6
- package/dist/nuxt/index.js +402 -15
- package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
- package/dist/nuxt/live.cjs +1928 -0
- package/dist/nuxt/live.d.cts +45 -0
- package/dist/nuxt/live.d.ts +45 -0
- package/dist/nuxt/live.js +216 -0
- package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
- package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
- package/dist/react/components.cjs +1865 -480
- package/dist/react/components.d.cts +43 -8
- package/dist/react/components.d.ts +43 -8
- package/dist/react/components.js +1865 -480
- package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
- package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
- package/dist/sveltekit/index.cjs +15 -16
- package/dist/sveltekit/index.d.cts +111 -10
- package/dist/sveltekit/index.d.ts +111 -10
- package/dist/sveltekit/index.js +398 -15
- package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
- package/dist/sveltekit/live.cjs +1940 -0
- package/dist/sveltekit/live.d.cts +61 -0
- package/dist/sveltekit/live.d.ts +61 -0
- package/dist/sveltekit/live.js +220 -0
- package/package.json +132 -71
- package/src/astro/PreprToolbar.astro +7 -1
- package/src/astro/PreprTrackingPixel.astro +2 -4
- package/src/nuxt/PreprToolbar.vue +12 -1
- package/src/nuxt/PreprTrackingPixel.vue +2 -4
- package/src/sveltekit/PreprToolbar.svelte +17 -2
- package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
- package/dist/astro/chunk-UN4JADNU.js +0 -173
- package/dist/astro/graphql.cjs +0 -1078
- package/dist/astro/graphql.d.cts +0 -300
- package/dist/astro/graphql.d.ts +0 -300
- package/dist/astro/graphql.js +0 -984
- package/dist/astro/index-XT_z-RYT.d.cts +0 -130
- package/dist/astro/index-XT_z-RYT.d.ts +0 -130
- package/dist/chunk-3NCEVJJ3.js +0 -10
- package/dist/chunk-S5RWVMDJ.js +0 -148
- package/dist/chunk-XL4Y7FGW.js +0 -499
- package/dist/graphql/codegen.cjs +0 -557
- package/dist/graphql/codegen.d.cts +0 -23
- package/dist/graphql/codegen.d.ts +0 -23
- package/dist/graphql/codegen.js +0 -99
- package/dist/graphql.cjs +0 -1020
- package/dist/graphql.d.cts +0 -335
- package/dist/graphql.d.ts +0 -335
- package/dist/graphql.js +0 -448
- package/dist/nextjs/chunk-CMV6ZP6E.js +0 -549
- package/dist/nextjs/graphql.cjs +0 -1836
- package/dist/nextjs/graphql.d.cts +0 -498
- package/dist/nextjs/graphql.d.ts +0 -498
- package/dist/nextjs/graphql.js +0 -1422
- package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
- package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
- package/dist/nuxt/chunk-XWOABVMW.js +0 -417
- package/dist/nuxt/graphql.cjs +0 -1085
- package/dist/nuxt/graphql.d.cts +0 -297
- package/dist/nuxt/graphql.d.ts +0 -297
- package/dist/nuxt/graphql.js +0 -985
- package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
- package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
- package/dist/pixel-DwW7cXJm.d.cts +0 -49
- package/dist/pixel-DwW7cXJm.d.ts +0 -49
- package/dist/server-Brr1UgtW.d.ts +0 -59
- package/dist/server-DJuS3YU0.d.cts +0 -59
- package/dist/sveltekit/chunk-3S5RA6G5.js +0 -413
- package/dist/sveltekit/graphql.cjs +0 -1091
- package/dist/sveltekit/graphql.d.cts +0 -302
- package/dist/sveltekit/graphql.d.ts +0 -302
- package/dist/sveltekit/graphql.js +0 -991
- package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
- package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
package/dist/astro/index.d.cts
CHANGED
|
@@ -1 +1,201 @@
|
|
|
1
|
-
|
|
1
|
+
/** A segment from Prepr, as listed in the toolbar's segment picker. */
|
|
2
|
+
interface PreprSegment {
|
|
3
|
+
readonly _id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
8
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
9
|
+
*/
|
|
10
|
+
type PreprFeatureConfig = boolean | {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
14
|
+
interface PreprFeatures {
|
|
15
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
16
|
+
segments?: PreprFeatureConfig;
|
|
17
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
18
|
+
abTesting?: PreprFeatureConfig;
|
|
19
|
+
/**
|
|
20
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
21
|
+
* tooltip/overlay and the close-edit pill.
|
|
22
|
+
*
|
|
23
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
24
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
25
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
26
|
+
* to visitors. See iframe-bridge.ts.
|
|
27
|
+
*/
|
|
28
|
+
editMode?: PreprFeatureConfig;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The data the toolbar shows. `getToolbarProps` builds it on the server from
|
|
32
|
+
* the request headers.
|
|
33
|
+
*/
|
|
34
|
+
interface PreprToolbarProps {
|
|
35
|
+
/**
|
|
36
|
+
* Server-resolved active segment. Optional: omit it with `segments`
|
|
37
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
38
|
+
* the persisted cookie is used.
|
|
39
|
+
*/
|
|
40
|
+
readonly activeSegment?: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
43
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
44
|
+
* the persisted cookie is used.
|
|
45
|
+
*/
|
|
46
|
+
readonly activeVariant?: string | null;
|
|
47
|
+
/** Available segments to personalize on. */
|
|
48
|
+
readonly segments?: readonly PreprSegment[];
|
|
49
|
+
/** @deprecated Alias for `segments`. */
|
|
50
|
+
readonly data?: readonly PreprSegment[];
|
|
51
|
+
}
|
|
52
|
+
/** The two sides of an A/B test. */
|
|
53
|
+
type PreprVariant = 'A' | 'B';
|
|
54
|
+
/**
|
|
55
|
+
* The headers to send with a Prepr GraphQL request so the API personalizes
|
|
56
|
+
* the response for this visitor. `getPreprHeaders` returns them; spread them
|
|
57
|
+
* into the request's `headers`.
|
|
58
|
+
*/
|
|
59
|
+
interface PreprHeaders {
|
|
60
|
+
readonly 'prepr-customer-id'?: string;
|
|
61
|
+
readonly 'Prepr-Segments'?: string;
|
|
62
|
+
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
63
|
+
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
64
|
+
readonly 'Prepr-Context-utm_source'?: string;
|
|
65
|
+
readonly 'Prepr-Context-utm_medium'?: string;
|
|
66
|
+
readonly 'Prepr-Context-utm_term'?: string;
|
|
67
|
+
readonly 'Prepr-Context-utm_content'?: string;
|
|
68
|
+
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
69
|
+
readonly 'Prepr-Context-initial_referral'?: string;
|
|
70
|
+
readonly 'Prepr-Visitor-IP'?: string;
|
|
71
|
+
readonly 'Prepr-Hubspot-Id'?: string;
|
|
72
|
+
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
73
|
+
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
74
|
+
readonly 'User-Agent'?: string;
|
|
75
|
+
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
76
|
+
readonly 'Prepr-User-Agent'?: string;
|
|
77
|
+
readonly 'Prepr-Package'?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Why a `PreprError` was thrown; read it from `error.code`. */
|
|
80
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
81
|
+
|
|
82
|
+
/** Options for the Prepr middleware of every framework. */
|
|
83
|
+
interface PreprMiddlewareOptions {
|
|
84
|
+
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
85
|
+
preview?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Disable features app-wide. Pass the same object you give the toolbar: a
|
|
88
|
+
* disabled feature injects no header and persists no cookie, whatever the
|
|
89
|
+
* request carries.
|
|
90
|
+
*/
|
|
91
|
+
features?: PreprFeatures;
|
|
92
|
+
/** Override the version reported in Prepr-Package (mainly for tests). */
|
|
93
|
+
version?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
|
|
98
|
+
* `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
|
|
99
|
+
* string-like object such as codegen's `TypedDocumentString`.
|
|
100
|
+
*/
|
|
101
|
+
type QueryInput = string | {
|
|
102
|
+
kind: 'Document';
|
|
103
|
+
} | {
|
|
104
|
+
toString(): string;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** Returns the Prepr Customer ID from the request headers. */
|
|
108
|
+
declare function getPreprUUID(headers: Headers): string | null;
|
|
109
|
+
/** Returns the active segment from the request headers. */
|
|
110
|
+
declare function getActiveSegment(headers: Headers): string | null;
|
|
111
|
+
/** Returns the active A/B testing variant from the request headers. */
|
|
112
|
+
declare function getActiveVariant(headers: Headers): string | null;
|
|
113
|
+
/** Returns all Prepr headers from the request headers. */
|
|
114
|
+
declare function getPreprHeaders(headers: Headers): PreprHeaders;
|
|
115
|
+
/**
|
|
116
|
+
* Props needed to mount the `PreprToolbar` component, from the request
|
|
117
|
+
* headers plus a Prepr GraphQL token.
|
|
118
|
+
*
|
|
119
|
+
* Ungated: call it only when your app is in preview mode. Resolve that however
|
|
120
|
+
* your deployment already does — the toolkit reads no environment variables of
|
|
121
|
+
* its own.
|
|
122
|
+
*/
|
|
123
|
+
declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
124
|
+
|
|
125
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
126
|
+
declare class PreprError extends Error {
|
|
127
|
+
readonly code: PreprErrorCode;
|
|
128
|
+
readonly context?: string | undefined;
|
|
129
|
+
readonly originalError?: Error | undefined;
|
|
130
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
134
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
135
|
+
*/
|
|
136
|
+
declare function validatePreprToken(token: string): void;
|
|
137
|
+
/**
|
|
138
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
139
|
+
* -> `abc123`.
|
|
140
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
141
|
+
*/
|
|
142
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Structural stand-in for Astro's `APIContext`, so this package needs no
|
|
146
|
+
* build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
|
|
147
|
+
*/
|
|
148
|
+
interface AstroLikeContext {
|
|
149
|
+
request: Request;
|
|
150
|
+
/** Unused; typed loosely so passing the real Astro context still checks. */
|
|
151
|
+
cookies?: unknown;
|
|
152
|
+
/** Per-request storage; carries the editor's unsaved changes in preview. */
|
|
153
|
+
locals?: object;
|
|
154
|
+
}
|
|
155
|
+
/** Astro middleware's `next()` — resolves to the `Response` from downstream. */
|
|
156
|
+
type AstroNext = () => Promise<Response>;
|
|
157
|
+
/**
|
|
158
|
+
* Astro middleware entry point: computes the Prepr headers/cookies for this
|
|
159
|
+
* request, forwards the headers downstream and sets the cookies on the response.
|
|
160
|
+
*
|
|
161
|
+
* Astro hands downstream code the same `Request` instance this middleware receives, so the
|
|
162
|
+
* headers are mutated in place — building a new `Request` would go nowhere,
|
|
163
|
+
* there's no way to hand a replacement back out of middleware.
|
|
164
|
+
*/
|
|
165
|
+
declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
|
|
166
|
+
|
|
167
|
+
interface AstroNormalizeQueryOptions {
|
|
168
|
+
/**
|
|
169
|
+
* Whether this render may show unsaved editor changes. Pass your preview
|
|
170
|
+
* flag, and never `true` on a production deployment. When false (the
|
|
171
|
+
* default) the result is returned untouched.
|
|
172
|
+
*/
|
|
173
|
+
enabled?: boolean;
|
|
174
|
+
/** `Astro.locals`, where `onPreprRequest` leaves the editor's changes. */
|
|
175
|
+
locals?: object;
|
|
176
|
+
/** Which operation to use when the document holds more than one. */
|
|
177
|
+
operationName?: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Show the Prepr editor's unsaved changes on a server-rendered Astro page:
|
|
181
|
+
* pass the query and the result you fetched (with any client), and render
|
|
182
|
+
* what comes back.
|
|
183
|
+
*
|
|
184
|
+
* ```astro
|
|
185
|
+
* ---
|
|
186
|
+
* const data = await fetchFromPrepr(GetPageDocument, { slug });
|
|
187
|
+
* const page = normalizeQuery(GetPageDocument, data, {
|
|
188
|
+
* enabled: preview,
|
|
189
|
+
* locals: Astro.locals,
|
|
190
|
+
* });
|
|
191
|
+
* ---
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* Needs `onPreprRequest` with `preview: true` in your middleware and
|
|
195
|
+
* `PreprToolbar.astro` on the page; the toolbar re-requests the page with
|
|
196
|
+
* the editor's changes while they type. Select `_id` on every item and
|
|
197
|
+
* component that should update.
|
|
198
|
+
*/
|
|
199
|
+
declare function normalizeQuery<T>(query: QueryInput, result: T, options?: AstroNormalizeQueryOptions): T;
|
|
200
|
+
|
|
201
|
+
export { type AstroLikeContext, type AstroNext, type AstroNormalizeQueryOptions, PreprError, type PreprMiddlewareOptions, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, onPreprRequest, validatePreprToken };
|
package/dist/astro/index.d.ts
CHANGED
|
@@ -1 +1,201 @@
|
|
|
1
|
-
|
|
1
|
+
/** A segment from Prepr, as listed in the toolbar's segment picker. */
|
|
2
|
+
interface PreprSegment {
|
|
3
|
+
readonly _id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
8
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
9
|
+
*/
|
|
10
|
+
type PreprFeatureConfig = boolean | {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
14
|
+
interface PreprFeatures {
|
|
15
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
16
|
+
segments?: PreprFeatureConfig;
|
|
17
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
18
|
+
abTesting?: PreprFeatureConfig;
|
|
19
|
+
/**
|
|
20
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
21
|
+
* tooltip/overlay and the close-edit pill.
|
|
22
|
+
*
|
|
23
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
24
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
25
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
26
|
+
* to visitors. See iframe-bridge.ts.
|
|
27
|
+
*/
|
|
28
|
+
editMode?: PreprFeatureConfig;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The data the toolbar shows. `getToolbarProps` builds it on the server from
|
|
32
|
+
* the request headers.
|
|
33
|
+
*/
|
|
34
|
+
interface PreprToolbarProps {
|
|
35
|
+
/**
|
|
36
|
+
* Server-resolved active segment. Optional: omit it with `segments`
|
|
37
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
38
|
+
* the persisted cookie is used.
|
|
39
|
+
*/
|
|
40
|
+
readonly activeSegment?: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
43
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
44
|
+
* the persisted cookie is used.
|
|
45
|
+
*/
|
|
46
|
+
readonly activeVariant?: string | null;
|
|
47
|
+
/** Available segments to personalize on. */
|
|
48
|
+
readonly segments?: readonly PreprSegment[];
|
|
49
|
+
/** @deprecated Alias for `segments`. */
|
|
50
|
+
readonly data?: readonly PreprSegment[];
|
|
51
|
+
}
|
|
52
|
+
/** The two sides of an A/B test. */
|
|
53
|
+
type PreprVariant = 'A' | 'B';
|
|
54
|
+
/**
|
|
55
|
+
* The headers to send with a Prepr GraphQL request so the API personalizes
|
|
56
|
+
* the response for this visitor. `getPreprHeaders` returns them; spread them
|
|
57
|
+
* into the request's `headers`.
|
|
58
|
+
*/
|
|
59
|
+
interface PreprHeaders {
|
|
60
|
+
readonly 'prepr-customer-id'?: string;
|
|
61
|
+
readonly 'Prepr-Segments'?: string;
|
|
62
|
+
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
63
|
+
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
64
|
+
readonly 'Prepr-Context-utm_source'?: string;
|
|
65
|
+
readonly 'Prepr-Context-utm_medium'?: string;
|
|
66
|
+
readonly 'Prepr-Context-utm_term'?: string;
|
|
67
|
+
readonly 'Prepr-Context-utm_content'?: string;
|
|
68
|
+
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
69
|
+
readonly 'Prepr-Context-initial_referral'?: string;
|
|
70
|
+
readonly 'Prepr-Visitor-IP'?: string;
|
|
71
|
+
readonly 'Prepr-Hubspot-Id'?: string;
|
|
72
|
+
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
73
|
+
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
74
|
+
readonly 'User-Agent'?: string;
|
|
75
|
+
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
76
|
+
readonly 'Prepr-User-Agent'?: string;
|
|
77
|
+
readonly 'Prepr-Package'?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Why a `PreprError` was thrown; read it from `error.code`. */
|
|
80
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
81
|
+
|
|
82
|
+
/** Options for the Prepr middleware of every framework. */
|
|
83
|
+
interface PreprMiddlewareOptions {
|
|
84
|
+
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
85
|
+
preview?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Disable features app-wide. Pass the same object you give the toolbar: a
|
|
88
|
+
* disabled feature injects no header and persists no cookie, whatever the
|
|
89
|
+
* request carries.
|
|
90
|
+
*/
|
|
91
|
+
features?: PreprFeatures;
|
|
92
|
+
/** Override the version reported in Prepr-Package (mainly for tests). */
|
|
93
|
+
version?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
|
|
98
|
+
* `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
|
|
99
|
+
* string-like object such as codegen's `TypedDocumentString`.
|
|
100
|
+
*/
|
|
101
|
+
type QueryInput = string | {
|
|
102
|
+
kind: 'Document';
|
|
103
|
+
} | {
|
|
104
|
+
toString(): string;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** Returns the Prepr Customer ID from the request headers. */
|
|
108
|
+
declare function getPreprUUID(headers: Headers): string | null;
|
|
109
|
+
/** Returns the active segment from the request headers. */
|
|
110
|
+
declare function getActiveSegment(headers: Headers): string | null;
|
|
111
|
+
/** Returns the active A/B testing variant from the request headers. */
|
|
112
|
+
declare function getActiveVariant(headers: Headers): string | null;
|
|
113
|
+
/** Returns all Prepr headers from the request headers. */
|
|
114
|
+
declare function getPreprHeaders(headers: Headers): PreprHeaders;
|
|
115
|
+
/**
|
|
116
|
+
* Props needed to mount the `PreprToolbar` component, from the request
|
|
117
|
+
* headers plus a Prepr GraphQL token.
|
|
118
|
+
*
|
|
119
|
+
* Ungated: call it only when your app is in preview mode. Resolve that however
|
|
120
|
+
* your deployment already does — the toolkit reads no environment variables of
|
|
121
|
+
* its own.
|
|
122
|
+
*/
|
|
123
|
+
declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
124
|
+
|
|
125
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
126
|
+
declare class PreprError extends Error {
|
|
127
|
+
readonly code: PreprErrorCode;
|
|
128
|
+
readonly context?: string | undefined;
|
|
129
|
+
readonly originalError?: Error | undefined;
|
|
130
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
134
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
135
|
+
*/
|
|
136
|
+
declare function validatePreprToken(token: string): void;
|
|
137
|
+
/**
|
|
138
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
139
|
+
* -> `abc123`.
|
|
140
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
141
|
+
*/
|
|
142
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Structural stand-in for Astro's `APIContext`, so this package needs no
|
|
146
|
+
* build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
|
|
147
|
+
*/
|
|
148
|
+
interface AstroLikeContext {
|
|
149
|
+
request: Request;
|
|
150
|
+
/** Unused; typed loosely so passing the real Astro context still checks. */
|
|
151
|
+
cookies?: unknown;
|
|
152
|
+
/** Per-request storage; carries the editor's unsaved changes in preview. */
|
|
153
|
+
locals?: object;
|
|
154
|
+
}
|
|
155
|
+
/** Astro middleware's `next()` — resolves to the `Response` from downstream. */
|
|
156
|
+
type AstroNext = () => Promise<Response>;
|
|
157
|
+
/**
|
|
158
|
+
* Astro middleware entry point: computes the Prepr headers/cookies for this
|
|
159
|
+
* request, forwards the headers downstream and sets the cookies on the response.
|
|
160
|
+
*
|
|
161
|
+
* Astro hands downstream code the same `Request` instance this middleware receives, so the
|
|
162
|
+
* headers are mutated in place — building a new `Request` would go nowhere,
|
|
163
|
+
* there's no way to hand a replacement back out of middleware.
|
|
164
|
+
*/
|
|
165
|
+
declare function onPreprRequest(context: AstroLikeContext, next: AstroNext, options?: PreprMiddlewareOptions): Promise<Response>;
|
|
166
|
+
|
|
167
|
+
interface AstroNormalizeQueryOptions {
|
|
168
|
+
/**
|
|
169
|
+
* Whether this render may show unsaved editor changes. Pass your preview
|
|
170
|
+
* flag, and never `true` on a production deployment. When false (the
|
|
171
|
+
* default) the result is returned untouched.
|
|
172
|
+
*/
|
|
173
|
+
enabled?: boolean;
|
|
174
|
+
/** `Astro.locals`, where `onPreprRequest` leaves the editor's changes. */
|
|
175
|
+
locals?: object;
|
|
176
|
+
/** Which operation to use when the document holds more than one. */
|
|
177
|
+
operationName?: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Show the Prepr editor's unsaved changes on a server-rendered Astro page:
|
|
181
|
+
* pass the query and the result you fetched (with any client), and render
|
|
182
|
+
* what comes back.
|
|
183
|
+
*
|
|
184
|
+
* ```astro
|
|
185
|
+
* ---
|
|
186
|
+
* const data = await fetchFromPrepr(GetPageDocument, { slug });
|
|
187
|
+
* const page = normalizeQuery(GetPageDocument, data, {
|
|
188
|
+
* enabled: preview,
|
|
189
|
+
* locals: Astro.locals,
|
|
190
|
+
* });
|
|
191
|
+
* ---
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* Needs `onPreprRequest` with `preview: true` in your middleware and
|
|
195
|
+
* `PreprToolbar.astro` on the page; the toolbar re-requests the page with
|
|
196
|
+
* the editor's changes while they type. Select `_id` on every item and
|
|
197
|
+
* component that should update.
|
|
198
|
+
*/
|
|
199
|
+
declare function normalizeQuery<T>(query: QueryInput, result: T, options?: AstroNormalizeQueryOptions): T;
|
|
200
|
+
|
|
201
|
+
export { type AstroLikeContext, type AstroNext, type AstroNormalizeQueryOptions, PreprError, type PreprMiddlewareOptions, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, onPreprRequest, validatePreprToken };
|