@prismicio/client 7.22.0 → 7.22.1-pr.452.2f1d8c4
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/README.md +6 -0
- package/dist/Client.cjs +8 -4
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.cts +14 -16
- package/dist/Client.d.cts.map +1 -1
- package/dist/Client.d.ts +14 -16
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +8 -4
- package/dist/Client.js.map +1 -1
- package/dist/Migration.cjs +24 -23
- package/dist/Migration.cjs.map +1 -1
- package/dist/Migration.d.cts +1 -3
- package/dist/Migration.d.cts.map +1 -1
- package/dist/Migration.d.ts +1 -3
- package/dist/Migration.d.ts.map +1 -1
- package/dist/Migration.js +24 -23
- package/dist/Migration.js.map +1 -1
- package/dist/WriteClient.cjs +21 -19
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.cts +18 -22
- package/dist/WriteClient.d.cts.map +1 -1
- package/dist/WriteClient.d.ts +18 -22
- package/dist/WriteClient.d.ts.map +1 -1
- package/dist/WriteClient.js +21 -19
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.cts +5 -6
- package/dist/buildQueryURL.d.cts.map +1 -1
- package/dist/buildQueryURL.d.ts +5 -6
- package/dist/buildQueryURL.d.ts.map +1 -1
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.d.cts +1 -1
- package/dist/cookie.d.cts.map +1 -1
- package/dist/cookie.d.ts +1 -1
- package/dist/cookie.d.ts.map +1 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.cts +2 -4
- package/dist/createClient.d.cts.map +1 -1
- package/dist/createClient.d.ts +2 -4
- package/dist/createClient.d.ts.map +1 -1
- package/dist/createClient.js.map +1 -1
- package/dist/createMigration.cjs.map +1 -1
- package/dist/createMigration.d.cts +2 -4
- package/dist/createMigration.d.cts.map +1 -1
- package/dist/createMigration.d.ts +2 -4
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js.map +1 -1
- package/dist/createWriteClient.cjs.map +1 -1
- package/dist/createWriteClient.d.cts +2 -4
- package/dist/createWriteClient.d.cts.map +1 -1
- package/dist/createWriteClient.d.ts +2 -4
- package/dist/createWriteClient.d.ts.map +1 -1
- package/dist/createWriteClient.js.map +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +9 -10
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts +9 -10
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/filter.cjs +175 -0
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.d.cts +3 -4
- package/dist/filter.d.cts.map +1 -1
- package/dist/filter.d.ts +3 -4
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +175 -0
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.d.cts +1 -2
- package/dist/getGraphQLEndpoint.d.cts.map +1 -1
- package/dist/getGraphQLEndpoint.d.ts +1 -2
- package/dist/getGraphQLEndpoint.d.ts.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.cts +1 -2
- package/dist/getRepositoryEndpoint.d.cts.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +1 -2
- package/dist/getRepositoryEndpoint.d.ts.map +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.d.cts +1 -2
- package/dist/getRepositoryName.d.cts.map +1 -1
- package/dist/getRepositoryName.d.ts +1 -2
- package/dist/getRepositoryName.d.ts.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.d.cts +1 -2
- package/dist/getToolbarSrc.d.cts.map +1 -1
- package/dist/getToolbarSrc.d.ts +1 -2
- package/dist/getToolbarSrc.d.ts.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.cts +1 -3
- package/dist/helpers/asDate.d.cts.map +1 -1
- package/dist/helpers/asDate.d.ts +1 -3
- package/dist/helpers/asDate.d.ts.map +1 -1
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs +7 -5
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.cts +12 -11
- package/dist/helpers/asHTML.d.cts.map +1 -1
- package/dist/helpers/asHTML.d.ts +12 -11
- package/dist/helpers/asHTML.d.ts.map +1 -1
- package/dist/helpers/asHTML.js +7 -5
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.cts +3 -4
- package/dist/helpers/asImagePixelDensitySrcSet.d.cts.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +3 -4
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.cts +1 -3
- package/dist/helpers/asImageSrc.d.cts.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +1 -3
- package/dist/helpers/asImageSrc.d.ts.map +1 -1
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.cts +3 -4
- package/dist/helpers/asImageWidthSrcSet.d.cts.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +3 -4
- package/dist/helpers/asImageWidthSrcSet.d.ts.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.cts +3 -5
- package/dist/helpers/asLink.d.cts.map +1 -1
- package/dist/helpers/asLink.d.ts +3 -5
- package/dist/helpers/asLink.d.ts.map +1 -1
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.cts +2 -4
- package/dist/helpers/asLinkAttrs.d.cts.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +2 -4
- package/dist/helpers/asLinkAttrs.d.ts.map +1 -1
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.cts +1 -3
- package/dist/helpers/asText.d.cts.map +1 -1
- package/dist/helpers/asText.d.ts +1 -3
- package/dist/helpers/asText.d.ts.map +1 -1
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.cts +1 -3
- package/dist/helpers/documentToLinkField.d.cts.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts +1 -3
- package/dist/helpers/documentToLinkField.d.ts.map +1 -1
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs +20 -0
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.cts +22 -24
- package/dist/helpers/isFilled.d.cts.map +1 -1
- package/dist/helpers/isFilled.d.ts +22 -24
- package/dist/helpers/isFilled.d.ts.map +1 -1
- package/dist/helpers/isFilled.js +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.cts +10 -8
- package/dist/helpers/mapSliceZone.d.cts.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +10 -8
- package/dist/helpers/mapSliceZone.d.ts.map +1 -1
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.cts +1 -2
- package/dist/isRepositoryEndpoint.d.cts.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +1 -2
- package/dist/isRepositoryEndpoint.d.ts.map +1 -1
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.d.cts +1 -2
- package/dist/isRepositoryName.d.cts.map +1 -1
- package/dist/isRepositoryName.d.ts +1 -2
- package/dist/isRepositoryName.d.ts.map +1 -1
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
- package/dist/lib/getOptionalLinkProperties.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/isMigrationValue.cjs.map +1 -1
- package/dist/lib/isMigrationValue.js.map +1 -1
- package/dist/lib/isValue.cjs.map +1 -1
- package/dist/lib/isValue.js.map +1 -1
- package/dist/lib/pLimit.cjs.map +1 -1
- package/dist/lib/pLimit.js.map +1 -1
- package/dist/lib/request.cjs +1 -0
- package/dist/lib/request.cjs.map +1 -1
- package/dist/lib/request.d.cts +5 -6
- package/dist/lib/request.d.cts.map +1 -1
- package/dist/lib/request.d.ts +5 -6
- package/dist/lib/request.d.ts.map +1 -1
- package/dist/lib/request.js +1 -1
- package/dist/lib/request.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs +3 -0
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.js +1 -1
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +10 -6
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.js +10 -6
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/throttledWarn.cjs.map +1 -1
- package/dist/lib/throttledWarn.js.map +1 -1
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.cts +1 -3
- package/dist/richtext/asText.d.cts.map +1 -1
- package/dist/richtext/asText.d.ts +1 -3
- package/dist/richtext/asText.d.ts.map +1 -1
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.cts +1 -3
- package/dist/richtext/asTree.d.cts.map +1 -1
- package/dist/richtext/asTree.d.ts +1 -3
- package/dist/richtext/asTree.d.ts.map +1 -1
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.cts +1 -3
- package/dist/richtext/composeSerializers.d.cts.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +1 -3
- package/dist/richtext/composeSerializers.d.ts.map +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.cts +1 -3
- package/dist/richtext/serialize.d.cts.map +1 -1
- package/dist/richtext/serialize.d.ts +1 -3
- package/dist/richtext/serialize.d.ts.map +1 -1
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.cts +5 -7
- package/dist/richtext/types.d.cts.map +1 -1
- package/dist/richtext/types.d.ts +5 -7
- package/dist/richtext/types.d.ts.map +1 -1
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.cts +1 -3
- package/dist/richtext/wrapMapSerializer.d.cts.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +1 -3
- package/dist/richtext/wrapMapSerializer.d.ts.map +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/api/asset/asset.d.cts +35 -20
- package/dist/types/api/asset/asset.d.cts.map +1 -1
- package/dist/types/api/asset/asset.d.ts +35 -20
- package/dist/types/api/asset/asset.d.ts.map +1 -1
- package/dist/types/api/asset/tag.d.cts +12 -7
- package/dist/types/api/asset/tag.d.cts.map +1 -1
- package/dist/types/api/asset/tag.d.ts +12 -7
- package/dist/types/api/asset/tag.d.ts.map +1 -1
- package/dist/types/api/integration.d.cts +2 -4
- package/dist/types/api/integration.d.cts.map +1 -1
- package/dist/types/api/integration.d.ts +2 -4
- package/dist/types/api/integration.d.ts.map +1 -1
- package/dist/types/api/migration/release.d.cts +3 -7
- package/dist/types/api/migration/release.d.cts.map +1 -1
- package/dist/types/api/migration/release.d.ts +3 -7
- package/dist/types/api/migration/release.d.ts.map +1 -1
- package/dist/types/api/query.d.cts +1 -3
- package/dist/types/api/query.d.cts.map +1 -1
- package/dist/types/api/query.d.ts +1 -3
- package/dist/types/api/query.d.ts.map +1 -1
- package/dist/types/api/ref.d.cts +1 -2
- package/dist/types/api/ref.d.cts.map +1 -1
- package/dist/types/api/ref.d.ts +1 -2
- package/dist/types/api/ref.d.ts.map +1 -1
- package/dist/types/api/release.d.cts +1 -3
- package/dist/types/api/release.d.cts.map +1 -1
- package/dist/types/api/release.d.ts +1 -3
- package/dist/types/api/release.d.ts.map +1 -1
- package/dist/types/api/repository.d.cts +4 -6
- package/dist/types/api/repository.d.cts.map +1 -1
- package/dist/types/api/repository.d.ts +4 -6
- package/dist/types/api/repository.d.ts.map +1 -1
- package/dist/types/api/tags.d.cts +1 -2
- package/dist/types/api/tags.d.cts.map +1 -1
- package/dist/types/api/tags.d.ts +1 -2
- package/dist/types/api/tags.d.ts.map +1 -1
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.d.cts +21 -15
- package/dist/types/migration/Asset.d.cts.map +1 -1
- package/dist/types/migration/Asset.d.ts +21 -15
- package/dist/types/migration/Asset.d.ts.map +1 -1
- package/dist/types/migration/Asset.js.map +1 -1
- package/dist/types/migration/ContentRelationship.d.cts +1 -3
- package/dist/types/migration/ContentRelationship.d.cts.map +1 -1
- package/dist/types/migration/ContentRelationship.d.ts +1 -3
- package/dist/types/migration/ContentRelationship.d.ts.map +1 -1
- package/dist/types/migration/Document.cjs.map +1 -1
- package/dist/types/migration/Document.d.cts +8 -8
- package/dist/types/migration/Document.d.cts.map +1 -1
- package/dist/types/migration/Document.d.ts +8 -8
- package/dist/types/migration/Document.d.ts.map +1 -1
- package/dist/types/migration/Document.js.map +1 -1
- package/dist/types/model/boolean.d.cts +1 -3
- package/dist/types/model/boolean.d.cts.map +1 -1
- package/dist/types/model/boolean.d.ts +1 -3
- package/dist/types/model/boolean.d.ts.map +1 -1
- package/dist/types/model/color.d.cts +1 -3
- package/dist/types/model/color.d.cts.map +1 -1
- package/dist/types/model/color.d.ts +1 -3
- package/dist/types/model/color.d.ts.map +1 -1
- package/dist/types/model/contentRelationship.d.cts +6 -8
- package/dist/types/model/contentRelationship.d.cts.map +1 -1
- package/dist/types/model/contentRelationship.d.ts +6 -8
- package/dist/types/model/contentRelationship.d.ts.map +1 -1
- package/dist/types/model/customType.d.cts +3 -5
- package/dist/types/model/customType.d.cts.map +1 -1
- package/dist/types/model/customType.d.ts +3 -5
- package/dist/types/model/customType.d.ts.map +1 -1
- package/dist/types/model/date.d.cts +1 -3
- package/dist/types/model/date.d.cts.map +1 -1
- package/dist/types/model/date.d.ts +1 -3
- package/dist/types/model/date.d.ts.map +1 -1
- package/dist/types/model/embed.d.cts +1 -3
- package/dist/types/model/embed.d.cts.map +1 -1
- package/dist/types/model/embed.d.ts +1 -3
- package/dist/types/model/embed.d.ts.map +1 -1
- package/dist/types/model/geoPoint.d.cts +1 -3
- package/dist/types/model/geoPoint.d.cts.map +1 -1
- package/dist/types/model/geoPoint.d.ts +1 -3
- package/dist/types/model/geoPoint.d.ts.map +1 -1
- package/dist/types/model/group.d.cts +2 -4
- package/dist/types/model/group.d.cts.map +1 -1
- package/dist/types/model/group.d.ts +2 -4
- package/dist/types/model/group.d.ts.map +1 -1
- package/dist/types/model/image.d.cts +3 -5
- package/dist/types/model/image.d.cts.map +1 -1
- package/dist/types/model/image.d.ts +3 -5
- package/dist/types/model/image.d.ts.map +1 -1
- package/dist/types/model/integration.d.cts +1 -3
- package/dist/types/model/integration.d.cts.map +1 -1
- package/dist/types/model/integration.d.ts +1 -3
- package/dist/types/model/integration.d.ts.map +1 -1
- package/dist/types/model/keyText.d.cts +1 -3
- package/dist/types/model/keyText.d.cts.map +1 -1
- package/dist/types/model/keyText.d.ts +1 -3
- package/dist/types/model/keyText.d.ts.map +1 -1
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.d.cts +2 -4
- package/dist/types/model/link.d.cts.map +1 -1
- package/dist/types/model/link.d.ts +2 -4
- package/dist/types/model/link.d.ts.map +1 -1
- package/dist/types/model/link.js.map +1 -1
- package/dist/types/model/linkToMedia.d.cts +1 -3
- package/dist/types/model/linkToMedia.d.cts.map +1 -1
- package/dist/types/model/linkToMedia.d.ts +1 -3
- package/dist/types/model/linkToMedia.d.ts.map +1 -1
- package/dist/types/model/number.d.cts +1 -3
- package/dist/types/model/number.d.cts.map +1 -1
- package/dist/types/model/number.d.ts +1 -3
- package/dist/types/model/number.d.ts.map +1 -1
- package/dist/types/model/range.d.cts +1 -3
- package/dist/types/model/range.d.cts.map +1 -1
- package/dist/types/model/range.d.ts +1 -3
- package/dist/types/model/range.d.ts.map +1 -1
- package/dist/types/model/richText.d.cts +3 -5
- package/dist/types/model/richText.d.cts.map +1 -1
- package/dist/types/model/richText.d.ts +3 -5
- package/dist/types/model/richText.d.ts.map +1 -1
- package/dist/types/model/select.d.cts +1 -3
- package/dist/types/model/select.d.cts.map +1 -1
- package/dist/types/model/select.d.ts +1 -3
- package/dist/types/model/select.d.ts.map +1 -1
- package/dist/types/model/separator.d.cts +1 -3
- package/dist/types/model/separator.d.cts.map +1 -1
- package/dist/types/model/separator.d.ts +1 -3
- package/dist/types/model/separator.d.ts.map +1 -1
- package/dist/types/model/sharedSlice.d.cts +1 -3
- package/dist/types/model/sharedSlice.d.cts.map +1 -1
- package/dist/types/model/sharedSlice.d.ts +1 -3
- package/dist/types/model/sharedSlice.d.ts.map +1 -1
- package/dist/types/model/sharedSliceVariation.d.cts +1 -3
- package/dist/types/model/sharedSliceVariation.d.cts.map +1 -1
- package/dist/types/model/sharedSliceVariation.d.ts +1 -3
- package/dist/types/model/sharedSliceVariation.d.ts.map +1 -1
- package/dist/types/model/slice.cjs.map +1 -1
- package/dist/types/model/slice.d.cts +3 -5
- package/dist/types/model/slice.d.cts.map +1 -1
- package/dist/types/model/slice.d.ts +3 -5
- package/dist/types/model/slice.d.ts.map +1 -1
- package/dist/types/model/slice.js.map +1 -1
- package/dist/types/model/sliceZone.cjs.map +1 -1
- package/dist/types/model/sliceZone.d.cts +4 -6
- package/dist/types/model/sliceZone.d.cts.map +1 -1
- package/dist/types/model/sliceZone.d.ts +4 -6
- package/dist/types/model/sliceZone.d.ts.map +1 -1
- package/dist/types/model/sliceZone.js.map +1 -1
- package/dist/types/model/table.d.cts +1 -3
- package/dist/types/model/table.d.cts.map +1 -1
- package/dist/types/model/table.d.ts +1 -3
- package/dist/types/model/table.d.ts.map +1 -1
- package/dist/types/model/timestamp.d.cts +1 -3
- package/dist/types/model/timestamp.d.cts.map +1 -1
- package/dist/types/model/timestamp.d.ts +1 -3
- package/dist/types/model/timestamp.d.ts.map +1 -1
- package/dist/types/model/title.d.cts +1 -3
- package/dist/types/model/title.d.cts.map +1 -1
- package/dist/types/model/title.d.ts +1 -3
- package/dist/types/model/title.d.ts.map +1 -1
- package/dist/types/model/types.cjs +4 -0
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.d.cts +13 -11
- package/dist/types/model/types.d.cts.map +1 -1
- package/dist/types/model/types.d.ts +13 -11
- package/dist/types/model/types.d.ts.map +1 -1
- package/dist/types/model/types.js +4 -0
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/model/uid.d.cts +1 -3
- package/dist/types/model/uid.d.cts.map +1 -1
- package/dist/types/model/uid.d.ts +1 -3
- package/dist/types/model/uid.d.ts.map +1 -1
- package/dist/types/value/boolean.d.cts +1 -2
- package/dist/types/value/boolean.d.cts.map +1 -1
- package/dist/types/value/boolean.d.ts +1 -2
- package/dist/types/value/boolean.d.ts.map +1 -1
- package/dist/types/value/color.d.cts +1 -3
- package/dist/types/value/color.d.cts.map +1 -1
- package/dist/types/value/color.d.ts +1 -3
- package/dist/types/value/color.d.ts.map +1 -1
- package/dist/types/value/contentRelationship.d.cts +3 -5
- package/dist/types/value/contentRelationship.d.cts.map +1 -1
- package/dist/types/value/contentRelationship.d.ts +3 -5
- package/dist/types/value/contentRelationship.d.ts.map +1 -1
- package/dist/types/value/date.d.cts +1 -3
- package/dist/types/value/date.d.cts.map +1 -1
- package/dist/types/value/date.d.ts +1 -3
- package/dist/types/value/date.d.ts.map +1 -1
- package/dist/types/value/document.d.cts +5 -7
- package/dist/types/value/document.d.cts.map +1 -1
- package/dist/types/value/document.d.ts +5 -7
- package/dist/types/value/document.d.ts.map +1 -1
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.d.cts +43 -25
- package/dist/types/value/embed.d.cts.map +1 -1
- package/dist/types/value/embed.d.ts +43 -25
- package/dist/types/value/embed.d.ts.map +1 -1
- package/dist/types/value/embed.js.map +1 -1
- package/dist/types/value/geoPoint.d.cts +1 -3
- package/dist/types/value/geoPoint.d.cts.map +1 -1
- package/dist/types/value/geoPoint.d.ts +1 -3
- package/dist/types/value/geoPoint.d.ts.map +1 -1
- package/dist/types/value/group.d.cts +2 -4
- package/dist/types/value/group.d.cts.map +1 -1
- package/dist/types/value/group.d.ts +2 -4
- package/dist/types/value/group.d.ts.map +1 -1
- package/dist/types/value/image.d.cts +4 -6
- package/dist/types/value/image.d.cts.map +1 -1
- package/dist/types/value/image.d.ts +4 -6
- package/dist/types/value/image.d.ts.map +1 -1
- package/dist/types/value/integration.d.cts +2 -4
- package/dist/types/value/integration.d.cts.map +1 -1
- package/dist/types/value/integration.d.ts +2 -4
- package/dist/types/value/integration.d.ts.map +1 -1
- package/dist/types/value/keyText.d.cts +1 -3
- package/dist/types/value/keyText.d.cts.map +1 -1
- package/dist/types/value/keyText.d.ts +1 -3
- package/dist/types/value/keyText.d.ts.map +1 -1
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.d.cts +6 -8
- package/dist/types/value/link.d.cts.map +1 -1
- package/dist/types/value/link.d.ts +6 -8
- package/dist/types/value/link.d.ts.map +1 -1
- package/dist/types/value/link.js.map +1 -1
- package/dist/types/value/linkToMedia.d.cts +2 -4
- package/dist/types/value/linkToMedia.d.cts.map +1 -1
- package/dist/types/value/linkToMedia.d.ts +2 -4
- package/dist/types/value/linkToMedia.d.ts.map +1 -1
- package/dist/types/value/number.d.cts +1 -3
- package/dist/types/value/number.d.cts.map +1 -1
- package/dist/types/value/number.d.ts +1 -3
- package/dist/types/value/number.d.ts.map +1 -1
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.d.cts +29 -31
- package/dist/types/value/richText.d.cts.map +1 -1
- package/dist/types/value/richText.d.ts +29 -31
- package/dist/types/value/richText.d.ts.map +1 -1
- package/dist/types/value/richText.js.map +1 -1
- package/dist/types/value/select.d.cts +1 -3
- package/dist/types/value/select.d.cts.map +1 -1
- package/dist/types/value/select.d.ts +1 -3
- package/dist/types/value/select.d.ts.map +1 -1
- package/dist/types/value/sharedSlice.d.cts +1 -3
- package/dist/types/value/sharedSlice.d.cts.map +1 -1
- package/dist/types/value/sharedSlice.d.ts +1 -3
- package/dist/types/value/sharedSlice.d.ts.map +1 -1
- package/dist/types/value/sharedSliceVariation.d.cts +1 -3
- package/dist/types/value/sharedSliceVariation.d.cts.map +1 -1
- package/dist/types/value/sharedSliceVariation.d.ts +1 -3
- package/dist/types/value/sharedSliceVariation.d.ts.map +1 -1
- package/dist/types/value/slice.d.cts +1 -3
- package/dist/types/value/slice.d.cts.map +1 -1
- package/dist/types/value/slice.d.ts +1 -3
- package/dist/types/value/slice.d.ts.map +1 -1
- package/dist/types/value/sliceZone.d.cts +1 -3
- package/dist/types/value/sliceZone.d.cts.map +1 -1
- package/dist/types/value/sliceZone.d.ts +1 -3
- package/dist/types/value/sliceZone.d.ts.map +1 -1
- package/dist/types/value/table.d.cts +26 -16
- package/dist/types/value/table.d.cts.map +1 -1
- package/dist/types/value/table.d.ts +26 -16
- package/dist/types/value/table.d.ts.map +1 -1
- package/dist/types/value/timestamp.d.cts +1 -3
- package/dist/types/value/timestamp.d.cts.map +1 -1
- package/dist/types/value/timestamp.d.ts +1 -3
- package/dist/types/value/timestamp.d.ts.map +1 -1
- package/dist/types/value/title.d.cts +1 -3
- package/dist/types/value/title.d.cts.map +1 -1
- package/dist/types/value/title.d.ts +1 -3
- package/dist/types/value/title.d.ts.map +1 -1
- package/dist/types/value/types.d.cts +6 -8
- package/dist/types/value/types.d.cts.map +1 -1
- package/dist/types/value/types.d.ts +6 -8
- package/dist/types/value/types.d.ts.map +1 -1
- package/dist/types/webhook/apiUpdate.d.cts +1 -3
- package/dist/types/webhook/apiUpdate.d.cts.map +1 -1
- package/dist/types/webhook/apiUpdate.d.ts +1 -3
- package/dist/types/webhook/apiUpdate.d.ts.map +1 -1
- package/dist/types/webhook/testTrigger.d.cts +1 -3
- package/dist/types/webhook/testTrigger.d.cts.map +1 -1
- package/dist/types/webhook/testTrigger.d.ts +1 -3
- package/dist/types/webhook/testTrigger.d.ts.map +1 -1
- package/dist/types/webhook/types.cjs.map +1 -1
- package/dist/types/webhook/types.d.cts +3 -5
- package/dist/types/webhook/types.d.cts.map +1 -1
- package/dist/types/webhook/types.d.ts +3 -5
- package/dist/types/webhook/types.d.ts.map +1 -1
- package/dist/types/webhook/types.js.map +1 -1
- package/package.json +10 -10
- package/src/WriteClient.ts +14 -19
- package/src/lib/resolveMigrationDocumentData.ts +1 -1
- package/src/types/api/migration/release.ts +2 -5
package/dist/Migration.js
CHANGED
|
@@ -38,31 +38,32 @@ var Migration = class {
|
|
|
38
38
|
createAsset(fileOrAssetOrField, filename, { notes, credits, alt, tags } = {}) {
|
|
39
39
|
let config;
|
|
40
40
|
let maybeInitialField;
|
|
41
|
-
if (typeof fileOrAssetOrField === "object" && "url" in fileOrAssetOrField)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
if (typeof fileOrAssetOrField === "object" && "url" in fileOrAssetOrField) {
|
|
42
|
+
if ("dimensions" in fileOrAssetOrField || "link_type" in fileOrAssetOrField) {
|
|
43
|
+
const url = fileOrAssetOrField.url.split("?")[0];
|
|
44
|
+
const filename = "name" in fileOrAssetOrField ? fileOrAssetOrField.name : url.split("/").pop().split("_").pop();
|
|
45
|
+
const credits = "copyright" in fileOrAssetOrField && fileOrAssetOrField.copyright ? fileOrAssetOrField.copyright : void 0;
|
|
46
|
+
const alt = "alt" in fileOrAssetOrField && fileOrAssetOrField.alt ? fileOrAssetOrField.alt : void 0;
|
|
47
|
+
if ("dimensions" in fileOrAssetOrField) maybeInitialField = fileOrAssetOrField;
|
|
48
|
+
config = {
|
|
49
|
+
id: fileOrAssetOrField.id,
|
|
50
|
+
file: url,
|
|
51
|
+
filename,
|
|
52
|
+
notes: void 0,
|
|
53
|
+
credits,
|
|
54
|
+
alt,
|
|
55
|
+
tags: void 0
|
|
56
|
+
};
|
|
57
|
+
} else config = {
|
|
48
58
|
id: fileOrAssetOrField.id,
|
|
49
|
-
file: url,
|
|
50
|
-
filename,
|
|
51
|
-
notes:
|
|
52
|
-
credits,
|
|
53
|
-
alt,
|
|
54
|
-
tags:
|
|
59
|
+
file: fileOrAssetOrField.url,
|
|
60
|
+
filename: fileOrAssetOrField.filename,
|
|
61
|
+
notes: fileOrAssetOrField.notes,
|
|
62
|
+
credits: fileOrAssetOrField.credits,
|
|
63
|
+
alt: fileOrAssetOrField.alt,
|
|
64
|
+
tags: fileOrAssetOrField.tags?.map(({ name }) => name)
|
|
55
65
|
};
|
|
56
66
|
} else config = {
|
|
57
|
-
id: fileOrAssetOrField.id,
|
|
58
|
-
file: fileOrAssetOrField.url,
|
|
59
|
-
filename: fileOrAssetOrField.filename,
|
|
60
|
-
notes: fileOrAssetOrField.notes,
|
|
61
|
-
credits: fileOrAssetOrField.credits,
|
|
62
|
-
alt: fileOrAssetOrField.alt,
|
|
63
|
-
tags: fileOrAssetOrField.tags?.map(({ name }) => name)
|
|
64
|
-
};
|
|
65
|
-
else config = {
|
|
66
67
|
id: fileOrAssetOrField,
|
|
67
68
|
file: fileOrAssetOrField,
|
|
68
69
|
filename,
|
|
@@ -78,7 +79,7 @@ var Migration = class {
|
|
|
78
79
|
maybeAsset.config.notes = maybeAsset.config.notes || config.notes;
|
|
79
80
|
maybeAsset.config.credits = maybeAsset.config.credits || config.credits;
|
|
80
81
|
maybeAsset.config.alt = maybeAsset.config.alt || config.alt;
|
|
81
|
-
maybeAsset.config.tags = Array.from(new Set([...maybeAsset.config.tags || [], ...config.tags || []]));
|
|
82
|
+
maybeAsset.config.tags = Array.from(/* @__PURE__ */ new Set([...maybeAsset.config.tags || [], ...config.tags || []]));
|
|
82
83
|
} else this._assets.set(config.id, migrationAsset);
|
|
83
84
|
return migrationAsset;
|
|
84
85
|
}
|
package/dist/Migration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Migration.js","names":["#migratePrismicDocumentData","is.filledContentRelationship","is.filledLinkToMedia","is.rtImageNode","is.filledImage"],"sources":["../src/Migration.ts"],"sourcesContent":["import { getOptionalLinkProperties } from \"./lib/getOptionalLinkProperties\"\nimport * as is from \"./lib/isValue\"\nimport { validateAssetMetadata } from \"./lib/validateAssetMetadata\"\nimport type { Asset } from \"./types/api/asset/asset\"\nimport type {\n\tMigrationAssetConfig,\n\tMigrationImage,\n\tMigrationLinkToMedia,\n\tMigrationRTImageNode,\n} from \"./types/migration/Asset\"\nimport { PrismicMigrationAsset } from \"./types/migration/Asset\"\nimport type { MigrationContentRelationship } from \"./types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"./types/migration/Document\"\nimport type { ExistingPrismicDocument, PendingPrismicDocument } from \"./types/migration/Document\"\nimport type { PrismicDocument } from \"./types/value/document\"\nimport type { FilledImageFieldImage } from \"./types/value/image\"\nimport { type FilledLinkToWebField, LinkType } from \"./types/value/link\"\nimport type { FilledLinkToMediaField } from \"./types/value/linkToMedia\"\nimport { RichTextNodeType } from \"./types/value/richText\"\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic document type. If no\n * matches are found, no extraction is performed and the union of all provided Prismic document\n * types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/**\n * A helper that allows preparing your migration to Prismic.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic repository. Query\n * methods will automatically be typed based on this type.\n */\nexport class Migration<TDocuments extends PrismicDocument = PrismicDocument> {\n\t/**\n\t * Assets registered in the migration.\n\t *\n\t * @internal\n\t */\n\t_assets: Map<MigrationAssetConfig[\"file\"], PrismicMigrationAsset> = new Map()\n\n\t/**\n\t * Documents registered in the migration.\n\t *\n\t * @internal\n\t */\n\t_documents: PrismicMigrationDocument<TDocuments>[] = []\n\n\t/**\n\t * Registers an asset to be created in the migration from an asset object.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @param asset - An asset object from Prismic Asset API.\n\t * @returns A migration asset field instance.\n\t * @internal\n\t */\n\tcreateAsset(asset: Asset): PrismicMigrationAsset\n\n\t/**\n\t * Registers an asset to be created in the migration from an image or link to media field.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @param imageOrLinkToMediaField - An image or link to media field from Prismic Document API.\n\t * @returns A migration asset field instance.\n\t * @internal\n\t */\n\tcreateAsset(\n\t\timageOrLinkToMediaField: FilledImageFieldImage | FilledLinkToMediaField,\n\t): PrismicMigrationAsset\n\n\t/**\n\t * Registers an asset to be created in the migration from a file.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @param file - The URL or content of the file to be created.\n\t * @param filename - The filename of the asset.\n\t * @param params - Additional asset data.\n\t * @returns A migration asset field instance.\n\t */\n\tcreateAsset(\n\t\tfile: MigrationAssetConfig[\"file\"],\n\t\tfilename: MigrationAssetConfig[\"filename\"],\n\t\tparams?: {\n\t\t\tnotes?: string\n\t\t\tcredits?: string\n\t\t\talt?: string\n\t\t\ttags?: string[]\n\t\t},\n\t): PrismicMigrationAsset\n\n\t/**\n\t * Registers an asset to be created in the migration from a file, an asset object, or an image or\n\t * link to media field.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @returns A migration asset field instance.\n\t */\n\tcreateAsset(\n\t\tfileOrAssetOrField:\n\t\t\t| MigrationAssetConfig[\"file\"]\n\t\t\t| Asset\n\t\t\t| FilledImageFieldImage\n\t\t\t| FilledLinkToMediaField,\n\t\tfilename?: MigrationAssetConfig[\"filename\"],\n\t\t{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\ttags,\n\t\t}: {\n\t\t\tnotes?: string\n\t\t\tcredits?: string\n\t\t\talt?: string\n\t\t\ttags?: string[]\n\t\t} = {},\n\t): PrismicMigrationAsset {\n\t\tlet config: MigrationAssetConfig\n\t\tlet maybeInitialField: FilledImageFieldImage | undefined\n\t\tif (typeof fileOrAssetOrField === \"object\" && \"url\" in fileOrAssetOrField) {\n\t\t\tif (\"dimensions\" in fileOrAssetOrField || \"link_type\" in fileOrAssetOrField) {\n\t\t\t\tconst url = fileOrAssetOrField.url.split(\"?\")[0]\n\t\t\t\tconst filename =\n\t\t\t\t\t\"name\" in fileOrAssetOrField\n\t\t\t\t\t\t? fileOrAssetOrField.name\n\t\t\t\t\t\t: url.split(\"/\").pop()!.split(\"_\").pop()!\n\t\t\t\tconst credits =\n\t\t\t\t\t\"copyright\" in fileOrAssetOrField && fileOrAssetOrField.copyright\n\t\t\t\t\t\t? fileOrAssetOrField.copyright\n\t\t\t\t\t\t: undefined\n\t\t\t\tconst alt =\n\t\t\t\t\t\"alt\" in fileOrAssetOrField && fileOrAssetOrField.alt ? fileOrAssetOrField.alt : undefined\n\n\t\t\t\tif (\"dimensions\" in fileOrAssetOrField) {\n\t\t\t\t\tmaybeInitialField = fileOrAssetOrField\n\t\t\t\t}\n\n\t\t\t\tconfig = {\n\t\t\t\t\tid: fileOrAssetOrField.id,\n\t\t\t\t\tfile: url,\n\t\t\t\t\tfilename,\n\t\t\t\t\tnotes: undefined,\n\t\t\t\t\tcredits,\n\t\t\t\t\talt,\n\t\t\t\t\ttags: undefined,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconfig = {\n\t\t\t\t\tid: fileOrAssetOrField.id,\n\t\t\t\t\tfile: fileOrAssetOrField.url,\n\t\t\t\t\tfilename: fileOrAssetOrField.filename,\n\t\t\t\t\tnotes: fileOrAssetOrField.notes,\n\t\t\t\t\tcredits: fileOrAssetOrField.credits,\n\t\t\t\t\talt: fileOrAssetOrField.alt,\n\t\t\t\t\ttags: fileOrAssetOrField.tags?.map(({ name }) => name),\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = {\n\t\t\t\tid: fileOrAssetOrField,\n\t\t\t\tfile: fileOrAssetOrField,\n\t\t\t\tfilename: filename!,\n\t\t\t\tnotes,\n\t\t\t\tcredits,\n\t\t\t\talt,\n\t\t\t\ttags,\n\t\t\t}\n\t\t}\n\n\t\tvalidateAssetMetadata(config)\n\n\t\t// We create a detached instance of the asset each time to serialize it properly\n\t\tconst migrationAsset = new PrismicMigrationAsset(config, maybeInitialField)\n\n\t\tconst maybeAsset = this._assets.get(config.id)\n\t\tif (maybeAsset) {\n\t\t\t// Consolidate existing asset with new asset value if possible\n\t\t\tmaybeAsset.config.notes = maybeAsset.config.notes || config.notes\n\t\t\tmaybeAsset.config.credits = maybeAsset.config.credits || config.credits\n\t\t\tmaybeAsset.config.alt = maybeAsset.config.alt || config.alt\n\t\t\tmaybeAsset.config.tags = Array.from(\n\t\t\t\tnew Set([...(maybeAsset.config.tags || []), ...(config.tags || [])]),\n\t\t\t)\n\t\t} else {\n\t\t\tthis._assets.set(config.id, migrationAsset)\n\t\t}\n\n\t\treturn migrationAsset\n\t}\n\n\t/**\n\t * Registers a document to be created in the migration.\n\t *\n\t * @remarks\n\t * This method does not create the document in Prismic right away. Instead, it registers it in\n\t * your migration. The document will be created when the migration is executed through the\n\t * `writeClient.migrate()` method.\n\t * @typeParam TType - Type of the Prismic document to create.\n\t * @param document - The document to create.\n\t * @param title - The title of the document to create which will be displayed in the editor.\n\t * @param params - Document master language document ID.\n\t * @returns A migration document instance.\n\t */\n\tcreateDocument<TType extends TDocuments[\"type\"]>(\n\t\tdocument: ExtractDocumentType<PendingPrismicDocument<TDocuments>, TType>,\n\t\ttitle: string,\n\t\tparams?: {\n\t\t\tmasterLanguageDocument?: MigrationContentRelationship\n\t\t},\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {\n\t\tconst doc = new PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>(\n\t\t\tdocument,\n\t\t\ttitle,\n\t\t\tparams,\n\t\t)\n\n\t\tthis._documents.push(doc)\n\n\t\treturn doc\n\t}\n\n\t/**\n\t * Registers an existing document to be updated in the migration.\n\t *\n\t * @remarks\n\t * This method does not update the document in Prismic right away. Instead, it registers it in\n\t * your migration. The document will be updated when the migration is executed through the\n\t * `writeClient.migrate()` method.\n\t * @typeParam TType - Type of Prismic documents to update.\n\t * @param document - The document to update.\n\t * @param title - The title of the document to update which will be displayed in the editor.\n\t * @returns A migration document instance.\n\t */\n\tupdateDocument<TType extends TDocuments[\"type\"]>(\n\t\tdocument: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>,\n\t\t// Title is optional for existing documents as we might not want to update it.\n\t\ttitle?: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {\n\t\tconst doc = new PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>(\n\t\t\tdocument,\n\t\t\ttitle,\n\t\t)\n\n\t\tthis._documents.push(doc)\n\n\t\treturn doc\n\t}\n\n\t/**\n\t * Registers a document from another Prismic repository to be created in the migration.\n\t *\n\t * @remarks\n\t * This method does not create the document in Prismic right away. Instead, it registers it in\n\t * your migration. The document will be created when the migration is executed through the\n\t * `writeClient.migrate()` method.\n\t * @param document - The document from Prismic to create.\n\t * @param title - The title of the document to create which will be displayed in the editor.\n\t * @returns A migration document instance.\n\t */\n\tcreateDocumentFromPrismic<TType extends TDocuments[\"type\"]>(\n\t\tdocument: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>,\n\t\ttitle: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {\n\t\tconst doc = new PrismicMigrationDocument(\n\t\t\tthis.#migratePrismicDocumentData({\n\t\t\t\ttype: document.type,\n\t\t\t\tlang: document.lang,\n\t\t\t\tuid: document.uid,\n\t\t\t\ttags: document.tags,\n\t\t\t\tdata: document.data,\n\t\t\t}) as PendingPrismicDocument<ExtractDocumentType<TDocuments, TType>>,\n\t\t\ttitle,\n\t\t\t{ originalPrismicDocument: document },\n\t\t)\n\n\t\tthis._documents.push(doc)\n\n\t\treturn doc\n\t}\n\n\t/**\n\t * Queries a document from the migration instance with a specific UID and custom type.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst contentRelationship = migration.createContentRelationship(() =>\n\t * \t\tmigration.getByUID(\"blog_post\", \"my-first-post\"),\n\t * \t)\n\t * \t```\n\t *\n\t * @typeParam TType - Type of the Prismic document returned.\n\t * @param type - The API ID of the document's custom type.\n\t * @param uid - The UID of the document.\n\t * @returns The migration document instance with a UID matching the `uid` parameter, if a matching\n\t * document is found.\n\t */\n\tgetByUID<TType extends TDocuments[\"type\"]>(\n\t\ttype: TType,\n\t\tuid: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined {\n\t\treturn this._documents.find(\n\t\t\t(doc): doc is PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> =>\n\t\t\t\tdoc.document.type === type && doc.document.uid === uid,\n\t\t)\n\t}\n\n\t/**\n\t * Queries a singleton document from the migration instance for a specific custom type.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst contentRelationship = migration.createContentRelationship(() =>\n\t * \t\tmigration.getSingle(\"settings\"),\n\t * \t)\n\t * \t```\n\t *\n\t * @typeParam TType - Type of the Prismic document returned.\n\t * @param type - The API ID of the singleton custom type.\n\t * @returns The migration document instance for the custom type, if a matching\n\t * document is found.\n\t */\n\tgetSingle<TType extends TDocuments[\"type\"]>(\n\t\ttype: TType,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined {\n\t\treturn this._documents.find(\n\t\t\t(doc): doc is PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> =>\n\t\t\t\tdoc.document.type === type,\n\t\t)\n\t}\n\n\t/**\n\t * Migrates a Prismic document data from another repository so that it can be created through the\n\t * current repository's Migration API.\n\t *\n\t * @param input - The Prismic document data to migrate.\n\t * @returns The migrated Prismic document data.\n\t */\n\t#migratePrismicDocumentData(input: unknown): unknown {\n\t\tif (is.filledContentRelationship(input)) {\n\t\t\tconst optionalLinkProperties = getOptionalLinkProperties(input)\n\n\t\t\tif (input.isBroken) {\n\t\t\t\treturn {\n\t\t\t\t\t...optionalLinkProperties,\n\t\t\t\t\tlink_type: LinkType.Document,\n\t\t\t\t\t// ID needs to be 16 characters long to be considered valid by the API\n\t\t\t\t\tid: \"_____broken_____\",\n\t\t\t\t\tisBroken: true,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\tlink_type: LinkType.Document,\n\t\t\t\tid: () => this._getByOriginalID(input.id),\n\t\t\t}\n\t\t}\n\n\t\tif (is.filledLinkToMedia(input)) {\n\t\t\tconst optionalLinkProperties = getOptionalLinkProperties(input)\n\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\tlink_type: LinkType.Media,\n\t\t\t\tid: this.createAsset(input),\n\t\t\t}\n\t\t}\n\n\t\tif (is.rtImageNode(input)) {\n\t\t\t// Rich text image nodes\n\t\t\tconst rtImageNode: MigrationRTImageNode = {\n\t\t\t\ttype: RichTextNodeType.image,\n\t\t\t\tid: this.createAsset(input),\n\t\t\t}\n\n\t\t\tif (input.linkTo) {\n\t\t\t\trtImageNode.linkTo = this.#migratePrismicDocumentData(input.linkTo) as\n\t\t\t\t\t| MigrationContentRelationship\n\t\t\t\t\t| MigrationLinkToMedia\n\t\t\t\t\t| FilledLinkToWebField\n\t\t\t}\n\n\t\t\treturn rtImageNode\n\t\t}\n\n\t\tif (is.filledImage(input)) {\n\t\t\tconst image: MigrationImage = {\n\t\t\t\tid: this.createAsset(input),\n\t\t\t}\n\n\t\t\tconst {\n\t\t\t\tid: _id,\n\t\t\t\turl: _url,\n\t\t\t\tdimensions: _dimensions,\n\t\t\t\tedit: _edit,\n\t\t\t\talt: _alt,\n\t\t\t\tcopyright: _copyright,\n\t\t\t\t...thumbnails\n\t\t\t} = input\n\n\t\t\tfor (const name in thumbnails) {\n\t\t\t\tif (is.filledImage(thumbnails[name])) {\n\t\t\t\t\timage[name] = this.createAsset(thumbnails[name])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn image\n\t\t}\n\n\t\tif (Array.isArray(input)) {\n\t\t\treturn input.map((element) => this.#migratePrismicDocumentData(element))\n\t\t}\n\n\t\tif (input && typeof input === \"object\") {\n\t\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\t\tfor (const key in input) {\n\t\t\t\tres[key] = this.#migratePrismicDocumentData(input[key as keyof typeof input])\n\t\t\t}\n\n\t\t\treturn res\n\t\t}\n\n\t\treturn input\n\t}\n\n\t/**\n\t * Queries a document from the migration instance for a specific original ID.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst contentRelationship = migration.createContentRelationship(() =>\n\t * \t\tmigration._getByOriginalID(\"YhdrDxIAACgAcp_b\"),\n\t * \t)\n\t * \t```\n\t *\n\t * @typeParam TType - Type of the Prismic document returned.\n\t * @param id - The original ID of the Prismic document.\n\t * @returns The migration document instance for the original ID, if a matching\n\t * document is found.\n\t * @internal\n\t */\n\t_getByOriginalID<TType extends TDocuments[\"type\"]>(\n\t\tid: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined {\n\t\treturn this._documents.find(\n\t\t\t(doc): doc is PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> =>\n\t\t\t\tdoc.originalPrismicDocument?.id === id,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,IAAa,YAAb,MAA6E;;;;;;CAM5E,0BAAoE,IAAI,KAAK;;;;;;CAO7E,aAAqD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,YAAY,MAAM;GAC3B;AAGF,MAAIC,YAAe,MAAM,EAAE;GAE1B,MAAM,cAAoC;IACzC,MAAM,iBAAiB;IACvB,IAAI,KAAK,YAAY,MAAM;IAC3B;AAED,OAAI,MAAM,OACT,aAAY,SAAS,MAAA,2BAAiC,MAAM,OAAO;AAMpE,UAAO;;AAGR,MAAIC,YAAe,MAAM,EAAE;GAC1B,MAAM,QAAwB,EAC7B,IAAI,KAAK,YAAY,MAAM,EAC3B;GAED,MAAM,EACL,IAAI,KACJ,KAAK,MACL,YAAY,aACZ,MAAM,OACN,KAAK,MACL,WAAW,YACX,GAAG,eACA;AAEJ,QAAK,MAAM,QAAQ,WAClB,KAAIA,YAAe,WAAW,MAAM,CACnC,OAAM,QAAQ,KAAK,YAAY,WAAW,MAAM;AAIlD,UAAO;;AAGR,MAAI,MAAM,QAAQ,MAAM,CACvB,QAAO,MAAM,KAAK,YAAY,MAAA,2BAAiC,QAAQ,CAAC;AAGzE,MAAI,SAAS,OAAO,UAAU,UAAU;GACvC,MAAM,MAAoC,EAAE;AAE5C,QAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAA,2BAAiC,MAAM,KAA2B;AAG9E,UAAO;;AAGR,SAAO;;;;;;;;;;;;;;;;;;CAmBR,iBACC,IAC+E;AAC/E,SAAO,KAAK,WAAW,MACrB,QACA,IAAI,yBAAyB,OAAO,GACrC"}
|
|
1
|
+
{"version":3,"file":"Migration.js","names":["is.filledContentRelationship","is.filledLinkToMedia","is.rtImageNode","is.filledImage"],"sources":["../src/Migration.ts"],"sourcesContent":["import { getOptionalLinkProperties } from \"./lib/getOptionalLinkProperties\"\nimport * as is from \"./lib/isValue\"\nimport { validateAssetMetadata } from \"./lib/validateAssetMetadata\"\nimport type { Asset } from \"./types/api/asset/asset\"\nimport type {\n\tMigrationAssetConfig,\n\tMigrationImage,\n\tMigrationLinkToMedia,\n\tMigrationRTImageNode,\n} from \"./types/migration/Asset\"\nimport { PrismicMigrationAsset } from \"./types/migration/Asset\"\nimport type { MigrationContentRelationship } from \"./types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"./types/migration/Document\"\nimport type { ExistingPrismicDocument, PendingPrismicDocument } from \"./types/migration/Document\"\nimport type { PrismicDocument } from \"./types/value/document\"\nimport type { FilledImageFieldImage } from \"./types/value/image\"\nimport { type FilledLinkToWebField, LinkType } from \"./types/value/link\"\nimport type { FilledLinkToMediaField } from \"./types/value/linkToMedia\"\nimport { RichTextNodeType } from \"./types/value/richText\"\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic document type. If no\n * matches are found, no extraction is performed and the union of all provided Prismic document\n * types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/**\n * A helper that allows preparing your migration to Prismic.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic repository. Query\n * methods will automatically be typed based on this type.\n */\nexport class Migration<TDocuments extends PrismicDocument = PrismicDocument> {\n\t/**\n\t * Assets registered in the migration.\n\t *\n\t * @internal\n\t */\n\t_assets: Map<MigrationAssetConfig[\"file\"], PrismicMigrationAsset> = new Map()\n\n\t/**\n\t * Documents registered in the migration.\n\t *\n\t * @internal\n\t */\n\t_documents: PrismicMigrationDocument<TDocuments>[] = []\n\n\t/**\n\t * Registers an asset to be created in the migration from an asset object.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @param asset - An asset object from Prismic Asset API.\n\t * @returns A migration asset field instance.\n\t * @internal\n\t */\n\tcreateAsset(asset: Asset): PrismicMigrationAsset\n\n\t/**\n\t * Registers an asset to be created in the migration from an image or link to media field.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @param imageOrLinkToMediaField - An image or link to media field from Prismic Document API.\n\t * @returns A migration asset field instance.\n\t * @internal\n\t */\n\tcreateAsset(\n\t\timageOrLinkToMediaField: FilledImageFieldImage | FilledLinkToMediaField,\n\t): PrismicMigrationAsset\n\n\t/**\n\t * Registers an asset to be created in the migration from a file.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @param file - The URL or content of the file to be created.\n\t * @param filename - The filename of the asset.\n\t * @param params - Additional asset data.\n\t * @returns A migration asset field instance.\n\t */\n\tcreateAsset(\n\t\tfile: MigrationAssetConfig[\"file\"],\n\t\tfilename: MigrationAssetConfig[\"filename\"],\n\t\tparams?: {\n\t\t\tnotes?: string\n\t\t\tcredits?: string\n\t\t\talt?: string\n\t\t\ttags?: string[]\n\t\t},\n\t): PrismicMigrationAsset\n\n\t/**\n\t * Registers an asset to be created in the migration from a file, an asset object, or an image or\n\t * link to media field.\n\t *\n\t * @remarks\n\t * This method does not create the asset in Prismic media library right away. Instead, it\n\t * registers it in your migration. The asset will be created when the migration is executed\n\t * through the `writeClient.migrate()` method.\n\t * @returns A migration asset field instance.\n\t */\n\tcreateAsset(\n\t\tfileOrAssetOrField:\n\t\t\t| MigrationAssetConfig[\"file\"]\n\t\t\t| Asset\n\t\t\t| FilledImageFieldImage\n\t\t\t| FilledLinkToMediaField,\n\t\tfilename?: MigrationAssetConfig[\"filename\"],\n\t\t{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\ttags,\n\t\t}: {\n\t\t\tnotes?: string\n\t\t\tcredits?: string\n\t\t\talt?: string\n\t\t\ttags?: string[]\n\t\t} = {},\n\t): PrismicMigrationAsset {\n\t\tlet config: MigrationAssetConfig\n\t\tlet maybeInitialField: FilledImageFieldImage | undefined\n\t\tif (typeof fileOrAssetOrField === \"object\" && \"url\" in fileOrAssetOrField) {\n\t\t\tif (\"dimensions\" in fileOrAssetOrField || \"link_type\" in fileOrAssetOrField) {\n\t\t\t\tconst url = fileOrAssetOrField.url.split(\"?\")[0]\n\t\t\t\tconst filename =\n\t\t\t\t\t\"name\" in fileOrAssetOrField\n\t\t\t\t\t\t? fileOrAssetOrField.name\n\t\t\t\t\t\t: url.split(\"/\").pop()!.split(\"_\").pop()!\n\t\t\t\tconst credits =\n\t\t\t\t\t\"copyright\" in fileOrAssetOrField && fileOrAssetOrField.copyright\n\t\t\t\t\t\t? fileOrAssetOrField.copyright\n\t\t\t\t\t\t: undefined\n\t\t\t\tconst alt =\n\t\t\t\t\t\"alt\" in fileOrAssetOrField && fileOrAssetOrField.alt ? fileOrAssetOrField.alt : undefined\n\n\t\t\t\tif (\"dimensions\" in fileOrAssetOrField) {\n\t\t\t\t\tmaybeInitialField = fileOrAssetOrField\n\t\t\t\t}\n\n\t\t\t\tconfig = {\n\t\t\t\t\tid: fileOrAssetOrField.id,\n\t\t\t\t\tfile: url,\n\t\t\t\t\tfilename,\n\t\t\t\t\tnotes: undefined,\n\t\t\t\t\tcredits,\n\t\t\t\t\talt,\n\t\t\t\t\ttags: undefined,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconfig = {\n\t\t\t\t\tid: fileOrAssetOrField.id,\n\t\t\t\t\tfile: fileOrAssetOrField.url,\n\t\t\t\t\tfilename: fileOrAssetOrField.filename,\n\t\t\t\t\tnotes: fileOrAssetOrField.notes,\n\t\t\t\t\tcredits: fileOrAssetOrField.credits,\n\t\t\t\t\talt: fileOrAssetOrField.alt,\n\t\t\t\t\ttags: fileOrAssetOrField.tags?.map(({ name }) => name),\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = {\n\t\t\t\tid: fileOrAssetOrField,\n\t\t\t\tfile: fileOrAssetOrField,\n\t\t\t\tfilename: filename!,\n\t\t\t\tnotes,\n\t\t\t\tcredits,\n\t\t\t\talt,\n\t\t\t\ttags,\n\t\t\t}\n\t\t}\n\n\t\tvalidateAssetMetadata(config)\n\n\t\t// We create a detached instance of the asset each time to serialize it properly\n\t\tconst migrationAsset = new PrismicMigrationAsset(config, maybeInitialField)\n\n\t\tconst maybeAsset = this._assets.get(config.id)\n\t\tif (maybeAsset) {\n\t\t\t// Consolidate existing asset with new asset value if possible\n\t\t\tmaybeAsset.config.notes = maybeAsset.config.notes || config.notes\n\t\t\tmaybeAsset.config.credits = maybeAsset.config.credits || config.credits\n\t\t\tmaybeAsset.config.alt = maybeAsset.config.alt || config.alt\n\t\t\tmaybeAsset.config.tags = Array.from(\n\t\t\t\tnew Set([...(maybeAsset.config.tags || []), ...(config.tags || [])]),\n\t\t\t)\n\t\t} else {\n\t\t\tthis._assets.set(config.id, migrationAsset)\n\t\t}\n\n\t\treturn migrationAsset\n\t}\n\n\t/**\n\t * Registers a document to be created in the migration.\n\t *\n\t * @remarks\n\t * This method does not create the document in Prismic right away. Instead, it registers it in\n\t * your migration. The document will be created when the migration is executed through the\n\t * `writeClient.migrate()` method.\n\t * @typeParam TType - Type of the Prismic document to create.\n\t * @param document - The document to create.\n\t * @param title - The title of the document to create which will be displayed in the editor.\n\t * @param params - Document master language document ID.\n\t * @returns A migration document instance.\n\t */\n\tcreateDocument<TType extends TDocuments[\"type\"]>(\n\t\tdocument: ExtractDocumentType<PendingPrismicDocument<TDocuments>, TType>,\n\t\ttitle: string,\n\t\tparams?: {\n\t\t\tmasterLanguageDocument?: MigrationContentRelationship\n\t\t},\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {\n\t\tconst doc = new PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>(\n\t\t\tdocument,\n\t\t\ttitle,\n\t\t\tparams,\n\t\t)\n\n\t\tthis._documents.push(doc)\n\n\t\treturn doc\n\t}\n\n\t/**\n\t * Registers an existing document to be updated in the migration.\n\t *\n\t * @remarks\n\t * This method does not update the document in Prismic right away. Instead, it registers it in\n\t * your migration. The document will be updated when the migration is executed through the\n\t * `writeClient.migrate()` method.\n\t * @typeParam TType - Type of Prismic documents to update.\n\t * @param document - The document to update.\n\t * @param title - The title of the document to update which will be displayed in the editor.\n\t * @returns A migration document instance.\n\t */\n\tupdateDocument<TType extends TDocuments[\"type\"]>(\n\t\tdocument: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>,\n\t\t// Title is optional for existing documents as we might not want to update it.\n\t\ttitle?: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {\n\t\tconst doc = new PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>(\n\t\t\tdocument,\n\t\t\ttitle,\n\t\t)\n\n\t\tthis._documents.push(doc)\n\n\t\treturn doc\n\t}\n\n\t/**\n\t * Registers a document from another Prismic repository to be created in the migration.\n\t *\n\t * @remarks\n\t * This method does not create the document in Prismic right away. Instead, it registers it in\n\t * your migration. The document will be created when the migration is executed through the\n\t * `writeClient.migrate()` method.\n\t * @param document - The document from Prismic to create.\n\t * @param title - The title of the document to create which will be displayed in the editor.\n\t * @returns A migration document instance.\n\t */\n\tcreateDocumentFromPrismic<TType extends TDocuments[\"type\"]>(\n\t\tdocument: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>,\n\t\ttitle: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {\n\t\tconst doc = new PrismicMigrationDocument(\n\t\t\tthis.#migratePrismicDocumentData({\n\t\t\t\ttype: document.type,\n\t\t\t\tlang: document.lang,\n\t\t\t\tuid: document.uid,\n\t\t\t\ttags: document.tags,\n\t\t\t\tdata: document.data,\n\t\t\t}) as PendingPrismicDocument<ExtractDocumentType<TDocuments, TType>>,\n\t\t\ttitle,\n\t\t\t{ originalPrismicDocument: document },\n\t\t)\n\n\t\tthis._documents.push(doc)\n\n\t\treturn doc\n\t}\n\n\t/**\n\t * Queries a document from the migration instance with a specific UID and custom type.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst contentRelationship = migration.createContentRelationship(() =>\n\t * \t\tmigration.getByUID(\"blog_post\", \"my-first-post\"),\n\t * \t)\n\t * \t```\n\t *\n\t * @typeParam TType - Type of the Prismic document returned.\n\t * @param type - The API ID of the document's custom type.\n\t * @param uid - The UID of the document.\n\t * @returns The migration document instance with a UID matching the `uid` parameter, if a matching\n\t * document is found.\n\t */\n\tgetByUID<TType extends TDocuments[\"type\"]>(\n\t\ttype: TType,\n\t\tuid: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined {\n\t\treturn this._documents.find(\n\t\t\t(doc): doc is PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> =>\n\t\t\t\tdoc.document.type === type && doc.document.uid === uid,\n\t\t)\n\t}\n\n\t/**\n\t * Queries a singleton document from the migration instance for a specific custom type.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst contentRelationship = migration.createContentRelationship(() =>\n\t * \t\tmigration.getSingle(\"settings\"),\n\t * \t)\n\t * \t```\n\t *\n\t * @typeParam TType - Type of the Prismic document returned.\n\t * @param type - The API ID of the singleton custom type.\n\t * @returns The migration document instance for the custom type, if a matching\n\t * document is found.\n\t */\n\tgetSingle<TType extends TDocuments[\"type\"]>(\n\t\ttype: TType,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined {\n\t\treturn this._documents.find(\n\t\t\t(doc): doc is PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> =>\n\t\t\t\tdoc.document.type === type,\n\t\t)\n\t}\n\n\t/**\n\t * Migrates a Prismic document data from another repository so that it can be created through the\n\t * current repository's Migration API.\n\t *\n\t * @param input - The Prismic document data to migrate.\n\t * @returns The migrated Prismic document data.\n\t */\n\t#migratePrismicDocumentData(input: unknown): unknown {\n\t\tif (is.filledContentRelationship(input)) {\n\t\t\tconst optionalLinkProperties = getOptionalLinkProperties(input)\n\n\t\t\tif (input.isBroken) {\n\t\t\t\treturn {\n\t\t\t\t\t...optionalLinkProperties,\n\t\t\t\t\tlink_type: LinkType.Document,\n\t\t\t\t\t// ID needs to be 16 characters long to be considered valid by the API\n\t\t\t\t\tid: \"_____broken_____\",\n\t\t\t\t\tisBroken: true,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\tlink_type: LinkType.Document,\n\t\t\t\tid: () => this._getByOriginalID(input.id),\n\t\t\t}\n\t\t}\n\n\t\tif (is.filledLinkToMedia(input)) {\n\t\t\tconst optionalLinkProperties = getOptionalLinkProperties(input)\n\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\tlink_type: LinkType.Media,\n\t\t\t\tid: this.createAsset(input),\n\t\t\t}\n\t\t}\n\n\t\tif (is.rtImageNode(input)) {\n\t\t\t// Rich text image nodes\n\t\t\tconst rtImageNode: MigrationRTImageNode = {\n\t\t\t\ttype: RichTextNodeType.image,\n\t\t\t\tid: this.createAsset(input),\n\t\t\t}\n\n\t\t\tif (input.linkTo) {\n\t\t\t\trtImageNode.linkTo = this.#migratePrismicDocumentData(input.linkTo) as\n\t\t\t\t\t| MigrationContentRelationship\n\t\t\t\t\t| MigrationLinkToMedia\n\t\t\t\t\t| FilledLinkToWebField\n\t\t\t}\n\n\t\t\treturn rtImageNode\n\t\t}\n\n\t\tif (is.filledImage(input)) {\n\t\t\tconst image: MigrationImage = {\n\t\t\t\tid: this.createAsset(input),\n\t\t\t}\n\n\t\t\tconst {\n\t\t\t\tid: _id,\n\t\t\t\turl: _url,\n\t\t\t\tdimensions: _dimensions,\n\t\t\t\tedit: _edit,\n\t\t\t\talt: _alt,\n\t\t\t\tcopyright: _copyright,\n\t\t\t\t...thumbnails\n\t\t\t} = input\n\n\t\t\tfor (const name in thumbnails) {\n\t\t\t\tif (is.filledImage(thumbnails[name])) {\n\t\t\t\t\timage[name] = this.createAsset(thumbnails[name])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn image\n\t\t}\n\n\t\tif (Array.isArray(input)) {\n\t\t\treturn input.map((element) => this.#migratePrismicDocumentData(element))\n\t\t}\n\n\t\tif (input && typeof input === \"object\") {\n\t\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\t\tfor (const key in input) {\n\t\t\t\tres[key] = this.#migratePrismicDocumentData(input[key as keyof typeof input])\n\t\t\t}\n\n\t\t\treturn res\n\t\t}\n\n\t\treturn input\n\t}\n\n\t/**\n\t * Queries a document from the migration instance for a specific original ID.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst contentRelationship = migration.createContentRelationship(() =>\n\t * \t\tmigration._getByOriginalID(\"YhdrDxIAACgAcp_b\"),\n\t * \t)\n\t * \t```\n\t *\n\t * @typeParam TType - Type of the Prismic document returned.\n\t * @param id - The original ID of the Prismic document.\n\t * @returns The migration document instance for the original ID, if a matching\n\t * document is found.\n\t * @internal\n\t */\n\t_getByOriginalID<TType extends TDocuments[\"type\"]>(\n\t\tid: string,\n\t): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined {\n\t\treturn this._documents.find(\n\t\t\t(doc): doc is PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> =>\n\t\t\t\tdoc.originalPrismicDocument?.id === id,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,IAAa,YAAb,MAA6E;;;;;;CAM5E,0BAAoE,IAAI,IAAI;;;;;;CAO5E,aAAqD,CAAC;;;;;;;;;;;CA+DtD,YACC,oBAKA,UACA,EACC,OACA,SACA,KACA,SAMG,CAAC,GACmB;EACxB,IAAI;EACJ,IAAI;EACJ,IAAI,OAAO,uBAAuB,YAAY,SAAS,oBAAoB;GAC1E,IAAI,gBAAgB,sBAAsB,eAAe,oBAAoB;IAC5E,MAAM,MAAM,mBAAmB,IAAI,MAAM,GAAG,CAAC,CAAC;IAC9C,MAAM,WACL,UAAU,qBACP,mBAAmB,OACn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e,KAAK,GAAG;GAC1B,MAAM,QAAwB,EAC7B,IAAI,KAAK,YAAY,KAAK,EAC3B;GAEA,MAAM,EACL,IAAI,KACJ,KAAK,MACL,YAAY,aACZ,MAAM,OACN,KAAK,MACL,WAAW,YACX,GAAG,eACA;GAEJ,KAAK,MAAM,QAAQ,YAClB,IAAIA,YAAe,WAAW,KAAK,GAClC,MAAM,QAAQ,KAAK,YAAY,WAAW,KAAK;GAIjD,OAAO;EACR;EAEA,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,KAAK,YAAY,KAAK,4BAA4B,OAAO,CAAC;EAGxE,IAAI,SAAS,OAAO,UAAU,UAAU;GACvC,MAAM,MAAoC,CAAC;GAE3C,KAAK,MAAM,OAAO,OACjB,IAAI,OAAO,KAAK,4BAA4B,MAAM,IAA0B;GAG7E,OAAO;EACR;EAEA,OAAO;CACR;;;;;;;;;;;;;;;;;CAkBA,iBACC,IAC+E;EAC/E,OAAO,KAAK,WAAW,MACrB,QACA,IAAI,yBAAyB,OAAO,EACtC;CACD;AACD"}
|
package/dist/WriteClient.cjs
CHANGED
|
@@ -65,27 +65,24 @@ var WriteClient = class extends require_Client.Client {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Publishes the repository's migration release, moving its documents into the
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @param params - Additional fetch parameters.
|
|
72
|
-
*
|
|
73
|
-
* @returns The result of the publish operation, including the total number of
|
|
74
|
-
* documents that were published.
|
|
68
|
+
* Publishes the repository's migration release, moving its documents into the repository as
|
|
69
|
+
* published content.
|
|
75
70
|
*
|
|
76
71
|
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const migration = createMigration()
|
|
77
74
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* // Prepare and run a migration.
|
|
82
|
-
* migration.createDocument(doc, "My document")
|
|
83
|
-
* await writeClient.migrate(migration)
|
|
75
|
+
* // Prepare and run a migration.
|
|
76
|
+
* migration.createDocument(doc, "My document")
|
|
77
|
+
* await writeClient.migrate(migration)
|
|
84
78
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
79
|
+
* // Publish the migration release.
|
|
80
|
+
* const { totalItems } = await writeClient.publishMigrationRelease()
|
|
81
|
+
* ```
|
|
88
82
|
*
|
|
83
|
+
* @param params - Additional fetch parameters.
|
|
84
|
+
* @returns The result of the publish operation, including the total number of documents that were
|
|
85
|
+
* published.
|
|
89
86
|
* @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
|
|
90
87
|
*/
|
|
91
88
|
async publishMigrationRelease(params) {
|
|
@@ -160,8 +157,10 @@ var WriteClient = class extends require_Client.Client {
|
|
|
160
157
|
data: { masterLocale }
|
|
161
158
|
});
|
|
162
159
|
const documentsToCreate = [];
|
|
163
|
-
for (const doc of migration._documents) if (!doc.document.id)
|
|
164
|
-
|
|
160
|
+
for (const doc of migration._documents) if (!doc.document.id) {
|
|
161
|
+
if (doc.document.lang === masterLocale) documentsToCreate.unshift(doc);
|
|
162
|
+
else documentsToCreate.push(doc);
|
|
163
|
+
}
|
|
165
164
|
let created = 0;
|
|
166
165
|
for (const doc of documentsToCreate) {
|
|
167
166
|
reporter?.({
|
|
@@ -473,7 +472,10 @@ var WriteClient = class extends require_Client.Client {
|
|
|
473
472
|
switch (response.status) {
|
|
474
473
|
case 400: throw new require_errors.InvalidDataError(message, response.url, payload);
|
|
475
474
|
case 401: throw new require_errors.ForbiddenError(message, response.url, payload);
|
|
476
|
-
case 403:
|
|
475
|
+
case 403: {
|
|
476
|
+
const msg = message ?? payload.Message;
|
|
477
|
+
throw new require_errors.ForbiddenError(msg, response.url, payload);
|
|
478
|
+
}
|
|
477
479
|
case 404: throw new require_errors.NotFoundError(message, response.url, payload);
|
|
478
480
|
default: throw new require_errors.PrismicError(message, response.url, payload);
|
|
479
481
|
}
|
package/dist/WriteClient.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.cjs","names":["name","version","Client","devMsg","#request","#handleMigrationAPIError","resolveMigrationContentRelationship","resolveMigrationDocumentData","#handleAssetAPIError","PrismicError","pLimit","request","ForbiddenError","NotFoundError","InvalidDataError"],"sources":["../src/WriteClient.ts"],"sourcesContent":["import { name, version } from \"../package.json\"\nimport { Client } from \"./Client\"\nimport type { ClientConfig, FetchParams } from \"./Client\"\n// oxlint-disable-next-line no-unused-vars\nimport type { createMigration } from \"./createMigration\"\nimport { ForbiddenError, InvalidDataError, NotFoundError, PrismicError } from \"./errors\"\nimport { devMsg } from \"./lib/devMsg\"\nimport { pLimit } from \"./lib/pLimit\"\nimport type { ResponseLike } from \"./lib/request\"\nimport { type RequestInitLike, request } from \"./lib/request\"\nimport {\n\tresolveMigrationContentRelationship,\n\tresolveMigrationDocumentData,\n} from \"./lib/resolveMigrationDocumentData\"\nimport type { Migration } from \"./Migration\"\nimport type {\n\tAsset,\n\tPatchAssetParams,\n\tPostAssetParams,\n\tPostAssetResult,\n} from \"./types/api/asset/asset\"\nimport type { AssetTag, GetAssetTagsResult, PostAssetTagResult } from \"./types/api/asset/tag\"\nimport { type PostDocumentResult } from \"./types/api/migration/document\"\nimport type { PublishMigrationReleaseResult } from \"./types/api/migration/release\"\nimport type { PrismicMigrationAsset } from \"./types/migration/Asset\"\nimport type {\n\tMigrationDocument,\n\tPendingPrismicDocument,\n\tPrismicMigrationDocument,\n} from \"./types/migration/Document\"\nimport type { PrismicDocument } from \"./types/value/document\"\n\nconst CLIENT_IDENTIFIER = `${name.replace(\"@\", \"\").replace(\"/\", \"-\")}/${version}`\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic document type. If no\n * matches are found, no extraction is performed and the union of all provided Prismic document\n * types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/** Utility type to construct events reported by the migration process. */\ntype MigrateReporterEvent<TType extends string, TData = never> = TData extends never\n\t? { type: TType }\n\t: {\n\t\t\ttype: TType\n\t\t\tdata: TData\n\t\t}\n\n/** A map of event types and their data reported by the migration process. */\ntype MigrateReporterEventMap = {\n\tstart: {\n\t\tpending: {\n\t\t\tdocuments: number\n\t\t\tassets: number\n\t\t}\n\t}\n\tend: {\n\t\tmigrated: {\n\t\t\tdocuments: number\n\t\t\tassets: number\n\t\t}\n\t}\n\t\"assets:creating\": {\n\t\tcurrent: number\n\t\tremaining: number\n\t\ttotal: number\n\t\tasset: PrismicMigrationAsset\n\t}\n\t\"assets:created\": {\n\t\tcreated: number\n\t}\n\t\"documents:masterLocale\": {\n\t\tmasterLocale: string\n\t}\n\t\"documents:creating\": {\n\t\tcurrent: number\n\t\tremaining: number\n\t\ttotal: number\n\t\tdocument: PrismicMigrationDocument\n\t}\n\t\"documents:created\": {\n\t\tcreated: number\n\t}\n\t\"documents:updating\": {\n\t\tcurrent: number\n\t\tremaining: number\n\t\ttotal: number\n\t\tdocument: PrismicMigrationDocument\n\t}\n\t\"documents:updated\": {\n\t\tupdated: number\n\t}\n}\n\n/** Available event types reported by the migration process. */\ntype MigrateReporterEventTypes = keyof MigrateReporterEventMap\n\n/**\n * All events reported by the migration process. Events can be listened to by providing a `reporter`\n * function to the `migrate` method.\n */\nexport type MigrateReporterEvents = {\n\t[K in MigrateReporterEventTypes]: MigrateReporterEvent<K, MigrateReporterEventMap[K]>\n}[MigrateReporterEventTypes]\n\n/** Additional parameters for creating an asset in the Prismic media library. */\nexport type CreateAssetParams = {\n\t/** Asset notes. */\n\tnotes?: string\n\n\t/** Asset credits. */\n\tcredits?: string\n\n\t/** Asset alt text. */\n\talt?: string\n\n\t/** Asset tags. */\n\ttags?: string[]\n}\n\n/** Configuration for clients that determine how content is queried. */\nexport type WriteClientConfig = {\n\t/** A Prismic write token that allows writing content to the repository. */\n\twriteToken: string\n\n\t/**\n\t * The Prismic Asset API endpoint.\n\t *\n\t * @defaultValue `\"https://asset-api.prismic.io/\"`\n\t * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}\n\t */\n\tassetAPIEndpoint?: string\n\n\t/**\n\t * The Prismic Migration API endpoint.\n\t *\n\t * @defaultValue `\"https://migration.prismic.io/\"`\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tmigrationAPIEndpoint?: string\n} & ClientConfig\n\n/**\n * A client that allows querying and writing content to a Prismic repository.\n *\n * If used in an environment where a global `fetch` function is unavailable, such as Node.js, the\n * `fetch` option must be provided as part of the `options` parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic repository. Query\n * methods will automatically be typed based on this type.\n */\nexport class WriteClient<\n\tTDocuments extends PrismicDocument = PrismicDocument,\n> extends Client<TDocuments> {\n\twriteToken: string\n\n\tassetAPIEndpoint = \"https://asset-api.prismic.io/\"\n\tmigrationAPIEndpoint = \"https://migration.prismic.io/\"\n\n\t/**\n\t * Creates a Prismic client that can be used to query and write content to a repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable, such as in some\n\t * Node.js versions, the `fetch` option must be provided as part of the `options` parameter.\n\t *\n\t * @param repositoryName - The Prismic repository name for the repository.\n\t * @param options - Configuration that determines how content will be queried from and written to\n\t * the Prismic repository.\n\t * @returns A client that can query and write content to the repository.\n\t */\n\tconstructor(repositoryName: string, options: WriteClientConfig) {\n\t\tsuper(repositoryName, options)\n\n\t\tif (typeof globalThis.window !== \"undefined\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] Prismic write client appears to be running in a browser environment. This is not recommended as it exposes your write token. Consider using Prismic write client in a server environment only, preferring the regular client for browser environment. For more details, see ${devMsg(\"avoid-write-client-in-browser\")}`,\n\t\t\t)\n\t\t}\n\n\t\tthis.writeToken = options.writeToken\n\n\t\tif (options.assetAPIEndpoint) {\n\t\t\tthis.assetAPIEndpoint = `${options.assetAPIEndpoint}/`\n\t\t}\n\n\t\tif (options.migrationAPIEndpoint) {\n\t\t\tthis.migrationAPIEndpoint = `${options.migrationAPIEndpoint}/`\n\t\t}\n\t}\n\n\t/**\n\t * Creates a migration release on the Prismic repository based on the provided prepared migration.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tasync migrate(\n\t\tmigration: Migration<TDocuments>,\n\t\tparams: {\n\t\t\treporter?: (event: MigrateReporterEvents) => void\n\t\t} & FetchParams = {},\n\t): Promise<void> {\n\t\tparams.reporter?.({\n\t\t\ttype: \"start\",\n\t\t\tdata: {\n\t\t\t\tpending: {\n\t\t\t\t\tdocuments: migration._documents.length,\n\t\t\t\t\tassets: migration._assets.size,\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\n\t\tawait this.migrateCreateAssets(migration, params)\n\t\tawait this.migrateCreateDocuments(migration, params)\n\t\tawait this.migrateUpdateDocuments(migration, params)\n\n\t\tparams.reporter?.({\n\t\t\ttype: \"end\",\n\t\t\tdata: {\n\t\t\t\tmigrated: {\n\t\t\t\t\tdocuments: migration._documents.length,\n\t\t\t\t\tassets: migration._assets.size,\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t}\n\n\t/**\n\t * Publishes the repository's migration release, moving its documents into the\n\t * repository as published content.\n\t *\n\t * @param params - Additional fetch parameters.\n\t *\n\t * @returns The result of the publish operation, including the total number of\n\t * documents that were published.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const migration = createMigration()\n\t *\n\t * // Prepare and run a migration.\n\t * migration.createDocument(doc, \"My document\")\n\t * await writeClient.migrate(migration)\n\t *\n\t * // Publish the migration release.\n\t * const { totalItems } = await writeClient.publishMigrationRelease()\n\t * ```\n\t *\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tasync publishMigrationRelease(\n\t\tparams?: FetchParams,\n\t): Promise<PublishMigrationReleaseResult> {\n\t\tconst url = new URL(\"migration-release/publish\", this.migrationAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\t// A body is included so `request()` treats this as a write: it is\n\t\t\t// routed through the per-host write throttle and, crucially, is not\n\t\t\t// deduplicated with concurrent publishes from other repositories\n\t\t\t// (which share this URL but differ only by auth headers).\n\t\t\tbody: JSON.stringify({}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"x-client\": CLIENT_IDENTIFIER,\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 202: {\n\t\t\t\tconst json = (await response.json()) as PublishMigrationReleaseResult\n\n\t\t\t\treturn { totalItems: json.totalItems }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleMigrationAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates assets in the Prismic repository's media library.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @internal This method is one of the step performed by the {@link migrate} method.\n\t */\n\tprivate async migrateCreateAssets(\n\t\tmigration: Migration<TDocuments>,\n\t\t{\n\t\t\treporter,\n\t\t\t...fetchParams\n\t\t}: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {},\n\t): Promise<void> {\n\t\tlet created = 0\n\t\tfor (const [_, migrationAsset] of migration._assets) {\n\t\t\treporter?.({\n\t\t\t\ttype: \"assets:creating\",\n\t\t\t\tdata: {\n\t\t\t\t\tcurrent: ++created,\n\t\t\t\t\tremaining: migration._assets.size - created,\n\t\t\t\t\ttotal: migration._assets.size,\n\t\t\t\t\tasset: migrationAsset,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tconst { file, filename, notes, credits, alt, tags } = migrationAsset.config\n\n\t\t\tlet resolvedFile: PostAssetParams[\"file\"] | File\n\t\t\tif (typeof file === \"string\") {\n\t\t\t\tlet url: URL | undefined\n\t\t\t\ttry {\n\t\t\t\t\turl = new URL(file)\n\t\t\t\t} catch {\n\t\t\t\t\t// noop only on invalid URL, fetch errors will throw in the next if statement\n\t\t\t\t}\n\n\t\t\t\tif (url) {\n\t\t\t\t\t// File is a URL, fetch it\n\t\t\t\t\tresolvedFile = await this.fetchForeignAsset(url.toString(), fetchParams)\n\t\t\t\t} else {\n\t\t\t\t\t// File is actual file content, use it as-is\n\t\t\t\t\tresolvedFile = file\n\t\t\t\t}\n\t\t\t} else if (file instanceof URL) {\n\t\t\t\t// File is a URL instance, fetch it\n\t\t\t\tresolvedFile = await this.fetchForeignAsset(file.toString(), fetchParams)\n\t\t\t} else {\n\t\t\t\tresolvedFile = file\n\t\t\t}\n\n\t\t\tconst asset = await this.createAsset(resolvedFile, filename, {\n\t\t\t\tnotes,\n\t\t\t\tcredits,\n\t\t\t\talt,\n\t\t\t\ttags,\n\t\t\t\t...fetchParams,\n\t\t\t})\n\n\t\t\tmigrationAsset.asset = asset\n\t\t}\n\n\t\treporter?.({\n\t\t\ttype: \"assets:created\",\n\t\t\tdata: {\n\t\t\t\tcreated,\n\t\t\t},\n\t\t})\n\t}\n\n\t/**\n\t * Creates documents in the Prismic repository's migration release.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @internal This method is one of the step performed by the {@link migrate} method.\n\t */\n\tprivate async migrateCreateDocuments(\n\t\tmigration: Migration<TDocuments>,\n\t\t{\n\t\t\treporter,\n\t\t\t...fetchParams\n\t\t}: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {},\n\t): Promise<void> {\n\t\t// Resolve master locale\n\t\tconst repository = await this.getRepository(fetchParams)\n\t\tconst masterLocale = repository.languages[0].id\n\t\treporter?.({\n\t\t\ttype: \"documents:masterLocale\",\n\t\t\tdata: {\n\t\t\t\tmasterLocale,\n\t\t\t},\n\t\t})\n\n\t\tconst documentsToCreate: PrismicMigrationDocument<TDocuments>[] = []\n\t\t// We create an array with non-master locale documents last because\n\t\t// we need their master locale document to be created first.\n\t\tfor (const doc of migration._documents) {\n\t\t\tif (!doc.document.id) {\n\t\t\t\tif (doc.document.lang === masterLocale) {\n\t\t\t\t\tdocumentsToCreate.unshift(doc)\n\t\t\t\t} else {\n\t\t\t\t\tdocumentsToCreate.push(doc)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet created = 0\n\t\tfor (const doc of documentsToCreate) {\n\t\t\treporter?.({\n\t\t\t\ttype: \"documents:creating\",\n\t\t\t\tdata: {\n\t\t\t\t\tcurrent: ++created,\n\t\t\t\t\tremaining: documentsToCreate.length - created,\n\t\t\t\t\ttotal: documentsToCreate.length,\n\t\t\t\t\tdocument: doc,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\t// Resolve master language document ID for non-master locale documents\n\t\t\tlet masterLanguageDocumentID: string | undefined\n\t\t\tif (doc.masterLanguageDocument) {\n\t\t\t\tconst masterLanguageDocument = await resolveMigrationContentRelationship(\n\t\t\t\t\tdoc.masterLanguageDocument,\n\t\t\t\t)\n\n\t\t\t\tmasterLanguageDocumentID =\n\t\t\t\t\t\"id\" in masterLanguageDocument ? masterLanguageDocument.id : undefined\n\t\t\t} else if (doc.originalPrismicDocument) {\n\t\t\t\tconst maybeOriginalID = doc.originalPrismicDocument.alternate_languages.find(\n\t\t\t\t\t({ lang }) => lang === masterLocale,\n\t\t\t\t)?.id\n\n\t\t\t\tif (maybeOriginalID) {\n\t\t\t\t\tmasterLanguageDocumentID = migration._getByOriginalID(maybeOriginalID)?.document.id\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { id } = await this.createDocument(\n\t\t\t\t// We'll upload documents data later on.\n\t\t\t\t{ ...doc.document, data: {} },\n\t\t\t\tdoc.title!,\n\t\t\t\t{\n\t\t\t\t\tmasterLanguageDocumentID,\n\t\t\t\t\t...fetchParams,\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tdoc.document.id = id\n\t\t}\n\n\t\treporter?.({\n\t\t\ttype: \"documents:created\",\n\t\t\tdata: { created },\n\t\t})\n\t}\n\n\t/**\n\t * Updates documents in the Prismic repository's migration release with their patched data.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @internal This method is one of the step performed by the {@link migrate} method.\n\t */\n\tprivate async migrateUpdateDocuments(\n\t\tmigration: Migration<TDocuments>,\n\t\t{\n\t\t\treporter,\n\t\t\t...fetchParams\n\t\t}: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {},\n\t): Promise<void> {\n\t\tlet i = 0\n\t\tfor (const doc of migration._documents) {\n\t\t\treporter?.({\n\t\t\t\ttype: \"documents:updating\",\n\t\t\t\tdata: {\n\t\t\t\t\tcurrent: ++i,\n\t\t\t\t\tremaining: migration._documents.length - i,\n\t\t\t\t\ttotal: migration._documents.length,\n\t\t\t\t\tdocument: doc,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tawait this.updateDocument(\n\t\t\t\tdoc.document.id!,\n\t\t\t\t// We need to forward again document name and tags to update them\n\t\t\t\t// in case the document already existed during the previous step.\n\t\t\t\t{\n\t\t\t\t\t...doc.document,\n\t\t\t\t\tdocumentTitle: doc.title,\n\t\t\t\t\tdata: await resolveMigrationDocumentData(doc.document.data, migration),\n\t\t\t\t},\n\t\t\t\tfetchParams,\n\t\t\t)\n\t\t}\n\n\t\treporter?.({\n\t\t\ttype: \"documents:updated\",\n\t\t\tdata: {\n\t\t\t\tupdated: migration._documents.length,\n\t\t\t},\n\t\t})\n\t}\n\n\t/**\n\t * Creates an asset in the Prismic media library.\n\t *\n\t * @param file - The file to upload as an asset.\n\t * @param filename - The filename of the asset.\n\t * @param params - Additional asset data and fetch parameters.\n\t * @returns The created asset.\n\t */\n\tprivate async createAsset(\n\t\tfile: PostAssetParams[\"file\"] | File,\n\t\tfilename: string,\n\t\t{ notes, credits, alt, tags, ...params }: CreateAssetParams & FetchParams = {},\n\t): Promise<Asset> {\n\t\tconst url = new URL(\"assets\", this.assetAPIEndpoint)\n\n\t\tconst formData = new FormData()\n\t\tformData.append(\n\t\t\t\"file\",\n\t\t\tnew File([file], filename, {\n\t\t\t\ttype: file instanceof File ? file.type : undefined,\n\t\t\t}),\n\t\t)\n\n\t\tif (notes) {\n\t\t\tformData.append(\"notes\", notes)\n\t\t}\n\n\t\tif (credits) {\n\t\t\tformData.append(\"credits\", credits)\n\t\t}\n\n\t\tif (alt) {\n\t\t\tformData.append(\"alt\", alt)\n\t\t}\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: formData,\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\tconst asset = (await response.json()) as PostAssetResult\n\n\t\t\t\tif (tags && tags.length) {\n\t\t\t\t\treturn this.updateAsset(asset.id, { tags })\n\t\t\t\t}\n\n\t\t\t\treturn asset\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates an asset in the Prismic media library.\n\t *\n\t * @param id - The ID of the asset to update.\n\t * @param params - The asset data to update and additional fetch parameters.\n\t * @returns The updated asset.\n\t */\n\tprivate async updateAsset(\n\t\tid: string,\n\t\t{ notes, credits, alt, filename, tags, ...params }: PatchAssetParams & FetchParams = {},\n\t): Promise<Asset> {\n\t\tconst url = new URL(`assets/${id}`, this.assetAPIEndpoint)\n\n\t\t// Resolve tags if any and create missing ones\n\t\tif (tags && tags.length) {\n\t\t\ttags = await this.resolveAssetTagIDs(tags, {\n\t\t\t\tcreateTags: true,\n\t\t\t\t...params,\n\t\t\t})\n\t\t}\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"PATCH\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnotes,\n\t\t\t\tcredits,\n\t\t\t\talt,\n\t\t\t\tfilename,\n\t\t\t\ttags,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\treturn (await response.json()) as Asset\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Fetches a foreign asset from a URL.\n\t *\n\t * @param url - The URL of the asset to fetch.\n\t * @param params - Additional fetch parameters.\n\t * @returns A file representing the fetched asset.\n\t */\n\tprivate async fetchForeignAsset(url: string, params: FetchParams = {}): Promise<Blob> {\n\t\tconst res = await this.#request(new URL(url), params)\n\n\t\tif (!res.ok) {\n\t\t\tthrow new PrismicError(\"Could not fetch foreign asset\", url, undefined)\n\t\t}\n\n\t\tconst buffer = await res.arrayBuffer()\n\n\t\t// Ensure a correct content type is attached to the blob.\n\t\treturn new File([buffer], \"\", {\n\t\t\ttype: res.headers.get(\"content-type\") || undefined,\n\t\t})\n\t}\n\n\t/** {@link resolveAssetTagIDs} rate limiter. */\n\tprivate _resolveAssetTagIDsLimit = pLimit()\n\n\t/**\n\t * Resolves asset tag IDs from tag names.\n\t *\n\t * @param tagNames - An array of tag names to resolve.\n\t * @param params - Whether or not missing tags should be created and additional fetch parameters.\n\t * @returns An array of resolved tag IDs.\n\t */\n\tprivate async resolveAssetTagIDs(\n\t\ttagNames: string[] = [],\n\t\t{ createTags, ...params }: { createTags?: boolean } & FetchParams = {},\n\t): Promise<string[]> {\n\t\treturn this._resolveAssetTagIDsLimit(async () => {\n\t\t\tconst existingTags = await this.getAssetTags(params)\n\t\t\tconst existingTagMap: Record<string, AssetTag> = {}\n\t\t\tfor (const tag of existingTags) {\n\t\t\t\texistingTagMap[tag.name] = tag\n\t\t\t}\n\n\t\t\tconst resolvedTagIDs = []\n\t\t\tfor (const tagName of tagNames) {\n\t\t\t\t// Tag does not exists yet, we create it if `createTags` is set\n\t\t\t\tif (!existingTagMap[tagName] && createTags) {\n\t\t\t\t\texistingTagMap[tagName] = await this.createAssetTag(tagName, params)\n\t\t\t\t}\n\n\t\t\t\t// Add tag if found\n\t\t\t\tif (existingTagMap[tagName]) {\n\t\t\t\t\tresolvedTagIDs.push(existingTagMap[tagName].id)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn resolvedTagIDs\n\t\t})\n\t}\n\n\t/**\n\t * Creates a tag in the Asset API.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t * @param name - The name of the tag to create.\n\t * @param params - Additional fetch parameters.\n\t * @returns The created tag.\n\t */\n\tprivate async createAssetTag(name: string, params?: FetchParams): Promise<AssetTag> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({ name }),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 201: {\n\t\t\t\treturn (await response.json()) as PostAssetTagResult\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Queries existing tags from the Asset API.\n\t *\n\t * @param params - Additional fetch parameters.\n\t * @returns An array of existing tags.\n\t */\n\tprivate async getAssetTags(params?: FetchParams): Promise<AssetTag[]> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params)\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\tconst json = (await response.json()) as GetAssetTagsResult\n\n\t\t\t\treturn json.items\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a document in the repository's migration release.\n\t *\n\t * @typeParam TType - Type of Prismic documents to create.\n\t * @param document - The document to create.\n\t * @param documentTitle - The title of the document to create which will be displayed in the\n\t * editor.\n\t * @param params - Document master language document ID and additional fetch parameters.\n\t * @returns The ID of the created document.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate async createDocument<TType extends TDocuments[\"type\"]>(\n\t\tdocument: PendingPrismicDocument<ExtractDocumentType<TDocuments, TType>>,\n\t\tdocumentTitle: string,\n\t\t{\n\t\t\tmasterLanguageDocumentID,\n\t\t\t...params\n\t\t}: { masterLanguageDocumentID?: string } & FetchParams = {},\n\t): Promise<{ id: string }> {\n\t\tconst url = new URL(\"documents\", this.migrationAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\ttitle: documentTitle,\n\t\t\t\ttype: document.type,\n\t\t\t\tuid: document.uid || undefined,\n\t\t\t\tlang: document.lang,\n\t\t\t\talternate_language_id: masterLanguageDocumentID,\n\t\t\t\ttags: document.tags,\n\t\t\t\tdata: document.data,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"x-client\": CLIENT_IDENTIFIER,\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 201: {\n\t\t\t\tconst json = (await response.json()) as PostDocumentResult\n\n\t\t\t\treturn { id: json.id }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleMigrationAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates an existing document in the repository's migration release.\n\t *\n\t * @typeParam TType - Type of Prismic documents to update.\n\t * @param id - The ID of the document to update.\n\t * @param document - The document content to update.\n\t * @param params - Additional fetch parameters.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate async updateDocument<TType extends TDocuments[\"type\"]>(\n\t\tid: string,\n\t\tdocument: MigrationDocument<ExtractDocumentType<TDocuments, TType>> & {\n\t\t\tdocumentTitle?: string\n\t\t},\n\t\tparams?: FetchParams,\n\t): Promise<void> {\n\t\tconst url = new URL(`documents/${id}`, this.migrationAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"PUT\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\ttitle: document.documentTitle,\n\t\t\t\tuid: document.uid || undefined,\n\t\t\t\ttags: document.tags,\n\t\t\t\tdata: document.data,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"x-client\": CLIENT_IDENTIFIER,\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tawait this.#handleMigrationAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Makes an authenticated HTTP request for write operations using the client's configured fetch\n\t * function and options.\n\t *\n\t * @param url - The URL to request.\n\t * @param params - Fetch options from the user.\n\t * @param init - Additional fetch options to merge with the user-provided options.\n\t * @returns The response from the fetch request.\n\t */\n\tasync #request(url: URL, params?: FetchParams, init?: RequestInitLike): Promise<ResponseLike> {\n\t\treturn await request(\n\t\t\turl,\n\t\t\t{\n\t\t\t\t...this.fetchOptions,\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\t...init,\n\t\t\t\theaders: {\n\t\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t\t...params?.fetchOptions?.headers,\n\t\t\t\t\t...init?.headers,\n\t\t\t\t\trepository: this.repositoryName,\n\t\t\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\t\t},\n\t\t\t\tsignal: params?.fetchOptions?.signal || params?.signal || this.fetchOptions?.signal,\n\t\t\t},\n\t\t\tthis.fetchFn,\n\t\t)\n\t}\n\n\t/**\n\t * Handles error responses from the Asset API with comprehensive error parsing.\n\t *\n\t * @param response - The HTTP response from the Asset API.\n\t * @throws {@link InvalidDataError} For 400 errors.\n\t * @throws {@link ForbiddenError} For 401 and 403 errors.\n\t * @throws {@link NotFoundError} For 404 errors.\n\t * @throws {@link PrismicError} For 500, 503, and other unexpected errors.\n\t */\n\tasync #handleAssetAPIError(response: ResponseLike): Promise<never> {\n\t\tconst json = await response.json()\n\t\tswitch (response.status) {\n\t\t\tcase 401:\n\t\t\tcase 403:\n\t\t\t\tthrow new ForbiddenError(json.error, response.url, json)\n\n\t\t\tcase 404:\n\t\t\t\tthrow new NotFoundError(json.error, response.url, json)\n\n\t\t\tcase 400:\n\t\t\t\tthrow new InvalidDataError(json.error, response.url, json)\n\n\t\t\tcase 500:\n\t\t\tcase 503:\n\t\t\tdefault:\n\t\t\t\tthrow new PrismicError(json.error, response.url, json)\n\t\t}\n\t}\n\n\t/**\n\t * Handles error responses from the Migration API with comprehensive error parsing.\n\t *\n\t * @param response - The HTTP response from the Migration API.\n\t * @throws {@link InvalidDataError} For 400 errors.\n\t * @throws {@link ForbiddenError} For 401 and 403 errors.\n\t * @throws {@link NotFoundError} For 404 errors.\n\t * @throws {@link PrismicError} For 500, and other unexpected errors.\n\t */\n\tasync #handleMigrationAPIError(response: ResponseLike): Promise<never> {\n\t\tconst payload = (await response.json()) as unknown\n\n\t\t// Common message across all branches\n\t\tconst message = (payload as { message?: string }).message\n\n\t\tswitch (response.status) {\n\t\t\tcase 400: {\n\t\t\t\tthrow new InvalidDataError(message, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 401: {\n\t\t\t\tthrow new ForbiddenError(message, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 403: {\n\t\t\t\t// The lambda authorizer uses an uppercase key, remove this once it is fixed\n\t\t\t\tconst msg = message ?? (payload as { Message?: string }).Message\n\t\t\t\tthrow new ForbiddenError(msg, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 404: {\n\t\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IJ,eAAAA,aAAa,SAAS,SAAS,KAAK,QAAQ"}
|
|
1
|
+
{"version":3,"file":"WriteClient.cjs","names":["name","version","Client","devMsg","resolveMigrationContentRelationship","resolveMigrationDocumentData","PrismicError","pLimit","request","ForbiddenError","NotFoundError","InvalidDataError"],"sources":["../src/WriteClient.ts"],"sourcesContent":["import { name, version } from \"../package.json\"\nimport { Client } from \"./Client\"\nimport type { ClientConfig, FetchParams } from \"./Client\"\n// oxlint-disable-next-line no-unused-vars\nimport type { createMigration } from \"./createMigration\"\nimport { ForbiddenError, InvalidDataError, NotFoundError, PrismicError } from \"./errors\"\nimport { devMsg } from \"./lib/devMsg\"\nimport { pLimit } from \"./lib/pLimit\"\nimport type { ResponseLike } from \"./lib/request\"\nimport { type RequestInitLike, request } from \"./lib/request\"\nimport {\n\tresolveMigrationContentRelationship,\n\tresolveMigrationDocumentData,\n} from \"./lib/resolveMigrationDocumentData\"\nimport type { Migration } from \"./Migration\"\nimport type {\n\tAsset,\n\tPatchAssetParams,\n\tPostAssetParams,\n\tPostAssetResult,\n} from \"./types/api/asset/asset\"\nimport type { AssetTag, GetAssetTagsResult, PostAssetTagResult } from \"./types/api/asset/tag\"\nimport { type PostDocumentResult } from \"./types/api/migration/document\"\nimport type { PublishMigrationReleaseResult } from \"./types/api/migration/release\"\nimport type { PrismicMigrationAsset } from \"./types/migration/Asset\"\nimport type {\n\tMigrationDocument,\n\tPendingPrismicDocument,\n\tPrismicMigrationDocument,\n} from \"./types/migration/Document\"\nimport type { PrismicDocument } from \"./types/value/document\"\n\nconst CLIENT_IDENTIFIER = `${name.replace(\"@\", \"\").replace(\"/\", \"-\")}/${version}`\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic document type. If no\n * matches are found, no extraction is performed and the union of all provided Prismic document\n * types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/** Utility type to construct events reported by the migration process. */\ntype MigrateReporterEvent<TType extends string, TData = never> = TData extends never\n\t? { type: TType }\n\t: {\n\t\t\ttype: TType\n\t\t\tdata: TData\n\t\t}\n\n/** A map of event types and their data reported by the migration process. */\ntype MigrateReporterEventMap = {\n\tstart: {\n\t\tpending: {\n\t\t\tdocuments: number\n\t\t\tassets: number\n\t\t}\n\t}\n\tend: {\n\t\tmigrated: {\n\t\t\tdocuments: number\n\t\t\tassets: number\n\t\t}\n\t}\n\t\"assets:creating\": {\n\t\tcurrent: number\n\t\tremaining: number\n\t\ttotal: number\n\t\tasset: PrismicMigrationAsset\n\t}\n\t\"assets:created\": {\n\t\tcreated: number\n\t}\n\t\"documents:masterLocale\": {\n\t\tmasterLocale: string\n\t}\n\t\"documents:creating\": {\n\t\tcurrent: number\n\t\tremaining: number\n\t\ttotal: number\n\t\tdocument: PrismicMigrationDocument\n\t}\n\t\"documents:created\": {\n\t\tcreated: number\n\t}\n\t\"documents:updating\": {\n\t\tcurrent: number\n\t\tremaining: number\n\t\ttotal: number\n\t\tdocument: PrismicMigrationDocument\n\t}\n\t\"documents:updated\": {\n\t\tupdated: number\n\t}\n}\n\n/** Available event types reported by the migration process. */\ntype MigrateReporterEventTypes = keyof MigrateReporterEventMap\n\n/**\n * All events reported by the migration process. Events can be listened to by providing a `reporter`\n * function to the `migrate` method.\n */\nexport type MigrateReporterEvents = {\n\t[K in MigrateReporterEventTypes]: MigrateReporterEvent<K, MigrateReporterEventMap[K]>\n}[MigrateReporterEventTypes]\n\n/** Additional parameters for creating an asset in the Prismic media library. */\nexport type CreateAssetParams = {\n\t/** Asset notes. */\n\tnotes?: string\n\n\t/** Asset credits. */\n\tcredits?: string\n\n\t/** Asset alt text. */\n\talt?: string\n\n\t/** Asset tags. */\n\ttags?: string[]\n}\n\n/** Configuration for clients that determine how content is queried. */\nexport type WriteClientConfig = {\n\t/** A Prismic write token that allows writing content to the repository. */\n\twriteToken: string\n\n\t/**\n\t * The Prismic Asset API endpoint.\n\t *\n\t * @defaultValue `\"https://asset-api.prismic.io/\"`\n\t * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}\n\t */\n\tassetAPIEndpoint?: string\n\n\t/**\n\t * The Prismic Migration API endpoint.\n\t *\n\t * @defaultValue `\"https://migration.prismic.io/\"`\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tmigrationAPIEndpoint?: string\n} & ClientConfig\n\n/**\n * A client that allows querying and writing content to a Prismic repository.\n *\n * If used in an environment where a global `fetch` function is unavailable, such as Node.js, the\n * `fetch` option must be provided as part of the `options` parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic repository. Query\n * methods will automatically be typed based on this type.\n */\nexport class WriteClient<\n\tTDocuments extends PrismicDocument = PrismicDocument,\n> extends Client<TDocuments> {\n\twriteToken: string\n\n\tassetAPIEndpoint = \"https://asset-api.prismic.io/\"\n\tmigrationAPIEndpoint = \"https://migration.prismic.io/\"\n\n\t/**\n\t * Creates a Prismic client that can be used to query and write content to a repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable, such as in some\n\t * Node.js versions, the `fetch` option must be provided as part of the `options` parameter.\n\t *\n\t * @param repositoryName - The Prismic repository name for the repository.\n\t * @param options - Configuration that determines how content will be queried from and written to\n\t * the Prismic repository.\n\t * @returns A client that can query and write content to the repository.\n\t */\n\tconstructor(repositoryName: string, options: WriteClientConfig) {\n\t\tsuper(repositoryName, options)\n\n\t\tif (typeof globalThis.window !== \"undefined\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] Prismic write client appears to be running in a browser environment. This is not recommended as it exposes your write token. Consider using Prismic write client in a server environment only, preferring the regular client for browser environment. For more details, see ${devMsg(\"avoid-write-client-in-browser\")}`,\n\t\t\t)\n\t\t}\n\n\t\tthis.writeToken = options.writeToken\n\n\t\tif (options.assetAPIEndpoint) {\n\t\t\tthis.assetAPIEndpoint = `${options.assetAPIEndpoint}/`\n\t\t}\n\n\t\tif (options.migrationAPIEndpoint) {\n\t\t\tthis.migrationAPIEndpoint = `${options.migrationAPIEndpoint}/`\n\t\t}\n\t}\n\n\t/**\n\t * Creates a migration release on the Prismic repository based on the provided prepared migration.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tasync migrate(\n\t\tmigration: Migration<TDocuments>,\n\t\tparams: {\n\t\t\treporter?: (event: MigrateReporterEvents) => void\n\t\t} & FetchParams = {},\n\t): Promise<void> {\n\t\tparams.reporter?.({\n\t\t\ttype: \"start\",\n\t\t\tdata: {\n\t\t\t\tpending: {\n\t\t\t\t\tdocuments: migration._documents.length,\n\t\t\t\t\tassets: migration._assets.size,\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\n\t\tawait this.migrateCreateAssets(migration, params)\n\t\tawait this.migrateCreateDocuments(migration, params)\n\t\tawait this.migrateUpdateDocuments(migration, params)\n\n\t\tparams.reporter?.({\n\t\t\ttype: \"end\",\n\t\t\tdata: {\n\t\t\t\tmigrated: {\n\t\t\t\t\tdocuments: migration._documents.length,\n\t\t\t\t\tassets: migration._assets.size,\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t}\n\n\t/**\n\t * Publishes the repository's migration release, moving its documents into the repository as\n\t * published content.\n\t *\n\t * @example\n\t * \t```ts\n\t * \tconst migration = createMigration()\n\t *\n\t * \t// Prepare and run a migration.\n\t * \tmigration.createDocument(doc, \"My document\")\n\t * \tawait writeClient.migrate(migration)\n\t *\n\t * \t// Publish the migration release.\n\t * \tconst { totalItems } = await writeClient.publishMigrationRelease()\n\t * \t```\n\t *\n\t * @param params - Additional fetch parameters.\n\t * @returns The result of the publish operation, including the total number of documents that were\n\t * published.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tasync publishMigrationRelease(params?: FetchParams): Promise<PublishMigrationReleaseResult> {\n\t\tconst url = new URL(\"migration-release/publish\", this.migrationAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\t// A body is included so `request()` treats this as a write: it is\n\t\t\t// routed through the per-host write throttle and, crucially, is not\n\t\t\t// deduplicated with concurrent publishes from other repositories\n\t\t\t// (which share this URL but differ only by auth headers).\n\t\t\tbody: JSON.stringify({}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"x-client\": CLIENT_IDENTIFIER,\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 202: {\n\t\t\t\tconst json = (await response.json()) as PublishMigrationReleaseResult\n\n\t\t\t\treturn { totalItems: json.totalItems }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleMigrationAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates assets in the Prismic repository's media library.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @internal This method is one of the step performed by the {@link migrate} method.\n\t */\n\tprivate async migrateCreateAssets(\n\t\tmigration: Migration<TDocuments>,\n\t\t{\n\t\t\treporter,\n\t\t\t...fetchParams\n\t\t}: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {},\n\t): Promise<void> {\n\t\tlet created = 0\n\t\tfor (const [_, migrationAsset] of migration._assets) {\n\t\t\treporter?.({\n\t\t\t\ttype: \"assets:creating\",\n\t\t\t\tdata: {\n\t\t\t\t\tcurrent: ++created,\n\t\t\t\t\tremaining: migration._assets.size - created,\n\t\t\t\t\ttotal: migration._assets.size,\n\t\t\t\t\tasset: migrationAsset,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tconst { file, filename, notes, credits, alt, tags } = migrationAsset.config\n\n\t\t\tlet resolvedFile: PostAssetParams[\"file\"] | File\n\t\t\tif (typeof file === \"string\") {\n\t\t\t\tlet url: URL | undefined\n\t\t\t\ttry {\n\t\t\t\t\turl = new URL(file)\n\t\t\t\t} catch {\n\t\t\t\t\t// noop only on invalid URL, fetch errors will throw in the next if statement\n\t\t\t\t}\n\n\t\t\t\tif (url) {\n\t\t\t\t\t// File is a URL, fetch it\n\t\t\t\t\tresolvedFile = await this.fetchForeignAsset(url.toString(), fetchParams)\n\t\t\t\t} else {\n\t\t\t\t\t// File is actual file content, use it as-is\n\t\t\t\t\tresolvedFile = file\n\t\t\t\t}\n\t\t\t} else if (file instanceof URL) {\n\t\t\t\t// File is a URL instance, fetch it\n\t\t\t\tresolvedFile = await this.fetchForeignAsset(file.toString(), fetchParams)\n\t\t\t} else {\n\t\t\t\tresolvedFile = file\n\t\t\t}\n\n\t\t\tconst asset = await this.createAsset(resolvedFile, filename, {\n\t\t\t\tnotes,\n\t\t\t\tcredits,\n\t\t\t\talt,\n\t\t\t\ttags,\n\t\t\t\t...fetchParams,\n\t\t\t})\n\n\t\t\tmigrationAsset.asset = asset\n\t\t}\n\n\t\treporter?.({\n\t\t\ttype: \"assets:created\",\n\t\t\tdata: {\n\t\t\t\tcreated,\n\t\t\t},\n\t\t})\n\t}\n\n\t/**\n\t * Creates documents in the Prismic repository's migration release.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @internal This method is one of the step performed by the {@link migrate} method.\n\t */\n\tprivate async migrateCreateDocuments(\n\t\tmigration: Migration<TDocuments>,\n\t\t{\n\t\t\treporter,\n\t\t\t...fetchParams\n\t\t}: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {},\n\t): Promise<void> {\n\t\t// Resolve master locale\n\t\tconst repository = await this.getRepository(fetchParams)\n\t\tconst masterLocale = repository.languages[0].id\n\t\treporter?.({\n\t\t\ttype: \"documents:masterLocale\",\n\t\t\tdata: {\n\t\t\t\tmasterLocale,\n\t\t\t},\n\t\t})\n\n\t\tconst documentsToCreate: PrismicMigrationDocument<TDocuments>[] = []\n\t\t// We create an array with non-master locale documents last because\n\t\t// we need their master locale document to be created first.\n\t\tfor (const doc of migration._documents) {\n\t\t\tif (!doc.document.id) {\n\t\t\t\tif (doc.document.lang === masterLocale) {\n\t\t\t\t\tdocumentsToCreate.unshift(doc)\n\t\t\t\t} else {\n\t\t\t\t\tdocumentsToCreate.push(doc)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet created = 0\n\t\tfor (const doc of documentsToCreate) {\n\t\t\treporter?.({\n\t\t\t\ttype: \"documents:creating\",\n\t\t\t\tdata: {\n\t\t\t\t\tcurrent: ++created,\n\t\t\t\t\tremaining: documentsToCreate.length - created,\n\t\t\t\t\ttotal: documentsToCreate.length,\n\t\t\t\t\tdocument: doc,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\t// Resolve master language document ID for non-master locale documents\n\t\t\tlet masterLanguageDocumentID: string | undefined\n\t\t\tif (doc.masterLanguageDocument) {\n\t\t\t\tconst masterLanguageDocument = await resolveMigrationContentRelationship(\n\t\t\t\t\tdoc.masterLanguageDocument,\n\t\t\t\t)\n\n\t\t\t\tmasterLanguageDocumentID =\n\t\t\t\t\t\"id\" in masterLanguageDocument ? masterLanguageDocument.id : undefined\n\t\t\t} else if (doc.originalPrismicDocument) {\n\t\t\t\tconst maybeOriginalID = doc.originalPrismicDocument.alternate_languages.find(\n\t\t\t\t\t({ lang }) => lang === masterLocale,\n\t\t\t\t)?.id\n\n\t\t\t\tif (maybeOriginalID) {\n\t\t\t\t\tmasterLanguageDocumentID = migration._getByOriginalID(maybeOriginalID)?.document.id\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { id } = await this.createDocument(\n\t\t\t\t// We'll upload documents data later on.\n\t\t\t\t{ ...doc.document, data: {} },\n\t\t\t\tdoc.title!,\n\t\t\t\t{\n\t\t\t\t\tmasterLanguageDocumentID,\n\t\t\t\t\t...fetchParams,\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tdoc.document.id = id\n\t\t}\n\n\t\treporter?.({\n\t\t\ttype: \"documents:created\",\n\t\t\tdata: { created },\n\t\t})\n\t}\n\n\t/**\n\t * Updates documents in the Prismic repository's migration release with their patched data.\n\t *\n\t * @param migration - A migration prepared with {@link createMigration}.\n\t * @param params - An event listener and additional fetch parameters.\n\t * @internal This method is one of the step performed by the {@link migrate} method.\n\t */\n\tprivate async migrateUpdateDocuments(\n\t\tmigration: Migration<TDocuments>,\n\t\t{\n\t\t\treporter,\n\t\t\t...fetchParams\n\t\t}: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {},\n\t): Promise<void> {\n\t\tlet i = 0\n\t\tfor (const doc of migration._documents) {\n\t\t\treporter?.({\n\t\t\t\ttype: \"documents:updating\",\n\t\t\t\tdata: {\n\t\t\t\t\tcurrent: ++i,\n\t\t\t\t\tremaining: migration._documents.length - i,\n\t\t\t\t\ttotal: migration._documents.length,\n\t\t\t\t\tdocument: doc,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tawait this.updateDocument(\n\t\t\t\tdoc.document.id!,\n\t\t\t\t// We need to forward again document name and tags to update them\n\t\t\t\t// in case the document already existed during the previous step.\n\t\t\t\t{\n\t\t\t\t\t...doc.document,\n\t\t\t\t\tdocumentTitle: doc.title,\n\t\t\t\t\tdata: await resolveMigrationDocumentData(doc.document.data, migration),\n\t\t\t\t},\n\t\t\t\tfetchParams,\n\t\t\t)\n\t\t}\n\n\t\treporter?.({\n\t\t\ttype: \"documents:updated\",\n\t\t\tdata: {\n\t\t\t\tupdated: migration._documents.length,\n\t\t\t},\n\t\t})\n\t}\n\n\t/**\n\t * Creates an asset in the Prismic media library.\n\t *\n\t * @param file - The file to upload as an asset.\n\t * @param filename - The filename of the asset.\n\t * @param params - Additional asset data and fetch parameters.\n\t * @returns The created asset.\n\t */\n\tprivate async createAsset(\n\t\tfile: PostAssetParams[\"file\"] | File,\n\t\tfilename: string,\n\t\t{ notes, credits, alt, tags, ...params }: CreateAssetParams & FetchParams = {},\n\t): Promise<Asset> {\n\t\tconst url = new URL(\"assets\", this.assetAPIEndpoint)\n\n\t\tconst formData = new FormData()\n\t\tformData.append(\n\t\t\t\"file\",\n\t\t\tnew File([file], filename, {\n\t\t\t\ttype: file instanceof File ? file.type : undefined,\n\t\t\t}),\n\t\t)\n\n\t\tif (notes) {\n\t\t\tformData.append(\"notes\", notes)\n\t\t}\n\n\t\tif (credits) {\n\t\t\tformData.append(\"credits\", credits)\n\t\t}\n\n\t\tif (alt) {\n\t\t\tformData.append(\"alt\", alt)\n\t\t}\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: formData,\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\tconst asset = (await response.json()) as PostAssetResult\n\n\t\t\t\tif (tags && tags.length) {\n\t\t\t\t\treturn this.updateAsset(asset.id, { tags })\n\t\t\t\t}\n\n\t\t\t\treturn asset\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates an asset in the Prismic media library.\n\t *\n\t * @param id - The ID of the asset to update.\n\t * @param params - The asset data to update and additional fetch parameters.\n\t * @returns The updated asset.\n\t */\n\tprivate async updateAsset(\n\t\tid: string,\n\t\t{ notes, credits, alt, filename, tags, ...params }: PatchAssetParams & FetchParams = {},\n\t): Promise<Asset> {\n\t\tconst url = new URL(`assets/${id}`, this.assetAPIEndpoint)\n\n\t\t// Resolve tags if any and create missing ones\n\t\tif (tags && tags.length) {\n\t\t\ttags = await this.resolveAssetTagIDs(tags, {\n\t\t\t\tcreateTags: true,\n\t\t\t\t...params,\n\t\t\t})\n\t\t}\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"PATCH\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnotes,\n\t\t\t\tcredits,\n\t\t\t\talt,\n\t\t\t\tfilename,\n\t\t\t\ttags,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\treturn (await response.json()) as Asset\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Fetches a foreign asset from a URL.\n\t *\n\t * @param url - The URL of the asset to fetch.\n\t * @param params - Additional fetch parameters.\n\t * @returns A file representing the fetched asset.\n\t */\n\tprivate async fetchForeignAsset(url: string, params: FetchParams = {}): Promise<Blob> {\n\t\tconst res = await this.#request(new URL(url), params)\n\n\t\tif (!res.ok) {\n\t\t\tthrow new PrismicError(\"Could not fetch foreign asset\", url, undefined)\n\t\t}\n\n\t\tconst buffer = await res.arrayBuffer()\n\n\t\t// Ensure a correct content type is attached to the blob.\n\t\treturn new File([buffer], \"\", {\n\t\t\ttype: res.headers.get(\"content-type\") || undefined,\n\t\t})\n\t}\n\n\t/** {@link resolveAssetTagIDs} rate limiter. */\n\tprivate _resolveAssetTagIDsLimit = pLimit()\n\n\t/**\n\t * Resolves asset tag IDs from tag names.\n\t *\n\t * @param tagNames - An array of tag names to resolve.\n\t * @param params - Whether or not missing tags should be created and additional fetch parameters.\n\t * @returns An array of resolved tag IDs.\n\t */\n\tprivate async resolveAssetTagIDs(\n\t\ttagNames: string[] = [],\n\t\t{ createTags, ...params }: { createTags?: boolean } & FetchParams = {},\n\t): Promise<string[]> {\n\t\treturn this._resolveAssetTagIDsLimit(async () => {\n\t\t\tconst existingTags = await this.getAssetTags(params)\n\t\t\tconst existingTagMap: Record<string, AssetTag> = {}\n\t\t\tfor (const tag of existingTags) {\n\t\t\t\texistingTagMap[tag.name] = tag\n\t\t\t}\n\n\t\t\tconst resolvedTagIDs = []\n\t\t\tfor (const tagName of tagNames) {\n\t\t\t\t// Tag does not exists yet, we create it if `createTags` is set\n\t\t\t\tif (!existingTagMap[tagName] && createTags) {\n\t\t\t\t\texistingTagMap[tagName] = await this.createAssetTag(tagName, params)\n\t\t\t\t}\n\n\t\t\t\t// Add tag if found\n\t\t\t\tif (existingTagMap[tagName]) {\n\t\t\t\t\tresolvedTagIDs.push(existingTagMap[tagName].id)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn resolvedTagIDs\n\t\t})\n\t}\n\n\t/**\n\t * Creates a tag in the Asset API.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t * @param name - The name of the tag to create.\n\t * @param params - Additional fetch parameters.\n\t * @returns The created tag.\n\t */\n\tprivate async createAssetTag(name: string, params?: FetchParams): Promise<AssetTag> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({ name }),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 201: {\n\t\t\t\treturn (await response.json()) as PostAssetTagResult\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Queries existing tags from the Asset API.\n\t *\n\t * @param params - Additional fetch parameters.\n\t * @returns An array of existing tags.\n\t */\n\tprivate async getAssetTags(params?: FetchParams): Promise<AssetTag[]> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params)\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\tconst json = (await response.json()) as GetAssetTagsResult\n\n\t\t\t\treturn json.items\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleAssetAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a document in the repository's migration release.\n\t *\n\t * @typeParam TType - Type of Prismic documents to create.\n\t * @param document - The document to create.\n\t * @param documentTitle - The title of the document to create which will be displayed in the\n\t * editor.\n\t * @param params - Document master language document ID and additional fetch parameters.\n\t * @returns The ID of the created document.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate async createDocument<TType extends TDocuments[\"type\"]>(\n\t\tdocument: PendingPrismicDocument<ExtractDocumentType<TDocuments, TType>>,\n\t\tdocumentTitle: string,\n\t\t{\n\t\t\tmasterLanguageDocumentID,\n\t\t\t...params\n\t\t}: { masterLanguageDocumentID?: string } & FetchParams = {},\n\t): Promise<{ id: string }> {\n\t\tconst url = new URL(\"documents\", this.migrationAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\ttitle: documentTitle,\n\t\t\t\ttype: document.type,\n\t\t\t\tuid: document.uid || undefined,\n\t\t\t\tlang: document.lang,\n\t\t\t\talternate_language_id: masterLanguageDocumentID,\n\t\t\t\ttags: document.tags,\n\t\t\t\tdata: document.data,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"x-client\": CLIENT_IDENTIFIER,\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 201: {\n\t\t\t\tconst json = (await response.json()) as PostDocumentResult\n\n\t\t\t\treturn { id: json.id }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn await this.#handleMigrationAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates an existing document in the repository's migration release.\n\t *\n\t * @typeParam TType - Type of Prismic documents to update.\n\t * @param id - The ID of the document to update.\n\t * @param document - The document content to update.\n\t * @param params - Additional fetch parameters.\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate async updateDocument<TType extends TDocuments[\"type\"]>(\n\t\tid: string,\n\t\tdocument: MigrationDocument<ExtractDocumentType<TDocuments, TType>> & {\n\t\t\tdocumentTitle?: string\n\t\t},\n\t\tparams?: FetchParams,\n\t): Promise<void> {\n\t\tconst url = new URL(`documents/${id}`, this.migrationAPIEndpoint)\n\n\t\tconst response = await this.#request(url, params, {\n\t\t\tmethod: \"PUT\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\ttitle: document.documentTitle,\n\t\t\t\tuid: document.uid || undefined,\n\t\t\t\ttags: document.tags,\n\t\t\t\tdata: document.data,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"x-client\": CLIENT_IDENTIFIER,\n\t\t\t},\n\t\t})\n\t\tswitch (response.status) {\n\t\t\tcase 200: {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tawait this.#handleMigrationAPIError(response)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Makes an authenticated HTTP request for write operations using the client's configured fetch\n\t * function and options.\n\t *\n\t * @param url - The URL to request.\n\t * @param params - Fetch options from the user.\n\t * @param init - Additional fetch options to merge with the user-provided options.\n\t * @returns The response from the fetch request.\n\t */\n\tasync #request(url: URL, params?: FetchParams, init?: RequestInitLike): Promise<ResponseLike> {\n\t\treturn await request(\n\t\t\turl,\n\t\t\t{\n\t\t\t\t...this.fetchOptions,\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\t...init,\n\t\t\t\theaders: {\n\t\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t\t...params?.fetchOptions?.headers,\n\t\t\t\t\t...init?.headers,\n\t\t\t\t\trepository: this.repositoryName,\n\t\t\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\t\t},\n\t\t\t\tsignal: params?.fetchOptions?.signal || params?.signal || this.fetchOptions?.signal,\n\t\t\t},\n\t\t\tthis.fetchFn,\n\t\t)\n\t}\n\n\t/**\n\t * Handles error responses from the Asset API with comprehensive error parsing.\n\t *\n\t * @param response - The HTTP response from the Asset API.\n\t * @throws {@link InvalidDataError} For 400 errors.\n\t * @throws {@link ForbiddenError} For 401 and 403 errors.\n\t * @throws {@link NotFoundError} For 404 errors.\n\t * @throws {@link PrismicError} For 500, 503, and other unexpected errors.\n\t */\n\tasync #handleAssetAPIError(response: ResponseLike): Promise<never> {\n\t\tconst json = await response.json()\n\t\tswitch (response.status) {\n\t\t\tcase 401:\n\t\t\tcase 403:\n\t\t\t\tthrow new ForbiddenError(json.error, response.url, json)\n\n\t\t\tcase 404:\n\t\t\t\tthrow new NotFoundError(json.error, response.url, json)\n\n\t\t\tcase 400:\n\t\t\t\tthrow new InvalidDataError(json.error, response.url, json)\n\n\t\t\tcase 500:\n\t\t\tcase 503:\n\t\t\tdefault:\n\t\t\t\tthrow new PrismicError(json.error, response.url, json)\n\t\t}\n\t}\n\n\t/**\n\t * Handles error responses from the Migration API with comprehensive error parsing.\n\t *\n\t * @param response - The HTTP response from the Migration API.\n\t * @throws {@link InvalidDataError} For 400 errors.\n\t * @throws {@link ForbiddenError} For 401 and 403 errors.\n\t * @throws {@link NotFoundError} For 404 errors.\n\t * @throws {@link PrismicError} For 500, and other unexpected errors.\n\t */\n\tasync #handleMigrationAPIError(response: ResponseLike): Promise<never> {\n\t\tconst payload = (await response.json()) as unknown\n\n\t\t// Common message across all branches\n\t\tconst message = (payload as { message?: string }).message\n\n\t\tswitch (response.status) {\n\t\t\tcase 400: {\n\t\t\t\tthrow new InvalidDataError(message, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 401: {\n\t\t\t\tthrow new ForbiddenError(message, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 403: {\n\t\t\t\t// The lambda authorizer uses an uppercase key, remove this once it is fixed\n\t\t\t\tconst msg = message ?? (payload as { Message?: string }).Message\n\t\t\t\tthrow new ForbiddenError(msg, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 404: {\n\t\t\t\tthrow new NotFoundError(message, response.url, pay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SAAS,KAAK,OAAO;GAGxD,KAAK,KAAK;IAET,MAAM,MAAM,WAAY,QAAiC;IACzD,MAAM,IAAIA,eAAAA,eAAe,KAAK,SAAS,KAAK,OAAO;GACpD;GAEA,KAAK,KACJ,MAAM,IAAIC,eAAAA,cAAc,SAAS,SAAS,KAAK,OAAO;GAIvD,SACC,MAAM,IAAIJ,eAAAA,aAAa,SAAS,SAAS,KAAK,OAAO;EAEvD;CACD;AACD"}
|
package/dist/WriteClient.d.cts
CHANGED
|
@@ -4,7 +4,6 @@ import { PrismicMigrationDocument } from "./types/migration/Document.cjs";
|
|
|
4
4
|
import { PrismicMigrationAsset } from "./types/migration/Asset.cjs";
|
|
5
5
|
import { Migration } from "./Migration.cjs";
|
|
6
6
|
import { PublishMigrationReleaseResult } from "./types/api/migration/release.cjs";
|
|
7
|
-
|
|
8
7
|
//#region src/WriteClient.d.ts
|
|
9
8
|
/** Utility type to construct events reported by the migration process. */
|
|
10
9
|
type MigrateReporterEvent<TType extends string, TData = never> = TData extends never ? {
|
|
@@ -64,10 +63,11 @@ type MigrateReporterEventTypes = keyof MigrateReporterEventMap;
|
|
|
64
63
|
* All events reported by the migration process. Events can be listened to by providing a `reporter`
|
|
65
64
|
* function to the `migrate` method.
|
|
66
65
|
*/
|
|
67
|
-
type MigrateReporterEvents = { [K in MigrateReporterEventTypes]: MigrateReporterEvent<K, MigrateReporterEventMap[K]
|
|
66
|
+
export type MigrateReporterEvents = { [K in MigrateReporterEventTypes]: MigrateReporterEvent<K, MigrateReporterEventMap[K]>; }[MigrateReporterEventTypes];
|
|
68
67
|
/** Configuration for clients that determine how content is queried. */
|
|
69
|
-
type WriteClientConfig = {
|
|
70
|
-
/** A Prismic write token that allows writing content to the repository. */
|
|
68
|
+
export type WriteClientConfig = {
|
|
69
|
+
/** A Prismic write token that allows writing content to the repository. */
|
|
70
|
+
writeToken: string;
|
|
71
71
|
/**
|
|
72
72
|
* The Prismic Asset API endpoint.
|
|
73
73
|
*
|
|
@@ -92,7 +92,7 @@ type WriteClientConfig = {
|
|
|
92
92
|
* @typeParam TDocuments - Document types that are registered for the Prismic repository. Query
|
|
93
93
|
* methods will automatically be typed based on this type.
|
|
94
94
|
*/
|
|
95
|
-
declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument> extends Client<TDocuments> {
|
|
95
|
+
export declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument> extends Client<TDocuments> {
|
|
96
96
|
#private;
|
|
97
97
|
writeToken: string;
|
|
98
98
|
assetAPIEndpoint: string;
|
|
@@ -120,27 +120,24 @@ declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument>
|
|
|
120
120
|
reporter?: (event: MigrateReporterEvents) => void;
|
|
121
121
|
} & FetchParams): Promise<void>;
|
|
122
122
|
/**
|
|
123
|
-
* Publishes the repository's migration release, moving its documents into the
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param params - Additional fetch parameters.
|
|
127
|
-
*
|
|
128
|
-
* @returns The result of the publish operation, including the total number of
|
|
129
|
-
* documents that were published.
|
|
123
|
+
* Publishes the repository's migration release, moving its documents into the repository as
|
|
124
|
+
* published content.
|
|
130
125
|
*
|
|
131
126
|
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const migration = createMigration()
|
|
132
129
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* // Prepare and run a migration.
|
|
137
|
-
* migration.createDocument(doc, "My document")
|
|
138
|
-
* await writeClient.migrate(migration)
|
|
130
|
+
* // Prepare and run a migration.
|
|
131
|
+
* migration.createDocument(doc, "My document")
|
|
132
|
+
* await writeClient.migrate(migration)
|
|
139
133
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
134
|
+
* // Publish the migration release.
|
|
135
|
+
* const { totalItems } = await writeClient.publishMigrationRelease()
|
|
136
|
+
* ```
|
|
143
137
|
*
|
|
138
|
+
* @param params - Additional fetch parameters.
|
|
139
|
+
* @returns The result of the publish operation, including the total number of documents that were
|
|
140
|
+
* published.
|
|
144
141
|
* @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
|
|
145
142
|
*/
|
|
146
143
|
publishMigrationRelease(params?: FetchParams): Promise<PublishMigrationReleaseResult>;
|
|
@@ -244,5 +241,4 @@ declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument>
|
|
|
244
241
|
private updateDocument;
|
|
245
242
|
}
|
|
246
243
|
//#endregion
|
|
247
|
-
export { MigrateReporterEvents, WriteClient, WriteClientConfig };
|
|
248
244
|
//# sourceMappingURL=WriteClient.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.d.cts","names":[],"sources":["../src/WriteClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WriteClient.d.cts","names":[],"sources":["../src/WriteClient.ts"],"mappings":";;;;;;;;KAmDK,qBAAqB,sBAAsB,iBAAiB;EAC5D,MAAM;;EAER,MAAM;EACN,MAAM;;;KAIJ;EACJ;IACC;MACC;MACA;;;EAGF;IACC;MACC;MACA;;;EAGF;IACC;IACA;IACA;IACA,OAAO;;EAER;IACC;;EAED;IACC;;EAED;IACC;IACA;IACA;IACA,UAAU;;EAEX;IACC;;EAED;IACC;IACA;IACA;IACA,UAAU;;EAEX;IACC;;;;KAKG,kCAAkC;;;;;YAM3B,2BACV,KAAK,4BAA4B,qBAAqB,GAAG,wBAAwB,OACjF;;YAkBU;;EAEX;;;;;;;EAQA;;;;;;;EAQA;IACG;;;;;;;;;;qBAWS,YACZ,mBAAmB,kBAAkB,yBAC5B,OAAO;;EAChB;EAEA;EACA;;;;;;;;;;;;EAaA,YAAY,wBAAwB,SAAS;;;;;;;;EA2BvC,QACL,WAAW,UAAU,aACrB;IACC,YAAY,OAAO;MAChB,cACF;;;;;;;;;;;;;;;;;;;;;;EA+CG,wBAAwB,SAAS,cAAc,QAAQ;;;;;;;;UAkC/C;;;;;;;;UAsEA;;;;;;;;UAuFA;;;;;;;;;UAgDA;;;;;;;;UAsDA;;;;;;;;UA4CA;;UAgBN;;;;;;;;UASM;;;;;;;;;;UAqCA;;;;;;;UA0BA;;;;;;;;;;;;UA2BA;;;;;;;;;;UA+CA"}
|
package/dist/WriteClient.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { PrismicMigrationDocument } from "./types/migration/Document.js";
|
|
|
4
4
|
import { PrismicMigrationAsset } from "./types/migration/Asset.js";
|
|
5
5
|
import { Migration } from "./Migration.js";
|
|
6
6
|
import { PublishMigrationReleaseResult } from "./types/api/migration/release.js";
|
|
7
|
-
|
|
8
7
|
//#region src/WriteClient.d.ts
|
|
9
8
|
/** Utility type to construct events reported by the migration process. */
|
|
10
9
|
type MigrateReporterEvent<TType extends string, TData = never> = TData extends never ? {
|
|
@@ -64,10 +63,11 @@ type MigrateReporterEventTypes = keyof MigrateReporterEventMap;
|
|
|
64
63
|
* All events reported by the migration process. Events can be listened to by providing a `reporter`
|
|
65
64
|
* function to the `migrate` method.
|
|
66
65
|
*/
|
|
67
|
-
type MigrateReporterEvents = { [K in MigrateReporterEventTypes]: MigrateReporterEvent<K, MigrateReporterEventMap[K]
|
|
66
|
+
export type MigrateReporterEvents = { [K in MigrateReporterEventTypes]: MigrateReporterEvent<K, MigrateReporterEventMap[K]>; }[MigrateReporterEventTypes];
|
|
68
67
|
/** Configuration for clients that determine how content is queried. */
|
|
69
|
-
type WriteClientConfig = {
|
|
70
|
-
/** A Prismic write token that allows writing content to the repository. */
|
|
68
|
+
export type WriteClientConfig = {
|
|
69
|
+
/** A Prismic write token that allows writing content to the repository. */
|
|
70
|
+
writeToken: string;
|
|
71
71
|
/**
|
|
72
72
|
* The Prismic Asset API endpoint.
|
|
73
73
|
*
|
|
@@ -92,7 +92,7 @@ type WriteClientConfig = {
|
|
|
92
92
|
* @typeParam TDocuments - Document types that are registered for the Prismic repository. Query
|
|
93
93
|
* methods will automatically be typed based on this type.
|
|
94
94
|
*/
|
|
95
|
-
declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument> extends Client<TDocuments> {
|
|
95
|
+
export declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument> extends Client<TDocuments> {
|
|
96
96
|
#private;
|
|
97
97
|
writeToken: string;
|
|
98
98
|
assetAPIEndpoint: string;
|
|
@@ -120,27 +120,24 @@ declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument>
|
|
|
120
120
|
reporter?: (event: MigrateReporterEvents) => void;
|
|
121
121
|
} & FetchParams): Promise<void>;
|
|
122
122
|
/**
|
|
123
|
-
* Publishes the repository's migration release, moving its documents into the
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param params - Additional fetch parameters.
|
|
127
|
-
*
|
|
128
|
-
* @returns The result of the publish operation, including the total number of
|
|
129
|
-
* documents that were published.
|
|
123
|
+
* Publishes the repository's migration release, moving its documents into the repository as
|
|
124
|
+
* published content.
|
|
130
125
|
*
|
|
131
126
|
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const migration = createMigration()
|
|
132
129
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* // Prepare and run a migration.
|
|
137
|
-
* migration.createDocument(doc, "My document")
|
|
138
|
-
* await writeClient.migrate(migration)
|
|
130
|
+
* // Prepare and run a migration.
|
|
131
|
+
* migration.createDocument(doc, "My document")
|
|
132
|
+
* await writeClient.migrate(migration)
|
|
139
133
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
134
|
+
* // Publish the migration release.
|
|
135
|
+
* const { totalItems } = await writeClient.publishMigrationRelease()
|
|
136
|
+
* ```
|
|
143
137
|
*
|
|
138
|
+
* @param params - Additional fetch parameters.
|
|
139
|
+
* @returns The result of the publish operation, including the total number of documents that were
|
|
140
|
+
* published.
|
|
144
141
|
* @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
|
|
145
142
|
*/
|
|
146
143
|
publishMigrationRelease(params?: FetchParams): Promise<PublishMigrationReleaseResult>;
|
|
@@ -244,5 +241,4 @@ declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument>
|
|
|
244
241
|
private updateDocument;
|
|
245
242
|
}
|
|
246
243
|
//#endregion
|
|
247
|
-
export { MigrateReporterEvents, WriteClient, WriteClientConfig };
|
|
248
244
|
//# sourceMappingURL=WriteClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.d.ts","names":[],"sources":["../src/WriteClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WriteClient.d.ts","names":[],"sources":["../src/WriteClient.ts"],"mappings":";;;;;;;;KAmDK,qBAAqB,sBAAsB,iBAAiB;EAC5D,MAAM;;EAER,MAAM;EACN,MAAM;;;KAIJ;EACJ;IACC;MACC;MACA;;;EAGF;IACC;MACC;MACA;;;EAGF;IACC;IACA;IACA;IACA,OAAO;;EAER;IACC;;EAED;IACC;;EAED;IACC;IACA;IACA;IACA,UAAU;;EAEX;IACC;;EAED;IACC;IACA;IACA;IACA,UAAU;;EAEX;IACC;;;;KAKG,kCAAkC;;;;;YAM3B,2BACV,KAAK,4BAA4B,qBAAqB,GAAG,wBAAwB,OACjF;;YAkBU;;EAEX;;;;;;;EAQA;;;;;;;EAQA;IACG;;;;;;;;;;qBAWS,YACZ,mBAAmB,kBAAkB,yBAC5B,OAAO;;EAChB;EAEA;EACA;;;;;;;;;;;;EAaA,YAAY,wBAAwB,SAAS;;;;;;;;EA2BvC,QACL,WAAW,UAAU,aACrB;IACC,YAAY,OAAO;MAChB,cACF;;;;;;;;;;;;;;;;;;;;;;EA+CG,wBAAwB,SAAS,cAAc,QAAQ;;;;;;;;UAkC/C;;;;;;;;UAsEA;;;;;;;;UAuFA;;;;;;;;;UAgDA;;;;;;;;UAsDA;;;;;;;;UA4CA;;UAgBN;;;;;;;;UASM;;;;;;;;;;UAqCA;;;;;;;UA0BA;;;;;;;;;;;;UA2BA;;;;;;;;;;UA+CA"}
|