@prismicio/client 7.22.2 → 7.22.3-canary.15d0e36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/Client.cjs +3 -1
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.cts +1 -0
  4. package/dist/Client.d.cts.map +1 -1
  5. package/dist/Client.d.ts +1 -0
  6. package/dist/Client.d.ts.map +1 -1
  7. package/dist/Client.js +3 -1
  8. package/dist/Client.js.map +1 -1
  9. package/dist/Migration.d.cts +1 -0
  10. package/dist/Migration.d.ts +1 -0
  11. package/dist/WriteClient.d.cts +1 -0
  12. package/dist/WriteClient.d.ts +1 -0
  13. package/dist/buildQueryURL.d.cts +1 -0
  14. package/dist/buildQueryURL.d.ts +1 -0
  15. package/dist/cookie.cjs +7 -1
  16. package/dist/cookie.cjs.map +1 -1
  17. package/dist/cookie.d.cts +3 -1
  18. package/dist/cookie.d.cts.map +1 -1
  19. package/dist/cookie.d.ts +3 -1
  20. package/dist/cookie.d.ts.map +1 -1
  21. package/dist/cookie.js +7 -2
  22. package/dist/cookie.js.map +1 -1
  23. package/dist/errors.d.cts +1 -0
  24. package/dist/errors.d.ts +1 -0
  25. package/dist/getToolbarSrc.cjs +8 -3
  26. package/dist/getToolbarSrc.cjs.map +1 -1
  27. package/dist/getToolbarSrc.d.cts +10 -1
  28. package/dist/getToolbarSrc.d.cts.map +1 -1
  29. package/dist/getToolbarSrc.d.ts +10 -1
  30. package/dist/getToolbarSrc.d.ts.map +1 -1
  31. package/dist/getToolbarSrc.js +8 -3
  32. package/dist/getToolbarSrc.js.map +1 -1
  33. package/dist/helpers/asDate.d.cts +1 -0
  34. package/dist/helpers/asDate.d.ts +1 -0
  35. package/dist/helpers/asHTML.d.cts +1 -0
  36. package/dist/helpers/asHTML.d.ts +1 -0
  37. package/dist/helpers/asImagePixelDensitySrcSet.d.cts +1 -0
  38. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +1 -0
  39. package/dist/helpers/asImageSrc.d.cts +1 -0
  40. package/dist/helpers/asImageSrc.d.ts +1 -0
  41. package/dist/helpers/asImageWidthSrcSet.d.cts +1 -0
  42. package/dist/helpers/asImageWidthSrcSet.d.ts +1 -0
  43. package/dist/helpers/asLink.d.cts +1 -0
  44. package/dist/helpers/asLink.d.ts +1 -0
  45. package/dist/helpers/asLinkAttrs.d.cts +1 -0
  46. package/dist/helpers/asLinkAttrs.d.ts +1 -0
  47. package/dist/helpers/asText.d.cts +1 -0
  48. package/dist/helpers/asText.d.ts +1 -0
  49. package/dist/helpers/documentToLinkField.d.cts +1 -0
  50. package/dist/helpers/documentToLinkField.d.ts +1 -0
  51. package/dist/helpers/mapSliceZone.d.cts +1 -0
  52. package/dist/helpers/mapSliceZone.d.ts +1 -0
  53. package/dist/package.cjs +1 -1
  54. package/dist/package.js +1 -1
  55. package/dist/types/migration/ContentRelationship.d.cts +1 -0
  56. package/dist/types/migration/ContentRelationship.d.ts +1 -0
  57. package/dist/types/migration/Document.d.cts +1 -0
  58. package/dist/types/migration/Document.d.ts +1 -0
  59. package/dist/types/value/embed.d.cts +1 -0
  60. package/dist/types/value/embed.d.ts +1 -0
  61. package/dist/types/value/linkToMedia.d.cts +1 -0
  62. package/dist/types/value/linkToMedia.d.ts +1 -0
  63. package/dist/types/value/types.d.cts +1 -0
  64. package/dist/types/value/types.d.ts +1 -0
  65. package/dist/types/webhook/apiUpdate.d.cts +1 -0
  66. package/dist/types/webhook/apiUpdate.d.ts +1 -0
  67. package/package.json +7 -7
  68. package/src/Client.ts +7 -1
  69. package/src/cookie.ts +3 -0
  70. package/src/getToolbarSrc.ts +18 -4
@@ -43,4 +43,5 @@ type AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null |
43
43
  */
44
44
  export declare const asImagePixelDensitySrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImagePixelDensitySrcSetConfig) => AsImagePixelDensitySrcSetReturnType<Field>;
45
45
  //#endregion
46
+ export {};
46
47
  //# sourceMappingURL=asImagePixelDensitySrcSet.d.ts.map
@@ -21,4 +21,5 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> = Fi
21
21
  */
22
22
  export declare const asImageSrc: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: ImgixURLParams) => AsImageSrcReturnType<Field>;
23
23
  //#endregion
24
+ export {};
24
25
  //# sourceMappingURL=asImageSrc.d.cts.map
@@ -21,4 +21,5 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> = Fi
21
21
  */
22
22
  export declare const asImageSrc: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: ImgixURLParams) => AsImageSrcReturnType<Field>;
23
23
  //#endregion
24
+ export {};
24
25
  //# sourceMappingURL=asImageSrc.d.ts.map
@@ -50,4 +50,5 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
50
50
  */
51
51
  export declare const asImageWidthSrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImageWidthSrcSetConfig) => AsImageWidthSrcSetReturnType<Field>;
52
52
  //#endregion
53
+ export {};
53
54
  //# sourceMappingURL=asImageWidthSrcSet.d.cts.map
@@ -50,4 +50,5 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
50
50
  */
51
51
  export declare const asImageWidthSrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImageWidthSrcSetConfig) => AsImageWidthSrcSetReturnType<Field>;
52
52
  //#endregion
53
+ export {};
53
54
  //# sourceMappingURL=asImageWidthSrcSet.d.ts.map
@@ -60,4 +60,5 @@ export declare const asLink: {
60
60
  <LinkResolverFunctionReturnType = string | null | undefined, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined>(linkFieldOrDocument: Field, ...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>): AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
61
61
  };
62
62
  //#endregion
63
+ export {};
63
64
  //# sourceMappingURL=asLink.d.cts.map
@@ -60,4 +60,5 @@ export declare const asLink: {
60
60
  <LinkResolverFunctionReturnType = string | null | undefined, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined>(linkFieldOrDocument: Field, ...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>): AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
61
61
  };
62
62
  //#endregion
63
+ export {};
63
64
  //# sourceMappingURL=asLink.d.ts.map
@@ -41,4 +41,5 @@ type AsLinkAttrsReturnType<LinkResolverFunctionReturnType = ReturnType<LinkResol
41
41
  */
42
42
  export declare const asLinkAttrs: <LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined>(linkFieldOrDocument: Field, config?: AsLinkAttrsConfig<LinkResolverFunctionReturnType>) => AsLinkAttrsReturnType<LinkResolverFunctionReturnType>;
43
43
  //#endregion
44
+ export {};
44
45
  //# sourceMappingURL=asLinkAttrs.d.cts.map
@@ -41,4 +41,5 @@ type AsLinkAttrsReturnType<LinkResolverFunctionReturnType = ReturnType<LinkResol
41
41
  */
42
42
  export declare const asLinkAttrs: <LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined>(linkFieldOrDocument: Field, config?: AsLinkAttrsConfig<LinkResolverFunctionReturnType>) => AsLinkAttrsReturnType<LinkResolverFunctionReturnType>;
43
43
  //#endregion
44
+ export {};
44
45
  //# sourceMappingURL=asLinkAttrs.d.ts.map
@@ -43,4 +43,5 @@ export declare const asText: {
43
43
  <Field extends RichTextField | null | undefined>(richTextField: Field, ...config: AsTextDeprecatedTupleConfig): AsTextReturnType<Field>;
44
44
  };
45
45
  //#endregion
46
+ export {};
46
47
  //# sourceMappingURL=asText.d.cts.map
@@ -43,4 +43,5 @@ export declare const asText: {
43
43
  <Field extends RichTextField | null | undefined>(richTextField: Field, ...config: AsTextDeprecatedTupleConfig): AsTextReturnType<Field>;
44
44
  };
45
45
  //#endregion
46
+ export {};
46
47
  //# sourceMappingURL=asText.d.ts.map
@@ -12,4 +12,5 @@ type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> & Partial<Pick<T, Keys
12
12
  */
13
13
  export declare const documentToLinkField: <TDocument extends SetOptional<PrismicDocument, "slugs">>(prismicDocument: TDocument) => FilledContentRelationshipField<TDocument["type"], TDocument["lang"], TDocument["data"]>;
14
14
  //#endregion
15
+ export {};
15
16
  //# sourceMappingURL=documentToLinkField.d.cts.map
@@ -12,4 +12,5 @@ type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> & Partial<Pick<T, Keys
12
12
  */
13
13
  export declare const documentToLinkField: <TDocument extends SetOptional<PrismicDocument, "slugs">>(prismicDocument: TDocument) => FilledContentRelationshipField<TDocument["type"], TDocument["lang"], TDocument["data"]>;
14
14
  //#endregion
15
+ export {};
15
16
  //# sourceMappingURL=documentToLinkField.d.ts.map
@@ -109,4 +109,5 @@ type MapSliceLike<TSliceLike extends SliceLike<any>, TSliceMappers extends Slice
109
109
  */
110
110
  export declare function mapSliceZone<TSliceLike extends SliceLike, TSliceMappers extends SliceMappers<TSliceLike, TContext>, TContext = unknown>(sliceZone: SliceZoneLike<TSliceLike>, mappers: TSliceMappers, context?: TContext): Promise<MapSliceLike<TSliceLike, TSliceMappers>[]>;
111
111
  //#endregion
112
+ export {};
112
113
  //# sourceMappingURL=mapSliceZone.d.cts.map
@@ -109,4 +109,5 @@ type MapSliceLike<TSliceLike extends SliceLike<any>, TSliceMappers extends Slice
109
109
  */
110
110
  export declare function mapSliceZone<TSliceLike extends SliceLike, TSliceMappers extends SliceMappers<TSliceLike, TContext>, TContext = unknown>(sliceZone: SliceZoneLike<TSliceLike>, mappers: TSliceMappers, context?: TContext): Promise<MapSliceLike<TSliceLike, TSliceMappers>[]>;
111
111
  //#endregion
112
+ export {};
112
113
  //# sourceMappingURL=mapSliceZone.d.ts.map
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@prismicio/client";
3
- var version = "7.22.2";
3
+ var version = "7.22.3-canary.15d0e36";
4
4
  //#endregion
5
5
  Object.defineProperty(exports, "name", {
6
6
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@prismicio/client";
3
- var version = "7.22.2";
3
+ var version = "7.22.3-canary.15d0e36";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -8,4 +8,5 @@ export type MigrationContentRelationship<TDocuments extends PrismicDocument = Pr
8
8
  id: ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined>;
9
9
  });
10
10
  //#endregion
11
+ export {};
11
12
  //# sourceMappingURL=ContentRelationship.d.cts.map
@@ -8,4 +8,5 @@ export type MigrationContentRelationship<TDocuments extends PrismicDocument = Pr
8
8
  id: ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined>;
9
9
  });
10
10
  //#endregion
11
+ export {};
11
12
  //# sourceMappingURL=ContentRelationship.d.ts.map
@@ -74,4 +74,5 @@ export declare class PrismicMigrationDocument<TDocument extends PrismicDocument
74
74
  });
75
75
  }
76
76
  //#endregion
77
+ export {};
77
78
  //# sourceMappingURL=Document.d.cts.map
@@ -74,4 +74,5 @@ export declare class PrismicMigrationDocument<TDocument extends PrismicDocument
74
74
  });
75
75
  }
76
76
  //#endregion
77
+ export {};
77
78
  //# sourceMappingURL=Document.d.ts.map
@@ -120,4 +120,5 @@ export type EmbedField<Data extends AnyOEmbed = AnyOEmbed & OEmbedExtra, State e
120
120
  html: string | null;
121
121
  };
122
122
  //#endregion
123
+ export {};
123
124
  //# sourceMappingURL=embed.d.cts.map
@@ -120,4 +120,5 @@ export type EmbedField<Data extends AnyOEmbed = AnyOEmbed & OEmbedExtra, State e
120
120
  html: string | null;
121
121
  };
122
122
  //#endregion
123
+ export {};
123
124
  //# sourceMappingURL=embed.d.ts.map
@@ -27,4 +27,5 @@ export type FilledLinkToMediaField<Variant = string> = {
27
27
  width?: string | null;
28
28
  } & OptionalLinkProperties<Variant>;
29
29
  //#endregion
30
+ export {};
30
31
  //# sourceMappingURL=linkToMedia.d.cts.map
@@ -27,4 +27,5 @@ export type FilledLinkToMediaField<Variant = string> = {
27
27
  width?: string | null;
28
28
  } & OptionalLinkProperties<Variant>;
29
29
  //#endregion
30
+ export {};
30
31
  //# sourceMappingURL=linkToMedia.d.ts.map
@@ -42,4 +42,5 @@ type WithKey<Field extends LinkField> = Field & {
42
42
  */
43
43
  export type Simplify<T> = { [P in keyof T]: T[P]; };
44
44
  //#endregion
45
+ export {};
45
46
  //# sourceMappingURL=types.d.cts.map
@@ -42,4 +42,5 @@ type WithKey<Field extends LinkField> = Field & {
42
42
  */
43
43
  export type Simplify<T> = { [P in keyof T]: T[P]; };
44
44
  //#endregion
45
+ export {};
45
46
  //# sourceMappingURL=types.d.ts.map
@@ -49,4 +49,5 @@ interface WebhookBodyAPIUpdateRelease {
49
49
  documents: string[];
50
50
  }
51
51
  //#endregion
52
+ export {};
52
53
  //# sourceMappingURL=apiUpdate.d.cts.map
@@ -49,4 +49,5 @@ interface WebhookBodyAPIUpdateRelease {
49
49
  documents: string[];
50
50
  }
51
51
  //#endregion
52
+ export {};
52
53
  //# sourceMappingURL=apiUpdate.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/client",
3
- "version": "7.22.2",
3
+ "version": "7.22.3-canary.15d0e36",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "client",
@@ -70,13 +70,13 @@
70
70
  "devDependencies": {
71
71
  "@prismicio/e2e-tests-utils": "^1.20.0",
72
72
  "@prismicio/types-internal": "^3.17.2",
73
- "@types/node": "^26.6.4",
74
- "@vitest/coverage-v8": "^5.0.3",
75
- "oxfmt": "^0.71.0",
76
- "oxlint": "^1.86.0",
77
- "tsdown": "^0.23.0",
73
+ "@types/node": "^26.6.5",
74
+ "@vitest/coverage-v8": "^5.0.5",
75
+ "oxfmt": "^0.73.0",
76
+ "oxlint": "^1.88.0",
77
+ "tsdown": "^0.23.1",
78
78
  "typescript": "^7.0.2",
79
- "vitest": "^5.0.3"
79
+ "vitest": "^5.0.5"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22"
package/src/Client.ts CHANGED
@@ -457,11 +457,17 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
457
457
  while ((!latestResult || latestResult.next_page) && documents.length < limit) {
458
458
  const page = latestResult ? latestResult.page + 1 : undefined
459
459
 
460
+ const requestedAt = Date.now()
460
461
  const response = await this.#internalGet({ ...resolvedParams, page })
461
462
  latestResult = (await response.json()) as Query<TDocument>
462
463
  documents.push(...latestResult.results)
463
464
 
464
- if (latestResult.next_page && !response.headers.get("x-cache")?.startsWith("Hit")) {
465
+ // Caches (CDN, Next.js Data Cache) replay the origin's `Date` header, even
466
+ // when they also replay an `x-cache: Miss`. The margin covers clock skew.
467
+ const isCached =
468
+ response.headers.get("x-cache")?.startsWith("Hit") ||
469
+ Date.parse(response.headers.get("date") ?? "") < requestedAt - 5000
470
+ if (latestResult.next_page && !isCached) {
465
471
  await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY))
466
472
  }
467
473
  }
package/src/cookie.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  /** The well-known name of the cookie used to store a Prismic preview session's ref. */
2
2
  export const preview = "io.prismic.preview"
3
+
4
+ /** The well-known name of the cookie used to store a Prismic preview session's ID. */
5
+ export const previewSession = "io.prismic.previewSession"
@@ -30,13 +30,27 @@ import { isRepositoryName } from "./isRepositoryName"
30
30
  *
31
31
  * @param repositoryName - The name of the Prismic repository. For example, `"my-repo"` if the
32
32
  * repository URL is `my-repo.prismic.io`.
33
+ * @param config - Options that configure the toolbar URL.
33
34
  * @returns The URL for the given Prismic repository's Prismic Toolbar script.
34
35
  */
35
- export const getToolbarSrc = <TRepositoryName extends string>(
36
- repositoryName: TRepositoryName,
37
- ): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {
36
+ export const getToolbarSrc = (
37
+ repositoryName: string,
38
+ config?: {
39
+ /** The version of the Prismic Toolbar to load. Defaults to 4. */
40
+ version?: 4 | 5
41
+ /**
42
+ * The URL the toolbar script is loaded from, without a trailing slash. For example, a toolbar
43
+ * preview build. Defaults to `https://static.cdn.prismic.io`.
44
+ */
45
+ host?: string
46
+ },
47
+ ): string => {
38
48
  if (isRepositoryName(repositoryName)) {
39
- return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const
49
+ const url = new URL(`${config?.host ?? "https://static.cdn.prismic.io"}/prismic.js`)
50
+ url.searchParams.set("repo", repositoryName)
51
+ if (config?.version) url.searchParams.set("v", config.version.toString())
52
+
53
+ return url.toString()
40
54
  } else {
41
55
  throw new PrismicError(
42
56
  `An invalid Prismic repository name was given: ${repositoryName}`,