@prismicio/e2e-tests-utils 1.18.0 → 1.19.0-pr.37.6283e4a

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