@prismicio/e2e-tests-utils 1.18.0 → 1.19.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 +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 +123 -145
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.cts +122 -0
- package/dist/clients/coreApi.d.cts.map +1 -0
- package/dist/clients/coreApi.d.ts +111 -109
- package/dist/clients/coreApi.d.ts.map +1 -0
- package/dist/clients/coreApi.js +122 -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 +529 -616
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.cts +308 -0
- package/dist/managers/repository.d.cts.map +1 -0
- package/dist/managers/repository.d.ts +303 -307
- package/dist/managers/repository.d.ts.map +1 -0
- package/dist/managers/repository.js +529 -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 +109 -129
- package/src/clients/coreApi.ts +113 -117
- package/src/clients/customTypesApi.ts +54 -76
- 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 +303 -368
- 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,112 @@
|
|
|
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
27
|
|
|
28
28
|
export type CoreApiRepository = Record<string, unknown> & {
|
|
29
|
-
simulator_url?: string
|
|
30
|
-
}
|
|
29
|
+
simulator_url?: string
|
|
30
|
+
}
|
|
31
31
|
|
|
32
32
|
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
|
|
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
|
|
41
41
|
versions: {
|
|
42
|
-
status: string
|
|
43
|
-
version_id: string
|
|
42
|
+
status: string
|
|
43
|
+
version_id: string
|
|
44
44
|
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
|
-
}
|
|
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
|
+
}
|
|
59
59
|
|
|
60
60
|
export type CoreApiDocumentsPayload = {
|
|
61
|
-
language?: string
|
|
62
|
-
limit?: number
|
|
63
|
-
statuses?: string[]
|
|
64
|
-
groupLangIds?: string[]
|
|
65
|
-
}
|
|
61
|
+
language?: string
|
|
62
|
+
limit?: number
|
|
63
|
+
statuses?: string[]
|
|
64
|
+
groupLangIds?: string[]
|
|
65
|
+
}
|
|
66
66
|
|
|
67
67
|
export type CoreApiDocumentsResponse = {
|
|
68
|
-
total: number
|
|
69
|
-
cursor: string
|
|
70
|
-
results: CoreApiDocumentCreationResponse[]
|
|
71
|
-
}
|
|
68
|
+
total: number
|
|
69
|
+
cursor: string
|
|
70
|
+
results: CoreApiDocumentCreationResponse[]
|
|
71
|
+
}
|
|
72
72
|
|
|
73
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
export type CoreApiDocumentData = Record<string, any
|
|
74
|
+
export type CoreApiDocumentData = Record<string, any>
|
|
75
75
|
|
|
76
76
|
export class CoreApiClient extends AuthenticatedApiClient {
|
|
77
77
|
/**
|
|
78
|
-
* @example
|
|
78
|
+
* @example
|
|
79
|
+
* To instantiate the class:
|
|
79
80
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
81
|
+
* ```js
|
|
82
|
+
* new CoreApiClient("https://my-repo.prismic.io", {
|
|
82
83
|
* authToken: "my-secret-token",
|
|
83
|
-
*
|
|
84
|
-
*
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
85
86
|
*
|
|
86
|
-
* @param baseURL -
|
|
87
|
+
* @param baseURL - The api base URL like https://my-repo.prismic.io
|
|
87
88
|
* @param config - Optional configuration
|
|
88
89
|
*
|
|
89
|
-
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
90
|
-
*
|
|
90
|
+
* - {@link config.authToken}: Api token generated from the auth service or a function to fetch it
|
|
91
|
+
* when it's needed.
|
|
91
92
|
*/
|
|
92
93
|
constructor(baseURL: string, config: AuthServerToken) {
|
|
93
|
-
super(baseURL, config)
|
|
94
|
+
super(baseURL, config)
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
async getLanguages(): Promise<Language[]> {
|
|
97
|
-
const profiler = logger.startTimer()
|
|
98
|
-
const context = await this.getContext()
|
|
99
|
-
const result = await context.get("core/repository")
|
|
98
|
+
const profiler = logger.startTimer()
|
|
99
|
+
const context = await this.getContext()
|
|
100
|
+
const result = await context.get("core/repository")
|
|
100
101
|
|
|
101
102
|
if (200 !== result.status() || !(await result.json()).languages) {
|
|
102
|
-
await logPlaywrightApiResponse(result)
|
|
103
|
-
throw new Error("Could not get languages from the core api.")
|
|
103
|
+
await logPlaywrightApiResponse(result)
|
|
104
|
+
throw new Error("Could not get languages from the core api.")
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
profiler.done({ message: "retrieved languages configuration" })
|
|
107
|
+
profiler.done({ message: "retrieved languages configuration" })
|
|
107
108
|
|
|
108
|
-
return (await result.json()).languages
|
|
109
|
+
return (await result.json()).languages
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
/**
|
|
@@ -114,49 +115,49 @@ export class CoreApiClient extends AuthenticatedApiClient {
|
|
|
114
115
|
* @returns An array of release metadata.
|
|
115
116
|
*/
|
|
116
117
|
async getReleases(): Promise<Release[]> {
|
|
117
|
-
const profiler = logger.startTimer()
|
|
118
|
-
const context = await this.getContext()
|
|
118
|
+
const profiler = logger.startTimer()
|
|
119
|
+
const context = await this.getContext()
|
|
119
120
|
const result = await context.get("core/releases", {
|
|
120
121
|
params: { include_migration_releases: true },
|
|
121
|
-
})
|
|
122
|
+
})
|
|
122
123
|
|
|
123
124
|
if (200 !== result.status() || !(await result.json()).results) {
|
|
124
|
-
await logPlaywrightApiResponse(result)
|
|
125
|
-
throw new Error("Could not get releases from the core api.")
|
|
125
|
+
await logPlaywrightApiResponse(result)
|
|
126
|
+
throw new Error("Could not get releases from the core api.")
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
profiler.done({ message: "retrieved releases" })
|
|
129
|
+
profiler.done({ message: "retrieved releases" })
|
|
129
130
|
|
|
130
|
-
return (await result.json()).results
|
|
131
|
+
return (await result.json()).results
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
async createDraft(
|
|
134
135
|
data: CoreApiDocumentCreationPayload,
|
|
135
136
|
): Promise<CoreApiDocumentCreationResponse> {
|
|
136
|
-
const context = await this.getContext()
|
|
137
|
+
const context = await this.getContext()
|
|
137
138
|
const result = await context.post("core/documents", {
|
|
138
139
|
data,
|
|
139
|
-
})
|
|
140
|
+
})
|
|
140
141
|
|
|
141
142
|
if (201 !== result.status()) {
|
|
142
|
-
await logPlaywrightApiResponse(result)
|
|
143
|
-
throw new Error("Could not create draft document")
|
|
143
|
+
await logPlaywrightApiResponse(result)
|
|
144
|
+
throw new Error("Could not create draft document")
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
return result.json()
|
|
147
|
+
return result.json()
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
async publishDraft(documentId: string): Promise<void> {
|
|
150
|
-
const context = await this.getContext()
|
|
151
|
+
const context = await this.getContext()
|
|
151
152
|
const result = await context.patch(`core/documents/${documentId}/draft`, {
|
|
152
153
|
data: {
|
|
153
154
|
status: "published",
|
|
154
155
|
},
|
|
155
|
-
})
|
|
156
|
+
})
|
|
156
157
|
|
|
157
158
|
if (204 !== result.status()) {
|
|
158
|
-
await logPlaywrightApiResponse(result)
|
|
159
|
-
throw new Error(`Could not publish document with id ${documentId}`)
|
|
159
|
+
await logPlaywrightApiResponse(result)
|
|
160
|
+
throw new Error(`Could not publish document with id ${documentId}`)
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
|
|
@@ -164,82 +165,77 @@ export class CoreApiClient extends AuthenticatedApiClient {
|
|
|
164
165
|
* Retrieves documents.
|
|
165
166
|
*
|
|
166
167
|
* @param args - Configure which documents are retrieved.
|
|
167
|
-
*
|
|
168
168
|
* @returns A paginated set of documents.
|
|
169
169
|
*/
|
|
170
|
-
async getDocuments(
|
|
171
|
-
|
|
172
|
-
): Promise<CoreApiDocumentsResponse> {
|
|
173
|
-
const context = await this.getContext();
|
|
170
|
+
async getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse> {
|
|
171
|
+
const context = await this.getContext()
|
|
174
172
|
const result = await context.post("core/documents/search", {
|
|
175
173
|
data: args,
|
|
176
|
-
})
|
|
174
|
+
})
|
|
177
175
|
|
|
178
176
|
if (200 !== result.status()) {
|
|
179
|
-
await logPlaywrightApiResponse(result)
|
|
180
|
-
throw new Error("Could not search documents")
|
|
177
|
+
await logPlaywrightApiResponse(result)
|
|
178
|
+
throw new Error("Could not search documents")
|
|
181
179
|
}
|
|
182
180
|
|
|
183
|
-
return result.json()
|
|
181
|
+
return result.json()
|
|
184
182
|
}
|
|
185
183
|
|
|
186
184
|
/**
|
|
187
185
|
* Retrieves data for a specific document version.
|
|
188
186
|
*
|
|
189
187
|
* @param versionId - The document's version ID.
|
|
190
|
-
*
|
|
191
188
|
* @returns The document's version data.
|
|
192
189
|
*/
|
|
193
190
|
async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
|
|
194
|
-
const context = await this.getContext()
|
|
195
|
-
const result = await context.get(`core/documents/data/${versionId}`)
|
|
191
|
+
const context = await this.getContext()
|
|
192
|
+
const result = await context.get(`core/documents/data/${versionId}`)
|
|
196
193
|
|
|
197
194
|
if (200 !== result.status()) {
|
|
198
|
-
await logPlaywrightApiResponse(result)
|
|
199
|
-
throw new Error("Could not retrieve document data")
|
|
195
|
+
await logPlaywrightApiResponse(result)
|
|
196
|
+
throw new Error("Could not retrieve document data")
|
|
200
197
|
}
|
|
201
198
|
|
|
202
|
-
return result.json()
|
|
199
|
+
return result.json()
|
|
203
200
|
}
|
|
204
201
|
|
|
205
202
|
/**
|
|
206
203
|
* Publishes a release.
|
|
207
204
|
*
|
|
208
205
|
* @param id - The ID of the release.
|
|
209
|
-
*
|
|
210
206
|
* @returns A Promise that resolves when the release is published.
|
|
211
207
|
*/
|
|
212
208
|
async publishRelease(id: string): Promise<void> {
|
|
213
|
-
const context = await this.getContext()
|
|
214
|
-
const result = await context.post(`core/releases/${id}/publish`)
|
|
209
|
+
const context = await this.getContext()
|
|
210
|
+
const result = await context.post(`core/releases/${id}/publish`)
|
|
215
211
|
|
|
216
212
|
if (200 !== result.status()) {
|
|
217
|
-
await logPlaywrightApiResponse(result)
|
|
218
|
-
throw new Error("Could not publish release ${id}")
|
|
213
|
+
await logPlaywrightApiResponse(result)
|
|
214
|
+
throw new Error("Could not publish release ${id}")
|
|
219
215
|
}
|
|
220
216
|
}
|
|
221
217
|
|
|
222
218
|
async getRepository(): Promise<CoreApiRepository> {
|
|
223
|
-
const context = await this.getContext()
|
|
224
|
-
const result = await context.get(`core/repository`)
|
|
219
|
+
const context = await this.getContext()
|
|
220
|
+
const result = await context.get(`core/repository`)
|
|
225
221
|
|
|
226
222
|
if (200 !== result.status()) {
|
|
227
|
-
await logPlaywrightApiResponse(result)
|
|
228
|
-
throw new Error(`Could not get repository`)
|
|
223
|
+
await logPlaywrightApiResponse(result)
|
|
224
|
+
throw new Error(`Could not get repository`)
|
|
229
225
|
}
|
|
230
226
|
|
|
231
|
-
return result.json()
|
|
227
|
+
return result.json()
|
|
232
228
|
}
|
|
233
229
|
|
|
234
230
|
async updateRepository(data: CoreApiRepository): Promise<void> {
|
|
235
|
-
const context = await this.getContext()
|
|
231
|
+
const context = await this.getContext()
|
|
236
232
|
const result = await context.patch(`core/repository`, {
|
|
237
233
|
data,
|
|
238
|
-
})
|
|
234
|
+
})
|
|
239
235
|
|
|
240
236
|
if (204 !== result.status()) {
|
|
241
|
-
await logPlaywrightApiResponse(result)
|
|
242
|
-
throw new Error(`Could not update repository`)
|
|
237
|
+
await logPlaywrightApiResponse(result)
|
|
238
|
+
throw new Error(`Could not update repository`)
|
|
243
239
|
}
|
|
244
240
|
}
|
|
245
241
|
}
|
|
@@ -1,88 +1,70 @@
|
|
|
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
|
-
private async getRemoteItems(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const context = await this.getContext();
|
|
61
|
-
const result = await context.get(endpoint);
|
|
41
|
+
private async getRemoteItems(endpoint: ItemTypePath): Promise<DynamicCustomTypeModel[] | SharedSliceModel[]> {
|
|
42
|
+
const context = await this.getContext()
|
|
43
|
+
const result = await context.get(endpoint)
|
|
62
44
|
|
|
63
45
|
if (!result.ok()) {
|
|
64
|
-
logPlaywrightApiResponse(result)
|
|
65
|
-
throw new Error("Could not get items status from the Custom Type api.")
|
|
46
|
+
logPlaywrightApiResponse(result)
|
|
47
|
+
throw new Error("Could not get items status from the Custom Type api.")
|
|
66
48
|
}
|
|
67
49
|
|
|
68
|
-
return result.json()
|
|
50
|
+
return result.json()
|
|
69
51
|
}
|
|
70
52
|
|
|
71
53
|
private async getDifference(
|
|
72
|
-
remoteItems:
|
|
54
|
+
remoteItems: DynamicCustomTypeModel[] | SharedSliceModel[],
|
|
73
55
|
local: ItemType,
|
|
74
56
|
): Promise<ItemOperation | undefined> {
|
|
75
57
|
const remoteItem = remoteItems.find(
|
|
76
|
-
(remote:
|
|
77
|
-
)
|
|
58
|
+
(remote: DynamicCustomTypeModel | SharedSliceModel) => remote.id === local.id,
|
|
59
|
+
)
|
|
78
60
|
if (!remoteItem) {
|
|
79
|
-
return "insert"
|
|
61
|
+
return "insert"
|
|
80
62
|
}
|
|
81
63
|
if (!isEqual(local, remoteItem)) {
|
|
82
|
-
return "update"
|
|
64
|
+
return "update"
|
|
83
65
|
}
|
|
84
66
|
|
|
85
|
-
return
|
|
67
|
+
return
|
|
86
68
|
}
|
|
87
69
|
|
|
88
70
|
/** Create items only if they have changed compared to their remote status */
|
|
@@ -90,44 +72,42 @@ export class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
|
90
72
|
itemType: ItemTypePath,
|
|
91
73
|
localItems: ItemType[] = [],
|
|
92
74
|
): Promise<void> {
|
|
93
|
-
const remoteItems = await this.getRemoteItems(itemType)
|
|
75
|
+
const remoteItems = await this.getRemoteItems(itemType)
|
|
94
76
|
await Promise.all(
|
|
95
77
|
localItems.map(async (localItem) => {
|
|
96
|
-
const operation = await this.getDifference(remoteItems, localItem)
|
|
78
|
+
const operation = await this.getDifference(remoteItems, localItem)
|
|
97
79
|
|
|
98
|
-
return operation && this.upsert(itemType, operation, localItem)
|
|
80
|
+
return operation && this.upsert(itemType, operation, localItem)
|
|
99
81
|
}),
|
|
100
|
-
)
|
|
82
|
+
)
|
|
101
83
|
}
|
|
102
84
|
|
|
103
85
|
/**
|
|
104
86
|
* Create Custom Types using the Custom types api.
|
|
105
87
|
*
|
|
106
|
-
* @param customTypes
|
|
88
|
+
* @param customTypes
|
|
107
89
|
*/
|
|
108
|
-
async createCustomTypes(customTypes:
|
|
109
|
-
await this.upsertIfChanged("customtypes", customTypes)
|
|
90
|
+
async createCustomTypes(customTypes: DynamicCustomTypeModel[] = []): Promise<void> {
|
|
91
|
+
await this.upsertIfChanged("customtypes", customTypes)
|
|
110
92
|
}
|
|
111
93
|
|
|
112
94
|
async deleteCustomType(customTypeId: string): Promise<void> {
|
|
113
|
-
const context = await this.getContext()
|
|
114
|
-
const result = await context.delete(`customtypes/${customTypeId}`)
|
|
95
|
+
const context = await this.getContext()
|
|
96
|
+
const result = await context.delete(`customtypes/${customTypeId}`)
|
|
115
97
|
|
|
116
98
|
if (!result.ok()) {
|
|
117
|
-
logPlaywrightApiResponse(result)
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Could not delete ${customTypeId} from the Custom Type api.`,
|
|
120
|
-
);
|
|
99
|
+
logPlaywrightApiResponse(result)
|
|
100
|
+
throw new Error(`Could not delete ${customTypeId} from the Custom Type api.`)
|
|
121
101
|
}
|
|
122
102
|
}
|
|
123
103
|
|
|
124
104
|
/**
|
|
125
105
|
* Create slices using the Custom types api.
|
|
126
106
|
*
|
|
127
|
-
* @param slices
|
|
107
|
+
* @param slices
|
|
128
108
|
*/
|
|
129
|
-
async createSlices(slices:
|
|
130
|
-
await this.upsertIfChanged("slices", slices)
|
|
109
|
+
async createSlices(slices: SharedSliceModel[] = []): Promise<void> {
|
|
110
|
+
await this.upsertIfChanged("slices", slices)
|
|
131
111
|
}
|
|
132
112
|
|
|
133
113
|
/**
|
|
@@ -135,17 +115,15 @@ export class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
|
135
115
|
*
|
|
136
116
|
* @param customTypeId - The id of the custom type to get.
|
|
137
117
|
*/
|
|
138
|
-
async getTypeById(customTypeId: string): Promise<
|
|
139
|
-
const context = await this.getContext()
|
|
140
|
-
const result = await context.get(`customtypes/${customTypeId}`)
|
|
118
|
+
async getTypeById(customTypeId: string): Promise<DynamicCustomTypeModel> {
|
|
119
|
+
const context = await this.getContext()
|
|
120
|
+
const result = await context.get(`customtypes/${customTypeId}`)
|
|
141
121
|
|
|
142
122
|
if (!result.ok()) {
|
|
143
|
-
logPlaywrightApiResponse(result)
|
|
144
|
-
throw new Error(
|
|
145
|
-
`Could not get ${customTypeId} type from the Custom Type api.`,
|
|
146
|
-
);
|
|
123
|
+
logPlaywrightApiResponse(result)
|
|
124
|
+
throw new Error(`Could not get ${customTypeId} type from the Custom Type api.`)
|
|
147
125
|
}
|
|
148
126
|
|
|
149
|
-
return result.json()
|
|
127
|
+
return result.json()
|
|
150
128
|
}
|
|
151
129
|
}
|