@prismicio/client 7.21.0-alpha.2 → 7.21.0-pr.414.8f3ed35

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