@prismicio/client 7.21.0 → 7.21.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 (809) hide show
  1. package/dist/Client.cjs +920 -1256
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.cts +704 -0
  4. package/dist/Client.d.cts.map +1 -0
  5. package/dist/Client.d.ts +678 -955
  6. package/dist/Client.d.ts.map +1 -0
  7. package/dist/Client.js +913 -1249
  8. package/dist/Client.js.map +1 -1
  9. package/dist/Migration.cjs +283 -296
  10. package/dist/Migration.cjs.map +1 -1
  11. package/dist/Migration.d.cts +216 -0
  12. package/dist/Migration.d.cts.map +1 -0
  13. package/dist/Migration.d.ts +197 -194
  14. package/dist/Migration.d.ts.map +1 -0
  15. package/dist/Migration.js +281 -294
  16. package/dist/Migration.js.map +1 -1
  17. package/dist/WriteClient.cjs +487 -574
  18. package/dist/WriteClient.cjs.map +1 -1
  19. package/dist/WriteClient.d.cts +262 -0
  20. package/dist/WriteClient.d.cts.map +1 -0
  21. package/dist/WriteClient.d.ts +226 -245
  22. package/dist/WriteClient.d.ts.map +1 -0
  23. package/dist/WriteClient.js +482 -569
  24. package/dist/WriteClient.js.map +1 -1
  25. package/dist/_virtual/rolldown_runtime.cjs +14 -0
  26. package/dist/_virtual/rolldown_runtime.js +13 -0
  27. package/dist/buildQueryURL.cjs +89 -59
  28. package/dist/buildQueryURL.cjs.map +1 -1
  29. package/dist/buildQueryURL.d.cts +212 -0
  30. package/dist/buildQueryURL.d.cts.map +1 -0
  31. package/dist/buildQueryURL.d.ts +146 -151
  32. package/dist/buildQueryURL.d.ts.map +1 -0
  33. package/dist/buildQueryURL.js +89 -59
  34. package/dist/buildQueryURL.js.map +1 -1
  35. package/dist/cookie.cjs +17 -3
  36. package/dist/cookie.cjs.map +1 -1
  37. package/dist/cookie.d.cts +11 -0
  38. package/dist/cookie.d.cts.map +1 -0
  39. package/dist/cookie.d.ts +7 -1
  40. package/dist/cookie.d.ts.map +1 -0
  41. package/dist/cookie.js +12 -4
  42. package/dist/cookie.js.map +1 -1
  43. package/dist/createClient.cjs +32 -5
  44. package/dist/createClient.cjs.map +1 -1
  45. package/dist/createClient.d.cts +41 -0
  46. package/dist/createClient.d.cts.map +1 -0
  47. package/dist/createClient.d.ts +11 -5
  48. package/dist/createClient.d.ts.map +1 -0
  49. package/dist/createClient.js +31 -4
  50. package/dist/createClient.js.map +1 -1
  51. package/dist/createMigration.cjs +21 -5
  52. package/dist/createMigration.cjs.map +1 -1
  53. package/dist/createMigration.d.cts +30 -0
  54. package/dist/createMigration.d.cts.map +1 -0
  55. package/dist/createMigration.d.ts +10 -4
  56. package/dist/createMigration.d.ts.map +1 -0
  57. package/dist/createMigration.js +20 -4
  58. package/dist/createMigration.js.map +1 -1
  59. package/dist/createWriteClient.cjs +29 -5
  60. package/dist/createWriteClient.cjs.map +1 -1
  61. package/dist/createWriteClient.d.cts +38 -0
  62. package/dist/createWriteClient.d.cts.map +1 -0
  63. package/dist/createWriteClient.d.ts +10 -4
  64. package/dist/createWriteClient.d.ts.map +1 -0
  65. package/dist/createWriteClient.js +28 -4
  66. package/dist/createWriteClient.js.map +1 -1
  67. package/dist/errors.cjs +31 -0
  68. package/dist/errors.cjs.map +1 -0
  69. package/dist/errors.d.cts +46 -0
  70. package/dist/errors.d.cts.map +1 -0
  71. package/dist/errors.d.ts +46 -0
  72. package/dist/errors.d.ts.map +1 -0
  73. package/dist/errors.js +22 -0
  74. package/dist/errors.js.map +1 -0
  75. package/dist/filter.cjs +93 -236
  76. package/dist/filter.cjs.map +1 -1
  77. package/dist/filter.d.cts +213 -0
  78. package/dist/filter.d.cts.map +1 -0
  79. package/dist/filter.d.ts +212 -208
  80. package/dist/filter.d.ts.map +1 -0
  81. package/dist/filter.js +93 -237
  82. package/dist/filter.js.map +1 -1
  83. package/dist/getGraphQLEndpoint.cjs +18 -10
  84. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  85. package/dist/getGraphQLEndpoint.d.cts +14 -0
  86. package/dist/getGraphQLEndpoint.d.cts.map +1 -0
  87. package/dist/getGraphQLEndpoint.d.ts +5 -1
  88. package/dist/getGraphQLEndpoint.d.ts.map +1 -0
  89. package/dist/getGraphQLEndpoint.js +18 -10
  90. package/dist/getGraphQLEndpoint.js.map +1 -1
  91. package/dist/getRepositoryEndpoint.cjs +27 -10
  92. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  93. package/dist/getRepositoryEndpoint.d.cts +23 -0
  94. package/dist/getRepositoryEndpoint.d.cts.map +1 -0
  95. package/dist/getRepositoryEndpoint.d.ts +5 -1
  96. package/dist/getRepositoryEndpoint.d.ts.map +1 -0
  97. package/dist/getRepositoryEndpoint.js +27 -10
  98. package/dist/getRepositoryEndpoint.js.map +1 -1
  99. package/dist/getRepositoryName.cjs +22 -14
  100. package/dist/getRepositoryName.cjs.map +1 -1
  101. package/dist/getRepositoryName.d.cts +16 -0
  102. package/dist/getRepositoryName.d.cts.map +1 -0
  103. package/dist/getRepositoryName.d.ts +5 -1
  104. package/dist/getRepositoryName.d.ts.map +1 -0
  105. package/dist/getRepositoryName.js +23 -15
  106. package/dist/getRepositoryName.js.map +1 -1
  107. package/dist/getToolbarSrc.cjs +42 -10
  108. package/dist/getToolbarSrc.cjs.map +1 -1
  109. package/dist/getToolbarSrc.d.cts +38 -0
  110. package/dist/getToolbarSrc.d.cts.map +1 -0
  111. package/dist/getToolbarSrc.d.ts +5 -1
  112. package/dist/getToolbarSrc.d.ts.map +1 -0
  113. package/dist/getToolbarSrc.js +42 -10
  114. package/dist/getToolbarSrc.js.map +1 -1
  115. package/dist/helpers/asDate.cjs +36 -11
  116. package/dist/helpers/asDate.cjs.map +1 -1
  117. package/dist/helpers/asDate.d.cts +29 -0
  118. package/dist/helpers/asDate.d.cts.map +1 -0
  119. package/dist/helpers/asDate.d.ts +9 -4
  120. package/dist/helpers/asDate.d.ts.map +1 -0
  121. package/dist/helpers/asDate.js +36 -12
  122. package/dist/helpers/asDate.js.map +1 -1
  123. package/dist/helpers/asHTML.cjs +76 -79
  124. package/dist/helpers/asHTML.cjs.map +1 -1
  125. package/dist/helpers/asHTML.d.cts +147 -0
  126. package/dist/helpers/asHTML.d.cts.map +1 -0
  127. package/dist/helpers/asHTML.d.ts +76 -78
  128. package/dist/helpers/asHTML.d.ts.map +1 -0
  129. package/dist/helpers/asHTML.js +74 -77
  130. package/dist/helpers/asHTML.js.map +1 -1
  131. package/dist/helpers/asImagePixelDensitySrcSet.cjs +57 -18
  132. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  133. package/dist/helpers/asImagePixelDensitySrcSet.d.cts +59 -0
  134. package/dist/helpers/asImagePixelDensitySrcSet.d.cts.map +1 -0
  135. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +18 -13
  136. package/dist/helpers/asImagePixelDensitySrcSet.d.ts.map +1 -0
  137. package/dist/helpers/asImagePixelDensitySrcSet.js +57 -18
  138. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  139. package/dist/helpers/asImageSrc.cjs +30 -10
  140. package/dist/helpers/asImageSrc.cjs.map +1 -1
  141. package/dist/helpers/asImageSrc.d.cts +34 -0
  142. package/dist/helpers/asImageSrc.d.cts.map +1 -0
  143. package/dist/helpers/asImageSrc.d.ts +9 -4
  144. package/dist/helpers/asImageSrc.d.ts.map +1 -0
  145. package/dist/helpers/asImageSrc.js +30 -10
  146. package/dist/helpers/asImageSrc.js.map +1 -1
  147. package/dist/helpers/asImageWidthSrcSet.cjs +76 -42
  148. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  149. package/dist/helpers/asImageWidthSrcSet.d.cts +67 -0
  150. package/dist/helpers/asImageWidthSrcSet.d.cts.map +1 -0
  151. package/dist/helpers/asImageWidthSrcSet.d.ts +19 -14
  152. package/dist/helpers/asImageWidthSrcSet.d.ts.map +1 -0
  153. package/dist/helpers/asImageWidthSrcSet.js +76 -42
  154. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  155. package/dist/helpers/asLink.cjs +26 -44
  156. package/dist/helpers/asLink.cjs.map +1 -1
  157. package/dist/helpers/asLink.d.cts +83 -0
  158. package/dist/helpers/asLink.d.cts.map +1 -0
  159. package/dist/helpers/asLink.d.ts +58 -53
  160. package/dist/helpers/asLink.d.ts.map +1 -0
  161. package/dist/helpers/asLink.js +25 -43
  162. package/dist/helpers/asLink.js.map +1 -1
  163. package/dist/helpers/asLinkAttrs.cjs +44 -25
  164. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  165. package/dist/helpers/asLinkAttrs.d.cts +51 -0
  166. package/dist/helpers/asLinkAttrs.d.cts.map +1 -0
  167. package/dist/helpers/asLinkAttrs.d.ts +23 -19
  168. package/dist/helpers/asLinkAttrs.d.ts.map +1 -0
  169. package/dist/helpers/asLinkAttrs.js +43 -24
  170. package/dist/helpers/asLinkAttrs.js.map +1 -1
  171. package/dist/helpers/asText.cjs +15 -20
  172. package/dist/helpers/asText.cjs.map +1 -1
  173. package/dist/helpers/asText.d.cts +62 -0
  174. package/dist/helpers/asText.d.cts.map +1 -0
  175. package/dist/helpers/asText.d.ts +48 -43
  176. package/dist/helpers/asText.d.ts.map +1 -0
  177. package/dist/helpers/asText.js +15 -20
  178. package/dist/helpers/asText.js.map +1 -1
  179. package/dist/helpers/documentToLinkField.cjs +30 -23
  180. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  181. package/dist/helpers/documentToLinkField.d.cts +21 -0
  182. package/dist/helpers/documentToLinkField.d.cts.map +1 -0
  183. package/dist/helpers/documentToLinkField.d.ts +8 -4
  184. package/dist/helpers/documentToLinkField.d.ts.map +1 -0
  185. package/dist/helpers/documentToLinkField.js +30 -23
  186. package/dist/helpers/documentToLinkField.js.map +1 -1
  187. package/dist/helpers/isFilled.cjs +215 -42
  188. package/dist/helpers/isFilled.cjs.map +1 -1
  189. package/dist/helpers/isFilled.d.cts +199 -0
  190. package/dist/helpers/isFilled.d.cts.map +1 -0
  191. package/dist/helpers/isFilled.d.ts +51 -43
  192. package/dist/helpers/isFilled.d.ts.map +1 -0
  193. package/dist/helpers/isFilled.js +210 -44
  194. package/dist/helpers/isFilled.js.map +1 -1
  195. package/dist/helpers/mapSliceZone.cjs +50 -39
  196. package/dist/helpers/mapSliceZone.cjs.map +1 -1
  197. package/dist/helpers/mapSliceZone.d.cts +139 -0
  198. package/dist/helpers/mapSliceZone.d.cts.map +1 -0
  199. package/dist/helpers/mapSliceZone.d.ts +37 -34
  200. package/dist/helpers/mapSliceZone.d.ts.map +1 -0
  201. package/dist/helpers/mapSliceZone.js +50 -40
  202. package/dist/helpers/mapSliceZone.js.map +1 -1
  203. package/dist/index.cjs +109 -96
  204. package/dist/index.cjs.map +1 -1
  205. package/dist/index.d.cts +173 -0
  206. package/dist/index.d.cts.map +1 -0
  207. package/dist/index.d.ts +142 -173
  208. package/dist/index.d.ts.map +1 -0
  209. package/dist/index.js +31 -75
  210. package/dist/index.js.map +1 -1
  211. package/dist/isRepositoryEndpoint.cjs +20 -9
  212. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  213. package/dist/isRepositoryEndpoint.d.cts +14 -0
  214. package/dist/isRepositoryEndpoint.d.cts.map +1 -0
  215. package/dist/isRepositoryEndpoint.d.ts +5 -1
  216. package/dist/isRepositoryEndpoint.d.ts.map +1 -0
  217. package/dist/isRepositoryEndpoint.js +20 -10
  218. package/dist/isRepositoryEndpoint.js.map +1 -1
  219. package/dist/isRepositoryName.cjs +14 -4
  220. package/dist/isRepositoryName.cjs.map +1 -1
  221. package/dist/isRepositoryName.d.cts +13 -0
  222. package/dist/isRepositoryName.d.cts.map +1 -0
  223. package/dist/isRepositoryName.d.ts +5 -1
  224. package/dist/isRepositoryName.d.ts.map +1 -0
  225. package/dist/isRepositoryName.js +14 -5
  226. package/dist/isRepositoryName.js.map +1 -1
  227. package/dist/lib/devMsg.cjs +22 -5
  228. package/dist/lib/devMsg.cjs.map +1 -1
  229. package/dist/lib/devMsg.js +23 -6
  230. package/dist/lib/devMsg.js.map +1 -1
  231. package/dist/lib/escapeHTML.cjs +36 -39
  232. package/dist/lib/escapeHTML.cjs.map +1 -1
  233. package/dist/lib/escapeHTML.js +36 -40
  234. package/dist/lib/escapeHTML.js.map +1 -1
  235. package/dist/lib/getOptionalLinkProperties.cjs +19 -11
  236. package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
  237. package/dist/lib/getOptionalLinkProperties.js +19 -12
  238. package/dist/lib/getOptionalLinkProperties.js.map +1 -1
  239. package/dist/lib/getPreviewCookie.cjs +25 -16
  240. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  241. package/dist/lib/getPreviewCookie.js +25 -16
  242. package/dist/lib/getPreviewCookie.js.map +1 -1
  243. package/dist/lib/isInternalURL.cjs +15 -6
  244. package/dist/lib/isInternalURL.cjs.map +1 -1
  245. package/dist/lib/isInternalURL.js +15 -7
  246. package/dist/lib/isInternalURL.js.map +1 -1
  247. package/dist/lib/isMigrationValue.cjs +65 -12
  248. package/dist/lib/isMigrationValue.cjs.map +1 -1
  249. package/dist/lib/isMigrationValue.js +63 -13
  250. package/dist/lib/isMigrationValue.js.map +1 -1
  251. package/dist/lib/isValue.cjs +93 -36
  252. package/dist/lib/isValue.cjs.map +1 -1
  253. package/dist/lib/isValue.js +93 -40
  254. package/dist/lib/isValue.js.map +1 -1
  255. package/dist/lib/pLimit.cjs +51 -44
  256. package/dist/lib/pLimit.cjs.map +1 -1
  257. package/dist/lib/pLimit.js +51 -45
  258. package/dist/lib/pLimit.js.map +1 -1
  259. package/dist/lib/request.cjs +54 -35
  260. package/dist/lib/request.cjs.map +1 -1
  261. package/dist/lib/request.d.cts +61 -0
  262. package/dist/lib/request.d.cts.map +1 -0
  263. package/dist/lib/request.d.ts +38 -50
  264. package/dist/lib/request.d.ts.map +1 -0
  265. package/dist/lib/request.js +54 -35
  266. package/dist/lib/request.js.map +1 -1
  267. package/dist/lib/resolveMigrationDocumentData.cjs +147 -123
  268. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
  269. package/dist/lib/resolveMigrationDocumentData.js +143 -120
  270. package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
  271. package/dist/lib/serializerHelpers.cjs +73 -91
  272. package/dist/lib/serializerHelpers.cjs.map +1 -1
  273. package/dist/lib/serializerHelpers.js +71 -94
  274. package/dist/lib/serializerHelpers.js.map +1 -1
  275. package/dist/lib/throttledWarn.cjs +27 -0
  276. package/dist/lib/throttledWarn.cjs.map +1 -0
  277. package/dist/lib/throttledWarn.js +26 -0
  278. package/dist/lib/throttledWarn.js.map +1 -0
  279. package/dist/lib/validateAssetMetadata.cjs +40 -20
  280. package/dist/lib/validateAssetMetadata.cjs.map +1 -1
  281. package/dist/lib/validateAssetMetadata.js +41 -21
  282. package/dist/lib/validateAssetMetadata.js.map +1 -1
  283. package/dist/package.cjs +19 -0
  284. package/dist/package.cjs.map +1 -0
  285. package/dist/package.js +7 -0
  286. package/dist/package.js.map +1 -0
  287. package/dist/richtext/asText.cjs +18 -10
  288. package/dist/richtext/asText.cjs.map +1 -1
  289. package/dist/richtext/asText.d.cts +18 -0
  290. package/dist/richtext/asText.d.cts.map +1 -0
  291. package/dist/richtext/asText.d.ts +8 -2
  292. package/dist/richtext/asText.d.ts.map +1 -0
  293. package/dist/richtext/asText.js +18 -11
  294. package/dist/richtext/asText.js.map +1 -1
  295. package/dist/richtext/asTree.cjs +106 -107
  296. package/dist/richtext/asTree.cjs.map +1 -1
  297. package/dist/richtext/asTree.d.cts +20 -0
  298. package/dist/richtext/asTree.d.cts.map +1 -0
  299. package/dist/richtext/asTree.d.ts +9 -3
  300. package/dist/richtext/asTree.d.ts.map +1 -0
  301. package/dist/richtext/asTree.js +106 -107
  302. package/dist/richtext/asTree.js.map +1 -1
  303. package/dist/richtext/composeSerializers.cjs +28 -14
  304. package/dist/richtext/composeSerializers.cjs.map +1 -1
  305. package/dist/richtext/composeSerializers.d.cts +22 -0
  306. package/dist/richtext/composeSerializers.d.cts.map +1 -0
  307. package/dist/richtext/composeSerializers.d.ts +8 -2
  308. package/dist/richtext/composeSerializers.d.ts.map +1 -0
  309. package/dist/richtext/composeSerializers.js +28 -15
  310. package/dist/richtext/composeSerializers.js.map +1 -1
  311. package/dist/richtext/serialize.cjs +30 -14
  312. package/dist/richtext/serialize.cjs.map +1 -1
  313. package/dist/richtext/serialize.d.cts +25 -0
  314. package/dist/richtext/serialize.d.cts.map +1 -0
  315. package/dist/richtext/serialize.d.ts +9 -3
  316. package/dist/richtext/serialize.d.ts.map +1 -0
  317. package/dist/richtext/serialize.js +30 -14
  318. package/dist/richtext/serialize.js.map +1 -1
  319. package/dist/richtext/types.cjs +10 -8
  320. package/dist/richtext/types.cjs.map +1 -1
  321. package/dist/richtext/types.d.cts +71 -0
  322. package/dist/richtext/types.d.cts.map +1 -0
  323. package/dist/richtext/types.d.ts +43 -43
  324. package/dist/richtext/types.d.ts.map +1 -0
  325. package/dist/richtext/types.js +10 -8
  326. package/dist/richtext/types.js.map +1 -1
  327. package/dist/richtext/wrapMapSerializer.cjs +29 -21
  328. package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
  329. package/dist/richtext/wrapMapSerializer.d.cts +21 -0
  330. package/dist/richtext/wrapMapSerializer.d.cts.map +1 -0
  331. package/dist/richtext/wrapMapSerializer.d.ts +8 -2
  332. package/dist/richtext/wrapMapSerializer.d.ts.map +1 -0
  333. package/dist/richtext/wrapMapSerializer.js +29 -21
  334. package/dist/richtext/wrapMapSerializer.js.map +1 -1
  335. package/dist/richtext.cjs +13 -15
  336. package/dist/richtext.d.cts +8 -0
  337. package/dist/richtext.d.ts +8 -0
  338. package/dist/richtext.js +4 -11
  339. package/dist/types/api/asset/asset.d.cts +97 -0
  340. package/dist/types/api/asset/asset.d.cts.map +1 -0
  341. package/dist/types/api/asset/asset.d.ts +87 -167
  342. package/dist/types/api/asset/asset.d.ts.map +1 -0
  343. package/dist/types/api/asset/tag.d.cts +35 -0
  344. package/dist/types/api/asset/tag.d.cts.map +1 -0
  345. package/dist/types/api/asset/tag.d.ts +29 -47
  346. package/dist/types/api/asset/tag.d.ts.map +1 -0
  347. package/dist/types/api/integration.d.cts +34 -0
  348. package/dist/types/api/integration.d.cts.map +1 -0
  349. package/dist/types/api/integration.d.ts +17 -11
  350. package/dist/types/api/integration.d.ts.map +1 -0
  351. package/dist/types/api/query.d.cts +49 -0
  352. package/dist/types/api/query.d.cts.map +1 -0
  353. package/dist/types/api/query.d.ts +40 -34
  354. package/dist/types/api/query.d.ts.map +1 -0
  355. package/dist/types/api/ref.d.cts +36 -0
  356. package/dist/types/api/ref.d.cts.map +1 -0
  357. package/dist/types/api/ref.d.ts +30 -26
  358. package/dist/types/api/ref.d.ts.map +1 -0
  359. package/dist/types/api/release.d.cts +17 -0
  360. package/dist/types/api/release.d.cts.map +1 -0
  361. package/dist/types/api/release.d.ts +8 -2
  362. package/dist/types/api/release.d.ts.map +1 -0
  363. package/dist/types/api/repository.d.cts +115 -0
  364. package/dist/types/api/repository.d.cts.map +1 -0
  365. package/dist/types/api/repository.d.ts +90 -84
  366. package/dist/types/api/repository.d.ts.map +1 -0
  367. package/dist/types/api/tags.d.cts +13 -0
  368. package/dist/types/api/tags.d.cts.map +1 -0
  369. package/dist/types/api/tags.d.ts +5 -1
  370. package/dist/types/api/tags.d.ts.map +1 -0
  371. package/dist/types/migration/Asset.cjs +34 -29
  372. package/dist/types/migration/Asset.cjs.map +1 -1
  373. package/dist/types/migration/Asset.d.cts +109 -0
  374. package/dist/types/migration/Asset.d.cts.map +1 -0
  375. package/dist/types/migration/Asset.d.ts +89 -88
  376. package/dist/types/migration/Asset.d.ts.map +1 -0
  377. package/dist/types/migration/Asset.js +33 -29
  378. package/dist/types/migration/Asset.js.map +1 -1
  379. package/dist/types/migration/ContentRelationship.d.cts +15 -0
  380. package/dist/types/migration/ContentRelationship.d.cts.map +1 -0
  381. package/dist/types/migration/ContentRelationship.d.ts +10 -11
  382. package/dist/types/migration/ContentRelationship.d.ts.map +1 -0
  383. package/dist/types/migration/Document.cjs +50 -43
  384. package/dist/types/migration/Document.cjs.map +1 -1
  385. package/dist/types/migration/Document.d.cts +97 -0
  386. package/dist/types/migration/Document.d.cts.map +1 -0
  387. package/dist/types/migration/Document.d.ts +62 -59
  388. package/dist/types/migration/Document.d.ts.map +1 -0
  389. package/dist/types/migration/Document.js +49 -43
  390. package/dist/types/migration/Document.js.map +1 -1
  391. package/dist/types/model/boolean.d.cts +21 -0
  392. package/dist/types/model/boolean.d.cts.map +1 -0
  393. package/dist/types/model/boolean.d.ts +15 -9
  394. package/dist/types/model/boolean.d.ts.map +1 -0
  395. package/dist/types/model/color.d.cts +19 -0
  396. package/dist/types/model/color.d.cts.map +1 -0
  397. package/dist/types/model/color.d.ts +13 -7
  398. package/dist/types/model/color.d.ts.map +1 -0
  399. package/dist/types/model/contentRelationship.d.cts +59 -0
  400. package/dist/types/model/contentRelationship.d.cts.map +1 -0
  401. package/dist/types/model/contentRelationship.d.ts +33 -27
  402. package/dist/types/model/contentRelationship.d.ts.map +1 -0
  403. package/dist/types/model/customType.d.cts +54 -0
  404. package/dist/types/model/customType.d.cts.map +1 -0
  405. package/dist/types/model/customType.d.ts +36 -30
  406. package/dist/types/model/customType.d.ts.map +1 -0
  407. package/dist/types/model/date.d.cts +20 -0
  408. package/dist/types/model/date.d.cts.map +1 -0
  409. package/dist/types/model/date.d.ts +14 -8
  410. package/dist/types/model/date.d.ts.map +1 -0
  411. package/dist/types/model/embed.d.cts +19 -0
  412. package/dist/types/model/embed.d.cts.map +1 -0
  413. package/dist/types/model/embed.d.ts +13 -7
  414. package/dist/types/model/embed.d.ts.map +1 -0
  415. package/dist/types/model/geoPoint.d.cts +18 -0
  416. package/dist/types/model/geoPoint.d.cts.map +1 -0
  417. package/dist/types/model/geoPoint.d.ts +12 -6
  418. package/dist/types/model/geoPoint.d.ts.map +1 -0
  419. package/dist/types/model/group.d.cts +29 -0
  420. package/dist/types/model/group.d.cts.map +1 -0
  421. package/dist/types/model/group.d.ts +14 -8
  422. package/dist/types/model/group.d.ts.map +1 -0
  423. package/dist/types/model/image.d.cts +37 -0
  424. package/dist/types/model/image.d.cts.map +1 -0
  425. package/dist/types/model/image.d.ts +19 -13
  426. package/dist/types/model/image.d.ts.map +1 -0
  427. package/dist/types/model/integration.d.cts +20 -0
  428. package/dist/types/model/integration.d.cts.map +1 -0
  429. package/dist/types/model/integration.d.ts +14 -8
  430. package/dist/types/model/integration.d.ts.map +1 -0
  431. package/dist/types/model/keyText.d.cts +19 -0
  432. package/dist/types/model/keyText.d.cts.map +1 -0
  433. package/dist/types/model/keyText.d.ts +13 -7
  434. package/dist/types/model/keyText.d.ts.map +1 -0
  435. package/dist/types/model/link.cjs +13 -6
  436. package/dist/types/model/link.cjs.map +1 -1
  437. package/dist/types/model/link.d.cts +34 -0
  438. package/dist/types/model/link.d.cts.map +1 -0
  439. package/dist/types/model/link.d.ts +22 -16
  440. package/dist/types/model/link.d.ts.map +1 -0
  441. package/dist/types/model/link.js +13 -7
  442. package/dist/types/model/link.js.map +1 -1
  443. package/dist/types/model/linkToMedia.d.cts +23 -0
  444. package/dist/types/model/linkToMedia.d.cts.map +1 -0
  445. package/dist/types/model/linkToMedia.d.ts +17 -11
  446. package/dist/types/model/linkToMedia.d.ts.map +1 -0
  447. package/dist/types/model/number.d.cts +21 -0
  448. package/dist/types/model/number.d.cts.map +1 -0
  449. package/dist/types/model/number.d.ts +15 -9
  450. package/dist/types/model/number.d.ts.map +1 -0
  451. package/dist/types/model/range.d.cts +20 -0
  452. package/dist/types/model/range.d.cts.map +1 -0
  453. package/dist/types/model/range.d.ts +16 -10
  454. package/dist/types/model/range.d.ts.map +1 -0
  455. package/dist/types/model/richText.d.cts +43 -0
  456. package/dist/types/model/richText.d.cts.map +1 -0
  457. package/dist/types/model/richText.d.ts +26 -20
  458. package/dist/types/model/richText.d.ts.map +1 -0
  459. package/dist/types/model/select.d.cts +24 -0
  460. package/dist/types/model/select.d.cts.map +1 -0
  461. package/dist/types/model/select.d.ts +15 -9
  462. package/dist/types/model/select.d.ts.map +1 -0
  463. package/dist/types/model/separator.d.cts +16 -0
  464. package/dist/types/model/separator.d.cts.map +1 -0
  465. package/dist/types/model/separator.d.ts +12 -6
  466. package/dist/types/model/separator.d.ts.map +1 -0
  467. package/dist/types/model/sharedSlice.d.cts +22 -0
  468. package/dist/types/model/sharedSlice.d.cts.map +1 -0
  469. package/dist/types/model/sharedSlice.d.ts +14 -8
  470. package/dist/types/model/sharedSlice.d.ts.map +1 -0
  471. package/dist/types/model/sharedSliceVariation.d.cts +25 -0
  472. package/dist/types/model/sharedSliceVariation.d.cts.map +1 -0
  473. package/dist/types/model/sharedSliceVariation.d.ts +16 -10
  474. package/dist/types/model/sharedSliceVariation.d.ts.map +1 -0
  475. package/dist/types/model/slice.cjs +12 -5
  476. package/dist/types/model/slice.cjs.map +1 -1
  477. package/dist/types/model/slice.d.cts +39 -0
  478. package/dist/types/model/slice.d.cts.map +1 -0
  479. package/dist/types/model/slice.d.ts +21 -15
  480. package/dist/types/model/slice.d.ts.map +1 -0
  481. package/dist/types/model/slice.js +12 -6
  482. package/dist/types/model/slice.js.map +1 -1
  483. package/dist/types/model/sliceZone.cjs +12 -5
  484. package/dist/types/model/sliceZone.cjs.map +1 -1
  485. package/dist/types/model/sliceZone.d.cts +47 -0
  486. package/dist/types/model/sliceZone.d.cts.map +1 -0
  487. package/dist/types/model/sliceZone.d.ts +23 -17
  488. package/dist/types/model/sliceZone.d.ts.map +1 -0
  489. package/dist/types/model/sliceZone.js +12 -6
  490. package/dist/types/model/sliceZone.js.map +1 -1
  491. package/dist/types/model/table.d.cts +18 -0
  492. package/dist/types/model/table.d.cts.map +1 -0
  493. package/dist/types/model/table.d.ts +12 -6
  494. package/dist/types/model/table.d.ts.map +1 -0
  495. package/dist/types/model/timestamp.d.cts +20 -0
  496. package/dist/types/model/timestamp.d.cts.map +1 -0
  497. package/dist/types/model/timestamp.d.ts +14 -8
  498. package/dist/types/model/timestamp.d.ts.map +1 -0
  499. package/dist/types/model/title.d.cts +13 -0
  500. package/dist/types/model/title.d.cts.map +1 -0
  501. package/dist/types/model/title.d.ts +8 -2
  502. package/dist/types/model/title.d.ts.map +1 -0
  503. package/dist/types/model/types.cjs +29 -36
  504. package/dist/types/model/types.cjs.map +1 -1
  505. package/dist/types/model/types.d.cts +82 -0
  506. package/dist/types/model/types.d.cts.map +1 -0
  507. package/dist/types/model/types.d.ts +66 -60
  508. package/dist/types/model/types.d.ts.map +1 -0
  509. package/dist/types/model/types.js +29 -37
  510. package/dist/types/model/types.js.map +1 -1
  511. package/dist/types/model/uid.d.cts +19 -0
  512. package/dist/types/model/uid.d.cts.map +1 -0
  513. package/dist/types/model/uid.d.ts +13 -7
  514. package/dist/types/model/uid.d.ts.map +1 -0
  515. package/dist/types/value/boolean.d.cts +10 -0
  516. package/dist/types/value/boolean.d.cts.map +1 -0
  517. package/dist/types/value/boolean.d.ts +5 -1
  518. package/dist/types/value/boolean.d.ts.map +1 -0
  519. package/dist/types/value/color.d.cts +15 -0
  520. package/dist/types/value/color.d.cts.map +1 -0
  521. package/dist/types/value/color.d.ts +8 -2
  522. package/dist/types/value/color.d.ts.map +1 -0
  523. package/dist/types/value/contentRelationship.d.cts +37 -0
  524. package/dist/types/value/contentRelationship.d.cts.map +1 -0
  525. package/dist/types/value/contentRelationship.d.ts +23 -17
  526. package/dist/types/value/contentRelationship.d.ts.map +1 -0
  527. package/dist/types/value/date.d.cts +15 -0
  528. package/dist/types/value/date.d.cts.map +1 -0
  529. package/dist/types/value/date.d.ts +8 -2
  530. package/dist/types/value/date.d.ts.map +1 -0
  531. package/dist/types/value/document.d.cts +120 -0
  532. package/dist/types/value/document.d.cts.map +1 -0
  533. package/dist/types/value/document.d.ts +90 -84
  534. package/dist/types/value/document.d.ts.map +1 -0
  535. package/dist/types/value/embed.cjs +14 -7
  536. package/dist/types/value/embed.cjs.map +1 -1
  537. package/dist/types/value/embed.d.cts +173 -0
  538. package/dist/types/value/embed.d.cts.map +1 -0
  539. package/dist/types/value/embed.d.ts +110 -105
  540. package/dist/types/value/embed.d.ts.map +1 -0
  541. package/dist/types/value/embed.js +14 -8
  542. package/dist/types/value/embed.js.map +1 -1
  543. package/dist/types/value/geoPoint.d.cts +18 -0
  544. package/dist/types/value/geoPoint.d.cts.map +1 -0
  545. package/dist/types/value/geoPoint.d.ts +10 -4
  546. package/dist/types/value/geoPoint.d.ts.map +1 -0
  547. package/dist/types/value/group.d.cts +19 -0
  548. package/dist/types/value/group.d.cts.map +1 -0
  549. package/dist/types/value/group.d.ts +9 -3
  550. package/dist/types/value/group.d.ts.map +1 -0
  551. package/dist/types/value/image.d.cts +53 -0
  552. package/dist/types/value/image.d.cts.map +1 -0
  553. package/dist/types/value/image.d.ts +31 -25
  554. package/dist/types/value/image.d.ts.map +1 -0
  555. package/dist/types/value/integration.d.cts +22 -0
  556. package/dist/types/value/integration.d.cts.map +1 -0
  557. package/dist/types/value/integration.d.ts +9 -3
  558. package/dist/types/value/integration.d.ts.map +1 -0
  559. package/dist/types/value/keyText.d.cts +15 -0
  560. package/dist/types/value/keyText.d.cts.map +1 -0
  561. package/dist/types/value/keyText.d.ts +8 -2
  562. package/dist/types/value/keyText.d.ts.map +1 -0
  563. package/dist/types/value/link.cjs +12 -7
  564. package/dist/types/value/link.cjs.map +1 -1
  565. package/dist/types/value/link.d.cts +74 -0
  566. package/dist/types/value/link.d.cts.map +1 -0
  567. package/dist/types/value/link.d.ts +27 -21
  568. package/dist/types/value/link.d.ts.map +1 -0
  569. package/dist/types/value/link.js +12 -8
  570. package/dist/types/value/link.js.map +1 -1
  571. package/dist/types/value/linkToMedia.d.cts +33 -0
  572. package/dist/types/value/linkToMedia.d.cts.map +1 -0
  573. package/dist/types/value/linkToMedia.d.ts +19 -14
  574. package/dist/types/value/linkToMedia.d.ts.map +1 -0
  575. package/dist/types/value/number.d.cts +15 -0
  576. package/dist/types/value/number.d.cts.map +1 -0
  577. package/dist/types/value/number.d.ts +8 -2
  578. package/dist/types/value/number.d.ts.map +1 -0
  579. package/dist/types/value/richText.cjs +29 -22
  580. package/dist/types/value/richText.cjs.map +1 -1
  581. package/dist/types/value/richText.d.cts +221 -0
  582. package/dist/types/value/richText.d.cts.map +1 -0
  583. package/dist/types/value/richText.d.ts +103 -97
  584. package/dist/types/value/richText.d.ts.map +1 -0
  585. package/dist/types/value/richText.js +29 -23
  586. package/dist/types/value/richText.js.map +1 -1
  587. package/dist/types/value/select.d.cts +16 -0
  588. package/dist/types/value/select.d.cts.map +1 -0
  589. package/dist/types/value/select.d.ts +8 -2
  590. package/dist/types/value/select.d.ts.map +1 -0
  591. package/dist/types/value/sharedSlice.d.cts +17 -0
  592. package/dist/types/value/sharedSlice.d.cts.map +1 -0
  593. package/dist/types/value/sharedSlice.d.ts +11 -5
  594. package/dist/types/value/sharedSlice.d.ts.map +1 -0
  595. package/dist/types/value/sharedSliceVariation.d.cts +16 -0
  596. package/dist/types/value/sharedSliceVariation.d.cts.map +1 -0
  597. package/dist/types/value/sharedSliceVariation.d.ts +12 -6
  598. package/dist/types/value/sharedSliceVariation.d.ts.map +1 -0
  599. package/dist/types/value/slice.d.cts +19 -0
  600. package/dist/types/value/slice.d.cts.map +1 -0
  601. package/dist/types/value/slice.d.ts +13 -7
  602. package/dist/types/value/slice.d.ts.map +1 -0
  603. package/dist/types/value/sliceZone.d.cts +18 -0
  604. package/dist/types/value/sliceZone.d.cts.map +1 -0
  605. package/dist/types/value/sliceZone.d.ts +10 -4
  606. package/dist/types/value/sliceZone.d.ts.map +1 -0
  607. package/dist/types/value/table.d.cts +97 -0
  608. package/dist/types/value/table.d.cts.map +1 -0
  609. package/dist/types/value/table.d.ts +65 -59
  610. package/dist/types/value/table.d.ts.map +1 -0
  611. package/dist/types/value/timestamp.d.cts +13 -0
  612. package/dist/types/value/timestamp.d.cts.map +1 -0
  613. package/dist/types/value/timestamp.d.ts +8 -3
  614. package/dist/types/value/timestamp.d.ts.map +1 -0
  615. package/dist/types/value/title.d.cts +16 -0
  616. package/dist/types/value/title.d.cts.map +1 -0
  617. package/dist/types/value/title.d.ts +11 -7
  618. package/dist/types/value/title.d.ts.map +1 -0
  619. package/dist/types/value/types.d.cts +61 -0
  620. package/dist/types/value/types.d.cts.map +1 -0
  621. package/dist/types/value/types.d.ts +31 -28
  622. package/dist/types/value/types.d.ts.map +1 -0
  623. package/dist/types/webhook/apiUpdate.d.cts +57 -0
  624. package/dist/types/webhook/apiUpdate.d.cts.map +1 -0
  625. package/dist/types/webhook/apiUpdate.d.ts +28 -23
  626. package/dist/types/webhook/apiUpdate.d.ts.map +1 -0
  627. package/dist/types/webhook/testTrigger.d.cts +15 -0
  628. package/dist/types/webhook/testTrigger.d.cts.map +1 -0
  629. package/dist/types/webhook/testTrigger.d.ts +9 -3
  630. package/dist/types/webhook/testTrigger.d.ts.map +1 -0
  631. package/dist/types/webhook/types.cjs +12 -5
  632. package/dist/types/webhook/types.cjs.map +1 -1
  633. package/dist/types/webhook/types.d.cts +23 -0
  634. package/dist/types/webhook/types.d.cts.map +1 -0
  635. package/dist/types/webhook/types.d.ts +16 -11
  636. package/dist/types/webhook/types.d.ts.map +1 -0
  637. package/dist/types/webhook/types.js +12 -6
  638. package/dist/types/webhook/types.js.map +1 -1
  639. package/package.json +16 -45
  640. package/src/Client.ts +682 -1028
  641. package/src/WriteClient.ts +23 -14
  642. package/src/buildQueryURL.ts +14 -20
  643. package/src/createClient.ts +1 -1
  644. package/src/errors.ts +94 -0
  645. package/src/filter.ts +1 -1
  646. package/src/getGraphQLEndpoint.ts +1 -1
  647. package/src/getRepositoryEndpoint.ts +1 -1
  648. package/src/getRepositoryName.ts +1 -1
  649. package/src/getToolbarSrc.ts +1 -1
  650. package/src/helpers/asHTML.ts +4 -4
  651. package/src/helpers/asImageWidthSrcSet.ts +1 -5
  652. package/src/helpers/asLink.ts +0 -3
  653. package/src/helpers/asLinkAttrs.ts +0 -4
  654. package/src/helpers/mapSliceZone.ts +5 -5
  655. package/src/index.ts +11 -9
  656. package/src/lib/isValue.ts +0 -6
  657. package/src/lib/pLimit.ts +1 -1
  658. package/src/lib/request.ts +3 -3
  659. package/src/lib/{throttledLog.ts → throttledWarn.ts} +3 -14
  660. package/src/lib/validateAssetMetadata.ts +1 -1
  661. package/src/types/migration/Document.ts +1 -1
  662. package/src/types/value/date.ts +1 -1
  663. package/src/types/value/document.ts +3 -3
  664. package/src/types/value/timestamp.ts +1 -5
  665. package/dist/errors/ForbiddenError.cjs +0 -7
  666. package/dist/errors/ForbiddenError.cjs.map +0 -1
  667. package/dist/errors/ForbiddenError.d.ts +0 -11
  668. package/dist/errors/ForbiddenError.js +0 -7
  669. package/dist/errors/ForbiddenError.js.map +0 -1
  670. package/dist/errors/InvalidDataError.cjs +0 -7
  671. package/dist/errors/InvalidDataError.cjs.map +0 -1
  672. package/dist/errors/InvalidDataError.d.ts +0 -3
  673. package/dist/errors/InvalidDataError.js +0 -7
  674. package/dist/errors/InvalidDataError.js.map +0 -1
  675. package/dist/errors/NotFoundError.cjs +0 -7
  676. package/dist/errors/NotFoundError.cjs.map +0 -1
  677. package/dist/errors/NotFoundError.d.ts +0 -3
  678. package/dist/errors/NotFoundError.js +0 -7
  679. package/dist/errors/NotFoundError.js.map +0 -1
  680. package/dist/errors/ParsingError.cjs +0 -7
  681. package/dist/errors/ParsingError.cjs.map +0 -1
  682. package/dist/errors/ParsingError.d.ts +0 -14
  683. package/dist/errors/ParsingError.js +0 -7
  684. package/dist/errors/ParsingError.js.map +0 -1
  685. package/dist/errors/PreviewTokenExpired.cjs +0 -7
  686. package/dist/errors/PreviewTokenExpired.cjs.map +0 -1
  687. package/dist/errors/PreviewTokenExpired.d.ts +0 -8
  688. package/dist/errors/PreviewTokenExpired.js +0 -7
  689. package/dist/errors/PreviewTokenExpired.js.map +0 -1
  690. package/dist/errors/PrismicError.cjs +0 -13
  691. package/dist/errors/PrismicError.cjs.map +0 -1
  692. package/dist/errors/PrismicError.d.ts +0 -5
  693. package/dist/errors/PrismicError.js +0 -13
  694. package/dist/errors/PrismicError.js.map +0 -1
  695. package/dist/errors/RefExpiredError.cjs +0 -7
  696. package/dist/errors/RefExpiredError.cjs.map +0 -1
  697. package/dist/errors/RefExpiredError.d.ts +0 -8
  698. package/dist/errors/RefExpiredError.js +0 -7
  699. package/dist/errors/RefExpiredError.js.map +0 -1
  700. package/dist/errors/RefNotFoundError.cjs +0 -7
  701. package/dist/errors/RefNotFoundError.cjs.map +0 -1
  702. package/dist/errors/RefNotFoundError.d.ts +0 -8
  703. package/dist/errors/RefNotFoundError.js +0 -7
  704. package/dist/errors/RefNotFoundError.js.map +0 -1
  705. package/dist/errors/RepositoryNotFoundError.cjs +0 -7
  706. package/dist/errors/RepositoryNotFoundError.cjs.map +0 -1
  707. package/dist/errors/RepositoryNotFoundError.d.ts +0 -3
  708. package/dist/errors/RepositoryNotFoundError.js +0 -7
  709. package/dist/errors/RepositoryNotFoundError.js.map +0 -1
  710. package/dist/lib/appendFilters.cjs +0 -11
  711. package/dist/lib/appendFilters.cjs.map +0 -1
  712. package/dist/lib/appendFilters.d.ts +0 -18
  713. package/dist/lib/appendFilters.js +0 -11
  714. package/dist/lib/appendFilters.js.map +0 -1
  715. package/dist/lib/castArray.cjs +0 -7
  716. package/dist/lib/castArray.cjs.map +0 -1
  717. package/dist/lib/castArray.d.ts +0 -12
  718. package/dist/lib/castArray.js +0 -7
  719. package/dist/lib/castArray.js.map +0 -1
  720. package/dist/lib/castThunk.cjs +0 -7
  721. package/dist/lib/castThunk.cjs.map +0 -1
  722. package/dist/lib/castThunk.d.ts +0 -11
  723. package/dist/lib/castThunk.js +0 -7
  724. package/dist/lib/castThunk.js.map +0 -1
  725. package/dist/lib/devMsg.d.ts +0 -16
  726. package/dist/lib/escapeHTML.d.ts +0 -1
  727. package/dist/lib/everyTagFilter.cjs +0 -9
  728. package/dist/lib/everyTagFilter.cjs.map +0 -1
  729. package/dist/lib/everyTagFilter.d.ts +0 -9
  730. package/dist/lib/everyTagFilter.js +0 -9
  731. package/dist/lib/everyTagFilter.js.map +0 -1
  732. package/dist/lib/findMasterRef.cjs +0 -8
  733. package/dist/lib/findMasterRef.cjs.map +0 -1
  734. package/dist/lib/findMasterRef.d.ts +0 -11
  735. package/dist/lib/findMasterRef.js +0 -8
  736. package/dist/lib/findMasterRef.js.map +0 -1
  737. package/dist/lib/findRef.cjs +0 -12
  738. package/dist/lib/findRef.cjs.map +0 -1
  739. package/dist/lib/findRef.d.ts +0 -14
  740. package/dist/lib/findRef.js +0 -12
  741. package/dist/lib/findRef.js.map +0 -1
  742. package/dist/lib/findRefByID.cjs +0 -8
  743. package/dist/lib/findRefByID.cjs.map +0 -1
  744. package/dist/lib/findRefByID.d.ts +0 -12
  745. package/dist/lib/findRefByID.js +0 -8
  746. package/dist/lib/findRefByID.js.map +0 -1
  747. package/dist/lib/findRefByLabel.cjs +0 -8
  748. package/dist/lib/findRefByLabel.cjs.map +0 -1
  749. package/dist/lib/findRefByLabel.d.ts +0 -12
  750. package/dist/lib/findRefByLabel.js +0 -8
  751. package/dist/lib/findRefByLabel.js.map +0 -1
  752. package/dist/lib/getOptionalLinkProperties.d.ts +0 -12
  753. package/dist/lib/getPreviewCookie.d.ts +0 -9
  754. package/dist/lib/isInternalURL.d.ts +0 -8
  755. package/dist/lib/isMigrationValue.d.ts +0 -71
  756. package/dist/lib/isValue.d.ts +0 -78
  757. package/dist/lib/minifyGraphQLQuery.cjs +0 -7
  758. package/dist/lib/minifyGraphQLQuery.cjs.map +0 -1
  759. package/dist/lib/minifyGraphQLQuery.d.ts +0 -8
  760. package/dist/lib/minifyGraphQLQuery.js +0 -7
  761. package/dist/lib/minifyGraphQLQuery.js.map +0 -1
  762. package/dist/lib/pLimit.d.ts +0 -22
  763. package/dist/lib/resolveMigrationDocumentData.d.ts +0 -54
  764. package/dist/lib/serializerHelpers.d.ts +0 -9
  765. package/dist/lib/someTagsFilter.cjs +0 -9
  766. package/dist/lib/someTagsFilter.cjs.map +0 -1
  767. package/dist/lib/someTagsFilter.d.ts +0 -9
  768. package/dist/lib/someTagsFilter.js +0 -9
  769. package/dist/lib/someTagsFilter.js.map +0 -1
  770. package/dist/lib/throttledLog.cjs +0 -17
  771. package/dist/lib/throttledLog.cjs.map +0 -1
  772. package/dist/lib/throttledLog.d.ts +0 -15
  773. package/dist/lib/throttledLog.js +0 -17
  774. package/dist/lib/throttledLog.js.map +0 -1
  775. package/dist/lib/typeFilter.cjs +0 -8
  776. package/dist/lib/typeFilter.cjs.map +0 -1
  777. package/dist/lib/typeFilter.d.ts +0 -8
  778. package/dist/lib/typeFilter.js +0 -8
  779. package/dist/lib/typeFilter.js.map +0 -1
  780. package/dist/lib/validateAssetMetadata.d.ts +0 -10
  781. package/dist/package.json.cjs +0 -7
  782. package/dist/package.json.cjs.map +0 -1
  783. package/dist/package.json.js +0 -7
  784. package/dist/package.json.js.map +0 -1
  785. package/dist/richtext/index.d.ts +0 -7
  786. package/dist/richtext.cjs.map +0 -1
  787. package/dist/richtext.js.map +0 -1
  788. package/dist/types/api/migration/document.d.ts +0 -60
  789. package/dist/types/migration/Link.d.ts +0 -19
  790. package/src/errors/ForbiddenError.ts +0 -16
  791. package/src/errors/InvalidDataError.ts +0 -5
  792. package/src/errors/NotFoundError.ts +0 -5
  793. package/src/errors/ParsingError.ts +0 -16
  794. package/src/errors/PreviewTokenExpired.ts +0 -12
  795. package/src/errors/PrismicError.ts +0 -15
  796. package/src/errors/RefExpiredError.ts +0 -14
  797. package/src/errors/RefNotFoundError.ts +0 -14
  798. package/src/errors/RepositoryNotFoundError.ts +0 -5
  799. package/src/lib/appendFilters.ts +0 -26
  800. package/src/lib/castArray.ts +0 -14
  801. package/src/lib/castThunk.ts +0 -13
  802. package/src/lib/everyTagFilter.ts +0 -15
  803. package/src/lib/findMasterRef.ts +0 -16
  804. package/src/lib/findRef.ts +0 -25
  805. package/src/lib/findRefByID.ts +0 -17
  806. package/src/lib/findRefByLabel.ts +0 -17
  807. package/src/lib/minifyGraphQLQuery.ts +0 -13
  808. package/src/lib/someTagsFilter.ts +0 -15
  809. package/src/lib/typeFilter.ts +0 -12
package/src/Client.ts CHANGED
@@ -1,12 +1,5 @@
1
- import { appendFilters } from "./lib/appendFilters"
2
- import { castThunk } from "./lib/castThunk"
3
1
  import { devMsg } from "./lib/devMsg"
4
- import { everyTagFilter } from "./lib/everyTagFilter"
5
- import { findMasterRef } from "./lib/findMasterRef"
6
- import { findRefByID } from "./lib/findRefByID"
7
- import { findRefByLabel } from "./lib/findRefByLabel"
8
2
  import { getPreviewCookie } from "./lib/getPreviewCookie"
9
- import { minifyGraphQLQuery } from "./lib/minifyGraphQLQuery"
10
3
  import type { ResponseLike } from "./lib/request"
11
4
  import {
12
5
  type AbortSignalLike,
@@ -14,71 +7,40 @@ import {
14
7
  type RequestInitLike,
15
8
  request,
16
9
  } from "./lib/request"
17
- import { someTagsFilter } from "./lib/someTagsFilter"
18
- import { throttledLog } from "./lib/throttledLog"
19
- import { typeFilter } from "./lib/typeFilter"
10
+ import { throttledWarn } from "./lib/throttledWarn"
20
11
 
21
12
  import type { Query } from "./types/api/query"
22
13
  import type { Ref } from "./types/api/ref"
23
14
  import type { Repository } from "./types/api/repository"
24
15
  import type { PrismicDocument } from "./types/value/document"
25
16
 
26
- import { ForbiddenError } from "./errors/ForbiddenError"
27
- import { NotFoundError } from "./errors/NotFoundError"
28
- import { ParsingError } from "./errors/ParsingError"
29
- import { PreviewTokenExpiredError } from "./errors/PreviewTokenExpired"
30
- import { PrismicError } from "./errors/PrismicError"
31
- import { RefExpiredError } from "./errors/RefExpiredError"
32
- import { RefNotFoundError } from "./errors/RefNotFoundError"
33
- import { RepositoryNotFoundError } from "./errors/RepositoryNotFoundError"
34
-
35
- import type { LinkResolverFunction } from "./helpers/asLink"
36
- import { asLink } from "./helpers/asLink"
37
-
38
- import type { BuildQueryURLArgs } from "./buildQueryURL"
39
- import { buildQueryURL } from "./buildQueryURL"
17
+ import {
18
+ ForbiddenError,
19
+ NotFoundError,
20
+ ParsingError,
21
+ PreviewTokenExpiredError,
22
+ PrismicError,
23
+ RefExpiredError,
24
+ RefNotFoundError,
25
+ RepositoryNotFoundError,
26
+ } from "./errors"
27
+
28
+ import { type LinkResolverFunction, asLink } from "./helpers/asLink"
29
+
30
+ import { type BuildQueryURLArgs, buildQueryURL } from "./buildQueryURL"
40
31
  import { filter } from "./filter"
41
32
  import { getRepositoryEndpoint } from "./getRepositoryEndpoint"
42
33
  import { getRepositoryName } from "./getRepositoryName"
43
34
  import { isRepositoryEndpoint } from "./isRepositoryEndpoint"
44
35
 
45
- /**
46
- * The largest page size allowed by the Prismic REST API V2. This value is used
47
- * to minimize the number of requests required to query content.
48
- */
49
36
  const MAX_PAGE_SIZE = 100
50
-
51
- /**
52
- * The number of milliseconds in which repository metadata is considered valid.
53
- * A ref can be invalidated quickly depending on how frequently content is
54
- * updated in the Prismic repository. As such, repository's metadata can only be
55
- * considered valid for a short amount of time.
56
- */
57
- export const REPOSITORY_CACHE_TTL = 5000
58
-
59
- /**
60
- * The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,
61
- * `getAllByType`, `getAllByTag`) will wait between individual page requests.
62
- *
63
- * This is done to ensure API performance is sustainable and reduces the chance
64
- * of a failed API request due to overloading.
65
- */
66
- export const GET_ALL_QUERY_DELAY = 500
67
-
68
- /**
69
- * The maximum number of attempts to retry a query with an invalid ref. We allow
70
- * multiple attempts since each attempt may use a different (and possibly
71
- * invalid) ref. Capping the number of attempts prevents infinite loops.
72
- */
37
+ const REPOSITORY_CACHE_TTL = 5000
38
+ const GET_ALL_QUERY_DELAY = 500
73
39
  const MAX_INVALID_REF_RETRY_ATTEMPTS = 3
74
40
 
75
41
  /**
76
- * Extracts one or more Prismic document types that match a given Prismic
77
- * document type. If no matches are found, no extraction is performed and the
78
- * union of all provided Prismic document types are returned.
79
- *
80
- * @typeParam TDocuments - Prismic document types from which to extract.
81
- * @typeParam TDocumentType - Type(s) to match `TDocuments` against.
42
+ * Extracts a document type with a matching `type` property from a union of
43
+ * document types.
82
44
  */
83
45
  type ExtractDocumentType<
84
46
  TDocuments extends PrismicDocument,
@@ -88,51 +50,19 @@ type ExtractDocumentType<
88
50
  ? TDocuments
89
51
  : Extract<TDocuments, { type: TDocumentType }>
90
52
 
91
- /**
92
- * Modes for client ref management.
93
- */
94
- enum RefStateMode {
95
- /**
96
- * Use the repository's master ref.
97
- */
98
- Master = "Master",
99
-
100
- /**
101
- * Use a given Release identified by its ID.
102
- */
103
- ReleaseID = "ReleaseID",
104
-
105
- /**
106
- * Use a given Release identified by its label.
107
- */
108
- ReleaseLabel = "ReleaseLabel",
109
-
110
- /**
111
- * Use a given ref.
112
- */
113
- Manual = "Manual",
114
- }
115
-
116
53
  /**
117
54
  * The minimum required properties to treat as an HTTP Request for automatic
118
55
  * Prismic preview support.
119
56
  */
120
57
  export type HttpRequestLike =
121
- | /**
122
- * Web API Request
123
- *
124
- * @see http://developer.mozilla.org/en-US/docs/Web/API/Request
125
- */
58
+ | // Web API Request
126
59
  {
127
60
  headers?: {
128
61
  get(name: string): string | null
129
62
  }
130
63
  url?: string
131
64
  }
132
-
133
- /**
134
- * Express-style Request
135
- */
65
+ // Express-style request
136
66
  | {
137
67
  headers?: {
138
68
  cookie?: string
@@ -141,49 +71,14 @@ export type HttpRequestLike =
141
71
  }
142
72
 
143
73
  /**
144
- * An object containing stateful information about a client's ref strategy.
74
+ * A function that returns a ref string. Used to configure which ref the client
75
+ * queries content from.
145
76
  */
146
- type RefState = {
147
- /**
148
- * Determines if automatic preview support is enabled.
149
- */
150
- autoPreviewsEnabled: boolean
77
+ type GetRef = (
78
+ params?: Pick<BuildQueryURLArgs, "accessToken"> & FetchParams,
79
+ ) => string | undefined | Promise<string | undefined>
151
80
 
152
- /**
153
- * An optional HTTP server request object used during previews if automatic
154
- * previews are enabled.
155
- */
156
- httpRequest?: HttpRequestLike
157
- } & (
158
- | {
159
- mode: RefStateMode.Master
160
- }
161
- | {
162
- mode: RefStateMode.ReleaseID
163
- releaseID: string
164
- }
165
- | {
166
- mode: RefStateMode.ReleaseLabel
167
- releaseLabel: string
168
- }
169
- | {
170
- mode: RefStateMode.Manual
171
- ref: RefStringOrThunk
172
- }
173
- )
174
-
175
- /**
176
- * A ref or a function that returns a ref. If a static ref is known, one can be
177
- * given. If the ref must be fetched on-demand, a function can be provided. This
178
- * function can optionally be asynchronous.
179
- */
180
- type RefStringOrThunk =
181
- | string
182
- | (() => string | undefined | Promise<string | undefined>)
183
-
184
- /**
185
- * Parameters for any client method that use `fetch()`.
186
- */
81
+ /** Parameters for client methods that use `fetch()`. */
187
82
  export type FetchParams = {
188
83
  /**
189
84
  * Options provided to the client's `fetch()` on all network requests. These
@@ -191,358 +86,286 @@ export type FetchParams = {
191
86
  * overriden on a per-query basis using the query's `fetchOptions` parameter.
192
87
  */
193
88
  fetchOptions?: RequestInitLike
194
-
195
- /**
196
- * An `AbortSignal` provided by an `AbortController`. This allows the network
197
- * request to be cancelled if necessary.
198
- *
199
- * @deprecated Move the `signal` parameter into `fetchOptions.signal`:
200
- *
201
- * @see \<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\>
202
- */
89
+ /** @deprecated Move to `fetchOptions.signal`: */
90
+ // TODO: Remove in v8.
203
91
  signal?: AbortSignalLike
204
92
  }
205
93
 
206
- /**
207
- * Configuration for clients that determine how content is queried.
208
- */
94
+ /** Prismic client configuration. */
209
95
  export type ClientConfig = {
210
96
  /**
211
- * The full Rest API V2 endpoint for the repository. This is only helpful if
212
- * you're using Prismic behind a proxy which we do not recommend.
97
+ * The client's Content API endpoint.
213
98
  *
214
- * @defaultValue `getRepositoryEndpoint(repositoryNameOrEndpoint)`
99
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
215
100
  */
216
101
  documentAPIEndpoint?: string
217
-
218
102
  /**
219
- * The secure token for accessing the Prismic repository. This is only
220
- * required if the repository is set to private.
103
+ * The secure token used for the Content API.
104
+ *
105
+ * @see {@link https://prismic.io/docs/fetch-content#content-visibility}
221
106
  */
222
107
  accessToken?: string
223
-
224
108
  /**
225
- * A string representing a version of the Prismic repository's content. This
226
- * may point to the latest version (called the "master ref"), or a preview
227
- * with draft content.
109
+ * The version of the repository's content. It can optionally be a function
110
+ * that returns a ref.
111
+ *
112
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
228
113
  */
229
- ref?: RefStringOrThunk
230
-
114
+ ref?: string | GetRef
231
115
  /**
232
116
  * A list of route resolver objects that define how a document's `url`
233
117
  * property is resolved.
234
118
  *
235
- * {@link https://prismic.io/docs/route-resolver}
119
+ * @see {@link https://prismic.io/docs/routes}
120
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
236
121
  */
237
122
  routes?: NonNullable<BuildQueryURLArgs["routes"]>
238
-
239
123
  /**
240
- * The `brokenRoute` option allows you to define the route populated in the
241
- * `url` property for broken link or content relationship fields. A broken
242
- * link is a link or content relationship field whose linked document has been
243
- * unpublished or deleted.
124
+ * The URL used for link or content relationship fields that point to an
125
+ * archived or deleted page.
244
126
  *
245
- * {@link https://prismic.io/docs/route-resolver}
127
+ * @see {@link https://prismic.io/docs/routes}
128
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
246
129
  */
247
130
  brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>
248
-
249
131
  /**
250
- * Default parameters that will be sent with each query. These parameters can
251
- * be overridden on each query if needed.
132
+ * Default parameters sent with each Content API request. These parameters can
133
+ * be overridden on each method.
134
+ *
135
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
252
136
  */
253
137
  defaultParams?: Omit<
254
138
  BuildQueryURLArgs,
255
139
  "ref" | "integrationFieldsRef" | "accessToken" | "routes" | "brokenRoute"
256
140
  >
257
-
258
141
  /**
259
- * The function used to make network requests to the Prismic REST API. In
260
- * environments where a global `fetch` function does not exist, such as
261
- * Node.js, this function must be provided.
142
+ * The `fetch` function used to make network requests.
143
+ *
144
+ * @default The global `fetch` function.
145
+ *
146
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
262
147
  */
263
148
  fetch?: FetchLike
264
-
265
149
  /**
266
- * Options provided to the client's `fetch()` on all network requests. These
267
- * options will be merged with internally required options. They can also be
268
- * overriden on a per-query basis using the query's `fetchOptions` parameter.
150
+ * The default `fetch` options sent with each Content API request. These
151
+ * parameters can be overriden on each method.
152
+ *
153
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
269
154
  */
270
155
  fetchOptions?: RequestInitLike
271
156
  }
272
157
 
273
158
  /**
274
159
  * Parameters specific to client methods that fetch all documents. These methods
275
- * start with `getAll` (for example, `getAllByType`).
160
+ * start with `getAll` (e.g. `getAllByType`).
276
161
  */
277
162
  type GetAllParams = {
278
163
  /**
279
- * Limit the number of documents queried. If a number is not provided, there
280
- * will be no limit and all matching documents will be returned.
164
+ * Limit the number of documents queried.
165
+ *
166
+ * @default No limit.
281
167
  */
282
168
  limit?: number
283
169
  }
284
170
 
285
171
  /**
286
- * Arguments to determine how the URL for a preview session is resolved.
287
- */
288
- type ResolvePreviewArgs<LinkResolverReturnType> = {
289
- /**
290
- * A function that maps a Prismic document to a URL within your app.
291
- */
292
- linkResolver?: LinkResolverFunction<LinkResolverReturnType>
293
-
294
- /**
295
- * A fallback URL if the link resolver does not return a value.
296
- */
297
- defaultURL: string
298
-
299
- /**
300
- * The preview token (also known as a ref) that will be used to query preview
301
- * content from the Prismic repository.
302
- */
303
- previewToken?: string
304
-
305
- /**
306
- * The previewed document that will be used to determine the destination URL.
307
- */
308
- documentID?: string
309
- }
310
-
311
- /**
312
- * A client that allows querying content from a Prismic repository.
172
+ * A client for fetching content from a Prismic repository.
313
173
  *
314
- * If used in an environment where a global `fetch` function is unavailable,
315
- * such as Node.js, the `fetch` option must be provided as part of the `options`
316
- * parameter.
317
- *
318
- * @typeParam TDocuments - Document types that are registered for the Prismic
319
- * repository. Query methods will automatically be typed based on this type.
174
+ * @see {@link https://prismic.io/docs/fetch-content}
175
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
320
176
  */
321
177
  export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
322
178
  /**
323
- * The function used to make network requests to the Prismic REST API. In
324
- * environments where a global `fetch` function does not exist, such as
325
- * Node.js, this function must be provided.
326
- */
327
- fetchFn: FetchLike
328
-
329
- fetchOptions?: RequestInitLike
330
-
331
- #repositoryName: string | undefined
332
-
333
- /**
334
- * The Prismic repository's name.
335
- */
336
- set repositoryName(value: string) {
337
- this.#repositoryName = value
338
- }
339
-
340
- /**
341
- * The Prismic repository's name.
342
- */
343
- get repositoryName(): string {
344
- if (!this.#repositoryName) {
345
- throw new PrismicError(
346
- `A repository name is required for this method but one could not be inferred from the provided API endpoint (\`${this.documentAPIEndpoint}\`). To fix this error, provide a repository name when creating the client. For more details, see ${devMsg("prefer-repository-name")}`,
347
- undefined,
348
- undefined,
349
- )
350
- }
351
-
352
- return this.#repositoryName
353
- }
354
-
355
- /**
356
- * The Prismic REST API V2 endpoint for the repository (use
357
- * `prismic.getRepositoryEndpoint` for the default endpoint).
358
- */
359
- documentAPIEndpoint: string
360
-
361
- /**
362
- * The Prismic REST API V2 endpoint for the repository (use
363
- * `prismic.getRepositoryEndpoint` for the default endpoint).
364
- *
365
- * @deprecated Use `documentAPIEndpoint` instead.
366
- */
367
- // TODO: Remove in v8.
368
- set endpoint(value: string) {
369
- this.documentAPIEndpoint = value
370
- }
371
-
372
- /**
373
- * The Prismic REST API V2 endpoint for the repository (use
374
- * `prismic.getRepositoryEndpoint` for the default endpoint).
179
+ * The client's Content API endpoint.
375
180
  *
376
- * @deprecated Use `documentAPIEndpoint` instead.
181
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
377
182
  */
378
- // TODO: Remove in v8.
379
- get endpoint(): string {
380
- return this.documentAPIEndpoint
381
- }
382
-
183
+ documentAPIEndpoint: string
383
184
  /**
384
- * The secure token for accessing the API (only needed if your repository is
385
- * set to private).
185
+ * The secure token used for the Content API.
386
186
  *
387
- * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
187
+ * @see {@link https://prismic.io/docs/fetch-content#content-visibility}
388
188
  */
389
189
  accessToken?: string
390
-
391
190
  /**
392
- * A list of route resolver objects that define how a document's `url` field
393
- * is resolved.
191
+ * A list of route resolver objects that define how a document's `url`
192
+ * property is resolved.
394
193
  *
395
- * {@link https://prismic.io/docs/route-resolver}
194
+ * @see {@link https://prismic.io/docs/routes}
195
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
396
196
  */
397
197
  routes?: NonNullable<BuildQueryURLArgs["routes"]>
398
-
399
198
  /**
400
- * The `brokenRoute` option allows you to define the route populated in the
401
- * `url` property for broken link or content relationship fields. A broken
402
- * link is a link or content relationship field whose linked document has been
403
- * unpublished or deleted.
199
+ * The URL used for link or content relationship fields that point to an
200
+ * archived or deleted page.
404
201
  *
405
- * {@link https://prismic.io/docs/route-resolver}
202
+ * @see {@link https://prismic.io/docs/routes}
203
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
406
204
  */
407
205
  brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>
408
-
409
206
  /**
410
- * Default parameters that will be sent with each query. These parameters can
411
- * be overridden on each query if needed.
207
+ * Default parameters sent with each Content API request. These parameters can
208
+ * be overridden on each method.
209
+ *
210
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
412
211
  */
413
212
  defaultParams?: Omit<
414
213
  BuildQueryURLArgs,
415
214
  "ref" | "integrationFieldsRef" | "accessToken" | "routes"
416
215
  >
417
-
418
216
  /**
419
- * The client's ref mode state. This determines which ref is used during
420
- * queries.
217
+ * The `fetch` function used to make network requests.
218
+ *
219
+ * @default The global `fetch` function.
220
+ *
221
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
421
222
  */
422
- private refState: RefState = {
423
- mode: RefStateMode.Master,
424
- autoPreviewsEnabled: true,
425
- }
426
-
223
+ fetchFn: FetchLike
427
224
  /**
428
- * Cached repository value.
225
+ * The default `fetch` options sent with each Content API request. These
226
+ * parameters can be overriden on each method.
227
+ *
228
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
429
229
  */
430
- private cachedRepository: Repository | undefined
230
+ fetchOptions: RequestInitLike
431
231
 
432
- /**
433
- * Timestamp at which the cached repository data is considered stale.
434
- */
435
- private cachedRepositoryExpiration = 0
232
+ #repositoryName: string | undefined
233
+
234
+ #getRef?: GetRef
235
+ #autoPreviews = true
236
+ #autoPreviewsRequest?: HttpRequestLike
237
+
238
+ #cachedRepository: Repository | undefined
239
+ #cachedRepositoryExpiration = 0 // Timestamp
436
240
 
437
241
  /**
438
- * Creates a Prismic client that can be used to query a repository.
439
- *
440
- * If used in an environment where a global `fetch` function is unavailable,
441
- * such as in some Node.js versions, the `fetch` option must be provided as
442
- * part of the `options` parameter.
443
- *
444
- * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
445
- * API V2 endpoint for the repository.
446
- * @param options - Configuration that determines how content will be queried
447
- * from the Prismic repository.
448
- *
449
- * @returns A client that can query content from the repository.
242
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full
243
+ * Content API endpoint for the repository.
244
+ * @param config - Client configuration.
450
245
  */
451
- constructor(repositoryNameOrEndpoint: string, options: ClientConfig = {}) {
452
- this.fetchOptions = options.fetchOptions
246
+ constructor(repositoryNameOrEndpoint: string, config: ClientConfig = {}) {
247
+ const {
248
+ documentAPIEndpoint,
249
+ accessToken,
250
+ ref,
251
+ routes,
252
+ brokenRoute,
253
+ defaultParams,
254
+ fetchOptions = {},
255
+ fetch = globalThis.fetch?.bind(globalThis),
256
+ } = config
453
257
 
454
- if (typeof options.fetch === "function") {
455
- this.fetchFn = options.fetch
456
- } else if (typeof globalThis.fetch === "function") {
457
- this.fetchFn = globalThis.fetch as FetchLike
258
+ if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
259
+ try {
260
+ this.repositoryName = getRepositoryName(repositoryNameOrEndpoint)
261
+ } catch {
262
+ console.warn(
263
+ `[@prismicio/client] A repository name could not be inferred from the provided endpoint (\`${repositoryNameOrEndpoint}\`). Some methods will be disabled. Create the client using a repository name to prevent this warning. For more details, see ${devMsg("prefer-repository-name")}`,
264
+ )
265
+ }
266
+ this.documentAPIEndpoint = documentAPIEndpoint || repositoryNameOrEndpoint
458
267
  } else {
268
+ this.repositoryName = repositoryNameOrEndpoint
269
+ this.documentAPIEndpoint =
270
+ documentAPIEndpoint || getRepositoryEndpoint(repositoryNameOrEndpoint)
271
+ }
272
+
273
+ if (!fetch) {
459
274
  throw new PrismicError(
460
- "A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.",
275
+ "A valid fetch implementation was not provided. In environments where fetch is not available, a fetch implementation must be provided via a polyfill or the `fetch` option.",
461
276
  undefined,
462
277
  undefined,
463
278
  )
464
279
  }
465
-
466
- // If the global fetch function is used, we must bind it to the global scope.
467
- if (this.fetchFn === globalThis.fetch) {
468
- this.fetchFn = this.fetchFn.bind(globalThis)
280
+ if (typeof fetch !== "function") {
281
+ throw new PrismicError(
282
+ `fetch must be a function, but received: ${typeof fetch}`,
283
+ undefined,
284
+ undefined,
285
+ )
469
286
  }
470
287
 
288
+ if (!isRepositoryEndpoint(this.documentAPIEndpoint)) {
289
+ throw new PrismicError(
290
+ `documentAPIEndpoint is not a valid URL: ${documentAPIEndpoint}`,
291
+ undefined,
292
+ undefined,
293
+ )
294
+ }
295
+ if (
296
+ isRepositoryEndpoint(repositoryNameOrEndpoint) &&
297
+ documentAPIEndpoint &&
298
+ repositoryNameOrEndpoint !== documentAPIEndpoint
299
+ ) {
300
+ console.warn(
301
+ `[@prismicio/client] Multiple incompatible endpoints were provided. Create the client using a repository name to prevent this error. For more details, see ${devMsg("prefer-repository-name")}`,
302
+ )
303
+ }
471
304
  if (
472
- (options.documentAPIEndpoint ||
473
- isRepositoryEndpoint(repositoryNameOrEndpoint)) &&
305
+ /\.prismic\.io\/(?!api\/v2\/?)/i.test(this.documentAPIEndpoint) &&
474
306
  process.env.NODE_ENV === "development"
475
307
  ) {
476
- const documentAPIEndpoint =
477
- options.documentAPIEndpoint || repositoryNameOrEndpoint
478
-
479
- // Matches non-API v2 `.prismic.io` endpoints, see: https://regex101.com/r/xRsavu/1
480
- if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(documentAPIEndpoint)) {
481
- throw new PrismicError(
482
- "@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.",
483
- undefined,
484
- undefined,
485
- )
486
- }
308
+ throw new PrismicError(
309
+ "@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.",
310
+ undefined,
311
+ undefined,
312
+ )
313
+ }
314
+ if (
315
+ /(?<!\.cdn)\.prismic\.io$/i.test(
316
+ new URL(this.documentAPIEndpoint).hostname,
317
+ ) &&
318
+ process.env.NODE_ENV === "development"
319
+ ) {
320
+ console.warn(
321
+ `[@prismicio/client] The client was created with a non-CDN endpoint. Convert it to the CDN endpoint for better performance. For more details, see ${devMsg("endpoint-must-use-cdn")}`,
322
+ )
323
+ }
487
324
 
488
- const hostname = new URL(documentAPIEndpoint).hostname.toLowerCase()
325
+ this.accessToken = accessToken
326
+ this.routes = routes
327
+ this.brokenRoute = brokenRoute
328
+ this.defaultParams = defaultParams
329
+ this.fetchOptions = fetchOptions
330
+ this.fetchFn = fetch
489
331
 
490
- // Matches non-.cdn `.prismic.io` endpoints
491
- if (
492
- hostname.endsWith(".prismic.io") &&
493
- !hostname.endsWith(".cdn.prismic.io")
494
- ) {
495
- console.warn(
496
- `[@prismicio/client] The client was created with a non-CDN endpoint. Convert it to the CDN endpoint for better performance. For more details, see ${devMsg("endpoint-must-use-cdn")}`,
497
- )
498
- }
332
+ this.graphQLFetch = this.graphQLFetch.bind(this)
499
333
 
500
- // Warn if the user provided both a repository endpoint and an `documentAPIEndpoint` and they are different
501
- if (
502
- options.documentAPIEndpoint &&
503
- isRepositoryEndpoint(repositoryNameOrEndpoint) &&
504
- repositoryNameOrEndpoint !== options.documentAPIEndpoint
505
- ) {
506
- console.warn(
507
- `[@prismicio/client] Multiple incompatible endpoints were provided. Create the client using a repository name to prevent this error. For more details, see ${devMsg("prefer-repository-name")}`,
508
- )
509
- }
334
+ if (ref) {
335
+ this.queryContentFromRef(ref)
510
336
  }
337
+ }
511
338
 
512
- if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
513
- this.documentAPIEndpoint = repositoryNameOrEndpoint
514
- try {
515
- this.repositoryName = getRepositoryName(repositoryNameOrEndpoint)
516
- } catch (error) {
517
- console.warn(
518
- `[@prismicio/client] A repository name could not be inferred from the provided endpoint (\`${repositoryNameOrEndpoint}\`). Some methods will be disabled. Create the client using a repository name to prevent this warning. For more details, see ${devMsg("prefer-repository-name")}`,
519
- )
520
- }
521
- } else {
522
- this.documentAPIEndpoint =
523
- options.documentAPIEndpoint ||
524
- getRepositoryEndpoint(repositoryNameOrEndpoint)
525
- this.repositoryName = repositoryNameOrEndpoint
339
+ /** The Prismic repository's name. */
340
+ set repositoryName(value: string) {
341
+ this.#repositoryName = value
342
+ }
343
+ /** The Prismic repository's name. */
344
+ get repositoryName(): string {
345
+ if (!this.#repositoryName) {
346
+ throw new PrismicError(
347
+ `A repository name is required for this method but one could not be inferred from the provided API endpoint (\`${this.documentAPIEndpoint}\`). To fix this error, provide a repository name when creating the client. For more details, see ${devMsg("prefer-repository-name")}`,
348
+ undefined,
349
+ undefined,
350
+ )
526
351
  }
527
352
 
528
- this.accessToken = options.accessToken
529
- this.routes = options.routes
530
- this.brokenRoute = options.brokenRoute
531
- this.defaultParams = options.defaultParams
532
-
533
- if (options.ref) {
534
- this.queryContentFromRef(options.ref)
535
- }
353
+ return this.#repositoryName
354
+ }
536
355
 
537
- this.graphQLFetch = this.graphQLFetch.bind(this)
356
+ /** @deprecated Replace with `documentAPIEndpoint`. */
357
+ // TODO: Remove in v8.
358
+ set endpoint(value: string) {
359
+ this.documentAPIEndpoint = value
360
+ }
361
+ /** @deprecated Replace with `documentAPIEndpoint`. */
362
+ // TODO: Remove in v8.
363
+ get endpoint(): string {
364
+ return this.documentAPIEndpoint
538
365
  }
539
366
 
540
367
  /**
541
- * Enables the client to automatically query content from a preview session if
542
- * one is active in browser environments. This is enabled by default in the
543
- * browser.
544
- *
545
- * For server environments, use `enableAutoPreviewsFromReq`.
368
+ * Enables the client to automatically query content from a preview session.
546
369
  *
547
370
  * @example
548
371
  *
@@ -550,132 +373,106 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
550
373
  * client.enableAutoPreviews()
551
374
  * ```
552
375
  *
553
- * @see enableAutoPreviewsFromReq
376
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
554
377
  */
555
378
  enableAutoPreviews(): void {
556
- this.refState.autoPreviewsEnabled = true
379
+ this.#autoPreviews = true
557
380
  }
558
381
 
559
382
  /**
560
- * Enables the client to automatically query content from a preview session if
561
- * one is active in server environments. This is disabled by default on the
562
- * server.
563
- *
564
- * For browser environments, use `enableAutoPreviews`.
383
+ * Enables the client to automatically query content from a preview session
384
+ * using an HTTP request object.
565
385
  *
566
386
  * @example
567
387
  *
568
388
  * ```ts
569
- * // In an express app
570
- * app.get("/", function (req, res) {
571
- * client.enableAutoPreviewsFromReq(req)
572
- * })
389
+ * client.enableAutoPreviewsFromReq(req)
573
390
  * ```
574
391
  *
575
- * @param req - An HTTP server request object containing the request's
576
- * cookies.
392
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
577
393
  */
578
- enableAutoPreviewsFromReq<R extends HttpRequestLike>(req: R): void {
579
- this.refState.httpRequest = req
580
- this.refState.autoPreviewsEnabled = true
394
+ enableAutoPreviewsFromReq(request: HttpRequestLike): void {
395
+ this.enableAutoPreviews()
396
+ this.#autoPreviewsRequest = request
581
397
  }
582
398
 
583
399
  /**
584
400
  * Disables the client from automatically querying content from a preview
585
- * session if one is active.
586
- *
587
- * Automatic preview content querying is enabled by default unless this method
588
- * is called.
401
+ * session.
589
402
  *
590
403
  * @example
591
404
  *
592
405
  * ```ts
593
406
  * client.disableAutoPreviews()
594
407
  * ```
408
+ *
409
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
595
410
  */
596
411
  disableAutoPreviews(): void {
597
- this.refState.autoPreviewsEnabled = false
412
+ this.#autoPreviews = false
413
+ this.#autoPreviewsRequest = undefined
598
414
  }
599
415
 
600
416
  /**
601
- * Queries content from the Prismic repository.
417
+ * Fetches pages based on the `params` argument. Results are paginated.
602
418
  *
603
419
  * @example
604
420
  *
605
421
  * ```ts
606
- * const response = await client.get()
422
+ * const response = await client.get({ pageSize: 10 })
607
423
  * ```
608
424
  *
609
- * @typeParam TDocument - Type of Prismic documents returned.
610
- *
611
- * @param params - Parameters to filter, sort, and paginate results.
612
- *
613
- * @returns A paginated response containing the result of the query.
425
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
614
426
  */
615
427
  async get<TDocument extends TDocuments>(
616
428
  params?: Partial<BuildQueryURLArgs> & FetchParams,
617
429
  ): Promise<Query<TDocument>> {
618
- const { data } = await this._get<TDocument>(params)
430
+ const response = await this.#internalGet(params)
619
431
 
620
- return data
432
+ return await response.json()
621
433
  }
622
434
 
623
435
  /**
624
- * Queries content from the Prismic repository and returns only the first
625
- * result, if any.
436
+ * Fetches the first page returned based on the `params` argument.
626
437
  *
627
438
  * @example
628
439
  *
629
440
  * ```ts
630
- * const document = await client.getFirst()
441
+ * const page = await client.getFirst()
631
442
  * ```
632
443
  *
633
- * @typeParam TDocument - Type of the Prismic document returned.
634
- *
635
- * @param params - Parameters to filter, sort, and paginate results.
636
- *
637
- * @returns The first result of the query, if any.
444
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
638
445
  */
639
446
  async getFirst<TDocument extends TDocuments>(
640
447
  params?: Partial<BuildQueryURLArgs> & FetchParams,
641
448
  ): Promise<TDocument> {
642
- const actualParams = { ...params }
643
- if (!(params && params.page) && !params?.pageSize) {
644
- actualParams.pageSize = this.defaultParams?.pageSize ?? 1
645
- }
646
- const { data, url } = await this._get<TDocument>(actualParams)
647
-
648
- const firstResult = data.results[0]
449
+ const actualParams =
450
+ params?.page || params?.pageSize ? params : { ...params, pageSize: 1 }
451
+ const response = await this.#internalGet(actualParams)
452
+ const { results }: Query<TDocument> = await response.clone().json()
649
453
 
650
- if (firstResult) {
651
- return firstResult
454
+ if (results[0]) {
455
+ return results[0]
652
456
  }
653
457
 
654
- throw new NotFoundError("No documents were returned", url, undefined)
458
+ throw new NotFoundError(
459
+ "No documents were returned",
460
+ response.url,
461
+ undefined,
462
+ )
655
463
  }
656
464
 
657
465
  /**
658
- * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
659
- * require more resources than other methods. Prefer using other methods that
660
- * filter by filters such as `getAllByType`.
661
- *
662
- * Queries content from the Prismic repository and returns all matching
663
- * content. If no filters are provided, all documents will be fetched.
664
- *
665
- * This method may make multiple network requests to query all matching
666
- * content.
466
+ * Fetches all pages based on the `params` argument. This method may make
467
+ * multiple network requests to fetch all matching pages.
667
468
  *
668
469
  * @example
669
470
  *
670
471
  * ```ts
671
- * const response = await client.dangerouslyGetAll()
472
+ * const pages = await client.dangerouslyGetAll()
672
473
  * ```
673
474
  *
674
- * @typeParam TDocument - Type of Prismic documents returned.
675
- *
676
- * @param params - Parameters to filter, sort, and paginate results.
677
- *
678
- * @returns A list of documents matching the query.
475
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
679
476
  */
680
477
  async dangerouslyGetAll<TDocument extends TDocuments>(
681
478
  params: Partial<Omit<BuildQueryURLArgs, "page">> &
@@ -712,27 +509,15 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
712
509
  }
713
510
 
714
511
  /**
715
- * Queries a document from the Prismic repository with a specific ID.
716
- *
717
- * @remarks
718
- * A document's UID is different from its ID. An ID is automatically generated
719
- * for all documents and is made available on its `id` property. A UID is
720
- * provided in the Prismic editor and is unique among all documents of its
721
- * custom type.
512
+ * Fetches a page with a specific ID.
722
513
  *
723
514
  * @example
724
515
  *
725
516
  * ```ts
726
- * const document = await client.getByID("WW4bKScAAMAqmluX")
517
+ * const page = await client.getByID("WW4bKScAAMAqmluX")
727
518
  * ```
728
519
  *
729
- * @typeParam TDocument- Type of the Prismic document returned.
730
- *
731
- * @param id - ID of the document.
732
- * @param params - Parameters to filter, sort, and paginate the results.
733
- *
734
- * @returns The document with an ID matching the `id` parameter, if a matching
735
- * document exists.
520
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
736
521
  */
737
522
  async getByID<TDocument extends TDocuments>(
738
523
  id: string,
@@ -744,13 +529,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
744
529
  }
745
530
 
746
531
  /**
747
- * Queries documents from the Prismic repository with specific IDs.
748
- *
749
- * @remarks
750
- * A document's UID is different from its ID. An ID is automatically generated
751
- * for all documents and is made available on its `id` property. A UID is
752
- * provided in the Prismic editor and is unique among all documents of its
753
- * custom type.
532
+ * Fetches pages with specific IDs. Results are paginated.
754
533
  *
755
534
  * @example
756
535
  *
@@ -761,13 +540,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
761
540
  * ])
762
541
  * ```
763
542
  *
764
- * @typeParam TDocument - Type of Prismic documents returned.
765
- *
766
- * @param ids - A list of document IDs.
767
- * @param params - Parameters to filter, sort, and paginate the results.
768
- *
769
- * @returns A paginated response containing documents with IDs matching the
770
- * `ids` parameter.
543
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
771
544
  */
772
545
  async getByIDs<TDocument extends TDocuments>(
773
546
  ids: string[],
@@ -779,32 +552,19 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
779
552
  }
780
553
 
781
554
  /**
782
- * Queries all documents from the Prismic repository with specific IDs.
783
- *
784
- * This method may make multiple network requests to query all matching
785
- * content.
786
- *
787
- * @remarks
788
- * A document's UID is different from its ID. An ID is automatically generated
789
- * for all documents and is made available on its `id` property. A UID is
790
- * provided in the Prismic editor and is unique among all documents of its
791
- * custom type.
555
+ * Fetches pages with specific IDs. This method may make multiple network
556
+ * requests to fetch all matching pages.
792
557
  *
793
558
  * @example
794
559
  *
795
560
  * ```ts
796
- * const response = await client.getAllByIDs([
561
+ * const pages = await client.getAllByIDs([
797
562
  * "WW4bKScAAMAqmluX",
798
563
  * "U1kTRgEAAC8A5ldS",
799
564
  * ])
800
565
  * ```
801
566
  *
802
- * @typeParam TDocument - Type of Prismic documents returned.
803
- *
804
- * @param ids - A list of document IDs.
805
- * @param params - Parameters to filter, sort, and paginate the results.
806
- *
807
- * @returns A list of documents with IDs matching the `ids` parameter.
567
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
808
568
  */
809
569
  async getAllByIDs<TDocument extends TDocuments>(
810
570
  ids: string[],
@@ -818,29 +578,15 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
818
578
  }
819
579
 
820
580
  /**
821
- * Queries a document from the Prismic repository with a specific UID and
822
- * custom type.
823
- *
824
- * @remarks
825
- * A document's UID is different from its ID. An ID is automatically generated
826
- * for all documents and is made available on its `id` property. A UID is
827
- * provided in the Prismic editor and is unique among all documents of its
828
- * custom type.
581
+ * Fetches a page with a specific UID and type.
829
582
  *
830
583
  * @example
831
584
  *
832
585
  * ```ts
833
- * const document = await client.getByUID("blog_post", "my-first-post")
586
+ * const page = await client.getByUID("blog_post", "my-first-post")
834
587
  * ```
835
588
  *
836
- * @typeParam TDocument - Type of the Prismic document returned.
837
- *
838
- * @param documentType - The API ID of the document's custom type.
839
- * @param uid - UID of the document.
840
- * @param params - Parameters to filter, sort, and paginate the results.
841
- *
842
- * @returns The document with a UID matching the `uid` parameter, if a
843
- * matching document exists.
589
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
844
590
  */
845
591
  async getByUID<
846
592
  TDocument extends TDocuments,
@@ -851,40 +597,28 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
851
597
  params?: Partial<BuildQueryURLArgs> & FetchParams,
852
598
  ): Promise<ExtractDocumentType<TDocument, TDocumentType>> {
853
599
  return await this.getFirst<ExtractDocumentType<TDocument, TDocumentType>>(
854
- appendFilters(params, [
855
- typeFilter(documentType),
600
+ appendFilters(
601
+ params,
602
+ filter.at("document.type", documentType),
856
603
  filter.at(`my.${documentType}.uid`, uid),
857
- ]),
604
+ ),
858
605
  )
859
606
  }
860
607
 
861
608
  /**
862
- * Queries document from the Prismic repository with specific UIDs and Custom
863
- * Type.
864
- *
865
- * @remarks
866
- * A document's UID is different from its ID. An ID is automatically generated
867
- * for all documents and is made available on its `id` property. A UID is
868
- * provided in the Prismic editor and is unique among all documents of its
869
- * custom type.
609
+ * Fetches pages with specific UIDs and a specific type. Results are
610
+ * paginated.
870
611
  *
871
612
  * @example
872
613
  *
873
614
  * ```ts
874
- * const document = await client.getByUIDs("blog_post", [
615
+ * const response = await client.getByUIDs("blog_post", [
875
616
  * "my-first-post",
876
617
  * "my-second-post",
877
618
  * ])
878
619
  * ```
879
620
  *
880
- * @typeParam TDocument - Type of the Prismic document returned.
881
- *
882
- * @param documentType - The API ID of the document's custom type.
883
- * @param uids - A list of document UIDs.
884
- * @param params - Parameters to filter, sort, and paginate the results.
885
- *
886
- * @returns A paginated response containing documents with UIDs matching the
887
- * `uids` parameter.
621
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
888
622
  */
889
623
  async getByUIDs<
890
624
  TDocument extends TDocuments,
@@ -895,42 +629,28 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
895
629
  params?: Partial<BuildQueryURLArgs> & FetchParams,
896
630
  ): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>> {
897
631
  return await this.get<ExtractDocumentType<TDocument, TDocumentType>>(
898
- appendFilters(params, [
899
- typeFilter(documentType),
632
+ appendFilters(
633
+ params,
634
+ filter.at("document.type", documentType),
900
635
  filter.in(`my.${documentType}.uid`, uids),
901
- ]),
636
+ ),
902
637
  )
903
638
  }
904
639
 
905
640
  /**
906
- * Queries all documents from the Prismic repository with specific UIDs and
907
- * custom type.
908
- *
909
- * This method may make multiple network requests to query all matching
910
- * content.
911
- *
912
- * @remarks
913
- * A document's UID is different from its ID. An ID is automatically generated
914
- * for all documents and is made available on its `id` property. A UID is
915
- * provided in the Prismic editor and is unique among all documents of its
916
- * custom type.
641
+ * Fetches pages with specific UIDs and a specific type. This method may make
642
+ * multiple network requests to fetch all matching pages.
917
643
  *
918
644
  * @example
919
645
  *
920
646
  * ```ts
921
- * const response = await client.getAllByUIDs([
647
+ * const pages = await client.getAllByUIDs("blog_post", [
922
648
  * "my-first-post",
923
649
  * "my-second-post",
924
650
  * ])
925
651
  * ```
926
652
  *
927
- * @typeParam TDocument - Type of Prismic documents returned.
928
- *
929
- * @param documentType - The API ID of the document's custom type.
930
- * @param uids - A list of document UIDs.
931
- * @param params - Parameters to filter, sort, and paginate the results.
932
- *
933
- * @returns A list of documents with UIDs matching the `uids` parameter.
653
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
934
654
  */
935
655
  async getAllByUIDs<
936
656
  TDocument extends TDocuments,
@@ -945,36 +665,24 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
945
665
  return await this.dangerouslyGetAll<
946
666
  ExtractDocumentType<TDocument, TDocumentType>
947
667
  >(
948
- appendFilters(params, [
949
- typeFilter(documentType),
668
+ appendFilters(
669
+ params,
670
+ filter.at("document.type", documentType),
950
671
  filter.in(`my.${documentType}.uid`, uids),
951
- ]),
672
+ ),
952
673
  )
953
674
  }
954
675
 
955
676
  /**
956
- * Queries a singleton document from the Prismic repository for a specific
957
- * custom type.
958
- *
959
- * @remarks
960
- * A singleton document is one that is configured in Prismic to only allow one
961
- * instance. For example, a repository may be configured to contain just one
962
- * Settings document. This is in contrast to a repeatable custom type which
963
- * allows multiple instances of itself.
677
+ * Fetches a specific single type page.
964
678
  *
965
679
  * @example
966
680
  *
967
681
  * ```ts
968
- * const document = await client.getSingle("settings")
682
+ * const page = await client.getSingle("settings")
969
683
  * ```
970
684
  *
971
- * @typeParam TDocument - Type of the Prismic document returned.
972
- *
973
- * @param documentType - The API ID of the singleton custom type.
974
- * @param params - Parameters to filter, sort, and paginate the results.
975
- *
976
- * @returns The singleton document for the custom type, if a matching document
977
- * exists.
685
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
978
686
  */
979
687
  async getSingle<
980
688
  TDocument extends TDocuments,
@@ -984,15 +692,12 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
984
692
  params?: Partial<BuildQueryURLArgs> & FetchParams,
985
693
  ): Promise<ExtractDocumentType<TDocument, TDocumentType>> {
986
694
  return await this.getFirst<ExtractDocumentType<TDocument, TDocumentType>>(
987
- appendFilters(params, typeFilter(documentType)),
695
+ appendFilters(params, filter.at("document.type", documentType)),
988
696
  )
989
697
  }
990
698
 
991
699
  /**
992
- * Queries documents from the Prismic repository for a specific custom type.
993
- *
994
- * Use `getAllByType` instead if you need to query all documents for a
995
- * specific custom type.
700
+ * Fetches pages with a specific type. Results are paginated.
996
701
  *
997
702
  * @example
998
703
  *
@@ -1000,12 +705,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1000
705
  * const response = await client.getByType("blog_post")
1001
706
  * ```
1002
707
  *
1003
- * @typeParam TDocument - Type of Prismic documents returned.
1004
- *
1005
- * @param documentType - The API ID of the custom type.
1006
- * @param params - Parameters to filter, sort, and paginate the results.
1007
- *
1008
- * @returns A paginated response containing documents of the custom type.
708
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
1009
709
  */
1010
710
  async getByType<
1011
711
  TDocument extends TDocuments,
@@ -1015,29 +715,21 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1015
715
  params?: Partial<BuildQueryURLArgs> & FetchParams,
1016
716
  ): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>> {
1017
717
  return await this.get<ExtractDocumentType<TDocument, TDocumentType>>(
1018
- appendFilters(params, typeFilter(documentType)),
718
+ appendFilters(params, filter.at("document.type", documentType)),
1019
719
  )
1020
720
  }
1021
721
 
1022
722
  /**
1023
- * Queries all documents from the Prismic repository for a specific Custom
1024
- * Type.
1025
- *
1026
- * This method may make multiple network requests to query all matching
1027
- * content.
723
+ * Fetches pages with a specific type. This method may make multiple network
724
+ * requests to fetch all matching documents.
1028
725
  *
1029
726
  * @example
1030
727
  *
1031
728
  * ```ts
1032
- * const response = await client.getByType("blog_post")
729
+ * const pages = await client.getAllByType("blog_post")
1033
730
  * ```
1034
731
  *
1035
- * @typeParam TDocument - Type of Prismic documents returned.
1036
- *
1037
- * @param documentType - The API ID of the custom type.
1038
- * @param params - Parameters to filter, sort, and paginate the results.
1039
- *
1040
- * @returns A list of all documents of the custom type.
732
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
1041
733
  */
1042
734
  async getAllByType<
1043
735
  TDocument extends TDocuments,
@@ -1050,53 +742,40 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1050
742
  ): Promise<ExtractDocumentType<TDocument, TDocumentType>[]> {
1051
743
  return await this.dangerouslyGetAll<
1052
744
  ExtractDocumentType<TDocument, TDocumentType>
1053
- >(appendFilters(params, typeFilter(documentType)))
745
+ >(appendFilters(params, filter.at("document.type", documentType)))
1054
746
  }
1055
747
 
1056
748
  /**
1057
- * Queries documents from the Prismic repository with a specific tag.
1058
- *
1059
- * Use `getAllByTag` instead if you need to query all documents with a
1060
- * specific tag.
749
+ * Fetches pages with a specific tag. Results are paginated.
1061
750
  *
1062
751
  * @example
1063
752
  *
1064
753
  * ```ts
1065
- * const response = await client.getByTag("food")
754
+ * const response = await client.getByTag("featured")
1066
755
  * ```
1067
756
  *
1068
- * @typeParam TDocument - Type of Prismic documents returned.
1069
- *
1070
- * @param tag - The tag that must be included on a document.
1071
- * @param params - Parameters to filter, sort, and paginate the results.
1072
- *
1073
- * @returns A paginated response containing documents with the tag.
757
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
1074
758
  */
1075
759
  async getByTag<TDocument extends TDocuments>(
1076
760
  tag: string,
1077
761
  params?: Partial<BuildQueryURLArgs> & FetchParams,
1078
762
  ): Promise<Query<TDocument>> {
1079
- return await this.get<TDocument>(appendFilters(params, someTagsFilter(tag)))
763
+ return await this.get<TDocument>(
764
+ appendFilters(params, filter.any("document.tags", [tag])),
765
+ )
1080
766
  }
1081
767
 
1082
768
  /**
1083
- * Queries all documents from the Prismic repository with a specific tag.
1084
- *
1085
- * This method may make multiple network requests to query all matching
1086
- * content.
769
+ * Fetches pages with a specific tag. This method may make multiple network
770
+ * requests to fetch all matching documents.
1087
771
  *
1088
772
  * @example
1089
773
  *
1090
774
  * ```ts
1091
- * const response = await client.getAllByTag("food")
775
+ * const pages = await client.getAllByTag("featured")
1092
776
  * ```
1093
777
  *
1094
- * @typeParam TDocument - Type of Prismic documents returned.
1095
- *
1096
- * @param tag - The tag that must be included on a document.
1097
- * @param params - Parameters to filter, sort, and paginate the results.
1098
- *
1099
- * @returns A list of all documents with the tag.
778
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
1100
779
  */
1101
780
  async getAllByTag<TDocument extends TDocuments>(
1102
781
  tag: string,
@@ -1105,55 +784,41 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1105
784
  FetchParams,
1106
785
  ): Promise<TDocument[]> {
1107
786
  return await this.dangerouslyGetAll<TDocument>(
1108
- appendFilters(params, someTagsFilter(tag)),
787
+ appendFilters(params, filter.any("document.tags", [tag])),
1109
788
  )
1110
789
  }
1111
790
 
1112
791
  /**
1113
- * Queries documents from the Prismic repository with specific tags. A
1114
- * document must be tagged with all of the queried tags to be included.
792
+ * Fetches pages with every tag from a list of tags. Results are paginated.
1115
793
  *
1116
794
  * @example
1117
795
  *
1118
796
  * ```ts
1119
- * const response = await client.getByEveryTag(["food", "fruit"])
797
+ * const response = await client.getByEveryTag(["featured", "homepage"])
1120
798
  * ```
1121
799
  *
1122
- * @typeParam TDocument - Type of Prismic documents returned.
1123
- *
1124
- * @param tags - A list of tags that must be included on a document.
1125
- * @param params - Parameters to filter, sort, and paginate the results.
1126
- *
1127
- * @returns A paginated response containing documents with the tags.
800
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
1128
801
  */
1129
802
  async getByEveryTag<TDocument extends TDocuments>(
1130
803
  tags: string[],
1131
804
  params?: Partial<BuildQueryURLArgs> & FetchParams,
1132
805
  ): Promise<Query<TDocument>> {
1133
806
  return await this.get<TDocument>(
1134
- appendFilters(params, everyTagFilter(tags)),
807
+ appendFilters(params, filter.at("document.tags", tags)),
1135
808
  )
1136
809
  }
1137
810
 
1138
811
  /**
1139
- * Queries documents from the Prismic repository with specific tags. A
1140
- * document must be tagged with all of the queried tags to be included.
1141
- *
1142
- * This method may make multiple network requests to query all matching
1143
- * content.
812
+ * Fetches pages with every tag from a list of tags. This method may make
813
+ * multiple network requests to fetch all matching pages.
1144
814
  *
1145
815
  * @example
1146
816
  *
1147
817
  * ```ts
1148
- * const response = await client.getAllByEveryTag(["food", "fruit"])
818
+ * const pages = await client.getAllByEveryTag(["featured", "homepage"])
1149
819
  * ```
1150
820
  *
1151
- * @typeParam TDocument - Type of Prismic documents returned.
1152
- *
1153
- * @param tags - A list of tags that must be included on a document.
1154
- * @param params - Parameters to filter, sort, and paginate the results.
1155
- *
1156
- * @returns A list of all documents with the tags.
821
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
1157
822
  */
1158
823
  async getAllByEveryTag<TDocument extends TDocuments>(
1159
824
  tags: string[],
@@ -1162,58 +827,42 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1162
827
  FetchParams,
1163
828
  ): Promise<TDocument[]> {
1164
829
  return await this.dangerouslyGetAll<TDocument>(
1165
- appendFilters(params, everyTagFilter(tags)),
830
+ appendFilters(params, filter.at("document.tags", tags)),
1166
831
  )
1167
832
  }
1168
833
 
1169
834
  /**
1170
- * Queries documents from the Prismic repository with specific tags. A
1171
- * document must be tagged with at least one of the queried tags to be
1172
- * included.
835
+ * Fetches pages with at least one tag from a list of tags. Results are
836
+ * paginated.
1173
837
  *
1174
838
  * @example
1175
839
  *
1176
840
  * ```ts
1177
- * const response = await client.getByEveryTag(["food", "fruit"])
841
+ * const response = await client.getBySomeTags(["featured", "homepage"])
1178
842
  * ```
1179
843
  *
1180
- * @typeParam TDocument - Type of Prismic documents returned.
1181
- *
1182
- * @param tags - A list of tags that must be included on a document.
1183
- * @param params - Parameters to filter, sort, and paginate the results.
1184
- *
1185
- * @returns A paginated response containing documents with at least one of the
1186
- * tags.
844
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
1187
845
  */
1188
846
  async getBySomeTags<TDocument extends TDocuments>(
1189
847
  tags: string[],
1190
848
  params?: Partial<BuildQueryURLArgs> & FetchParams,
1191
849
  ): Promise<Query<TDocument>> {
1192
850
  return await this.get<TDocument>(
1193
- appendFilters(params, someTagsFilter(tags)),
851
+ appendFilters(params, filter.any("document.tags", tags)),
1194
852
  )
1195
853
  }
1196
854
 
1197
855
  /**
1198
- * Queries documents from the Prismic repository with specific tags. A
1199
- * document must be tagged with at least one of the queried tags to be
1200
- * included.
1201
- *
1202
- * This method may make multiple network requests to query all matching
1203
- * content.
856
+ * Fetches pages with at least one tag from a list of tags. This method may
857
+ * make multiple network requests to fetch all matching documents.
1204
858
  *
1205
859
  * @example
1206
860
  *
1207
861
  * ```ts
1208
- * const response = await client.getAllBySomeTags(["food", "fruit"])
862
+ * const pages = await client.getAllBySomeTags(["featured", "homepage"])
1209
863
  * ```
1210
864
  *
1211
- * @typeParam TDocument - Type of Prismic documents returned.
1212
- *
1213
- * @param tags - A list of tags that must be included on a document.
1214
- * @param params - Parameters to filter, sort, and paginate the results.
1215
- *
1216
- * @returns A list of all documents with at least one of the tags.
865
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
1217
866
  */
1218
867
  async getAllBySomeTags<TDocument extends TDocuments>(
1219
868
  tags: string[],
@@ -1222,53 +871,68 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1222
871
  FetchParams,
1223
872
  ): Promise<TDocument[]> {
1224
873
  return await this.dangerouslyGetAll<TDocument>(
1225
- appendFilters(params, someTagsFilter(tags)),
874
+ appendFilters(params, filter.any("document.tags", tags)),
1226
875
  )
1227
876
  }
1228
877
 
1229
878
  /**
1230
- * Returns metadata about the Prismic repository, such as its refs, releases,
1231
- * and custom types.
879
+ * Fetches metadata about the client's Prismic repository.
1232
880
  *
1233
- * @returns Repository metadata.
881
+ * @example
882
+ *
883
+ * ```ts
884
+ * const repository = await client.getRepository()
885
+ * ```
886
+ *
887
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrepository}
1234
888
  */
1235
- async getRepository(params?: FetchParams): Promise<Repository> {
889
+ async getRepository(
890
+ params?: Pick<BuildQueryURLArgs, "accessToken"> & FetchParams,
891
+ ): Promise<Repository> {
892
+ if (
893
+ this.#cachedRepository &&
894
+ this.#cachedRepositoryExpiration > Date.now()
895
+ ) {
896
+ return this.#cachedRepository
897
+ }
898
+
1236
899
  const url = new URL(this.documentAPIEndpoint)
1237
900
 
1238
- if (this.accessToken) {
1239
- url.searchParams.set("access_token", this.accessToken)
901
+ const accessToken = params?.accessToken || this.accessToken
902
+ if (accessToken) {
903
+ url.searchParams.set("access_token", accessToken)
1240
904
  }
1241
905
 
1242
906
  const response = await this.#request(url, params)
1243
- switch (response.status) {
1244
- case 200: {
1245
- return (await response.json()) as Repository
1246
- }
1247
- case 401: {
1248
- const json = await response.json()
1249
- throw new ForbiddenError(json.error, url.toString(), json)
1250
- }
1251
- case 404: {
1252
- throw new RepositoryNotFoundError(
1253
- `Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`,
1254
- url.toString(),
1255
- undefined,
1256
- )
1257
- }
1258
- default: {
1259
- throw new PrismicError(undefined, url.toString(), await response.text())
1260
- }
907
+
908
+ if (response.ok) {
909
+ this.#cachedRepository = (await response.json()) as Repository
910
+ this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL
911
+
912
+ return this.#cachedRepository
913
+ }
914
+
915
+ if (response.status === 404) {
916
+ throw new RepositoryNotFoundError(
917
+ `Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`,
918
+ url.toString(),
919
+ undefined,
920
+ )
1261
921
  }
922
+
923
+ return await this.#throwContentAPIError(response, url.toString())
1262
924
  }
1263
925
 
1264
926
  /**
1265
- * Returns a list of all refs for the Prismic repository.
927
+ * Fetches the repository's active refs.
1266
928
  *
1267
- * Refs are used to identify which version of the repository's content should
1268
- * be queried. All repositories will have at least one ref pointing to the
1269
- * latest published content called the "master ref".
929
+ * @example
1270
930
  *
1271
- * @returns A list of all refs for the Prismic repository.
931
+ * ```ts
932
+ * const refs = await client.getRefs()
933
+ * ```
934
+ *
935
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefs}
1272
936
  */
1273
937
  async getRefs(params?: FetchParams): Promise<Ref[]> {
1274
938
  const repository = await this.getRepository(params)
@@ -1277,48 +941,94 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1277
941
  }
1278
942
 
1279
943
  /**
1280
- * Returns a ref for the Prismic repository with a matching ID.
944
+ * Fetches a ref by its ID.
945
+ *
946
+ * @example
1281
947
  *
1282
- * @param id - ID of the ref.
948
+ * ```ts
949
+ * const ref = await client.getRefByID("YhE3YhEAACIA4321")
950
+ * ```
1283
951
  *
1284
- * @returns The ref with a matching ID, if it exists.
952
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
1285
953
  */
1286
954
  async getRefByID(id: string, params?: FetchParams): Promise<Ref> {
1287
955
  const refs = await this.getRefs(params)
956
+ const ref = refs.find((ref) => ref.id === id)
957
+
958
+ if (!ref) {
959
+ throw new PrismicError(
960
+ `Ref with ID "${id}" could not be found.`,
961
+ undefined,
962
+ undefined,
963
+ )
964
+ }
1288
965
 
1289
- return findRefByID(refs, id)
966
+ return ref
1290
967
  }
1291
968
 
1292
969
  /**
1293
- * Returns a ref for the Prismic repository with a matching label.
970
+ * Fetches a ref by its label. A release ref's label is its name shown in the
971
+ * Page Builder.
1294
972
  *
1295
- * @param label - Label of the ref.
973
+ * @example
974
+ *
975
+ * ```ts
976
+ * const ref = await client.getRefByLabel("My Release")
977
+ * ```
1296
978
  *
1297
- * @returns The ref with a matching label, if it exists.
979
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
1298
980
  */
1299
981
  async getRefByLabel(label: string, params?: FetchParams): Promise<Ref> {
1300
982
  const refs = await this.getRefs(params)
983
+ const ref = refs.find((ref) => ref.label === label)
1301
984
 
1302
- return findRefByLabel(refs, label)
985
+ if (!ref) {
986
+ throw new PrismicError(
987
+ `Ref with label "${label}" could not be found.`,
988
+ undefined,
989
+ undefined,
990
+ )
991
+ }
992
+
993
+ return ref
1303
994
  }
1304
995
 
1305
996
  /**
1306
- * Returns the master ref for the Prismic repository. The master ref points to
1307
- * the repository's latest published content.
997
+ * Fetches the repository's master ref.
998
+ *
999
+ * @example
1308
1000
  *
1309
- * @returns The repository's master ref.
1001
+ * ```ts
1002
+ * const masterRef = await client.getMasterRef()
1003
+ * ```
1004
+ *
1005
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
1310
1006
  */
1311
1007
  async getMasterRef(params?: FetchParams): Promise<Ref> {
1312
1008
  const refs = await this.getRefs(params)
1009
+ const ref = refs.find((ref) => ref.isMasterRef)
1313
1010
 
1314
- return findMasterRef(refs)
1011
+ if (!ref) {
1012
+ throw new PrismicError(
1013
+ "Master ref could not be found.",
1014
+ undefined,
1015
+ undefined,
1016
+ )
1017
+ }
1018
+
1019
+ return ref
1315
1020
  }
1316
1021
 
1317
1022
  /**
1318
- * Returns a list of all Releases for the Prismic repository. Releases are
1319
- * used to group content changes before publishing.
1023
+ * Fetches the repository's active releases.
1024
+ *
1025
+ * @example
1320
1026
  *
1321
- * @returns A list of all Releases for the Prismic repository.
1027
+ * ```ts
1028
+ * const releases = await client.getReleases()
1029
+ * ```
1030
+ *
1031
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleases}
1322
1032
  */
1323
1033
  async getReleases(params?: FetchParams): Promise<Ref[]> {
1324
1034
  const refs = await this.getRefs(params)
@@ -1327,39 +1037,72 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1327
1037
  }
1328
1038
 
1329
1039
  /**
1330
- * Returns a Release for the Prismic repository with a matching ID.
1040
+ * Fetches a release with a specific ID.
1041
+ *
1042
+ * @example
1331
1043
  *
1332
- * @param id - ID of the Release.
1044
+ * ```ts
1045
+ * const release = await client.getReleaseByID("YhE3YhEAACIA4321")
1046
+ * ```
1333
1047
  *
1334
- * @returns The Release with a matching ID, if it exists.
1048
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
1335
1049
  */
1336
1050
  async getReleaseByID(id: string, params?: FetchParams): Promise<Ref> {
1337
1051
  const releases = await this.getReleases(params)
1052
+ const release = releases.find((ref) => ref.id === id)
1053
+
1054
+ if (!release) {
1055
+ throw new PrismicError(
1056
+ `Release with ID "${id}" could not be found.`,
1057
+ undefined,
1058
+ undefined,
1059
+ )
1060
+ }
1338
1061
 
1339
- return findRefByID(releases, id)
1062
+ return release
1340
1063
  }
1341
1064
 
1342
1065
  /**
1343
- * Returns a Release for the Prismic repository with a matching label.
1066
+ * Fetches a release by its label. A release ref's label is its name shown in
1067
+ * the Page Builder.
1344
1068
  *
1345
- * @param label - Label of the ref.
1069
+ * @example
1346
1070
  *
1347
- * @returns The ref with a matching label, if it exists.
1071
+ * ```ts
1072
+ * const release = await client.getReleaseByLabel("My Release")
1073
+ * ```
1074
+ *
1075
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
1348
1076
  */
1349
1077
  async getReleaseByLabel(label: string, params?: FetchParams): Promise<Ref> {
1350
1078
  const releases = await this.getReleases(params)
1079
+ const release = releases.find((ref) => ref.label === label)
1080
+
1081
+ if (!release) {
1082
+ throw new PrismicError(
1083
+ `Release with label "${label}" could not be found.`,
1084
+ undefined,
1085
+ undefined,
1086
+ )
1087
+ }
1351
1088
 
1352
- return findRefByLabel(releases, label)
1089
+ return release
1353
1090
  }
1354
1091
 
1355
1092
  /**
1356
- * Returns a list of all tags used in the Prismic repository.
1093
+ * Fetches the repository's page tags.
1357
1094
  *
1358
- * @returns A list of all tags used in the repository.
1095
+ * @example
1096
+ *
1097
+ * ```ts
1098
+ * const tags = await client.getTags()
1099
+ * ```
1100
+ *
1101
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#gettags}
1359
1102
  */
1360
1103
  async getTags(params?: FetchParams): Promise<string[]> {
1361
- const cachedRepository = await this.getCachedRepository(params)
1362
- const form = cachedRepository.forms.tags
1104
+ const repository = await this.getRepository(params)
1105
+ const form = repository.forms.tags
1363
1106
  if (form) {
1364
1107
  const url = new URL(form.action)
1365
1108
  if (this.accessToken) {
@@ -1372,17 +1115,21 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1372
1115
  }
1373
1116
  }
1374
1117
 
1375
- const repository = await this.getRepository(params)
1376
-
1377
1118
  return repository.tags
1378
1119
  }
1379
1120
 
1380
1121
  /**
1381
- * Builds a URL used to query content from the Prismic repository.
1122
+ * Builds a Content API query URL with a set of parameters.
1382
1123
  *
1383
- * @param params - Parameters to filter, sort, and paginate the results.
1124
+ * @example
1125
+ *
1126
+ * ```ts
1127
+ * const url = await client.buildQueryURL({
1128
+ * filters: [filter.at("document.type", "blog_post")],
1129
+ * })
1130
+ * ```
1384
1131
  *
1385
- * @returns A URL string that can be requested to query content.
1132
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
1386
1133
  */
1387
1134
  async buildQueryURL({
1388
1135
  signal,
@@ -1390,11 +1137,21 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1390
1137
  ...params
1391
1138
  }: Partial<BuildQueryURLArgs> & FetchParams = {}): Promise<string> {
1392
1139
  const ref =
1393
- params.ref || (await this.getResolvedRefString({ signal, fetchOptions }))
1140
+ params.ref ||
1141
+ (await this.#getResolvedRef({
1142
+ accessToken: params.accessToken,
1143
+ signal,
1144
+ fetchOptions,
1145
+ }))
1394
1146
  const integrationFieldsRef =
1395
1147
  params.integrationFieldsRef ||
1396
- (await this.getCachedRepository({ signal, fetchOptions }))
1397
- .integrationFieldsRef ||
1148
+ (
1149
+ await this.getRepository({
1150
+ accessToken: params.accessToken,
1151
+ signal,
1152
+ fetchOptions,
1153
+ })
1154
+ ).integrationFieldsRef ||
1398
1155
  undefined
1399
1156
 
1400
1157
  return buildQueryURL(this.documentAPIEndpoint, {
@@ -1409,26 +1166,30 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1409
1166
  }
1410
1167
 
1411
1168
  /**
1412
- * Determines the URL for a previewed document during an active preview
1413
- * session. The result of this method should be used to redirect the user to
1414
- * the document's URL.
1169
+ * Fetches a previewed page's URL using a preview token and page ID.
1415
1170
  *
1416
1171
  * @example
1417
1172
  *
1418
1173
  * ```ts
1419
- * const url = client.resolvePreviewURL({
1420
- * linkResolver: (document) => `/${document.uid}`
1421
- * defaultURL: '/'
1422
- * })
1174
+ * const url = await client.resolvePreviewURL({
1175
+ * linkResolver,
1176
+ * defaultURL: "/",
1177
+ * })
1423
1178
  * ```
1424
1179
  *
1425
- * @param args - Arguments to configure the URL resolving.
1426
- *
1427
- * @returns The URL for the previewed document during an active preview
1428
- * session. The user should be redirected to this URL.
1180
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#resolvepreviewurl}
1429
1181
  */
1430
1182
  async resolvePreviewURL<LinkResolverReturnType>(
1431
- args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams,
1183
+ args: {
1184
+ /** A function converts a document to a URL in your website. */
1185
+ linkResolver?: LinkResolverFunction<LinkResolverReturnType>
1186
+ /** A fallback URL used when the document does not have a URL. */
1187
+ defaultURL: string
1188
+ /** The preview token for the preview session. */
1189
+ previewToken?: string
1190
+ /** The previewed document's ID. */
1191
+ documentID?: string
1192
+ } & FetchParams,
1432
1193
  ): Promise<string> {
1433
1194
  let documentID: string | undefined | null = args.documentID
1434
1195
  let previewToken: string | undefined | null = args.previewToken
@@ -1438,15 +1199,15 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1438
1199
 
1439
1200
  documentID = documentID || searchParams.get("documentId")
1440
1201
  previewToken = previewToken || searchParams.get("token")
1441
- } else if (this.refState.httpRequest) {
1442
- if ("query" in this.refState.httpRequest) {
1202
+ } else if (this.#autoPreviewsRequest) {
1203
+ if ("query" in this.#autoPreviewsRequest) {
1443
1204
  documentID =
1444
- documentID || (this.refState.httpRequest.query?.documentId as string)
1205
+ documentID || (this.#autoPreviewsRequest.query?.documentId as string)
1445
1206
  previewToken =
1446
- previewToken || (this.refState.httpRequest.query?.token as string)
1207
+ previewToken || (this.#autoPreviewsRequest.query?.token as string)
1447
1208
  } else if (
1448
- "url" in this.refState.httpRequest &&
1449
- this.refState.httpRequest.url
1209
+ "url" in this.#autoPreviewsRequest &&
1210
+ this.#autoPreviewsRequest.url
1450
1211
  ) {
1451
1212
  // Including "missing-host://" by default
1452
1213
  // handles a case where Next.js Route Handlers
@@ -1454,7 +1215,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1454
1215
  // parameters in the `url` property
1455
1216
  // (e.g. `/api/preview?foo=bar`).
1456
1217
  const searchParams = new URL(
1457
- this.refState.httpRequest.url,
1218
+ this.#autoPreviewsRequest.url,
1458
1219
  "missing-host://",
1459
1220
  ).searchParams
1460
1221
 
@@ -1482,108 +1243,86 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1482
1243
  }
1483
1244
 
1484
1245
  /**
1485
- * Configures the client to query the latest published content for all future
1486
- * queries.
1487
- *
1488
- * If the `ref` parameter is provided during a query, it takes priority for
1489
- * that query.
1246
+ * Configures the client to query the latest published content. This is the
1247
+ * client's default mode.
1490
1248
  *
1491
1249
  * @example
1492
1250
  *
1493
1251
  * ```ts
1494
- * await client.queryLatestContent()
1495
- * const document = await client.getByID("WW4bKScAAMAqmluX")
1252
+ * client.queryLatestContent()
1496
1253
  * ```
1254
+ *
1255
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
1497
1256
  */
1498
1257
  queryLatestContent(): void {
1499
- this.refState.mode = RefStateMode.Master
1258
+ this.#getRef = undefined
1500
1259
  }
1501
1260
 
1502
1261
  /**
1503
- * Configures the client to query content from a specific Release identified
1504
- * by its ID for all future queries.
1505
- *
1506
- * If the `ref` parameter is provided during a query, it takes priority for
1507
- * that query.
1262
+ * Configures the client to query content from a release with a specific ID.
1508
1263
  *
1509
1264
  * @example
1510
1265
  *
1511
1266
  * ```ts
1512
- * await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa")
1513
- * const document = await client.getByID("WW4bKScAAMAqmluX")
1267
+ * client.queryContentFromReleaseByID("YhE3YhEAACIA4321")
1514
1268
  * ```
1515
1269
  *
1516
- * @param releaseID - The ID of the Release.
1270
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
1517
1271
  */
1518
- queryContentFromReleaseByID(releaseID: string): void {
1519
- this.refState = {
1520
- ...this.refState,
1521
- mode: RefStateMode.ReleaseID,
1522
- releaseID,
1272
+ queryContentFromReleaseByID(id: string): void {
1273
+ this.#getRef = async (params) => {
1274
+ const release = await this.getReleaseByID(id, params)
1275
+ return release.ref
1523
1276
  }
1524
1277
  }
1525
1278
 
1526
1279
  /**
1527
- * Configures the client to query content from a specific Release identified
1528
- * by its label for all future queries.
1529
- *
1530
- * If the `ref` parameter is provided during a query, it takes priority for
1531
- * that query.
1280
+ * Configures the client to query content from a release with a specific
1281
+ * label.
1532
1282
  *
1533
1283
  * @example
1534
1284
  *
1535
1285
  * ```ts
1536
- * await client.queryContentFromReleaseByLabel("My Release")
1537
- * const document = await client.getByID("WW4bKScAAMAqmluX")
1286
+ * client.queryContentFromReleaseByLabel("My Release")
1538
1287
  * ```
1539
1288
  *
1540
- * @param releaseLabel - The label of the Release.
1289
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
1541
1290
  */
1542
- queryContentFromReleaseByLabel(releaseLabel: string): void {
1543
- this.refState = {
1544
- ...this.refState,
1545
- mode: RefStateMode.ReleaseLabel,
1546
- releaseLabel,
1291
+ queryContentFromReleaseByLabel(label: string): void {
1292
+ this.#getRef = async (params) => {
1293
+ const release = await this.getReleaseByLabel(label, params)
1294
+ return release.ref
1547
1295
  }
1548
1296
  }
1549
1297
 
1550
1298
  /**
1551
- * Configures the client to query content from a specific ref. The ref can be
1552
- * provided as a string or a function.
1553
- *
1554
- * If a function is provided, the ref is fetched lazily before each query. The
1555
- * function may also be asynchronous.
1299
+ * Configures the client to query content from a specific ref.
1556
1300
  *
1557
1301
  * @example
1558
1302
  *
1559
1303
  * ```ts
1560
- * await client.queryContentFromRef("my-ref")
1561
- * const document = await client.getByID("WW4bKScAAMAqmluX")
1304
+ * client.queryContentFromRef("my-ref")
1562
1305
  * ```
1563
1306
  *
1564
- * @param ref - The ref or a function that returns the ref from which to query
1565
- * content.
1307
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
1566
1308
  */
1567
- queryContentFromRef(ref: RefStringOrThunk): void {
1568
- this.refState = {
1569
- ...this.refState,
1570
- mode: RefStateMode.Manual,
1571
- ref,
1572
- }
1309
+ queryContentFromRef(ref: string | GetRef): void {
1310
+ this.#getRef = typeof ref === "string" ? () => ref : ref
1573
1311
  }
1574
1312
 
1575
1313
  /**
1576
- * A `fetch()` function to be used with GraphQL clients configured for
1577
- * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
1578
- * and Authorization headers. Queries will automatically be minified by
1579
- * removing whitespace where possible.
1314
+ * A preconfigured `fetch()` function for Prismic's GraphQL API that can be
1315
+ * provided to GraphQL clients.
1580
1316
  *
1581
1317
  * @example
1582
1318
  *
1583
1319
  * ```ts
1320
+ * import { createClient, getGraphQLEndpoint } from "@prismicio/client"
1321
+ *
1322
+ * const client = createClient("example-prismic-repo")
1584
1323
  * const graphQLClient = new ApolloClient({
1585
1324
  * link: new HttpLink({
1586
- * uri: prismic.getGraphQLEndpoint(repositoryName),
1325
+ * uri: getGraphQLEndpoint(client.repositoryName),
1587
1326
  * // Provide `client.graphQLFetch` as the fetch implementation.
1588
1327
  * fetch: client.graphQLFetch,
1589
1328
  * // Using GET is required.
@@ -1593,105 +1332,53 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1593
1332
  * })
1594
1333
  * ```
1595
1334
  *
1596
- * @param input - The `fetch()` `input` parameter. Only strings are supported.
1597
- * @param init - The `fetch()` `init` parameter. Only plain objects are
1598
- * supported.
1599
- *
1600
- * @returns The `fetch()` Response for the request.
1601
- *
1602
- * @experimental
1335
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
1603
1336
  */
1604
1337
  async graphQLFetch(
1605
1338
  input: RequestInfo,
1606
1339
  init?: Omit<RequestInit, "signal"> & { signal?: AbortSignalLike },
1607
1340
  ): Promise<Response> {
1608
- const cachedRepository = await this.getCachedRepository()
1609
- const ref = await this.getResolvedRefString()
1610
-
1611
- const unsanitizedHeaders: Record<string, string> = {
1612
- "Prismic-ref": ref,
1613
- Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
1614
- // Asserting `init.headers` is a Record since popular GraphQL
1615
- // libraries pass this as a Record. Header objects as input
1616
- // are unsupported.
1617
- ...(init ? (init.headers as Record<string, string>) : {}),
1341
+ const params = {
1342
+ accessToken: this.accessToken,
1343
+ fetchOptions: this.fetchOptions,
1618
1344
  }
1345
+ const repository = await this.getRepository(params)
1346
+ const ref = await this.#getResolvedRef(params)
1619
1347
 
1620
- if (cachedRepository.integrationFieldsRef) {
1621
- unsanitizedHeaders["Prismic-integration-field-ref"] =
1622
- cachedRepository.integrationFieldsRef
1348
+ const headers: NonNullable<RequestInitLike["headers"]> = {}
1349
+ headers["prismic-ref"] = ref
1350
+ if (this.accessToken) {
1351
+ headers["authorization"] = `Token ${this.accessToken}`
1623
1352
  }
1624
-
1625
- // Normalize header keys to lowercase. This prevents header
1626
- // conflicts between the Prismic client and the GraphQL
1627
- // client.
1628
- const headers: Record<string, string> = {}
1629
- for (const key in unsanitizedHeaders) {
1630
- if (unsanitizedHeaders[key]) {
1631
- headers[key.toLowerCase()] =
1632
- unsanitizedHeaders[key as keyof typeof unsanitizedHeaders]
1633
- }
1353
+ if (repository.integrationFieldsRef) {
1354
+ headers["prismic-integration-field-ref"] = repository.integrationFieldsRef
1355
+ }
1356
+ for (const [key, value] of Object.entries(init?.headers ?? {})) {
1357
+ headers[key.toLowerCase()] = value
1634
1358
  }
1635
1359
 
1636
- const url = new URL(
1637
- // Asserting `input` is a string since popular GraphQL
1638
- // libraries pass this as a string. Request objects as
1639
- // input are unsupported.
1640
- input as string,
1360
+ const url = new URL(typeof input === "string" ? input : input.url)
1361
+ const query = (url.searchParams.get("query") ?? "").replace(
1362
+ // Minify the query
1363
+ /(\n| )*( |{|})(\n| )*/gm,
1364
+ (_chars, _spaces, brackets) => brackets,
1641
1365
  )
1642
-
1643
- // This prevents the request from being cached unnecessarily.
1644
- // Without adding this `ref` param, re-running a query
1645
- // could return a locally cached response, even if the
1646
- // `ref` changed. This happens because the URL is
1647
- // identical when the `ref` is not included. Caches may ignore
1648
- // headers.
1649
- //
1650
- // The Prismic GraphQL API ignores the `ref` param.
1366
+ url.searchParams.set("query", query)
1367
+ // Only used to prevent caching; caches ignore header differences
1651
1368
  url.searchParams.set("ref", ref)
1652
1369
 
1653
- const query = url.searchParams.get("query")
1654
- if (query) {
1655
- url.searchParams.set(
1656
- "query",
1657
- // Compress the GraphQL query (if it exists) by
1658
- // removing whitespace. This is done to
1659
- // optimize the query size and avoid
1660
- // hitting the upper limit of GET requests
1661
- // (2048 characters).
1662
- minifyGraphQLQuery(query),
1663
- )
1664
- }
1665
-
1666
1370
  return (await this.fetchFn(url.toString(), {
1667
1371
  ...init,
1668
1372
  headers,
1669
1373
  })) as Response
1670
1374
  }
1671
1375
 
1672
- /**
1673
- * Returns a cached version of `getRepository` with a TTL.
1674
- *
1675
- * @returns Cached repository metadata.
1676
- */
1677
- private async getCachedRepository(params?: FetchParams): Promise<Repository> {
1678
- if (
1679
- !this.cachedRepository ||
1680
- Date.now() >= this.cachedRepositoryExpiration
1681
- ) {
1682
- this.cachedRepository = await this.getRepository(params)
1683
- this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL
1684
- }
1685
-
1686
- return this.cachedRepository
1687
- }
1688
-
1689
1376
  /**
1690
1377
  * Returns the ref needed to query based on the client's current state. This
1691
1378
  * method may make a network request to fetch a ref or resolve the user's ref
1692
1379
  * thunk.
1693
1380
  *
1694
- * If auto previews are enabled, the preview ref takes priority if available.
1381
+ * If auto previews are enabled, the preview ref takes priority.
1695
1382
  *
1696
1383
  * The following strategies are used depending on the client's state:
1697
1384
  *
@@ -1706,185 +1393,152 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1706
1393
  * release is fetched.
1707
1394
  * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
1708
1395
  * to the master ref if the ref is not a string.
1709
- *
1710
- * @returns The ref to use during a query.
1711
1396
  */
1712
- private async getResolvedRefString(params?: FetchParams): Promise<string> {
1713
- if (this.refState.autoPreviewsEnabled) {
1714
- let previewRef: string | undefined
1715
-
1716
- let cookieJar: string | null | undefined
1717
-
1718
- if (this.refState.httpRequest?.headers) {
1719
- if (
1720
- "get" in this.refState.httpRequest.headers &&
1721
- typeof this.refState.httpRequest.headers.get === "function"
1722
- ) {
1723
- // Web API Headers
1724
- cookieJar = this.refState.httpRequest.headers.get("cookie")
1725
- } else if ("cookie" in this.refState.httpRequest.headers) {
1726
- // Express-style headers
1727
- cookieJar = this.refState.httpRequest.headers.cookie
1728
- }
1729
- } else if (globalThis.document?.cookie) {
1730
- cookieJar = globalThis.document.cookie
1731
- }
1732
-
1733
- if (cookieJar) {
1734
- previewRef = getPreviewCookie(cookieJar)
1735
- }
1736
-
1397
+ async #getResolvedRef(
1398
+ params?: Pick<BuildQueryURLArgs, "accessToken"> & FetchParams,
1399
+ ) {
1400
+ if (this.#autoPreviews) {
1401
+ const cookies = this.#autoPreviewsRequest?.headers
1402
+ ? "get" in this.#autoPreviewsRequest.headers
1403
+ ? this.#autoPreviewsRequest.headers.get("cookie")
1404
+ : this.#autoPreviewsRequest.headers.cookie
1405
+ : globalThis.document?.cookie
1406
+ const previewRef = getPreviewCookie(cookies ?? "")
1737
1407
  if (previewRef) {
1738
1408
  return previewRef
1739
1409
  }
1740
1410
  }
1741
1411
 
1742
- const cachedRepository = await this.getCachedRepository(params)
1743
-
1744
- const refModeType = this.refState.mode
1745
- if (refModeType === RefStateMode.ReleaseID) {
1746
- return findRefByID(cachedRepository.refs, this.refState.releaseID).ref
1747
- } else if (refModeType === RefStateMode.ReleaseLabel) {
1748
- return findRefByLabel(cachedRepository.refs, this.refState.releaseLabel)
1749
- .ref
1750
- } else if (refModeType === RefStateMode.Manual) {
1751
- const res = await castThunk(this.refState.ref)()
1752
-
1753
- if (typeof res === "string") {
1754
- return res
1755
- }
1412
+ const ref = await this.#getRef?.(params)
1413
+ if (ref) {
1414
+ return ref
1756
1415
  }
1757
1416
 
1758
- return findMasterRef(cachedRepository.refs).ref
1417
+ const masterRef = await this.getMasterRef(params)
1418
+ return masterRef.ref
1759
1419
  }
1760
1420
 
1761
1421
  /**
1762
- * The private implementation of `this.get`. It returns the API response and
1763
- * the URL used to make the request. The URL is sometimes used in the public
1764
- * method to include in thrown errors.
1765
- *
1766
- * This method retries requests that throw `RefNotFoundError` or
1767
- * `RefExpiredError`. It contains special logic to retry with the latest
1768
- * master ref, provided in the API's error message.
1769
- *
1770
- * @typeParam TDocument - Type of Prismic documents returned.
1771
- *
1772
- * @param params - Parameters to filter, sort, and paginate results.
1773
- *
1774
- * @returns An object containing the paginated response containing the result
1775
- * of the query and the URL used to make the API request.
1422
+ * Performs a low-level Content API request with the given parameters.
1423
+ * Automatically retries if an invalid ref is used.
1776
1424
  */
1777
- private async _get<TDocument extends TDocuments>(
1425
+ async #internalGet(
1778
1426
  params?: Partial<BuildQueryURLArgs> & FetchParams,
1779
- attemptCount = 0,
1780
- ): Promise<{ data: Query<TDocument>; url: string }> {
1427
+ attempt = 1,
1428
+ ): Promise<ResponseLike> {
1781
1429
  const url = await this.buildQueryURL(params)
1430
+ const response = await this.#request(new URL(url), params)
1431
+
1432
+ if (response.ok) {
1433
+ return response
1434
+ }
1782
1435
 
1783
1436
  try {
1784
- const response = await this.#request(new URL(url), params)
1785
- switch (response.status) {
1786
- case 200: {
1787
- try {
1788
- return {
1789
- data: (await response.clone().json()) as Query<TDocument>,
1790
- url,
1791
- }
1792
- } catch {
1793
- throw new PrismicError(undefined, url, await response.text())
1794
- }
1795
- }
1796
- case 400: {
1797
- const json = await response.json()
1798
- throw new ParsingError(json.message, url, json)
1799
- }
1800
- case 401: {
1801
- const json = await response.json()
1802
- throw new ForbiddenError(json.message, url, json)
1803
- }
1804
- case 404: {
1805
- const json = await response.json()
1806
- switch (json.type) {
1807
- case "api_notfound_error": {
1808
- throw new RefNotFoundError(json.message, url, json)
1809
- }
1810
- case "api_security_error": {
1811
- if (/preview token.*expired/i.test(json.message)) {
1812
- throw new PreviewTokenExpiredError(json.message, url, json)
1813
- }
1814
- }
1815
- default: {
1816
- throw new NotFoundError(json.message, url, json)
1817
- }
1818
- }
1819
- }
1820
- case 410: {
1821
- const json = await response.json()
1822
- throw new RefExpiredError(json.message, url, json)
1823
- }
1824
- default: {
1825
- throw new PrismicError(undefined, url, await response.text())
1826
- }
1827
- }
1437
+ return await this.#throwContentAPIError(response, url)
1828
1438
  } catch (error) {
1829
1439
  if (
1830
- !(
1831
- error instanceof RefNotFoundError || error instanceof RefExpiredError
1832
- ) ||
1833
- attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1
1440
+ (error instanceof RefNotFoundError ||
1441
+ error instanceof RefExpiredError) &&
1442
+ attempt < MAX_INVALID_REF_RETRY_ATTEMPTS
1834
1443
  ) {
1835
- throw error
1836
- }
1444
+ // If no explicit ref is given (i.e. the master ref from
1445
+ // /api/v2 is used), clear the cached repository value.
1446
+ // Clearing the cached value prevents other methods from
1447
+ // using a known-stale ref.
1448
+ if (!params?.ref) {
1449
+ this.#cachedRepository = undefined
1450
+ }
1837
1451
 
1838
- // If no explicit ref is given (i.e. the master ref from
1839
- // /api/v2 is used), clear the cached repository value.
1840
- // Clearing the cached value prevents other methods from
1841
- // using a known-stale ref.
1842
- if (!params?.ref) {
1843
- this.cachedRepository = undefined
1844
- }
1452
+ const masterRef = error.message.match(/master ref is: (?<ref>.*)$/i)
1453
+ ?.groups?.ref
1454
+ if (!masterRef) {
1455
+ throw error
1456
+ }
1845
1457
 
1846
- const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)
1847
- ?.groups?.ref
1848
- if (!masterRef) {
1849
- throw error
1850
- }
1458
+ const badRef = new URL(url).searchParams.get("ref")
1459
+ const issue = error instanceof RefNotFoundError ? "invalid" : "expired"
1460
+ throttledWarn(
1461
+ `[@prismicio/client] The ref (${badRef}) was ${issue}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`,
1462
+ )
1851
1463
 
1852
- const badRef = new URL(url).searchParams.get("ref")
1853
- const issue = error instanceof RefNotFoundError ? "invalid" : "expired"
1854
- throttledLog(
1855
- `[@prismicio/client] The ref (${badRef}) was ${issue}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`,
1856
- { level: "warn" },
1857
- )
1464
+ return await this.#internalGet(
1465
+ { ...params, ref: masterRef },
1466
+ attempt + 1,
1467
+ )
1468
+ }
1858
1469
 
1859
- return await this._get({ ...params, ref: masterRef }, attemptCount + 1)
1470
+ throw error
1860
1471
  }
1861
1472
  }
1862
1473
 
1863
1474
  /**
1864
- * Makes an HTTP request using the client's configured fetch function and
1865
- * options.
1866
- *
1867
- * @param url - The URL to request.
1868
- * @param params - Fetch options.
1869
- *
1870
- * @returns The response from the fetch request.
1475
+ * Throws an error based on a Content API response. Only call in known-errored
1476
+ * states.
1871
1477
  */
1872
- async #request(url: URL, params?: RequestInitLike): Promise<ResponseLike> {
1873
- return await request(url, this._buildRequestInit(params), this.fetchFn)
1478
+ async #throwContentAPIError(
1479
+ response: ResponseLike,
1480
+ url: string,
1481
+ ): Promise<never> {
1482
+ switch (response.status) {
1483
+ case 400: {
1484
+ const json = await response.clone().json()
1485
+ throw new ParsingError(json.message, url, json)
1486
+ }
1487
+ case 401: {
1488
+ const json = await response.clone().json()
1489
+ throw new ForbiddenError(json.message, url, json)
1490
+ }
1491
+ case 404: {
1492
+ const json = await response.clone().json()
1493
+ switch (json.type) {
1494
+ case "api_notfound_error": {
1495
+ throw new RefNotFoundError(json.message, url, json)
1496
+ }
1497
+ case "api_security_error": {
1498
+ if (/preview token.*expired/i.test(json.message)) {
1499
+ throw new PreviewTokenExpiredError(json.message, url, json)
1500
+ }
1501
+ }
1502
+ default: {
1503
+ throw new NotFoundError(json.message, url, json)
1504
+ }
1505
+ }
1506
+ }
1507
+ case 410: {
1508
+ const json = await response.clone().json()
1509
+ throw new RefExpiredError(json.message, url, json)
1510
+ }
1511
+ default: {
1512
+ throw new PrismicError(undefined, url, await response.text())
1513
+ }
1514
+ }
1874
1515
  }
1875
1516
 
1876
- protected _buildRequestInit(params?: FetchParams): RequestInitLike {
1877
- return {
1878
- ...this.fetchOptions,
1879
- ...params?.fetchOptions,
1880
- headers: {
1881
- ...this.fetchOptions?.headers,
1882
- ...params?.fetchOptions?.headers,
1517
+ /** Performs a low-level network request with the client's fetch options. */
1518
+ async #request(url: URL, params?: FetchParams): Promise<ResponseLike> {
1519
+ return await request(
1520
+ url,
1521
+ {
1522
+ ...this.fetchOptions,
1523
+ ...params?.fetchOptions,
1524
+ headers: {
1525
+ ...this.fetchOptions?.headers,
1526
+ ...params?.fetchOptions?.headers,
1527
+ },
1528
+ signal:
1529
+ params?.fetchOptions?.signal ||
1530
+ params?.signal ||
1531
+ this.fetchOptions?.signal,
1883
1532
  },
1884
- signal:
1885
- params?.fetchOptions?.signal ||
1886
- params?.signal ||
1887
- this.fetchOptions?.signal,
1888
- }
1533
+ this.fetchFn,
1534
+ )
1889
1535
  }
1890
1536
  }
1537
+
1538
+ /** Appends filters to a params object. */
1539
+ function appendFilters<T extends Pick<BuildQueryURLArgs, "filters">>(
1540
+ params = {} as T,
1541
+ ...filters: string[]
1542
+ ): T & { filters: string[] } {
1543
+ return { ...params, filters: [...(params.filters ?? []), ...filters] }
1544
+ }