@prismicio/client 7.21.8-pr.446.7e39a41 → 7.21.8-pr.446.c5cd5fe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WriteClient.cjs +1 -0
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.cts.map +1 -1
- package/dist/WriteClient.d.ts.map +1 -1
- package/dist/WriteClient.js +1 -0
- package/dist/WriteClient.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/src/WriteClient.ts +5 -0
package/dist/WriteClient.cjs
CHANGED
|
@@ -92,6 +92,7 @@ var WriteClient = class extends require_Client.Client {
|
|
|
92
92
|
const url = new URL("migration-release/publish", this.migrationAPIEndpoint);
|
|
93
93
|
const response = await this.#request(url, params, {
|
|
94
94
|
method: "POST",
|
|
95
|
+
body: JSON.stringify({}),
|
|
95
96
|
headers: {
|
|
96
97
|
"content-type": "application/json",
|
|
97
98
|
"x-client": CLIENT_IDENTIFIER
|
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\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, payload)\n\t\t\t}\n\n\t\t\tcase 500:\n\t\t\tdefault: {\n\t\t\t\tthrow new PrismicError(message, response.url, payload)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AAgCA,MAAM,oBAAoB,GAAGA,gBAAAA,KAAK,QAAQ,KAAK,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC,GAAGC,gBAAAA;;;;;;;;;;AAiIxE,IAAa,cAAb,cAEUC,eAAAA,OAAmB;CAC5B;CAEA,mBAAmB;CACnB,uBAAuB;;;;;;;;;;;;CAavB,YAAY,gBAAwB,SAA4B;AAC/D,QAAM,gBAAgB,QAAQ;AAE9B,MAAI,OAAO,WAAW,WAAW,YAChC,SAAQ,KACP,mSAAmSC,eAAAA,OAAO,gCAAgC,GAC1U;AAGF,OAAK,aAAa,QAAQ;AAE1B,MAAI,QAAQ,iBACX,MAAK,mBAAmB,GAAG,QAAQ,iBAAiB;AAGrD,MAAI,QAAQ,qBACX,MAAK,uBAAuB,GAAG,QAAQ,qBAAqB;;;;;;;;;CAW9D,MAAM,QACL,WACA,SAEkB,EAAE,EACJ;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AK,OAAO,SAAS,KAAK,KAAK;;;;;;;;;;;;CAazD,OAAA,wBAA+B,UAAwC;EACtE,MAAM,UAAW,MAAM,SAAS,MAAM;EAGtC,MAAM,UAAW,QAAiC;AAElD,UAAQ,SAAS,QAAjB;GACC,KAAK,IACJ,OAAM,IAAIK,eAAAA,iBAAiB,SAAS,SAAS,KAAK,QAAQ;GAG3D,KAAK,IACJ,OAAM,IAAIF,eAAAA,eAAe,SAAS,SAAS,KAAK,QAAQ;GAGzD,KAAK,IAGJ,OAAM,IAAIA,eAAAA,eADE,WAAY,QAAiC,SAC3B,SAAS,KAAK,QAAQ;GAGrD,KAAK,IACJ,OAAM,IAAIC,eAAAA,cAAc,SAAS,SAAS,KAAK,QAAQ;GAIxD,QACC,OAAM,IAAIJ,eAAAA,aAAa,SAAS,SAAS,KAAK,QAAQ"}
|
|
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\t\t\tthrow new NotFoundError(message, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 500:\n\t\t\tdefault: {\n\t\t\t\tthrow new PrismicError(message, response.url, payload)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AAgCA,MAAM,oBAAoB,GAAGA,gBAAAA,KAAK,QAAQ,KAAK,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC,GAAGC,gBAAAA;;;;;;;;;;AAiIxE,IAAa,cAAb,cAEUC,eAAAA,OAAmB;CAC5B;CAEA,mBAAmB;CACnB,uBAAuB;;;;;;;;;;;;CAavB,YAAY,gBAAwB,SAA4B;AAC/D,QAAM,gBAAgB,QAAQ;AAE9B,MAAI,OAAO,WAAW,WAAW,YAChC,SAAQ,KACP,mSAAmSC,eAAAA,OAAO,gCAAgC,GAC1U;AAGF,OAAK,aAAa,QAAQ;AAE1B,MAAI,QAAQ,iBACX,MAAK,mBAAmB,GAAG,QAAQ,iBAAiB;AAGrD,MAAI,QAAQ,qBACX,MAAK,uBAAuB,GAAG,QAAQ,qBAAqB;;;;;;;;;CAW9D,MAAM,QACL,WACA,SAEkB,EAAE,EACJ;AAChB,SAAO,WAAW;GACjB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H;;;;;;;EAAA,QA/TM,mBAAA;;;;;;;;UAsEA,sBAAA;;;;;;;;UAuFA,sBAAA;;;;;;;;;UAgDA,WAAA;;;;;;;;UAsDA,WAAA;;;;;;;;UA4CA,iBAAA;;UAgBN,wBAAA;;;;;;;;UASM,kBAAA;;;;;;;;;;UAqCA,cAAA;;;;;;;UA0BA,YAAA;;;;;;;;;;;;UA2BA,cAAA;;;;;;;;;;UA+CA,cAAA;AAAA"}
|
package/dist/WriteClient.js
CHANGED
|
@@ -92,6 +92,7 @@ var WriteClient = class extends Client {
|
|
|
92
92
|
const url = new URL("migration-release/publish", this.migrationAPIEndpoint);
|
|
93
93
|
const response = await this.#request(url, params, {
|
|
94
94
|
method: "POST",
|
|
95
|
+
body: JSON.stringify({}),
|
|
95
96
|
headers: {
|
|
96
97
|
"content-type": "application/json",
|
|
97
98
|
"x-client": CLIENT_IDENTIFIER
|
package/dist/WriteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.js","names":["#request","#handleMigrationAPIError","#handleAssetAPIError"],"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\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, payload)\n\t\t\t}\n\n\t\t\tcase 500:\n\t\t\tdefault: {\n\t\t\t\tthrow new PrismicError(message, response.url, payload)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AAgCA,MAAM,oBAAoB,GAAG,KAAK,QAAQ,KAAK,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC,GAAG;;;;;;;;;;AAiIxE,IAAa,cAAb,cAEU,OAAmB;CAC5B;CAEA,mBAAmB;CACnB,uBAAuB;;;;;;;;;;;;CAavB,YAAY,gBAAwB,SAA4B;AAC/D,QAAM,gBAAgB,QAAQ;AAE9B,MAAI,OAAO,WAAW,WAAW,YAChC,SAAQ,KACP,mSAAmS,OAAO,gCAAgC,GAC1U;AAGF,OAAK,aAAa,QAAQ;AAE1B,MAAI,QAAQ,iBACX,MAAK,mBAAmB,GAAG,QAAQ,iBAAiB;AAGrD,MAAI,QAAQ,qBACX,MAAK,uBAAuB,GAAG,QAAQ,qBAAqB;;;;;;;;;CAW9D,MAAM,QACL,WACA,SAEkB,EAAE,EACJ;AAChB,SAAO,WAAW;GACjB,MAAM;GACN,MAAM,EACL,SAAS;IACR,WAAW,UAAU,WAAW;IAChC,QAAQ,UAAU,QAAQ;IAC1B,EACD;GACD,CAAC;AAEF,QAAM,KAAK,oBAAoB,WAAW,OAAO;AACjD,QAAM,KAAK,uBAAuB,WAAW,OAAO;AACpD,QAAM,KAAK,uBAAuB,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M,IAAI,eADE,WAAY,QAAiC,SAC3B,SAAS,KAAK,QAAQ;GAGrD,KAAK,IACJ,OAAM,IAAI,cAAc,SAAS,SAAS,KAAK,QAAQ;GAIxD,QACC,OAAM,IAAI,aAAa,SAAS,SAAS,KAAK,QAAQ"}
|
|
1
|
+
{"version":3,"file":"WriteClient.js","names":["#request","#handleMigrationAPIError","#handleAssetAPIError"],"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\t\t\tthrow new NotFoundError(message, response.url, payload)\n\t\t\t}\n\n\t\t\tcase 500:\n\t\t\tdefault: {\n\t\t\t\tthrow new PrismicError(message, response.url, payload)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AAgCA,MAAM,oBAAoB,GAAG,KAAK,QAAQ,KAAK,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC,GAAG;;;;;;;;;;AAiIxE,IAAa,cAAb,cAEU,OAAmB;CAC5B;CAEA,mBAAmB;CACnB,uBAAuB;;;;;;;;;;;;CAavB,YAAY,gBAAwB,SAA4B;AAC/D,QAAM,gBAAgB,QAAQ;AAE9B,MAAI,OAAO,WAAW,WAAW,YAChC,SAAQ,KACP,mSAAmS,OAAO,gCAAgC,GAC1U;AAGF,OAAK,aAAa,QAAQ;AAE1B,MAAI,QAAQ,iBACX,MAAK,mBAAmB,GAAG,QAAQ,iBAAiB;AAGrD,MAAI,QAAQ,qBACX,MAAK,uBAAuB,GAAG,QAAQ,qBAAqB;;;;;;;;;CAW9D,MAAM,QACL,WACA,SAEkB,EAAE,EACJ;AAChB,SAAO,WAAW;GACjB,MAAM;GACN,MAAM,EACL,SAAS;IACR,WAAW,UAAU,WAAW;IAChC,QAAQ,UAAU,QAAQ;IAC1B,EACD;GACD,CAAC;AAEF,QAAM,KAAK,oBAAoB,WAAW,OAAO;AACjD,QAAM,KAAK,uBAAuB,WAAW,OAAO;AACpD,QAAM,KAAK,uBAAuB,WAAW,OAAO;AAEpD,SAAO,WAAW;GACjB,MAAM;GACN,MAAM,EACL,UAAU;IACT,WAAW,UAAU,WAAW;IAChC,QAAQ,UAAU,QAAQ;IAC1B,EACD;GACD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BH,MAAM,wBACL,QACyC;EACzC,MAAM,MAAM,IAAI,IAAI,6BAA6B,KAAK,qBAAqB;EAE3E,MAAM,WAAW,MAAM,MAA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Client.ts
CHANGED
|
@@ -267,6 +267,11 @@ export class WriteClient<
|
|
|
267
267
|
|
|
268
268
|
const response = await this.#request(url, params, {
|
|
269
269
|
method: "POST",
|
|
270
|
+
// A body is included so `request()` treats this as a write: it is
|
|
271
|
+
// routed through the per-host write throttle and, crucially, is not
|
|
272
|
+
// deduplicated with concurrent publishes from other repositories
|
|
273
|
+
// (which share this URL but differ only by auth headers).
|
|
274
|
+
body: JSON.stringify({}),
|
|
270
275
|
headers: {
|
|
271
276
|
"content-type": "application/json",
|
|
272
277
|
"x-client": CLIENT_IDENTIFIER,
|