@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.
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 +123 -145
  36. package/dist/clients/coreApi.cjs.map +1 -1
  37. package/dist/clients/coreApi.d.cts +122 -0
  38. package/dist/clients/coreApi.d.cts.map +1 -0
  39. package/dist/clients/coreApi.d.ts +111 -109
  40. package/dist/clients/coreApi.d.ts.map +1 -0
  41. package/dist/clients/coreApi.js +122 -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 +529 -616
  96. package/dist/managers/repository.cjs.map +1 -1
  97. package/dist/managers/repository.d.cts +308 -0
  98. package/dist/managers/repository.d.cts.map +1 -0
  99. package/dist/managers/repository.d.ts +303 -307
  100. package/dist/managers/repository.d.ts.map +1 -0
  101. package/dist/managers/repository.js +529 -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 +109 -129
  136. package/src/clients/coreApi.ts +113 -117
  137. package/src/clients/customTypesApi.ts +54 -76
  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 +303 -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,112 @@
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
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 To instantiate the class:
78
+ * @example
79
+ * To instantiate the class:
79
80
  *
80
- * ```js
81
- * new CoreApiClient("https://my-repo.prismic.io", {
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 - the api base URL like https://my-repo.prismic.io
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
- * function to fetch it when it's needed.
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
- args: CoreApiDocumentsPayload,
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 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
- private async getRemoteItems(
58
- endpoint: ItemTypePath,
59
- ): Promise<CustomType[] | SharedSlice[]> {
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: CustomType[] | SharedSlice[],
54
+ remoteItems: DynamicCustomTypeModel[] | SharedSliceModel[],
73
55
  local: ItemType,
74
56
  ): Promise<ItemOperation | undefined> {
75
57
  const remoteItem = remoteItems.find(
76
- (remote: CustomType | SharedSlice) => remote.id === local.id,
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: CustomType[] = []): Promise<void> {
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: SharedSlice[] = []): Promise<void> {
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<CustomType> {
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
  }