@prismicio/client 7.2.0 → 7.3.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.
Files changed (131) hide show
  1. package/dist/createClient.cjs +18 -2
  2. package/dist/createClient.cjs.map +1 -1
  3. package/dist/createClient.js +18 -2
  4. package/dist/createClient.js.map +1 -1
  5. package/dist/errors/ForbiddenError.cjs.map +1 -1
  6. package/dist/errors/ForbiddenError.d.ts +1 -1
  7. package/dist/errors/ForbiddenError.js.map +1 -1
  8. package/dist/errors/NotFoundError.cjs.map +1 -1
  9. package/dist/errors/NotFoundError.d.ts +1 -1
  10. package/dist/errors/NotFoundError.js.map +1 -1
  11. package/dist/errors/ParsingError.cjs.map +1 -1
  12. package/dist/errors/ParsingError.d.ts +1 -1
  13. package/dist/errors/ParsingError.js.map +1 -1
  14. package/dist/errors/PreviewTokenExpired.cjs +7 -0
  15. package/dist/errors/PreviewTokenExpired.cjs.map +1 -0
  16. package/dist/errors/PreviewTokenExpired.d.ts +8 -0
  17. package/dist/errors/PreviewTokenExpired.js +7 -0
  18. package/dist/errors/PreviewTokenExpired.js.map +1 -0
  19. package/dist/errors/RefExpiredError.cjs +7 -0
  20. package/dist/errors/RefExpiredError.cjs.map +1 -0
  21. package/dist/errors/RefExpiredError.d.ts +8 -0
  22. package/dist/errors/RefExpiredError.js +7 -0
  23. package/dist/errors/RefExpiredError.js.map +1 -0
  24. package/dist/errors/RefNotFoundError.cjs +7 -0
  25. package/dist/errors/RefNotFoundError.cjs.map +1 -0
  26. package/dist/errors/RefNotFoundError.d.ts +8 -0
  27. package/dist/errors/RefNotFoundError.js +7 -0
  28. package/dist/errors/RefNotFoundError.js.map +1 -0
  29. package/dist/errors/RepositoryNotFoundError.cjs +7 -0
  30. package/dist/errors/RepositoryNotFoundError.cjs.map +1 -0
  31. package/dist/errors/RepositoryNotFoundError.d.ts +3 -0
  32. package/dist/errors/RepositoryNotFoundError.js +7 -0
  33. package/dist/errors/RepositoryNotFoundError.js.map +1 -0
  34. package/dist/helpers/asHTML.cjs +43 -50
  35. package/dist/helpers/asHTML.cjs.map +1 -1
  36. package/dist/helpers/asHTML.d.ts +31 -6
  37. package/dist/helpers/asHTML.js +42 -49
  38. package/dist/helpers/asHTML.js.map +1 -1
  39. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +1 -1
  40. package/dist/helpers/asImageSrc.d.ts +1 -1
  41. package/dist/helpers/asImageWidthSrcSet.cjs +1 -1
  42. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  43. package/dist/helpers/asImageWidthSrcSet.d.ts +1 -1
  44. package/dist/helpers/asImageWidthSrcSet.js +1 -1
  45. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  46. package/dist/helpers/asLinkAttrs.d.ts +1 -1
  47. package/dist/helpers/asText.cjs +2 -2
  48. package/dist/helpers/asText.cjs.map +1 -1
  49. package/dist/helpers/asText.js +1 -1
  50. package/dist/helpers/asText.js.map +1 -1
  51. package/dist/helpers/isFilled.d.ts +10 -13
  52. package/dist/index.cjs +12 -7
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.d.ts +30 -2
  55. package/dist/index.js +10 -2
  56. package/dist/index.js.map +1 -1
  57. package/dist/lib/serializerHelpers.cjs +91 -35
  58. package/dist/lib/serializerHelpers.cjs.map +1 -1
  59. package/dist/lib/serializerHelpers.d.ts +8 -8
  60. package/dist/lib/serializerHelpers.js +91 -35
  61. package/dist/lib/serializerHelpers.js.map +1 -1
  62. package/dist/package.json.cjs +1 -1
  63. package/dist/package.json.js +1 -1
  64. package/dist/richtext/asText.cjs +13 -0
  65. package/dist/richtext/asText.cjs.map +1 -0
  66. package/dist/richtext/asText.d.ts +12 -0
  67. package/dist/richtext/asText.js +13 -0
  68. package/dist/richtext/asText.js.map +1 -0
  69. package/dist/richtext/asTree.cjs +123 -0
  70. package/dist/richtext/asTree.cjs.map +1 -0
  71. package/dist/richtext/asTree.d.ts +14 -0
  72. package/dist/richtext/asTree.js +123 -0
  73. package/dist/richtext/asTree.js.map +1 -0
  74. package/dist/richtext/composeSerializers.cjs +17 -0
  75. package/dist/richtext/composeSerializers.cjs.map +1 -0
  76. package/dist/richtext/composeSerializers.d.ts +16 -0
  77. package/dist/richtext/composeSerializers.js +17 -0
  78. package/dist/richtext/composeSerializers.js.map +1 -0
  79. package/dist/richtext/index.d.ts +7 -0
  80. package/dist/richtext/serialize.cjs +19 -0
  81. package/dist/richtext/serialize.cjs.map +1 -0
  82. package/dist/richtext/serialize.d.ts +19 -0
  83. package/dist/richtext/serialize.js +19 -0
  84. package/dist/richtext/serialize.js.map +1 -0
  85. package/dist/richtext/types.cjs +11 -0
  86. package/dist/richtext/types.cjs.map +1 -0
  87. package/dist/richtext/types.d.ts +71 -0
  88. package/dist/richtext/types.js +11 -0
  89. package/dist/richtext/types.js.map +1 -0
  90. package/dist/richtext/wrapMapSerializer.cjs +24 -0
  91. package/dist/richtext/wrapMapSerializer.cjs.map +1 -0
  92. package/dist/richtext/wrapMapSerializer.d.ts +15 -0
  93. package/dist/richtext/wrapMapSerializer.js +24 -0
  94. package/dist/richtext/wrapMapSerializer.js.map +1 -0
  95. package/dist/richtext.cjs +15 -0
  96. package/dist/richtext.cjs.map +1 -0
  97. package/dist/richtext.js +15 -0
  98. package/dist/richtext.js.map +1 -0
  99. package/dist/types/value/image.d.ts +9 -0
  100. package/dist/types/value/linkToMedia.d.ts +1 -0
  101. package/dist/types/value/richText.cjs.map +1 -1
  102. package/dist/types/value/richText.d.ts +7 -0
  103. package/dist/types/value/richText.js.map +1 -1
  104. package/dist/types/value/sharedSlice.d.ts +1 -1
  105. package/dist/types/value/slice.d.ts +1 -1
  106. package/package.json +34 -15
  107. package/src/createClient.ts +35 -8
  108. package/src/errors/ForbiddenError.ts +5 -3
  109. package/src/errors/NotFoundError.ts +3 -1
  110. package/src/errors/ParsingError.ts +3 -1
  111. package/src/errors/PreviewTokenExpired.ts +12 -0
  112. package/src/errors/RefExpiredError.ts +14 -0
  113. package/src/errors/RefNotFoundError.ts +14 -0
  114. package/src/errors/RepositoryNotFoundError.ts +5 -0
  115. package/src/helpers/asHTML.ts +166 -76
  116. package/src/helpers/asImageWidthSrcSet.ts +2 -0
  117. package/src/helpers/asText.ts +2 -2
  118. package/src/index.ts +11 -4
  119. package/src/lib/serializerHelpers.ts +140 -67
  120. package/src/richtext/asText.ts +27 -0
  121. package/src/richtext/asTree.ts +211 -0
  122. package/src/richtext/composeSerializers.ts +36 -0
  123. package/src/richtext/index.ts +14 -0
  124. package/src/richtext/serialize.ts +54 -0
  125. package/src/richtext/types.ts +153 -0
  126. package/src/richtext/wrapMapSerializer.ts +46 -0
  127. package/src/types/value/image.ts +9 -0
  128. package/src/types/value/linkToMedia.ts +1 -0
  129. package/src/types/value/richText.ts +7 -0
  130. package/src/types/value/sharedSlice.ts +1 -1
  131. package/src/types/value/slice.ts +1 -1
@@ -0,0 +1,153 @@
1
+ import {
2
+ RTAnyNode,
3
+ RTEmNode,
4
+ RTEmbedNode,
5
+ RTHeading1Node,
6
+ RTHeading2Node,
7
+ RTHeading3Node,
8
+ RTHeading4Node,
9
+ RTHeading5Node,
10
+ RTHeading6Node,
11
+ RTImageNode,
12
+ RTLabelNode,
13
+ RTLinkNode,
14
+ RTListItemNode,
15
+ RTListNode,
16
+ RTOListItemNode,
17
+ RTOListNode,
18
+ RTParagraphNode,
19
+ RTPreformattedNode,
20
+ RTSpanNode,
21
+ RTStrongNode,
22
+ RichTextNodeType,
23
+ } from "../types/value/richText";
24
+
25
+ // Serializers
26
+
27
+ /**
28
+ * Serializes a node from a rich text or title field with a function
29
+ *
30
+ * @typeParam ReturnType - Return type of the function serializer
31
+ *
32
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
33
+ */
34
+ export type RichTextFunctionSerializer<ReturnType> = (
35
+ type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType],
36
+ node: RTAnyNode,
37
+ text: string | undefined,
38
+ children: ReturnType[],
39
+ key: string,
40
+ ) => ReturnType | null | undefined;
41
+
42
+ /**
43
+ * Map serializer's tag function serializer, can be helpful for typing those
44
+ * handlers
45
+ *
46
+ * @typeParam ReturnType - Return type of the tag serializer
47
+ */
48
+ export type RichTextMapSerializerFunction<
49
+ ReturnType,
50
+ Node extends RTAnyNode = RTAnyNode,
51
+ TextType = string | undefined,
52
+ > = (payload: {
53
+ type: Node["type"];
54
+ node: Node;
55
+ text: TextType;
56
+ children: ReturnType[];
57
+ key: string;
58
+ }) => ReturnType | null | undefined;
59
+
60
+ /**
61
+ * Serializes a node from a rich text or title field with a map
62
+ *
63
+ * @remarks
64
+ * This type of serializer needs to be processed through
65
+ * {@link wrapMapSerializer} before being used with {@link serialize}
66
+ *
67
+ * @typeParam ReturnType - Return type of the map serializer
68
+ *
69
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
70
+ */
71
+ export type RichTextMapSerializer<ReturnType> = {
72
+ heading1?: RichTextMapSerializerFunction<
73
+ ReturnType,
74
+ RTHeading1Node,
75
+ undefined
76
+ >;
77
+ heading2?: RichTextMapSerializerFunction<
78
+ ReturnType,
79
+ RTHeading2Node,
80
+ undefined
81
+ >;
82
+ heading3?: RichTextMapSerializerFunction<
83
+ ReturnType,
84
+ RTHeading3Node,
85
+ undefined
86
+ >;
87
+ heading4?: RichTextMapSerializerFunction<
88
+ ReturnType,
89
+ RTHeading4Node,
90
+ undefined
91
+ >;
92
+ heading5?: RichTextMapSerializerFunction<
93
+ ReturnType,
94
+ RTHeading5Node,
95
+ undefined
96
+ >;
97
+ heading6?: RichTextMapSerializerFunction<
98
+ ReturnType,
99
+ RTHeading6Node,
100
+ undefined
101
+ >;
102
+ paragraph?: RichTextMapSerializerFunction<
103
+ ReturnType,
104
+ RTParagraphNode,
105
+ undefined
106
+ >;
107
+ preformatted?: RichTextMapSerializerFunction<
108
+ ReturnType,
109
+ RTPreformattedNode,
110
+ undefined
111
+ >;
112
+ strong?: RichTextMapSerializerFunction<ReturnType, RTStrongNode, string>;
113
+ em?: RichTextMapSerializerFunction<ReturnType, RTEmNode, string>;
114
+ listItem?: RichTextMapSerializerFunction<
115
+ ReturnType,
116
+ RTListItemNode,
117
+ undefined
118
+ >;
119
+ oListItem?: RichTextMapSerializerFunction<
120
+ ReturnType,
121
+ RTOListItemNode,
122
+ undefined
123
+ >;
124
+ list?: RichTextMapSerializerFunction<ReturnType, RTListNode, undefined>;
125
+ oList?: RichTextMapSerializerFunction<ReturnType, RTOListNode, undefined>;
126
+ image?: RichTextMapSerializerFunction<ReturnType, RTImageNode, undefined>;
127
+ embed?: RichTextMapSerializerFunction<ReturnType, RTEmbedNode, undefined>;
128
+ hyperlink?: RichTextMapSerializerFunction<ReturnType, RTLinkNode, string>;
129
+ label?: RichTextMapSerializerFunction<ReturnType, RTLabelNode, string>;
130
+ span?: RichTextMapSerializerFunction<ReturnType, RTSpanNode, string>;
131
+ };
132
+
133
+ // Tree
134
+ export interface Tree {
135
+ key: string;
136
+ children: TreeNode[];
137
+ }
138
+
139
+ export interface TreeNode {
140
+ key: string;
141
+ type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType];
142
+ text?: string;
143
+ node: RTAnyNode;
144
+ children: TreeNode[];
145
+ }
146
+
147
+ // Helpers
148
+ export const RichTextReversedNodeType = {
149
+ [RichTextNodeType.listItem]: "listItem",
150
+ [RichTextNodeType.oListItem]: "oListItem",
151
+ [RichTextNodeType.list]: "list",
152
+ [RichTextNodeType.oList]: "oList",
153
+ } as const;
@@ -0,0 +1,46 @@
1
+ import {
2
+ RichTextFunctionSerializer,
3
+ RichTextMapSerializer,
4
+ RichTextReversedNodeType,
5
+ } from "./types";
6
+
7
+ /**
8
+ * Wraps a map serializer into a regular function serializer
9
+ *
10
+ * @remarks
11
+ * This is a low level helper mainly intended to be used by higher level
12
+ * packages Most users aren't expected to this function directly
13
+ *
14
+ * @typeParam SerializerReturnType - Return type of the map serializer
15
+ *
16
+ * @param mapSerializer - Map serializer to wrap
17
+ *
18
+ * @returns A regular function serializer
19
+ */
20
+ export const wrapMapSerializer = <SerializerReturnType>(
21
+ mapSerializer: RichTextMapSerializer<SerializerReturnType>,
22
+ ): RichTextFunctionSerializer<SerializerReturnType> => {
23
+ return (type, node, text, children, key) => {
24
+ const tagSerializer: RichTextMapSerializer<SerializerReturnType>[keyof RichTextMapSerializer<SerializerReturnType>] =
25
+ mapSerializer[
26
+ (RichTextReversedNodeType[
27
+ type as keyof typeof RichTextReversedNodeType
28
+ ] || type) as keyof RichTextMapSerializer<SerializerReturnType>
29
+ ];
30
+
31
+ if (tagSerializer) {
32
+ return tagSerializer({
33
+ // @ts-expect-error cannot type check here
34
+ type,
35
+ // @ts-expect-error cannot type check here
36
+ node,
37
+ // @ts-expect-error cannot type check here
38
+ text,
39
+ // @ts-expect-error cannot type check here
40
+ children,
41
+ // @ts-expect-error cannot type check here
42
+ key,
43
+ });
44
+ }
45
+ };
46
+ };
@@ -12,18 +12,27 @@ export type ImageFieldImage<State extends FieldState = FieldState> =
12
12
  State extends "empty" ? EmptyImageFieldImage : FilledImageFieldImage;
13
13
 
14
14
  export interface FilledImageFieldImage {
15
+ id: string;
15
16
  url: string;
16
17
  dimensions: {
17
18
  width: number;
18
19
  height: number;
19
20
  };
21
+ edit: {
22
+ x: number;
23
+ y: number;
24
+ zoom: number;
25
+ background: string;
26
+ };
20
27
  alt: string | null;
21
28
  copyright: string | null;
22
29
  }
23
30
 
24
31
  export interface EmptyImageFieldImage {
32
+ id?: null;
25
33
  url?: null;
26
34
  dimensions?: null;
35
+ edit?: null;
27
36
  alt?: null;
28
37
  copyright?: null;
29
38
  }
@@ -16,6 +16,7 @@ export type LinkToMediaField<State extends FieldState = FieldState> =
16
16
  * A link that points to media.
17
17
  */
18
18
  export interface FilledLinkToMediaField {
19
+ id: string;
19
20
  link_type: typeof LinkType.Media;
20
21
  name: string;
21
22
  kind: string;
@@ -153,6 +153,7 @@ export interface RTLabelNode extends RTSpanNodeBase {
153
153
  */
154
154
  export type RTImageNode = {
155
155
  type: typeof RichTextNodeType.image;
156
+ id: string;
156
157
  url: string;
157
158
  alt: string | null;
158
159
  copyright: string | null;
@@ -160,6 +161,12 @@ export type RTImageNode = {
160
161
  width: number;
161
162
  height: number;
162
163
  };
164
+ edit: {
165
+ x: number;
166
+ y: number;
167
+ zoom: number;
168
+ background: string;
169
+ };
163
170
  linkTo?:
164
171
  | FilledContentRelationshipField
165
172
  | FilledLinkToWebField
@@ -11,5 +11,5 @@ export type SharedSlice<
11
11
  > = {
12
12
  slice_type: SliceType;
13
13
  slice_label: null;
14
- id?: string;
14
+ id: string;
15
15
  } & Variations;
@@ -18,7 +18,7 @@ export interface Slice<
18
18
  > {
19
19
  slice_type: SliceType;
20
20
  slice_label: string | null;
21
- id?: string;
21
+ id: string;
22
22
  primary: PrimaryFields;
23
23
  items: ItemsFields[];
24
24
  }