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