@prismicio/client 7.18.1 → 7.18.2
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 +13 -2
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.ts +9 -0
- package/dist/WriteClient.js +13 -2
- package/dist/WriteClient.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +1 -1
- package/src/WriteClient.ts +29 -1
package/dist/WriteClient.cjs
CHANGED
|
@@ -8,6 +8,14 @@ const pLimit = require("./lib/pLimit.cjs");
|
|
|
8
8
|
const resolveMigrationDocumentData = require("./lib/resolveMigrationDocumentData.cjs");
|
|
9
9
|
const PrismicError = require("./errors/PrismicError.cjs");
|
|
10
10
|
const Client = require("./Client.cjs");
|
|
11
|
+
const MIGRATION_API_DEMO_KEYS = [
|
|
12
|
+
"cSaZlfkQlF9C6CEAM2Del6MNX9WonlV86HPbeEJL",
|
|
13
|
+
"pZCexCajUQ4jriYwIGSxA1drZrFxDyFf1S0D1K0P",
|
|
14
|
+
"Yc0mfrkGDw8gaaGKTrzwC3QUZDajv6k73DA99vWN",
|
|
15
|
+
"ySzSEbVMAb5S1oSCQfbVG4mbh9Cb8wlF7BCvKI0L",
|
|
16
|
+
"g2DA3EKWvx8uxVYcNFrmT5nJpon1Vi9V4XcOibJD",
|
|
17
|
+
"CCNIlI0Vz41J66oFwsHUXaZa6NYFIY6z7aDF62Bc"
|
|
18
|
+
];
|
|
11
19
|
class WriteClient extends Client.Client {
|
|
12
20
|
/**
|
|
13
21
|
* Creates a Prismic client that can be used to query and write content to a
|
|
@@ -26,6 +34,7 @@ class WriteClient extends Client.Client {
|
|
|
26
34
|
constructor(repositoryName, options) {
|
|
27
35
|
super(repositoryName, options);
|
|
28
36
|
__publicField(this, "writeToken");
|
|
37
|
+
__publicField(this, "migrationAPIKey");
|
|
29
38
|
__publicField(this, "assetAPIEndpoint", "https://asset-api.prismic.io/");
|
|
30
39
|
__publicField(this, "migrationAPIEndpoint", "https://migration.prismic.io/");
|
|
31
40
|
/**
|
|
@@ -33,9 +42,10 @@ class WriteClient extends Client.Client {
|
|
|
33
42
|
*/
|
|
34
43
|
__publicField(this, "_resolveAssetTagIDsLimit", pLimit.pLimit());
|
|
35
44
|
if (typeof globalThis.window !== "undefined") {
|
|
36
|
-
console.warn(`[@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
|
|
45
|
+
console.warn(`[@prismicio/client] Prismic write client appears to be running in a browser environment. This is not recommended as it exposes your write token and Migration API key. Consider using Prismic write client in a server environment only, preferring the regular client for browser environement. For more details, see ${devMsg.devMsg("avoid-write-client-in-browser")}`);
|
|
37
46
|
}
|
|
38
47
|
this.writeToken = options.writeToken;
|
|
48
|
+
this.migrationAPIKey = options.migrationAPIKey || MIGRATION_API_DEMO_KEYS[Math.floor(Math.random() * MIGRATION_API_DEMO_KEYS.length)];
|
|
39
49
|
if (options.assetAPIEndpoint) {
|
|
40
50
|
this.assetAPIEndpoint = `${options.assetAPIEndpoint}/`;
|
|
41
51
|
}
|
|
@@ -495,7 +505,8 @@ class WriteClient extends Client.Client {
|
|
|
495
505
|
...(_a = params == null ? void 0 : params.fetchOptions) == null ? void 0 : _a.headers,
|
|
496
506
|
"content-type": "application/json",
|
|
497
507
|
repository: this.repositoryName,
|
|
498
|
-
authorization: `Bearer ${this.writeToken}
|
|
508
|
+
authorization: `Bearer ${this.writeToken}`,
|
|
509
|
+
"x-api-key": this.migrationAPIKey
|
|
499
510
|
}
|
|
500
511
|
}
|
|
501
512
|
};
|
package/dist/WriteClient.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.cjs","sources":["../../src/WriteClient.ts"],"sourcesContent":["import { devMsg } from \"./lib/devMsg\"\nimport { pLimit } from \"./lib/pLimit\"\nimport {\n\tresolveMigrationContentRelationship,\n\tresolveMigrationDocumentData,\n} from \"./lib/resolveMigrationDocumentData\"\n\nimport type {\n\tAsset,\n\tPatchAssetParams,\n\tPatchAssetResult,\n\tPostAssetParams,\n\tPostAssetResult,\n} from \"./types/api/asset/asset\"\nimport type {\n\tAssetTag,\n\tGetAssetTagsResult,\n\tPostAssetTagParams,\n\tPostAssetTagResult,\n} from \"./types/api/asset/tag\"\nimport type { PutDocumentResult } from \"./types/api/migration/document\"\nimport {\n\ttype PostDocumentParams,\n\ttype PostDocumentResult,\n\ttype PutDocumentParams,\n} from \"./types/api/migration/document\"\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\nimport { PrismicError } from \"./errors/PrismicError\"\n\nimport type { FetchParams, RequestInitLike } from \"./BaseClient\"\nimport { Client } from \"./Client\"\nimport type { ClientConfig } from \"./Client\"\nimport type { Migration } from \"./Migration\"\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { createMigration } from \"./createMigration\"\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic\n * document type. If no matches are found, no extraction is performed and the\n * union of all provided Prismic document types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/**\n * Utility type to construct events reported by the migration process.\n */\ntype MigrateReporterEvent<\n\tTType extends string,\n\tTData = never,\n> = TData extends never\n\t? { type: TType }\n\t: {\n\t\t\ttype: TType\n\t\t\tdata: TData\n\t\t}\n\n/**\n * A map of event types and their data reported by the migration process.\n */\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/**\n * Available event types reported by the migration process.\n */\ntype MigrateReporterEventTypes = keyof MigrateReporterEventMap\n\n/**\n * All events reported by the migration process. Events can be listened to by\n * providing a `reporter` function to the `migrate` method.\n */\nexport type MigrateReporterEvents = {\n\t[K in MigrateReporterEventTypes]: MigrateReporterEvent<\n\t\tK,\n\t\tMigrateReporterEventMap[K]\n\t>\n}[MigrateReporterEventTypes]\n\n/**\n * Additional parameters for creating an asset in the Prismic media library.\n */\nexport type CreateAssetParams = {\n\t/**\n\t * Asset notes.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Asset credits.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Asset alt text.\n\t */\n\talt?: string\n\n\t/**\n\t * Asset tags.\n\t */\n\ttags?: string[]\n}\n\n/**\n * Configuration for clients that determine how content is queried.\n */\nexport type WriteClientConfig = {\n\t/**\n\t * A Prismic write token that allows writing content to the repository.\n\t */\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 *\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 *\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,\n * such as Node.js, the `fetch` option must be provided as part of the `options`\n * parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic\n * repository. Query 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\n\t * repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable,\n\t * such as in some Node.js versions, the `fetch` option must be provided as\n\t * 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\n\t * from and written to the Prismic repository.\n\t *\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\n\t * 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 *\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 * 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 *\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 } =\n\t\t\t\tmigrationAsset.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 (error) {\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(\n\t\t\t\t\t\turl.toString(),\n\t\t\t\t\t\tfetchParams,\n\t\t\t\t\t)\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(\n\t\t\t\t\tfile.toString(),\n\t\t\t\t\tfetchParams,\n\t\t\t\t)\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\t...{ notes, credits, alt, tags },\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 *\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.find((lang) => lang.is_master)!.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 =\n\t\t\t\t\tawait resolveMigrationContentRelationship(doc.masterLanguageDocument)\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 =\n\t\t\t\t\tdoc.originalPrismicDocument.alternate_languages.find(\n\t\t\t\t\t\t({ lang }) => lang === masterLocale,\n\t\t\t\t\t)?.id\n\n\t\t\t\tif (maybeOriginalID) {\n\t\t\t\t\tmasterLanguageDocumentID =\n\t\t\t\t\t\tmigration._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\n\t * 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 *\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(\n\t\t\t\t\t\tdoc.document.data,\n\t\t\t\t\t\tmigration,\n\t\t\t\t\t),\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 *\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{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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 asset = await this.fetch<PostAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\tif (tags && tags.length) {\n\t\t\treturn this.updateAsset(asset.id, { tags })\n\t\t}\n\n\t\treturn asset\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 *\n\t * @returns The updated asset.\n\t */\n\tprivate async updateAsset(\n\t\tid: string,\n\t\t{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\tfilename,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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\treturn this.fetch<PatchAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PatchAssetParams>({\n\t\t\t\tmethod: \"PATCH\",\n\t\t\t\tbody: {\n\t\t\t\t\tnotes,\n\t\t\t\t\tcredits,\n\t\t\t\t\talt,\n\t\t\t\t\tfilename,\n\t\t\t\t\ttags,\n\t\t\t\t},\n\t\t\t\tparams,\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 *\n\t * @returns A file representing the fetched asset.\n\t */\n\tprivate async fetchForeignAsset(\n\t\turl: string,\n\t\tparams: FetchParams = {},\n\t): Promise<Blob> {\n\t\tconst requestInit: RequestInitLike = {\n\t\t\t...this.fetchOptions,\n\t\t\t...params.fetchOptions,\n\t\t\theaders: {\n\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t...params.fetchOptions?.headers,\n\t\t\t},\n\t\t\tsignal:\n\t\t\t\tparams.fetchOptions?.signal ||\n\t\t\t\tparams.signal ||\n\t\t\t\tthis.fetchOptions?.signal,\n\t\t}\n\n\t\tconst res = await this.fetchFn(url, requestInit)\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 blob = await res.blob()\n\n\t\t// Ensure a correct content type is attached to the blob.\n\t\treturn new File([blob], \"\", {\n\t\t\ttype: res.headers.get(\"content-type\") || undefined,\n\t\t})\n\t}\n\n\t/**\n\t * {@link resolveAssetTagIDs} rate limiter.\n\t */\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\n\t * additional fetch parameters.\n\t *\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 *\n\t * @param name - The name of the tag to create.\n\t * @param params - Additional fetch parameters.\n\t *\n\t * @returns The created tag.\n\t */\n\tprivate async createAssetTag(\n\t\tname: string,\n\t\tparams?: FetchParams,\n\t): Promise<AssetTag> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\treturn this.fetch<PostAssetTagResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PostAssetTagParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: { name },\n\t\t\t\tparams,\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 *\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 { items } = await this.fetch<GetAssetTagsResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({ params }),\n\t\t)\n\n\t\treturn items\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 *\n\t * @param document - The document to create.\n\t * @param documentTitle - The title of the document to create which will be\n\t * displayed in the editor.\n\t * @param params - Document master language document ID and additional fetch\n\t * parameters.\n\t *\n\t * @returns The ID of the created document.\n\t *\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 result = await this.fetch<PostDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams<PostDocumentParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: documentTitle,\n\t\t\t\t\ttype: document.type,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\tlang: document.lang,\n\t\t\t\t\talternate_language_id: masterLanguageDocumentID,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\treturn { id: result.id }\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 *\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 *\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\tawait this.fetch<PutDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams({\n\t\t\t\tmethod: \"PUT\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: document.documentTitle,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Asset API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch parameters.\n\t *\n\t * @returns An object that can be fetched to interact with the Asset API.\n\t *\n\t * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}\n\t */\n\tprivate buildAssetAPIQueryParams<TBody = FormData | Record<string, unknown>>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody?: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...params?.fetchOptions?.headers,\n\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\trepository: this.repositoryName,\n\t\t}\n\n\t\tlet _body: FormData | string | undefined\n\t\tif (body instanceof FormData) {\n\t\t\t_body = body\n\t\t} else if (body) {\n\t\t\t_body = JSON.stringify(body)\n\t\t\theaders[\"content-type\"] = \"application/json\"\n\t\t}\n\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: _body,\n\t\t\t\theaders,\n\t\t\t},\n\t\t}\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Migration API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch options.\n\t *\n\t * @returns An object that can be fetched to interact with the Migration API.\n\t *\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate buildMigrationAPIQueryParams<\n\t\tTBody extends PostDocumentParams | PutDocumentParams,\n\t>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\theaders: {\n\t\t\t\t\t...params?.fetchOptions?.headers,\n\t\t\t\t\t\"content-type\": \"application/json\",\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},\n\t\t}\n\t}\n}\n"],"names":["Client","pLimit","devMsg","resolveMigrationContentRelationship","resolveMigrationDocumentData","PrismicError"],"mappings":";;;;;;;;;;AAuMM,MAAO,oBAEHA,OAAAA,OAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB3B,YAAY,gBAAwB,SAA0B;AAC7D,UAAM,gBAAgB,OA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,MAAM;AAAA,QACN;AAAA,MAAA;AAAA;;;;;;;;;;;;;EAgBK,6BAEN,EACD,QACA,MACA,UAKA;;AACO,WAAA;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAG,iCAAQ;AAAA,QACX;AAAA,QACA,MAAM,KAAK,UAAU,IAAI;AAAA,QACzB,SAAS;AAAA,UACR,IAAG,sCAAQ,iBAAR,mBAAsB;AAAA,UACzB,gBAAgB;AAAA,UAChB,YAAY,KAAK;AAAA,UACjB,eAAe,UAAU,KAAK,UAAU;AAAA,QAAA;AAAA,MACxC;AAAA;;AAIJ;;"}
|
|
1
|
+
{"version":3,"file":"WriteClient.cjs","sources":["../../src/WriteClient.ts"],"sourcesContent":["import { devMsg } from \"./lib/devMsg\"\nimport { pLimit } from \"./lib/pLimit\"\nimport {\n\tresolveMigrationContentRelationship,\n\tresolveMigrationDocumentData,\n} from \"./lib/resolveMigrationDocumentData\"\n\nimport type {\n\tAsset,\n\tPatchAssetParams,\n\tPatchAssetResult,\n\tPostAssetParams,\n\tPostAssetResult,\n} from \"./types/api/asset/asset\"\nimport type {\n\tAssetTag,\n\tGetAssetTagsResult,\n\tPostAssetTagParams,\n\tPostAssetTagResult,\n} from \"./types/api/asset/tag\"\nimport type { PutDocumentResult } from \"./types/api/migration/document\"\nimport {\n\ttype PostDocumentParams,\n\ttype PostDocumentResult,\n\ttype PutDocumentParams,\n} from \"./types/api/migration/document\"\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\nimport { PrismicError } from \"./errors/PrismicError\"\n\nimport type { FetchParams, RequestInitLike } from \"./BaseClient\"\nimport { Client } from \"./Client\"\nimport type { ClientConfig } from \"./Client\"\nimport type { Migration } from \"./Migration\"\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { createMigration } from \"./createMigration\"\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic\n * document type. If no matches are found, no extraction is performed and the\n * union of all provided Prismic document types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/**\n * Utility type to construct events reported by the migration process.\n */\ntype MigrateReporterEvent<\n\tTType extends string,\n\tTData = never,\n> = TData extends never\n\t? { type: TType }\n\t: {\n\t\t\ttype: TType\n\t\t\tdata: TData\n\t\t}\n\n/**\n * A map of event types and their data reported by the migration process.\n */\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/**\n * Available event types reported by the migration process.\n */\ntype MigrateReporterEventTypes = keyof MigrateReporterEventMap\n\n/**\n * All events reported by the migration process. Events can be listened to by\n * providing a `reporter` function to the `migrate` method.\n */\nexport type MigrateReporterEvents = {\n\t[K in MigrateReporterEventTypes]: MigrateReporterEvent<\n\t\tK,\n\t\tMigrateReporterEventMap[K]\n\t>\n}[MigrateReporterEventTypes]\n\n/**\n * Additional parameters for creating an asset in the Prismic media library.\n */\nexport type CreateAssetParams = {\n\t/**\n\t * Asset notes.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Asset credits.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Asset alt text.\n\t */\n\talt?: string\n\n\t/**\n\t * Asset tags.\n\t */\n\ttags?: string[]\n}\n\n/**\n * Prismic Migration API demo keys.\n */\nconst MIGRATION_API_DEMO_KEYS = [\n\t\"cSaZlfkQlF9C6CEAM2Del6MNX9WonlV86HPbeEJL\",\n\t\"pZCexCajUQ4jriYwIGSxA1drZrFxDyFf1S0D1K0P\",\n\t\"Yc0mfrkGDw8gaaGKTrzwC3QUZDajv6k73DA99vWN\",\n\t\"ySzSEbVMAb5S1oSCQfbVG4mbh9Cb8wlF7BCvKI0L\",\n\t\"g2DA3EKWvx8uxVYcNFrmT5nJpon1Vi9V4XcOibJD\",\n\t\"CCNIlI0Vz41J66oFwsHUXaZa6NYFIY6z7aDF62Bc\",\n]\n\n/**\n * Configuration for clients that determine how content is queried.\n */\nexport type WriteClientConfig = {\n\t/**\n\t * A Prismic write token that allows writing content to the repository.\n\t */\n\twriteToken: string\n\n\t/**\n\t * A Prismic Migration API key that allows working with the Migration API.\n\t *\n\t * @remarks\n\t * If no key is provided, the client will use one of the demo key available\n\t * which has stricter rate limiting rules enforced.\n\t */\n\tmigrationAPIKey?: string\n\n\t/**\n\t * The Prismic Asset API endpoint.\n\t *\n\t * @defaultValue `\"https://asset-api.prismic.io/\"`\n\t *\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 *\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,\n * such as Node.js, the `fetch` option must be provided as part of the `options`\n * parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic\n * repository. Query 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\tmigrationAPIKey: 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\n\t * repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable,\n\t * such as in some Node.js versions, the `fetch` option must be provided as\n\t * 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\n\t * from and written to the Prismic repository.\n\t *\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 and Migration API key. Consider using Prismic write client in a server environment only, preferring the regular client for browser environement. 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\t\tthis.migrationAPIKey =\n\t\t\toptions.migrationAPIKey ||\n\t\t\tMIGRATION_API_DEMO_KEYS[\n\t\t\t\tMath.floor(Math.random() * MIGRATION_API_DEMO_KEYS.length)\n\t\t\t]\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\n\t * 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 *\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 * 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 *\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 } =\n\t\t\t\tmigrationAsset.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 (error) {\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(\n\t\t\t\t\t\turl.toString(),\n\t\t\t\t\t\tfetchParams,\n\t\t\t\t\t)\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(\n\t\t\t\t\tfile.toString(),\n\t\t\t\t\tfetchParams,\n\t\t\t\t)\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\t...{ notes, credits, alt, tags },\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 *\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.find((lang) => lang.is_master)!.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 =\n\t\t\t\t\tawait resolveMigrationContentRelationship(doc.masterLanguageDocument)\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 =\n\t\t\t\t\tdoc.originalPrismicDocument.alternate_languages.find(\n\t\t\t\t\t\t({ lang }) => lang === masterLocale,\n\t\t\t\t\t)?.id\n\n\t\t\t\tif (maybeOriginalID) {\n\t\t\t\t\tmasterLanguageDocumentID =\n\t\t\t\t\t\tmigration._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\n\t * 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 *\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(\n\t\t\t\t\t\tdoc.document.data,\n\t\t\t\t\t\tmigration,\n\t\t\t\t\t),\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 *\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{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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 asset = await this.fetch<PostAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\tif (tags && tags.length) {\n\t\t\treturn this.updateAsset(asset.id, { tags })\n\t\t}\n\n\t\treturn asset\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 *\n\t * @returns The updated asset.\n\t */\n\tprivate async updateAsset(\n\t\tid: string,\n\t\t{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\tfilename,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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\treturn this.fetch<PatchAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PatchAssetParams>({\n\t\t\t\tmethod: \"PATCH\",\n\t\t\t\tbody: {\n\t\t\t\t\tnotes,\n\t\t\t\t\tcredits,\n\t\t\t\t\talt,\n\t\t\t\t\tfilename,\n\t\t\t\t\ttags,\n\t\t\t\t},\n\t\t\t\tparams,\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 *\n\t * @returns A file representing the fetched asset.\n\t */\n\tprivate async fetchForeignAsset(\n\t\turl: string,\n\t\tparams: FetchParams = {},\n\t): Promise<Blob> {\n\t\tconst requestInit: RequestInitLike = {\n\t\t\t...this.fetchOptions,\n\t\t\t...params.fetchOptions,\n\t\t\theaders: {\n\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t...params.fetchOptions?.headers,\n\t\t\t},\n\t\t\tsignal:\n\t\t\t\tparams.fetchOptions?.signal ||\n\t\t\t\tparams.signal ||\n\t\t\t\tthis.fetchOptions?.signal,\n\t\t}\n\n\t\tconst res = await this.fetchFn(url, requestInit)\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 blob = await res.blob()\n\n\t\t// Ensure a correct content type is attached to the blob.\n\t\treturn new File([blob], \"\", {\n\t\t\ttype: res.headers.get(\"content-type\") || undefined,\n\t\t})\n\t}\n\n\t/**\n\t * {@link resolveAssetTagIDs} rate limiter.\n\t */\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\n\t * additional fetch parameters.\n\t *\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 *\n\t * @param name - The name of the tag to create.\n\t * @param params - Additional fetch parameters.\n\t *\n\t * @returns The created tag.\n\t */\n\tprivate async createAssetTag(\n\t\tname: string,\n\t\tparams?: FetchParams,\n\t): Promise<AssetTag> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\treturn this.fetch<PostAssetTagResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PostAssetTagParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: { name },\n\t\t\t\tparams,\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 *\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 { items } = await this.fetch<GetAssetTagsResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({ params }),\n\t\t)\n\n\t\treturn items\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 *\n\t * @param document - The document to create.\n\t * @param documentTitle - The title of the document to create which will be\n\t * displayed in the editor.\n\t * @param params - Document master language document ID and additional fetch\n\t * parameters.\n\t *\n\t * @returns The ID of the created document.\n\t *\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 result = await this.fetch<PostDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams<PostDocumentParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: documentTitle,\n\t\t\t\t\ttype: document.type,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\tlang: document.lang,\n\t\t\t\t\talternate_language_id: masterLanguageDocumentID,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\treturn { id: result.id }\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 *\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 *\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\tawait this.fetch<PutDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams({\n\t\t\t\tmethod: \"PUT\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: document.documentTitle,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Asset API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch parameters.\n\t *\n\t * @returns An object that can be fetched to interact with the Asset API.\n\t *\n\t * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}\n\t */\n\tprivate buildAssetAPIQueryParams<TBody = FormData | Record<string, unknown>>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody?: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...params?.fetchOptions?.headers,\n\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\trepository: this.repositoryName,\n\t\t}\n\n\t\tlet _body: FormData | string | undefined\n\t\tif (body instanceof FormData) {\n\t\t\t_body = body\n\t\t} else if (body) {\n\t\t\t_body = JSON.stringify(body)\n\t\t\theaders[\"content-type\"] = \"application/json\"\n\t\t}\n\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: _body,\n\t\t\t\theaders,\n\t\t\t},\n\t\t}\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Migration API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch options.\n\t *\n\t * @returns An object that can be fetched to interact with the Migration API.\n\t *\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate buildMigrationAPIQueryParams<\n\t\tTBody extends PostDocumentParams | PutDocumentParams,\n\t>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\theaders: {\n\t\t\t\t\t...params?.fetchOptions?.headers,\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\trepository: this.repositoryName,\n\t\t\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\t\t\t\"x-api-key\": this.migrationAPIKey,\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["Client","pLimit","devMsg","resolveMigrationContentRelationship","resolveMigrationDocumentData","PrismicError"],"mappings":";;;;;;;;;;AAoKA,MAAM,0BAA0B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAkDK,MAAO,oBAEHA,OAAAA,OAAkB;AAAA;AAAA;AAAA;AA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A;AACJ,QAAI,gBAAgB,UAAU;AACrB,cAAA;AAAA,eACE,MAAM;AACR,cAAA,KAAK,UAAU,IAAI;AAC3B,cAAQ,cAAc,IAAI;AAAA,IAAA;AAGpB,WAAA;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAG,iCAAQ;AAAA,QACX;AAAA,QACA,MAAM;AAAA,QACN;AAAA,MAAA;AAAA;;;;;;;;;;;;;EAgBK,6BAEN,EACD,QACA,MACA,UAKA;;AACO,WAAA;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAG,iCAAQ;AAAA,QACX;AAAA,QACA,MAAM,KAAK,UAAU,IAAI;AAAA,QACzB,SAAS;AAAA,UACR,IAAG,sCAAQ,iBAAR,mBAAsB;AAAA,UACzB,gBAAgB;AAAA,UAChB,YAAY,KAAK;AAAA,UACjB,eAAe,UAAU,KAAK,UAAU;AAAA,UACxC,aAAa,KAAK;AAAA,QAAA;AAAA,MAClB;AAAA;;AAIJ;;"}
|
package/dist/WriteClient.d.ts
CHANGED
|
@@ -101,6 +101,14 @@ export type WriteClientConfig = {
|
|
|
101
101
|
* A Prismic write token that allows writing content to the repository.
|
|
102
102
|
*/
|
|
103
103
|
writeToken: string;
|
|
104
|
+
/**
|
|
105
|
+
* A Prismic Migration API key that allows working with the Migration API.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* If no key is provided, the client will use one of the demo key available
|
|
109
|
+
* which has stricter rate limiting rules enforced.
|
|
110
|
+
*/
|
|
111
|
+
migrationAPIKey?: string;
|
|
104
112
|
/**
|
|
105
113
|
* The Prismic Asset API endpoint.
|
|
106
114
|
*
|
|
@@ -130,6 +138,7 @@ export type WriteClientConfig = {
|
|
|
130
138
|
*/
|
|
131
139
|
export declare class WriteClient<TDocuments extends PrismicDocument = PrismicDocument> extends Client<TDocuments> {
|
|
132
140
|
writeToken: string;
|
|
141
|
+
migrationAPIKey: string;
|
|
133
142
|
assetAPIEndpoint: string;
|
|
134
143
|
migrationAPIEndpoint: string;
|
|
135
144
|
/**
|
package/dist/WriteClient.js
CHANGED
|
@@ -6,6 +6,14 @@ import { pLimit } from "./lib/pLimit.js";
|
|
|
6
6
|
import { resolveMigrationContentRelationship, resolveMigrationDocumentData } from "./lib/resolveMigrationDocumentData.js";
|
|
7
7
|
import { PrismicError } from "./errors/PrismicError.js";
|
|
8
8
|
import { Client } from "./Client.js";
|
|
9
|
+
const MIGRATION_API_DEMO_KEYS = [
|
|
10
|
+
"cSaZlfkQlF9C6CEAM2Del6MNX9WonlV86HPbeEJL",
|
|
11
|
+
"pZCexCajUQ4jriYwIGSxA1drZrFxDyFf1S0D1K0P",
|
|
12
|
+
"Yc0mfrkGDw8gaaGKTrzwC3QUZDajv6k73DA99vWN",
|
|
13
|
+
"ySzSEbVMAb5S1oSCQfbVG4mbh9Cb8wlF7BCvKI0L",
|
|
14
|
+
"g2DA3EKWvx8uxVYcNFrmT5nJpon1Vi9V4XcOibJD",
|
|
15
|
+
"CCNIlI0Vz41J66oFwsHUXaZa6NYFIY6z7aDF62Bc"
|
|
16
|
+
];
|
|
9
17
|
class WriteClient extends Client {
|
|
10
18
|
/**
|
|
11
19
|
* Creates a Prismic client that can be used to query and write content to a
|
|
@@ -24,6 +32,7 @@ class WriteClient extends Client {
|
|
|
24
32
|
constructor(repositoryName, options) {
|
|
25
33
|
super(repositoryName, options);
|
|
26
34
|
__publicField(this, "writeToken");
|
|
35
|
+
__publicField(this, "migrationAPIKey");
|
|
27
36
|
__publicField(this, "assetAPIEndpoint", "https://asset-api.prismic.io/");
|
|
28
37
|
__publicField(this, "migrationAPIEndpoint", "https://migration.prismic.io/");
|
|
29
38
|
/**
|
|
@@ -31,9 +40,10 @@ class WriteClient extends Client {
|
|
|
31
40
|
*/
|
|
32
41
|
__publicField(this, "_resolveAssetTagIDsLimit", pLimit());
|
|
33
42
|
if (typeof globalThis.window !== "undefined") {
|
|
34
|
-
console.warn(`[@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
|
|
43
|
+
console.warn(`[@prismicio/client] Prismic write client appears to be running in a browser environment. This is not recommended as it exposes your write token and Migration API key. Consider using Prismic write client in a server environment only, preferring the regular client for browser environement. For more details, see ${devMsg("avoid-write-client-in-browser")}`);
|
|
35
44
|
}
|
|
36
45
|
this.writeToken = options.writeToken;
|
|
46
|
+
this.migrationAPIKey = options.migrationAPIKey || MIGRATION_API_DEMO_KEYS[Math.floor(Math.random() * MIGRATION_API_DEMO_KEYS.length)];
|
|
37
47
|
if (options.assetAPIEndpoint) {
|
|
38
48
|
this.assetAPIEndpoint = `${options.assetAPIEndpoint}/`;
|
|
39
49
|
}
|
|
@@ -493,7 +503,8 @@ class WriteClient extends Client {
|
|
|
493
503
|
...(_a = params == null ? void 0 : params.fetchOptions) == null ? void 0 : _a.headers,
|
|
494
504
|
"content-type": "application/json",
|
|
495
505
|
repository: this.repositoryName,
|
|
496
|
-
authorization: `Bearer ${this.writeToken}
|
|
506
|
+
authorization: `Bearer ${this.writeToken}`,
|
|
507
|
+
"x-api-key": this.migrationAPIKey
|
|
497
508
|
}
|
|
498
509
|
}
|
|
499
510
|
};
|
package/dist/WriteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.js","sources":["../../src/WriteClient.ts"],"sourcesContent":["import { devMsg } from \"./lib/devMsg\"\nimport { pLimit } from \"./lib/pLimit\"\nimport {\n\tresolveMigrationContentRelationship,\n\tresolveMigrationDocumentData,\n} from \"./lib/resolveMigrationDocumentData\"\n\nimport type {\n\tAsset,\n\tPatchAssetParams,\n\tPatchAssetResult,\n\tPostAssetParams,\n\tPostAssetResult,\n} from \"./types/api/asset/asset\"\nimport type {\n\tAssetTag,\n\tGetAssetTagsResult,\n\tPostAssetTagParams,\n\tPostAssetTagResult,\n} from \"./types/api/asset/tag\"\nimport type { PutDocumentResult } from \"./types/api/migration/document\"\nimport {\n\ttype PostDocumentParams,\n\ttype PostDocumentResult,\n\ttype PutDocumentParams,\n} from \"./types/api/migration/document\"\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\nimport { PrismicError } from \"./errors/PrismicError\"\n\nimport type { FetchParams, RequestInitLike } from \"./BaseClient\"\nimport { Client } from \"./Client\"\nimport type { ClientConfig } from \"./Client\"\nimport type { Migration } from \"./Migration\"\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { createMigration } from \"./createMigration\"\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic\n * document type. If no matches are found, no extraction is performed and the\n * union of all provided Prismic document types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/**\n * Utility type to construct events reported by the migration process.\n */\ntype MigrateReporterEvent<\n\tTType extends string,\n\tTData = never,\n> = TData extends never\n\t? { type: TType }\n\t: {\n\t\t\ttype: TType\n\t\t\tdata: TData\n\t\t}\n\n/**\n * A map of event types and their data reported by the migration process.\n */\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/**\n * Available event types reported by the migration process.\n */\ntype MigrateReporterEventTypes = keyof MigrateReporterEventMap\n\n/**\n * All events reported by the migration process. Events can be listened to by\n * providing a `reporter` function to the `migrate` method.\n */\nexport type MigrateReporterEvents = {\n\t[K in MigrateReporterEventTypes]: MigrateReporterEvent<\n\t\tK,\n\t\tMigrateReporterEventMap[K]\n\t>\n}[MigrateReporterEventTypes]\n\n/**\n * Additional parameters for creating an asset in the Prismic media library.\n */\nexport type CreateAssetParams = {\n\t/**\n\t * Asset notes.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Asset credits.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Asset alt text.\n\t */\n\talt?: string\n\n\t/**\n\t * Asset tags.\n\t */\n\ttags?: string[]\n}\n\n/**\n * Configuration for clients that determine how content is queried.\n */\nexport type WriteClientConfig = {\n\t/**\n\t * A Prismic write token that allows writing content to the repository.\n\t */\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 *\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 *\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,\n * such as Node.js, the `fetch` option must be provided as part of the `options`\n * parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic\n * repository. Query 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\n\t * repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable,\n\t * such as in some Node.js versions, the `fetch` option must be provided as\n\t * 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\n\t * from and written to the Prismic repository.\n\t *\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\n\t * 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 *\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 * 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 *\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 } =\n\t\t\t\tmigrationAsset.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 (error) {\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(\n\t\t\t\t\t\turl.toString(),\n\t\t\t\t\t\tfetchParams,\n\t\t\t\t\t)\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(\n\t\t\t\t\tfile.toString(),\n\t\t\t\t\tfetchParams,\n\t\t\t\t)\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\t...{ notes, credits, alt, tags },\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 *\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.find((lang) => lang.is_master)!.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 =\n\t\t\t\t\tawait resolveMigrationContentRelationship(doc.masterLanguageDocument)\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 =\n\t\t\t\t\tdoc.originalPrismicDocument.alternate_languages.find(\n\t\t\t\t\t\t({ lang }) => lang === masterLocale,\n\t\t\t\t\t)?.id\n\n\t\t\t\tif (maybeOriginalID) {\n\t\t\t\t\tmasterLanguageDocumentID =\n\t\t\t\t\t\tmigration._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\n\t * 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 *\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(\n\t\t\t\t\t\tdoc.document.data,\n\t\t\t\t\t\tmigration,\n\t\t\t\t\t),\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 *\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{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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 asset = await this.fetch<PostAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\tif (tags && tags.length) {\n\t\t\treturn this.updateAsset(asset.id, { tags })\n\t\t}\n\n\t\treturn asset\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 *\n\t * @returns The updated asset.\n\t */\n\tprivate async updateAsset(\n\t\tid: string,\n\t\t{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\tfilename,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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\treturn this.fetch<PatchAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PatchAssetParams>({\n\t\t\t\tmethod: \"PATCH\",\n\t\t\t\tbody: {\n\t\t\t\t\tnotes,\n\t\t\t\t\tcredits,\n\t\t\t\t\talt,\n\t\t\t\t\tfilename,\n\t\t\t\t\ttags,\n\t\t\t\t},\n\t\t\t\tparams,\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 *\n\t * @returns A file representing the fetched asset.\n\t */\n\tprivate async fetchForeignAsset(\n\t\turl: string,\n\t\tparams: FetchParams = {},\n\t): Promise<Blob> {\n\t\tconst requestInit: RequestInitLike = {\n\t\t\t...this.fetchOptions,\n\t\t\t...params.fetchOptions,\n\t\t\theaders: {\n\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t...params.fetchOptions?.headers,\n\t\t\t},\n\t\t\tsignal:\n\t\t\t\tparams.fetchOptions?.signal ||\n\t\t\t\tparams.signal ||\n\t\t\t\tthis.fetchOptions?.signal,\n\t\t}\n\n\t\tconst res = await this.fetchFn(url, requestInit)\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 blob = await res.blob()\n\n\t\t// Ensure a correct content type is attached to the blob.\n\t\treturn new File([blob], \"\", {\n\t\t\ttype: res.headers.get(\"content-type\") || undefined,\n\t\t})\n\t}\n\n\t/**\n\t * {@link resolveAssetTagIDs} rate limiter.\n\t */\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\n\t * additional fetch parameters.\n\t *\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 *\n\t * @param name - The name of the tag to create.\n\t * @param params - Additional fetch parameters.\n\t *\n\t * @returns The created tag.\n\t */\n\tprivate async createAssetTag(\n\t\tname: string,\n\t\tparams?: FetchParams,\n\t): Promise<AssetTag> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\treturn this.fetch<PostAssetTagResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PostAssetTagParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: { name },\n\t\t\t\tparams,\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 *\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 { items } = await this.fetch<GetAssetTagsResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({ params }),\n\t\t)\n\n\t\treturn items\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 *\n\t * @param document - The document to create.\n\t * @param documentTitle - The title of the document to create which will be\n\t * displayed in the editor.\n\t * @param params - Document master language document ID and additional fetch\n\t * parameters.\n\t *\n\t * @returns The ID of the created document.\n\t *\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 result = await this.fetch<PostDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams<PostDocumentParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: documentTitle,\n\t\t\t\t\ttype: document.type,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\tlang: document.lang,\n\t\t\t\t\talternate_language_id: masterLanguageDocumentID,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\treturn { id: result.id }\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 *\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 *\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\tawait this.fetch<PutDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams({\n\t\t\t\tmethod: \"PUT\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: document.documentTitle,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Asset API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch parameters.\n\t *\n\t * @returns An object that can be fetched to interact with the Asset API.\n\t *\n\t * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}\n\t */\n\tprivate buildAssetAPIQueryParams<TBody = FormData | Record<string, unknown>>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody?: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...params?.fetchOptions?.headers,\n\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\trepository: this.repositoryName,\n\t\t}\n\n\t\tlet _body: FormData | string | undefined\n\t\tif (body instanceof FormData) {\n\t\t\t_body = body\n\t\t} else if (body) {\n\t\t\t_body = JSON.stringify(body)\n\t\t\theaders[\"content-type\"] = \"application/json\"\n\t\t}\n\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: _body,\n\t\t\t\theaders,\n\t\t\t},\n\t\t}\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Migration API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch options.\n\t *\n\t * @returns An object that can be fetched to interact with the Migration API.\n\t *\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate buildMigrationAPIQueryParams<\n\t\tTBody extends PostDocumentParams | PutDocumentParams,\n\t>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\theaders: {\n\t\t\t\t\t...params?.fetchOptions?.headers,\n\t\t\t\t\t\"content-type\": \"application/json\",\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},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAuMM,MAAO,oBAEH,OAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB3B,YAAY,gBAAwB,SAA0B;AAC7D,UAAM,gBAAgB,OAAO;AApB9B;AAEA,4CAAmB;AACnB,gDAAuB;AAqbf;AAAA;AAAA;AAAA,oDAA2B,OAAM;AAlapC,QAAA,OAAO,WAAW,WAAW,aAAa;AAC7C,cAAQ,KACP,mSAAmS,OAAO,+BAA+B,CAAC,EAAE;AAAA,IAAA;AAI9U,SAAK,aAAa,QAAQ;AAE1B,QAAI,QAAQ,kBAAkB;AACxB,WAAA,mBAAmB,GAAG,QAAQ,gBAAgB;AAAA,IAAA;AAGpD,QAAI,QAAQ,sBAAsB;AAC5B,WAAA,uBAAuB,GAAG,QAAQ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1
|
+
{"version":3,"file":"WriteClient.js","sources":["../../src/WriteClient.ts"],"sourcesContent":["import { devMsg } from \"./lib/devMsg\"\nimport { pLimit } from \"./lib/pLimit\"\nimport {\n\tresolveMigrationContentRelationship,\n\tresolveMigrationDocumentData,\n} from \"./lib/resolveMigrationDocumentData\"\n\nimport type {\n\tAsset,\n\tPatchAssetParams,\n\tPatchAssetResult,\n\tPostAssetParams,\n\tPostAssetResult,\n} from \"./types/api/asset/asset\"\nimport type {\n\tAssetTag,\n\tGetAssetTagsResult,\n\tPostAssetTagParams,\n\tPostAssetTagResult,\n} from \"./types/api/asset/tag\"\nimport type { PutDocumentResult } from \"./types/api/migration/document\"\nimport {\n\ttype PostDocumentParams,\n\ttype PostDocumentResult,\n\ttype PutDocumentParams,\n} from \"./types/api/migration/document\"\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\nimport { PrismicError } from \"./errors/PrismicError\"\n\nimport type { FetchParams, RequestInitLike } from \"./BaseClient\"\nimport { Client } from \"./Client\"\nimport type { ClientConfig } from \"./Client\"\nimport type { Migration } from \"./Migration\"\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { createMigration } from \"./createMigration\"\n\n/**\n * Extracts one or more Prismic document types that match a given Prismic\n * document type. If no matches are found, no extraction is performed and the\n * union of all provided Prismic document types are returned.\n *\n * @typeParam TDocuments - Prismic document types from which to extract.\n * @typeParam TDocumentType - Type(s) to match `TDocuments` against.\n */\ntype ExtractDocumentType<\n\tTDocuments extends { type: string },\n\tTDocumentType extends TDocuments[\"type\"],\n> =\n\tExtract<TDocuments, { type: TDocumentType }> extends never\n\t\t? TDocuments\n\t\t: Extract<TDocuments, { type: TDocumentType }>\n\n/**\n * Utility type to construct events reported by the migration process.\n */\ntype MigrateReporterEvent<\n\tTType extends string,\n\tTData = never,\n> = TData extends never\n\t? { type: TType }\n\t: {\n\t\t\ttype: TType\n\t\t\tdata: TData\n\t\t}\n\n/**\n * A map of event types and their data reported by the migration process.\n */\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/**\n * Available event types reported by the migration process.\n */\ntype MigrateReporterEventTypes = keyof MigrateReporterEventMap\n\n/**\n * All events reported by the migration process. Events can be listened to by\n * providing a `reporter` function to the `migrate` method.\n */\nexport type MigrateReporterEvents = {\n\t[K in MigrateReporterEventTypes]: MigrateReporterEvent<\n\t\tK,\n\t\tMigrateReporterEventMap[K]\n\t>\n}[MigrateReporterEventTypes]\n\n/**\n * Additional parameters for creating an asset in the Prismic media library.\n */\nexport type CreateAssetParams = {\n\t/**\n\t * Asset notes.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Asset credits.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Asset alt text.\n\t */\n\talt?: string\n\n\t/**\n\t * Asset tags.\n\t */\n\ttags?: string[]\n}\n\n/**\n * Prismic Migration API demo keys.\n */\nconst MIGRATION_API_DEMO_KEYS = [\n\t\"cSaZlfkQlF9C6CEAM2Del6MNX9WonlV86HPbeEJL\",\n\t\"pZCexCajUQ4jriYwIGSxA1drZrFxDyFf1S0D1K0P\",\n\t\"Yc0mfrkGDw8gaaGKTrzwC3QUZDajv6k73DA99vWN\",\n\t\"ySzSEbVMAb5S1oSCQfbVG4mbh9Cb8wlF7BCvKI0L\",\n\t\"g2DA3EKWvx8uxVYcNFrmT5nJpon1Vi9V4XcOibJD\",\n\t\"CCNIlI0Vz41J66oFwsHUXaZa6NYFIY6z7aDF62Bc\",\n]\n\n/**\n * Configuration for clients that determine how content is queried.\n */\nexport type WriteClientConfig = {\n\t/**\n\t * A Prismic write token that allows writing content to the repository.\n\t */\n\twriteToken: string\n\n\t/**\n\t * A Prismic Migration API key that allows working with the Migration API.\n\t *\n\t * @remarks\n\t * If no key is provided, the client will use one of the demo key available\n\t * which has stricter rate limiting rules enforced.\n\t */\n\tmigrationAPIKey?: string\n\n\t/**\n\t * The Prismic Asset API endpoint.\n\t *\n\t * @defaultValue `\"https://asset-api.prismic.io/\"`\n\t *\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 *\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,\n * such as Node.js, the `fetch` option must be provided as part of the `options`\n * parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic\n * repository. Query 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\tmigrationAPIKey: 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\n\t * repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable,\n\t * such as in some Node.js versions, the `fetch` option must be provided as\n\t * 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\n\t * from and written to the Prismic repository.\n\t *\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 and Migration API key. Consider using Prismic write client in a server environment only, preferring the regular client for browser environement. 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\t\tthis.migrationAPIKey =\n\t\t\toptions.migrationAPIKey ||\n\t\t\tMIGRATION_API_DEMO_KEYS[\n\t\t\t\tMath.floor(Math.random() * MIGRATION_API_DEMO_KEYS.length)\n\t\t\t]\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\n\t * 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 *\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 * 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 *\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 } =\n\t\t\t\tmigrationAsset.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 (error) {\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(\n\t\t\t\t\t\turl.toString(),\n\t\t\t\t\t\tfetchParams,\n\t\t\t\t\t)\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(\n\t\t\t\t\tfile.toString(),\n\t\t\t\t\tfetchParams,\n\t\t\t\t)\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\t...{ notes, credits, alt, tags },\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 *\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.find((lang) => lang.is_master)!.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 =\n\t\t\t\t\tawait resolveMigrationContentRelationship(doc.masterLanguageDocument)\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 =\n\t\t\t\t\tdoc.originalPrismicDocument.alternate_languages.find(\n\t\t\t\t\t\t({ lang }) => lang === masterLocale,\n\t\t\t\t\t)?.id\n\n\t\t\t\tif (maybeOriginalID) {\n\t\t\t\t\tmasterLanguageDocumentID =\n\t\t\t\t\t\tmigration._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\n\t * 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 *\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(\n\t\t\t\t\t\tdoc.document.data,\n\t\t\t\t\t\tmigration,\n\t\t\t\t\t),\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 *\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{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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 asset = await this.fetch<PostAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\tif (tags && tags.length) {\n\t\t\treturn this.updateAsset(asset.id, { tags })\n\t\t}\n\n\t\treturn asset\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 *\n\t * @returns The updated asset.\n\t */\n\tprivate async updateAsset(\n\t\tid: string,\n\t\t{\n\t\t\tnotes,\n\t\t\tcredits,\n\t\t\talt,\n\t\t\tfilename,\n\t\t\ttags,\n\t\t\t...params\n\t\t}: 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\treturn this.fetch<PatchAssetResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PatchAssetParams>({\n\t\t\t\tmethod: \"PATCH\",\n\t\t\t\tbody: {\n\t\t\t\t\tnotes,\n\t\t\t\t\tcredits,\n\t\t\t\t\talt,\n\t\t\t\t\tfilename,\n\t\t\t\t\ttags,\n\t\t\t\t},\n\t\t\t\tparams,\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 *\n\t * @returns A file representing the fetched asset.\n\t */\n\tprivate async fetchForeignAsset(\n\t\turl: string,\n\t\tparams: FetchParams = {},\n\t): Promise<Blob> {\n\t\tconst requestInit: RequestInitLike = {\n\t\t\t...this.fetchOptions,\n\t\t\t...params.fetchOptions,\n\t\t\theaders: {\n\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t...params.fetchOptions?.headers,\n\t\t\t},\n\t\t\tsignal:\n\t\t\t\tparams.fetchOptions?.signal ||\n\t\t\t\tparams.signal ||\n\t\t\t\tthis.fetchOptions?.signal,\n\t\t}\n\n\t\tconst res = await this.fetchFn(url, requestInit)\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 blob = await res.blob()\n\n\t\t// Ensure a correct content type is attached to the blob.\n\t\treturn new File([blob], \"\", {\n\t\t\ttype: res.headers.get(\"content-type\") || undefined,\n\t\t})\n\t}\n\n\t/**\n\t * {@link resolveAssetTagIDs} rate limiter.\n\t */\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\n\t * additional fetch parameters.\n\t *\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 *\n\t * @param name - The name of the tag to create.\n\t * @param params - Additional fetch parameters.\n\t *\n\t * @returns The created tag.\n\t */\n\tprivate async createAssetTag(\n\t\tname: string,\n\t\tparams?: FetchParams,\n\t): Promise<AssetTag> {\n\t\tconst url = new URL(\"tags\", this.assetAPIEndpoint)\n\n\t\treturn this.fetch<PostAssetTagResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams<PostAssetTagParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: { name },\n\t\t\t\tparams,\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 *\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 { items } = await this.fetch<GetAssetTagsResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildAssetAPIQueryParams({ params }),\n\t\t)\n\n\t\treturn items\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 *\n\t * @param document - The document to create.\n\t * @param documentTitle - The title of the document to create which will be\n\t * displayed in the editor.\n\t * @param params - Document master language document ID and additional fetch\n\t * parameters.\n\t *\n\t * @returns The ID of the created document.\n\t *\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 result = await this.fetch<PostDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams<PostDocumentParams>({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: documentTitle,\n\t\t\t\t\ttype: document.type,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\tlang: document.lang,\n\t\t\t\t\talternate_language_id: masterLanguageDocumentID,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\n\t\treturn { id: result.id }\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 *\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 *\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\tawait this.fetch<PutDocumentResult>(\n\t\t\turl.toString(),\n\t\t\tthis.buildMigrationAPIQueryParams({\n\t\t\t\tmethod: \"PUT\",\n\t\t\t\tbody: {\n\t\t\t\t\ttitle: document.documentTitle,\n\t\t\t\t\tuid: document.uid || undefined,\n\t\t\t\t\ttags: document.tags,\n\t\t\t\t\tdata: document.data,\n\t\t\t\t},\n\t\t\t\tparams,\n\t\t\t}),\n\t\t)\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Asset API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch parameters.\n\t *\n\t * @returns An object that can be fetched to interact with the Asset API.\n\t *\n\t * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}\n\t */\n\tprivate buildAssetAPIQueryParams<TBody = FormData | Record<string, unknown>>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody?: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...params?.fetchOptions?.headers,\n\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\trepository: this.repositoryName,\n\t\t}\n\n\t\tlet _body: FormData | string | undefined\n\t\tif (body instanceof FormData) {\n\t\t\t_body = body\n\t\t} else if (body) {\n\t\t\t_body = JSON.stringify(body)\n\t\t\theaders[\"content-type\"] = \"application/json\"\n\t\t}\n\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: _body,\n\t\t\t\theaders,\n\t\t\t},\n\t\t}\n\t}\n\n\t/**\n\t * Builds fetch parameters for the Migration API.\n\t *\n\t * @typeParam TBody - Type of the body to send in the fetch request.\n\t *\n\t * @param params - Method, body, and additional fetch options.\n\t *\n\t * @returns An object that can be fetched to interact with the Migration API.\n\t *\n\t * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}\n\t */\n\tprivate buildMigrationAPIQueryParams<\n\t\tTBody extends PostDocumentParams | PutDocumentParams,\n\t>({\n\t\tmethod,\n\t\tbody,\n\t\tparams,\n\t}: {\n\t\tmethod?: string\n\t\tbody: TBody\n\t\tparams?: FetchParams\n\t}): FetchParams {\n\t\treturn {\n\t\t\t...params,\n\t\t\tfetchOptions: {\n\t\t\t\t...params?.fetchOptions,\n\t\t\t\tmethod,\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\theaders: {\n\t\t\t\t\t...params?.fetchOptions?.headers,\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\trepository: this.repositoryName,\n\t\t\t\t\tauthorization: `Bearer ${this.writeToken}`,\n\t\t\t\t\t\"x-api-key\": this.migrationAPIKey,\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAoKA,MAAM,0BAA0B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAkDK,MAAO,oBAEH,OAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB3B,YAAY,gBAAwB,SAA0B;AAC7D,UAAM,gBAAgB,OAAO;AArB9B;AACA;AAEA,4CAAmB;AACnB,gDAAuB;AA0bf;AAAA;AAAA;AAAA,oDAA2B,OAAM;AAvapC,QAAA,OAAO,WAAW,WAAW,aAAa;AAC7C,cAAQ,KACP,0TAA0T,OAAO,+BAA+B,CAAC,EAAE;AAAA,IAAA;AAIrW,SAAK,aAAa,QAAQ;AACrB,SAAA,kBACJ,QAAQ,mBACR,wBACC,KAAK,MAAM,KAAK,OAAM,IAAK,wBAAwB,MAAM,CAAC;AAG5D,QAAI,QAAQ,kBAAkB;AAC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BAAgB;AAAA,UAChB,YAAY,KAAK;AAAA,UACjB,eAAe,UAAU,KAAK,UAAU;AAAA,UACxC,aAAa,KAAK;AAAA,QAAA;AAAA,MAClB;AAAA;;AAIJ;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
package/src/WriteClient.ts
CHANGED
|
@@ -159,6 +159,18 @@ export type CreateAssetParams = {
|
|
|
159
159
|
tags?: string[]
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Prismic Migration API demo keys.
|
|
164
|
+
*/
|
|
165
|
+
const MIGRATION_API_DEMO_KEYS = [
|
|
166
|
+
"cSaZlfkQlF9C6CEAM2Del6MNX9WonlV86HPbeEJL",
|
|
167
|
+
"pZCexCajUQ4jriYwIGSxA1drZrFxDyFf1S0D1K0P",
|
|
168
|
+
"Yc0mfrkGDw8gaaGKTrzwC3QUZDajv6k73DA99vWN",
|
|
169
|
+
"ySzSEbVMAb5S1oSCQfbVG4mbh9Cb8wlF7BCvKI0L",
|
|
170
|
+
"g2DA3EKWvx8uxVYcNFrmT5nJpon1Vi9V4XcOibJD",
|
|
171
|
+
"CCNIlI0Vz41J66oFwsHUXaZa6NYFIY6z7aDF62Bc",
|
|
172
|
+
]
|
|
173
|
+
|
|
162
174
|
/**
|
|
163
175
|
* Configuration for clients that determine how content is queried.
|
|
164
176
|
*/
|
|
@@ -168,6 +180,15 @@ export type WriteClientConfig = {
|
|
|
168
180
|
*/
|
|
169
181
|
writeToken: string
|
|
170
182
|
|
|
183
|
+
/**
|
|
184
|
+
* A Prismic Migration API key that allows working with the Migration API.
|
|
185
|
+
*
|
|
186
|
+
* @remarks
|
|
187
|
+
* If no key is provided, the client will use one of the demo key available
|
|
188
|
+
* which has stricter rate limiting rules enforced.
|
|
189
|
+
*/
|
|
190
|
+
migrationAPIKey?: string
|
|
191
|
+
|
|
171
192
|
/**
|
|
172
193
|
* The Prismic Asset API endpoint.
|
|
173
194
|
*
|
|
@@ -201,6 +222,7 @@ export class WriteClient<
|
|
|
201
222
|
TDocuments extends PrismicDocument = PrismicDocument,
|
|
202
223
|
> extends Client<TDocuments> {
|
|
203
224
|
writeToken: string
|
|
225
|
+
migrationAPIKey: string
|
|
204
226
|
|
|
205
227
|
assetAPIEndpoint = "https://asset-api.prismic.io/"
|
|
206
228
|
migrationAPIEndpoint = "https://migration.prismic.io/"
|
|
@@ -224,11 +246,16 @@ export class WriteClient<
|
|
|
224
246
|
|
|
225
247
|
if (typeof globalThis.window !== "undefined") {
|
|
226
248
|
console.warn(
|
|
227
|
-
`[@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
|
|
249
|
+
`[@prismicio/client] Prismic write client appears to be running in a browser environment. This is not recommended as it exposes your write token and Migration API key. Consider using Prismic write client in a server environment only, preferring the regular client for browser environement. For more details, see ${devMsg("avoid-write-client-in-browser")}`,
|
|
228
250
|
)
|
|
229
251
|
}
|
|
230
252
|
|
|
231
253
|
this.writeToken = options.writeToken
|
|
254
|
+
this.migrationAPIKey =
|
|
255
|
+
options.migrationAPIKey ||
|
|
256
|
+
MIGRATION_API_DEMO_KEYS[
|
|
257
|
+
Math.floor(Math.random() * MIGRATION_API_DEMO_KEYS.length)
|
|
258
|
+
]
|
|
232
259
|
|
|
233
260
|
if (options.assetAPIEndpoint) {
|
|
234
261
|
this.assetAPIEndpoint = `${options.assetAPIEndpoint}/`
|
|
@@ -882,6 +909,7 @@ export class WriteClient<
|
|
|
882
909
|
"content-type": "application/json",
|
|
883
910
|
repository: this.repositoryName,
|
|
884
911
|
authorization: `Bearer ${this.writeToken}`,
|
|
912
|
+
"x-api-key": this.migrationAPIKey,
|
|
885
913
|
},
|
|
886
914
|
},
|
|
887
915
|
}
|