@prismicio/e2e-tests-utils 1.1.3 → 1.2.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.
- package/dist/clients/authenticationApi.cjs +2 -21
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.ts +2 -3
- package/dist/clients/authenticationApi.js +3 -22
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/wroom.cjs +0 -28
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.ts +2 -22
- package/dist/clients/wroom.js +0 -28
- package/dist/clients/wroom.js.map +1 -1
- package/dist/managers/repositories.cjs +17 -20
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.ts +22 -12
- package/dist/managers/repositories.js +17 -20
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +32 -113
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +22 -50
- package/dist/managers/repository.js +32 -113
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.ts +1 -18
- package/package.json +1 -3
- package/src/clients/authenticationApi.ts +4 -33
- package/src/clients/wroom.ts +2 -42
- package/src/managers/repositories.ts +37 -39
- package/src/managers/repository.ts +58 -156
- package/src/types.ts +1 -27
- package/dist/clients/manageV2.cjs +0 -145
- package/dist/clients/manageV2.cjs.map +0 -1
- package/dist/clients/manageV2.d.ts +0 -91
- package/dist/clients/manageV2.js +0 -145
- package/dist/clients/manageV2.js.map +0 -1
- package/src/clients/manageV2.ts +0 -178
|
@@ -9,19 +9,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
9
9
|
const log = require("../utils/log.cjs");
|
|
10
10
|
const urls = require("../utils/urls.cjs");
|
|
11
11
|
class RepositoryManager {
|
|
12
|
-
constructor(name, coreApiClient,
|
|
12
|
+
constructor(name, coreApiClient, wroomClient, customTypesApiClient) {
|
|
13
13
|
__publicField(this, "name");
|
|
14
14
|
__publicField(this, "coreApiClient");
|
|
15
|
-
__publicField(this, "authApiClient");
|
|
16
15
|
__publicField(this, "wroomClient");
|
|
17
16
|
__publicField(this, "customTypesApiClient");
|
|
18
|
-
__publicField(this, "manageV2Client");
|
|
19
17
|
this.name = name;
|
|
20
18
|
this.coreApiClient = coreApiClient;
|
|
21
|
-
this.authApiClient = authApiClient;
|
|
22
19
|
this.wroomClient = wroomClient;
|
|
23
20
|
this.customTypesApiClient = customTypesApiClient;
|
|
24
|
-
this.manageV2Client = manageV2Client;
|
|
25
21
|
}
|
|
26
22
|
async configure(config) {
|
|
27
23
|
const hasLangConfig = config.defaultLocale || config.locales || config.customLocale;
|
|
@@ -59,9 +55,6 @@ class RepositoryManager {
|
|
|
59
55
|
if (config.preview) {
|
|
60
56
|
await this.createPreview(config.preview);
|
|
61
57
|
}
|
|
62
|
-
if (config.rolePerLocal) {
|
|
63
|
-
await this.toggleRolePerLocal(true);
|
|
64
|
-
}
|
|
65
58
|
}
|
|
66
59
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
67
60
|
getBaseURL() {
|
|
@@ -197,6 +190,35 @@ class RepositoryManager {
|
|
|
197
190
|
this.failIfNot200(response, `Could not delete preview with id ${id}`);
|
|
198
191
|
profiler.done({ message: `preview '${id}' deleted` });
|
|
199
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Create a webhook.
|
|
195
|
+
*
|
|
196
|
+
* @returns A Promise that resolves with the webhook id.
|
|
197
|
+
*/
|
|
198
|
+
async createWebhook(name, url, secret, triggers, active) {
|
|
199
|
+
const profiler = log.logger.startTimer();
|
|
200
|
+
const response = await this.wroomClient.post(this.name, "app/settings/webhooks/create", {
|
|
201
|
+
name,
|
|
202
|
+
url,
|
|
203
|
+
secret,
|
|
204
|
+
active: active ? "on" : "off",
|
|
205
|
+
...triggers
|
|
206
|
+
});
|
|
207
|
+
this.failIfNot200(response, `Could not create webhook ${name}`);
|
|
208
|
+
profiler.done({ message: `webhook '${name}' created` });
|
|
209
|
+
return response.data.created;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Deletes a webhook.
|
|
213
|
+
*
|
|
214
|
+
* @param id - The webhook ID.
|
|
215
|
+
*/
|
|
216
|
+
async deleteWebhook(id) {
|
|
217
|
+
const profiler = log.logger.startTimer();
|
|
218
|
+
const response = await this.wroomClient.post(this.name, `app/settings/webhooks/${id}/delete`, {});
|
|
219
|
+
this.failIfNot200(response, `Could not delete webhook with id ${id}`);
|
|
220
|
+
profiler.done({ message: `webhook '${id}' deleted` });
|
|
221
|
+
}
|
|
200
222
|
/**
|
|
201
223
|
* Create Custom Types using the Custom types api.
|
|
202
224
|
*
|
|
@@ -214,11 +236,11 @@ class RepositoryManager {
|
|
|
214
236
|
await this.customTypesApiClient.createSlices(slices);
|
|
215
237
|
}
|
|
216
238
|
/**
|
|
217
|
-
* Create
|
|
239
|
+
* Create a permanent access token along with an application name
|
|
218
240
|
*
|
|
219
241
|
* @param appName - mandatory authorized application name
|
|
220
242
|
*/
|
|
221
|
-
async
|
|
243
|
+
async createPermanentAccessToken(appName) {
|
|
222
244
|
const profiler = log.logger.startTimer();
|
|
223
245
|
const existingApps = await this.wroomClient.get(this.name, "settings/security/contentapi");
|
|
224
246
|
this.failIfNot200(existingApps, `Could not get status of existing applications to generate a permanent token`);
|
|
@@ -237,109 +259,6 @@ class RepositoryManager {
|
|
|
237
259
|
});
|
|
238
260
|
return response.data.wroom_auths[0].token;
|
|
239
261
|
}
|
|
240
|
-
/** Create a permanent access token to authenticate to Prismic public apis. */
|
|
241
|
-
async createPermanentAccessToken() {
|
|
242
|
-
const profiler = log.logger.startTimer();
|
|
243
|
-
const token = await this.authApiClient.getMachine2MachineToken(this.name);
|
|
244
|
-
profiler.done({
|
|
245
|
-
message: `machine2machine token created`
|
|
246
|
-
});
|
|
247
|
-
return token;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Toggle the Role per local feature
|
|
251
|
-
*
|
|
252
|
-
* @param enabled - The feature new status
|
|
253
|
-
*/
|
|
254
|
-
async toggleRolePerLocal(enabled) {
|
|
255
|
-
const profiler = log.logger.startTimer();
|
|
256
|
-
const response = await this.manageV2Client.toggleRolePerLocal({
|
|
257
|
-
repository: this.name,
|
|
258
|
-
enabled
|
|
259
|
-
});
|
|
260
|
-
this.failIfNot200(response, `Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`);
|
|
261
|
-
profiler.done({
|
|
262
|
-
message: `Role per local ${enabled ? "enabled" : "disabled"}`
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Change the Repository Plan
|
|
267
|
-
*
|
|
268
|
-
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
269
|
-
*/
|
|
270
|
-
async changePlan(newPlanId) {
|
|
271
|
-
const profiler = log.logger.startTimer();
|
|
272
|
-
const response = await this.manageV2Client.changePlan({
|
|
273
|
-
repository: this.name,
|
|
274
|
-
newPlanId,
|
|
275
|
-
bypassManualBilling: true
|
|
276
|
-
// For now the library does not support Stripe features
|
|
277
|
-
});
|
|
278
|
-
this.failIfNot200(response, "Could not change the Repository Plan");
|
|
279
|
-
profiler.done({
|
|
280
|
-
message: `Repository Plan changed to ${newPlanId}`
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Add a new user to the repository
|
|
285
|
-
*
|
|
286
|
-
* @param {string} email - The email of the user
|
|
287
|
-
*/
|
|
288
|
-
async addUser(email) {
|
|
289
|
-
const profiler = log.logger.startTimer();
|
|
290
|
-
const response = await this.manageV2Client.addUserToRepository({
|
|
291
|
-
repository: this.name,
|
|
292
|
-
email
|
|
293
|
-
});
|
|
294
|
-
const { data, status } = response;
|
|
295
|
-
const success = status === 200 || status === 409 && JSON.stringify(data).includes("already a member of the repo");
|
|
296
|
-
if (!success) {
|
|
297
|
-
log.logHttpResponse(response);
|
|
298
|
-
throw new Error(`Could not add a new user ${email} to the repository`);
|
|
299
|
-
}
|
|
300
|
-
profiler.done({
|
|
301
|
-
message: `User ${email} was added to the repository`
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Remove a user from the repository
|
|
306
|
-
*
|
|
307
|
-
* @param {string} email - The email of the user
|
|
308
|
-
*/
|
|
309
|
-
async removeUser(email) {
|
|
310
|
-
const profiler = log.logger.startTimer();
|
|
311
|
-
const response = await this.manageV2Client.removeUserFromRepository({
|
|
312
|
-
repository: this.name,
|
|
313
|
-
email
|
|
314
|
-
});
|
|
315
|
-
this.failIfNot200(response, `Could not remove the user ${email} from the repository`);
|
|
316
|
-
profiler.done({
|
|
317
|
-
message: `User ${email} was removed from the repository`
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Update the role of a user in a repository
|
|
322
|
-
*
|
|
323
|
-
* @param {string} email - The email of the user
|
|
324
|
-
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
325
|
-
* either a string for basic workflow or an object such as `{ "lang_id":
|
|
326
|
-
* "Writer" }`
|
|
327
|
-
*
|
|
328
|
-
* Example of roles are
|
|
329
|
-
*
|
|
330
|
-
* - Administrator
|
|
331
|
-
* - Writer
|
|
332
|
-
* - Contributor
|
|
333
|
-
* - Manager (publisher)
|
|
334
|
-
*/
|
|
335
|
-
async updateUserRole(email, role) {
|
|
336
|
-
const profiler = log.logger.startTimer();
|
|
337
|
-
const response = typeof role === "string" ? await this.wroomClient.updateRole(this.name, email, role) : await this.wroomClient.updateRolePerLocal(this.name, email, role);
|
|
338
|
-
this.failIfNot200(response, `Could not update the ${typeof role === "string" ? "role" : "rolePerLocal"} of the user ${email}`);
|
|
339
|
-
profiler.done({
|
|
340
|
-
message: `Updated User's ${typeof role === "string" ? "role" : "rolePerLocal"} for user ${email}`
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
262
|
}
|
|
344
263
|
exports.RepositoryManager = RepositoryManager;
|
|
345
264
|
//# sourceMappingURL=repository.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.cjs","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport type { AuthenticationClient } from \"../clients/authenticationApi\";\nimport type { CoreClient } from \"../clients/coreApi\";\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly coreApiClient: CoreClient,\n\t\tprivate readonly authApiClient: AuthenticationClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t\tprivate readonly manageV2Client: ManageV2Client,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tconst hasLangConfig =\n\t\t\tconfig.defaultLocale || config.locales || config.customLocale;\n\t\tif (hasLangConfig) {\n\t\t\tconst languages = await this.coreApiClient.getLanguages();\n\n\t\t\t// default locale must be set first\n\t\t\tif (config.defaultLocale) {\n\t\t\t\tconst master = languages.find(({ is_master }) => is_master === true);\n\t\t\t\tif (!master) {\n\t\t\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`Master locale is already set to '${master.id}', cannot update it to '${config.defaultLocale}'`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\tconst localesToAdd = config.locales.filter(\n\t\t\t\t\t(id) => !languages.some((language) => language.id === id),\n\t\t\t\t);\n\t\t\t\tif (localesToAdd.length > 0) {\n\t\t\t\t\tawait this.createLocales(localesToAdd);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.customLocale) {\n\t\t\t\tif (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {\n\t\t\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\n\t\tif (config.rolePerLocal) {\n\t\t\tawait this.toggleRolePerLocal(true);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\treturn getRepositoryUrl(this.wroomClient.getBaseURL(), this.name);\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `locales '${locales}' created` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && JSON.stringify(data).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/createMasterLang`,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`);\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id ${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n\n\t/**\n\t * Create an access token to query private items of the Content api.\n\t *\n\t * @param appName - mandatory authorized application name\n\t */\n\tasync createContentAPIToken(appName: string): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\t\ttype AuthorizedAppResponse = {\n\t\t\tname: string;\n\t\t\twroom_auths: { token: string }[];\n\t\t};\n\t\tconst existingApps: AxiosResponse<AuthorizedAppResponse[]> =\n\t\t\tawait this.wroomClient.get(this.name, \"settings/security/contentapi\");\n\n\t\tthis.failIfNot200(\n\t\t\texistingApps,\n\t\t\t`Could not get status of existing applications to generate a permanent token`,\n\t\t);\n\t\tconst existingApp = existingApps.data.find(({ name, wroom_auths }) => {\n\t\t\treturn name === appName && wroom_auths.length > 0;\n\t\t});\n\t\tif (existingApp) {\n\t\t\treturn existingApp.wroom_auths[0].token;\n\t\t}\n\t\tconst response: AxiosResponse<AuthorizedAppResponse> =\n\t\t\tawait this.wroomClient.post(this.name, \"settings/security/oauthapp\", {\n\t\t\t\tapp_name: appName,\n\t\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not create permanent access token for app name ${appName}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `permanent access token for app name '${appName}' created`,\n\t\t});\n\n\t\t// only return the generated token since there is no need to access more\n\t\treturn response.data.wroom_auths[0].token;\n\t}\n\n\t/** Create a permanent access token to authenticate to Prismic public apis. */\n\tasync createPermanentAccessToken(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst token = await this.authApiClient.getMachine2MachineToken(this.name);\n\n\t\tprofiler.done({\n\t\t\tmessage: `machine2machine token created`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/**\n\t * Toggle the Role per local feature\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleRolePerLocal(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.toggleRolePerLocal({\n\t\t\trepository: this.name,\n\t\t\tenabled: enabled,\n\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not ${enabled ? \"enable\" : \"disable\"} Role per local for ${\n\t\t\t\tthis.name\n\t\t\t}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `Role per local ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t});\n\t}\n\n\t/**\n\t * Change the Repository Plan\n\t *\n\t * @param {string} newPlanId - The Id of the new Plan to apply\n\t */\n\tasync changePlan(newPlanId: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.changePlan({\n\t\t\trepository: this.name,\n\t\t\tnewPlanId: newPlanId,\n\t\t\tbypassManualBilling: true, // For now the library does not support Stripe features\n\t\t});\n\n\t\tthis.failIfNot200(response, \"Could not change the Repository Plan\");\n\t\tprofiler.done({\n\t\t\tmessage: `Repository Plan changed to ${newPlanId}`,\n\t\t});\n\t}\n\n\t/**\n\t * Add a new user to the repository\n\t *\n\t * @param {string} email - The email of the user\n\t */\n\tasync addUser(email: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.addUserToRepository({\n\t\t\trepository: this.name,\n\t\t\temail: email,\n\t\t});\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 409 &&\n\t\t\t\tJSON.stringify(data).includes(\"already a member of the repo\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add a new user ${email} to the repository`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `User ${email} was added to the repository`,\n\t\t});\n\t}\n\n\t/**\n\t * Remove a user from the repository\n\t *\n\t * @param {string} email - The email of the user\n\t */\n\tasync removeUser(email: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.removeUserFromRepository({\n\t\t\trepository: this.name,\n\t\t\temail: email,\n\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not remove the user ${email} from the repository`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `User ${email} was removed from the repository`,\n\t\t});\n\t}\n\n\t/**\n\t * Update the role of a user in a repository\n\t *\n\t * @param {string} email - The email of the user\n\t * @param {string | Record<string, string>} role - The new Role of the user,\n\t * either a string for basic workflow or an object such as `{ \"lang_id\":\n\t * \"Writer\" }`\n\t *\n\t * Example of roles are\n\t *\n\t * - Administrator\n\t * - Writer\n\t * - Contributor\n\t * - Manager (publisher)\n\t */\n\tasync updateUserRole(\n\t\temail: string,\n\t\trole: string | Record<string, string>,\n\t): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response =\n\t\t\ttypeof role === \"string\"\n\t\t\t\t? await this.wroomClient.updateRole(this.name, email, role)\n\t\t\t\t: await this.wroomClient.updateRolePerLocal(this.name, email, role);\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not update the ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} of the user ${email}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `Updated User's ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} for user ${email}`,\n\t\t});\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n\trolePerLocal?: boolean;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":["logger","getRepositoryUrl","logHttpResponse"],"mappings":";;;;;;;;;;MAgBa,kBAAiB;AAAA,EAC7B,YACU,MACQ,eACA,eACA,aACA,sBACA,gBAA8B;AALtC;AACQ;AACA;AACA;AACA;AACA;AALR,SAAI,OAAJ;AACQ,SAAa,gBAAb;AACA,SAAa,gBAAb;AACA,SAAW,cAAX;AACA,SAAoB,uBAApB;AACA,SAAc,iBAAd;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,QAAwB;AACvC,UAAM,gBACL,OAAO,iBAAiB,OAAO,WAAW,OAAO;AAClD,QAAI,eAAe;AAClB,YAAM,YAAY,MAAM,KAAK,cAAc,aAAY;AAGvD,UAAI,OAAO,eAAe;AACnB,cAAA,SAAS,UAAU,KAAK,CAAC,EAAE,gBAAgB,cAAc,IAAI;AACnE,YAAI,CAAC,QAAQ;AACN,gBAAA,KAAK,iBAAiB,OAAO,aAAa;AAAA,QACtC,WAAA,OAAO,OAAO,OAAO,eAAe;AAC9CA,cAAAA,OAAO,KACN,oCAAoC,OAAO,EAAE,2BAA2B,OAAO,aAAa,GAAG;AAAA,QAEhG;AAAA,MACD;AAED,UAAI,OAAO,SAAS;AACnB,cAAM,eAAe,OAAO,QAAQ,OACnC,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC,aAAa,SAAS,OAAO,EAAE,CAAC;AAEtD,YAAA,aAAa,SAAS,GAAG;AACtB,gBAAA,KAAK,cAAc,YAAY;AAAA,QACrC;AAAA,MACD;AAED,UAAI,OAAO,cAAc;AACxB,YAAI,CAAC,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AA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAM,eACL,OACA,MAAqC;AAE/B,UAAA,WAAWA,WAAO;AAElB,UAAA,WACL,OAAO,SAAS,WACb,MAAM,KAAK,YAAY,WAAW,KAAK,MAAM,OAAO,IAAI,IACxD,MAAM,KAAK,YAAY,mBAAmB,KAAK,MAAM,OAAO,IAAI;AAE/D,SAAA,aACJ,UACA,wBACC,OAAO,SAAS,WAAW,SAAS,cACrC,gBAAgB,KAAK,EAAE;AAExB,aAAS,KAAK;AAAA,MACb,SAAS,kBACR,OAAO,SAAS,WAAW,SAAS,cACrC,aAAa,KAAK;AAAA,IAAA,CAClB;AAAA,EACF;AACA;;"}
|
|
1
|
+
{"version":3,"file":"repository.cjs","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport type { CoreClient } from \"../clients/coreApi\";\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly coreApiClient: CoreClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tconst hasLangConfig =\n\t\t\tconfig.defaultLocale || config.locales || config.customLocale;\n\t\tif (hasLangConfig) {\n\t\t\tconst languages = await this.coreApiClient.getLanguages();\n\n\t\t\t// default locale must be set first\n\t\t\tif (config.defaultLocale) {\n\t\t\t\tconst master = languages.find(({ is_master }) => is_master === true);\n\t\t\t\tif (!master) {\n\t\t\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`Master locale is already set to '${master.id}', cannot update it to '${config.defaultLocale}'`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\tconst localesToAdd = config.locales.filter(\n\t\t\t\t\t(id) => !languages.some((language) => language.id === id),\n\t\t\t\t);\n\t\t\t\tif (localesToAdd.length > 0) {\n\t\t\t\t\tawait this.createLocales(localesToAdd);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.customLocale) {\n\t\t\t\tif (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {\n\t\t\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\treturn getRepositoryUrl(this.wroomClient.getBaseURL(), this.name);\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `locales '${locales}' created` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && JSON.stringify(data).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/createMasterLang`,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`);\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id ${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create a webhook.\n\t *\n\t * @returns A Promise that resolves with the webhook id.\n\t */\n\tasync createWebhook(\n\t\tname: string,\n\t\turl: string,\n\t\tsecret: string,\n\t\ttriggers: {\n\t\t\tdocumentsPublished?: boolean;\n\t\t\tdocumentsUnpublished?: boolean;\n\t\t\treleasesCreated?: boolean;\n\t\t\treleasesUpdated?: boolean;\n\t\t\ttagsCreated?: boolean;\n\t\t\ttagsDeleted?: boolean;\n\t\t},\n\t\tactive: boolean,\n\t): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/webhooks/create\",\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\turl,\n\t\t\t\tsecret,\n\t\t\t\tactive: active ? \"on\" : \"off\",\n\t\t\t\t...triggers,\n\t\t\t},\n\t\t);\n\t\tthis.failIfNot200(response, `Could not create webhook ${name}`);\n\t\tprofiler.done({ message: `webhook '${name}' created` });\n\n\t\treturn response.data.created;\n\t}\n\n\t/**\n\t * Deletes a webhook.\n\t *\n\t * @param id - The webhook ID.\n\t */\n\tasync deleteWebhook(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/webhooks/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete webhook with id ${id}`);\n\t\tprofiler.done({ message: `webhook '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n\n\t/**\n\t * Create a permanent access token along with an application name\n\t *\n\t * @param appName - mandatory authorized application name\n\t */\n\tasync createPermanentAccessToken(appName: string): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\t\ttype AuthorizedAppResponse = {\n\t\t\tname: string;\n\t\t\twroom_auths: { token: string }[];\n\t\t};\n\t\tconst existingApps: AxiosResponse<AuthorizedAppResponse[]> =\n\t\t\tawait this.wroomClient.get(this.name, \"settings/security/contentapi\");\n\n\t\tthis.failIfNot200(\n\t\t\texistingApps,\n\t\t\t`Could not get status of existing applications to generate a permanent token`,\n\t\t);\n\t\tconst existingApp = existingApps.data.find(({ name, wroom_auths }) => {\n\t\t\treturn name === appName && wroom_auths.length > 0;\n\t\t});\n\t\tif (existingApp) {\n\t\t\treturn existingApp.wroom_auths[0].token;\n\t\t}\n\t\tconst response: AxiosResponse<AuthorizedAppResponse> =\n\t\t\tawait this.wroomClient.post(this.name, \"settings/security/oauthapp\", {\n\t\t\t\tapp_name: appName,\n\t\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not create permanent access token for app name ${appName}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `permanent access token for app name '${appName}' created`,\n\t\t});\n\n\t\t// only return the generated token since there is no need to access more\n\t\treturn response.data.wroom_auths[0].token;\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":["logger","getRepositoryUrl","logHttpResponse"],"mappings":";;;;;;;;;;MAca,kBAAiB;AAAA,EAC7B,YACU,MACQ,eACA,aACA,sBAAuC;AAH/C;AACQ;AACA;AACA;AAHR,SAAI,OAAJ;AACQ,SAAa,gBAAb;AACA,SAAW,cAAX;AACA,SAAoB,uBAApB;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,QAAwB;AACvC,UAAM,gBACL,OAAO,iBAAiB,OAAO,WAAW,OAAO;AAClD,QAAI,eAAe;AAClB,YAAM,YAAY,MAAM,KAAK,cAAc,aAAY;AAGvD,UAAI,OAAO,eAAe;AACnB,cAAA,SAAS,UAAU,KAAK,CAAC,EAAE,gBAAgB,cAAc,IAAI;AACnE,YAAI,CAAC,QAAQ;AACN,gBAAA,KAAK,iBAAiB,OAAO,aAAa;AAAA,QACtC,WAAA,OAAO,OAAO,OAAO,eAAe;AAC9CA,cAAAA,OAAO,KACN,oCAAoC,OAAO,EAAE,2BAA2B,OAAO,aAAa,GAAG;AAAA,QAEhG;AAAA,MACD;AAED,UAAI,OAAO,SAAS;AACnB,cAAM,eAAe,OAAO,QAAQ,OACnC,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC,aAAa,SAAS,OAAO,EAAE,CAAC;AAEtD,YAAA,aAAa,SAAS,GAAG;AACtB,gBAAA,KAAK,cAAc,YAAY;AAAA,QACrC;AAAA,MACD;AAED,UAAI,OAAO,cAAc;AACxB,YAAI,CAAC,UAAU,KAAK,CAAC,EAAE,GAAA;;AAAS,0BAAO,YAAO,iBAAP,mBAAqB,KAAK;AAAA,SAAE,GAAG;AAC/D,gBAAA,KAAK,mBAAmB,OAAO,YAAY;AAAA,QACjD;AAAA,M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
1
1
|
import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
import type { AuthenticationClient } from "../clients/authenticationApi";
|
|
3
2
|
import type { CoreClient } from "../clients/coreApi";
|
|
4
3
|
import { CustomTypesClient } from "../clients/customTypesApi";
|
|
5
|
-
import { ManageV2Client } from "../clients/manageV2";
|
|
6
4
|
import { WroomClient } from "../clients/wroom";
|
|
7
5
|
/** Utility to manage test data for a Prismic repository */
|
|
8
6
|
export declare class RepositoryManager {
|
|
9
7
|
readonly name: string;
|
|
10
8
|
private readonly coreApiClient;
|
|
11
|
-
private readonly authApiClient;
|
|
12
9
|
private readonly wroomClient;
|
|
13
10
|
private readonly customTypesApiClient;
|
|
14
|
-
|
|
15
|
-
constructor(name: string, coreApiClient: CoreClient, authApiClient: AuthenticationClient, wroomClient: WroomClient, customTypesApiClient: CustomTypesClient, manageV2Client: ManageV2Client);
|
|
11
|
+
constructor(name: string, coreApiClient: CoreClient, wroomClient: WroomClient, customTypesApiClient: CustomTypesClient);
|
|
16
12
|
configure(config: RepositoryConfig): Promise<void>;
|
|
17
13
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
18
14
|
getBaseURL(): string;
|
|
@@ -81,6 +77,25 @@ export declare class RepositoryManager {
|
|
|
81
77
|
* @param id - The ID of the preview to be deleted.
|
|
82
78
|
*/
|
|
83
79
|
deletePreview(id: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a webhook.
|
|
82
|
+
*
|
|
83
|
+
* @returns A Promise that resolves with the webhook id.
|
|
84
|
+
*/
|
|
85
|
+
createWebhook(name: string, url: string, secret: string, triggers: {
|
|
86
|
+
documentsPublished?: boolean;
|
|
87
|
+
documentsUnpublished?: boolean;
|
|
88
|
+
releasesCreated?: boolean;
|
|
89
|
+
releasesUpdated?: boolean;
|
|
90
|
+
tagsCreated?: boolean;
|
|
91
|
+
tagsDeleted?: boolean;
|
|
92
|
+
}, active: boolean): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Deletes a webhook.
|
|
95
|
+
*
|
|
96
|
+
* @param id - The webhook ID.
|
|
97
|
+
*/
|
|
98
|
+
deleteWebhook(id: string): Promise<void>;
|
|
84
99
|
/**
|
|
85
100
|
* Create Custom Types using the Custom types api.
|
|
86
101
|
*
|
|
@@ -94,53 +109,11 @@ export declare class RepositoryManager {
|
|
|
94
109
|
*/
|
|
95
110
|
createSlices(slices: SharedSlice[]): Promise<void>;
|
|
96
111
|
/**
|
|
97
|
-
* Create
|
|
112
|
+
* Create a permanent access token along with an application name
|
|
98
113
|
*
|
|
99
114
|
* @param appName - mandatory authorized application name
|
|
100
115
|
*/
|
|
101
|
-
|
|
102
|
-
/** Create a permanent access token to authenticate to Prismic public apis. */
|
|
103
|
-
createPermanentAccessToken(): Promise<string>;
|
|
104
|
-
/**
|
|
105
|
-
* Toggle the Role per local feature
|
|
106
|
-
*
|
|
107
|
-
* @param enabled - The feature new status
|
|
108
|
-
*/
|
|
109
|
-
toggleRolePerLocal(enabled: boolean): Promise<void>;
|
|
110
|
-
/**
|
|
111
|
-
* Change the Repository Plan
|
|
112
|
-
*
|
|
113
|
-
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
114
|
-
*/
|
|
115
|
-
changePlan(newPlanId: string): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* Add a new user to the repository
|
|
118
|
-
*
|
|
119
|
-
* @param {string} email - The email of the user
|
|
120
|
-
*/
|
|
121
|
-
addUser(email: string): Promise<void>;
|
|
122
|
-
/**
|
|
123
|
-
* Remove a user from the repository
|
|
124
|
-
*
|
|
125
|
-
* @param {string} email - The email of the user
|
|
126
|
-
*/
|
|
127
|
-
removeUser(email: string): Promise<void>;
|
|
128
|
-
/**
|
|
129
|
-
* Update the role of a user in a repository
|
|
130
|
-
*
|
|
131
|
-
* @param {string} email - The email of the user
|
|
132
|
-
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
133
|
-
* either a string for basic workflow or an object such as `{ "lang_id":
|
|
134
|
-
* "Writer" }`
|
|
135
|
-
*
|
|
136
|
-
* Example of roles are
|
|
137
|
-
*
|
|
138
|
-
* - Administrator
|
|
139
|
-
* - Writer
|
|
140
|
-
* - Contributor
|
|
141
|
-
* - Manager (publisher)
|
|
142
|
-
*/
|
|
143
|
-
updateUserRole(email: string, role: string | Record<string, string>): Promise<void>;
|
|
116
|
+
createPermanentAccessToken(appName: string): Promise<string>;
|
|
144
117
|
}
|
|
145
118
|
export type RepositoryConfig = {
|
|
146
119
|
customLocale?: CustomLocale;
|
|
@@ -149,7 +122,6 @@ export type RepositoryConfig = {
|
|
|
149
122
|
slices?: SharedSlice[];
|
|
150
123
|
customTypes?: CustomType[];
|
|
151
124
|
preview?: Preview;
|
|
152
|
-
rolePerLocal?: boolean;
|
|
153
125
|
};
|
|
154
126
|
export type Preview = {
|
|
155
127
|
name: string;
|
|
@@ -7,19 +7,15 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { logger, logHttpResponse } from "../utils/log.js";
|
|
8
8
|
import { getRepositoryUrl } from "../utils/urls.js";
|
|
9
9
|
class RepositoryManager {
|
|
10
|
-
constructor(name, coreApiClient,
|
|
10
|
+
constructor(name, coreApiClient, wroomClient, customTypesApiClient) {
|
|
11
11
|
__publicField(this, "name");
|
|
12
12
|
__publicField(this, "coreApiClient");
|
|
13
|
-
__publicField(this, "authApiClient");
|
|
14
13
|
__publicField(this, "wroomClient");
|
|
15
14
|
__publicField(this, "customTypesApiClient");
|
|
16
|
-
__publicField(this, "manageV2Client");
|
|
17
15
|
this.name = name;
|
|
18
16
|
this.coreApiClient = coreApiClient;
|
|
19
|
-
this.authApiClient = authApiClient;
|
|
20
17
|
this.wroomClient = wroomClient;
|
|
21
18
|
this.customTypesApiClient = customTypesApiClient;
|
|
22
|
-
this.manageV2Client = manageV2Client;
|
|
23
19
|
}
|
|
24
20
|
async configure(config) {
|
|
25
21
|
const hasLangConfig = config.defaultLocale || config.locales || config.customLocale;
|
|
@@ -57,9 +53,6 @@ class RepositoryManager {
|
|
|
57
53
|
if (config.preview) {
|
|
58
54
|
await this.createPreview(config.preview);
|
|
59
55
|
}
|
|
60
|
-
if (config.rolePerLocal) {
|
|
61
|
-
await this.toggleRolePerLocal(true);
|
|
62
|
-
}
|
|
63
56
|
}
|
|
64
57
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
65
58
|
getBaseURL() {
|
|
@@ -195,6 +188,35 @@ class RepositoryManager {
|
|
|
195
188
|
this.failIfNot200(response, `Could not delete preview with id ${id}`);
|
|
196
189
|
profiler.done({ message: `preview '${id}' deleted` });
|
|
197
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a webhook.
|
|
193
|
+
*
|
|
194
|
+
* @returns A Promise that resolves with the webhook id.
|
|
195
|
+
*/
|
|
196
|
+
async createWebhook(name, url, secret, triggers, active) {
|
|
197
|
+
const profiler = logger.startTimer();
|
|
198
|
+
const response = await this.wroomClient.post(this.name, "app/settings/webhooks/create", {
|
|
199
|
+
name,
|
|
200
|
+
url,
|
|
201
|
+
secret,
|
|
202
|
+
active: active ? "on" : "off",
|
|
203
|
+
...triggers
|
|
204
|
+
});
|
|
205
|
+
this.failIfNot200(response, `Could not create webhook ${name}`);
|
|
206
|
+
profiler.done({ message: `webhook '${name}' created` });
|
|
207
|
+
return response.data.created;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Deletes a webhook.
|
|
211
|
+
*
|
|
212
|
+
* @param id - The webhook ID.
|
|
213
|
+
*/
|
|
214
|
+
async deleteWebhook(id) {
|
|
215
|
+
const profiler = logger.startTimer();
|
|
216
|
+
const response = await this.wroomClient.post(this.name, `app/settings/webhooks/${id}/delete`, {});
|
|
217
|
+
this.failIfNot200(response, `Could not delete webhook with id ${id}`);
|
|
218
|
+
profiler.done({ message: `webhook '${id}' deleted` });
|
|
219
|
+
}
|
|
198
220
|
/**
|
|
199
221
|
* Create Custom Types using the Custom types api.
|
|
200
222
|
*
|
|
@@ -212,11 +234,11 @@ class RepositoryManager {
|
|
|
212
234
|
await this.customTypesApiClient.createSlices(slices);
|
|
213
235
|
}
|
|
214
236
|
/**
|
|
215
|
-
* Create
|
|
237
|
+
* Create a permanent access token along with an application name
|
|
216
238
|
*
|
|
217
239
|
* @param appName - mandatory authorized application name
|
|
218
240
|
*/
|
|
219
|
-
async
|
|
241
|
+
async createPermanentAccessToken(appName) {
|
|
220
242
|
const profiler = logger.startTimer();
|
|
221
243
|
const existingApps = await this.wroomClient.get(this.name, "settings/security/contentapi");
|
|
222
244
|
this.failIfNot200(existingApps, `Could not get status of existing applications to generate a permanent token`);
|
|
@@ -235,109 +257,6 @@ class RepositoryManager {
|
|
|
235
257
|
});
|
|
236
258
|
return response.data.wroom_auths[0].token;
|
|
237
259
|
}
|
|
238
|
-
/** Create a permanent access token to authenticate to Prismic public apis. */
|
|
239
|
-
async createPermanentAccessToken() {
|
|
240
|
-
const profiler = logger.startTimer();
|
|
241
|
-
const token = await this.authApiClient.getMachine2MachineToken(this.name);
|
|
242
|
-
profiler.done({
|
|
243
|
-
message: `machine2machine token created`
|
|
244
|
-
});
|
|
245
|
-
return token;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Toggle the Role per local feature
|
|
249
|
-
*
|
|
250
|
-
* @param enabled - The feature new status
|
|
251
|
-
*/
|
|
252
|
-
async toggleRolePerLocal(enabled) {
|
|
253
|
-
const profiler = logger.startTimer();
|
|
254
|
-
const response = await this.manageV2Client.toggleRolePerLocal({
|
|
255
|
-
repository: this.name,
|
|
256
|
-
enabled
|
|
257
|
-
});
|
|
258
|
-
this.failIfNot200(response, `Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`);
|
|
259
|
-
profiler.done({
|
|
260
|
-
message: `Role per local ${enabled ? "enabled" : "disabled"}`
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Change the Repository Plan
|
|
265
|
-
*
|
|
266
|
-
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
267
|
-
*/
|
|
268
|
-
async changePlan(newPlanId) {
|
|
269
|
-
const profiler = logger.startTimer();
|
|
270
|
-
const response = await this.manageV2Client.changePlan({
|
|
271
|
-
repository: this.name,
|
|
272
|
-
newPlanId,
|
|
273
|
-
bypassManualBilling: true
|
|
274
|
-
// For now the library does not support Stripe features
|
|
275
|
-
});
|
|
276
|
-
this.failIfNot200(response, "Could not change the Repository Plan");
|
|
277
|
-
profiler.done({
|
|
278
|
-
message: `Repository Plan changed to ${newPlanId}`
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Add a new user to the repository
|
|
283
|
-
*
|
|
284
|
-
* @param {string} email - The email of the user
|
|
285
|
-
*/
|
|
286
|
-
async addUser(email) {
|
|
287
|
-
const profiler = logger.startTimer();
|
|
288
|
-
const response = await this.manageV2Client.addUserToRepository({
|
|
289
|
-
repository: this.name,
|
|
290
|
-
email
|
|
291
|
-
});
|
|
292
|
-
const { data, status } = response;
|
|
293
|
-
const success = status === 200 || status === 409 && JSON.stringify(data).includes("already a member of the repo");
|
|
294
|
-
if (!success) {
|
|
295
|
-
logHttpResponse(response);
|
|
296
|
-
throw new Error(`Could not add a new user ${email} to the repository`);
|
|
297
|
-
}
|
|
298
|
-
profiler.done({
|
|
299
|
-
message: `User ${email} was added to the repository`
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Remove a user from the repository
|
|
304
|
-
*
|
|
305
|
-
* @param {string} email - The email of the user
|
|
306
|
-
*/
|
|
307
|
-
async removeUser(email) {
|
|
308
|
-
const profiler = logger.startTimer();
|
|
309
|
-
const response = await this.manageV2Client.removeUserFromRepository({
|
|
310
|
-
repository: this.name,
|
|
311
|
-
email
|
|
312
|
-
});
|
|
313
|
-
this.failIfNot200(response, `Could not remove the user ${email} from the repository`);
|
|
314
|
-
profiler.done({
|
|
315
|
-
message: `User ${email} was removed from the repository`
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Update the role of a user in a repository
|
|
320
|
-
*
|
|
321
|
-
* @param {string} email - The email of the user
|
|
322
|
-
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
323
|
-
* either a string for basic workflow or an object such as `{ "lang_id":
|
|
324
|
-
* "Writer" }`
|
|
325
|
-
*
|
|
326
|
-
* Example of roles are
|
|
327
|
-
*
|
|
328
|
-
* - Administrator
|
|
329
|
-
* - Writer
|
|
330
|
-
* - Contributor
|
|
331
|
-
* - Manager (publisher)
|
|
332
|
-
*/
|
|
333
|
-
async updateUserRole(email, role) {
|
|
334
|
-
const profiler = logger.startTimer();
|
|
335
|
-
const response = typeof role === "string" ? await this.wroomClient.updateRole(this.name, email, role) : await this.wroomClient.updateRolePerLocal(this.name, email, role);
|
|
336
|
-
this.failIfNot200(response, `Could not update the ${typeof role === "string" ? "role" : "rolePerLocal"} of the user ${email}`);
|
|
337
|
-
profiler.done({
|
|
338
|
-
message: `Updated User's ${typeof role === "string" ? "role" : "rolePerLocal"} for user ${email}`
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
260
|
}
|
|
342
261
|
export {
|
|
343
262
|
RepositoryManager
|