@prismicio/e2e-tests-utils 1.18.0 → 1.19.0-canary.d349d21
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 +24 -27
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/clients/apiClient.cjs +38 -38
- package/dist/clients/apiClient.cjs.map +1 -1
- package/dist/clients/apiClient.d.cts +30 -0
- package/dist/clients/apiClient.d.cts.map +1 -0
- package/dist/clients/apiClient.d.ts +23 -23
- package/dist/clients/apiClient.d.ts.map +1 -0
- package/dist/clients/apiClient.js +38 -38
- package/dist/clients/apiClient.js.map +1 -1
- package/dist/clients/assetApi.cjs +81 -93
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.cts +105 -0
- package/dist/clients/assetApi.d.cts.map +1 -0
- package/dist/clients/assetApi.d.ts +96 -97
- package/dist/clients/assetApi.d.ts.map +1 -0
- package/dist/clients/assetApi.js +79 -91
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/authenticationApi.cjs +66 -73
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.cts +20 -0
- package/dist/clients/authenticationApi.d.cts.map +1 -0
- package/dist/clients/authenticationApi.d.ts +18 -13
- package/dist/clients/authenticationApi.d.ts.map +1 -0
- package/dist/clients/authenticationApi.js +65 -72
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +94 -103
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.d.cts +116 -0
- package/dist/clients/contentApi.d.cts.map +1 -0
- package/dist/clients/contentApi.d.ts +102 -98
- package/dist/clients/contentApi.d.ts.map +1 -0
- package/dist/clients/contentApi.js +94 -103
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +154 -145
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.cts +143 -0
- package/dist/clients/coreApi.d.cts.map +1 -0
- package/dist/clients/coreApi.d.ts +132 -109
- package/dist/clients/coreApi.d.ts.map +1 -0
- package/dist/clients/coreApi.js +153 -144
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +90 -99
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.d.cts +46 -0
- package/dist/clients/customTypesApi.d.cts.map +1 -0
- package/dist/clients/customTypesApi.d.ts +45 -45
- package/dist/clients/customTypesApi.d.ts.map +1 -0
- package/dist/clients/customTypesApi.js +87 -98
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/integrationFields.cjs +96 -87
- package/dist/clients/integrationFields.cjs.map +1 -1
- package/dist/clients/integrationFields.d.cts +30 -0
- package/dist/clients/integrationFields.d.cts.map +1 -0
- package/dist/clients/integrationFields.d.ts +27 -22
- package/dist/clients/integrationFields.d.ts.map +1 -0
- package/dist/clients/integrationFields.js +93 -86
- package/dist/clients/integrationFields.js.map +1 -1
- package/dist/clients/manageV2.cjs +154 -171
- package/dist/clients/manageV2.cjs.map +1 -1
- package/dist/clients/manageV2.d.cts +105 -0
- package/dist/clients/manageV2.d.cts.map +1 -0
- package/dist/clients/manageV2.d.ts +103 -111
- package/dist/clients/manageV2.d.ts.map +1 -0
- package/dist/clients/manageV2.js +149 -169
- package/dist/clients/manageV2.js.map +1 -1
- package/dist/clients/migrationApi.cjs +37 -36
- package/dist/clients/migrationApi.cjs.map +1 -1
- package/dist/clients/migrationApi.d.cts +48 -0
- package/dist/clients/migrationApi.d.cts.map +1 -0
- package/dist/clients/migrationApi.d.ts +45 -39
- package/dist/clients/migrationApi.d.ts.map +1 -0
- package/dist/clients/migrationApi.js +35 -34
- package/dist/clients/migrationApi.js.map +1 -1
- package/dist/clients/wroom.cjs +101 -122
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.cts +48 -0
- package/dist/clients/wroom.d.cts.map +1 -0
- package/dist/clients/wroom.d.ts +46 -47
- package/dist/clients/wroom.d.ts.map +1 -0
- package/dist/clients/wroom.js +99 -122
- package/dist/clients/wroom.js.map +1 -1
- package/dist/index.cjs +13 -15
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +5 -14
- package/dist/managers/repositories.cjs +159 -169
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.cts +67 -0
- package/dist/managers/repositories.d.cts.map +1 -0
- package/dist/managers/repositories.d.ts +56 -63
- package/dist/managers/repositories.d.ts.map +1 -0
- package/dist/managers/repositories.js +148 -159
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +595 -616
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.cts +341 -0
- package/dist/managers/repository.d.cts.map +1 -0
- package/dist/managers/repository.d.ts +336 -307
- package/dist/managers/repository.d.ts.map +1 -0
- package/dist/managers/repository.js +595 -616
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.cts +41 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +35 -37
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/cookies.cjs +19 -17
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js +20 -18
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/envVariableManager.cjs +33 -34
- package/dist/utils/envVariableManager.cjs.map +1 -1
- package/dist/utils/envVariableManager.js +34 -35
- package/dist/utils/envVariableManager.js.map +1 -1
- package/dist/utils/log.cjs +18 -19
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.js +18 -21
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/random.cjs +13 -6
- package/dist/utils/random.cjs.map +1 -1
- package/dist/utils/random.js +13 -6
- package/dist/utils/random.js.map +1 -1
- package/dist/utils/strings.cjs +13 -7
- package/dist/utils/strings.cjs.map +1 -1
- package/dist/utils/strings.js +14 -8
- package/dist/utils/strings.js.map +1 -1
- package/dist/utils/urls.cjs +21 -10
- package/dist/utils/urls.cjs.map +1 -1
- package/dist/utils/urls.js +22 -12
- package/dist/utils/urls.js.map +1 -1
- package/package.json +42 -67
- package/src/clients/apiClient.ts +16 -21
- package/src/clients/assetApi.ts +75 -82
- package/src/clients/authenticationApi.ts +54 -27
- package/src/clients/contentApi.ts +111 -129
- package/src/clients/coreApi.ts +166 -117
- package/src/clients/customTypesApi.ts +54 -74
- package/src/clients/integrationFields.ts +59 -74
- package/src/clients/manageV2.ts +72 -96
- package/src/clients/migrationApi.ts +35 -39
- package/src/clients/wroom.ts +42 -56
- package/src/index.ts +7 -7
- package/src/managers/repositories.ts +85 -108
- package/src/managers/repository.ts +410 -378
- package/src/types.ts +31 -31
- package/src/utils/cookies.ts +8 -8
- package/src/utils/envVariableManager.ts +15 -15
- package/src/utils/log.ts +17 -21
- package/src/utils/random.ts +5 -6
- package/src/utils/strings.ts +7 -9
- package/src/utils/urls.ts +10 -12
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/cookies.d.ts +0 -8
- package/dist/utils/envVariableManager.d.ts +0 -16
- package/dist/utils/log.d.ts +0 -5
- package/dist/utils/random.d.ts +0 -8
- package/dist/utils/strings.d.ts +0 -11
- package/dist/utils/urls.d.ts +0 -16
package/src/clients/coreApi.ts
CHANGED
|
@@ -1,111 +1,119 @@
|
|
|
1
|
-
import { logPlaywrightApiResponse, logger } from "../utils/log"
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { logPlaywrightApiResponse, logger } from "../utils/log"
|
|
2
|
+
import type { AuthServerToken } from "./apiClient"
|
|
3
|
+
import { AuthenticatedApiClient } from "./apiClient"
|
|
4
4
|
|
|
5
5
|
type Language = {
|
|
6
|
-
id: string
|
|
7
|
-
name: string
|
|
8
|
-
is_master: boolean
|
|
9
|
-
}
|
|
6
|
+
id: string
|
|
7
|
+
name: string
|
|
8
|
+
is_master: boolean
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
export type Release = {
|
|
12
|
-
id: string
|
|
13
|
-
label: string
|
|
14
|
-
migration: boolean
|
|
15
|
-
}
|
|
12
|
+
id: string
|
|
13
|
+
label: string
|
|
14
|
+
migration: boolean
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
export type CoreApiDocumentCreationPayload = {
|
|
18
|
-
title: string
|
|
19
|
-
locale?: string
|
|
20
|
-
group_lang_id?: string
|
|
21
|
-
release_id?: string
|
|
22
|
-
integration_field_ids: string[]
|
|
23
|
-
data: Record<string, unknown
|
|
24
|
-
custom_type_id: string
|
|
25
|
-
tags: string[]
|
|
26
|
-
}
|
|
18
|
+
title: string
|
|
19
|
+
locale?: string
|
|
20
|
+
group_lang_id?: string
|
|
21
|
+
release_id?: string
|
|
22
|
+
integration_field_ids: string[]
|
|
23
|
+
data: Record<string, unknown>
|
|
24
|
+
custom_type_id: string
|
|
25
|
+
tags: string[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type CoreApiDocumentUpdatePayload = {
|
|
29
|
+
data: Record<string, unknown>
|
|
30
|
+
integration_field_ids: string[]
|
|
31
|
+
tags: string[]
|
|
32
|
+
}
|
|
27
33
|
|
|
28
34
|
export type CoreApiRepository = Record<string, unknown> & {
|
|
29
|
-
simulator_url?: string
|
|
30
|
-
}
|
|
35
|
+
simulator_url?: string
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
export type CoreApiDocumentCreationResponse = {
|
|
33
|
-
id: string
|
|
34
|
-
group_lang_id: string
|
|
35
|
-
custom_type_id: string
|
|
36
|
-
locale: string
|
|
37
|
-
language: { id: string; name: string }
|
|
38
|
-
first_publication_date: number | null
|
|
39
|
-
last_publication_date: number | null
|
|
40
|
-
title: string
|
|
39
|
+
id: string
|
|
40
|
+
group_lang_id: string
|
|
41
|
+
custom_type_id: string
|
|
42
|
+
locale: string
|
|
43
|
+
language: { id: string; name: string }
|
|
44
|
+
first_publication_date: number | null
|
|
45
|
+
last_publication_date: number | null
|
|
46
|
+
title: string
|
|
41
47
|
versions: {
|
|
42
|
-
status: string
|
|
43
|
-
version_id: string
|
|
48
|
+
status: string
|
|
49
|
+
version_id: string
|
|
44
50
|
author: {
|
|
45
|
-
id: string
|
|
46
|
-
first_name: string | null
|
|
47
|
-
last_name: string | null
|
|
48
|
-
email: string
|
|
49
|
-
}
|
|
50
|
-
release_id: string | null
|
|
51
|
-
last_modified_date: number
|
|
52
|
-
tags: string[]
|
|
53
|
-
custom_type_label: string
|
|
54
|
-
preview_summary?: string
|
|
55
|
-
preview_image?: string
|
|
56
|
-
uid?: string
|
|
57
|
-
}[]
|
|
58
|
-
}
|
|
51
|
+
id: string
|
|
52
|
+
first_name: string | null
|
|
53
|
+
last_name: string | null
|
|
54
|
+
email: string
|
|
55
|
+
}
|
|
56
|
+
release_id: string | null
|
|
57
|
+
last_modified_date: number
|
|
58
|
+
tags: string[]
|
|
59
|
+
custom_type_label: string
|
|
60
|
+
preview_summary?: string
|
|
61
|
+
preview_image?: string
|
|
62
|
+
uid?: string
|
|
63
|
+
}[]
|
|
64
|
+
}
|
|
59
65
|
|
|
60
66
|
export type CoreApiDocumentsPayload = {
|
|
61
|
-
language?: string
|
|
62
|
-
limit?: number
|
|
63
|
-
statuses?: string[]
|
|
64
|
-
groupLangIds?: string[]
|
|
65
|
-
|
|
67
|
+
language?: string
|
|
68
|
+
limit?: number
|
|
69
|
+
statuses?: string[]
|
|
70
|
+
groupLangIds?: string[]
|
|
71
|
+
documentIds?: string[]
|
|
72
|
+
}
|
|
66
73
|
|
|
67
74
|
export type CoreApiDocumentsResponse = {
|
|
68
|
-
total: number
|
|
69
|
-
cursor: string
|
|
70
|
-
results: CoreApiDocumentCreationResponse[]
|
|
71
|
-
}
|
|
75
|
+
total: number
|
|
76
|
+
cursor: string
|
|
77
|
+
results: CoreApiDocumentCreationResponse[]
|
|
78
|
+
}
|
|
72
79
|
|
|
73
80
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
export type CoreApiDocumentData = Record<string, any
|
|
81
|
+
export type CoreApiDocumentData = Record<string, any>
|
|
75
82
|
|
|
76
83
|
export class CoreApiClient extends AuthenticatedApiClient {
|
|
77
84
|
/**
|
|
78
|
-
* @example
|
|
85
|
+
* @example
|
|
86
|
+
* To instantiate the class:
|
|
79
87
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
88
|
+
* ```js
|
|
89
|
+
* new CoreApiClient("https://my-repo.prismic.io", {
|
|
82
90
|
* authToken: "my-secret-token",
|
|
83
|
-
*
|
|
84
|
-
*
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
85
93
|
*
|
|
86
|
-
* @param baseURL -
|
|
94
|
+
* @param baseURL - The api base URL like https://my-repo.prismic.io
|
|
87
95
|
* @param config - Optional configuration
|
|
88
96
|
*
|
|
89
|
-
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
90
|
-
*
|
|
97
|
+
* - {@link config.authToken}: Api token generated from the auth service or a function to fetch it
|
|
98
|
+
* when it's needed.
|
|
91
99
|
*/
|
|
92
100
|
constructor(baseURL: string, config: AuthServerToken) {
|
|
93
|
-
super(baseURL, config)
|
|
101
|
+
super(baseURL, config)
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
async getLanguages(): Promise<Language[]> {
|
|
97
|
-
const profiler = logger.startTimer()
|
|
98
|
-
const context = await this.getContext()
|
|
99
|
-
const result = await context.get("core/repository")
|
|
105
|
+
const profiler = logger.startTimer()
|
|
106
|
+
const context = await this.getContext()
|
|
107
|
+
const result = await context.get("core/repository")
|
|
100
108
|
|
|
101
109
|
if (200 !== result.status() || !(await result.json()).languages) {
|
|
102
|
-
await logPlaywrightApiResponse(result)
|
|
103
|
-
throw new Error("Could not get languages from the core api.")
|
|
110
|
+
await logPlaywrightApiResponse(result)
|
|
111
|
+
throw new Error("Could not get languages from the core api.")
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
profiler.done({ message: "retrieved languages configuration" })
|
|
114
|
+
profiler.done({ message: "retrieved languages configuration" })
|
|
107
115
|
|
|
108
|
-
return (await result.json()).languages
|
|
116
|
+
return (await result.json()).languages
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
/**
|
|
@@ -114,49 +122,95 @@ export class CoreApiClient extends AuthenticatedApiClient {
|
|
|
114
122
|
* @returns An array of release metadata.
|
|
115
123
|
*/
|
|
116
124
|
async getReleases(): Promise<Release[]> {
|
|
117
|
-
const profiler = logger.startTimer()
|
|
118
|
-
const context = await this.getContext()
|
|
125
|
+
const profiler = logger.startTimer()
|
|
126
|
+
const context = await this.getContext()
|
|
119
127
|
const result = await context.get("core/releases", {
|
|
120
128
|
params: { include_migration_releases: true },
|
|
121
|
-
})
|
|
129
|
+
})
|
|
122
130
|
|
|
123
131
|
if (200 !== result.status() || !(await result.json()).results) {
|
|
124
|
-
await logPlaywrightApiResponse(result)
|
|
125
|
-
throw new Error("Could not get releases from the core api.")
|
|
132
|
+
await logPlaywrightApiResponse(result)
|
|
133
|
+
throw new Error("Could not get releases from the core api.")
|
|
126
134
|
}
|
|
127
135
|
|
|
128
|
-
profiler.done({ message: "retrieved releases" })
|
|
136
|
+
profiler.done({ message: "retrieved releases" })
|
|
129
137
|
|
|
130
|
-
return (await result.json()).results
|
|
138
|
+
return (await result.json()).results
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
async createDraft(
|
|
134
142
|
data: CoreApiDocumentCreationPayload,
|
|
135
143
|
): Promise<CoreApiDocumentCreationResponse> {
|
|
136
|
-
const context = await this.getContext()
|
|
144
|
+
const context = await this.getContext()
|
|
137
145
|
const result = await context.post("core/documents", {
|
|
138
146
|
data,
|
|
139
|
-
})
|
|
147
|
+
})
|
|
140
148
|
|
|
141
149
|
if (201 !== result.status()) {
|
|
142
|
-
await logPlaywrightApiResponse(result)
|
|
143
|
-
throw new Error("Could not create draft document")
|
|
150
|
+
await logPlaywrightApiResponse(result)
|
|
151
|
+
throw new Error("Could not create draft document")
|
|
144
152
|
}
|
|
145
153
|
|
|
146
|
-
return result.json()
|
|
154
|
+
return result.json()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Creates a new draft version of an existing document, on top of the given base version.
|
|
159
|
+
*
|
|
160
|
+
* @param documentId - The id of the document to update.
|
|
161
|
+
* @param data - The new version payload in the core api format.
|
|
162
|
+
* @param baseVersionId - The id of the version the draft is created from.
|
|
163
|
+
* @returns The updated document, including the new version's id.
|
|
164
|
+
*/
|
|
165
|
+
async updateDraft(
|
|
166
|
+
documentId: string,
|
|
167
|
+
data: CoreApiDocumentUpdatePayload,
|
|
168
|
+
baseVersionId: string,
|
|
169
|
+
): Promise<CoreApiDocumentCreationResponse> {
|
|
170
|
+
const context = await this.getContext()
|
|
171
|
+
const result = await context.put(`core/documents/${documentId}/draft`, {
|
|
172
|
+
params: { base_version_id: baseVersionId },
|
|
173
|
+
data,
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
if (200 !== result.status()) {
|
|
177
|
+
await logPlaywrightApiResponse(result)
|
|
178
|
+
throw new Error(`Could not update draft for document with id ${documentId}`)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return result.json()
|
|
147
182
|
}
|
|
148
183
|
|
|
149
184
|
async publishDraft(documentId: string): Promise<void> {
|
|
150
|
-
const context = await this.getContext()
|
|
185
|
+
const context = await this.getContext()
|
|
151
186
|
const result = await context.patch(`core/documents/${documentId}/draft`, {
|
|
152
187
|
data: {
|
|
153
188
|
status: "published",
|
|
154
189
|
},
|
|
155
|
-
})
|
|
190
|
+
})
|
|
156
191
|
|
|
157
192
|
if (204 !== result.status()) {
|
|
158
|
-
await logPlaywrightApiResponse(result)
|
|
159
|
-
throw new Error(`Could not publish document with id ${documentId}`)
|
|
193
|
+
await logPlaywrightApiResponse(result)
|
|
194
|
+
throw new Error(`Could not publish document with id ${documentId}`)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Unpublishes (archives) a live document.
|
|
200
|
+
*
|
|
201
|
+
* @param documentId - The id of the document to unpublish.
|
|
202
|
+
*/
|
|
203
|
+
async unpublishDocument(documentId: string): Promise<void> {
|
|
204
|
+
const context = await this.getContext()
|
|
205
|
+
const result = await context.patch(`core/documents/${documentId}/live`, {
|
|
206
|
+
data: {
|
|
207
|
+
status: "archived",
|
|
208
|
+
},
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
if (204 !== result.status()) {
|
|
212
|
+
await logPlaywrightApiResponse(result)
|
|
213
|
+
throw new Error(`Could not unpublish document with id ${documentId}`)
|
|
160
214
|
}
|
|
161
215
|
}
|
|
162
216
|
|
|
@@ -164,82 +218,77 @@ export class CoreApiClient extends AuthenticatedApiClient {
|
|
|
164
218
|
* Retrieves documents.
|
|
165
219
|
*
|
|
166
220
|
* @param args - Configure which documents are retrieved.
|
|
167
|
-
*
|
|
168
221
|
* @returns A paginated set of documents.
|
|
169
222
|
*/
|
|
170
|
-
async getDocuments(
|
|
171
|
-
|
|
172
|
-
): Promise<CoreApiDocumentsResponse> {
|
|
173
|
-
const context = await this.getContext();
|
|
223
|
+
async getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse> {
|
|
224
|
+
const context = await this.getContext()
|
|
174
225
|
const result = await context.post("core/documents/search", {
|
|
175
226
|
data: args,
|
|
176
|
-
})
|
|
227
|
+
})
|
|
177
228
|
|
|
178
229
|
if (200 !== result.status()) {
|
|
179
|
-
await logPlaywrightApiResponse(result)
|
|
180
|
-
throw new Error("Could not search documents")
|
|
230
|
+
await logPlaywrightApiResponse(result)
|
|
231
|
+
throw new Error("Could not search documents")
|
|
181
232
|
}
|
|
182
233
|
|
|
183
|
-
return result.json()
|
|
234
|
+
return result.json()
|
|
184
235
|
}
|
|
185
236
|
|
|
186
237
|
/**
|
|
187
238
|
* Retrieves data for a specific document version.
|
|
188
239
|
*
|
|
189
240
|
* @param versionId - The document's version ID.
|
|
190
|
-
*
|
|
191
241
|
* @returns The document's version data.
|
|
192
242
|
*/
|
|
193
243
|
async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
|
|
194
|
-
const context = await this.getContext()
|
|
195
|
-
const result = await context.get(`core/documents/data/${versionId}`)
|
|
244
|
+
const context = await this.getContext()
|
|
245
|
+
const result = await context.get(`core/documents/data/${versionId}`)
|
|
196
246
|
|
|
197
247
|
if (200 !== result.status()) {
|
|
198
|
-
await logPlaywrightApiResponse(result)
|
|
199
|
-
throw new Error("Could not retrieve document data")
|
|
248
|
+
await logPlaywrightApiResponse(result)
|
|
249
|
+
throw new Error("Could not retrieve document data")
|
|
200
250
|
}
|
|
201
251
|
|
|
202
|
-
return result.json()
|
|
252
|
+
return result.json()
|
|
203
253
|
}
|
|
204
254
|
|
|
205
255
|
/**
|
|
206
256
|
* Publishes a release.
|
|
207
257
|
*
|
|
208
258
|
* @param id - The ID of the release.
|
|
209
|
-
*
|
|
210
259
|
* @returns A Promise that resolves when the release is published.
|
|
211
260
|
*/
|
|
212
261
|
async publishRelease(id: string): Promise<void> {
|
|
213
|
-
const context = await this.getContext()
|
|
214
|
-
const result = await context.post(`core/releases/${id}/publish`)
|
|
262
|
+
const context = await this.getContext()
|
|
263
|
+
const result = await context.post(`core/releases/${id}/publish`)
|
|
215
264
|
|
|
216
265
|
if (200 !== result.status()) {
|
|
217
|
-
await logPlaywrightApiResponse(result)
|
|
218
|
-
throw new Error("Could not publish release ${id}")
|
|
266
|
+
await logPlaywrightApiResponse(result)
|
|
267
|
+
throw new Error("Could not publish release ${id}")
|
|
219
268
|
}
|
|
220
269
|
}
|
|
221
270
|
|
|
222
271
|
async getRepository(): Promise<CoreApiRepository> {
|
|
223
|
-
const context = await this.getContext()
|
|
224
|
-
const result = await context.get(`core/repository`)
|
|
272
|
+
const context = await this.getContext()
|
|
273
|
+
const result = await context.get(`core/repository`)
|
|
225
274
|
|
|
226
275
|
if (200 !== result.status()) {
|
|
227
|
-
await logPlaywrightApiResponse(result)
|
|
228
|
-
throw new Error(`Could not get repository`)
|
|
276
|
+
await logPlaywrightApiResponse(result)
|
|
277
|
+
throw new Error(`Could not get repository`)
|
|
229
278
|
}
|
|
230
279
|
|
|
231
|
-
return result.json()
|
|
280
|
+
return result.json()
|
|
232
281
|
}
|
|
233
282
|
|
|
234
283
|
async updateRepository(data: CoreApiRepository): Promise<void> {
|
|
235
|
-
const context = await this.getContext()
|
|
284
|
+
const context = await this.getContext()
|
|
236
285
|
const result = await context.patch(`core/repository`, {
|
|
237
286
|
data,
|
|
238
|
-
})
|
|
287
|
+
})
|
|
239
288
|
|
|
240
289
|
if (204 !== result.status()) {
|
|
241
|
-
await logPlaywrightApiResponse(result)
|
|
242
|
-
throw new Error(`Could not update repository`)
|
|
290
|
+
await logPlaywrightApiResponse(result)
|
|
291
|
+
throw new Error(`Could not update repository`)
|
|
243
292
|
}
|
|
244
293
|
}
|
|
245
294
|
}
|
|
@@ -1,88 +1,72 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { DynamicCustomTypeModel, SharedSliceModel } from "@prismicio/types-internal"
|
|
2
|
+
import isEqual from "lodash.isequal"
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@prismicio/types-internal/lib/customtypes";
|
|
4
|
+
import { logPlaywrightApiResponse, logger } from "../utils/log"
|
|
5
|
+
import type { AuthServerToken } from "./apiClient"
|
|
6
|
+
import { AuthenticatedApiClient } from "./apiClient"
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type ItemType = DynamicCustomTypeModel | SharedSliceModel
|
|
9
|
+
type ItemTypePath = "customtypes" | "slices"
|
|
10
|
+
type ItemOperation = "insert" | "update"
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type ItemType = CustomType | SharedSlice;
|
|
13
|
-
type ItemTypePath = "customtypes" | "slices";
|
|
14
|
-
type ItemOperation = "insert" | "update";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Client for interacting with the Custom Types API to create/update custom
|
|
18
|
-
* types and slices.
|
|
19
|
-
*/
|
|
12
|
+
/** Client for interacting with the Custom Types API to create/update custom types and slices. */
|
|
20
13
|
export class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
21
|
-
constructor(
|
|
22
|
-
baseURL:
|
|
23
|
-
config: { authToken: AuthServerToken; repository: string },
|
|
24
|
-
) {
|
|
25
|
-
super(baseURL, config.authToken, { repository: config.repository });
|
|
14
|
+
constructor(baseURL: string, config: { authToken: AuthServerToken; repository: string }) {
|
|
15
|
+
super(baseURL, config.authToken, { repository: config.repository })
|
|
26
16
|
}
|
|
27
17
|
|
|
28
18
|
/**
|
|
29
19
|
* Create or update a custom type or slice.
|
|
30
20
|
*
|
|
31
|
-
* @param endpoint - - The API endpoint for custom types or slices
|
|
32
|
-
* ('customtypes' or 'slices').
|
|
21
|
+
* @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').
|
|
33
22
|
* @param data - - The data representing the custom type or slice.
|
|
34
|
-
*
|
|
35
23
|
* @throws Error if the item status cannot be retrieved or the item cannot be
|
|
36
|
-
*
|
|
24
|
+
* created/updated.
|
|
37
25
|
*/
|
|
38
|
-
private async upsert(
|
|
39
|
-
|
|
40
|
-
operation
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const path = `${endpoint}/${operation}`;
|
|
45
|
-
|
|
46
|
-
const context = await this.getContext();
|
|
47
|
-
const result = await context.post(path, { data });
|
|
26
|
+
private async upsert(endpoint: ItemTypePath, operation: ItemOperation, data: ItemType) {
|
|
27
|
+
const profiler = logger.startTimer()
|
|
28
|
+
const path = `${endpoint}/${operation}`
|
|
29
|
+
|
|
30
|
+
const context = await this.getContext()
|
|
31
|
+
const result = await context.post(path, { data })
|
|
48
32
|
if (!result.ok()) {
|
|
49
|
-
logPlaywrightApiResponse(result)
|
|
50
|
-
throw new Error(`Could not ${operation} item`)
|
|
33
|
+
logPlaywrightApiResponse(result)
|
|
34
|
+
throw new Error(`Could not ${operation} item`)
|
|
51
35
|
}
|
|
52
36
|
profiler.done({
|
|
53
37
|
message: `called customtypes api /${path} for item with id '${data.id}'`,
|
|
54
|
-
})
|
|
38
|
+
})
|
|
55
39
|
}
|
|
56
40
|
|
|
57
41
|
private async getRemoteItems(
|
|
58
42
|
endpoint: ItemTypePath,
|
|
59
|
-
): Promise<
|
|
60
|
-
const context = await this.getContext()
|
|
61
|
-
const result = await context.get(endpoint)
|
|
43
|
+
): Promise<DynamicCustomTypeModel[] | SharedSliceModel[]> {
|
|
44
|
+
const context = await this.getContext()
|
|
45
|
+
const result = await context.get(endpoint)
|
|
62
46
|
|
|
63
47
|
if (!result.ok()) {
|
|
64
|
-
logPlaywrightApiResponse(result)
|
|
65
|
-
throw new Error("Could not get items status from the Custom Type api.")
|
|
48
|
+
logPlaywrightApiResponse(result)
|
|
49
|
+
throw new Error("Could not get items status from the Custom Type api.")
|
|
66
50
|
}
|
|
67
51
|
|
|
68
|
-
return result.json()
|
|
52
|
+
return result.json()
|
|
69
53
|
}
|
|
70
54
|
|
|
71
55
|
private async getDifference(
|
|
72
|
-
remoteItems:
|
|
56
|
+
remoteItems: DynamicCustomTypeModel[] | SharedSliceModel[],
|
|
73
57
|
local: ItemType,
|
|
74
58
|
): Promise<ItemOperation | undefined> {
|
|
75
59
|
const remoteItem = remoteItems.find(
|
|
76
|
-
(remote:
|
|
77
|
-
)
|
|
60
|
+
(remote: DynamicCustomTypeModel | SharedSliceModel) => remote.id === local.id,
|
|
61
|
+
)
|
|
78
62
|
if (!remoteItem) {
|
|
79
|
-
return "insert"
|
|
63
|
+
return "insert"
|
|
80
64
|
}
|
|
81
65
|
if (!isEqual(local, remoteItem)) {
|
|
82
|
-
return "update"
|
|
66
|
+
return "update"
|
|
83
67
|
}
|
|
84
68
|
|
|
85
|
-
return
|
|
69
|
+
return
|
|
86
70
|
}
|
|
87
71
|
|
|
88
72
|
/** Create items only if they have changed compared to their remote status */
|
|
@@ -90,44 +74,42 @@ export class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
|
90
74
|
itemType: ItemTypePath,
|
|
91
75
|
localItems: ItemType[] = [],
|
|
92
76
|
): Promise<void> {
|
|
93
|
-
const remoteItems = await this.getRemoteItems(itemType)
|
|
77
|
+
const remoteItems = await this.getRemoteItems(itemType)
|
|
94
78
|
await Promise.all(
|
|
95
79
|
localItems.map(async (localItem) => {
|
|
96
|
-
const operation = await this.getDifference(remoteItems, localItem)
|
|
80
|
+
const operation = await this.getDifference(remoteItems, localItem)
|
|
97
81
|
|
|
98
|
-
return operation && this.upsert(itemType, operation, localItem)
|
|
82
|
+
return operation && this.upsert(itemType, operation, localItem)
|
|
99
83
|
}),
|
|
100
|
-
)
|
|
84
|
+
)
|
|
101
85
|
}
|
|
102
86
|
|
|
103
87
|
/**
|
|
104
88
|
* Create Custom Types using the Custom types api.
|
|
105
89
|
*
|
|
106
|
-
* @param customTypes
|
|
90
|
+
* @param customTypes
|
|
107
91
|
*/
|
|
108
|
-
async createCustomTypes(customTypes:
|
|
109
|
-
await this.upsertIfChanged("customtypes", customTypes)
|
|
92
|
+
async createCustomTypes(customTypes: DynamicCustomTypeModel[] = []): Promise<void> {
|
|
93
|
+
await this.upsertIfChanged("customtypes", customTypes)
|
|
110
94
|
}
|
|
111
95
|
|
|
112
96
|
async deleteCustomType(customTypeId: string): Promise<void> {
|
|
113
|
-
const context = await this.getContext()
|
|
114
|
-
const result = await context.delete(`customtypes/${customTypeId}`)
|
|
97
|
+
const context = await this.getContext()
|
|
98
|
+
const result = await context.delete(`customtypes/${customTypeId}`)
|
|
115
99
|
|
|
116
100
|
if (!result.ok()) {
|
|
117
|
-
logPlaywrightApiResponse(result)
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Could not delete ${customTypeId} from the Custom Type api.`,
|
|
120
|
-
);
|
|
101
|
+
logPlaywrightApiResponse(result)
|
|
102
|
+
throw new Error(`Could not delete ${customTypeId} from the Custom Type api.`)
|
|
121
103
|
}
|
|
122
104
|
}
|
|
123
105
|
|
|
124
106
|
/**
|
|
125
107
|
* Create slices using the Custom types api.
|
|
126
108
|
*
|
|
127
|
-
* @param slices
|
|
109
|
+
* @param slices
|
|
128
110
|
*/
|
|
129
|
-
async createSlices(slices:
|
|
130
|
-
await this.upsertIfChanged("slices", slices)
|
|
111
|
+
async createSlices(slices: SharedSliceModel[] = []): Promise<void> {
|
|
112
|
+
await this.upsertIfChanged("slices", slices)
|
|
131
113
|
}
|
|
132
114
|
|
|
133
115
|
/**
|
|
@@ -135,17 +117,15 @@ export class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
|
135
117
|
*
|
|
136
118
|
* @param customTypeId - The id of the custom type to get.
|
|
137
119
|
*/
|
|
138
|
-
async getTypeById(customTypeId: string): Promise<
|
|
139
|
-
const context = await this.getContext()
|
|
140
|
-
const result = await context.get(`customtypes/${customTypeId}`)
|
|
120
|
+
async getTypeById(customTypeId: string): Promise<DynamicCustomTypeModel> {
|
|
121
|
+
const context = await this.getContext()
|
|
122
|
+
const result = await context.get(`customtypes/${customTypeId}`)
|
|
141
123
|
|
|
142
124
|
if (!result.ok()) {
|
|
143
|
-
logPlaywrightApiResponse(result)
|
|
144
|
-
throw new Error(
|
|
145
|
-
`Could not get ${customTypeId} type from the Custom Type api.`,
|
|
146
|
-
);
|
|
125
|
+
logPlaywrightApiResponse(result)
|
|
126
|
+
throw new Error(`Could not get ${customTypeId} type from the Custom Type api.`)
|
|
147
127
|
}
|
|
148
128
|
|
|
149
|
-
return result.json()
|
|
129
|
+
return result.json()
|
|
150
130
|
}
|
|
151
131
|
}
|