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