@prismicio/client 7.21.0 → 7.21.1-pr.425.573f39f

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 +683 -1029
  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/dist/Client.js CHANGED
@@ -1,1262 +1,926 @@
1
- import { appendFilters } from "./lib/appendFilters.js";
2
- import { castThunk } from "./lib/castThunk.js";
1
+ import { filter } from "./filter.js";
3
2
  import { devMsg } from "./lib/devMsg.js";
4
- import { everyTagFilter } from "./lib/everyTagFilter.js";
5
- import { findMasterRef } from "./lib/findMasterRef.js";
6
- import { findRefByID } from "./lib/findRefByID.js";
7
- import { findRefByLabel } from "./lib/findRefByLabel.js";
8
3
  import { getPreviewCookie } from "./lib/getPreviewCookie.js";
9
- import { minifyGraphQLQuery } from "./lib/minifyGraphQLQuery.js";
10
4
  import { request } from "./lib/request.js";
11
- import { someTagsFilter } from "./lib/someTagsFilter.js";
12
- import { throttledLog } from "./lib/throttledLog.js";
13
- import { typeFilter } from "./lib/typeFilter.js";
14
- import { ForbiddenError } from "./errors/ForbiddenError.js";
15
- import { NotFoundError } from "./errors/NotFoundError.js";
16
- import { ParsingError } from "./errors/ParsingError.js";
17
- import { PreviewTokenExpiredError } from "./errors/PreviewTokenExpired.js";
18
- import { PrismicError } from "./errors/PrismicError.js";
19
- import { RefExpiredError } from "./errors/RefExpiredError.js";
20
- import { RefNotFoundError } from "./errors/RefNotFoundError.js";
21
- import { RepositoryNotFoundError } from "./errors/RepositoryNotFoundError.js";
5
+ import { throttledWarn } from "./lib/throttledWarn.js";
6
+ import { ForbiddenError, NotFoundError, ParsingError, PreviewTokenExpiredError, PrismicError, RefExpiredError, RefNotFoundError, RepositoryNotFoundError } from "./errors.js";
22
7
  import { asLink } from "./helpers/asLink.js";
23
8
  import { buildQueryURL } from "./buildQueryURL.js";
24
- import { filter } from "./filter.js";
25
9
  import { getRepositoryEndpoint } from "./getRepositoryEndpoint.js";
26
10
  import { getRepositoryName } from "./getRepositoryName.js";
27
11
  import { isRepositoryEndpoint } from "./isRepositoryEndpoint.js";
12
+
13
+ //#region src/Client.ts
28
14
  const MAX_PAGE_SIZE = 100;
29
15
  const REPOSITORY_CACHE_TTL = 5e3;
30
16
  const GET_ALL_QUERY_DELAY = 500;
31
17
  const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
32
- var RefStateMode;
33
- (function(RefStateMode2) {
34
- RefStateMode2["Master"] = "Master";
35
- RefStateMode2["ReleaseID"] = "ReleaseID";
36
- RefStateMode2["ReleaseLabel"] = "ReleaseLabel";
37
- RefStateMode2["Manual"] = "Manual";
38
- })(RefStateMode || (RefStateMode = {}));
39
- class Client {
40
- /**
41
- * The function used to make network requests to the Prismic REST API. In
42
- * environments where a global `fetch` function does not exist, such as
43
- * Node.js, this function must be provided.
44
- */
45
- fetchFn;
46
- fetchOptions;
47
- #repositoryName;
48
- /**
49
- * The Prismic repository's name.
50
- */
51
- set repositoryName(value) {
52
- this.#repositoryName = value;
53
- }
54
- /**
55
- * The Prismic repository's name.
56
- */
57
- get repositoryName() {
58
- if (!this.#repositoryName) {
59
- throw new PrismicError(`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")}`, void 0, void 0);
60
- }
61
- return this.#repositoryName;
62
- }
63
- /**
64
- * The Prismic REST API V2 endpoint for the repository (use
65
- * `prismic.getRepositoryEndpoint` for the default endpoint).
66
- */
67
- documentAPIEndpoint;
68
- /**
69
- * The Prismic REST API V2 endpoint for the repository (use
70
- * `prismic.getRepositoryEndpoint` for the default endpoint).
71
- *
72
- * @deprecated Use `documentAPIEndpoint` instead.
73
- */
74
- // TODO: Remove in v8.
75
- set endpoint(value) {
76
- this.documentAPIEndpoint = value;
77
- }
78
- /**
79
- * The Prismic REST API V2 endpoint for the repository (use
80
- * `prismic.getRepositoryEndpoint` for the default endpoint).
81
- *
82
- * @deprecated Use `documentAPIEndpoint` instead.
83
- */
84
- // TODO: Remove in v8.
85
- get endpoint() {
86
- return this.documentAPIEndpoint;
87
- }
88
- /**
89
- * The secure token for accessing the API (only needed if your repository is
90
- * set to private).
91
- *
92
- * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
93
- */
94
- accessToken;
95
- /**
96
- * A list of route resolver objects that define how a document's `url` field
97
- * is resolved.
98
- *
99
- * {@link https://prismic.io/docs/route-resolver}
100
- */
101
- routes;
102
- /**
103
- * The `brokenRoute` option allows you to define the route populated in the
104
- * `url` property for broken link or content relationship fields. A broken
105
- * link is a link or content relationship field whose linked document has been
106
- * unpublished or deleted.
107
- *
108
- * {@link https://prismic.io/docs/route-resolver}
109
- */
110
- brokenRoute;
111
- /**
112
- * Default parameters that will be sent with each query. These parameters can
113
- * be overridden on each query if needed.
114
- */
115
- defaultParams;
116
- /**
117
- * The client's ref mode state. This determines which ref is used during
118
- * queries.
119
- */
120
- refState = {
121
- mode: RefStateMode.Master,
122
- autoPreviewsEnabled: true
123
- };
124
- /**
125
- * Cached repository value.
126
- */
127
- cachedRepository;
128
- /**
129
- * Timestamp at which the cached repository data is considered stale.
130
- */
131
- cachedRepositoryExpiration = 0;
132
- /**
133
- * Creates a Prismic client that can be used to query a repository.
134
- *
135
- * If used in an environment where a global `fetch` function is unavailable,
136
- * such as in some Node.js versions, the `fetch` option must be provided as
137
- * part of the `options` parameter.
138
- *
139
- * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
140
- * API V2 endpoint for the repository.
141
- * @param options - Configuration that determines how content will be queried
142
- * from the Prismic repository.
143
- *
144
- * @returns A client that can query content from the repository.
145
- */
146
- constructor(repositoryNameOrEndpoint, options = {}) {
147
- this.fetchOptions = options.fetchOptions;
148
- if (typeof options.fetch === "function") {
149
- this.fetchFn = options.fetch;
150
- } else if (typeof globalThis.fetch === "function") {
151
- this.fetchFn = globalThis.fetch;
152
- } else {
153
- throw new PrismicError("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.", void 0, void 0);
154
- }
155
- if (this.fetchFn === globalThis.fetch) {
156
- this.fetchFn = this.fetchFn.bind(globalThis);
157
- }
158
- if ((options.documentAPIEndpoint || isRepositoryEndpoint(repositoryNameOrEndpoint)) && process.env.NODE_ENV === "development") {
159
- const documentAPIEndpoint = options.documentAPIEndpoint || repositoryNameOrEndpoint;
160
- if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(documentAPIEndpoint)) {
161
- throw new PrismicError("@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.", void 0, void 0);
162
- }
163
- const hostname = new URL(documentAPIEndpoint).hostname.toLowerCase();
164
- if (hostname.endsWith(".prismic.io") && !hostname.endsWith(".cdn.prismic.io")) {
165
- console.warn(`[@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")}`);
166
- }
167
- if (options.documentAPIEndpoint && isRepositoryEndpoint(repositoryNameOrEndpoint) && repositoryNameOrEndpoint !== options.documentAPIEndpoint) {
168
- console.warn(`[@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")}`);
169
- }
170
- }
171
- if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
172
- this.documentAPIEndpoint = repositoryNameOrEndpoint;
173
- try {
174
- this.repositoryName = getRepositoryName(repositoryNameOrEndpoint);
175
- } catch (error) {
176
- console.warn(`[@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")}`);
177
- }
178
- } else {
179
- this.documentAPIEndpoint = options.documentAPIEndpoint || getRepositoryEndpoint(repositoryNameOrEndpoint);
180
- this.repositoryName = repositoryNameOrEndpoint;
181
- }
182
- this.accessToken = options.accessToken;
183
- this.routes = options.routes;
184
- this.brokenRoute = options.brokenRoute;
185
- this.defaultParams = options.defaultParams;
186
- if (options.ref) {
187
- this.queryContentFromRef(options.ref);
188
- }
189
- this.graphQLFetch = this.graphQLFetch.bind(this);
190
- }
191
- /**
192
- * Enables the client to automatically query content from a preview session if
193
- * one is active in browser environments. This is enabled by default in the
194
- * browser.
195
- *
196
- * For server environments, use `enableAutoPreviewsFromReq`.
197
- *
198
- * @example
199
- *
200
- * ```ts
201
- * client.enableAutoPreviews()
202
- * ```
203
- *
204
- * @see enableAutoPreviewsFromReq
205
- */
206
- enableAutoPreviews() {
207
- this.refState.autoPreviewsEnabled = true;
208
- }
209
- /**
210
- * Enables the client to automatically query content from a preview session if
211
- * one is active in server environments. This is disabled by default on the
212
- * server.
213
- *
214
- * For browser environments, use `enableAutoPreviews`.
215
- *
216
- * @example
217
- *
218
- * ```ts
219
- * // In an express app
220
- * app.get("/", function (req, res) {
221
- * client.enableAutoPreviewsFromReq(req)
222
- * })
223
- * ```
224
- *
225
- * @param req - An HTTP server request object containing the request's
226
- * cookies.
227
- */
228
- enableAutoPreviewsFromReq(req) {
229
- this.refState.httpRequest = req;
230
- this.refState.autoPreviewsEnabled = true;
231
- }
232
- /**
233
- * Disables the client from automatically querying content from a preview
234
- * session if one is active.
235
- *
236
- * Automatic preview content querying is enabled by default unless this method
237
- * is called.
238
- *
239
- * @example
240
- *
241
- * ```ts
242
- * client.disableAutoPreviews()
243
- * ```
244
- */
245
- disableAutoPreviews() {
246
- this.refState.autoPreviewsEnabled = false;
247
- }
248
- /**
249
- * Queries content from the Prismic repository.
250
- *
251
- * @example
252
- *
253
- * ```ts
254
- * const response = await client.get()
255
- * ```
256
- *
257
- * @typeParam TDocument - Type of Prismic documents returned.
258
- *
259
- * @param params - Parameters to filter, sort, and paginate results.
260
- *
261
- * @returns A paginated response containing the result of the query.
262
- */
263
- async get(params) {
264
- const { data } = await this._get(params);
265
- return data;
266
- }
267
- /**
268
- * Queries content from the Prismic repository and returns only the first
269
- * result, if any.
270
- *
271
- * @example
272
- *
273
- * ```ts
274
- * const document = await client.getFirst()
275
- * ```
276
- *
277
- * @typeParam TDocument - Type of the Prismic document returned.
278
- *
279
- * @param params - Parameters to filter, sort, and paginate results.
280
- *
281
- * @returns The first result of the query, if any.
282
- */
283
- async getFirst(params) {
284
- const actualParams = { ...params };
285
- if (!(params && params.page) && !params?.pageSize) {
286
- actualParams.pageSize = this.defaultParams?.pageSize ?? 1;
287
- }
288
- const { data, url } = await this._get(actualParams);
289
- const firstResult = data.results[0];
290
- if (firstResult) {
291
- return firstResult;
292
- }
293
- throw new NotFoundError("No documents were returned", url, void 0);
294
- }
295
- /**
296
- * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
297
- * require more resources than other methods. Prefer using other methods that
298
- * filter by filters such as `getAllByType`.
299
- *
300
- * Queries content from the Prismic repository and returns all matching
301
- * content. If no filters are provided, all documents will be fetched.
302
- *
303
- * This method may make multiple network requests to query all matching
304
- * content.
305
- *
306
- * @example
307
- *
308
- * ```ts
309
- * const response = await client.dangerouslyGetAll()
310
- * ```
311
- *
312
- * @typeParam TDocument - Type of Prismic documents returned.
313
- *
314
- * @param params - Parameters to filter, sort, and paginate results.
315
- *
316
- * @returns A list of documents matching the query.
317
- */
318
- async dangerouslyGetAll(params = {}) {
319
- const { limit = Infinity, ...actualParams } = params;
320
- const resolvedParams = {
321
- ...actualParams,
322
- pageSize: Math.min(limit, actualParams.pageSize || this.defaultParams?.pageSize || MAX_PAGE_SIZE)
323
- };
324
- const documents = [];
325
- let latestResult;
326
- while ((!latestResult || latestResult.next_page) && documents.length < limit) {
327
- const page = latestResult ? latestResult.page + 1 : void 0;
328
- latestResult = await this.get({ ...resolvedParams, page });
329
- documents.push(...latestResult.results);
330
- if (latestResult.next_page) {
331
- await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));
332
- }
333
- }
334
- return documents.slice(0, limit);
335
- }
336
- /**
337
- * Queries a document from the Prismic repository with a specific ID.
338
- *
339
- * @remarks
340
- * A document's UID is different from its ID. An ID is automatically generated
341
- * for all documents and is made available on its `id` property. A UID is
342
- * provided in the Prismic editor and is unique among all documents of its
343
- * custom type.
344
- *
345
- * @example
346
- *
347
- * ```ts
348
- * const document = await client.getByID("WW4bKScAAMAqmluX")
349
- * ```
350
- *
351
- * @typeParam TDocument- Type of the Prismic document returned.
352
- *
353
- * @param id - ID of the document.
354
- * @param params - Parameters to filter, sort, and paginate the results.
355
- *
356
- * @returns The document with an ID matching the `id` parameter, if a matching
357
- * document exists.
358
- */
359
- async getByID(id, params) {
360
- return await this.getFirst(appendFilters(params, filter.at("document.id", id)));
361
- }
362
- /**
363
- * Queries documents from the Prismic repository with specific IDs.
364
- *
365
- * @remarks
366
- * A document's UID is different from its ID. An ID is automatically generated
367
- * for all documents and is made available on its `id` property. A UID is
368
- * provided in the Prismic editor and is unique among all documents of its
369
- * custom type.
370
- *
371
- * @example
372
- *
373
- * ```ts
374
- * const response = await client.getByIDs([
375
- * "WW4bKScAAMAqmluX",
376
- * "U1kTRgEAAC8A5ldS",
377
- * ])
378
- * ```
379
- *
380
- * @typeParam TDocument - Type of Prismic documents returned.
381
- *
382
- * @param ids - A list of document IDs.
383
- * @param params - Parameters to filter, sort, and paginate the results.
384
- *
385
- * @returns A paginated response containing documents with IDs matching the
386
- * `ids` parameter.
387
- */
388
- async getByIDs(ids, params) {
389
- return await this.get(appendFilters(params, filter.in("document.id", ids)));
390
- }
391
- /**
392
- * Queries all documents from the Prismic repository with specific IDs.
393
- *
394
- * This method may make multiple network requests to query all matching
395
- * content.
396
- *
397
- * @remarks
398
- * A document's UID is different from its ID. An ID is automatically generated
399
- * for all documents and is made available on its `id` property. A UID is
400
- * provided in the Prismic editor and is unique among all documents of its
401
- * custom type.
402
- *
403
- * @example
404
- *
405
- * ```ts
406
- * const response = await client.getAllByIDs([
407
- * "WW4bKScAAMAqmluX",
408
- * "U1kTRgEAAC8A5ldS",
409
- * ])
410
- * ```
411
- *
412
- * @typeParam TDocument - Type of Prismic documents returned.
413
- *
414
- * @param ids - A list of document IDs.
415
- * @param params - Parameters to filter, sort, and paginate the results.
416
- *
417
- * @returns A list of documents with IDs matching the `ids` parameter.
418
- */
419
- async getAllByIDs(ids, params) {
420
- return await this.dangerouslyGetAll(appendFilters(params, filter.in("document.id", ids)));
421
- }
422
- /**
423
- * Queries a document from the Prismic repository with a specific UID and
424
- * custom type.
425
- *
426
- * @remarks
427
- * A document's UID is different from its ID. An ID is automatically generated
428
- * for all documents and is made available on its `id` property. A UID is
429
- * provided in the Prismic editor and is unique among all documents of its
430
- * custom type.
431
- *
432
- * @example
433
- *
434
- * ```ts
435
- * const document = await client.getByUID("blog_post", "my-first-post")
436
- * ```
437
- *
438
- * @typeParam TDocument - Type of the Prismic document returned.
439
- *
440
- * @param documentType - The API ID of the document's custom type.
441
- * @param uid - UID of the document.
442
- * @param params - Parameters to filter, sort, and paginate the results.
443
- *
444
- * @returns The document with a UID matching the `uid` parameter, if a
445
- * matching document exists.
446
- */
447
- async getByUID(documentType, uid, params) {
448
- return await this.getFirst(appendFilters(params, [
449
- typeFilter(documentType),
450
- filter.at(`my.${documentType}.uid`, uid)
451
- ]));
452
- }
453
- /**
454
- * Queries document from the Prismic repository with specific UIDs and Custom
455
- * Type.
456
- *
457
- * @remarks
458
- * A document's UID is different from its ID. An ID is automatically generated
459
- * for all documents and is made available on its `id` property. A UID is
460
- * provided in the Prismic editor and is unique among all documents of its
461
- * custom type.
462
- *
463
- * @example
464
- *
465
- * ```ts
466
- * const document = await client.getByUIDs("blog_post", [
467
- * "my-first-post",
468
- * "my-second-post",
469
- * ])
470
- * ```
471
- *
472
- * @typeParam TDocument - Type of the Prismic document returned.
473
- *
474
- * @param documentType - The API ID of the document's custom type.
475
- * @param uids - A list of document UIDs.
476
- * @param params - Parameters to filter, sort, and paginate the results.
477
- *
478
- * @returns A paginated response containing documents with UIDs matching the
479
- * `uids` parameter.
480
- */
481
- async getByUIDs(documentType, uids, params) {
482
- return await this.get(appendFilters(params, [
483
- typeFilter(documentType),
484
- filter.in(`my.${documentType}.uid`, uids)
485
- ]));
486
- }
487
- /**
488
- * Queries all documents from the Prismic repository with specific UIDs and
489
- * custom type.
490
- *
491
- * This method may make multiple network requests to query all matching
492
- * content.
493
- *
494
- * @remarks
495
- * A document's UID is different from its ID. An ID is automatically generated
496
- * for all documents and is made available on its `id` property. A UID is
497
- * provided in the Prismic editor and is unique among all documents of its
498
- * custom type.
499
- *
500
- * @example
501
- *
502
- * ```ts
503
- * const response = await client.getAllByUIDs([
504
- * "my-first-post",
505
- * "my-second-post",
506
- * ])
507
- * ```
508
- *
509
- * @typeParam TDocument - Type of Prismic documents returned.
510
- *
511
- * @param documentType - The API ID of the document's custom type.
512
- * @param uids - A list of document UIDs.
513
- * @param params - Parameters to filter, sort, and paginate the results.
514
- *
515
- * @returns A list of documents with UIDs matching the `uids` parameter.
516
- */
517
- async getAllByUIDs(documentType, uids, params) {
518
- return await this.dangerouslyGetAll(appendFilters(params, [
519
- typeFilter(documentType),
520
- filter.in(`my.${documentType}.uid`, uids)
521
- ]));
522
- }
523
- /**
524
- * Queries a singleton document from the Prismic repository for a specific
525
- * custom type.
526
- *
527
- * @remarks
528
- * A singleton document is one that is configured in Prismic to only allow one
529
- * instance. For example, a repository may be configured to contain just one
530
- * Settings document. This is in contrast to a repeatable custom type which
531
- * allows multiple instances of itself.
532
- *
533
- * @example
534
- *
535
- * ```ts
536
- * const document = await client.getSingle("settings")
537
- * ```
538
- *
539
- * @typeParam TDocument - Type of the Prismic document returned.
540
- *
541
- * @param documentType - The API ID of the singleton custom type.
542
- * @param params - Parameters to filter, sort, and paginate the results.
543
- *
544
- * @returns The singleton document for the custom type, if a matching document
545
- * exists.
546
- */
547
- async getSingle(documentType, params) {
548
- return await this.getFirst(appendFilters(params, typeFilter(documentType)));
549
- }
550
- /**
551
- * Queries documents from the Prismic repository for a specific custom type.
552
- *
553
- * Use `getAllByType` instead if you need to query all documents for a
554
- * specific custom type.
555
- *
556
- * @example
557
- *
558
- * ```ts
559
- * const response = await client.getByType("blog_post")
560
- * ```
561
- *
562
- * @typeParam TDocument - Type of Prismic documents returned.
563
- *
564
- * @param documentType - The API ID of the custom type.
565
- * @param params - Parameters to filter, sort, and paginate the results.
566
- *
567
- * @returns A paginated response containing documents of the custom type.
568
- */
569
- async getByType(documentType, params) {
570
- return await this.get(appendFilters(params, typeFilter(documentType)));
571
- }
572
- /**
573
- * Queries all documents from the Prismic repository for a specific Custom
574
- * Type.
575
- *
576
- * This method may make multiple network requests to query all matching
577
- * content.
578
- *
579
- * @example
580
- *
581
- * ```ts
582
- * const response = await client.getByType("blog_post")
583
- * ```
584
- *
585
- * @typeParam TDocument - Type of Prismic documents returned.
586
- *
587
- * @param documentType - The API ID of the custom type.
588
- * @param params - Parameters to filter, sort, and paginate the results.
589
- *
590
- * @returns A list of all documents of the custom type.
591
- */
592
- async getAllByType(documentType, params) {
593
- return await this.dangerouslyGetAll(appendFilters(params, typeFilter(documentType)));
594
- }
595
- /**
596
- * Queries documents from the Prismic repository with a specific tag.
597
- *
598
- * Use `getAllByTag` instead if you need to query all documents with a
599
- * specific tag.
600
- *
601
- * @example
602
- *
603
- * ```ts
604
- * const response = await client.getByTag("food")
605
- * ```
606
- *
607
- * @typeParam TDocument - Type of Prismic documents returned.
608
- *
609
- * @param tag - The tag that must be included on a document.
610
- * @param params - Parameters to filter, sort, and paginate the results.
611
- *
612
- * @returns A paginated response containing documents with the tag.
613
- */
614
- async getByTag(tag, params) {
615
- return await this.get(appendFilters(params, someTagsFilter(tag)));
616
- }
617
- /**
618
- * Queries all documents from the Prismic repository with a specific tag.
619
- *
620
- * This method may make multiple network requests to query all matching
621
- * content.
622
- *
623
- * @example
624
- *
625
- * ```ts
626
- * const response = await client.getAllByTag("food")
627
- * ```
628
- *
629
- * @typeParam TDocument - Type of Prismic documents returned.
630
- *
631
- * @param tag - The tag that must be included on a document.
632
- * @param params - Parameters to filter, sort, and paginate the results.
633
- *
634
- * @returns A list of all documents with the tag.
635
- */
636
- async getAllByTag(tag, params) {
637
- return await this.dangerouslyGetAll(appendFilters(params, someTagsFilter(tag)));
638
- }
639
- /**
640
- * Queries documents from the Prismic repository with specific tags. A
641
- * document must be tagged with all of the queried tags to be included.
642
- *
643
- * @example
644
- *
645
- * ```ts
646
- * const response = await client.getByEveryTag(["food", "fruit"])
647
- * ```
648
- *
649
- * @typeParam TDocument - Type of Prismic documents returned.
650
- *
651
- * @param tags - A list of tags that must be included on a document.
652
- * @param params - Parameters to filter, sort, and paginate the results.
653
- *
654
- * @returns A paginated response containing documents with the tags.
655
- */
656
- async getByEveryTag(tags, params) {
657
- return await this.get(appendFilters(params, everyTagFilter(tags)));
658
- }
659
- /**
660
- * Queries documents from the Prismic repository with specific tags. A
661
- * document must be tagged with all of the queried tags to be included.
662
- *
663
- * This method may make multiple network requests to query all matching
664
- * content.
665
- *
666
- * @example
667
- *
668
- * ```ts
669
- * const response = await client.getAllByEveryTag(["food", "fruit"])
670
- * ```
671
- *
672
- * @typeParam TDocument - Type of Prismic documents returned.
673
- *
674
- * @param tags - A list of tags that must be included on a document.
675
- * @param params - Parameters to filter, sort, and paginate the results.
676
- *
677
- * @returns A list of all documents with the tags.
678
- */
679
- async getAllByEveryTag(tags, params) {
680
- return await this.dangerouslyGetAll(appendFilters(params, everyTagFilter(tags)));
681
- }
682
- /**
683
- * Queries documents from the Prismic repository with specific tags. A
684
- * document must be tagged with at least one of the queried tags to be
685
- * included.
686
- *
687
- * @example
688
- *
689
- * ```ts
690
- * const response = await client.getByEveryTag(["food", "fruit"])
691
- * ```
692
- *
693
- * @typeParam TDocument - Type of Prismic documents returned.
694
- *
695
- * @param tags - A list of tags that must be included on a document.
696
- * @param params - Parameters to filter, sort, and paginate the results.
697
- *
698
- * @returns A paginated response containing documents with at least one of the
699
- * tags.
700
- */
701
- async getBySomeTags(tags, params) {
702
- return await this.get(appendFilters(params, someTagsFilter(tags)));
703
- }
704
- /**
705
- * Queries documents from the Prismic repository with specific tags. A
706
- * document must be tagged with at least one of the queried tags to be
707
- * included.
708
- *
709
- * This method may make multiple network requests to query all matching
710
- * content.
711
- *
712
- * @example
713
- *
714
- * ```ts
715
- * const response = await client.getAllBySomeTags(["food", "fruit"])
716
- * ```
717
- *
718
- * @typeParam TDocument - Type of Prismic documents returned.
719
- *
720
- * @param tags - A list of tags that must be included on a document.
721
- * @param params - Parameters to filter, sort, and paginate the results.
722
- *
723
- * @returns A list of all documents with at least one of the tags.
724
- */
725
- async getAllBySomeTags(tags, params) {
726
- return await this.dangerouslyGetAll(appendFilters(params, someTagsFilter(tags)));
727
- }
728
- /**
729
- * Returns metadata about the Prismic repository, such as its refs, releases,
730
- * and custom types.
731
- *
732
- * @returns Repository metadata.
733
- */
734
- async getRepository(params) {
735
- const url = new URL(this.documentAPIEndpoint);
736
- if (this.accessToken) {
737
- url.searchParams.set("access_token", this.accessToken);
738
- }
739
- const response = await this.#request(url, params);
740
- switch (response.status) {
741
- case 200: {
742
- return await response.json();
743
- }
744
- case 401: {
745
- const json = await response.json();
746
- throw new ForbiddenError(json.error, url.toString(), json);
747
- }
748
- case 404: {
749
- throw new RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
750
- }
751
- default: {
752
- throw new PrismicError(void 0, url.toString(), await response.text());
753
- }
754
- }
755
- }
756
- /**
757
- * Returns a list of all refs for the Prismic repository.
758
- *
759
- * Refs are used to identify which version of the repository's content should
760
- * be queried. All repositories will have at least one ref pointing to the
761
- * latest published content called the "master ref".
762
- *
763
- * @returns A list of all refs for the Prismic repository.
764
- */
765
- async getRefs(params) {
766
- const repository = await this.getRepository(params);
767
- return repository.refs;
768
- }
769
- /**
770
- * Returns a ref for the Prismic repository with a matching ID.
771
- *
772
- * @param id - ID of the ref.
773
- *
774
- * @returns The ref with a matching ID, if it exists.
775
- */
776
- async getRefByID(id, params) {
777
- const refs = await this.getRefs(params);
778
- return findRefByID(refs, id);
779
- }
780
- /**
781
- * Returns a ref for the Prismic repository with a matching label.
782
- *
783
- * @param label - Label of the ref.
784
- *
785
- * @returns The ref with a matching label, if it exists.
786
- */
787
- async getRefByLabel(label, params) {
788
- const refs = await this.getRefs(params);
789
- return findRefByLabel(refs, label);
790
- }
791
- /**
792
- * Returns the master ref for the Prismic repository. The master ref points to
793
- * the repository's latest published content.
794
- *
795
- * @returns The repository's master ref.
796
- */
797
- async getMasterRef(params) {
798
- const refs = await this.getRefs(params);
799
- return findMasterRef(refs);
800
- }
801
- /**
802
- * Returns a list of all Releases for the Prismic repository. Releases are
803
- * used to group content changes before publishing.
804
- *
805
- * @returns A list of all Releases for the Prismic repository.
806
- */
807
- async getReleases(params) {
808
- const refs = await this.getRefs(params);
809
- return refs.filter((ref) => !ref.isMasterRef);
810
- }
811
- /**
812
- * Returns a Release for the Prismic repository with a matching ID.
813
- *
814
- * @param id - ID of the Release.
815
- *
816
- * @returns The Release with a matching ID, if it exists.
817
- */
818
- async getReleaseByID(id, params) {
819
- const releases = await this.getReleases(params);
820
- return findRefByID(releases, id);
821
- }
822
- /**
823
- * Returns a Release for the Prismic repository with a matching label.
824
- *
825
- * @param label - Label of the ref.
826
- *
827
- * @returns The ref with a matching label, if it exists.
828
- */
829
- async getReleaseByLabel(label, params) {
830
- const releases = await this.getReleases(params);
831
- return findRefByLabel(releases, label);
832
- }
833
- /**
834
- * Returns a list of all tags used in the Prismic repository.
835
- *
836
- * @returns A list of all tags used in the repository.
837
- */
838
- async getTags(params) {
839
- const cachedRepository = await this.getCachedRepository(params);
840
- const form = cachedRepository.forms.tags;
841
- if (form) {
842
- const url = new URL(form.action);
843
- if (this.accessToken) {
844
- url.searchParams.set("access_token", this.accessToken);
845
- }
846
- const response = await this.#request(url, params);
847
- if (response.ok) {
848
- return await response.json();
849
- }
850
- }
851
- const repository = await this.getRepository(params);
852
- return repository.tags;
853
- }
854
- /**
855
- * Builds a URL used to query content from the Prismic repository.
856
- *
857
- * @param params - Parameters to filter, sort, and paginate the results.
858
- *
859
- * @returns A URL string that can be requested to query content.
860
- */
861
- async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
862
- const ref = params.ref || await this.getResolvedRefString({ signal, fetchOptions });
863
- const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, fetchOptions })).integrationFieldsRef || void 0;
864
- return buildQueryURL(this.documentAPIEndpoint, {
865
- ...this.defaultParams,
866
- ...params,
867
- ref,
868
- integrationFieldsRef,
869
- routes: params.routes || this.routes,
870
- brokenRoute: params.brokenRoute || this.brokenRoute,
871
- accessToken: params.accessToken || this.accessToken
872
- });
873
- }
874
- /**
875
- * Determines the URL for a previewed document during an active preview
876
- * session. The result of this method should be used to redirect the user to
877
- * the document's URL.
878
- *
879
- * @example
880
- *
881
- * ```ts
882
- * const url = client.resolvePreviewURL({
883
- * linkResolver: (document) => `/${document.uid}`
884
- * defaultURL: '/'
885
- * })
886
- * ```
887
- *
888
- * @param args - Arguments to configure the URL resolving.
889
- *
890
- * @returns The URL for the previewed document during an active preview
891
- * session. The user should be redirected to this URL.
892
- */
893
- async resolvePreviewURL(args) {
894
- let documentID = args.documentID;
895
- let previewToken = args.previewToken;
896
- if (typeof globalThis.location !== "undefined") {
897
- const searchParams = new URLSearchParams(globalThis.location.search);
898
- documentID = documentID || searchParams.get("documentId");
899
- previewToken = previewToken || searchParams.get("token");
900
- } else if (this.refState.httpRequest) {
901
- if ("query" in this.refState.httpRequest) {
902
- documentID = documentID || this.refState.httpRequest.query?.documentId;
903
- previewToken = previewToken || this.refState.httpRequest.query?.token;
904
- } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
905
- const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
906
- documentID = documentID || searchParams.get("documentId");
907
- previewToken = previewToken || searchParams.get("token");
908
- }
909
- }
910
- if (documentID != null && previewToken != null) {
911
- const document = await this.getByID(documentID, {
912
- ref: previewToken,
913
- lang: "*",
914
- signal: args.signal,
915
- fetchOptions: args.fetchOptions
916
- });
917
- const url = asLink(document, { linkResolver: args.linkResolver });
918
- if (typeof url === "string") {
919
- return url;
920
- }
921
- }
922
- return args.defaultURL;
923
- }
924
- /**
925
- * Configures the client to query the latest published content for all future
926
- * queries.
927
- *
928
- * If the `ref` parameter is provided during a query, it takes priority for
929
- * that query.
930
- *
931
- * @example
932
- *
933
- * ```ts
934
- * await client.queryLatestContent()
935
- * const document = await client.getByID("WW4bKScAAMAqmluX")
936
- * ```
937
- */
938
- queryLatestContent() {
939
- this.refState.mode = RefStateMode.Master;
940
- }
941
- /**
942
- * Configures the client to query content from a specific Release identified
943
- * by its ID for all future queries.
944
- *
945
- * If the `ref` parameter is provided during a query, it takes priority for
946
- * that query.
947
- *
948
- * @example
949
- *
950
- * ```ts
951
- * await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa")
952
- * const document = await client.getByID("WW4bKScAAMAqmluX")
953
- * ```
954
- *
955
- * @param releaseID - The ID of the Release.
956
- */
957
- queryContentFromReleaseByID(releaseID) {
958
- this.refState = {
959
- ...this.refState,
960
- mode: RefStateMode.ReleaseID,
961
- releaseID
962
- };
963
- }
964
- /**
965
- * Configures the client to query content from a specific Release identified
966
- * by its label for all future queries.
967
- *
968
- * If the `ref` parameter is provided during a query, it takes priority for
969
- * that query.
970
- *
971
- * @example
972
- *
973
- * ```ts
974
- * await client.queryContentFromReleaseByLabel("My Release")
975
- * const document = await client.getByID("WW4bKScAAMAqmluX")
976
- * ```
977
- *
978
- * @param releaseLabel - The label of the Release.
979
- */
980
- queryContentFromReleaseByLabel(releaseLabel) {
981
- this.refState = {
982
- ...this.refState,
983
- mode: RefStateMode.ReleaseLabel,
984
- releaseLabel
985
- };
986
- }
987
- /**
988
- * Configures the client to query content from a specific ref. The ref can be
989
- * provided as a string or a function.
990
- *
991
- * If a function is provided, the ref is fetched lazily before each query. The
992
- * function may also be asynchronous.
993
- *
994
- * @example
995
- *
996
- * ```ts
997
- * await client.queryContentFromRef("my-ref")
998
- * const document = await client.getByID("WW4bKScAAMAqmluX")
999
- * ```
1000
- *
1001
- * @param ref - The ref or a function that returns the ref from which to query
1002
- * content.
1003
- */
1004
- queryContentFromRef(ref) {
1005
- this.refState = {
1006
- ...this.refState,
1007
- mode: RefStateMode.Manual,
1008
- ref
1009
- };
1010
- }
1011
- /**
1012
- * A `fetch()` function to be used with GraphQL clients configured for
1013
- * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
1014
- * and Authorization headers. Queries will automatically be minified by
1015
- * removing whitespace where possible.
1016
- *
1017
- * @example
1018
- *
1019
- * ```ts
1020
- * const graphQLClient = new ApolloClient({
1021
- * link: new HttpLink({
1022
- * uri: prismic.getGraphQLEndpoint(repositoryName),
1023
- * // Provide `client.graphQLFetch` as the fetch implementation.
1024
- * fetch: client.graphQLFetch,
1025
- * // Using GET is required.
1026
- * useGETForQueries: true,
1027
- * }),
1028
- * cache: new InMemoryCache(),
1029
- * })
1030
- * ```
1031
- *
1032
- * @param input - The `fetch()` `input` parameter. Only strings are supported.
1033
- * @param init - The `fetch()` `init` parameter. Only plain objects are
1034
- * supported.
1035
- *
1036
- * @returns The `fetch()` Response for the request.
1037
- *
1038
- * @experimental
1039
- */
1040
- async graphQLFetch(input, init) {
1041
- const cachedRepository = await this.getCachedRepository();
1042
- const ref = await this.getResolvedRefString();
1043
- const unsanitizedHeaders = {
1044
- "Prismic-ref": ref,
1045
- Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
1046
- // Asserting `init.headers` is a Record since popular GraphQL
1047
- // libraries pass this as a Record. Header objects as input
1048
- // are unsupported.
1049
- ...init ? init.headers : {}
1050
- };
1051
- if (cachedRepository.integrationFieldsRef) {
1052
- unsanitizedHeaders["Prismic-integration-field-ref"] = cachedRepository.integrationFieldsRef;
1053
- }
1054
- const headers = {};
1055
- for (const key in unsanitizedHeaders) {
1056
- if (unsanitizedHeaders[key]) {
1057
- headers[key.toLowerCase()] = unsanitizedHeaders[key];
1058
- }
1059
- }
1060
- const url = new URL(
1061
- // Asserting `input` is a string since popular GraphQL
1062
- // libraries pass this as a string. Request objects as
1063
- // input are unsupported.
1064
- input
1065
- );
1066
- url.searchParams.set("ref", ref);
1067
- const query = url.searchParams.get("query");
1068
- if (query) {
1069
- url.searchParams.set(
1070
- "query",
1071
- // Compress the GraphQL query (if it exists) by
1072
- // removing whitespace. This is done to
1073
- // optimize the query size and avoid
1074
- // hitting the upper limit of GET requests
1075
- // (2048 characters).
1076
- minifyGraphQLQuery(query)
1077
- );
1078
- }
1079
- return await this.fetchFn(url.toString(), {
1080
- ...init,
1081
- headers
1082
- });
1083
- }
1084
- /**
1085
- * Returns a cached version of `getRepository` with a TTL.
1086
- *
1087
- * @returns Cached repository metadata.
1088
- */
1089
- async getCachedRepository(params) {
1090
- if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
1091
- this.cachedRepository = await this.getRepository(params);
1092
- this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
1093
- }
1094
- return this.cachedRepository;
1095
- }
1096
- /**
1097
- * Returns the ref needed to query based on the client's current state. This
1098
- * method may make a network request to fetch a ref or resolve the user's ref
1099
- * thunk.
1100
- *
1101
- * If auto previews are enabled, the preview ref takes priority if available.
1102
- *
1103
- * The following strategies are used depending on the client's state:
1104
- *
1105
- * - If the user called `queryLatestContent`: Use the repository's master ref.
1106
- * The ref is cached for 5 seconds. After 5 seconds, a new master ref is
1107
- * fetched.
1108
- * - If the user called `queryContentFromReleaseByID`: Use the release's ref.
1109
- * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
1110
- * release is fetched.
1111
- * - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
1112
- * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
1113
- * release is fetched.
1114
- * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
1115
- * to the master ref if the ref is not a string.
1116
- *
1117
- * @returns The ref to use during a query.
1118
- */
1119
- async getResolvedRefString(params) {
1120
- if (this.refState.autoPreviewsEnabled) {
1121
- let previewRef;
1122
- let cookieJar;
1123
- if (this.refState.httpRequest?.headers) {
1124
- if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
1125
- cookieJar = this.refState.httpRequest.headers.get("cookie");
1126
- } else if ("cookie" in this.refState.httpRequest.headers) {
1127
- cookieJar = this.refState.httpRequest.headers.cookie;
1128
- }
1129
- } else if (globalThis.document?.cookie) {
1130
- cookieJar = globalThis.document.cookie;
1131
- }
1132
- if (cookieJar) {
1133
- previewRef = getPreviewCookie(cookieJar);
1134
- }
1135
- if (previewRef) {
1136
- return previewRef;
1137
- }
1138
- }
1139
- const cachedRepository = await this.getCachedRepository(params);
1140
- const refModeType = this.refState.mode;
1141
- if (refModeType === RefStateMode.ReleaseID) {
1142
- return findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
1143
- } else if (refModeType === RefStateMode.ReleaseLabel) {
1144
- return findRefByLabel(cachedRepository.refs, this.refState.releaseLabel).ref;
1145
- } else if (refModeType === RefStateMode.Manual) {
1146
- const res = await castThunk(this.refState.ref)();
1147
- if (typeof res === "string") {
1148
- return res;
1149
- }
1150
- }
1151
- return findMasterRef(cachedRepository.refs).ref;
1152
- }
1153
- /**
1154
- * The private implementation of `this.get`. It returns the API response and
1155
- * the URL used to make the request. The URL is sometimes used in the public
1156
- * method to include in thrown errors.
1157
- *
1158
- * This method retries requests that throw `RefNotFoundError` or
1159
- * `RefExpiredError`. It contains special logic to retry with the latest
1160
- * master ref, provided in the API's error message.
1161
- *
1162
- * @typeParam TDocument - Type of Prismic documents returned.
1163
- *
1164
- * @param params - Parameters to filter, sort, and paginate results.
1165
- *
1166
- * @returns An object containing the paginated response containing the result
1167
- * of the query and the URL used to make the API request.
1168
- */
1169
- async _get(params, attemptCount = 0) {
1170
- const url = await this.buildQueryURL(params);
1171
- try {
1172
- const response = await this.#request(new URL(url), params);
1173
- switch (response.status) {
1174
- case 200: {
1175
- try {
1176
- return {
1177
- data: await response.clone().json(),
1178
- url
1179
- };
1180
- } catch {
1181
- throw new PrismicError(void 0, url, await response.text());
1182
- }
1183
- }
1184
- case 400: {
1185
- const json = await response.json();
1186
- throw new ParsingError(json.message, url, json);
1187
- }
1188
- case 401: {
1189
- const json = await response.json();
1190
- throw new ForbiddenError(json.message, url, json);
1191
- }
1192
- case 404: {
1193
- const json = await response.json();
1194
- switch (json.type) {
1195
- case "api_notfound_error": {
1196
- throw new RefNotFoundError(json.message, url, json);
1197
- }
1198
- case "api_security_error": {
1199
- if (/preview token.*expired/i.test(json.message)) {
1200
- throw new PreviewTokenExpiredError(json.message, url, json);
1201
- }
1202
- }
1203
- default: {
1204
- throw new NotFoundError(json.message, url, json);
1205
- }
1206
- }
1207
- }
1208
- case 410: {
1209
- const json = await response.json();
1210
- throw new RefExpiredError(json.message, url, json);
1211
- }
1212
- default: {
1213
- throw new PrismicError(void 0, url, await response.text());
1214
- }
1215
- }
1216
- } catch (error) {
1217
- if (!(error instanceof RefNotFoundError || error instanceof RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) {
1218
- throw error;
1219
- }
1220
- if (!params?.ref) {
1221
- this.cachedRepository = void 0;
1222
- }
1223
- const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)?.groups?.ref;
1224
- if (!masterRef) {
1225
- throw error;
1226
- }
1227
- const badRef = new URL(url).searchParams.get("ref");
1228
- const issue = error instanceof RefNotFoundError ? "invalid" : "expired";
1229
- throttledLog(`[@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.`, { level: "warn" });
1230
- return await this._get({ ...params, ref: masterRef }, attemptCount + 1);
1231
- }
1232
- }
1233
- /**
1234
- * Makes an HTTP request using the client's configured fetch function and
1235
- * options.
1236
- *
1237
- * @param url - The URL to request.
1238
- * @param params - Fetch options.
1239
- *
1240
- * @returns The response from the fetch request.
1241
- */
1242
- async #request(url, params) {
1243
- return await request(url, this._buildRequestInit(params), this.fetchFn);
1244
- }
1245
- _buildRequestInit(params) {
1246
- return {
1247
- ...this.fetchOptions,
1248
- ...params?.fetchOptions,
1249
- headers: {
1250
- ...this.fetchOptions?.headers,
1251
- ...params?.fetchOptions?.headers
1252
- },
1253
- signal: params?.fetchOptions?.signal || params?.signal || this.fetchOptions?.signal
1254
- };
1255
- }
1256
- }
1257
- export {
1258
- Client,
1259
- GET_ALL_QUERY_DELAY,
1260
- REPOSITORY_CACHE_TTL
18
+ /**
19
+ * A client for fetching content from a Prismic repository.
20
+ *
21
+ * @see {@link https://prismic.io/docs/fetch-content}
22
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
23
+ */
24
+ var Client = class {
25
+ /**
26
+ * The client's Content API endpoint.
27
+ *
28
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
29
+ */
30
+ documentAPIEndpoint;
31
+ /**
32
+ * The secure token used for the Content API.
33
+ *
34
+ * @see {@link https://prismic.io/docs/fetch-content#content-visibility}
35
+ */
36
+ accessToken;
37
+ /**
38
+ * A list of route resolver objects that define how a document's `url`
39
+ * property is resolved.
40
+ *
41
+ * @see {@link https://prismic.io/docs/routes}
42
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
43
+ */
44
+ routes;
45
+ /**
46
+ * The URL used for link or content relationship fields that point to an
47
+ * archived or deleted page.
48
+ *
49
+ * @see {@link https://prismic.io/docs/routes}
50
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
51
+ */
52
+ brokenRoute;
53
+ /**
54
+ * Default parameters sent with each Content API request. These parameters can
55
+ * be overridden on each method.
56
+ *
57
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
58
+ */
59
+ defaultParams;
60
+ /**
61
+ * The `fetch` function used to make network requests.
62
+ *
63
+ * @default The global `fetch` function.
64
+ *
65
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
66
+ */
67
+ fetchFn;
68
+ /**
69
+ * The default `fetch` options sent with each Content API request. These
70
+ * parameters can be overriden on each method.
71
+ *
72
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
73
+ */
74
+ fetchOptions;
75
+ #repositoryName;
76
+ #getRef;
77
+ #autoPreviews = true;
78
+ #autoPreviewsRequest;
79
+ #cachedRepository;
80
+ #cachedRepositoryExpiration = 0;
81
+ /**
82
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full
83
+ * Content API endpoint for the repository.
84
+ * @param config - Client configuration.
85
+ */
86
+ constructor(repositoryNameOrEndpoint, config = {}) {
87
+ var _globalThis$fetch;
88
+ const { documentAPIEndpoint, accessToken, ref, routes, brokenRoute, defaultParams, fetchOptions = {}, fetch = (_globalThis$fetch = globalThis.fetch) === null || _globalThis$fetch === void 0 ? void 0 : _globalThis$fetch.bind(globalThis) } = config;
89
+ if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
90
+ try {
91
+ this.repositoryName = getRepositoryName(repositoryNameOrEndpoint);
92
+ } catch {
93
+ console.warn(`[@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")}`);
94
+ }
95
+ this.documentAPIEndpoint = documentAPIEndpoint || repositoryNameOrEndpoint;
96
+ } else {
97
+ this.repositoryName = repositoryNameOrEndpoint;
98
+ this.documentAPIEndpoint = documentAPIEndpoint || getRepositoryEndpoint(repositoryNameOrEndpoint);
99
+ }
100
+ if (!fetch) throw new PrismicError("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.", void 0, void 0);
101
+ if (typeof fetch !== "function") throw new PrismicError(`fetch must be a function, but received: ${typeof fetch}`, void 0, void 0);
102
+ if (!isRepositoryEndpoint(this.documentAPIEndpoint)) throw new PrismicError(`documentAPIEndpoint is not a valid URL: ${documentAPIEndpoint}`, void 0, void 0);
103
+ if (isRepositoryEndpoint(repositoryNameOrEndpoint) && documentAPIEndpoint && repositoryNameOrEndpoint !== documentAPIEndpoint) console.warn(`[@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")}`);
104
+ if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/i.test(this.documentAPIEndpoint)) throw new PrismicError("@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.", void 0, void 0);
105
+ if (process.env.NODE_ENV === "development" && /(?<!\.cdn)\.prismic\.io$/i.test(new URL(this.documentAPIEndpoint).hostname)) console.warn(`[@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")}`);
106
+ this.accessToken = accessToken;
107
+ this.routes = routes;
108
+ this.brokenRoute = brokenRoute;
109
+ this.defaultParams = defaultParams;
110
+ this.fetchOptions = fetchOptions;
111
+ this.fetchFn = fetch;
112
+ this.graphQLFetch = this.graphQLFetch.bind(this);
113
+ if (ref) this.queryContentFromRef(ref);
114
+ }
115
+ /** The Prismic repository's name. */
116
+ set repositoryName(value) {
117
+ this.#repositoryName = value;
118
+ }
119
+ /** The Prismic repository's name. */
120
+ get repositoryName() {
121
+ if (!this.#repositoryName) throw new PrismicError(`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")}`, void 0, void 0);
122
+ return this.#repositoryName;
123
+ }
124
+ /** @deprecated Replace with `documentAPIEndpoint`. */
125
+ set endpoint(value) {
126
+ this.documentAPIEndpoint = value;
127
+ }
128
+ /** @deprecated Replace with `documentAPIEndpoint`. */
129
+ get endpoint() {
130
+ return this.documentAPIEndpoint;
131
+ }
132
+ /**
133
+ * Enables the client to automatically query content from a preview session.
134
+ *
135
+ * @example
136
+ *
137
+ * ```ts
138
+ * client.enableAutoPreviews()
139
+ * ```
140
+ *
141
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
142
+ */
143
+ enableAutoPreviews() {
144
+ this.#autoPreviews = true;
145
+ }
146
+ /**
147
+ * Enables the client to automatically query content from a preview session
148
+ * using an HTTP request object.
149
+ *
150
+ * @example
151
+ *
152
+ * ```ts
153
+ * client.enableAutoPreviewsFromReq(req)
154
+ * ```
155
+ *
156
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
157
+ */
158
+ enableAutoPreviewsFromReq(request$1) {
159
+ this.enableAutoPreviews();
160
+ this.#autoPreviewsRequest = request$1;
161
+ }
162
+ /**
163
+ * Disables the client from automatically querying content from a preview
164
+ * session.
165
+ *
166
+ * @example
167
+ *
168
+ * ```ts
169
+ * client.disableAutoPreviews()
170
+ * ```
171
+ *
172
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
173
+ */
174
+ disableAutoPreviews() {
175
+ this.#autoPreviews = false;
176
+ this.#autoPreviewsRequest = void 0;
177
+ }
178
+ /**
179
+ * Fetches pages based on the `params` argument. Results are paginated.
180
+ *
181
+ * @example
182
+ *
183
+ * ```ts
184
+ * const response = await client.get({ pageSize: 10 })
185
+ * ```
186
+ *
187
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
188
+ */
189
+ async get(params) {
190
+ return await (await this.#internalGet(params)).json();
191
+ }
192
+ /**
193
+ * Fetches the first page returned based on the `params` argument.
194
+ *
195
+ * @example
196
+ *
197
+ * ```ts
198
+ * const page = await client.getFirst()
199
+ * ```
200
+ *
201
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
202
+ */
203
+ async getFirst(params) {
204
+ const actualParams = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params.pageSize) ? params : {
205
+ ...params,
206
+ pageSize: 1
207
+ };
208
+ const response = await this.#internalGet(actualParams);
209
+ const { results } = await response.clone().json();
210
+ if (results[0]) return results[0];
211
+ throw new NotFoundError("No documents were returned", response.url, void 0);
212
+ }
213
+ /**
214
+ * Fetches all pages based on the `params` argument. This method may make
215
+ * multiple network requests to fetch all matching pages.
216
+ *
217
+ * @example
218
+ *
219
+ * ```ts
220
+ * const pages = await client.dangerouslyGetAll()
221
+ * ```
222
+ *
223
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
224
+ */
225
+ async dangerouslyGetAll(params = {}) {
226
+ var _this$defaultParams;
227
+ const { limit = Infinity,...actualParams } = params;
228
+ const resolvedParams = {
229
+ ...actualParams,
230
+ pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) || MAX_PAGE_SIZE)
231
+ };
232
+ const documents = [];
233
+ let latestResult;
234
+ while ((!latestResult || latestResult.next_page) && documents.length < limit) {
235
+ const page = latestResult ? latestResult.page + 1 : void 0;
236
+ latestResult = await this.get({
237
+ ...resolvedParams,
238
+ page
239
+ });
240
+ documents.push(...latestResult.results);
241
+ if (latestResult.next_page) await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));
242
+ }
243
+ return documents.slice(0, limit);
244
+ }
245
+ /**
246
+ * Fetches a page with a specific ID.
247
+ *
248
+ * @example
249
+ *
250
+ * ```ts
251
+ * const page = await client.getByID("WW4bKScAAMAqmluX")
252
+ * ```
253
+ *
254
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
255
+ */
256
+ async getByID(id, params) {
257
+ return await this.getFirst(appendFilters(params, filter.at("document.id", id)));
258
+ }
259
+ /**
260
+ * Fetches pages with specific IDs. Results are paginated.
261
+ *
262
+ * @example
263
+ *
264
+ * ```ts
265
+ * const response = await client.getByIDs([
266
+ * "WW4bKScAAMAqmluX",
267
+ * "U1kTRgEAAC8A5ldS",
268
+ * ])
269
+ * ```
270
+ *
271
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
272
+ */
273
+ async getByIDs(ids, params) {
274
+ return await this.get(appendFilters(params, filter.in("document.id", ids)));
275
+ }
276
+ /**
277
+ * Fetches pages with specific IDs. This method may make multiple network
278
+ * requests to fetch all matching pages.
279
+ *
280
+ * @example
281
+ *
282
+ * ```ts
283
+ * const pages = await client.getAllByIDs([
284
+ * "WW4bKScAAMAqmluX",
285
+ * "U1kTRgEAAC8A5ldS",
286
+ * ])
287
+ * ```
288
+ *
289
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
290
+ */
291
+ async getAllByIDs(ids, params) {
292
+ return await this.dangerouslyGetAll(appendFilters(params, filter.in("document.id", ids)));
293
+ }
294
+ /**
295
+ * Fetches a page with a specific UID and type.
296
+ *
297
+ * @example
298
+ *
299
+ * ```ts
300
+ * const page = await client.getByUID("blog_post", "my-first-post")
301
+ * ```
302
+ *
303
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
304
+ */
305
+ async getByUID(documentType, uid, params) {
306
+ return await this.getFirst(appendFilters(params, filter.at("document.type", documentType), filter.at(`my.${documentType}.uid`, uid)));
307
+ }
308
+ /**
309
+ * Fetches pages with specific UIDs and a specific type. Results are
310
+ * paginated.
311
+ *
312
+ * @example
313
+ *
314
+ * ```ts
315
+ * const response = await client.getByUIDs("blog_post", [
316
+ * "my-first-post",
317
+ * "my-second-post",
318
+ * ])
319
+ * ```
320
+ *
321
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
322
+ */
323
+ async getByUIDs(documentType, uids, params) {
324
+ return await this.get(appendFilters(params, filter.at("document.type", documentType), filter.in(`my.${documentType}.uid`, uids)));
325
+ }
326
+ /**
327
+ * Fetches pages with specific UIDs and a specific type. This method may make
328
+ * multiple network requests to fetch all matching pages.
329
+ *
330
+ * @example
331
+ *
332
+ * ```ts
333
+ * const pages = await client.getAllByUIDs("blog_post", [
334
+ * "my-first-post",
335
+ * "my-second-post",
336
+ * ])
337
+ * ```
338
+ *
339
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
340
+ */
341
+ async getAllByUIDs(documentType, uids, params) {
342
+ return await this.dangerouslyGetAll(appendFilters(params, filter.at("document.type", documentType), filter.in(`my.${documentType}.uid`, uids)));
343
+ }
344
+ /**
345
+ * Fetches a specific single type page.
346
+ *
347
+ * @example
348
+ *
349
+ * ```ts
350
+ * const page = await client.getSingle("settings")
351
+ * ```
352
+ *
353
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
354
+ */
355
+ async getSingle(documentType, params) {
356
+ return await this.getFirst(appendFilters(params, filter.at("document.type", documentType)));
357
+ }
358
+ /**
359
+ * Fetches pages with a specific type. Results are paginated.
360
+ *
361
+ * @example
362
+ *
363
+ * ```ts
364
+ * const response = await client.getByType("blog_post")
365
+ * ```
366
+ *
367
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
368
+ */
369
+ async getByType(documentType, params) {
370
+ return await this.get(appendFilters(params, filter.at("document.type", documentType)));
371
+ }
372
+ /**
373
+ * Fetches pages with a specific type. This method may make multiple network
374
+ * requests to fetch all matching documents.
375
+ *
376
+ * @example
377
+ *
378
+ * ```ts
379
+ * const pages = await client.getAllByType("blog_post")
380
+ * ```
381
+ *
382
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
383
+ */
384
+ async getAllByType(documentType, params) {
385
+ return await this.dangerouslyGetAll(appendFilters(params, filter.at("document.type", documentType)));
386
+ }
387
+ /**
388
+ * Fetches pages with a specific tag. Results are paginated.
389
+ *
390
+ * @example
391
+ *
392
+ * ```ts
393
+ * const response = await client.getByTag("featured")
394
+ * ```
395
+ *
396
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
397
+ */
398
+ async getByTag(tag, params) {
399
+ return await this.get(appendFilters(params, filter.any("document.tags", [tag])));
400
+ }
401
+ /**
402
+ * Fetches pages with a specific tag. This method may make multiple network
403
+ * requests to fetch all matching documents.
404
+ *
405
+ * @example
406
+ *
407
+ * ```ts
408
+ * const pages = await client.getAllByTag("featured")
409
+ * ```
410
+ *
411
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
412
+ */
413
+ async getAllByTag(tag, params) {
414
+ return await this.dangerouslyGetAll(appendFilters(params, filter.any("document.tags", [tag])));
415
+ }
416
+ /**
417
+ * Fetches pages with every tag from a list of tags. Results are paginated.
418
+ *
419
+ * @example
420
+ *
421
+ * ```ts
422
+ * const response = await client.getByEveryTag(["featured", "homepage"])
423
+ * ```
424
+ *
425
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
426
+ */
427
+ async getByEveryTag(tags, params) {
428
+ return await this.get(appendFilters(params, filter.at("document.tags", tags)));
429
+ }
430
+ /**
431
+ * Fetches pages with every tag from a list of tags. This method may make
432
+ * multiple network requests to fetch all matching pages.
433
+ *
434
+ * @example
435
+ *
436
+ * ```ts
437
+ * const pages = await client.getAllByEveryTag(["featured", "homepage"])
438
+ * ```
439
+ *
440
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
441
+ */
442
+ async getAllByEveryTag(tags, params) {
443
+ return await this.dangerouslyGetAll(appendFilters(params, filter.at("document.tags", tags)));
444
+ }
445
+ /**
446
+ * Fetches pages with at least one tag from a list of tags. Results are
447
+ * paginated.
448
+ *
449
+ * @example
450
+ *
451
+ * ```ts
452
+ * const response = await client.getBySomeTags(["featured", "homepage"])
453
+ * ```
454
+ *
455
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
456
+ */
457
+ async getBySomeTags(tags, params) {
458
+ return await this.get(appendFilters(params, filter.any("document.tags", tags)));
459
+ }
460
+ /**
461
+ * Fetches pages with at least one tag from a list of tags. This method may
462
+ * make multiple network requests to fetch all matching documents.
463
+ *
464
+ * @example
465
+ *
466
+ * ```ts
467
+ * const pages = await client.getAllBySomeTags(["featured", "homepage"])
468
+ * ```
469
+ *
470
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
471
+ */
472
+ async getAllBySomeTags(tags, params) {
473
+ return await this.dangerouslyGetAll(appendFilters(params, filter.any("document.tags", tags)));
474
+ }
475
+ /**
476
+ * Fetches metadata about the client's Prismic repository.
477
+ *
478
+ * @example
479
+ *
480
+ * ```ts
481
+ * const repository = await client.getRepository()
482
+ * ```
483
+ *
484
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrepository}
485
+ */
486
+ async getRepository(params) {
487
+ if (this.#cachedRepository && this.#cachedRepositoryExpiration > Date.now()) return this.#cachedRepository;
488
+ const url = new URL(this.documentAPIEndpoint);
489
+ const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
490
+ if (accessToken) url.searchParams.set("access_token", accessToken);
491
+ const response = await this.#request(url, params);
492
+ if (response.ok) {
493
+ this.#cachedRepository = await response.json();
494
+ this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
495
+ return this.#cachedRepository;
496
+ }
497
+ if (response.status === 404) throw new RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
498
+ return await this.#throwContentAPIError(response, url.toString());
499
+ }
500
+ /**
501
+ * Fetches the repository's active refs.
502
+ *
503
+ * @example
504
+ *
505
+ * ```ts
506
+ * const refs = await client.getRefs()
507
+ * ```
508
+ *
509
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefs}
510
+ */
511
+ async getRefs(params) {
512
+ return (await this.getRepository(params)).refs;
513
+ }
514
+ /**
515
+ * Fetches a ref by its ID.
516
+ *
517
+ * @example
518
+ *
519
+ * ```ts
520
+ * const ref = await client.getRefByID("YhE3YhEAACIA4321")
521
+ * ```
522
+ *
523
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
524
+ */
525
+ async getRefByID(id, params) {
526
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.id === id);
527
+ if (!ref) throw new PrismicError(`Ref with ID "${id}" could not be found.`, void 0, void 0);
528
+ return ref;
529
+ }
530
+ /**
531
+ * Fetches a ref by its label. A release ref's label is its name shown in the
532
+ * Page Builder.
533
+ *
534
+ * @example
535
+ *
536
+ * ```ts
537
+ * const ref = await client.getRefByLabel("My Release")
538
+ * ```
539
+ *
540
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
541
+ */
542
+ async getRefByLabel(label, params) {
543
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.label === label);
544
+ if (!ref) throw new PrismicError(`Ref with label "${label}" could not be found.`, void 0, void 0);
545
+ return ref;
546
+ }
547
+ /**
548
+ * Fetches the repository's master ref.
549
+ *
550
+ * @example
551
+ *
552
+ * ```ts
553
+ * const masterRef = await client.getMasterRef()
554
+ * ```
555
+ *
556
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
557
+ */
558
+ async getMasterRef(params) {
559
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.isMasterRef);
560
+ if (!ref) throw new PrismicError("Master ref could not be found.", void 0, void 0);
561
+ return ref;
562
+ }
563
+ /**
564
+ * Fetches the repository's active releases.
565
+ *
566
+ * @example
567
+ *
568
+ * ```ts
569
+ * const releases = await client.getReleases()
570
+ * ```
571
+ *
572
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleases}
573
+ */
574
+ async getReleases(params) {
575
+ return (await this.getRefs(params)).filter((ref) => !ref.isMasterRef);
576
+ }
577
+ /**
578
+ * Fetches a release with a specific ID.
579
+ *
580
+ * @example
581
+ *
582
+ * ```ts
583
+ * const release = await client.getReleaseByID("YhE3YhEAACIA4321")
584
+ * ```
585
+ *
586
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
587
+ */
588
+ async getReleaseByID(id, params) {
589
+ const release = (await this.getReleases(params)).find((ref) => ref.id === id);
590
+ if (!release) throw new PrismicError(`Release with ID "${id}" could not be found.`, void 0, void 0);
591
+ return release;
592
+ }
593
+ /**
594
+ * Fetches a release by its label. A release ref's label is its name shown in
595
+ * the Page Builder.
596
+ *
597
+ * @example
598
+ *
599
+ * ```ts
600
+ * const release = await client.getReleaseByLabel("My Release")
601
+ * ```
602
+ *
603
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
604
+ */
605
+ async getReleaseByLabel(label, params) {
606
+ const release = (await this.getReleases(params)).find((ref) => ref.label === label);
607
+ if (!release) throw new PrismicError(`Release with label "${label}" could not be found.`, void 0, void 0);
608
+ return release;
609
+ }
610
+ /**
611
+ * Fetches the repository's page tags.
612
+ *
613
+ * @example
614
+ *
615
+ * ```ts
616
+ * const tags = await client.getTags()
617
+ * ```
618
+ *
619
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#gettags}
620
+ */
621
+ async getTags(params) {
622
+ const repository = await this.getRepository(params);
623
+ const form = repository.forms.tags;
624
+ if (form) {
625
+ const url = new URL(form.action);
626
+ if (this.accessToken) url.searchParams.set("access_token", this.accessToken);
627
+ const response = await this.#request(url, params);
628
+ if (response.ok) return await response.json();
629
+ }
630
+ return repository.tags;
631
+ }
632
+ /**
633
+ * Builds a Content API query URL with a set of parameters.
634
+ *
635
+ * @example
636
+ *
637
+ * ```ts
638
+ * const url = await client.buildQueryURL({
639
+ * filters: [filter.at("document.type", "blog_post")],
640
+ * })
641
+ * ```
642
+ *
643
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
644
+ */
645
+ async buildQueryURL({ signal, fetchOptions,...params } = {}) {
646
+ const ref = params.ref || await this.#getResolvedRef({
647
+ accessToken: params.accessToken,
648
+ signal,
649
+ fetchOptions
650
+ });
651
+ const integrationFieldsRef = params.integrationFieldsRef || (await this.getRepository({
652
+ accessToken: params.accessToken,
653
+ signal,
654
+ fetchOptions
655
+ })).integrationFieldsRef || void 0;
656
+ return buildQueryURL(this.documentAPIEndpoint, {
657
+ ...this.defaultParams,
658
+ ...params,
659
+ ref,
660
+ integrationFieldsRef,
661
+ routes: params.routes || this.routes,
662
+ brokenRoute: params.brokenRoute || this.brokenRoute,
663
+ accessToken: params.accessToken || this.accessToken
664
+ });
665
+ }
666
+ /**
667
+ * Fetches a previewed page's URL using a preview token and page ID.
668
+ *
669
+ * @example
670
+ *
671
+ * ```ts
672
+ * const url = await client.resolvePreviewURL({
673
+ * linkResolver,
674
+ * defaultURL: "/",
675
+ * })
676
+ * ```
677
+ *
678
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#resolvepreviewurl}
679
+ */
680
+ async resolvePreviewURL(args) {
681
+ let documentID = args.documentID;
682
+ let previewToken = args.previewToken;
683
+ if (typeof globalThis.location !== "undefined") {
684
+ const searchParams = new URLSearchParams(globalThis.location.search);
685
+ documentID = documentID || searchParams.get("documentId");
686
+ previewToken = previewToken || searchParams.get("token");
687
+ } else if (this.#autoPreviewsRequest) {
688
+ if ("query" in this.#autoPreviewsRequest) {
689
+ var _this$autoPreviewsReq, _this$autoPreviewsReq2;
690
+ documentID = documentID || ((_this$autoPreviewsReq = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq === void 0 ? void 0 : _this$autoPreviewsReq.documentId);
691
+ previewToken = previewToken || ((_this$autoPreviewsReq2 = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq2 === void 0 ? void 0 : _this$autoPreviewsReq2.token);
692
+ } else if ("url" in this.#autoPreviewsRequest && this.#autoPreviewsRequest.url) {
693
+ const searchParams = new URL(this.#autoPreviewsRequest.url, "missing-host://").searchParams;
694
+ documentID = documentID || searchParams.get("documentId");
695
+ previewToken = previewToken || searchParams.get("token");
696
+ }
697
+ }
698
+ if (documentID != null && previewToken != null) {
699
+ const url = asLink(await this.getByID(documentID, {
700
+ ref: previewToken,
701
+ lang: "*",
702
+ signal: args.signal,
703
+ fetchOptions: args.fetchOptions
704
+ }), { linkResolver: args.linkResolver });
705
+ if (typeof url === "string") return url;
706
+ }
707
+ return args.defaultURL;
708
+ }
709
+ /**
710
+ * Configures the client to query the latest published content. This is the
711
+ * client's default mode.
712
+ *
713
+ * @example
714
+ *
715
+ * ```ts
716
+ * client.queryLatestContent()
717
+ * ```
718
+ *
719
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
720
+ */
721
+ queryLatestContent() {
722
+ this.#getRef = void 0;
723
+ }
724
+ /**
725
+ * Configures the client to query content from a release with a specific ID.
726
+ *
727
+ * @example
728
+ *
729
+ * ```ts
730
+ * client.queryContentFromReleaseByID("YhE3YhEAACIA4321")
731
+ * ```
732
+ *
733
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
734
+ */
735
+ queryContentFromReleaseByID(id) {
736
+ this.#getRef = async (params) => {
737
+ return (await this.getReleaseByID(id, params)).ref;
738
+ };
739
+ }
740
+ /**
741
+ * Configures the client to query content from a release with a specific
742
+ * label.
743
+ *
744
+ * @example
745
+ *
746
+ * ```ts
747
+ * client.queryContentFromReleaseByLabel("My Release")
748
+ * ```
749
+ *
750
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
751
+ */
752
+ queryContentFromReleaseByLabel(label) {
753
+ this.#getRef = async (params) => {
754
+ return (await this.getReleaseByLabel(label, params)).ref;
755
+ };
756
+ }
757
+ /**
758
+ * Configures the client to query content from a specific ref.
759
+ *
760
+ * @example
761
+ *
762
+ * ```ts
763
+ * client.queryContentFromRef("my-ref")
764
+ * ```
765
+ *
766
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
767
+ */
768
+ queryContentFromRef(ref) {
769
+ this.#getRef = typeof ref === "string" ? () => ref : ref;
770
+ }
771
+ /**
772
+ * A preconfigured `fetch()` function for Prismic's GraphQL API that can be
773
+ * provided to GraphQL clients.
774
+ *
775
+ * @example
776
+ *
777
+ * ```ts
778
+ * import { createClient, getGraphQLEndpoint } from "@prismicio/client"
779
+ *
780
+ * const client = createClient("example-prismic-repo")
781
+ * const graphQLClient = new ApolloClient({
782
+ * link: new HttpLink({
783
+ * uri: getGraphQLEndpoint(client.repositoryName),
784
+ * // Provide `client.graphQLFetch` as the fetch implementation.
785
+ * fetch: client.graphQLFetch,
786
+ * // Using GET is required.
787
+ * useGETForQueries: true,
788
+ * }),
789
+ * cache: new InMemoryCache(),
790
+ * })
791
+ * ```
792
+ *
793
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
794
+ */
795
+ async graphQLFetch(input, init) {
796
+ const params = {
797
+ accessToken: this.accessToken,
798
+ fetchOptions: this.fetchOptions
799
+ };
800
+ const repository = await this.getRepository(params);
801
+ const ref = await this.#getResolvedRef(params);
802
+ const headers = {};
803
+ headers["prismic-ref"] = ref;
804
+ if (this.accessToken) headers["authorization"] = `Token ${this.accessToken}`;
805
+ if (repository.integrationFieldsRef) headers["prismic-integration-field-ref"] = repository.integrationFieldsRef;
806
+ for (const [key, value] of Object.entries((init === null || init === void 0 ? void 0 : init.headers) ?? {})) headers[key.toLowerCase()] = value;
807
+ const url = new URL(typeof input === "string" ? input : input.url);
808
+ const query = (url.searchParams.get("query") ?? "").replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
809
+ url.searchParams.set("query", query);
810
+ url.searchParams.set("ref", ref);
811
+ return await this.fetchFn(url.toString(), {
812
+ ...init,
813
+ headers
814
+ });
815
+ }
816
+ /**
817
+ * Returns the ref needed to query based on the client's current state. This
818
+ * method may make a network request to fetch a ref or resolve the user's ref
819
+ * thunk.
820
+ *
821
+ * If auto previews are enabled, the preview ref takes priority.
822
+ *
823
+ * The following strategies are used depending on the client's state:
824
+ *
825
+ * - If the user called `queryLatestContent`: Use the repository's master ref.
826
+ * The ref is cached for 5 seconds. After 5 seconds, a new master ref is
827
+ * fetched.
828
+ * - If the user called `queryContentFromReleaseByID`: Use the release's ref.
829
+ * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
830
+ * release is fetched.
831
+ * - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
832
+ * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
833
+ * release is fetched.
834
+ * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
835
+ * to the master ref if the ref is not a string.
836
+ */
837
+ async #getResolvedRef(params) {
838
+ var _this$getRef;
839
+ if (this.#autoPreviews) {
840
+ var _this$autoPreviewsReq3, _globalThis$document;
841
+ const previewRef = getPreviewCookie((((_this$autoPreviewsReq3 = this.#autoPreviewsRequest) === null || _this$autoPreviewsReq3 === void 0 ? void 0 : _this$autoPreviewsReq3.headers) ? "get" in this.#autoPreviewsRequest.headers ? this.#autoPreviewsRequest.headers.get("cookie") : this.#autoPreviewsRequest.headers.cookie : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) ?? "");
842
+ if (previewRef) return previewRef;
843
+ }
844
+ const ref = await ((_this$getRef = this.#getRef) === null || _this$getRef === void 0 ? void 0 : _this$getRef.call(this, params));
845
+ if (ref) return ref;
846
+ return (await this.getMasterRef(params)).ref;
847
+ }
848
+ /**
849
+ * Performs a low-level Content API request with the given parameters.
850
+ * Automatically retries if an invalid ref is used.
851
+ */
852
+ async #internalGet(params, attempt = 1) {
853
+ const url = await this.buildQueryURL(params);
854
+ const response = await this.#request(new URL(url), params);
855
+ if (response.ok) return response;
856
+ try {
857
+ return await this.#throwContentAPIError(response, url);
858
+ } catch (error) {
859
+ if ((error instanceof RefNotFoundError || error instanceof RefExpiredError) && attempt < MAX_INVALID_REF_RETRY_ATTEMPTS) {
860
+ var _error$message$match;
861
+ if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
862
+ const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
863
+ if (!masterRef) throw error;
864
+ throttledWarn(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`);
865
+ return await this.#internalGet({
866
+ ...params,
867
+ ref: masterRef
868
+ }, attempt + 1);
869
+ }
870
+ throw error;
871
+ }
872
+ }
873
+ /**
874
+ * Throws an error based on a Content API response. Only call in known-errored
875
+ * states.
876
+ */
877
+ async #throwContentAPIError(response, url) {
878
+ switch (response.status) {
879
+ case 400: {
880
+ const json = await response.clone().json();
881
+ throw new ParsingError(json.message, url, json);
882
+ }
883
+ case 401: {
884
+ const json = await response.clone().json();
885
+ throw new ForbiddenError(json.message, url, json);
886
+ }
887
+ case 404: {
888
+ const json = await response.clone().json();
889
+ switch (json.type) {
890
+ case "api_notfound_error": throw new RefNotFoundError(json.message, url, json);
891
+ case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new PreviewTokenExpiredError(json.message, url, json);
892
+ default: throw new NotFoundError(json.message, url, json);
893
+ }
894
+ }
895
+ case 410: {
896
+ const json = await response.clone().json();
897
+ throw new RefExpiredError(json.message, url, json);
898
+ }
899
+ default: throw new PrismicError(void 0, url, await response.text());
900
+ }
901
+ }
902
+ /** Performs a low-level network request with the client's fetch options. */
903
+ async #request(url, params) {
904
+ var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
905
+ return await request(url, {
906
+ ...this.fetchOptions,
907
+ ...params === null || params === void 0 ? void 0 : params.fetchOptions,
908
+ headers: {
909
+ ...(_this$fetchOptions = this.fetchOptions) === null || _this$fetchOptions === void 0 ? void 0 : _this$fetchOptions.headers,
910
+ ...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
911
+ },
912
+ signal: (params === null || params === void 0 || (_params$fetchOptions2 = params.fetchOptions) === null || _params$fetchOptions2 === void 0 ? void 0 : _params$fetchOptions2.signal) || (params === null || params === void 0 ? void 0 : params.signal) || ((_this$fetchOptions2 = this.fetchOptions) === null || _this$fetchOptions2 === void 0 ? void 0 : _this$fetchOptions2.signal)
913
+ }, this.fetchFn);
914
+ }
1261
915
  };
1262
- //# sourceMappingURL=Client.js.map
916
+ /** Appends filters to a params object. */
917
+ function appendFilters(params = {}, ...filters) {
918
+ return {
919
+ ...params,
920
+ filters: [...params.filters ?? [], ...filters]
921
+ };
922
+ }
923
+
924
+ //#endregion
925
+ export { Client };
926
+ //# sourceMappingURL=Client.js.map