@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,129 +1,126 @@
1
- import { APIResponse } from "@playwright/test";
1
+ import type { APIResponse } from "@playwright/test"
2
2
 
3
- import { AuthenticatedApiClient } from "./apiClient";
3
+ import { AuthenticatedApiClient } from "./apiClient"
4
4
 
5
5
  export interface ContentApiError {
6
- type: string;
7
- message: string;
6
+ type: string
7
+ message: string
8
8
  }
9
9
  export interface ContentApiSearchResponse {
10
- page: number;
11
- results_per_page: number;
12
- results_size: number;
13
- total_results_size: number;
14
- total_pages: number;
15
- next_page: string | null;
16
- prev_page: string | null;
17
- results: ContentApiDocument[];
10
+ page: number
11
+ results_per_page: number
12
+ results_size: number
13
+ total_results_size: number
14
+ total_pages: number
15
+ next_page: string | null
16
+ prev_page: string | null
17
+ results: ContentApiDocument[]
18
18
  }
19
19
 
20
20
  export interface ContentApiDocument {
21
- id: string;
22
- uid: string | null;
23
- url: string | null;
24
- type: string;
25
- href: string;
26
- tags: string[];
27
- first_publication_date: string;
28
- last_publication_date: string;
29
- slugs: string[];
30
- linked_documents: unknown[];
31
- lang: string;
32
- alternate_languages: ContentApiAlternateLanguage[];
21
+ id: string
22
+ uid: string | null
23
+ url: string | null
24
+ type: string
25
+ href: string
26
+ tags: string[]
27
+ first_publication_date: string
28
+ last_publication_date: string
29
+ slugs: string[]
30
+ linked_documents: unknown[]
31
+ lang: string
32
+ alternate_languages: ContentApiAlternateLanguage[]
33
33
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- data: Record<string, any>;
34
+ data: Record<string, any>
35
35
  }
36
36
 
37
37
  export interface ContentApiGraphQLResponse {
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- data: Record<string, any>;
39
+ data: Record<string, any>
40
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- errors?: { message: string; locations: any }[];
41
+ errors?: { message: string; locations: any }[]
42
42
  }
43
43
 
44
44
  export interface ContentApiRef {
45
- id: string;
46
- ref: string;
47
- label: string;
48
- isMasterRef?: boolean;
49
- scheduledAt?: number | undefined;
45
+ id: string
46
+ ref: string
47
+ label: string
48
+ isMasterRef?: boolean
49
+ scheduledAt?: number | undefined
50
50
  }
51
51
 
52
52
  interface ContentApiAlternateLanguage {
53
- id: string;
54
- type: string;
55
- lang: string;
56
- uid?: string;
53
+ id: string
54
+ type: string
55
+ lang: string
56
+ uid?: string
57
57
  }
58
58
 
59
59
  interface ContentApiRepoConfigResponse {
60
- refs: ContentApiRef[];
61
- bookmarks: Record<string, unknown>;
62
- types: Record<string, string>;
60
+ refs: ContentApiRef[]
61
+ bookmarks: Record<string, unknown>
62
+ types: Record<string, string>
63
63
  languages: {
64
- id: string;
65
- name: string;
66
- is_master: boolean;
67
- }[];
68
- oauth_initiate: string;
69
- oauth_token: string;
70
- tags: string[];
71
- license: string;
72
- version: string;
64
+ id: string
65
+ name: string
66
+ is_master: boolean
67
+ }[]
68
+ oauth_initiate: string
69
+ oauth_token: string
70
+ tags: string[]
71
+ license: string
72
+ version: string
73
73
  }
74
74
 
75
75
  type SearchQueryParams = {
76
- ref?: string;
77
- query?: string;
78
- q?: string;
79
- graphQuery?: string;
80
- fetchLinks?: string;
81
- orderings?: string;
82
- pageSize?: number;
83
- page?: number;
84
- lang?: string;
85
- after?: string;
86
- routes?: string;
87
- };
88
-
89
- type ApiVersions = "v1" | "v2";
76
+ ref?: string
77
+ query?: string
78
+ q?: string
79
+ graphQuery?: string
80
+ fetchLinks?: string
81
+ orderings?: string
82
+ pageSize?: number
83
+ page?: number
84
+ lang?: string
85
+ after?: string
86
+ routes?: string
87
+ }
88
+
89
+ type ApiVersions = "v1" | "v2"
90
90
 
91
91
  /**
92
- * Client to query the Prismic content api. Uses Playwright to benefit from
93
- * network request traces in your reports. See api docs:
94
- * https://prismic.io/docs/rest-api-technical-reference
92
+ * Client to query the Prismic content api. Uses Playwright to benefit from network request traces
93
+ * in your reports. See api docs: https://prismic.io/docs/rest-api-technical-reference
95
94
  */
96
95
  export class ContentApiClient extends AuthenticatedApiClient {
97
- private version: ApiVersions;
98
- private accessToken: string | undefined;
96
+ private version: ApiVersions
97
+ private accessToken: string | undefined
99
98
 
100
99
  /**
101
- * @example To instantiate the class:
100
+ * @example
101
+ * To instantiate the class:
102
102
  *
103
- * ```js
104
- * new ContentApiClient("https://my-repo.cdn.prismic.io", {
103
+ * ```js
104
+ * new ContentApiClient("https://my-repo.cdn.prismic.io", {
105
105
  * version: "v2",
106
106
  * accessToken: "my-secret-token",
107
- * });
108
- * ```
107
+ * });
108
+ * ```
109
109
  *
110
- * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
110
+ * @param baseURL - The api base URL like https://my-repo.cdn.prismic.io
111
111
  * @param config - Optional configuration
112
112
  *
113
113
  * - {@link config.version}: Api version, default is "v2"
114
114
  * - {@link config.accessToken}: Access token for the content api -
115
- * https://prismic.io/docs/access-token
115
+ * https://prismic.io/docs/access-token
116
116
  */
117
- constructor(
118
- baseURL: string,
119
- config: { version?: ApiVersions; accessToken?: string } = {},
120
- ) {
117
+ constructor(baseURL: string, config: { version?: ApiVersions; accessToken?: string } = {}) {
121
118
  // Use an empty string as Authorization header in case it is already set globally in the project Playwright config file.
122
119
  // This is because the content api returns an error in case it gets an non-empty invalid Authorization
123
120
  // even though it actually checks authorization from the access_token query parameter.
124
- super(baseURL, config.accessToken || "");
125
- this.version = config.version || "v2";
126
- this.accessToken = config.accessToken;
121
+ super(baseURL, config.accessToken || "")
122
+ this.version = config.version || "v2"
123
+ this.accessToken = config.accessToken
127
124
  }
128
125
 
129
126
  async get(
@@ -131,15 +128,13 @@ export class ContentApiClient extends AuthenticatedApiClient {
131
128
  params?: SearchQueryParams,
132
129
  headers?: Record<string, string>,
133
130
  ): Promise<APIResponse> {
134
- const context = await this.getContext();
135
- const securityParams = {
136
- ...(this.accessToken ? { access_token: this.accessToken } : {}),
137
- };
131
+ const context = await this.getContext()
132
+ const securityParams = this.accessToken ? { access_token: this.accessToken } : {} as Record<string, never>
138
133
 
139
134
  return context.get(path, {
140
135
  params: { ...securityParams, ...params },
141
136
  headers,
142
- });
137
+ })
143
138
  }
144
139
 
145
140
  async getAsJson<T>(
@@ -147,77 +142,62 @@ export class ContentApiClient extends AuthenticatedApiClient {
147
142
  params?: SearchQueryParams,
148
143
  headers?: Record<string, string>,
149
144
  ): Promise<T> {
150
- const response = await this.get(url, params, headers);
145
+ const response = await this.get(url, params, headers)
151
146
 
152
- return response.json() as T;
147
+ return response.json() as T
153
148
  }
154
149
 
155
150
  /** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
156
- async graphql(
157
- ref: string,
158
- query: string,
159
- ): Promise<ContentApiGraphQLResponse> {
160
- return this.getAsJson<ContentApiGraphQLResponse>(
161
- "graphql",
162
- { query },
163
- { "Prismic-ref": ref },
164
- );
151
+ async graphql(ref: string, query: string): Promise<ContentApiGraphQLResponse> {
152
+ return this.getAsJson<ContentApiGraphQLResponse>("graphql", { query }, { "Prismic-ref": ref })
165
153
  }
166
154
 
167
155
  async getRefs(): Promise<ContentApiRef[]> {
168
- const data = await this.getAsJson<ContentApiRepoConfigResponse>(
169
- `api/${this.version}`,
170
- );
156
+ const data = await this.getAsJson<ContentApiRepoConfigResponse>(`api/${this.version}`)
171
157
 
172
- return data.refs;
158
+ return data.refs
173
159
  }
174
160
 
175
161
  async getMasterRef(): Promise<string> {
176
- const refs = await this.getRefs();
162
+ const refs = await this.getRefs()
177
163
 
178
- const masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);
164
+ const masterRef = refs.find(({ isMasterRef }) => isMasterRef === true)
179
165
  if (!masterRef) {
180
- throw "No master ref found";
166
+ throw "No master ref found"
181
167
  }
182
168
 
183
- return masterRef.ref;
169
+ return masterRef.ref
184
170
  }
185
171
 
186
172
  async getRefByReleaseID(releaseID: string): Promise<string> {
187
- const refs = await this.getRefs();
188
- const release = refs.find(({ id }) => id === releaseID);
173
+ const refs = await this.getRefs()
174
+ const release = refs.find(({ id }) => id === releaseID)
189
175
  if (!release) {
190
- throw `No ref found for release ${releaseID}`;
176
+ throw `No ref found for release ${releaseID}`
191
177
  }
192
178
 
193
- return release.ref;
179
+ return release.ref
194
180
  }
195
181
 
196
182
  /** Search documents from the `/api/v<version>/documents/search` endpoint. */
197
183
  async search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {
198
- let ref = filters?.ref;
184
+ let ref = filters?.ref
199
185
  if (!ref) {
200
- ref = await this.getMasterRef();
186
+ ref = await this.getMasterRef()
201
187
  }
202
188
 
203
- return this.getAsJson<ContentApiSearchResponse>(
204
- `api/${this.version}/documents/search`,
205
- {
206
- ...filters,
207
- ref,
208
- },
209
- );
189
+ return this.getAsJson<ContentApiSearchResponse>(`api/${this.version}/documents/search`, {
190
+ ...filters,
191
+ ref,
192
+ })
210
193
  }
211
194
 
212
195
  /**
213
- * Search for a single document by its it, using the
214
- * `/api/v<version>/documents/search` endpoint and a default filter.
196
+ * Search for a single document by its it, using the `/api/v<version>/documents/search` endpoint
197
+ * and a default filter.
215
198
  */
216
- async searchByID(
217
- id: string,
218
- filters?: SearchQueryParams,
219
- ): Promise<ContentApiSearchResponse> {
220
- return this.search({ ...filters, q: `[[at(document.id, "${id}")]]` });
199
+ async searchByID(id: string, filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {
200
+ return this.search({ ...filters, q: `[[at(document.id, "${id}")]]` })
221
201
  }
222
202
 
223
203
  /** Retrieve a single document or undefined if not found. */
@@ -225,14 +205,14 @@ export class ContentApiClient extends AuthenticatedApiClient {
225
205
  id: string,
226
206
  filters?: SearchQueryParams,
227
207
  ): Promise<ContentApiDocument | undefined> {
228
- const data = await this.searchByID(id, filters);
208
+ const data = await this.searchByID(id, filters)
229
209
  switch (data.results_size) {
230
210
  case 0:
231
- return;
211
+ return
232
212
  case 1:
233
- return data.results[0];
213
+ return data.results[0]
234
214
  default:
235
- throw new Error(`Too many documents returned with the same id ${id}`);
215
+ throw new Error(`Too many documents returned with the same id ${id}`)
236
216
  }
237
217
  }
238
218
  }