@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,24 +1,20 @@
1
- import axios, { AxiosInstance, AxiosResponse } from "axios";
1
+ import type { AxiosInstance, AxiosResponse } from "axios"
2
+ import axios from "axios"
2
3
 
3
- import { AuthConfig } from "../types";
4
+ import type { AuthConfig } from "../types"
5
+ import { extractCookie } from "../utils/cookies"
6
+ import { logHttpResponse, logger } from "../utils/log"
7
+ import { getRepositoryUrl } from "../utils/urls"
4
8
 
5
- import { extractCookie } from "../utils/cookies";
6
- import { logHttpResponse, logger } from "../utils/log";
7
- import { getRepositoryUrl } from "../utils/urls";
8
-
9
- /**
10
- * Client for interacting with the Wroom service to perform operations on
11
- * repositories.
12
- */
9
+ /** Client for interacting with the Wroom service to perform operations on repositories. */
13
10
  export class WroomClient {
14
- private readonly client: AxiosInstance;
15
- private loggedIn = false;
11
+ private readonly client: AxiosInstance
12
+ private loggedIn = false
16
13
 
17
14
  /**
18
15
  * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
19
16
  * @param auth - Authentication credentials.
20
- * @param cluster - Cluster where to create the repository (only work in
21
- * staging)
17
+ * @param cluster - Cluster where to create the repository (only work in staging)
22
18
  */
23
19
  constructor(
24
20
  baseURL: string,
@@ -29,7 +25,7 @@ export class WroomClient {
29
25
  ? {
30
26
  "X-Prismic-Cluster": cluster,
31
27
  }
32
- : {};
28
+ : {}
33
29
 
34
30
  this.client = axios.create({
35
31
  baseURL,
@@ -40,58 +36,54 @@ export class WroomClient {
40
36
  "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
41
37
  ...clusterHeader,
42
38
  },
43
- });
39
+ })
44
40
 
45
41
  // cookies are not forwarded automatically in a non-browser env
46
42
  this.client.interceptors.response.use((response) => {
47
- const cookies = response.headers["set-cookie"];
43
+ const cookies = response.headers["set-cookie"]
48
44
  if (cookies && extractCookie(cookies, "SESSION")) {
49
- this.client.defaults.headers["Cookie"] = cookies;
45
+ this.client.defaults.headers["Cookie"] = cookies
50
46
  }
51
47
 
52
- return response;
53
- });
48
+ return response
49
+ })
54
50
  }
55
51
 
56
52
  getBaseURL(): string {
57
- return this.client.getUri();
53
+ return this.client.getUri()
58
54
  }
59
55
 
60
- /** authenticated GET request on the wroom backend */
56
+ /** Authenticated GET request on the wroom backend */
61
57
  async get(repository: string | null, path: string): Promise<AxiosResponse> {
62
58
  if (!this.loggedIn) {
63
- await this.login();
59
+ await this.login()
64
60
  }
65
61
 
66
- let url = new URL(path, this.client.getUri()).toString();
62
+ let url = new URL(path, this.client.getUri()).toString()
67
63
  if (repository) {
68
- url = getRepositoryUrl(url, repository);
64
+ url = getRepositoryUrl(url, repository)
69
65
  }
70
66
 
71
- return this.client.get(url);
67
+ return this.client.get(url)
72
68
  }
73
69
 
74
- /** authenticated POST request on the wroom backend */
75
- async post(
76
- repository: string | null,
77
- path: string,
78
- data?: unknown,
79
- ): Promise<AxiosResponse> {
70
+ /** Authenticated POST request on the wroom backend */
71
+ async post(repository: string | null, path: string, data?: unknown): Promise<AxiosResponse> {
80
72
  if (!this.loggedIn) {
81
- await this.login();
73
+ await this.login()
82
74
  }
83
75
 
84
- let url = new URL(path, this.client.getUri()).toString();
76
+ let url = new URL(path, this.client.getUri()).toString()
85
77
  if (repository) {
86
- url = getRepositoryUrl(url, repository);
78
+ url = getRepositoryUrl(url, repository)
87
79
  }
88
80
  const response = await this.client.post(url.toString(), data, {
89
81
  params: {
90
82
  _: extractCookie(this.client.defaults.headers["Cookie"], "X_XSRF"),
91
83
  },
92
- });
84
+ })
93
85
 
94
- return response;
86
+ return response
95
87
  }
96
88
 
97
89
  /**
@@ -100,18 +92,13 @@ export class WroomClient {
100
92
  * @param {string} repository - The repository name
101
93
  * @param {string} email - The email of the user
102
94
  * @param {string} role - The new role to be given
103
- *
104
95
  * @returns The Axios Reponse
105
96
  */
106
- async updateRole(
107
- repository: string,
108
- email: string,
109
- role: string,
110
- ): Promise<AxiosResponse> {
111
- const params = new URLSearchParams({ email, profile: role });
112
- const path = `/app/settings/users/profiles?${params.toString()}`;
97
+ async updateRole(repository: string, email: string, role: string): Promise<AxiosResponse> {
98
+ const params = new URLSearchParams({ email, profile: role })
99
+ const path = `/app/settings/users/profiles?${params.toString()}`
113
100
 
114
- return this.post(repository, path);
101
+ return this.post(repository, path)
115
102
  }
116
103
 
117
104
  /**
@@ -120,7 +107,6 @@ export class WroomClient {
120
107
  * @param {string} repository - The repository name
121
108
  * @param {string} email - The email of the user
122
109
  * @param {string} rolePerLocal - The role per local object
123
- *
124
110
  * @returns The Axios Reponse
125
111
  */
126
112
  async updateRolePerLocal(
@@ -128,10 +114,10 @@ export class WroomClient {
128
114
  email: string,
129
115
  rolePerLocal: Record<string, string>,
130
116
  ): Promise<AxiosResponse> {
131
- const params = new URLSearchParams({ email });
132
- const path = `/app/settings/users/rolesperlocale?${params.toString()}`;
117
+ const params = new URLSearchParams({ email })
118
+ const path = `/app/settings/users/rolesperlocale?${params.toString()}`
133
119
 
134
- return this.post(repository, path, rolePerLocal);
120
+ return this.post(repository, path, rolePerLocal)
135
121
  }
136
122
 
137
123
  /**
@@ -140,17 +126,17 @@ export class WroomClient {
140
126
  * @throws Error if the login to Wroom fails.
141
127
  */
142
128
  private async login(): Promise<void> {
143
- const profiler = logger.startTimer();
129
+ const profiler = logger.startTimer()
144
130
  const response = await this.client.post<string>("/authentication/signin", {
145
131
  email: this.auth.email,
146
132
  password: this.auth.password,
147
- });
133
+ })
148
134
 
149
135
  if (response.status !== 200) {
150
- logHttpResponse(response);
151
- throw new Error("Could not login to Prismic, check your credentials");
136
+ logHttpResponse(response)
137
+ throw new Error("Could not login to Prismic, check your credentials")
152
138
  }
153
- this.loggedIn = true;
154
- profiler.done({ message: "logged in to Prismic" });
139
+ this.loggedIn = true
140
+ profiler.done({ message: "logged in to Prismic" })
155
141
  }
156
142
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from "./managers/repositories";
2
- export * from "./managers/repository";
3
- export * from "./clients/coreApi";
4
- export * from "./clients/contentApi";
5
- export * from "./clients/assetApi";
6
- export * from "./clients/migrationApi";
7
- export * from "./types";
1
+ export * from "./managers/repositories"
2
+ export * from "./managers/repository"
3
+ export * from "./clients/coreApi"
4
+ export * from "./clients/contentApi"
5
+ export * from "./clients/assetApi"
6
+ export * from "./clients/migrationApi"
7
+ export * from "./types"
@@ -1,26 +1,24 @@
1
- import { SetupConfiguration, UrlConfig } from "../types";
2
-
3
- import { AssetApiClient } from "../clients/assetApi";
4
- import { AuthenticationApiClient } from "../clients/authenticationApi";
5
- import { CoreApiClient } from "../clients/coreApi";
6
- import { CustomTypesApiClient } from "../clients/customTypesApi";
7
- import { IntegrationFieldsClient } from "../clients/integrationFields";
8
- import { ManageV2Client } from "../clients/manageV2";
9
- import { MigrationApiClient } from "../clients/migrationApi";
10
- import { WroomClient } from "../clients/wroom";
11
- import { EnvVariableManager } from "../utils/envVariableManager";
12
- import { logHttpResponse, logger } from "../utils/log";
13
- import { randomString } from "../utils/random";
14
- import { getRepositoryUrl } from "../utils/urls";
15
-
16
- import { RepositoryConfig, RepositoryManager } from "./repository";
1
+ import { AssetApiClient } from "../clients/assetApi"
2
+ import { AuthenticationApiClient } from "../clients/authenticationApi"
3
+ import { CoreApiClient } from "../clients/coreApi"
4
+ import { CustomTypesApiClient } from "../clients/customTypesApi"
5
+ import { IntegrationFieldsClient } from "../clients/integrationFields"
6
+ import { ManageV2Client } from "../clients/manageV2"
7
+ import { MigrationApiClient } from "../clients/migrationApi"
8
+ import { WroomClient } from "../clients/wroom"
9
+ import type { SetupConfiguration, UrlConfig } from "../types"
10
+ import { EnvVariableManager } from "../utils/envVariableManager"
11
+ import { logHttpResponse, logger } from "../utils/log"
12
+ import { randomString } from "../utils/random"
13
+ import { getRepositoryUrl } from "../utils/urls"
14
+ import type { RepositoryConfig } from "./repository"
15
+ import { RepositoryManager } from "./repository"
17
16
 
18
17
  /**
19
- * Factory method to create a RepositoriesManager to manage repositories test
20
- * data.
18
+ * Factory method to create a RepositoriesManager to manage repositories test data.
21
19
  *
22
- * @param configuration - Global object containing the different configurations
23
- * required to setup the RepositoriesManager.
20
+ * @param configuration - Global object containing the different configurations required to setup
21
+ * the RepositoriesManager.
24
22
  *
25
23
  * - {@link configuration.urlConfig}: Configuration around the API's URLs management.
26
24
  * - {@link configuration.authConfig}: Configuration around the authentication of a user.
@@ -31,28 +29,23 @@ import { RepositoryConfig, RepositoryManager } from "./repository";
31
29
  export const createRepositoriesManager = (
32
30
  configuration: SetupConfiguration,
33
31
  ): RepositoriesManager => {
34
- return new RepositoriesManager(configuration);
35
- };
32
+ return new RepositoriesManager(configuration)
33
+ }
36
34
 
37
35
  /** Utility object to manage Prismic test data */
38
36
  export class RepositoriesManager {
39
37
  private readonly config: Omit<SetupConfiguration, "urlConfig"> & {
40
- urlConfig: UrlConfig;
41
- };
42
- private readonly wroomClient: WroomClient;
43
- private readonly authClient: AuthenticationApiClient;
44
- private readonly manageV2Client: ManageV2Client;
45
- /**
46
- * helper to keep track of repositories across independent test phases (setup,
47
- * teardown)
48
- */
49
- private readonly repositories = new EnvVariableManager(
50
- "_PRISMIC_E2E_TESTS_REPOS",
51
- );
38
+ urlConfig: UrlConfig
39
+ }
40
+ private readonly wroomClient: WroomClient
41
+ private readonly authClient: AuthenticationApiClient
42
+ private readonly manageV2Client: ManageV2Client
43
+ /** Helper to keep track of repositories across independent test phases (setup, teardown) */
44
+ private readonly repositories = new EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS")
52
45
 
53
46
  /**
54
- * @param configuration - Global object containing the different configuration
55
- * required to setup the different clients.
47
+ * @param configuration - Global object containing the different configuration required to setup
48
+ * the different clients.
56
49
  * @param credentials - Authentication credentials (email and password)
57
50
  */
58
51
  constructor(configuration: SetupConfiguration) {
@@ -64,39 +57,35 @@ export class RepositoriesManager {
64
57
  typeof configuration.urlConfig === "string"
65
58
  ? this.inferUrls(configuration.urlConfig)
66
59
  : configuration.urlConfig,
67
- };
60
+ }
68
61
 
69
62
  this.wroomClient = new WroomClient(
70
63
  this.config.urlConfig.baseURL,
71
64
  this.config.authConfig,
72
65
  this.config.cluster,
73
- );
66
+ )
74
67
  this.authClient = new AuthenticationApiClient(
75
68
  this.config.urlConfig.authenticationApi,
76
69
  this.config.authConfig,
77
- );
70
+ )
78
71
  this.manageV2Client = new ManageV2Client(
79
72
  this.config.urlConfig.baseURL,
80
73
  this.config.manageV2Config,
81
- );
74
+ )
82
75
 
83
76
  // This logic specific to staging environment allow us to target a specific version of the custom types API.
84
77
  // This is only works for unify-exp at the moment.
85
78
  // Having this logic here avoids duplicating it across different CI workflows.
86
79
  this.config.urlConfig.customTypesApi =
87
- configuration.environment === "stage" &&
88
- configuration.cluster === "unify-exp"
80
+ configuration.environment === "stage" && configuration.cluster === "unify-exp"
89
81
  ? `https://customtypes.wroom.io/${configuration.cluster}/`
90
- : this.config.urlConfig.customTypesApi;
82
+ : this.config.urlConfig.customTypesApi
91
83
  }
92
84
 
93
- /**
94
- * If the baseURL is prismic.io, assume the other services have the format
95
- * <name>.prismic.io
96
- */
85
+ /** If the baseURL is prismic.io, assume the other services have the format <name>.prismic.io */
97
86
  private inferUrls(baseURL: string): UrlConfig {
98
- const url = new URL(baseURL);
99
- const protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol
87
+ const url = new URL(baseURL)
88
+ const protocol = url.protocol.slice(0, -1) // Remove the trailing colon from the protocol
100
89
 
101
90
  return {
102
91
  baseURL: baseURL,
@@ -108,100 +97,91 @@ export class RepositoriesManager {
108
97
  url.hostname === "prismic.io"
109
98
  ? `${protocol}://if-api.${url.hostname}`
110
99
  : `${protocol}://api.${url.hostname}`,
111
- };
100
+ }
112
101
  }
113
102
 
114
103
  /**
115
104
  * Generate a user token from the authentication service.
116
105
  *
117
- * @returns a JWT token
106
+ * @returns A JWT token
118
107
  */
119
108
  async getUserApiToken(): Promise<string> {
120
- return this.authClient.getToken();
109
+ return this.authClient.getToken()
121
110
  }
122
111
 
123
112
  /**
124
113
  * Create a new repository in Wroom.
125
114
  *
126
115
  * @param repositoryName - The name of the repository.
127
- *
128
116
  * @throws Error if the repository creation fails.
129
117
  */
130
118
  async createRepository(
131
119
  config: {
132
- prefix?: string;
120
+ prefix?: string
133
121
  } & RepositoryConfig = {},
134
122
  ): Promise<RepositoryManager> {
135
- const profiler = logger.startTimer();
136
-
137
- const { prefix = "e2e-tests" } = config;
138
- const repositoryName = `${prefix}-${randomString()}`;
139
-
140
- const response = await this.wroomClient.post(
141
- null,
142
- "authentication/newrepository",
143
- {
144
- domain: repositoryName,
145
- framework: "next",
146
- plan: "personal",
147
- isAnnual: "false",
148
- role: "developer",
149
- },
150
- );
123
+ const profiler = logger.startTimer()
124
+
125
+ const { prefix = "e2e-tests" } = config
126
+ const repositoryName = `${prefix}-${randomString()}`
127
+
128
+ const response = await this.wroomClient.post(null, "authentication/newrepository", {
129
+ domain: repositoryName,
130
+ framework: "next",
131
+ plan: "personal",
132
+ isAnnual: "false",
133
+ role: "developer",
134
+ })
151
135
  if (response.status !== 200) {
152
- logHttpResponse(response);
153
- throw new Error(`Could not create repository ${repositoryName}`);
136
+ logHttpResponse(response)
137
+ throw new Error(`Could not create repository ${repositoryName}`)
154
138
  }
155
- this.repositories.add(repositoryName);
139
+ this.repositories.add(repositoryName)
156
140
 
157
- const repository = this.getRepositoryManager(repositoryName);
158
- const version = await repository.getDeployedVersion();
141
+ const repository = this.getRepositoryManager(repositoryName)
142
+ const version = await repository.getDeployedVersion()
159
143
 
160
144
  profiler.done({
161
145
  message: `created repository '${repositoryName}', Wroom version is "${version}"`,
162
- });
163
- await repository.configure(config);
146
+ })
147
+ await repository.configure(config)
164
148
 
165
- return repository;
149
+ return repository
166
150
  }
167
151
 
168
152
  /**
169
153
  * Delete a repository from Wroom.
170
154
  *
171
155
  * @param repository - The name of the repository.
172
- *
173
156
  * @throws Error if the repository deletion fails.
174
157
  */
175
158
  async deleteRepository(repository: string): Promise<void> {
176
- const profiler = logger.startTimer();
159
+ const profiler = logger.startTimer()
177
160
 
178
161
  const post = async () =>
179
162
  this.wroomClient.post(repository, "app/settings/delete", {
180
163
  confirm: repository,
181
164
  password: this.config.authConfig.password,
182
- });
183
- const response = await post();
165
+ })
166
+ const response = await post()
184
167
  if (response.status !== 200) {
185
168
  // sometimes the deletion returns 500 but actually succeeds
186
169
  // we run the query again and check the repo is actually deleted (404)
187
- const retry = await post();
170
+ const retry = await post()
188
171
  if (retry.status !== 404) {
189
- logHttpResponse(response);
190
- throw new Error(`Could not delete repository ${repository}`);
172
+ logHttpResponse(response)
173
+ throw new Error(`Could not delete repository ${repository}`)
191
174
  }
192
175
  }
193
- this.repositories.remove(repository);
194
- profiler.done({ message: `deleted repository '${repository}'` });
176
+ this.repositories.remove(repository)
177
+ profiler.done({ message: `deleted repository '${repository}'` })
195
178
  }
196
179
 
197
- /**
198
- * Cleanup test data. For example, it deletes repositories created using
199
- * createRepository()
200
- */
180
+ /** Cleanup test data. For example, it deletes repositories created using createRepository() */
201
181
  async tearDown(): Promise<void> {
202
- const repositories = this.repositories.getAll();
182
+ const repositories = this.repositories.getAll()
203
183
  for (const repository of repositories) {
204
- await this.deleteRepository(repository);
184
+ await this.deleteRepository(repository)
205
185
  }
206
186
  }
207
187
 
@@ -211,34 +191,31 @@ export class RepositoriesManager {
211
191
  * @param repository - The name of the repository.
212
192
  */
213
193
  getRepositoryManager(repository: string): RepositoryManager {
214
- const { urlConfig } = this.config;
215
- const authToken = () => this.authClient.getToken();
216
- const customTypeClient = new CustomTypesApiClient(
217
- urlConfig.customTypesApi,
218
- {
219
- authToken,
220
- repository,
221
- },
222
- );
223
- const coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository);
224
- const coreApiClient = new CoreApiClient(coreApiUrl, authToken);
194
+ const { urlConfig } = this.config
195
+ const authToken = () => this.authClient.getToken()
196
+ const customTypeClient = new CustomTypesApiClient(urlConfig.customTypesApi, {
197
+ authToken,
198
+ repository,
199
+ })
200
+ const coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository)
201
+ const coreApiClient = new CoreApiClient(coreApiUrl, authToken)
225
202
  const migrationApiClient = urlConfig.migrationApi
226
203
  ? new MigrationApiClient(urlConfig.migrationApi, {
227
204
  authToken,
228
205
  repository,
229
206
  })
230
- : undefined;
207
+ : undefined
231
208
  const assetApiClient = new AssetApiClient(urlConfig.assetApi, {
232
209
  authToken,
233
210
  repository,
234
- });
211
+ })
235
212
  const integrationFieldsClient = urlConfig.integrationFieldApi
236
213
  ? new IntegrationFieldsClient(urlConfig.integrationFieldApi, {
237
214
  customTypesApiClient: customTypeClient,
238
215
  wroomClient: this.wroomClient,
239
216
  repository,
240
217
  })
241
- : undefined;
218
+ : undefined
242
219
 
243
220
  return new RepositoryManager(
244
221
  repository,
@@ -250,6 +227,6 @@ export class RepositoriesManager {
250
227
  assetApiClient,
251
228
  this.manageV2Client,
252
229
  integrationFieldsClient,
253
- );
230
+ )
254
231
  }
255
232
  }