@prismicio/client 7.10.0-alpha.0 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/BaseClient.cjs +108 -0
  2. package/dist/BaseClient.cjs.map +1 -0
  3. package/dist/BaseClient.d.ts +152 -0
  4. package/dist/BaseClient.js +108 -0
  5. package/dist/BaseClient.js.map +1 -0
  6. package/dist/Client.cjs +1217 -0
  7. package/dist/Client.cjs.map +1 -0
  8. package/dist/Client.d.ts +924 -0
  9. package/dist/Client.js +1217 -0
  10. package/dist/Client.js.map +1 -0
  11. package/dist/Migration.cjs +318 -0
  12. package/dist/Migration.cjs.map +1 -0
  13. package/dist/Migration.d.ts +213 -0
  14. package/dist/Migration.js +318 -0
  15. package/dist/Migration.js.map +1 -0
  16. package/dist/WriteClient.cjs +512 -0
  17. package/dist/WriteClient.cjs.map +1 -0
  18. package/dist/WriteClient.d.ts +314 -0
  19. package/dist/WriteClient.js +512 -0
  20. package/dist/WriteClient.js.map +1 -0
  21. package/dist/createClient.cjs +2 -1215
  22. package/dist/createClient.cjs.map +1 -1
  23. package/dist/createClient.d.ts +2 -1003
  24. package/dist/createClient.js +1 -1214
  25. package/dist/createClient.js.map +1 -1
  26. package/dist/createMigration.cjs +6 -0
  27. package/dist/createMigration.cjs.map +1 -0
  28. package/dist/createMigration.d.ts +24 -0
  29. package/dist/createMigration.js +6 -0
  30. package/dist/createMigration.js.map +1 -0
  31. package/dist/createWriteClient.cjs +6 -0
  32. package/dist/createWriteClient.cjs.map +1 -0
  33. package/dist/createWriteClient.d.ts +32 -0
  34. package/dist/createWriteClient.js +6 -0
  35. package/dist/createWriteClient.js.map +1 -0
  36. package/dist/getRepositoryName.cjs +7 -2
  37. package/dist/getRepositoryName.cjs.map +1 -1
  38. package/dist/getRepositoryName.d.ts +3 -6
  39. package/dist/getRepositoryName.js +7 -2
  40. package/dist/getRepositoryName.js.map +1 -1
  41. package/dist/index.cjs +14 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +17 -2
  44. package/dist/index.js +14 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/isMigrationValue.cjs +24 -0
  47. package/dist/lib/isMigrationValue.cjs.map +1 -0
  48. package/dist/lib/isMigrationValue.d.ts +62 -0
  49. package/dist/lib/isMigrationValue.js +24 -0
  50. package/dist/lib/isMigrationValue.js.map +1 -0
  51. package/dist/lib/isValue.cjs +53 -0
  52. package/dist/lib/isValue.cjs.map +1 -0
  53. package/dist/lib/isValue.d.ts +72 -0
  54. package/dist/lib/isValue.js +53 -0
  55. package/dist/lib/isValue.js.map +1 -0
  56. package/dist/lib/pLimit.cjs +49 -0
  57. package/dist/lib/pLimit.cjs.map +1 -0
  58. package/dist/lib/pLimit.d.ts +22 -0
  59. package/dist/lib/pLimit.js +49 -0
  60. package/dist/lib/pLimit.js.map +1 -0
  61. package/dist/lib/resolveMigrationDocumentData.cjs +123 -0
  62. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -0
  63. package/dist/lib/resolveMigrationDocumentData.d.ts +52 -0
  64. package/dist/lib/resolveMigrationDocumentData.js +123 -0
  65. package/dist/lib/resolveMigrationDocumentData.js.map +1 -0
  66. package/dist/lib/validateAssetMetadata.cjs +28 -0
  67. package/dist/lib/validateAssetMetadata.cjs.map +1 -0
  68. package/dist/lib/validateAssetMetadata.d.ts +10 -0
  69. package/dist/lib/validateAssetMetadata.js +28 -0
  70. package/dist/lib/validateAssetMetadata.js.map +1 -0
  71. package/dist/package.json.cjs +1 -1
  72. package/dist/package.json.js +1 -1
  73. package/dist/types/api/asset/asset.d.ts +177 -0
  74. package/dist/types/api/asset/tag.d.ts +53 -0
  75. package/dist/types/api/migration/document.d.ts +60 -0
  76. package/dist/types/migration/Asset.cjs +33 -0
  77. package/dist/types/migration/Asset.cjs.map +1 -0
  78. package/dist/types/migration/Asset.d.ts +109 -0
  79. package/dist/types/migration/Asset.js +33 -0
  80. package/dist/types/migration/Asset.js.map +1 -0
  81. package/dist/types/migration/ContentRelationship.d.ts +17 -0
  82. package/dist/types/migration/Document.cjs +47 -0
  83. package/dist/types/migration/Document.cjs.map +1 -0
  84. package/dist/types/migration/Document.d.ts +94 -0
  85. package/dist/types/migration/Document.js +47 -0
  86. package/dist/types/migration/Document.js.map +1 -0
  87. package/dist/types/model/link.cjs.map +1 -1
  88. package/dist/types/model/link.d.ts +0 -1
  89. package/dist/types/model/link.js.map +1 -1
  90. package/dist/types/model/linkToMedia.d.ts +0 -1
  91. package/dist/types/value/contentRelationship.d.ts +0 -1
  92. package/dist/types/value/link.cjs.map +1 -1
  93. package/dist/types/value/link.d.ts +0 -2
  94. package/dist/types/value/link.js.map +1 -1
  95. package/dist/types/value/linkToMedia.d.ts +0 -1
  96. package/package.json +2 -2
  97. package/src/BaseClient.ts +330 -0
  98. package/src/Client.ts +1787 -0
  99. package/src/Migration.ts +531 -0
  100. package/src/WriteClient.ts +911 -0
  101. package/src/createClient.ts +3 -1931
  102. package/src/createMigration.ts +31 -0
  103. package/src/createWriteClient.ts +43 -0
  104. package/src/getRepositoryName.ts +19 -14
  105. package/src/index.ts +32 -4
  106. package/src/lib/isMigrationValue.ts +126 -0
  107. package/src/lib/isValue.ts +196 -0
  108. package/src/lib/pLimit.ts +106 -0
  109. package/src/lib/resolveMigrationDocumentData.ts +233 -0
  110. package/src/lib/validateAssetMetadata.ts +82 -0
  111. package/src/types/api/asset/asset.ts +211 -0
  112. package/src/types/api/asset/tag.ts +59 -0
  113. package/src/types/api/migration/document.ts +84 -0
  114. package/src/types/migration/Asset.ts +156 -0
  115. package/src/types/migration/ContentRelationship.ts +36 -0
  116. package/src/types/migration/Document.ts +157 -0
  117. package/src/types/model/link.ts +0 -1
  118. package/src/types/model/linkToMedia.ts +0 -1
  119. package/src/types/value/contentRelationship.ts +0 -1
  120. package/src/types/value/link.ts +0 -2
  121. package/src/types/value/linkToMedia.ts +0 -1
@@ -0,0 +1,512 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const devMsg = require("./lib/devMsg.cjs");
7
+ const pLimit = require("./lib/pLimit.cjs");
8
+ const resolveMigrationDocumentData = require("./lib/resolveMigrationDocumentData.cjs");
9
+ const PrismicError = require("./errors/PrismicError.cjs");
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
+ ];
19
+ class WriteClient extends Client.Client {
20
+ /**
21
+ * Creates a Prismic client that can be used to query and write content to a
22
+ * repository.
23
+ *
24
+ * If used in an environment where a global `fetch` function is unavailable,
25
+ * such as in some Node.js versions, the `fetch` option must be provided as
26
+ * part of the `options` parameter.
27
+ *
28
+ * @param repositoryName - The Prismic repository name for the repository.
29
+ * @param options - Configuration that determines how content will be queried
30
+ * from and written to the Prismic repository.
31
+ *
32
+ * @returns A client that can query and write content to the repository.
33
+ */
34
+ constructor(repositoryName, options) {
35
+ super(repositoryName, options);
36
+ __publicField(this, "writeToken");
37
+ __publicField(this, "migrationAPIKey");
38
+ __publicField(this, "assetAPIEndpoint", "https://asset-api.prismic.io/");
39
+ __publicField(this, "migrationAPIEndpoint", "https://migration.prismic.io/");
40
+ /**
41
+ * {@link resolveAssetTagIDs} rate limiter.
42
+ */
43
+ __publicField(this, "_resolveAssetTagIDsLimit", pLimit.pLimit());
44
+ if (typeof globalThis.window !== "undefined") {
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")}`);
46
+ }
47
+ this.writeToken = options.writeToken;
48
+ this.migrationAPIKey = options.migrationAPIKey || MIGRATION_API_DEMO_KEYS[Math.floor(Math.random() * MIGRATION_API_DEMO_KEYS.length)];
49
+ if (options.assetAPIEndpoint) {
50
+ this.assetAPIEndpoint = `${options.assetAPIEndpoint}/`;
51
+ }
52
+ if (options.migrationAPIEndpoint) {
53
+ this.migrationAPIEndpoint = `${options.migrationAPIEndpoint}/`;
54
+ }
55
+ }
56
+ /**
57
+ * Creates a migration release on the Prismic repository based on the provided
58
+ * prepared migration.
59
+ *
60
+ * @param migration - A migration prepared with {@link createMigration}.
61
+ * @param params - An event listener and additional fetch parameters.
62
+ *
63
+ * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
64
+ */
65
+ async migrate(migration, params = {}) {
66
+ var _a, _b;
67
+ (_a = params.reporter) == null ? void 0 : _a.call(params, {
68
+ type: "start",
69
+ data: {
70
+ pending: {
71
+ documents: migration._documents.length,
72
+ assets: migration._assets.size
73
+ }
74
+ }
75
+ });
76
+ await this.migrateCreateAssets(migration, params);
77
+ await this.migrateCreateDocuments(migration, params);
78
+ await this.migrateUpdateDocuments(migration, params);
79
+ (_b = params.reporter) == null ? void 0 : _b.call(params, {
80
+ type: "end",
81
+ data: {
82
+ migrated: {
83
+ documents: migration._documents.length,
84
+ assets: migration._assets.size
85
+ }
86
+ }
87
+ });
88
+ }
89
+ /**
90
+ * Creates assets in the Prismic repository's media library.
91
+ *
92
+ * @param migration - A migration prepared with {@link createMigration}.
93
+ * @param params - An event listener and additional fetch parameters.
94
+ *
95
+ * @internal This method is one of the step performed by the {@link migrate} method.
96
+ */
97
+ async migrateCreateAssets(migration, { reporter, ...fetchParams } = {}) {
98
+ let created = 0;
99
+ for (const [_, migrationAsset] of migration._assets) {
100
+ reporter == null ? void 0 : reporter({
101
+ type: "assets:creating",
102
+ data: {
103
+ current: ++created,
104
+ remaining: migration._assets.size - created,
105
+ total: migration._assets.size,
106
+ asset: migrationAsset
107
+ }
108
+ });
109
+ const { file, filename, notes, credits, alt, tags } = migrationAsset.config;
110
+ let resolvedFile;
111
+ if (typeof file === "string") {
112
+ let url;
113
+ try {
114
+ url = new URL(file);
115
+ } catch (error) {
116
+ }
117
+ if (url) {
118
+ resolvedFile = await this.fetchForeignAsset(url.toString(), fetchParams);
119
+ } else {
120
+ resolvedFile = file;
121
+ }
122
+ } else if (file instanceof URL) {
123
+ resolvedFile = await this.fetchForeignAsset(file.toString(), fetchParams);
124
+ } else {
125
+ resolvedFile = file;
126
+ }
127
+ const asset = await this.createAsset(resolvedFile, filename, {
128
+ ...{ notes, credits, alt, tags },
129
+ ...fetchParams
130
+ });
131
+ migrationAsset.asset = asset;
132
+ }
133
+ reporter == null ? void 0 : reporter({
134
+ type: "assets:created",
135
+ data: {
136
+ created
137
+ }
138
+ });
139
+ }
140
+ /**
141
+ * Creates documents in the Prismic repository's migration release.
142
+ *
143
+ * @param migration - A migration prepared with {@link createMigration}.
144
+ * @param params - An event listener and additional fetch parameters.
145
+ *
146
+ * @internal This method is one of the step performed by the {@link migrate} method.
147
+ */
148
+ async migrateCreateDocuments(migration, { reporter, ...fetchParams } = {}) {
149
+ var _a, _b;
150
+ const repository = await this.getRepository(fetchParams);
151
+ const masterLocale = repository.languages.find((lang) => lang.is_master).id;
152
+ reporter == null ? void 0 : reporter({
153
+ type: "documents:masterLocale",
154
+ data: {
155
+ masterLocale
156
+ }
157
+ });
158
+ const documentsToCreate = [];
159
+ for (const doc of migration._documents) {
160
+ if (!doc.document.id) {
161
+ if (doc.document.lang === masterLocale) {
162
+ documentsToCreate.unshift(doc);
163
+ } else {
164
+ documentsToCreate.push(doc);
165
+ }
166
+ }
167
+ }
168
+ let created = 0;
169
+ for (const doc of documentsToCreate) {
170
+ reporter == null ? void 0 : reporter({
171
+ type: "documents:creating",
172
+ data: {
173
+ current: ++created,
174
+ remaining: documentsToCreate.length - created,
175
+ total: documentsToCreate.length,
176
+ document: doc
177
+ }
178
+ });
179
+ let masterLanguageDocumentID;
180
+ if (doc.masterLanguageDocument) {
181
+ const masterLanguageDocument = await resolveMigrationDocumentData.resolveMigrationContentRelationship(doc.masterLanguageDocument);
182
+ masterLanguageDocumentID = "id" in masterLanguageDocument ? masterLanguageDocument.id : void 0;
183
+ } else if (doc.originalPrismicDocument) {
184
+ const maybeOriginalID = (_a = doc.originalPrismicDocument.alternate_languages.find(({ lang }) => lang === masterLocale)) == null ? void 0 : _a.id;
185
+ if (maybeOriginalID) {
186
+ masterLanguageDocumentID = (_b = migration._getByOriginalID(maybeOriginalID)) == null ? void 0 : _b.document.id;
187
+ }
188
+ }
189
+ const { id } = await this.createDocument(
190
+ // We'll upload documents data later on.
191
+ { ...doc.document, data: {} },
192
+ doc.title,
193
+ {
194
+ masterLanguageDocumentID,
195
+ ...fetchParams
196
+ }
197
+ );
198
+ doc.document.id = id;
199
+ }
200
+ reporter == null ? void 0 : reporter({
201
+ type: "documents:created",
202
+ data: { created }
203
+ });
204
+ }
205
+ /**
206
+ * Updates documents in the Prismic repository's migration release with their
207
+ * patched data.
208
+ *
209
+ * @param migration - A migration prepared with {@link createMigration}.
210
+ * @param params - An event listener and additional fetch parameters.
211
+ *
212
+ * @internal This method is one of the step performed by the {@link migrate} method.
213
+ */
214
+ async migrateUpdateDocuments(migration, { reporter, ...fetchParams } = {}) {
215
+ let i = 0;
216
+ for (const doc of migration._documents) {
217
+ reporter == null ? void 0 : reporter({
218
+ type: "documents:updating",
219
+ data: {
220
+ current: ++i,
221
+ remaining: migration._documents.length - i,
222
+ total: migration._documents.length,
223
+ document: doc
224
+ }
225
+ });
226
+ await this.updateDocument(
227
+ doc.document.id,
228
+ // We need to forward again document name and tags to update them
229
+ // in case the document already existed during the previous step.
230
+ {
231
+ ...doc.document,
232
+ data: await resolveMigrationDocumentData.resolveMigrationDocumentData(doc.document.data, migration)
233
+ },
234
+ fetchParams
235
+ );
236
+ }
237
+ reporter == null ? void 0 : reporter({
238
+ type: "documents:updated",
239
+ data: {
240
+ updated: migration._documents.length
241
+ }
242
+ });
243
+ }
244
+ /**
245
+ * Creates an asset in the Prismic media library.
246
+ *
247
+ * @param file - The file to upload as an asset.
248
+ * @param filename - The filename of the asset.
249
+ * @param params - Additional asset data and fetch parameters.
250
+ *
251
+ * @returns The created asset.
252
+ */
253
+ async createAsset(file, filename, { notes, credits, alt, tags, ...params } = {}) {
254
+ const url = new URL("assets", this.assetAPIEndpoint);
255
+ const formData = new FormData();
256
+ formData.append("file", new File([file], filename, {
257
+ type: file instanceof File ? file.type : void 0
258
+ }));
259
+ if (notes) {
260
+ formData.append("notes", notes);
261
+ }
262
+ if (credits) {
263
+ formData.append("credits", credits);
264
+ }
265
+ if (alt) {
266
+ formData.append("alt", alt);
267
+ }
268
+ const asset = await this.fetch(url.toString(), this.buildAssetAPIQueryParams({
269
+ method: "POST",
270
+ body: formData,
271
+ params
272
+ }));
273
+ if (tags && tags.length) {
274
+ return this.updateAsset(asset.id, { tags });
275
+ }
276
+ return asset;
277
+ }
278
+ /**
279
+ * Updates an asset in the Prismic media library.
280
+ *
281
+ * @param id - The ID of the asset to update.
282
+ * @param params - The asset data to update and additional fetch parameters.
283
+ *
284
+ * @returns The updated asset.
285
+ */
286
+ async updateAsset(id, { notes, credits, alt, filename, tags, ...params } = {}) {
287
+ const url = new URL(`assets/${id}`, this.assetAPIEndpoint);
288
+ if (tags && tags.length) {
289
+ tags = await this.resolveAssetTagIDs(tags, {
290
+ createTags: true,
291
+ ...params
292
+ });
293
+ }
294
+ return this.fetch(url.toString(), this.buildAssetAPIQueryParams({
295
+ method: "PATCH",
296
+ body: {
297
+ notes,
298
+ credits,
299
+ alt,
300
+ filename,
301
+ tags
302
+ },
303
+ params
304
+ }));
305
+ }
306
+ /**
307
+ * Fetches a foreign asset from a URL.
308
+ *
309
+ * @param url - The URL of the asset to fetch.
310
+ * @param params - Additional fetch parameters.
311
+ *
312
+ * @returns A file representing the fetched asset.
313
+ */
314
+ async fetchForeignAsset(url, params = {}) {
315
+ var _a, _b, _c, _d;
316
+ const requestInit = {
317
+ ...this.fetchOptions,
318
+ ...params.fetchOptions,
319
+ headers: {
320
+ ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
321
+ ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
322
+ },
323
+ signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
324
+ };
325
+ const res = await this.fetchFn(url, requestInit);
326
+ if (!res.ok) {
327
+ throw new PrismicError.PrismicError("Could not fetch foreign asset", url, void 0);
328
+ }
329
+ return res.blob();
330
+ }
331
+ /**
332
+ * Resolves asset tag IDs from tag names.
333
+ *
334
+ * @param tagNames - An array of tag names to resolve.
335
+ * @param params - Whether or not missing tags should be created and
336
+ * additional fetch parameters.
337
+ *
338
+ * @returns An array of resolved tag IDs.
339
+ */
340
+ async resolveAssetTagIDs(tagNames = [], { createTags, ...params } = {}) {
341
+ return this._resolveAssetTagIDsLimit(async () => {
342
+ const existingTags = await this.getAssetTags(params);
343
+ const existingTagMap = {};
344
+ for (const tag of existingTags) {
345
+ existingTagMap[tag.name] = tag;
346
+ }
347
+ const resolvedTagIDs = [];
348
+ for (const tagName of tagNames) {
349
+ if (!existingTagMap[tagName] && createTags) {
350
+ existingTagMap[tagName] = await this.createAssetTag(tagName, params);
351
+ }
352
+ if (existingTagMap[tagName]) {
353
+ resolvedTagIDs.push(existingTagMap[tagName].id);
354
+ }
355
+ }
356
+ return resolvedTagIDs;
357
+ });
358
+ }
359
+ /**
360
+ * Creates a tag in the Asset API.
361
+ *
362
+ * @remarks
363
+ * Tags should be at least 3 characters long and 20 characters at most.
364
+ *
365
+ * @param name - The name of the tag to create.
366
+ * @param params - Additional fetch parameters.
367
+ *
368
+ * @returns The created tag.
369
+ */
370
+ async createAssetTag(name, params) {
371
+ const url = new URL("tags", this.assetAPIEndpoint);
372
+ return this.fetch(url.toString(), this.buildAssetAPIQueryParams({
373
+ method: "POST",
374
+ body: { name },
375
+ params
376
+ }));
377
+ }
378
+ /**
379
+ * Queries existing tags from the Asset API.
380
+ *
381
+ * @param params - Additional fetch parameters.
382
+ *
383
+ * @returns An array of existing tags.
384
+ */
385
+ async getAssetTags(params) {
386
+ const url = new URL("tags", this.assetAPIEndpoint);
387
+ const { items } = await this.fetch(url.toString(), this.buildAssetAPIQueryParams({ params }));
388
+ return items;
389
+ }
390
+ /**
391
+ * Creates a document in the repository's migration release.
392
+ *
393
+ * @typeParam TType - Type of Prismic documents to create.
394
+ *
395
+ * @param document - The document to create.
396
+ * @param documentTitle - The title of the document to create which will be
397
+ * displayed in the editor.
398
+ * @param params - Document master language document ID and additional fetch
399
+ * parameters.
400
+ *
401
+ * @returns The ID of the created document.
402
+ *
403
+ * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
404
+ */
405
+ async createDocument(document, documentTitle, { masterLanguageDocumentID, ...params } = {}) {
406
+ const url = new URL("documents", this.migrationAPIEndpoint);
407
+ const result = await this.fetch(url.toString(), this.buildMigrationAPIQueryParams({
408
+ method: "POST",
409
+ body: {
410
+ title: documentTitle,
411
+ type: document.type,
412
+ uid: document.uid || void 0,
413
+ lang: document.lang,
414
+ alternate_language_id: masterLanguageDocumentID,
415
+ tags: document.tags,
416
+ data: document.data
417
+ },
418
+ params
419
+ }));
420
+ return { id: result.id };
421
+ }
422
+ /**
423
+ * Updates an existing document in the repository's migration release.
424
+ *
425
+ * @typeParam TType - Type of Prismic documents to update.
426
+ *
427
+ * @param id - The ID of the document to update.
428
+ * @param document - The document content to update.
429
+ * @param params - Additional fetch parameters.
430
+ *
431
+ * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
432
+ */
433
+ async updateDocument(id, document, params) {
434
+ const url = new URL(`documents/${id}`, this.migrationAPIEndpoint);
435
+ await this.fetch(url.toString(), this.buildMigrationAPIQueryParams({
436
+ method: "PUT",
437
+ body: {
438
+ title: document.documentTitle,
439
+ uid: document.uid || void 0,
440
+ tags: document.tags,
441
+ data: document.data
442
+ },
443
+ params
444
+ }));
445
+ }
446
+ /**
447
+ * Builds fetch parameters for the Asset API.
448
+ *
449
+ * @typeParam TBody - Type of the body to send in the fetch request.
450
+ *
451
+ * @param params - Method, body, and additional fetch parameters.
452
+ *
453
+ * @returns An object that can be fetched to interact with the Asset API.
454
+ *
455
+ * @see Prismic Asset API technical reference: {@link https://prismic.io/docs/asset-api-technical-reference}
456
+ */
457
+ buildAssetAPIQueryParams({ method, body, params }) {
458
+ var _a;
459
+ const headers = {
460
+ ...(_a = params == null ? void 0 : params.fetchOptions) == null ? void 0 : _a.headers,
461
+ authorization: `Bearer ${this.writeToken}`,
462
+ repository: this.repositoryName
463
+ };
464
+ let _body;
465
+ if (body instanceof FormData) {
466
+ _body = body;
467
+ } else if (body) {
468
+ _body = JSON.stringify(body);
469
+ headers["content-type"] = "application/json";
470
+ }
471
+ return {
472
+ ...params,
473
+ fetchOptions: {
474
+ ...params == null ? void 0 : params.fetchOptions,
475
+ method,
476
+ body: _body,
477
+ headers
478
+ }
479
+ };
480
+ }
481
+ /**
482
+ * Builds fetch parameters for the Migration API.
483
+ *
484
+ * @typeParam TBody - Type of the body to send in the fetch request.
485
+ *
486
+ * @param params - Method, body, and additional fetch options.
487
+ *
488
+ * @returns An object that can be fetched to interact with the Migration API.
489
+ *
490
+ * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference}
491
+ */
492
+ buildMigrationAPIQueryParams({ method, body, params }) {
493
+ var _a;
494
+ return {
495
+ ...params,
496
+ fetchOptions: {
497
+ ...params == null ? void 0 : params.fetchOptions,
498
+ method,
499
+ body: JSON.stringify(body),
500
+ headers: {
501
+ ...(_a = params == null ? void 0 : params.fetchOptions) == null ? void 0 : _a.headers,
502
+ "content-type": "application/json",
503
+ repository: this.repositoryName,
504
+ authorization: `Bearer ${this.writeToken}`,
505
+ "x-api-key": this.migrationAPIKey
506
+ }
507
+ }
508
+ };
509
+ }
510
+ }
511
+ exports.WriteClient = WriteClient;
512
+ //# sourceMappingURL=WriteClient.cjs.map
@@ -0,0 +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 * 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\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\treturn res.blob()\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;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,gDA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