@prismicio/e2e-tests-utils 1.3.2 → 1.4.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/README.md +16 -9
- package/dist/clients/apiClient.cjs +39 -0
- package/dist/clients/apiClient.cjs.map +1 -0
- package/dist/clients/apiClient.d.ts +30 -0
- package/dist/clients/apiClient.js +39 -0
- package/dist/clients/apiClient.js.map +1 -0
- package/dist/clients/authenticationApi.cjs +54 -34
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.ts +13 -5
- package/dist/clients/authenticationApi.js +55 -35
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +12 -48
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.d.ts +5 -6
- package/dist/clients/contentApi.js +12 -48
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +36 -31
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +21 -3
- package/dist/clients/coreApi.js +37 -32
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +48 -42
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.d.ts +34 -6
- package/dist/clients/customTypesApi.js +49 -43
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/migrationApi.cjs +30 -29
- package/dist/clients/migrationApi.cjs.map +1 -1
- package/dist/clients/migrationApi.d.ts +25 -5
- package/dist/clients/migrationApi.js +31 -30
- package/dist/clients/migrationApi.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/managers/repositories.cjs +19 -9
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.ts +2 -2
- package/dist/managers/repositories.js +23 -13
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +5 -0
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +6 -4
- package/dist/managers/repository.js +5 -0
- package/dist/managers/repository.js.map +1 -1
- package/dist/utils/log.cjs +4 -0
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.d.ts +2 -0
- package/dist/utils/log.js +4 -0
- package/dist/utils/log.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/apiClient.ts +48 -0
- package/src/clients/authenticationApi.ts +52 -50
- package/src/clients/contentApi.ts +18 -24
- package/src/clients/coreApi.ts +36 -42
- package/src/clients/customTypesApi.ts +34 -59
- package/src/clients/migrationApi.ts +33 -45
- package/src/managers/repositories.ts +26 -20
- package/src/managers/repository.ts +17 -7
- package/src/utils/log.ts +11 -0
|
@@ -1,82 +1,84 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { APIRequestContext, request } from "@playwright/test";
|
|
2
2
|
|
|
3
3
|
import { AuthConfig } from "../types";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export type AuthenticationClient = {
|
|
8
|
-
getToken: () => Promise<string>;
|
|
9
|
-
getMachine2MachineToken: (repository: string) => Promise<string>;
|
|
10
|
-
};
|
|
5
|
+
import { logPlaywrightApiResponse, logger } from "../utils/log";
|
|
11
6
|
|
|
12
7
|
/** Client for interacting with the authentication service to manage tokens */
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
export class AuthenticationApiClient {
|
|
9
|
+
private authToken?: string;
|
|
10
|
+
private _context?: APIRequestContext;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
private readonly baseURL: string,
|
|
14
|
+
private readonly auth: AuthConfig,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
private async getContext(): Promise<APIRequestContext> {
|
|
18
|
+
if (!this._context) {
|
|
19
|
+
this._context = await request.newContext({
|
|
20
|
+
baseURL: this.baseURL,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return this._context;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async login(): Promise<string> {
|
|
25
28
|
const profiler = logger.startTimer();
|
|
26
29
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const context = await this.getContext();
|
|
31
|
+
const result = await context.post("login", {
|
|
32
|
+
data: {
|
|
33
|
+
email: this.auth.email,
|
|
34
|
+
password: this.auth.password,
|
|
35
|
+
},
|
|
30
36
|
});
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
const token = await result.text();
|
|
39
|
+
if (!result.ok() || !token) {
|
|
40
|
+
logPlaywrightApiResponse(result);
|
|
34
41
|
throw new Error("Authentication failed, no token received.");
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
profiler.done({
|
|
38
|
-
message: `generated user token for ${auth.email} from auth service`,
|
|
45
|
+
message: `generated user token for ${this.auth.email} from auth service`,
|
|
39
46
|
});
|
|
40
47
|
|
|
41
|
-
return
|
|
48
|
+
return token;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
/** Return an api user token. Creates one if needed. */
|
|
45
|
-
async
|
|
46
|
-
if (!authToken) {
|
|
47
|
-
authToken = await login();
|
|
52
|
+
async getToken(): Promise<string> {
|
|
53
|
+
if (!this.authToken) {
|
|
54
|
+
this.authToken = await this.login();
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
return authToken;
|
|
57
|
+
return this.authToken;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
/** Return an api user token. Creates one if needed. */
|
|
54
|
-
async
|
|
55
|
-
if (!authToken) {
|
|
56
|
-
authToken = await login();
|
|
61
|
+
async getMachine2MachineToken(repository: string): Promise<string> {
|
|
62
|
+
if (!this.authToken) {
|
|
63
|
+
this.authToken = await this.login();
|
|
57
64
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
+
|
|
66
|
+
const context = await this.getContext();
|
|
67
|
+
const result = await context.get("machine2machine", {
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
70
|
+
repository,
|
|
65
71
|
},
|
|
66
|
-
);
|
|
72
|
+
});
|
|
67
73
|
|
|
68
|
-
if (!
|
|
69
|
-
|
|
74
|
+
if (!result.ok()) {
|
|
75
|
+
logPlaywrightApiResponse(result);
|
|
70
76
|
throw new Error(
|
|
71
77
|
"Machine2Machine token generation failed, no token received.",
|
|
72
78
|
);
|
|
73
79
|
}
|
|
80
|
+
const token = (await result.json()).token;
|
|
74
81
|
|
|
75
|
-
return
|
|
82
|
+
return token;
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
getToken,
|
|
80
|
-
getMachine2MachineToken,
|
|
81
|
-
};
|
|
82
|
-
};
|
|
84
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { APIResponse
|
|
1
|
+
import { APIResponse } from "@playwright/test";
|
|
2
|
+
|
|
3
|
+
import { AuthenticatedApiClient } from "./apiClient";
|
|
2
4
|
|
|
3
5
|
export interface ContentApiError {
|
|
4
6
|
type: string;
|
|
@@ -80,14 +82,12 @@ type ApiVersions = "v1" | "v2";
|
|
|
80
82
|
|
|
81
83
|
/**
|
|
82
84
|
* Client to query the Prismic content api. Uses Playwright to benefit from
|
|
83
|
-
* network request traces in your reports.
|
|
84
|
-
* have been used but had too many abstractions (caching, error handling) that
|
|
85
|
-
* we didn't want for test execution. See api docs:
|
|
85
|
+
* network request traces in your reports. See api docs:
|
|
86
86
|
* https://prismic.io/docs/rest-api-technical-reference
|
|
87
87
|
*/
|
|
88
|
-
export class ContentApiClient {
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
export class ContentApiClient extends AuthenticatedApiClient {
|
|
89
|
+
private version: ApiVersions;
|
|
90
|
+
private accessToken: string | undefined;
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* @example To instantiate the class:
|
|
@@ -107,20 +107,14 @@ export class ContentApiClient {
|
|
|
107
107
|
* https://prismic.io/docs/access-token
|
|
108
108
|
*/
|
|
109
109
|
constructor(
|
|
110
|
-
|
|
110
|
+
baseURL: string,
|
|
111
111
|
config: { version?: ApiVersions; accessToken?: string } = {},
|
|
112
112
|
) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return request.newContext({
|
|
119
|
-
baseURL: this.baseURL,
|
|
120
|
-
// reset any Authorization header set globally with Playwright
|
|
121
|
-
// didn't find a way to delete it
|
|
122
|
-
extraHTTPHeaders: { Authorization: "" },
|
|
123
|
-
});
|
|
113
|
+
// Use an empty string as auth header in case it is already set globally in the project Playwright config file.
|
|
114
|
+
// This is because the api returns an error whenever an auth header is present in the content api request.
|
|
115
|
+
super(baseURL, "");
|
|
116
|
+
this.version = config.version || "v2";
|
|
117
|
+
this.accessToken = config.accessToken;
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
async get(
|
|
@@ -128,9 +122,9 @@ export class ContentApiClient {
|
|
|
128
122
|
params?: SearchQueryParams,
|
|
129
123
|
headers?: Record<string, string>,
|
|
130
124
|
): Promise<APIResponse> {
|
|
131
|
-
const context = await this
|
|
125
|
+
const context = await this.getContext();
|
|
132
126
|
const securityParams = {
|
|
133
|
-
...(this
|
|
127
|
+
...(this.accessToken ? { access_token: this.accessToken } : {}),
|
|
134
128
|
};
|
|
135
129
|
|
|
136
130
|
return context.get(path, {
|
|
@@ -155,7 +149,7 @@ export class ContentApiClient {
|
|
|
155
149
|
query: string,
|
|
156
150
|
): Promise<ContentApiGraphQLResponse> {
|
|
157
151
|
return this.getAsJson<ContentApiGraphQLResponse>(
|
|
158
|
-
"
|
|
152
|
+
"graphql",
|
|
159
153
|
{ query },
|
|
160
154
|
{ "Prismic-ref": ref },
|
|
161
155
|
);
|
|
@@ -163,7 +157,7 @@ export class ContentApiClient {
|
|
|
163
157
|
|
|
164
158
|
async getRefs(): Promise<ContentApiRef[]> {
|
|
165
159
|
const data = await this.getAsJson<ContentApiRepoConfigResponse>(
|
|
166
|
-
|
|
160
|
+
`api/${this.version}`,
|
|
167
161
|
);
|
|
168
162
|
|
|
169
163
|
return data.refs;
|
|
@@ -198,7 +192,7 @@ export class ContentApiClient {
|
|
|
198
192
|
}
|
|
199
193
|
|
|
200
194
|
return this.getAsJson<ContentApiSearchResponse>(
|
|
201
|
-
|
|
195
|
+
`api/${this.version}/documents/search`,
|
|
202
196
|
{
|
|
203
197
|
...filters,
|
|
204
198
|
ref,
|
package/src/clients/coreApi.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { logPlaywrightApiResponse, logger } from "../utils/log";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { AuthenticationClient } from "./authenticationApi";
|
|
3
|
+
import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
|
|
6
4
|
|
|
7
5
|
type Language = {
|
|
8
6
|
id: string;
|
|
@@ -15,56 +13,52 @@ export type CoreClient = {
|
|
|
15
13
|
publishDraft(documentId: string): Promise<void>;
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
16
|
+
export class CoreApiClient extends AuthenticatedApiClient {
|
|
17
|
+
/**
|
|
18
|
+
* @example To instantiate the class:
|
|
19
|
+
*
|
|
20
|
+
* ```js
|
|
21
|
+
* new CoreApiClient("https://my-repo.prismic.io", {
|
|
22
|
+
* authToken: "my-secret-token",
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param baseURL - the api base URL like https://my-repo.prismic.io
|
|
27
|
+
* @param config - Optional configuration
|
|
28
|
+
*
|
|
29
|
+
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
30
|
+
* function to fetch it when it's needed.
|
|
31
|
+
*/
|
|
32
|
+
constructor(baseURL: string, config: AuthServerToken) {
|
|
33
|
+
super(baseURL, config);
|
|
34
|
+
}
|
|
38
35
|
|
|
39
|
-
async
|
|
36
|
+
async getLanguages(): Promise<Language[]> {
|
|
40
37
|
const profiler = logger.startTimer();
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
);
|
|
38
|
+
const context = await this.getContext();
|
|
39
|
+
const result = await context.get("core/repository");
|
|
44
40
|
|
|
45
|
-
if (200 !== result.status || !result.
|
|
46
|
-
|
|
41
|
+
if (200 !== result.status() || !(await result.json()).languages) {
|
|
42
|
+
await logPlaywrightApiResponse(result);
|
|
47
43
|
throw new Error("Could not get languages from the core api.");
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
profiler.done({ message: "retrieved languages configuration" });
|
|
51
47
|
|
|
52
|
-
return result.
|
|
48
|
+
return (await result.json()).languages;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
async
|
|
56
|
-
const
|
|
57
|
-
|
|
51
|
+
async publishDraft(documentId: string): Promise<void> {
|
|
52
|
+
const context = await this.getContext();
|
|
53
|
+
const result = await context.patch(`core/documents/${documentId}/draft`, {
|
|
54
|
+
data: {
|
|
55
|
+
status: "published",
|
|
56
|
+
},
|
|
58
57
|
});
|
|
59
58
|
|
|
60
|
-
if (204 !== result.status) {
|
|
61
|
-
|
|
59
|
+
if (204 !== result.status()) {
|
|
60
|
+
await logPlaywrightApiResponse(result);
|
|
62
61
|
throw new Error(`Could not publish document with id ${documentId}`);
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
getLanguages,
|
|
68
|
-
publishDraft,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
64
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios, { AxiosInstance } from "axios";
|
|
2
1
|
import isEqual from "lodash.isequal";
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -6,46 +5,25 @@ import {
|
|
|
6
5
|
SharedSlice,
|
|
7
6
|
} from "@prismicio/types-internal/lib/customtypes";
|
|
8
7
|
|
|
9
|
-
import {
|
|
8
|
+
import { logPlaywrightApiResponse, logger } from "../utils/log";
|
|
10
9
|
|
|
11
|
-
import {
|
|
10
|
+
import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
12
|
+
type ItemType = CustomType | SharedSlice;
|
|
13
|
+
type ItemTypePath = "customtypes" | "slices";
|
|
14
|
+
type ItemOperation = "insert" | "update";
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
17
|
* Client for interacting with the Custom Types API to create/update custom
|
|
20
18
|
* types and slices.
|
|
21
19
|
*/
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type ItemOperation = "insert" | "update";
|
|
30
|
-
|
|
31
|
-
const client: AxiosInstance = axios.create({
|
|
32
|
-
baseURL,
|
|
33
|
-
validateStatus: () => true, // Don't throw on 4XX errors
|
|
34
|
-
headers: {
|
|
35
|
-
repository,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Add an interceptor to authenticate requests
|
|
40
|
-
client.interceptors.request.use(async (config) => {
|
|
41
|
-
const auth = "Authorization";
|
|
42
|
-
if (!config.headers[auth]) {
|
|
43
|
-
const token = await authClient.getToken();
|
|
44
|
-
config.headers[auth] = `Bearer ${token}`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return config;
|
|
48
|
-
});
|
|
20
|
+
export class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
21
|
+
constructor(
|
|
22
|
+
baseURL: string,
|
|
23
|
+
config: { authToken: AuthServerToken; repository: string },
|
|
24
|
+
) {
|
|
25
|
+
super(baseURL, config.authToken, { repository: config.repository });
|
|
26
|
+
}
|
|
49
27
|
|
|
50
28
|
/**
|
|
51
29
|
* Create or update a custom type or slice.
|
|
@@ -57,7 +35,7 @@ export const createCustomTypesApiClient = (
|
|
|
57
35
|
* @throws Error if the item status cannot be retrieved or the item cannot be
|
|
58
36
|
* created/updated.
|
|
59
37
|
*/
|
|
60
|
-
async
|
|
38
|
+
private async upsert(
|
|
61
39
|
endpoint: ItemTypePath,
|
|
62
40
|
operation: ItemOperation,
|
|
63
41
|
data: ItemType,
|
|
@@ -65,9 +43,10 @@ export const createCustomTypesApiClient = (
|
|
|
65
43
|
const profiler = logger.startTimer();
|
|
66
44
|
const path = `${endpoint}/${operation}`;
|
|
67
45
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
const context = await this.getContext();
|
|
47
|
+
const result = await context.post(path, { data });
|
|
48
|
+
if (!result.ok()) {
|
|
49
|
+
logPlaywrightApiResponse(result);
|
|
71
50
|
throw new Error(`Could not ${operation} item`);
|
|
72
51
|
}
|
|
73
52
|
profiler.done({
|
|
@@ -75,20 +54,21 @@ export const createCustomTypesApiClient = (
|
|
|
75
54
|
});
|
|
76
55
|
}
|
|
77
56
|
|
|
78
|
-
async
|
|
57
|
+
private async getRemoteItems(
|
|
79
58
|
endpoint: ItemTypePath,
|
|
80
59
|
): Promise<CustomType[] | SharedSlice[]> {
|
|
81
|
-
const
|
|
60
|
+
const context = await this.getContext();
|
|
61
|
+
const result = await context.get(endpoint);
|
|
82
62
|
|
|
83
|
-
if (!
|
|
84
|
-
|
|
63
|
+
if (!result.ok()) {
|
|
64
|
+
logPlaywrightApiResponse(result);
|
|
85
65
|
throw new Error("Could not get items status from the Custom Type api.");
|
|
86
66
|
}
|
|
87
67
|
|
|
88
|
-
return result.
|
|
68
|
+
return result.json();
|
|
89
69
|
}
|
|
90
70
|
|
|
91
|
-
async
|
|
71
|
+
private async getDifference(
|
|
92
72
|
remoteItems: CustomType[] | SharedSlice[],
|
|
93
73
|
local: ItemType,
|
|
94
74
|
): Promise<ItemOperation | undefined> {
|
|
@@ -106,16 +86,16 @@ export const createCustomTypesApiClient = (
|
|
|
106
86
|
}
|
|
107
87
|
|
|
108
88
|
/** Create items only if they have changed compared to their remote status */
|
|
109
|
-
async
|
|
89
|
+
private async upsertIfChanged(
|
|
110
90
|
itemType: ItemTypePath,
|
|
111
91
|
localItems: ItemType[] = [],
|
|
112
|
-
) {
|
|
113
|
-
const remoteItems = await getRemoteItems(itemType);
|
|
92
|
+
): Promise<void> {
|
|
93
|
+
const remoteItems = await this.getRemoteItems(itemType);
|
|
114
94
|
await Promise.all(
|
|
115
95
|
localItems.map(async (localItem) => {
|
|
116
|
-
const operation = await getDifference(remoteItems, localItem);
|
|
96
|
+
const operation = await this.getDifference(remoteItems, localItem);
|
|
117
97
|
|
|
118
|
-
return operation && upsert(itemType, operation, localItem);
|
|
98
|
+
return operation && this.upsert(itemType, operation, localItem);
|
|
119
99
|
}),
|
|
120
100
|
);
|
|
121
101
|
}
|
|
@@ -125,8 +105,8 @@ export const createCustomTypesApiClient = (
|
|
|
125
105
|
*
|
|
126
106
|
* @param customTypes -
|
|
127
107
|
*/
|
|
128
|
-
async
|
|
129
|
-
await upsertIfChanged("customtypes", customTypes);
|
|
108
|
+
async createCustomTypes(customTypes: CustomType[] = []): Promise<void> {
|
|
109
|
+
await this.upsertIfChanged("customtypes", customTypes);
|
|
130
110
|
}
|
|
131
111
|
|
|
132
112
|
/**
|
|
@@ -134,12 +114,7 @@ export const createCustomTypesApiClient = (
|
|
|
134
114
|
*
|
|
135
115
|
* @param slices -
|
|
136
116
|
*/
|
|
137
|
-
async
|
|
138
|
-
await upsertIfChanged("slices", slices);
|
|
117
|
+
async createSlices(slices: SharedSlice[] = []): Promise<void> {
|
|
118
|
+
await this.upsertIfChanged("slices", slices);
|
|
139
119
|
}
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
createCustomTypes,
|
|
143
|
-
createSlices,
|
|
144
|
-
};
|
|
145
|
-
};
|
|
120
|
+
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { logPlaywrightApiResponse } from "../utils/log";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { AuthenticationClient } from "./authenticationApi";
|
|
6
|
-
|
|
7
|
-
export type MigrationClient = {
|
|
8
|
-
createDocument(data: DocumentPayload): Promise<DocumentResponse>;
|
|
9
|
-
};
|
|
3
|
+
import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
|
|
10
4
|
|
|
11
5
|
export type DocumentPayload = {
|
|
12
6
|
uid?: string | null;
|
|
@@ -19,7 +13,6 @@ export type DocumentPayload = {
|
|
|
19
13
|
// if true, the document will be part of the documents list instead of in the migration release
|
|
20
14
|
inDocuments?: boolean;
|
|
21
15
|
};
|
|
22
|
-
|
|
23
16
|
export type DocumentResponse = {
|
|
24
17
|
id: string;
|
|
25
18
|
type: string;
|
|
@@ -28,45 +21,40 @@ export type DocumentResponse = {
|
|
|
28
21
|
uid?: string;
|
|
29
22
|
};
|
|
30
23
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
config
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
24
|
+
export class MigrationApiClient extends AuthenticatedApiClient {
|
|
25
|
+
/**
|
|
26
|
+
* @example To instantiate the class:
|
|
27
|
+
*
|
|
28
|
+
* ```js
|
|
29
|
+
* new MigrationApiClient("https://migration.prismic.io", {
|
|
30
|
+
* authToken: "my-secret-token",
|
|
31
|
+
* repository: "my-repo-name",
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param baseURL - the api base URL like https://migration.prismic.io
|
|
36
|
+
* @param config - Optional configuration
|
|
37
|
+
*
|
|
38
|
+
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
39
|
+
* function to fetch it when it's needed.
|
|
40
|
+
* - {@link config.repository}: Repository name.
|
|
41
|
+
*/
|
|
42
|
+
constructor(
|
|
43
|
+
baseURL: string,
|
|
44
|
+
config: { authToken: AuthServerToken; repository: string },
|
|
45
|
+
) {
|
|
46
|
+
super(baseURL, config.authToken, { repository: config.repository });
|
|
47
|
+
}
|
|
55
48
|
|
|
56
|
-
async
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const result = await client.post<DocumentResponse>("/documents", data);
|
|
49
|
+
async createDocument(data: DocumentPayload): Promise<DocumentResponse> {
|
|
50
|
+
const context = await this.getContext();
|
|
51
|
+
const result = await context.post("documents", { data });
|
|
60
52
|
|
|
61
|
-
if (201 !== result.status) {
|
|
62
|
-
|
|
53
|
+
if (201 !== result.status()) {
|
|
54
|
+
await logPlaywrightApiResponse(result);
|
|
63
55
|
throw new Error("Could not create a document with the migration api.");
|
|
64
56
|
}
|
|
65
57
|
|
|
66
|
-
return result.
|
|
58
|
+
return result.json();
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
createDocument,
|
|
71
|
-
};
|
|
72
|
-
};
|
|
60
|
+
}
|