@preprio/toolkit 1.0.0-rc.1 → 1.0.0-rc.3

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@preprio/toolkit.svg)](https://www.npmjs.com/package/@preprio/toolkit)
4
4
  [![npm downloads](https://img.shields.io/npm/dm/@preprio/toolkit.svg)](https://www.npmjs.com/package/@preprio/toolkit)
5
- [![license](https://img.shields.io/npm/l/@preprio/toolkit.svg)](https://github.com/preprio/prepr-toolkit/blob/main/LICENSE)
5
+ [![license](https://img.shields.io/npm/l/@preprio/toolkit.svg)](./LICENSE)
6
6
 
7
7
  Preview, visual editing, live preview and personalization for [Prepr CMS](https://prepr.io), for Next.js, Nuxt, Astro, SvelteKit, React and any other stack. One framework-free core with a thin wrapper per framework.
8
8
 
@@ -40,16 +40,16 @@ npm install @preprio/toolkit
40
40
 
41
41
  ## Choose your entry point
42
42
 
43
- | You use | Import from | Guide |
44
- | -------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------- |
45
- | Next.js | `@preprio/toolkit/nextjs` | [Next.js](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nextjs.md) |
46
- | Astro | `@preprio/toolkit/astro` | [Astro](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/astro.md) |
47
- | SvelteKit | `@preprio/toolkit/sveltekit` | [SvelteKit](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/sveltekit.md) |
48
- | Nuxt | `@preprio/toolkit/nuxt` | [Nuxt](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nuxt.md) |
49
- | React, no framework | `@preprio/toolkit/react` | [React](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/react.md) |
50
- | Express, Hono, other | `@preprio/toolkit` | [Any other framework](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/other-frameworks.md) |
43
+ | You use | Import from | Guide |
44
+ | -------------------- | ---------------------------- | ------------------------------------------------- |
45
+ | Next.js | `@preprio/toolkit/nextjs` | [Next.js](./docs/nextjs.md) |
46
+ | Astro | `@preprio/toolkit/astro` | [Astro](./docs/astro.md) |
47
+ | SvelteKit | `@preprio/toolkit/sveltekit` | [SvelteKit](./docs/sveltekit.md) |
48
+ | Nuxt | `@preprio/toolkit/nuxt` | [Nuxt](./docs/nuxt.md) |
49
+ | React, no framework | `@preprio/toolkit/react` | [React](./docs/react.md) |
50
+ | Express, Hono, other | `@preprio/toolkit` | [Any other framework](./docs/other-frameworks.md) |
51
51
 
52
- Coming from `@preprio/prepr-nextjs`? See the [migration guide](https://github.com/preprio/prepr-toolkit/blob/main/MIGRATION.md).
52
+ Coming from `@preprio/prepr-nextjs`? See the [migration guide](../../MIGRATION.md).
53
53
 
54
54
  ## How it fits together
55
55
 
@@ -67,7 +67,7 @@ Two rules hold everywhere:
67
67
 
68
68
  ## Quick start (Next.js)
69
69
 
70
- Other frameworks follow the same steps: [Astro](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/astro.md), [SvelteKit](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/sveltekit.md), [Nuxt](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nuxt.md).
70
+ Other frameworks follow the same steps: [Astro](./docs/astro.md), [SvelteKit](./docs/sveltekit.md), [Nuxt](./docs/nuxt.md).
71
71
 
72
72
  **1. Add your GraphQL URL to `.env`.** The name is yours.
73
73
 
@@ -147,7 +147,7 @@ const response = await fetch(process.env.PREPR_GRAPHQL_URL!, {
147
147
  2. Pick a segment. The page updates with that segment's content.
148
148
  3. Open a content item's preview in Prepr and click text on the page. Prepr opens the field.
149
149
 
150
- Nothing showing? See [Troubleshooting](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/troubleshooting.md).
150
+ Nothing showing? See [Troubleshooting](./docs/troubleshooting.md).
151
151
 
152
152
  ## Set up live preview
153
153
 
@@ -179,7 +179,7 @@ const config = {
179
179
  };
180
180
  ```
181
181
 
182
- No Codegen? See [the other two ways](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/live-preview.md#preparing-your-queries).
182
+ No Codegen? See [the other two ways](./docs/live-preview.md#preparing-your-queries).
183
183
 
184
184
  **5. Run your query results through the live preview helper**, with your preview flag as `enabled`:
185
185
 
@@ -190,29 +190,29 @@ No Codegen? See [the other two ways](https://github.com/preprio/prepr-toolkit/bl
190
190
  | SvelteKit | `normalizedQuery(GetPageDocument, data.result, { enabled: data.preview, onSave: invalidateAll })` from `@preprio/toolkit/sveltekit/live` |
191
191
  | Nuxt | `useNormalizedQuery(GetPageDocument, data, { enabled: preview, onSave: refresh })` from `@preprio/toolkit/nuxt/live` |
192
192
 
193
- Full snippets per framework: [Next.js](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nextjs.md#live-preview) · [Astro](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/astro.md#live-preview) · [SvelteKit](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/sveltekit.md#live-preview) · [Nuxt](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nuxt.md#live-preview).
193
+ Full snippets per framework: [Next.js](./docs/nextjs.md#live-preview) · [Astro](./docs/astro.md#live-preview) · [SvelteKit](./docs/sveltekit.md#live-preview) · [Nuxt](./docs/nuxt.md#live-preview).
194
194
 
195
195
  **6. Verify it works.** Open a content item and its preview in Prepr, and type in a text field. The page shows the text before you save.
196
196
 
197
- Not updating? Check, in this order: `enabled` is true, the page is served over HTTPS, the browser console shows no `Refused to frame` error, and the query selects `_id`. More in [Troubleshooting](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/troubleshooting.md#live-preview-does-not-update).
197
+ Not updating? Check, in this order: `enabled` is true, the page is served over HTTPS, the browser console shows no `Refused to frame` error, and the query selects `_id`. More in [Troubleshooting](./docs/troubleshooting.md#live-preview-does-not-update).
198
198
 
199
- The [live preview guide](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/live-preview.md) covers how it works, every option, the cookies involved and the security model.
199
+ The [live preview guide](./docs/live-preview.md) covers how it works, every option, the cookies involved and the security model.
200
200
 
201
201
  ## Documentation
202
202
 
203
- | Topic | |
204
- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
205
- | Framework guides | [Next.js](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nextjs.md) · [Astro](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/astro.md) · [SvelteKit](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/sveltekit.md) · [Nuxt](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/nuxt.md) · [React](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/react.md) · [Other](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/other-frameworks.md) |
206
- | [Live preview](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/live-preview.md) | Checklist, preparing queries, options, security, cookies |
207
- | [Visual editing](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/visual-editing.md) | How click-to-edit picks elements, and marking content by hand |
208
- | [Configuration](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/configuration.md) | Middleware and preview options, feature flags, headless preview, theming, languages |
209
- | [API reference](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/api-reference.md) | Every entry point, helper and component |
210
- | [Troubleshooting](https://github.com/preprio/prepr-toolkit/blob/main/packages/toolkit/docs/troubleshooting.md) | Toolbar, click-to-edit, headers, live preview, cookies |
211
- | [Examples](https://github.com/preprio/prepr-toolkit/tree/main/examples) | Runnable Next.js, Astro, SvelteKit, Nuxt and Express apps |
203
+ | Topic | |
204
+ | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
205
+ | Framework guides | [Next.js](./docs/nextjs.md) · [Astro](./docs/astro.md) · [SvelteKit](./docs/sveltekit.md) · [Nuxt](./docs/nuxt.md) · [React](./docs/react.md) · [Other](./docs/other-frameworks.md) |
206
+ | [Live preview](./docs/live-preview.md) | Checklist, preparing queries, options, security, cookies |
207
+ | [Visual editing](./docs/visual-editing.md) | How click-to-edit picks elements, and marking content by hand |
208
+ | [Configuration](./docs/configuration.md) | Middleware and preview options, feature flags, headless preview, theming, languages |
209
+ | [API reference](./docs/api-reference.md) | Every entry point, helper and component |
210
+ | [Troubleshooting](./docs/troubleshooting.md) | Toolbar, click-to-edit, headers, live preview, cookies |
211
+ | [Examples](../../examples) | Runnable Next.js, Astro, SvelteKit, Nuxt and Express apps |
212
212
 
213
213
  ## Versioning
214
214
 
215
- The package follows semver. Minor and patch releases never break the public API; a breaking change ships as a major version with a migration entry. An API on its way out is marked `@deprecated` and keeps working until the next major. See the [changelog](https://github.com/preprio/prepr-toolkit/blob/main/CHANGELOG.md).
215
+ The package follows semver. Minor and patch releases never break the public API; a breaking change ships as a major version with a migration entry. An API on its way out is marked `@deprecated` and keeps working until the next major. See the [changelog](../../CHANGELOG.md).
216
216
 
217
217
  Cookie names, header names, `data-prepr-*` attributes and the editor's message format are part of that contract.
218
218
 
@@ -34,7 +34,7 @@ __export(astro_exports, {
34
34
  module.exports = __toCommonJS(astro_exports);
35
35
 
36
36
  // src/version.ts
37
- var VERSION = "1.0.0-rc.1";
37
+ var VERSION = "1.0.0-rc.3";
38
38
 
39
39
  // src/core/constants.ts
40
40
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "1.0.0-rc.1";
2
+ var VERSION = "1.0.0-rc.3";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "1.0.0-rc.1";
2
+ var VERSION = "1.0.0-rc.3";
3
3
 
4
4
  // src/core/features.ts
5
5
  function isEnabled(config) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  VERSION,
3
3
  resolveFeatures
4
- } from "./chunk-33GWVTRJ.js";
4
+ } from "./chunk-EJDHVIFU.js";
5
5
 
6
6
  // src/core/server.ts
7
7
  var PreprError = class extends Error {
@@ -2,7 +2,7 @@ import {
2
2
  ALL_FEATURES_ENABLED,
3
3
  VERSION,
4
4
  resolveFeatures
5
- } from "./chunk-33GWVTRJ.js";
5
+ } from "./chunk-EJDHVIFU.js";
6
6
  import {
7
7
  createIframeBridge,
8
8
  isLocale,
@@ -29,13 +29,56 @@ var import_graphql = require("graphql");
29
29
  function field(name) {
30
30
  return { kind: import_graphql.Kind.FIELD, name: { kind: import_graphql.Kind.NAME, value: name } };
31
31
  }
32
+ function optionalField(name) {
33
+ return {
34
+ ...field(name),
35
+ directives: [
36
+ {
37
+ kind: import_graphql.Kind.DIRECTIVE,
38
+ name: { kind: import_graphql.Kind.NAME, value: "include" },
39
+ arguments: [
40
+ {
41
+ kind: import_graphql.Kind.ARGUMENT,
42
+ name: { kind: import_graphql.Kind.NAME, value: "if" },
43
+ value: { kind: import_graphql.Kind.BOOLEAN, value: true }
44
+ }
45
+ ]
46
+ }
47
+ ]
48
+ };
49
+ }
50
+ function collectFragmentTypes(documents) {
51
+ const types = /* @__PURE__ */ new Map();
52
+ for (const document of documents) {
53
+ for (const definition of document.definitions) {
54
+ if (definition.kind === import_graphql.Kind.FRAGMENT_DEFINITION) {
55
+ types.set(definition.name.value, definition.typeCondition.name.value);
56
+ }
57
+ }
58
+ }
59
+ return types;
60
+ }
61
+ function spreadCarriesId(set, type, schema, fragments) {
62
+ return set.selections.some((s) => {
63
+ if (s.kind !== import_graphql.Kind.FRAGMENT_SPREAD || s.directives?.length) return false;
64
+ const name = fragments.get(s.name.value);
65
+ const on = name ? schema.getType(name) : void 0;
66
+ if (!on || !((0, import_graphql.isObjectType)(on) || (0, import_graphql.isInterfaceType)(on))) return false;
67
+ if (!("_id" in on.getFields())) return false;
68
+ return on.name === type.name || (0, import_graphql.isInterfaceType)(on) && schema.isSubType(on, type);
69
+ });
70
+ }
32
71
  function hasResponseKey(set, key) {
33
72
  return set.selections.some(
34
73
  (s) => s.kind === import_graphql.Kind.FIELD && (s.alias ?? s.name).value === key
35
74
  );
36
75
  }
37
76
  function addPreprIds(document, schema, options = {}) {
77
+ return addIds(document, schema, options, collectFragmentTypes([document]));
78
+ }
79
+ function addIds(document, schema, options, fragments) {
38
80
  const typename = options.typename ?? false;
81
+ const idField = options.optionalInTypes ? optionalField("_id") : field("_id");
39
82
  const roots = new Set(
40
83
  [
41
84
  schema.getQueryType(),
@@ -51,8 +94,8 @@ function addPreprIds(document, schema, options = {}) {
51
94
  const type = typeInfo.getParentType();
52
95
  if (!type || !(0, import_graphql.isCompositeType)(type) || roots.has(type)) return;
53
96
  const added = [];
54
- if (((0, import_graphql.isObjectType)(type) || (0, import_graphql.isInterfaceType)(type)) && "_id" in type.getFields() && !hasResponseKey(node, "_id")) {
55
- added.push(field("_id"));
97
+ if (((0, import_graphql.isObjectType)(type) || (0, import_graphql.isInterfaceType)(type)) && "_id" in type.getFields() && !hasResponseKey(node, "_id") && !spreadCarriesId(node, type, schema, fragments)) {
98
+ added.push(idField);
56
99
  }
57
100
  if (typename && !hasResponseKey(node, "__typename")) {
58
101
  added.push(field("__typename"));
@@ -67,8 +110,14 @@ function createPreprIds(options = {}) {
67
110
  return {
68
111
  transform({ documents, schema }) {
69
112
  const built = (0, import_graphql.buildASTSchema)(schema, { assumeValidSDL: true });
113
+ const fragments = collectFragmentTypes(
114
+ documents.flatMap((file) => file.document ? [file.document] : [])
115
+ );
70
116
  return documents.map(
71
- (file) => file.document ? { ...file, document: addPreprIds(file.document, built, options) } : file
117
+ (file) => file.document ? {
118
+ ...file,
119
+ document: addIds(file.document, built, options, fragments)
120
+ } : file
72
121
  );
73
122
  }
74
123
  };
@@ -17,6 +17,17 @@ interface PreprIdsOptions {
17
17
  * already to render them.
18
18
  */
19
19
  typename?: boolean;
20
+ /**
21
+ * Type the added `_id` as optional (`_id?: string`), so objects written by
22
+ * hand against the generated types, such as test fixtures and mocks, keep
23
+ * compiling without one. Default `false`.
24
+ *
25
+ * The field is selected as `_id @include(if: true)`: the API always
26
+ * returns it, and Codegen types a field with `@include` as optional. Code
27
+ * that reads an added `_id` gets `string | undefined`. An `_id` you select
28
+ * yourself is left as written.
29
+ */
30
+ optionalInTypes?: boolean;
20
31
  }
21
32
  /**
22
33
  * Select `_id` on every level of a query that has one, so live preview and
@@ -24,10 +35,15 @@ interface PreprIdsOptions {
24
35
  *
25
36
  * The schema decides where it goes: only on types that have an `_id`
26
37
  * (models and components, not collections like `Pages` or unions; inside a
27
- * union, on each member). Adding a field never breaks the types Codegen
28
- * generates. With `typename: true`, `__typename` is added on every object,
38
+ * union, on each member). Code that reads the data keeps compiling; objects
39
+ * written by hand against the generated types need an `_id` too, unless
40
+ * `optionalInTypes` is set. With `typename: true`, `__typename` is added on every object,
29
41
  * interface and union below the root too. Fields already selected are left
30
42
  * as they are.
43
+ *
44
+ * A level that spreads a fragment on its own type gets no `_id` of its own:
45
+ * the fragment selects it, and a second one next to the spread would sit
46
+ * outside the fragment's masked type. Fragments are looked up in `document`.
31
47
  */
32
48
  declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema, options?: PreprIdsOptions): DocumentNode;
33
49
  /** A GraphQL Codegen document transform. */
@@ -63,7 +79,8 @@ declare function createPreprIds(options?: PreprIdsOptions): CodegenDocumentTrans
63
79
  * },
64
80
  * ```
65
81
  *
66
- * `createPreprIds({ typename: true })` adds `__typename` as well.
82
+ * `createPreprIds({ typename: true })` adds `__typename` as well, and
83
+ * `createPreprIds({ optionalInTypes: true })` types the added `_id` as optional.
67
84
  */
68
85
  declare const preprIds: CodegenDocumentTransform;
69
86
 
@@ -17,6 +17,17 @@ interface PreprIdsOptions {
17
17
  * already to render them.
18
18
  */
19
19
  typename?: boolean;
20
+ /**
21
+ * Type the added `_id` as optional (`_id?: string`), so objects written by
22
+ * hand against the generated types, such as test fixtures and mocks, keep
23
+ * compiling without one. Default `false`.
24
+ *
25
+ * The field is selected as `_id @include(if: true)`: the API always
26
+ * returns it, and Codegen types a field with `@include` as optional. Code
27
+ * that reads an added `_id` gets `string | undefined`. An `_id` you select
28
+ * yourself is left as written.
29
+ */
30
+ optionalInTypes?: boolean;
20
31
  }
21
32
  /**
22
33
  * Select `_id` on every level of a query that has one, so live preview and
@@ -24,10 +35,15 @@ interface PreprIdsOptions {
24
35
  *
25
36
  * The schema decides where it goes: only on types that have an `_id`
26
37
  * (models and components, not collections like `Pages` or unions; inside a
27
- * union, on each member). Adding a field never breaks the types Codegen
28
- * generates. With `typename: true`, `__typename` is added on every object,
38
+ * union, on each member). Code that reads the data keeps compiling; objects
39
+ * written by hand against the generated types need an `_id` too, unless
40
+ * `optionalInTypes` is set. With `typename: true`, `__typename` is added on every object,
29
41
  * interface and union below the root too. Fields already selected are left
30
42
  * as they are.
43
+ *
44
+ * A level that spreads a fragment on its own type gets no `_id` of its own:
45
+ * the fragment selects it, and a second one next to the spread would sit
46
+ * outside the fragment's masked type. Fragments are looked up in `document`.
31
47
  */
32
48
  declare function addPreprIds(document: DocumentNode, schema: GraphQLSchema, options?: PreprIdsOptions): DocumentNode;
33
49
  /** A GraphQL Codegen document transform. */
@@ -63,7 +79,8 @@ declare function createPreprIds(options?: PreprIdsOptions): CodegenDocumentTrans
63
79
  * },
64
80
  * ```
65
81
  *
66
- * `createPreprIds({ typename: true })` adds `__typename` as well.
82
+ * `createPreprIds({ typename: true })` adds `__typename` as well, and
83
+ * `createPreprIds({ optionalInTypes: true })` types the added `_id` as optional.
67
84
  */
68
85
  declare const preprIds: CodegenDocumentTransform;
69
86
 
@@ -12,13 +12,56 @@ import {
12
12
  function field(name) {
13
13
  return { kind: Kind.FIELD, name: { kind: Kind.NAME, value: name } };
14
14
  }
15
+ function optionalField(name) {
16
+ return {
17
+ ...field(name),
18
+ directives: [
19
+ {
20
+ kind: Kind.DIRECTIVE,
21
+ name: { kind: Kind.NAME, value: "include" },
22
+ arguments: [
23
+ {
24
+ kind: Kind.ARGUMENT,
25
+ name: { kind: Kind.NAME, value: "if" },
26
+ value: { kind: Kind.BOOLEAN, value: true }
27
+ }
28
+ ]
29
+ }
30
+ ]
31
+ };
32
+ }
33
+ function collectFragmentTypes(documents) {
34
+ const types = /* @__PURE__ */ new Map();
35
+ for (const document of documents) {
36
+ for (const definition of document.definitions) {
37
+ if (definition.kind === Kind.FRAGMENT_DEFINITION) {
38
+ types.set(definition.name.value, definition.typeCondition.name.value);
39
+ }
40
+ }
41
+ }
42
+ return types;
43
+ }
44
+ function spreadCarriesId(set, type, schema, fragments) {
45
+ return set.selections.some((s) => {
46
+ if (s.kind !== Kind.FRAGMENT_SPREAD || s.directives?.length) return false;
47
+ const name = fragments.get(s.name.value);
48
+ const on = name ? schema.getType(name) : void 0;
49
+ if (!on || !(isObjectType(on) || isInterfaceType(on))) return false;
50
+ if (!("_id" in on.getFields())) return false;
51
+ return on.name === type.name || isInterfaceType(on) && schema.isSubType(on, type);
52
+ });
53
+ }
15
54
  function hasResponseKey(set, key) {
16
55
  return set.selections.some(
17
56
  (s) => s.kind === Kind.FIELD && (s.alias ?? s.name).value === key
18
57
  );
19
58
  }
20
59
  function addPreprIds(document, schema, options = {}) {
60
+ return addIds(document, schema, options, collectFragmentTypes([document]));
61
+ }
62
+ function addIds(document, schema, options, fragments) {
21
63
  const typename = options.typename ?? false;
64
+ const idField = options.optionalInTypes ? optionalField("_id") : field("_id");
22
65
  const roots = new Set(
23
66
  [
24
67
  schema.getQueryType(),
@@ -34,8 +77,8 @@ function addPreprIds(document, schema, options = {}) {
34
77
  const type = typeInfo.getParentType();
35
78
  if (!type || !isCompositeType(type) || roots.has(type)) return;
36
79
  const added = [];
37
- if ((isObjectType(type) || isInterfaceType(type)) && "_id" in type.getFields() && !hasResponseKey(node, "_id")) {
38
- added.push(field("_id"));
80
+ if ((isObjectType(type) || isInterfaceType(type)) && "_id" in type.getFields() && !hasResponseKey(node, "_id") && !spreadCarriesId(node, type, schema, fragments)) {
81
+ added.push(idField);
39
82
  }
40
83
  if (typename && !hasResponseKey(node, "__typename")) {
41
84
  added.push(field("__typename"));
@@ -50,8 +93,14 @@ function createPreprIds(options = {}) {
50
93
  return {
51
94
  transform({ documents, schema }) {
52
95
  const built = buildASTSchema(schema, { assumeValidSDL: true });
96
+ const fragments = collectFragmentTypes(
97
+ documents.flatMap((file) => file.document ? [file.document] : [])
98
+ );
53
99
  return documents.map(
54
- (file) => file.document ? { ...file, document: addPreprIds(file.document, built, options) } : file
100
+ (file) => file.document ? {
101
+ ...file,
102
+ document: addIds(file.document, built, options, fragments)
103
+ } : file
55
104
  );
56
105
  }
57
106
  };
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ __export(src_exports, {
51
51
  module.exports = __toCommonJS(src_exports);
52
52
 
53
53
  // src/version.ts
54
- var VERSION = "1.0.0-rc.1";
54
+ var VERSION = "1.0.0-rc.3";
55
55
 
56
56
  // src/core/features.ts
57
57
  function isEnabled(config) {
package/dist/index.d.cts CHANGED
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "1.0.0-rc.1";
8
+ declare const VERSION = "1.0.0-rc.3";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "1.0.0-rc.1";
8
+ declare const VERSION = "1.0.0-rc.3";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  setTrackingParam,
9
9
  stegaClean,
10
10
  trackEvent
11
- } from "./chunk-WBMN4L7G.js";
11
+ } from "./chunk-PI5HUQ6G.js";
12
12
  import {
13
13
  PreprError,
14
14
  extractAccessToken,
@@ -19,11 +19,11 @@ import {
19
19
  getPreprUUIDFromHeaders,
20
20
  getToolbarPropsFromHeaders,
21
21
  validatePreprToken
22
- } from "./chunk-DSJ22P6J.js";
22
+ } from "./chunk-N6CXRQQP.js";
23
23
  import {
24
24
  VERSION,
25
25
  resolveFeatures
26
- } from "./chunk-33GWVTRJ.js";
26
+ } from "./chunk-EJDHVIFU.js";
27
27
  import {
28
28
  createLiveBridge,
29
29
  createLiveStore
@@ -3707,7 +3707,7 @@ function createPreprPreview(opts = {}) {
3707
3707
  var import_react = require("react");
3708
3708
 
3709
3709
  // src/version.ts
3710
- var VERSION = "1.0.0-rc.1";
3710
+ var VERSION = "1.0.0-rc.3";
3711
3711
 
3712
3712
  // src/core/pixel.ts
3713
3713
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  createPreprPreview,
4
4
  loadTrackingPixel
5
- } from "../chunk-WBMN4L7G.js";
6
- import "../chunk-33GWVTRJ.js";
5
+ } from "../chunk-PI5HUQ6G.js";
6
+ import "../chunk-EJDHVIFU.js";
7
7
  import "../chunk-Y7JWV7WV.js";
8
8
  import "../chunk-UTKH7DOI.js";
9
9
  import "../chunk-V7MCHPE7.js";
@@ -49,7 +49,7 @@ module.exports = __toCommonJS(nextjs_exports);
49
49
  var import_server = require("next/server");
50
50
 
51
51
  // src/version.ts
52
- var VERSION = "1.0.0-rc.1";
52
+ var VERSION = "1.0.0-rc.3";
53
53
 
54
54
  // src/core/constants.ts
55
55
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -2,7 +2,7 @@
2
2
  import { NextResponse } from "next/server";
3
3
 
4
4
  // src/version.ts
5
- var VERSION = "1.0.0-rc.1";
5
+ var VERSION = "1.0.0-rc.3";
6
6
 
7
7
  // src/core/constants.ts
8
8
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -1,8 +1,8 @@
1
1
  "use server";
2
2
  import {
3
3
  isPreviewFromHeaders
4
- } from "../chunk-DSJ22P6J.js";
5
- import "../chunk-33GWVTRJ.js";
4
+ } from "../chunk-N6CXRQQP.js";
5
+ import "../chunk-EJDHVIFU.js";
6
6
  import {
7
7
  parsePatchLog
8
8
  } from "../chunk-KM2GME62.js";
@@ -35,7 +35,7 @@ __export(nuxt_exports, {
35
35
  module.exports = __toCommonJS(nuxt_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "1.0.0-rc.1";
38
+ var VERSION = "1.0.0-rc.3";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-LUKVPOJ2.js";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = "1.0.0-rc.1";
14
+ var VERSION = "1.0.0-rc.3";
15
15
 
16
16
  // src/core/features.ts
17
17
  function isEnabled(config) {
@@ -3703,7 +3703,7 @@ function createPreprPreview(opts = {}) {
3703
3703
  }
3704
3704
 
3705
3705
  // src/version.ts
3706
- var VERSION = "1.0.0-rc.1";
3706
+ var VERSION = "1.0.0-rc.3";
3707
3707
 
3708
3708
  // src/core/pixel.ts
3709
3709
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -3679,7 +3679,7 @@ function createPreprPreview(opts = {}) {
3679
3679
  }
3680
3680
 
3681
3681
  // src/version.ts
3682
- var VERSION = "1.0.0-rc.1";
3682
+ var VERSION = "1.0.0-rc.3";
3683
3683
 
3684
3684
  // src/core/pixel.ts
3685
3685
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -35,7 +35,7 @@ __export(sveltekit_exports, {
35
35
  module.exports = __toCommonJS(sveltekit_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "1.0.0-rc.1";
38
+ var VERSION = "1.0.0-rc.3";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-LUKVPOJ2.js";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = "1.0.0-rc.1";
14
+ var VERSION = "1.0.0-rc.3";
15
15
 
16
16
  // src/core/features.ts
17
17
  function isEnabled(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preprio/toolkit",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.0.0-rc.3",
4
4
  "description": "Prepr personalization, A/B testing and preview toolkit for React, Next.js, Nuxt, Astro, SvelteKit and Express",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Prepr B.V. (https://prepr.io)",