@prismicio/e2e-tests-utils 1.18.0 → 1.19.0-pr.37.6283e4a

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 (159) hide show
  1. package/README.md +24 -27
  2. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/clients/apiClient.cjs +38 -38
  4. package/dist/clients/apiClient.cjs.map +1 -1
  5. package/dist/clients/apiClient.d.cts +30 -0
  6. package/dist/clients/apiClient.d.cts.map +1 -0
  7. package/dist/clients/apiClient.d.ts +23 -23
  8. package/dist/clients/apiClient.d.ts.map +1 -0
  9. package/dist/clients/apiClient.js +38 -38
  10. package/dist/clients/apiClient.js.map +1 -1
  11. package/dist/clients/assetApi.cjs +81 -93
  12. package/dist/clients/assetApi.cjs.map +1 -1
  13. package/dist/clients/assetApi.d.cts +105 -0
  14. package/dist/clients/assetApi.d.cts.map +1 -0
  15. package/dist/clients/assetApi.d.ts +96 -97
  16. package/dist/clients/assetApi.d.ts.map +1 -0
  17. package/dist/clients/assetApi.js +79 -91
  18. package/dist/clients/assetApi.js.map +1 -1
  19. package/dist/clients/authenticationApi.cjs +66 -73
  20. package/dist/clients/authenticationApi.cjs.map +1 -1
  21. package/dist/clients/authenticationApi.d.cts +20 -0
  22. package/dist/clients/authenticationApi.d.cts.map +1 -0
  23. package/dist/clients/authenticationApi.d.ts +18 -13
  24. package/dist/clients/authenticationApi.d.ts.map +1 -0
  25. package/dist/clients/authenticationApi.js +65 -72
  26. package/dist/clients/authenticationApi.js.map +1 -1
  27. package/dist/clients/contentApi.cjs +94 -103
  28. package/dist/clients/contentApi.cjs.map +1 -1
  29. package/dist/clients/contentApi.d.cts +116 -0
  30. package/dist/clients/contentApi.d.cts.map +1 -0
  31. package/dist/clients/contentApi.d.ts +102 -98
  32. package/dist/clients/contentApi.d.ts.map +1 -0
  33. package/dist/clients/contentApi.js +94 -103
  34. package/dist/clients/contentApi.js.map +1 -1
  35. package/dist/clients/coreApi.cjs +154 -145
  36. package/dist/clients/coreApi.cjs.map +1 -1
  37. package/dist/clients/coreApi.d.cts +142 -0
  38. package/dist/clients/coreApi.d.cts.map +1 -0
  39. package/dist/clients/coreApi.d.ts +131 -109
  40. package/dist/clients/coreApi.d.ts.map +1 -0
  41. package/dist/clients/coreApi.js +153 -144
  42. package/dist/clients/coreApi.js.map +1 -1
  43. package/dist/clients/customTypesApi.cjs +90 -99
  44. package/dist/clients/customTypesApi.cjs.map +1 -1
  45. package/dist/clients/customTypesApi.d.cts +46 -0
  46. package/dist/clients/customTypesApi.d.cts.map +1 -0
  47. package/dist/clients/customTypesApi.d.ts +45 -45
  48. package/dist/clients/customTypesApi.d.ts.map +1 -0
  49. package/dist/clients/customTypesApi.js +87 -98
  50. package/dist/clients/customTypesApi.js.map +1 -1
  51. package/dist/clients/integrationFields.cjs +96 -87
  52. package/dist/clients/integrationFields.cjs.map +1 -1
  53. package/dist/clients/integrationFields.d.cts +30 -0
  54. package/dist/clients/integrationFields.d.cts.map +1 -0
  55. package/dist/clients/integrationFields.d.ts +27 -22
  56. package/dist/clients/integrationFields.d.ts.map +1 -0
  57. package/dist/clients/integrationFields.js +93 -86
  58. package/dist/clients/integrationFields.js.map +1 -1
  59. package/dist/clients/manageV2.cjs +154 -171
  60. package/dist/clients/manageV2.cjs.map +1 -1
  61. package/dist/clients/manageV2.d.cts +105 -0
  62. package/dist/clients/manageV2.d.cts.map +1 -0
  63. package/dist/clients/manageV2.d.ts +103 -111
  64. package/dist/clients/manageV2.d.ts.map +1 -0
  65. package/dist/clients/manageV2.js +149 -169
  66. package/dist/clients/manageV2.js.map +1 -1
  67. package/dist/clients/migrationApi.cjs +37 -36
  68. package/dist/clients/migrationApi.cjs.map +1 -1
  69. package/dist/clients/migrationApi.d.cts +48 -0
  70. package/dist/clients/migrationApi.d.cts.map +1 -0
  71. package/dist/clients/migrationApi.d.ts +45 -39
  72. package/dist/clients/migrationApi.d.ts.map +1 -0
  73. package/dist/clients/migrationApi.js +35 -34
  74. package/dist/clients/migrationApi.js.map +1 -1
  75. package/dist/clients/wroom.cjs +101 -122
  76. package/dist/clients/wroom.cjs.map +1 -1
  77. package/dist/clients/wroom.d.cts +48 -0
  78. package/dist/clients/wroom.d.cts.map +1 -0
  79. package/dist/clients/wroom.d.ts +46 -47
  80. package/dist/clients/wroom.d.ts.map +1 -0
  81. package/dist/clients/wroom.js +99 -122
  82. package/dist/clients/wroom.js.map +1 -1
  83. package/dist/index.cjs +13 -15
  84. package/dist/index.d.cts +8 -0
  85. package/dist/index.d.ts +8 -7
  86. package/dist/index.js +5 -14
  87. package/dist/managers/repositories.cjs +159 -169
  88. package/dist/managers/repositories.cjs.map +1 -1
  89. package/dist/managers/repositories.d.cts +67 -0
  90. package/dist/managers/repositories.d.cts.map +1 -0
  91. package/dist/managers/repositories.d.ts +56 -63
  92. package/dist/managers/repositories.d.ts.map +1 -0
  93. package/dist/managers/repositories.js +148 -159
  94. package/dist/managers/repositories.js.map +1 -1
  95. package/dist/managers/repository.cjs +591 -616
  96. package/dist/managers/repository.cjs.map +1 -1
  97. package/dist/managers/repository.d.cts +338 -0
  98. package/dist/managers/repository.d.cts.map +1 -0
  99. package/dist/managers/repository.d.ts +333 -307
  100. package/dist/managers/repository.d.ts.map +1 -0
  101. package/dist/managers/repository.js +591 -616
  102. package/dist/managers/repository.js.map +1 -1
  103. package/dist/types.d.cts +41 -0
  104. package/dist/types.d.cts.map +1 -0
  105. package/dist/types.d.ts +35 -37
  106. package/dist/types.d.ts.map +1 -0
  107. package/dist/utils/cookies.cjs +19 -17
  108. package/dist/utils/cookies.cjs.map +1 -1
  109. package/dist/utils/cookies.js +20 -18
  110. package/dist/utils/cookies.js.map +1 -1
  111. package/dist/utils/envVariableManager.cjs +33 -34
  112. package/dist/utils/envVariableManager.cjs.map +1 -1
  113. package/dist/utils/envVariableManager.js +34 -35
  114. package/dist/utils/envVariableManager.js.map +1 -1
  115. package/dist/utils/log.cjs +18 -19
  116. package/dist/utils/log.cjs.map +1 -1
  117. package/dist/utils/log.js +18 -21
  118. package/dist/utils/log.js.map +1 -1
  119. package/dist/utils/random.cjs +13 -6
  120. package/dist/utils/random.cjs.map +1 -1
  121. package/dist/utils/random.js +13 -6
  122. package/dist/utils/random.js.map +1 -1
  123. package/dist/utils/strings.cjs +13 -7
  124. package/dist/utils/strings.cjs.map +1 -1
  125. package/dist/utils/strings.js +14 -8
  126. package/dist/utils/strings.js.map +1 -1
  127. package/dist/utils/urls.cjs +21 -10
  128. package/dist/utils/urls.cjs.map +1 -1
  129. package/dist/utils/urls.js +22 -12
  130. package/dist/utils/urls.js.map +1 -1
  131. package/package.json +42 -67
  132. package/src/clients/apiClient.ts +16 -21
  133. package/src/clients/assetApi.ts +75 -82
  134. package/src/clients/authenticationApi.ts +54 -27
  135. package/src/clients/contentApi.ts +111 -129
  136. package/src/clients/coreApi.ts +165 -117
  137. package/src/clients/customTypesApi.ts +54 -74
  138. package/src/clients/integrationFields.ts +59 -74
  139. package/src/clients/manageV2.ts +72 -96
  140. package/src/clients/migrationApi.ts +35 -39
  141. package/src/clients/wroom.ts +42 -56
  142. package/src/index.ts +7 -7
  143. package/src/managers/repositories.ts +85 -108
  144. package/src/managers/repository.ts +393 -368
  145. package/src/types.ts +31 -31
  146. package/src/utils/cookies.ts +8 -8
  147. package/src/utils/envVariableManager.ts +15 -15
  148. package/src/utils/log.ts +17 -21
  149. package/src/utils/random.ts +5 -6
  150. package/src/utils/strings.ts +7 -9
  151. package/src/utils/urls.ts +10 -12
  152. package/dist/index.cjs.map +0 -1
  153. package/dist/index.js.map +0 -1
  154. package/dist/utils/cookies.d.ts +0 -8
  155. package/dist/utils/envVariableManager.d.ts +0 -16
  156. package/dist/utils/log.d.ts +0 -5
  157. package/dist/utils/random.d.ts +0 -8
  158. package/dist/utils/strings.d.ts +0 -11
  159. package/dist/utils/urls.d.ts +0 -16
@@ -1,32 +1,28 @@
1
- import { expect } from "@playwright/test";
2
- import { AxiosResponse } from "axios";
3
-
4
- import {
5
- CustomType,
6
- SharedSlice,
7
- } from "@prismicio/types-internal/lib/customtypes";
8
-
9
- import { IntegrationFieldConfig } from "../types";
10
-
11
- import { AssetApiClient } from "../clients/assetApi";
12
- import { AuthenticationApiClient } from "../clients/authenticationApi";
13
- import { ContentApiClient } from "../clients/contentApi";
14
- import {
1
+ import { expect } from "@playwright/test"
2
+ import type { DynamicCustomTypeModel, SharedSliceModel } from "@prismicio/types-internal"
3
+ import type { AxiosResponse } from "axios"
4
+
5
+ import type { AssetApiClient } from "../clients/assetApi"
6
+ import type { AuthenticationApiClient } from "../clients/authenticationApi"
7
+ import { ContentApiClient } from "../clients/contentApi"
8
+ import type {
15
9
  CoreApiClient,
16
10
  CoreApiDocumentCreationPayload,
17
11
  CoreApiDocumentCreationResponse,
18
12
  CoreApiDocumentData,
19
13
  CoreApiDocumentsPayload,
20
14
  CoreApiDocumentsResponse,
15
+ CoreApiDocumentUpdatePayload,
21
16
  Release,
22
- } from "../clients/coreApi";
23
- import { CustomTypesApiClient } from "../clients/customTypesApi";
24
- import { IntegrationFieldsClient } from "../clients/integrationFields";
25
- import { ManageV2Client } from "../clients/manageV2";
26
- import { MigrationApiClient } from "../clients/migrationApi";
27
- import { WroomClient } from "../clients/wroom";
28
- import { logHttpResponse, logger } from "../utils/log";
29
- import { getRepositoryUrl } from "../utils/urls";
17
+ } from "../clients/coreApi"
18
+ import type { CustomTypesApiClient } from "../clients/customTypesApi"
19
+ import type { IntegrationFieldsClient } from "../clients/integrationFields"
20
+ import type { ManageV2Client } from "../clients/manageV2"
21
+ import type { MigrationApiClient } from "../clients/migrationApi"
22
+ import type { WroomClient } from "../clients/wroom"
23
+ import type { IntegrationFieldConfig } from "../types"
24
+ import { logHttpResponse, logger } from "../utils/log"
25
+ import { getRepositoryUrl } from "../utils/urls"
30
26
 
31
27
  /** Utility to manage test data for a Prismic repository */
32
28
  export class RepositoryManager {
@@ -39,25 +35,22 @@ export class RepositoryManager {
39
35
  private readonly migrationApiClient: MigrationApiClient | undefined,
40
36
  private readonly assetApiClient: AssetApiClient,
41
37
  private readonly manageV2Client: ManageV2Client,
42
- private readonly integrationFieldsClient:
43
- | IntegrationFieldsClient
44
- | undefined,
38
+ private readonly integrationFieldsClient: IntegrationFieldsClient | undefined,
45
39
  ) {}
46
40
 
47
41
  async configure(config: RepositoryConfig): Promise<void> {
48
- const hasLangConfig =
49
- config.defaultLocale || config.locales || config.customLocale;
42
+ const hasLangConfig = config.defaultLocale || config.locales || config.customLocale
50
43
  if (hasLangConfig) {
51
- const languages = await this.coreApiClient.getLanguages();
52
- let updateDefaultLocaleAtTheEnd = false;
44
+ const languages = await this.coreApiClient.getLanguages()
45
+ let updateDefaultLocaleAtTheEnd = false
53
46
  // if no locale exists on repo, the master locale needs to be set first
54
47
  if (config.defaultLocale) {
55
- const master = languages.find(({ is_master }) => is_master === true);
48
+ const master = languages.find(({ is_master }) => is_master === true)
56
49
  if (!master) {
57
- await this.setDefaultLocale(config.defaultLocale, "create");
50
+ await this.setDefaultLocale(config.defaultLocale, "create")
58
51
  } else if (master.id !== config.defaultLocale) {
59
52
  // update the master lang at the end, after it is created.
60
- updateDefaultLocaleAtTheEnd = true;
53
+ updateDefaultLocaleAtTheEnd = true
61
54
  }
62
55
  }
63
56
 
@@ -65,258 +58,238 @@ export class RepositoryManager {
65
58
  // No need to add default locale and already existing languages
66
59
  const localesToAdd = config.locales.filter(
67
60
  (id) => !languages.some((language) => language.id === id),
68
- );
61
+ )
69
62
  if (localesToAdd.length > 0) {
70
- await this.createLocales(localesToAdd);
63
+ await this.createLocales(localesToAdd)
71
64
  }
72
65
  }
73
66
 
74
67
  if (config.customLocale) {
75
68
  if (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {
76
- await this.createCustomLocale(config.customLocale);
69
+ await this.createCustomLocale(config.customLocale)
77
70
  }
78
71
  }
79
72
 
80
73
  if (config.defaultLocale && updateDefaultLocaleAtTheEnd) {
81
- await this.setDefaultLocale(config.defaultLocale, "update");
74
+ await this.setDefaultLocale(config.defaultLocale, "update")
82
75
  }
83
76
  }
84
77
 
85
78
  if (config.slices) {
86
- await this.createSlices(config.slices);
79
+ await this.createSlices(config.slices)
87
80
  }
88
81
 
89
82
  if (config.customTypes) {
90
- await this.createCustomTypes(config.customTypes);
83
+ await this.createCustomTypes(config.customTypes)
91
84
  }
92
85
 
93
86
  if (config.preview) {
94
- await this.createPreview(config.preview);
87
+ await this.createPreview(config.preview)
95
88
  }
96
89
 
97
90
  if (config.simulatorURL) {
98
- await this.setSimulatorURL(config.simulatorURL);
91
+ await this.setSimulatorURL(config.simulatorURL)
99
92
  }
100
93
 
101
94
  if (config.rolePerLocal) {
102
- await this.toggleRolePerLocal(true);
95
+ await this.toggleRolePerLocal(true)
103
96
  }
104
97
 
105
98
  if (config.customRoles) {
106
- await this.toggleCustomRoles(true);
99
+ await this.toggleCustomRoles(true)
107
100
  }
108
101
 
109
102
  if (config.integrationFields) {
110
- await this.toggleIntegrationFields(true);
111
- await this.setupIntegrationFields(config.integrationFields);
103
+ await this.toggleIntegrationFields(true)
104
+ await this.setupIntegrationFields(config.integrationFields)
112
105
  }
113
106
  }
114
107
 
115
- /** @returns the repository base url, like https://my-repo.prismic.io */
108
+ /** @returns The repository base url, like https://my-repo.prismic.io */
116
109
  getBaseURL(): string {
117
- return getRepositoryUrl(this.wroomClient.getBaseURL(), this.name);
110
+ return getRepositoryUrl(this.wroomClient.getBaseURL(), this.name)
118
111
  }
119
112
 
120
- /** @returns the repository base cdn url, like https://my-repo.cdn.prismic.io */
113
+ /** @returns The repository base cdn url, like https://my-repo.cdn.prismic.io */
121
114
  getBaseCdnURL(): string {
122
- return getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`);
115
+ return getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`)
123
116
  }
124
117
 
125
118
  /**
126
- * @returns a Content Type api client configured to target the repository CDN
127
- * url. Uses Playwright for requests so if your project uses Playwright too,
128
- * any network request will be present in Playwright test reports.
119
+ * @returns A Content Type api client configured to target the repository CDN url. Uses Playwright
120
+ * for requests so if your project uses Playwright too, any network request will be present in
121
+ * Playwright test reports.
129
122
  */
130
- getContentApiClient(config?: {
131
- version?: "v1" | "v2";
132
- accessToken?: string;
133
- }): ContentApiClient {
134
- return new ContentApiClient(this.getBaseCdnURL(), config);
123
+ getContentApiClient(config?: { version?: "v1" | "v2"; accessToken?: string }): ContentApiClient {
124
+ return new ContentApiClient(this.getBaseCdnURL(), config)
135
125
  }
136
126
 
137
127
  /**
138
- * @returns an instance of the Migration api client, see
128
+ * @returns An instance of the Migration api client, see
139
129
  * https://prismic.io/docs/migration-api-technical-reference
140
130
  */
141
131
  getMigrationApiClient(): MigrationApiClient {
142
132
  if (!this.migrationApiClient) {
143
- throw "No client found for the migration api. Did you provide a migration api url in the configuration?";
133
+ throw "No client found for the migration api. Did you provide a migration api url in the configuration?"
144
134
  }
145
135
 
146
- return this.migrationApiClient;
136
+ return this.migrationApiClient
147
137
  }
148
138
 
149
139
  /**
150
- * @returns an instance of the Asset api client, see
140
+ * @returns An instance of the Asset api client, see
151
141
  * https://prismic.io/docs/asset-api-technical-reference
152
142
  */
153
143
  getAssetApiClient(): AssetApiClient {
154
- return this.assetApiClient;
144
+ return this.assetApiClient
155
145
  }
156
146
 
157
- /** @returns the Wroom commit hash deployed on the current repository */
147
+ /** @returns The Wroom commit hash deployed on the current repository */
158
148
  async getDeployedVersion(): Promise<string | undefined> {
159
149
  const response = await this.wroomClient.get(
160
150
  this.name,
161
151
  "underground/834b34f16f451e00f268dd5c8c81d16e3c020275",
162
- );
152
+ )
163
153
 
164
154
  // Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute
165
- return response.data.version;
155
+ return response.data.version
166
156
  }
167
157
 
168
158
  /**
169
- * Set additional standard locales for a repository in Wroom, does not fail if
170
- * the locales already exist.
159
+ * Set additional standard locales for a repository in Wroom, does not fail if the locales already
160
+ * exist.
171
161
  *
172
162
  * @param locales - An array of all locales to be added to the repository.
173
- *
174
163
  * @throws Error if setting the locales fails.
175
164
  */
176
165
  async createLocales(locales: string[]): Promise<void> {
177
- const profiler = logger.startTimer();
166
+ const profiler = logger.startTimer()
178
167
 
179
- const response = await this.wroomClient.post(
180
- this.name,
181
- "app/settings/multilanguages",
182
- { languages: locales },
183
- );
168
+ const response = await this.wroomClient.post(this.name, "app/settings/multilanguages", {
169
+ languages: locales,
170
+ })
184
171
 
185
- const { data, status } = response;
172
+ const { data, status } = response
186
173
  const success =
187
- status === 200 ||
188
- (status === 400 &&
189
- (data as string).includes("already existing languages"));
174
+ status === 200 || (status === 400 && (data as string).includes("already existing languages"))
190
175
  if (!success) {
191
- logHttpResponse(response);
192
- throw new Error(`Could not add locales ${locales.join(", ")}`);
176
+ logHttpResponse(response)
177
+ throw new Error(`Could not add locales ${locales.join(", ")}`)
193
178
  }
194
- profiler.done({ message: `locales '${locales}' created` });
179
+ profiler.done({ message: `locales '${locales}' created` })
195
180
  }
196
181
 
197
182
  /**
198
- * Set additional custom locale for a repository in Wroom, does not fail if
199
- * the locales already exist.
183
+ * Set additional custom locale for a repository in Wroom, does not fail if the locales already
184
+ * exist.
200
185
  *
201
186
  * @param locale - The locale to be added to the repository.
202
- *
203
187
  * @throws Error if setting the locale fails.
204
188
  */
205
189
  async createCustomLocale(locale: CustomLocale): Promise<void> {
206
- const profiler = logger.startTimer();
190
+ const profiler = logger.startTimer()
207
191
 
208
192
  const response = await this.wroomClient.post(
209
193
  this.name,
210
194
  "app/settings/multilanguages/custom",
211
195
  locale,
212
- );
196
+ )
213
197
 
214
- const { data, status } = response;
198
+ const { data, status } = response
215
199
  const success =
216
- status === 200 ||
217
- (status === 400 && JSON.stringify(data).includes("code is already used"));
200
+ status === 200 || (status === 400 && JSON.stringify(data).includes("code is already used"))
218
201
  if (!success) {
219
- logHttpResponse(response);
220
- throw new Error(`Could not create custom locale ${locale}`);
202
+ logHttpResponse(response)
203
+ throw new Error(`Could not create custom locale ${locale}`)
221
204
  }
222
205
  profiler.done({
223
206
  message: `custom locale ${JSON.stringify(locale)} created`,
224
- });
207
+ })
225
208
  }
226
209
 
227
210
  private failIfNot200(response: AxiosResponse, msg: string) {
228
211
  if (response.status !== 200) {
229
- logHttpResponse(response);
230
- throw new Error(msg);
212
+ logHttpResponse(response)
213
+ throw new Error(msg)
231
214
  }
232
215
  }
233
216
 
234
217
  /**
235
218
  * Delete a locale from a repository.
236
219
  *
237
- * @param locale - locale to remove from the repository configuration.
238
- *
220
+ * @param locale - Locale to remove from the repository configuration.
239
221
  * @throws Error if deleting the locale fails.
240
222
  */
241
223
  async deleteLocale(locale: string): Promise<void> {
242
- const profiler = logger.startTimer();
224
+ const profiler = logger.startTimer()
243
225
 
244
226
  const response = await this.wroomClient.post(
245
227
  this.name,
246
228
  `app/settings/multilanguages/${locale}/delete`,
247
- );
248
- this.failIfNot200(response, `Could not delete locale ${locale}`);
249
- profiler.done({ message: `locale '${locale}' deleted` });
229
+ )
230
+ this.failIfNot200(response, `Could not delete locale ${locale}`)
231
+ profiler.done({ message: `locale '${locale}' deleted` })
250
232
  }
251
233
 
252
234
  /**
253
- * Create or update the default (master) locale for a repository in Wroom, the
254
- * locale needs to exist in the repository.
235
+ * Create or update the default (master) locale for a repository in Wroom, the locale needs to
236
+ * exist in the repository.
255
237
  *
256
238
  * @param locale - The locale to be set as the default.
257
- * @param endpoint - "createMasterLang" to create it, "defineAsMaster" to
258
- * update it.
259
- *
239
+ * @param endpoint - "createMasterLang" to create it, "defineAsMaster" to update it.
260
240
  * @throws Error if setting the default locale fails.
261
241
  */
262
- async setDefaultLocale(
263
- locale: string,
264
- action: "create" | "update",
265
- ): Promise<void> {
266
- const profiler = logger.startTimer();
242
+ async setDefaultLocale(locale: string, action: "create" | "update"): Promise<void> {
243
+ const profiler = logger.startTimer()
267
244
 
268
245
  const endpoint = {
269
246
  create: "createMasterLang",
270
247
  update: "defineAsMaster",
271
- };
248
+ }
272
249
  const response = await this.wroomClient.post(
273
250
  this.name,
274
251
  `/app/settings/multilanguages/${locale}/${endpoint[action]}`,
275
- );
252
+ )
276
253
 
277
- const { data, status } = response;
254
+ const { data, status } = response
278
255
  const success =
279
256
  status === 200 ||
280
257
  (status === 400 &&
281
258
  // returns 400 if master lang is already set
282
- JSON.stringify(data).includes("Unable to set as master language"));
259
+ JSON.stringify(data).includes("Unable to set as master language"))
283
260
  if (!success) {
284
- logHttpResponse(response);
285
- throw new Error(`Could not set default locale to ${locale}`);
261
+ logHttpResponse(response)
262
+ throw new Error(`Could not set default locale to ${locale}`)
286
263
  }
287
- profiler.done({ message: `default locale set to '${locale}'` });
264
+ profiler.done({ message: `default locale set to '${locale}'` })
288
265
  }
289
266
 
290
267
  /**
291
268
  * Retrieves documents.
292
269
  *
293
270
  * @param args - Configure which documents are retrieved.
294
- *
295
271
  * @returns A paginated set of documents.
296
272
  */
297
- async getDocuments(
298
- args: CoreApiDocumentsPayload,
299
- ): Promise<CoreApiDocumentsResponse> {
300
- return this.coreApiClient.getDocuments(args);
273
+ async getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse> {
274
+ return this.coreApiClient.getDocuments(args)
301
275
  }
302
276
 
303
277
  /**
304
278
  * Creates a release.
305
279
  *
306
280
  * @param label - The label for the release.
307
- *
308
281
  * @returns A Promise that resolves when the release is created.
309
282
  */
310
283
  async createRelease(label: string): Promise<{ id: string }> {
311
- const profiler = logger.startTimer();
284
+ const profiler = logger.startTimer()
312
285
 
313
286
  const response = await this.wroomClient.post(this.name, "app/releases", {
314
287
  label,
315
- });
316
- this.failIfNot200(response, `Could not create release ${label}`);
317
- profiler.done({ message: `release '${label}' created` });
288
+ })
289
+ this.failIfNot200(response, `Could not create release ${label}`)
290
+ profiler.done({ message: `release '${label}' created` })
318
291
 
319
- return response.data;
292
+ return response.data
320
293
  }
321
294
 
322
295
  /**
@@ -325,39 +298,38 @@ export class RepositoryManager {
325
298
  * @returns The migration relese metadata.
326
299
  */
327
300
  async getMigrationRelease(): Promise<Release> {
328
- const releases = await this.coreApiClient.getReleases();
329
- const migrationRelease = releases.find((release) => release.migration);
301
+ const releases = await this.coreApiClient.getReleases()
302
+ const migrationRelease = releases.find((release) => release.migration)
330
303
  if (!migrationRelease) {
331
- throw new Error(`The repository does not have a migration release`);
304
+ throw new Error(`The repository does not have a migration release`)
332
305
  }
333
306
 
334
- return migrationRelease;
307
+ return migrationRelease
335
308
  }
336
309
 
337
310
  /**
338
311
  * Publishes a release.
339
312
  *
340
313
  * @param id - The ID of the release.
341
- *
342
- * @returns A Promise that resolves when the release is published and a new
343
- * master ref is available.
314
+ * @returns A Promise that resolves when the release is published and a new master ref is
315
+ * available.
344
316
  */
345
317
  async publishRelease(id: string): Promise<void> {
346
- const profiler = logger.startTimer();
318
+ const profiler = logger.startTimer()
347
319
 
348
- const contentApi = this.getContentApiClient();
349
- const masterRef = await contentApi.getMasterRef();
350
- await this.coreApiClient.publishRelease(id);
320
+ const contentApi = this.getContentApiClient()
321
+ const masterRef = await contentApi.getMasterRef()
322
+ await this.coreApiClient.publishRelease(id)
351
323
  await expect
352
324
  .poll(async () => contentApi.getMasterRef(), {
353
325
  timeout: 10_000,
354
326
  message: "Waiting for new master ref to be available",
355
327
  })
356
- .not.toBe(masterRef);
328
+ .not.toBe(masterRef)
357
329
 
358
330
  profiler.done({
359
331
  message: `release '${id}' published and new master ref available`,
360
- });
332
+ })
361
333
  }
362
334
 
363
335
  /**
@@ -366,16 +338,12 @@ export class RepositoryManager {
366
338
  * @param id - The ID of the release to be deleted.
367
339
  */
368
340
  async deleteRelease(id: string): Promise<void> {
369
- const profiler = logger.startTimer();
341
+ const profiler = logger.startTimer()
370
342
 
371
- const response = await this.wroomClient.post(
372
- this.name,
373
- `app/releases/${id}/delete`,
374
- {},
375
- );
343
+ const response = await this.wroomClient.post(this.name, `app/releases/${id}/delete`, {})
376
344
 
377
- this.failIfNot200(response, `Could not delete release with id ${id}`);
378
- profiler.done({ message: `release '${id}' deleted` });
345
+ this.failIfNot200(response, `Could not delete release with id ${id}`)
346
+ profiler.done({ message: `release '${id}' deleted` })
379
347
  }
380
348
 
381
349
  /**
@@ -384,18 +352,14 @@ export class RepositoryManager {
384
352
  * @param data - The data for creating the preview.
385
353
  */
386
354
  async createPreview(data: Preview): Promise<void> {
387
- const profiler = logger.startTimer();
355
+ const profiler = logger.startTimer()
388
356
 
389
- const response = await this.wroomClient.post(
390
- this.name,
391
- `previews/new`,
392
- data,
393
- );
357
+ const response = await this.wroomClient.post(this.name, `previews/new`, data)
394
358
 
395
- this.failIfNot200(response, `Could not create preview ${data.name}`);
396
- profiler.done({ message: `preview '${data.name}' created` });
359
+ this.failIfNot200(response, `Could not create preview ${data.name}`)
360
+ profiler.done({ message: `preview '${data.name}' created` })
397
361
 
398
- return response.data;
362
+ return response.data
399
363
  }
400
364
 
401
365
  /**
@@ -404,17 +368,17 @@ export class RepositoryManager {
404
368
  * @param data - The simulator URL to set.
405
369
  */
406
370
  async setSimulatorURL(simulatorURL: string): Promise<void> {
407
- const profiler = logger.startTimer();
371
+ const profiler = logger.startTimer()
408
372
 
409
- const repository = await this.coreApiClient.getRepository();
373
+ const repository = await this.coreApiClient.getRepository()
410
374
  await this.coreApiClient.updateRepository({
411
375
  ...repository,
412
376
  simulator_url: simulatorURL,
413
- });
377
+ })
414
378
 
415
379
  profiler.done({
416
380
  message: `simulator preview '${simulatorURL}' created`,
417
- });
381
+ })
418
382
  }
419
383
 
420
384
  /**
@@ -423,16 +387,12 @@ export class RepositoryManager {
423
387
  * @param id - The ID of the preview to be deleted.
424
388
  */
425
389
  async deletePreview(id: string): Promise<void> {
426
- const profiler = logger.startTimer();
390
+ const profiler = logger.startTimer()
427
391
 
428
- const response = await this.wroomClient.post(
429
- this.name,
430
- `previews/delete/${id}`,
431
- {},
432
- );
392
+ const response = await this.wroomClient.post(this.name, `previews/delete/${id}`, {})
433
393
 
434
- this.failIfNot200(response, `Could not delete preview with id ${id}`);
435
- profiler.done({ message: `preview '${id}' deleted` });
394
+ this.failIfNot200(response, `Could not delete preview with id ${id}`)
395
+ profiler.done({ message: `preview '${id}' deleted` })
436
396
  }
437
397
 
438
398
  /**
@@ -445,32 +405,28 @@ export class RepositoryManager {
445
405
  url: string,
446
406
  secret: string,
447
407
  triggers: {
448
- documentsPublished?: boolean;
449
- documentsUnpublished?: boolean;
450
- releasesCreated?: boolean;
451
- releasesUpdated?: boolean;
452
- tagsCreated?: boolean;
453
- tagsDeleted?: boolean;
408
+ documentsPublished?: boolean
409
+ documentsUnpublished?: boolean
410
+ releasesCreated?: boolean
411
+ releasesUpdated?: boolean
412
+ tagsCreated?: boolean
413
+ tagsDeleted?: boolean
454
414
  },
455
415
  active: boolean,
456
416
  ): Promise<string> {
457
- const profiler = logger.startTimer();
417
+ const profiler = logger.startTimer()
458
418
 
459
- const response = await this.wroomClient.post(
460
- this.name,
461
- "app/settings/webhooks/create",
462
- {
463
- name,
464
- url,
465
- secret,
466
- active: active ? "on" : "off",
467
- ...triggers,
468
- },
469
- );
470
- this.failIfNot200(response, `Could not create webhook ${name}`);
471
- profiler.done({ message: `webhook '${name}' created` });
419
+ const response = await this.wroomClient.post(this.name, "app/settings/webhooks/create", {
420
+ name,
421
+ url,
422
+ secret,
423
+ active: active ? "on" : "off",
424
+ ...triggers,
425
+ })
426
+ this.failIfNot200(response, `Could not create webhook ${name}`)
427
+ profiler.done({ message: `webhook '${name}' created` })
472
428
 
473
- return response.data.created;
429
+ return response.data.created
474
430
  }
475
431
 
476
432
  /**
@@ -479,120 +435,118 @@ export class RepositoryManager {
479
435
  * @param id - The webhook ID.
480
436
  */
481
437
  async deleteWebhook(id: string): Promise<void> {
482
- const profiler = logger.startTimer();
438
+ const profiler = logger.startTimer()
483
439
 
484
440
  const response = await this.wroomClient.post(
485
441
  this.name,
486
442
  `app/settings/webhooks/${id}/delete`,
487
443
  {},
488
- );
444
+ )
489
445
 
490
- this.failIfNot200(response, `Could not delete webhook with id ${id}`);
491
- profiler.done({ message: `webhook '${id}' deleted` });
446
+ this.failIfNot200(response, `Could not delete webhook with id ${id}`)
447
+ profiler.done({ message: `webhook '${id}' deleted` })
492
448
  }
493
449
 
494
450
  /**
495
451
  * Create Custom Types using the Custom types api.
496
452
  *
497
- * @param customTypes -
453
+ * @param customTypes
498
454
  */
499
- async createCustomTypes(customTypes: CustomType[]): Promise<void> {
500
- await this.customTypesApiClient.createCustomTypes(customTypes);
455
+ async createCustomTypes(customTypes: DynamicCustomTypeModel[]): Promise<void> {
456
+ await this.customTypesApiClient.createCustomTypes(customTypes)
501
457
  }
502
458
 
503
459
  async deleteCustomType(customTypeId: string): Promise<void> {
504
- await this.customTypesApiClient.deleteCustomType(customTypeId);
460
+ await this.customTypesApiClient.deleteCustomType(customTypeId)
505
461
  }
506
462
 
507
463
  /**
508
464
  * Create slices using the Custom types api.
509
465
  *
510
- * @param slices -
466
+ * @param slices
511
467
  */
512
- async createSlices(slices: SharedSlice[]): Promise<void> {
513
- await this.customTypesApiClient.createSlices(slices);
468
+ async createSlices(slices: SharedSliceModel[]): Promise<void> {
469
+ await this.customTypesApiClient.createSlices(slices)
514
470
  }
515
471
 
516
472
  /**
517
473
  * Create an access token to query private items of the Content api.
518
474
  *
519
- * @param appName - mandatory authorized application name
520
- * @param tokenScope - access token scope. Use "master" to when your content
521
- * api is fully private or "master+releases" to access private releases
475
+ * @param appName - Mandatory authorized application name
476
+ * @param tokenScope - Access token scope. Use "master" to when your content api is fully private
477
+ * or "master+releases" to access private releases
522
478
  */
523
479
  async createContentAPIToken(
524
480
  appName: string,
525
481
  tokenScope: "master" | "master+releases" = "master",
526
482
  ): Promise<string> {
527
- const profiler = logger.startTimer();
483
+ const profiler = logger.startTimer()
528
484
  type AuthorizedAppResponse = {
529
- id: string;
530
- name: string;
531
- wroom_auths: { token: string; scope: "master" | "master+releases" }[];
532
- };
533
- const existingApps: AxiosResponse<AuthorizedAppResponse[]> =
534
- await this.wroomClient.get(this.name, "settings/security/contentapi");
485
+ id: string
486
+ name: string
487
+ wroom_auths: { token: string; scope: "master" | "master+releases" }[]
488
+ }
489
+ const existingApps: AxiosResponse<AuthorizedAppResponse[]> = await this.wroomClient.get(
490
+ this.name,
491
+ "settings/security/contentapi",
492
+ )
535
493
 
536
494
  this.failIfNot200(
537
495
  existingApps,
538
496
  `Could not get status of existing applications to generate a content api token`,
539
- );
497
+ )
540
498
  let app = existingApps.data.find(({ name, wroom_auths }) => {
541
- return name === appName && wroom_auths.length > 0;
542
- });
499
+ return name === appName && wroom_auths.length > 0
500
+ })
543
501
 
544
502
  if (!app) {
545
- const response: AxiosResponse<AuthorizedAppResponse> =
546
- await this.wroomClient.post(this.name, "settings/security/oauthapp", {
503
+ const response: AxiosResponse<AuthorizedAppResponse> = await this.wroomClient.post(
504
+ this.name,
505
+ "settings/security/oauthapp",
506
+ {
547
507
  app_name: appName,
548
- });
508
+ },
509
+ )
549
510
 
550
- this.failIfNot200(
551
- response,
552
- `Could not create content api app ${appName}`,
553
- );
554
- app = response.data;
511
+ this.failIfNot200(response, `Could not create content api app ${appName}`)
512
+ app = response.data
555
513
  }
556
514
 
557
- let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope);
515
+ let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope)
558
516
  if (!tokenInfo) {
559
- const response = await this.wroomClient.post(
560
- this.name,
561
- "settings/security/authorizations",
562
- {
563
- app: app.id,
564
- scope: tokenScope,
565
- },
566
- );
517
+ const response = await this.wroomClient.post(this.name, "settings/security/authorizations", {
518
+ app: app.id,
519
+ scope: tokenScope,
520
+ })
567
521
  this.failIfNot200(
568
522
  response,
569
523
  `Could not create content api access token for app ${appName} with scope ${tokenScope}`,
570
- );
571
- tokenInfo = response.data;
524
+ )
525
+ tokenInfo = response.data
572
526
  }
573
527
 
574
528
  profiler.done({
575
529
  message: `content api access token for app '${appName}' created`,
576
- });
530
+ })
577
531
 
578
532
  if (!tokenInfo?.token) {
579
- throw `Could not create content api access token for app ${appName} with scope ${tokenScope}`;
533
+ throw `Could not create content api access token for app ${appName} with scope ${tokenScope}`
580
534
  }
581
535
 
582
- return tokenInfo.token;
536
+ return tokenInfo.token
583
537
  }
584
538
 
585
539
  /** Create a permanent access token to authenticate to Prismic public apis. */
586
540
  async createPermanentAccessToken(): Promise<string> {
587
- const profiler = logger.startTimer();
541
+ const profiler = logger.startTimer()
588
542
 
589
- const token = await this.authApiClient.getMachine2MachineToken(this.name);
543
+ const token = await this.authApiClient.getMachine2MachineToken(this.name)
590
544
 
591
545
  profiler.done({
592
546
  message: `machine2machine token created`,
593
- });
547
+ })
594
548
 
595
- return token;
549
+ return token
596
550
  }
597
551
 
598
552
  /**
@@ -601,22 +555,20 @@ export class RepositoryManager {
601
555
  * @param enabled - The feature new status
602
556
  */
603
557
  async toggleRolePerLocal(enabled: boolean): Promise<void> {
604
- const profiler = logger.startTimer();
558
+ const profiler = logger.startTimer()
605
559
 
606
560
  const response = await this.manageV2Client.toggleRolePerLocal({
607
561
  repository: this.name,
608
562
  enabled: enabled,
609
- });
563
+ })
610
564
 
611
565
  this.failIfNot200(
612
566
  response,
613
- `Could not ${enabled ? "enable" : "disable"} Role per local for ${
614
- this.name
615
- }`,
616
- );
567
+ `Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`,
568
+ )
617
569
  profiler.done({
618
570
  message: `Role per local ${enabled ? "enabled" : "disabled"}`,
619
- });
571
+ })
620
572
  }
621
573
 
622
574
  /**
@@ -625,22 +577,20 @@ export class RepositoryManager {
625
577
  * @param enabled - The feature new status
626
578
  */
627
579
  async toggleCustomRoles(enabled: boolean): Promise<void> {
628
- const profiler = logger.startTimer();
580
+ const profiler = logger.startTimer()
629
581
 
630
582
  const response = await this.manageV2Client.toggleCustomRoles({
631
583
  repository: this.name,
632
584
  enabled: enabled,
633
- });
585
+ })
634
586
 
635
587
  this.failIfNot200(
636
588
  response,
637
- `Could not ${enabled ? "enable" : "disable"} Custom Roles for ${
638
- this.name
639
- }`,
640
- );
589
+ `Could not ${enabled ? "enable" : "disable"} Custom Roles for ${this.name}`,
590
+ )
641
591
  profiler.done({
642
592
  message: `Custom Roles ${enabled ? "enabled" : "disabled"}`,
643
- });
593
+ })
644
594
  }
645
595
 
646
596
  /**
@@ -649,22 +599,20 @@ export class RepositoryManager {
649
599
  * @param enabled - The feature new status
650
600
  */
651
601
  async toggleIntegrationFields(enabled: boolean): Promise<void> {
652
- const profiler = logger.startTimer();
602
+ const profiler = logger.startTimer()
653
603
 
654
604
  const response = await this.manageV2Client.toggleIntegrationFields({
655
605
  repository: this.name,
656
606
  enabled: enabled,
657
- });
607
+ })
658
608
 
659
609
  this.failIfNot200(
660
610
  response,
661
- `Could not ${enabled ? "enable" : "disable"} Integration Fields for ${
662
- this.name
663
- }`,
664
- );
611
+ `Could not ${enabled ? "enable" : "disable"} Integration Fields for ${this.name}`,
612
+ )
665
613
  profiler.done({
666
614
  message: `Integration Fields ${enabled ? "enabled" : "disabled"}`,
667
- });
615
+ })
668
616
  }
669
617
 
670
618
  /**
@@ -673,18 +621,18 @@ export class RepositoryManager {
673
621
  * @param {string} newPlanId - The Id of the new Plan to apply
674
622
  */
675
623
  async changePlan(newPlanId: string): Promise<void> {
676
- const profiler = logger.startTimer();
624
+ const profiler = logger.startTimer()
677
625
 
678
626
  const response = await this.manageV2Client.changePlan({
679
627
  repository: this.name,
680
628
  newPlanId: newPlanId,
681
629
  bypassManualBilling: true, // For now the library does not support Stripe features
682
- });
630
+ })
683
631
 
684
- this.failIfNot200(response, "Could not change the Repository Plan");
632
+ this.failIfNot200(response, "Could not change the Repository Plan")
685
633
  profiler.done({
686
634
  message: `Repository Plan changed to ${newPlanId}`,
687
- });
635
+ })
688
636
  }
689
637
 
690
638
  /**
@@ -693,25 +641,24 @@ export class RepositoryManager {
693
641
  * @param {string} email - The email of the user
694
642
  */
695
643
  async addUser(email: string): Promise<void> {
696
- const profiler = logger.startTimer();
644
+ const profiler = logger.startTimer()
697
645
 
698
646
  const response = await this.manageV2Client.addUserToRepository({
699
647
  repository: this.name,
700
648
  email: email,
701
- });
649
+ })
702
650
 
703
- const { data, status } = response;
651
+ const { data, status } = response
704
652
  const success =
705
653
  status === 200 ||
706
- (status === 409 &&
707
- JSON.stringify(data).includes("already a member of the repo"));
654
+ (status === 409 && JSON.stringify(data).includes("already a member of the repo"))
708
655
  if (!success) {
709
- logHttpResponse(response);
710
- throw new Error(`Could not add a new user ${email} to the repository`);
656
+ logHttpResponse(response)
657
+ throw new Error(`Could not add a new user ${email} to the repository`)
711
658
  }
712
659
  profiler.done({
713
660
  message: `User ${email} was added to the repository`,
714
- });
661
+ })
715
662
  }
716
663
 
717
664
  /**
@@ -720,29 +667,25 @@ export class RepositoryManager {
720
667
  * @param {string} email - The email of the user
721
668
  */
722
669
  async removeUser(email: string): Promise<void> {
723
- const profiler = logger.startTimer();
670
+ const profiler = logger.startTimer()
724
671
 
725
672
  const response = await this.manageV2Client.removeUserFromRepository({
726
673
  repository: this.name,
727
674
  email: email,
728
- });
675
+ })
729
676
 
730
- this.failIfNot200(
731
- response,
732
- `Could not remove the user ${email} from the repository`,
733
- );
677
+ this.failIfNot200(response, `Could not remove the user ${email} from the repository`)
734
678
  profiler.done({
735
679
  message: `User ${email} was removed from the repository`,
736
- });
680
+ })
737
681
  }
738
682
 
739
683
  /**
740
684
  * Update the role of a user in a repository
741
685
  *
742
686
  * @param {string} email - The email of the user
743
- * @param {string | Record<string, string>} role - The new Role of the user,
744
- * either a string for basic workflow or an object such as `{ "lang_id":
745
- * "Writer" }`
687
+ * @param {string | Record<string, string>} role - The new Role of the user, either a string for
688
+ * basic workflow or an object such as `{ "lang_id": "Writer" }`
746
689
  *
747
690
  * Example of roles are
748
691
  *
@@ -751,150 +694,232 @@ export class RepositoryManager {
751
694
  * - Contributor
752
695
  * - Manager (publisher)
753
696
  */
754
- async updateUserRole(
755
- email: string,
756
- role: string | Record<string, string>,
757
- ): Promise<void> {
758
- const profiler = logger.startTimer();
697
+ async updateUserRole(email: string, role: string | Record<string, string>): Promise<void> {
698
+ const profiler = logger.startTimer()
759
699
 
760
700
  const response =
761
701
  typeof role === "string"
762
702
  ? await this.wroomClient.updateRole(this.name, email, role)
763
- : await this.wroomClient.updateRolePerLocal(this.name, email, role);
703
+ : await this.wroomClient.updateRolePerLocal(this.name, email, role)
764
704
 
765
705
  this.failIfNot200(
766
706
  response,
767
707
  `Could not update the ${
768
708
  typeof role === "string" ? "role" : "rolePerLocal"
769
709
  } of the user ${email}`,
770
- );
710
+ )
771
711
  profiler.done({
772
712
  message: `Updated User's ${
773
713
  typeof role === "string" ? "role" : "rolePerLocal"
774
714
  } for user ${email}`,
775
- });
715
+ })
776
716
  }
777
717
 
778
718
  /**
779
- * Creates a document using the core api. If the Core api format is too
780
- * specific, use the migration api client to create a document with the
781
- * MigrationApiClient. See the `getMigrationApiClient()` method.
782
- *
783
- * @example To create a document by converting it from the Page Builder to
784
- * Core api format
785
- *
786
- * ```js
787
- * import { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';
788
- *
789
- * const document = {
790
- * title: 'A new document',
791
- * custom_type_id: 'home-page',
792
- * locale: 'en-gb',
793
- * integration_field_ids: [],
794
- * tags: [],
795
- * data: DocumentLegacy.encode({
796
- * uid: {
797
- * __TYPE__: UIDContentType,
798
- * value: 'home-page',
799
- * },
800
- * })
801
- * }
802
- * await repository.createDocument(document, 'published');
803
- * * ```
804
- * ```
805
- *
806
- * @returns
807
- *
808
- * @param document - in the core api format.
809
- *
810
- * @param status - status of the document, if published, the function will
811
- * wait for a new content api master ref to be created
719
+ * Creates a document using the core api. If the Core api format is too specific, use the
720
+ * migration api client to create a document with the MigrationApiClient. See the
721
+ * `getMigrationApiClient()` method.
722
+ *
723
+ * @example
724
+ * To create a document by converting it from the Page Builder to
725
+ * Core api format
726
+ *
727
+ * ```js
728
+ * import { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';
729
+ *
730
+ * const document = {
731
+ * title: 'A new document',
732
+ * custom_type_id: 'home-page',
733
+ * locale: 'en-gb',
734
+ * integration_field_ids: [],
735
+ * tags: [],
736
+ * data: DocumentLegacy.encode({
737
+ * uid: {
738
+ * __TYPE__: UIDContentType,
739
+ * value: 'home-page',
740
+ * },
741
+ * })
742
+ * }
743
+ * await repository.createDocument(document, 'published');
744
+ * * ```
745
+ * ```
746
+ *
747
+ * @returns
748
+ *
749
+ * @param document - in the core api format.
750
+ *
751
+ * @param status - status of the document, if published, the function will
752
+ * wait for a new content api master ref to be created
812
753
  */
813
754
  async createDocument(
814
755
  document: CoreApiDocumentCreationPayload,
815
756
  status: "draft" | "published",
816
757
  ): Promise<CoreApiDocumentCreationResponse> {
817
- const profiler = logger.startTimer();
818
- const result = await this.coreApiClient.createDraft(document);
758
+ const profiler = logger.startTimer()
759
+ const result = await this.coreApiClient.createDraft(document)
819
760
 
820
- let message = `Document created with id '${result.id}'`;
761
+ let message = `Document created with id '${result.id}'`
821
762
  if (status === "published") {
822
- const contentApi = this.getContentApiClient();
823
- const masterRef = await contentApi.getMasterRef();
824
- await this.coreApiClient.publishDraft(result.id);
763
+ const contentApi = this.getContentApiClient()
764
+ const masterRef = await contentApi.getMasterRef()
765
+ await this.coreApiClient.publishDraft(result.id)
825
766
  await expect
826
767
  .poll(async () => contentApi.getMasterRef(), {
827
768
  timeout: 10_000,
828
769
  message: "Waiting for new master ref to be available",
829
770
  })
830
- .not.toBe(masterRef);
831
- message += ", status 'published' and new master ref available";
771
+ .not.toBe(masterRef)
772
+ message += ", status 'published' and new master ref available"
773
+ }
774
+ profiler.done({
775
+ message,
776
+ })
777
+
778
+ return result
779
+ }
780
+
781
+ /**
782
+ * Updates an existing document using the core api by creating a new draft version on top of the
783
+ * given base version. If the status is published, the function will, unless disabled, wait for a
784
+ * new content api master ref to be created.
785
+ *
786
+ * @param documentId - The id of the document to update.
787
+ * @param data - The new version payload in the core api format.
788
+ * @param baseVersionId - The id of the version the draft is created from.
789
+ * @param status - Status of the new version, if published, the function will wait for a new
790
+ * content api master ref to be created.
791
+ * @param options - Additional options.
792
+ * @param options.waitForMasterRef - When publishing, wait for a new content api master ref to be
793
+ * available (default true). Set to false to return without waiting for the projection.
794
+ * @returns The updated document, including the new version's id.
795
+ */
796
+ async updateDocument(
797
+ documentId: string,
798
+ data: CoreApiDocumentUpdatePayload,
799
+ baseVersionId: string,
800
+ status: "draft" | "published",
801
+ options: { waitForMasterRef?: boolean } = {},
802
+ ): Promise<CoreApiDocumentCreationResponse> {
803
+ const { waitForMasterRef = true } = options
804
+ const profiler = logger.startTimer()
805
+ const result = await this.coreApiClient.updateDraft(documentId, data, baseVersionId)
806
+
807
+ let message = `Document '${documentId}' updated`
808
+ if (status === "published") {
809
+ if (waitForMasterRef) {
810
+ const contentApi = this.getContentApiClient()
811
+ const masterRef = await contentApi.getMasterRef()
812
+ await this.coreApiClient.publishDraft(documentId)
813
+ await expect
814
+ .poll(async () => contentApi.getMasterRef(), {
815
+ timeout: 10_000,
816
+ message: "Waiting for new master ref to be available",
817
+ })
818
+ .not.toBe(masterRef)
819
+ message += ", status 'published' and new master ref available"
820
+ } else {
821
+ await this.coreApiClient.publishDraft(documentId)
822
+ message += ", status 'published'"
823
+ }
832
824
  }
833
825
  profiler.done({
834
826
  message,
835
- });
827
+ })
836
828
 
837
- return result;
829
+ return result
830
+ }
831
+
832
+ /**
833
+ * Unpublishes (archives) a live document using the core api. Unless disabled, waits for a new
834
+ * content api master ref to be available.
835
+ *
836
+ * @param documentId - The id of the document to unpublish.
837
+ * @param options - Additional options.
838
+ * @param options.waitForMasterRef - Wait for a new content api master ref to be available
839
+ * (default true). Set to false to return without waiting for the projection.
840
+ */
841
+ async unpublishDocument(
842
+ documentId: string,
843
+ options: { waitForMasterRef?: boolean } = {},
844
+ ): Promise<void> {
845
+ const { waitForMasterRef = true } = options
846
+ const profiler = logger.startTimer()
847
+
848
+ if (!waitForMasterRef) {
849
+ await this.coreApiClient.unpublishDocument(documentId)
850
+ profiler.done({ message: `Document '${documentId}' unpublished` })
851
+
852
+ return
853
+ }
854
+
855
+ const contentApi = this.getContentApiClient()
856
+ const masterRef = await contentApi.getMasterRef()
857
+ await this.coreApiClient.unpublishDocument(documentId)
858
+ await expect
859
+ .poll(async () => contentApi.getMasterRef(), {
860
+ timeout: 10_000,
861
+ message: "Waiting for new master ref to be available",
862
+ })
863
+ .not.toBe(masterRef)
864
+
865
+ profiler.done({
866
+ message: `Document '${documentId}' unpublished and new master ref available`,
867
+ })
838
868
  }
839
869
 
840
870
  /**
841
871
  * Retrieves data for a specific document version.
842
872
  *
843
873
  * @param versionId - The document's version ID.
844
- *
845
874
  * @returns The document's version data.
846
875
  */
847
876
  async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
848
- return await this.coreApiClient.getDocumentData(versionId);
877
+ return await this.coreApiClient.getDocumentData(versionId)
849
878
  }
850
879
 
851
- async setupIntegrationFields(
852
- integrationFields: IntegrationFieldConfig[],
853
- ): Promise<void> {
854
- const profiler = logger.startTimer();
880
+ async setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {
881
+ const profiler = logger.startTimer()
855
882
 
856
883
  if (!this.integrationFieldsClient) {
857
884
  throw new Error(
858
885
  "Integration Fields client not found. Did you provide a integration fields api url in the configuration?",
859
- );
886
+ )
860
887
  }
861
888
 
862
- await this.integrationFieldsClient.setupIntegrationFields(
863
- integrationFields,
864
- );
889
+ await this.integrationFieldsClient.setupIntegrationFields(integrationFields)
865
890
  profiler.done({
866
891
  message: `Integration Fields setup`,
867
- });
892
+ })
868
893
  }
869
894
  }
870
895
 
871
896
  export type RepositoryConfig = {
872
- customLocale?: CustomLocale;
873
- locales?: string[];
874
- defaultLocale?: string;
875
- slices?: SharedSlice[];
876
- customTypes?: CustomType[];
877
- preview?: Preview;
878
- simulatorURL?: string;
879
- rolePerLocal?: boolean;
880
- customRoles?: boolean;
881
- integrationFields?: IntegrationFieldConfig[];
882
- };
897
+ customLocale?: CustomLocale
898
+ locales?: string[]
899
+ defaultLocale?: string
900
+ slices?: SharedSliceModel[]
901
+ customTypes?: DynamicCustomTypeModel[]
902
+ preview?: Preview
903
+ simulatorURL?: string
904
+ rolePerLocal?: boolean
905
+ customRoles?: boolean
906
+ integrationFields?: IntegrationFieldConfig[]
907
+ }
883
908
 
884
909
  export type Preview = {
885
- name: string;
886
- websiteURL: string;
887
- resolverPath: string;
888
- };
910
+ name: string
911
+ websiteURL: string
912
+ resolverPath: string
913
+ }
889
914
 
890
915
  export type CustomLocale = {
891
916
  lang: {
892
- label: string;
893
- id: string;
894
- useStandardAnalyzer?: boolean;
895
- };
917
+ label: string
918
+ id: string
919
+ useStandardAnalyzer?: boolean
920
+ }
896
921
  region: {
897
- label: string;
898
- id: string;
899
- };
900
- };
922
+ label: string
923
+ id: string
924
+ }
925
+ }