@prismicio/client 7.21.0-alpha.1 → 7.21.0-pr.414.2f27ec1

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