@prismicio/e2e-tests-utils 1.2.0 → 1.3.1
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 +21 -2
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.ts +3 -2
- package/dist/clients/authenticationApi.js +22 -3
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +141 -0
- package/dist/clients/contentApi.cjs.map +1 -0
- package/dist/clients/contentApi.d.ts +106 -0
- package/dist/clients/contentApi.js +141 -0
- package/dist/clients/contentApi.js.map +1 -0
- package/dist/clients/coreApi.cjs +12 -2
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +1 -0
- package/dist/clients/coreApi.js +12 -2
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +1 -0
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.js +1 -0
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/manageV2.cjs +145 -0
- package/dist/clients/manageV2.cjs.map +1 -0
- package/dist/clients/manageV2.d.ts +91 -0
- package/dist/clients/manageV2.js +145 -0
- package/dist/clients/manageV2.js.map +1 -0
- package/dist/clients/migrationApi.cjs +36 -0
- package/dist/clients/migrationApi.cjs.map +1 -0
- package/dist/clients/migrationApi.d.ts +20 -0
- package/dist/clients/migrationApi.js +36 -0
- package/dist/clients/migrationApi.js.map +1 -0
- package/dist/clients/wroom.cjs +28 -0
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.ts +22 -2
- package/dist/clients/wroom.js +28 -0
- package/dist/clients/wroom.js.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/managers/repositories.cjs +25 -18
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.ts +12 -22
- package/dist/managers/repositories.js +25 -18
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +184 -41
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +77 -22
- package/dist/managers/repository.js +184 -41
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.ts +20 -1
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.js.map +1 -1
- package/package.json +9 -2
- package/src/clients/authenticationApi.ts +33 -4
- package/src/clients/contentApi.ts +235 -0
- package/src/clients/coreApi.ts +14 -1
- package/src/clients/manageV2.ts +178 -0
- package/src/clients/migrationApi.ts +69 -0
- package/src/clients/wroom.ts +42 -2
- package/src/index.ts +2 -0
- package/src/managers/repositories.ts +46 -37
- package/src/managers/repository.ts +263 -70
- package/src/types.ts +29 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SetupConfiguration, UrlConfig } from "../types";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
AuthenticationClient,
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
} from "../clients/authenticationApi";
|
|
7
7
|
import { createCoreApiClient } from "../clients/coreApi";
|
|
8
8
|
import { createCustomTypesApiClient } from "../clients/customTypesApi";
|
|
9
|
+
import { ManageV2Client } from "../clients/manageV2";
|
|
10
|
+
import { createMigrationApiClient } from "../clients/migrationApi";
|
|
9
11
|
import { WroomClient } from "../clients/wroom";
|
|
10
12
|
import { EnvVariableManager } from "../utils/envVariableManager";
|
|
11
13
|
import { logHttpResponse, logger } from "../utils/log";
|
|
@@ -18,30 +20,29 @@ import { RepositoryConfig, RepositoryManager } from "./repository";
|
|
|
18
20
|
* Factory method to create a RepositoriesManager to manage repositories test
|
|
19
21
|
* data.
|
|
20
22
|
*
|
|
21
|
-
* @param
|
|
23
|
+
* @param configuration - Global object containing the different configurations
|
|
24
|
+
* required to setup the RepositoriesManager.
|
|
22
25
|
*
|
|
23
|
-
* - {@link
|
|
24
|
-
* - {@link
|
|
25
|
-
* - {@link
|
|
26
|
-
*
|
|
27
|
-
* If provided as a string: It is treated as the base URL for Prismic. Other
|
|
28
|
-
* URLs (Custom Types API, Auth API) will be derived from it.
|
|
29
|
-
* @param auth - The authentication credentials
|
|
26
|
+
* - {@link configuration.urlConfig}: Configuration around the API's URLs management.
|
|
27
|
+
* - {@link configuration.authConfig}: Configuration around the authentication of a user.
|
|
28
|
+
* - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.
|
|
30
29
|
*
|
|
31
30
|
* @returns An instance of {@link RepositoriesManager} to manage test data.
|
|
32
31
|
*/
|
|
33
32
|
export const createRepositoriesManager = (
|
|
34
|
-
|
|
35
|
-
auth: Credentials,
|
|
33
|
+
configuration: SetupConfiguration,
|
|
36
34
|
): RepositoriesManager => {
|
|
37
|
-
return new RepositoriesManager(
|
|
35
|
+
return new RepositoriesManager(configuration);
|
|
38
36
|
};
|
|
39
37
|
|
|
40
38
|
/** Utility object to manage Prismic test data */
|
|
41
39
|
export class RepositoriesManager {
|
|
42
|
-
private readonly
|
|
40
|
+
private readonly config: Omit<SetupConfiguration, "urlConfig"> & {
|
|
41
|
+
urlConfig: UrlConfig;
|
|
42
|
+
};
|
|
43
43
|
private readonly wroomClient: WroomClient;
|
|
44
44
|
private readonly authClient: AuthenticationClient;
|
|
45
|
+
private readonly manageV2Client: ManageV2Client;
|
|
45
46
|
/**
|
|
46
47
|
* helper to keep track of repositories across independent test phases (setup,
|
|
47
48
|
* teardown)
|
|
@@ -51,22 +52,31 @@ export class RepositoriesManager {
|
|
|
51
52
|
);
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
|
-
* @param
|
|
55
|
+
* @param configuration - Global object containing the different configuration
|
|
56
|
+
* required to setup the different clients.
|
|
55
57
|
* @param credentials - Authentication credentials (email and password)
|
|
56
58
|
*/
|
|
57
|
-
constructor(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
) {
|
|
61
|
-
if (typeof urlConfig === "string") {
|
|
59
|
+
constructor(configuration: SetupConfiguration) {
|
|
60
|
+
this.config = {
|
|
61
|
+
...configuration,
|
|
62
62
|
// When a string is provided, treat it as the 'base' property
|
|
63
|
-
urlConfig
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
urlConfig:
|
|
64
|
+
typeof configuration.urlConfig === "string"
|
|
65
|
+
? this.inferUrls(configuration.urlConfig)
|
|
66
|
+
: configuration.urlConfig,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
this.wroomClient = new WroomClient(
|
|
70
|
+
this.config.urlConfig.baseURL,
|
|
71
|
+
this.config.authConfig,
|
|
72
|
+
);
|
|
67
73
|
this.authClient = createAuthenticationApiClient(
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
74
|
+
this.config.urlConfig.authenticationApi,
|
|
75
|
+
this.config.authConfig,
|
|
76
|
+
);
|
|
77
|
+
this.manageV2Client = new ManageV2Client(
|
|
78
|
+
this.config.urlConfig.baseURL,
|
|
79
|
+
this.config.manageV2Config,
|
|
70
80
|
);
|
|
71
81
|
}
|
|
72
82
|
|
|
@@ -82,6 +92,7 @@ export class RepositoriesManager {
|
|
|
82
92
|
baseURL: baseURL,
|
|
83
93
|
authenticationApi: `${protocol}://auth.${url.hostname}`,
|
|
84
94
|
customTypesApi: `${protocol}://customtypes.${url.hostname}`,
|
|
95
|
+
migrationApi: `${protocol}://migration.${url.hostname}`,
|
|
85
96
|
};
|
|
86
97
|
}
|
|
87
98
|
|
|
@@ -149,7 +160,7 @@ export class RepositoriesManager {
|
|
|
149
160
|
const post = async () =>
|
|
150
161
|
this.wroomClient.post(repository, "app/settings/delete", {
|
|
151
162
|
confirm: repository,
|
|
152
|
-
password: this.
|
|
163
|
+
password: this.config.authConfig.password,
|
|
153
164
|
});
|
|
154
165
|
const response = await post();
|
|
155
166
|
if (response.status !== 200) {
|
|
@@ -182,28 +193,26 @@ export class RepositoriesManager {
|
|
|
182
193
|
* @param name - The name of the repository.
|
|
183
194
|
*/
|
|
184
195
|
getRepositoryManager(name: string): RepositoryManager {
|
|
196
|
+
const { urlConfig } = this.config;
|
|
185
197
|
const customTypeClient = createCustomTypesApiClient(
|
|
186
|
-
|
|
198
|
+
urlConfig.customTypesApi,
|
|
187
199
|
name,
|
|
188
200
|
this.authClient,
|
|
189
201
|
);
|
|
190
|
-
const coreApiUrl = getRepositoryUrl(
|
|
202
|
+
const coreApiUrl = getRepositoryUrl(urlConfig.baseURL, name);
|
|
191
203
|
const coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);
|
|
204
|
+
const migrationApiClient = urlConfig.migrationApi
|
|
205
|
+
? createMigrationApiClient(urlConfig.migrationApi, name, this.authClient)
|
|
206
|
+
: undefined;
|
|
192
207
|
|
|
193
208
|
return new RepositoryManager(
|
|
194
209
|
name,
|
|
195
210
|
coreApiClient,
|
|
211
|
+
this.authClient,
|
|
196
212
|
this.wroomClient,
|
|
197
213
|
customTypeClient,
|
|
214
|
+
migrationApiClient,
|
|
215
|
+
this.manageV2Client,
|
|
198
216
|
);
|
|
199
217
|
}
|
|
200
218
|
}
|
|
201
|
-
|
|
202
|
-
export type UrlConfig = {
|
|
203
|
-
/** Prismic base url */
|
|
204
|
-
baseURL: string;
|
|
205
|
-
/** Custom types api base url */
|
|
206
|
-
customTypesApi: string;
|
|
207
|
-
/** Auth service api base url */
|
|
208
|
-
authenticationApi: string;
|
|
209
|
-
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { expect } from "@playwright/test";
|
|
1
2
|
import { AxiosResponse } from "axios";
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -5,8 +6,16 @@ import {
|
|
|
5
6
|
SharedSlice,
|
|
6
7
|
} from "@prismicio/types-internal/lib/customtypes";
|
|
7
8
|
|
|
9
|
+
import type { AuthenticationClient } from "../clients/authenticationApi";
|
|
10
|
+
import { ContentApiClient } from "../clients/contentApi";
|
|
8
11
|
import type { CoreClient } from "../clients/coreApi";
|
|
9
12
|
import { CustomTypesClient } from "../clients/customTypesApi";
|
|
13
|
+
import { ManageV2Client } from "../clients/manageV2";
|
|
14
|
+
import {
|
|
15
|
+
DocumentPayload,
|
|
16
|
+
DocumentResponse,
|
|
17
|
+
MigrationClient,
|
|
18
|
+
} from "../clients/migrationApi";
|
|
10
19
|
import { WroomClient } from "../clients/wroom";
|
|
11
20
|
import { logHttpResponse, logger } from "../utils/log";
|
|
12
21
|
import { getRepositoryUrl } from "../utils/urls";
|
|
@@ -16,8 +25,11 @@ export class RepositoryManager {
|
|
|
16
25
|
constructor(
|
|
17
26
|
readonly name: string,
|
|
18
27
|
private readonly coreApiClient: CoreClient,
|
|
28
|
+
private readonly authApiClient: AuthenticationClient,
|
|
19
29
|
private readonly wroomClient: WroomClient,
|
|
20
30
|
private readonly customTypesApiClient: CustomTypesClient,
|
|
31
|
+
private readonly migrationApiClient: MigrationClient | undefined,
|
|
32
|
+
private readonly manageV2Client: ManageV2Client,
|
|
21
33
|
) {}
|
|
22
34
|
|
|
23
35
|
async configure(config: RepositoryConfig): Promise<void> {
|
|
@@ -65,12 +77,34 @@ export class RepositoryManager {
|
|
|
65
77
|
if (config.preview) {
|
|
66
78
|
await this.createPreview(config.preview);
|
|
67
79
|
}
|
|
80
|
+
|
|
81
|
+
if (config.rolePerLocal) {
|
|
82
|
+
await this.toggleRolePerLocal(true);
|
|
83
|
+
}
|
|
68
84
|
}
|
|
85
|
+
|
|
69
86
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
70
87
|
getBaseURL(): string {
|
|
71
88
|
return getRepositoryUrl(this.wroomClient.getBaseURL(), this.name);
|
|
72
89
|
}
|
|
73
90
|
|
|
91
|
+
/** @returns the repository base cdn url, like https://my-repo.cdn.prismic.io */
|
|
92
|
+
getBaseCdnURL(): string {
|
|
93
|
+
return getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @returns a Content Type api client configured to target the repository CDN
|
|
98
|
+
* url. Uses Playwright for requests so if your project uses Playwright too,
|
|
99
|
+
* any network request will be present in Playwright test reports.
|
|
100
|
+
*/
|
|
101
|
+
getContentApiClient(config?: {
|
|
102
|
+
version?: "v1" | "v2";
|
|
103
|
+
accessToken?: string;
|
|
104
|
+
}): ContentApiClient {
|
|
105
|
+
return new ContentApiClient(this.getBaseCdnURL(), config);
|
|
106
|
+
}
|
|
107
|
+
|
|
74
108
|
/**
|
|
75
109
|
* Set additional standard locales for a repository in Wroom, does not fail if
|
|
76
110
|
* the locales already exist.
|
|
@@ -261,118 +295,276 @@ export class RepositoryManager {
|
|
|
261
295
|
}
|
|
262
296
|
|
|
263
297
|
/**
|
|
264
|
-
* Create
|
|
298
|
+
* Create Custom Types using the Custom types api.
|
|
299
|
+
*
|
|
300
|
+
* @param customTypes -
|
|
301
|
+
*/
|
|
302
|
+
async createCustomTypes(customTypes: CustomType[]): Promise<void> {
|
|
303
|
+
await this.customTypesApiClient.createCustomTypes(customTypes);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Create slices using the Custom types api.
|
|
308
|
+
*
|
|
309
|
+
* @param slices -
|
|
310
|
+
*/
|
|
311
|
+
async createSlices(slices: SharedSlice[]): Promise<void> {
|
|
312
|
+
await this.customTypesApiClient.createSlices(slices);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Create an access token to query private items of the Content api.
|
|
265
317
|
*
|
|
266
|
-
* @
|
|
318
|
+
* @param appName - mandatory authorized application name
|
|
319
|
+
* @param tokenScope - access token scope. Use "master" to when your content
|
|
320
|
+
* api is fully private or "master+releases" to access private releases
|
|
267
321
|
*/
|
|
268
|
-
async
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
secret: string,
|
|
272
|
-
triggers: {
|
|
273
|
-
documentsPublished?: boolean;
|
|
274
|
-
documentsUnpublished?: boolean;
|
|
275
|
-
releasesCreated?: boolean;
|
|
276
|
-
releasesUpdated?: boolean;
|
|
277
|
-
tagsCreated?: boolean;
|
|
278
|
-
tagsDeleted?: boolean;
|
|
279
|
-
},
|
|
280
|
-
active: boolean,
|
|
322
|
+
async createContentAPIToken(
|
|
323
|
+
appName: string,
|
|
324
|
+
tokenScope: "master" | "master+releases" = "master",
|
|
281
325
|
): Promise<string> {
|
|
282
326
|
const profiler = logger.startTimer();
|
|
327
|
+
type AuthorizedAppResponse = {
|
|
328
|
+
id: string;
|
|
329
|
+
name: string;
|
|
330
|
+
wroom_auths: { token: string; scope: "master" | "master+releases" }[];
|
|
331
|
+
};
|
|
332
|
+
const existingApps: AxiosResponse<AuthorizedAppResponse[]> =
|
|
333
|
+
await this.wroomClient.get(this.name, "settings/security/contentapi");
|
|
283
334
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
{
|
|
288
|
-
name,
|
|
289
|
-
url,
|
|
290
|
-
secret,
|
|
291
|
-
active: active ? "on" : "off",
|
|
292
|
-
...triggers,
|
|
293
|
-
},
|
|
335
|
+
this.failIfNot200(
|
|
336
|
+
existingApps,
|
|
337
|
+
`Could not get status of existing applications to generate a content api token`,
|
|
294
338
|
);
|
|
295
|
-
|
|
296
|
-
|
|
339
|
+
let app = existingApps.data.find(({ name, wroom_auths }) => {
|
|
340
|
+
return name === appName && wroom_auths.length > 0;
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
if (!app) {
|
|
344
|
+
const response: AxiosResponse<AuthorizedAppResponse> =
|
|
345
|
+
await this.wroomClient.post(this.name, "settings/security/oauthapp", {
|
|
346
|
+
app_name: appName,
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
this.failIfNot200(
|
|
350
|
+
response,
|
|
351
|
+
`Could not create content api app ${appName}`,
|
|
352
|
+
);
|
|
353
|
+
app = response.data;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope);
|
|
357
|
+
if (!tokenInfo) {
|
|
358
|
+
const response = await this.wroomClient.post(
|
|
359
|
+
this.name,
|
|
360
|
+
"settings/security/authorizations",
|
|
361
|
+
{
|
|
362
|
+
app: app.id,
|
|
363
|
+
scope: tokenScope,
|
|
364
|
+
},
|
|
365
|
+
);
|
|
366
|
+
this.failIfNot200(
|
|
367
|
+
response,
|
|
368
|
+
`Could not create content api access token for app ${appName} with scope ${tokenScope}`,
|
|
369
|
+
);
|
|
370
|
+
tokenInfo = response.data;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
profiler.done({
|
|
374
|
+
message: `content api access token for app '${appName}' created`,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
if (!tokenInfo?.token) {
|
|
378
|
+
throw `Could not create content api access token for app ${appName} with scope ${tokenScope}`;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return tokenInfo.token;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Create a permanent access token to authenticate to Prismic public apis. */
|
|
385
|
+
async createPermanentAccessToken(): Promise<string> {
|
|
386
|
+
const profiler = logger.startTimer();
|
|
387
|
+
|
|
388
|
+
const token = await this.authApiClient.getMachine2MachineToken(this.name);
|
|
389
|
+
|
|
390
|
+
profiler.done({
|
|
391
|
+
message: `machine2machine token created`,
|
|
392
|
+
});
|
|
297
393
|
|
|
298
|
-
return
|
|
394
|
+
return token;
|
|
299
395
|
}
|
|
300
396
|
|
|
301
397
|
/**
|
|
302
|
-
*
|
|
398
|
+
* Toggle the Role per local feature
|
|
303
399
|
*
|
|
304
|
-
* @param
|
|
400
|
+
* @param enabled - The feature new status
|
|
305
401
|
*/
|
|
306
|
-
async
|
|
402
|
+
async toggleRolePerLocal(enabled: boolean): Promise<void> {
|
|
307
403
|
const profiler = logger.startTimer();
|
|
308
404
|
|
|
309
|
-
const response = await this.
|
|
310
|
-
this.name,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
);
|
|
405
|
+
const response = await this.manageV2Client.toggleRolePerLocal({
|
|
406
|
+
repository: this.name,
|
|
407
|
+
enabled: enabled,
|
|
408
|
+
});
|
|
314
409
|
|
|
315
|
-
this.failIfNot200(
|
|
316
|
-
|
|
410
|
+
this.failIfNot200(
|
|
411
|
+
response,
|
|
412
|
+
`Could not ${enabled ? "enable" : "disable"} Role per local for ${
|
|
413
|
+
this.name
|
|
414
|
+
}`,
|
|
415
|
+
);
|
|
416
|
+
profiler.done({
|
|
417
|
+
message: `Role per local ${enabled ? "enabled" : "disabled"}`,
|
|
418
|
+
});
|
|
317
419
|
}
|
|
318
420
|
|
|
319
421
|
/**
|
|
320
|
-
*
|
|
422
|
+
* Change the Repository Plan
|
|
321
423
|
*
|
|
322
|
-
* @param
|
|
424
|
+
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
323
425
|
*/
|
|
324
|
-
async
|
|
325
|
-
|
|
426
|
+
async changePlan(newPlanId: string): Promise<void> {
|
|
427
|
+
const profiler = logger.startTimer();
|
|
428
|
+
|
|
429
|
+
const response = await this.manageV2Client.changePlan({
|
|
430
|
+
repository: this.name,
|
|
431
|
+
newPlanId: newPlanId,
|
|
432
|
+
bypassManualBilling: true, // For now the library does not support Stripe features
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
this.failIfNot200(response, "Could not change the Repository Plan");
|
|
436
|
+
profiler.done({
|
|
437
|
+
message: `Repository Plan changed to ${newPlanId}`,
|
|
438
|
+
});
|
|
326
439
|
}
|
|
327
440
|
|
|
328
441
|
/**
|
|
329
|
-
*
|
|
442
|
+
* Add a new user to the repository
|
|
330
443
|
*
|
|
331
|
-
* @param
|
|
444
|
+
* @param {string} email - The email of the user
|
|
332
445
|
*/
|
|
333
|
-
async
|
|
334
|
-
|
|
446
|
+
async addUser(email: string): Promise<void> {
|
|
447
|
+
const profiler = logger.startTimer();
|
|
448
|
+
|
|
449
|
+
const response = await this.manageV2Client.addUserToRepository({
|
|
450
|
+
repository: this.name,
|
|
451
|
+
email: email,
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const { data, status } = response;
|
|
455
|
+
const success =
|
|
456
|
+
status === 200 ||
|
|
457
|
+
(status === 409 &&
|
|
458
|
+
JSON.stringify(data).includes("already a member of the repo"));
|
|
459
|
+
if (!success) {
|
|
460
|
+
logHttpResponse(response);
|
|
461
|
+
throw new Error(`Could not add a new user ${email} to the repository`);
|
|
462
|
+
}
|
|
463
|
+
profiler.done({
|
|
464
|
+
message: `User ${email} was added to the repository`,
|
|
465
|
+
});
|
|
335
466
|
}
|
|
336
467
|
|
|
337
468
|
/**
|
|
338
|
-
*
|
|
469
|
+
* Remove a user from the repository
|
|
339
470
|
*
|
|
340
|
-
* @param
|
|
471
|
+
* @param {string} email - The email of the user
|
|
341
472
|
*/
|
|
342
|
-
async
|
|
473
|
+
async removeUser(email: string): Promise<void> {
|
|
343
474
|
const profiler = logger.startTimer();
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
await this.wroomClient.get(this.name, "settings/security/contentapi");
|
|
475
|
+
|
|
476
|
+
const response = await this.manageV2Client.removeUserFromRepository({
|
|
477
|
+
repository: this.name,
|
|
478
|
+
email: email,
|
|
479
|
+
});
|
|
350
480
|
|
|
351
481
|
this.failIfNot200(
|
|
352
|
-
|
|
353
|
-
`Could not
|
|
482
|
+
response,
|
|
483
|
+
`Could not remove the user ${email} from the repository`,
|
|
354
484
|
);
|
|
355
|
-
|
|
356
|
-
|
|
485
|
+
profiler.done({
|
|
486
|
+
message: `User ${email} was removed from the repository`,
|
|
357
487
|
});
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Update the role of a user in a repository
|
|
492
|
+
*
|
|
493
|
+
* @param {string} email - The email of the user
|
|
494
|
+
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
495
|
+
* either a string for basic workflow or an object such as `{ "lang_id":
|
|
496
|
+
* "Writer" }`
|
|
497
|
+
*
|
|
498
|
+
* Example of roles are
|
|
499
|
+
*
|
|
500
|
+
* - Administrator
|
|
501
|
+
* - Writer
|
|
502
|
+
* - Contributor
|
|
503
|
+
* - Manager (publisher)
|
|
504
|
+
*/
|
|
505
|
+
async updateUserRole(
|
|
506
|
+
email: string,
|
|
507
|
+
role: string | Record<string, string>,
|
|
508
|
+
): Promise<void> {
|
|
509
|
+
const profiler = logger.startTimer();
|
|
510
|
+
|
|
511
|
+
const response =
|
|
512
|
+
typeof role === "string"
|
|
513
|
+
? await this.wroomClient.updateRole(this.name, email, role)
|
|
514
|
+
: await this.wroomClient.updateRolePerLocal(this.name, email, role);
|
|
365
515
|
|
|
366
516
|
this.failIfNot200(
|
|
367
517
|
response,
|
|
368
|
-
`Could not
|
|
518
|
+
`Could not update the ${
|
|
519
|
+
typeof role === "string" ? "role" : "rolePerLocal"
|
|
520
|
+
} of the user ${email}`,
|
|
369
521
|
);
|
|
370
522
|
profiler.done({
|
|
371
|
-
message: `
|
|
523
|
+
message: `Updated User's ${
|
|
524
|
+
typeof role === "string" ? "role" : "rolePerLocal"
|
|
525
|
+
} for user ${email}`,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Creates a document using the migration api, see
|
|
531
|
+
* https://prismic.io/docs/migration-api-technical-reference
|
|
532
|
+
*
|
|
533
|
+
* @param {DocumentPayload} document - in the migration api format
|
|
534
|
+
* @param {string} status - status of the document, if published, the function
|
|
535
|
+
* will wait for a new content api master ref to be created
|
|
536
|
+
*
|
|
537
|
+
* @returns
|
|
538
|
+
*/
|
|
539
|
+
async createDocument(
|
|
540
|
+
document: DocumentPayload,
|
|
541
|
+
status: "draft" | "published",
|
|
542
|
+
): Promise<DocumentResponse> {
|
|
543
|
+
if (!this.migrationApiClient) {
|
|
544
|
+
throw "No client found for the migration api. Did you provide a migration api url in your configuration?";
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const profiler = logger.startTimer();
|
|
548
|
+
|
|
549
|
+
const result = await this.migrationApiClient.createDocument(document);
|
|
550
|
+
let message = `Document created with id '${result.id}'`;
|
|
551
|
+
if (status === "published") {
|
|
552
|
+
const contentApi = this.getContentApiClient();
|
|
553
|
+
const masterRef = await contentApi.getMasterRef();
|
|
554
|
+
await this.coreApiClient.publishDraft(result.id);
|
|
555
|
+
await expect
|
|
556
|
+
.poll(async () => contentApi.getMasterRef(), {
|
|
557
|
+
timeout: 10_000,
|
|
558
|
+
message: "Waiting for new master ref to be available",
|
|
559
|
+
})
|
|
560
|
+
.not.toBe(masterRef);
|
|
561
|
+
message += ", status 'published' and new master ref available";
|
|
562
|
+
}
|
|
563
|
+
profiler.done({
|
|
564
|
+
message,
|
|
372
565
|
});
|
|
373
566
|
|
|
374
|
-
|
|
375
|
-
return response.data.wroom_auths[0].token;
|
|
567
|
+
return result;
|
|
376
568
|
}
|
|
377
569
|
}
|
|
378
570
|
|
|
@@ -383,6 +575,7 @@ export type RepositoryConfig = {
|
|
|
383
575
|
slices?: SharedSlice[];
|
|
384
576
|
customTypes?: CustomType[];
|
|
385
577
|
preview?: Preview;
|
|
578
|
+
rolePerLocal?: boolean;
|
|
386
579
|
};
|
|
387
580
|
|
|
388
581
|
export type Preview = {
|
package/src/types.ts
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type UrlConfig = {
|
|
2
|
+
/** Prismic base url */
|
|
3
|
+
baseURL: string;
|
|
4
|
+
/** Custom types api base url */
|
|
5
|
+
customTypesApi: string;
|
|
6
|
+
/** Auth service api base url */
|
|
7
|
+
authenticationApi: string;
|
|
8
|
+
/** Prismic migration api base url */
|
|
9
|
+
migrationApi?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type AuthConfig = {
|
|
13
|
+
email: string;
|
|
14
|
+
password: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ManageV2Config = {
|
|
18
|
+
secret: string;
|
|
19
|
+
audience: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Global configuration Object
|
|
23
|
+
export type SetupConfiguration = {
|
|
24
|
+
// If provided as a string: It is treated as the base URL for Prismic. Other
|
|
25
|
+
// URLs (Custom Types API, Auth API) will be derived from it.
|
|
26
|
+
urlConfig: UrlConfig | string;
|
|
27
|
+
authConfig: AuthConfig;
|
|
28
|
+
manageV2Config?: ManageV2Config;
|
|
29
|
+
};
|