@prismicio/e2e-tests-utils 1.0.0-alpha.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # @prismicio/e2e-tests-utils
2
2
 
3
- A utility library for end-to-end tests with Prismic.
3
+ This library comprises utility functions tailored for end-to-end tests at Prismic, with a primary focus on tasks like repository creation, configuration, and deletion.
4
+
5
+ #### Purpose
6
+ In the context of testing, it's essential to operate in a controlled environment where the necessary conditions are defined explicitly. To avoid redundant logic across various services for setting up test data, this library consolidates and provides the required functionalities.
4
7
 
5
8
  ## Installation
6
9
 
7
10
  ```bash
8
- npm install @prismicio/e2e-tests-utils
11
+ npm install --save-dev @prismicio/e2e-tests-utils
9
12
  ```
10
13
 
11
14
  ## Usage
@@ -18,21 +21,21 @@ Useful to run the tests on a clean repository with a controlled configuration, f
18
21
  import { createRepositoriesManager } from "@prismicio/e2e-tests-utils";
19
22
  import type { RepositoryConfig } from "@prismicio/e2e-tests-utils";
20
23
 
21
- export const settings: RepositoryConfig = {
24
+ const config: RepositoryConfig = {
22
25
  locales: ["en-gb", "fr-fr"],
23
26
  defaultLocale: "en-gb",
27
+ // ... see RepositoryConfig for other options
24
28
  };
29
+ const credentials = { email, password };
25
30
 
26
- const reposClient = createRepositoriesManager("https://prismic.io", {
27
- email,
28
- password,
29
- });
30
- const repositoryClient = await reposClient.createRepository(settings); // creates the repository and applies the settings
31
+ const testUtils = createRepositoriesManager("https://prismic.io", credentials);
32
+ const repository = await testUtils.createRepository(config);
31
33
 
32
- console.log("repository name is", repositoryClient.name);
34
+ // A repository is now available with a unique name and configured as required
35
+ repository.getBaseURL() // https://my-unique-repo-name.prismic.io
33
36
 
34
- // run tests then delete the repository
35
- await reposClient.tearDown();
37
+ // run your tests, delete the repository
38
+ await testUtils.tearDown();
36
39
  ```
37
40
 
38
41
  ### Create Custom Types
@@ -75,53 +78,45 @@ const customType: CustomType = {
75
78
  },
76
79
  };
77
80
 
78
- await repositoryClient.createSlices([slice]);
79
- await repositoryClient.createCustomTypes([customType]);
81
+ // Create them individually
82
+ await repository.createSlices([slice]);
83
+ await repository.createCustomTypes([customType]);
80
84
 
81
- // Create custom types while creating the repository
82
- const settings = { slices: [slice], customTypes: [customType] };
83
- await reposClient.createRepository(settings);
85
+ // Or create them via the RepositoryConfig object
86
+ const config = { slices: [slice], customTypes: [customType] };
87
+ await testUtils.createRepository(config);
84
88
  ```
85
89
 
86
90
  ### Retrieve an API token (jwt)
87
91
 
88
92
  ```typescript
89
- import { createRepositoriesManager } from "@prismicio/e2e-tests-utils";
90
-
91
- const reposClient = createRepositoriesManager("https://prismic.io", {
92
- email,
93
- password,
94
- });
95
- const token = await reposClient.getUserApiToken();
93
+ const token = await testUtils.getUserApiToken();
96
94
  ```
97
95
 
98
96
  ### Retrieve a RepositoryManager of an existing repository
99
97
 
100
98
  ```typescript
101
- import { createRepositoriesManager } from "@prismicio/e2e-tests-utils";
102
-
103
- const reposClient = createRepositoriesManager("https://prismic.io", {
104
- email,
105
- password,
106
- });
107
99
  const repository = await testUtils.getRepositoryManager(name);
108
- // use it to configure the repository or any other operations.
100
+ // configure multiple settings and once
109
101
  await repository.configure(settings);
102
+ // or configure them individually
103
+ await repository.createRelease("next release");
110
104
  ```
111
105
 
112
- ### How does the library determine endpoints urls its using under the hood (authentication server, custom types api)?
106
+ ### How does the library know which endpoints urls to use under the hood (authentication server, custom types api)?
113
107
 
114
108
  When you create the manager, you have 2 options:
115
109
 
116
- - Provide the base Prismic url, like `createRepositoriesManager("https://prismic.io", { email, password })`. The library infers the service urls from the base URL like `http://authentication.prismic.io`
117
- - One a dev environment, you might want to have control over each service url. Use `createRepositoriesManager({ baseURL: "https://...", customTypesApi : "https://...", authenticationApi : "https://..."}, { email, password })`
110
+ - Provide the base Prismic url, like `createRepositoriesManager("https://prismic.io", credentials)`. The library infers the service urls from the base URL like `http://authentication.prismic.io`
111
+ - One a dev environment, you might want to have control over each service url. Use `createRepositoriesManager({ baseURL: "https://...", customTypesApi : "https://...", authenticationApi : "https://..."}, credentials)`
118
112
 
119
113
  #### Customise the log level
120
114
 
121
- By default, the library logs each operation, you can change this.
115
+ By default, the library logs each operation, this can be changed:
116
+
117
+ - Set the environment variable to `prismic_e2e_tests_utils_silent` to `true` to remove all logs.
118
+ - Set the environment variable to `prismic_e2e_tests_utils_log_level` to `info` or `debug`.
122
119
 
123
- Set the environment variable to `prismic_e2e_tests_utils_silent` to `true`` to remove all logs.
124
- Set the environment variable to `prismic_e2e_tests_utils_log_level`to`info`or`debug`.
125
120
 
126
121
  ---
127
122
 
@@ -11,7 +11,7 @@ const createAuthenticationApiClient = (baseURL, auth) => {
11
11
  });
12
12
  async function login() {
13
13
  const profiler = log.logger.startTimer();
14
- const result = await client.post("/login", {
14
+ const result = await client.post("login", {
15
15
  email: auth.email,
16
16
  password: auth.password
17
17
  });
@@ -1 +1 @@
1
- {"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n};\n\n/** Client for interacting with an authentication service to generate API tokens. */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: Credentials,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"/login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"generated user token from auth service\" });\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken() {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAWa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAWA,WAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,UAAU;AAAA,MAC1C,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpDC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK,EAAE,SAAS,yCAA0C,CAAA;AAEnE,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
1
+ {"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: Credentials,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"generated user token from auth service\" });\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken() {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAWa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAWA,WAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpDC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK,EAAE,SAAS,yCAA0C,CAAA;AAEnE,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
@@ -2,5 +2,5 @@ import { Credentials } from "../types";
2
2
  export type AuthenticationClient = {
3
3
  getToken: () => Promise<string>;
4
4
  };
5
- /** Client for interacting with an authentication service to generate API tokens. */
5
+ /** Client for interacting with the authentication service to manage tokens */
6
6
  export declare const createAuthenticationApiClient: (baseURL: string, auth: Credentials) => AuthenticationClient;
@@ -9,7 +9,7 @@ const createAuthenticationApiClient = (baseURL, auth) => {
9
9
  });
10
10
  async function login() {
11
11
  const profiler = logger.startTimer();
12
- const result = await client.post("/login", {
12
+ const result = await client.post("login", {
13
13
  email: auth.email,
14
14
  password: auth.password
15
15
  });
@@ -1 +1 @@
1
- {"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n};\n\n/** Client for interacting with an authentication service to generate API tokens. */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: Credentials,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"/login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"generated user token from auth service\" });\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken() {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t};\n};\n"],"names":[],"mappings":";;AAWa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAW,OAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,UAAU;AAAA,MAC1C,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK,EAAE,SAAS,yCAA0C,CAAA;AAEnE,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: Credentials,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"generated user token from auth service\" });\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken() {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t};\n};\n"],"names":[],"mappings":";;AAWa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAW,OAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK,EAAE,SAAS,yCAA0C,CAAA;AAEnE,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
@@ -18,10 +18,10 @@ const createRepositoriesManager = (urlConfig, auth) => {
18
18
  };
19
19
  class RepositoriesManager {
20
20
  /**
21
- * @param prismicUrl - The base URL of the Wroom app.
21
+ * @param urlConfig - The base URL of the Wroom app.
22
22
  * @param credentials - Authentication credentials (email and password)
23
23
  */
24
- constructor(urls, credentials) {
24
+ constructor(urlConfig, credentials) {
25
25
  __publicField(this, "credentials");
26
26
  __publicField(this, "urls");
27
27
  __publicField(this, "wroomClient");
@@ -32,10 +32,10 @@ class RepositoriesManager {
32
32
  */
33
33
  __publicField(this, "repositories", new envVariableManager.EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
34
34
  this.credentials = credentials;
35
- if (typeof urls === "string") {
36
- urls = this.inferUrls(urls);
35
+ if (typeof urlConfig === "string") {
36
+ urlConfig = this.inferUrls(urlConfig);
37
37
  }
38
- this.urls = urls;
38
+ this.urls = urlConfig;
39
39
  this.wroomClient = new wroom.WroomClient(this.urls.baseURL, this.credentials);
40
40
  this.authClient = authenticationApi.createAuthenticationApiClient(this.urls.authenticationApi, this.credentials);
41
41
  }
@@ -71,9 +71,9 @@ class RepositoriesManager {
71
71
  const profiler = log.logger.startTimer();
72
72
  const { prefix = "e2e-tests" } = config;
73
73
  const repositoryName = `${prefix}-${random.randomString()}`;
74
- const response = await this.wroomClient.post(null, "/authentication/newrepository", {
74
+ const response = await this.wroomClient.post(null, "authentication/newrepository", {
75
75
  domain: repositoryName,
76
- framework: "next",
76
+ framework: "vue",
77
77
  plan: "personal",
78
78
  isAnnual: "false",
79
79
  role: "developer"
@@ -97,7 +97,7 @@ class RepositoriesManager {
97
97
  */
98
98
  async deleteRepository(repository2) {
99
99
  const profiler = log.logger.startTimer();
100
- const post = async () => this.wroomClient.post(repository2, "./app/settings/delete", {
100
+ const post = async () => this.wroomClient.post(repository2, "app/settings/delete", {
101
101
  confirm: repository2,
102
102
  password: this.credentials.password
103
103
  });
@@ -1 +1 @@
1
- {"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { Credentials } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param urlConfig - If provided as an object:\n *\n * - {@link UrlConfig.baseURL}: The Prismic base URL.\n * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.\n * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.\n *\n * If provided as a string: It is treated as the base URL for Prismic. Other\n * URLs (Custom Types API, Auth API) will be derived from it.\n * @param auth - The authentication credentials\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\turlConfig: UrlConfig | string,\n\tauth: Credentials,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(urlConfig, auth);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly urls: UrlConfig;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param prismicUrl - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turls: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urls === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turls = this.inferUrls(urls);\n\t\t}\n\t\tthis.urls = urls;\n\t\tthis.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.urls.authenticationApi,\n\t\t\tthis.credentials,\n\t\t);\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"/authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"next\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tprofiler.done({ message: `created repository '${repositoryName}'` });\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"./app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.credentials.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param name - The name of the repository.\n\t */\n\tgetRepositoryManager(name: string): RepositoryManager {\n\t\tconst customTypeClient = createCustomTypesApiClient(\n\t\t\tthis.urls.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\n\t\treturn new RepositoryManager(name, this.wroomClient, customTypeClient);\n\t}\n}\n\nexport type UrlConfig = {\n\t/** Prismic base url */\n\tbaseURL: string;\n\t/** Custom types api base url */\n\tcustomTypesApi: string;\n\t/** Auth service api base url */\n\tauthenticationApi: string;\n};\n"],"names":["EnvVariableManager","WroomClient","createAuthenticationApiClient","logger","randomString","logHttpResponse","repository","createCustomTypesApiClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,MACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAIA,sCACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,SAAS,UAAU;AAEtB,aAAA,KAAK,UAAU,IAAI;AAAA,IAC1B;AACD,SAAK,OAAO;AACZ,SAAK,cAAc,IAAIC,kBAAY,KAAK,KAAK,SAAS,KAAK,WAAW;AACtE,SAAK,aAAaC,kBAAAA,8BACjB,KAAK,KAAK,mBACV,KAAK,WAAW;AAAA,EAElB;AAAA;A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,IAAA,CAC3B;AACI,UAAA,WAAW,MAAM;AACnB,QAAA,SAAS,WAAW,KAAK;AAGtB,YAAA,QAAQ,MAAM;AAChB,UAAA,MAAM,WAAW,KAAK;AACzBD,YAAA,gBAAgB,QAAQ;AACxB,cAAM,IAAI,MAAM,+BAA+BC,WAAU,EAAE;AAAA,MAC3D;AAAA,IACD;AACI,SAAA,aAAa,OAAOA,WAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuBA,WAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAWA,eAAc,cAAc;AAChC,YAAA,KAAK,iBAAiBA,WAAU;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqB,MAAY;AAChC,UAAM,mBAAmBC,eACxB,2BAAA,KAAK,KAAK,gBACV,MACA,KAAK,UAAU;AAGhB,WAAO,IAAIC,WAAA,kBAAkB,MAAM,KAAK,aAAa,gBAAgB;AAAA,EACtE;AACA;;;"}
1
+ {"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { Credentials } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param urlConfig - If provided as an object:\n *\n * - {@link UrlConfig.baseURL}: The Prismic base URL.\n * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.\n * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.\n *\n * If provided as a string: It is treated as the base URL for Prismic. Other\n * URLs (Custom Types API, Auth API) will be derived from it.\n * @param auth - The authentication credentials\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\turlConfig: UrlConfig | string,\n\tauth: Credentials,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(urlConfig, auth);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly urls: UrlConfig;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param urlConfig - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turlConfig: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urlConfig === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig = this.inferUrls(urlConfig);\n\t\t}\n\t\tthis.urls = urlConfig;\n\t\tthis.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.urls.authenticationApi,\n\t\t\tthis.credentials,\n\t\t);\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"vue\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tprofiler.done({ message: `created repository '${repositoryName}'` });\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.credentials.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param name - The name of the repository.\n\t */\n\tgetRepositoryManager(name: string): RepositoryManager {\n\t\tconst customTypeClient = createCustomTypesApiClient(\n\t\t\tthis.urls.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\n\t\treturn new RepositoryManager(name, this.wroomClient, customTypeClient);\n\t}\n}\n\nexport type UrlConfig = {\n\t/** Prismic base url */\n\tbaseURL: string;\n\t/** Custom types api base url */\n\tcustomTypesApi: string;\n\t/** Auth service api base url */\n\tauthenticationApi: string;\n};\n"],"names":["EnvVariableManager","WroomClient","createAuthenticationApiClient","logger","randomString","logHttpResponse","repository","createCustomTypesApiClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,WACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAIA,sCACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,cAAc,UAAU;AAEtB,kBAAA,KAAK,UAAU,SAAS;AAAA,IACpC;AACD,SAAK,OAAO;AACZ,SAAK,cAAc,IAAIC,kBAAY,KAAK,KAAK,SAAS,KAAK,WAAW;AACtE,SAAK,aAAaC,kBAAAA,8BACjB,KAAK,KAAK,mBACV,KAAK,WAAW;AAAA,EAElB;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;AAAA,IAAA,CAC3B;AACI,UAAA,WAAW,MAAM;AACnB,QAAA,SAAS,WAAW,KAAK;AAGtB,YAAA,QAAQ,MAAM;AAChB,UAAA,MAAM,WAAW,KAAK;AACzBD,YAAA,gBAAgB,QAAQ;AACxB,cAAM,IAAI,MAAM,+BAA+BC,WAAU,EAAE;AAAA,MAC3D;AAAA,IACD;AACI,SAAA,aAAa,OAAOA,WAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuBA,WAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAWA,eAAc,cAAc;AAChC,YAAA,KAAK,iBAAiBA,WAAU;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqB,MAAY;AAChC,UAAM,mBAAmBC,eACxB,2BAAA,KAAK,KAAK,gBACV,MACA,KAAK,UAAU;AAGhB,WAAO,IAAIC,WAAA,kBAAkB,MAAM,KAAK,aAAa,gBAAgB;AAAA,EACtE;AACA;;;"}
@@ -29,10 +29,10 @@ export declare class RepositoriesManager {
29
29
  */
30
30
  private readonly repositories;
31
31
  /**
32
- * @param prismicUrl - The base URL of the Wroom app.
32
+ * @param urlConfig - The base URL of the Wroom app.
33
33
  * @param credentials - Authentication credentials (email and password)
34
34
  */
35
- constructor(urls: UrlConfig | string, credentials: Credentials);
35
+ constructor(urlConfig: UrlConfig | string, credentials: Credentials);
36
36
  /**
37
37
  * If the baseURL is prismic.io, assume the other services have the format
38
38
  * <name>.prismic.io
@@ -16,10 +16,10 @@ const createRepositoriesManager = (urlConfig, auth) => {
16
16
  };
17
17
  class RepositoriesManager {
18
18
  /**
19
- * @param prismicUrl - The base URL of the Wroom app.
19
+ * @param urlConfig - The base URL of the Wroom app.
20
20
  * @param credentials - Authentication credentials (email and password)
21
21
  */
22
- constructor(urls, credentials) {
22
+ constructor(urlConfig, credentials) {
23
23
  __publicField(this, "credentials");
24
24
  __publicField(this, "urls");
25
25
  __publicField(this, "wroomClient");
@@ -30,10 +30,10 @@ class RepositoriesManager {
30
30
  */
31
31
  __publicField(this, "repositories", new EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
32
32
  this.credentials = credentials;
33
- if (typeof urls === "string") {
34
- urls = this.inferUrls(urls);
33
+ if (typeof urlConfig === "string") {
34
+ urlConfig = this.inferUrls(urlConfig);
35
35
  }
36
- this.urls = urls;
36
+ this.urls = urlConfig;
37
37
  this.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);
38
38
  this.authClient = createAuthenticationApiClient(this.urls.authenticationApi, this.credentials);
39
39
  }
@@ -69,9 +69,9 @@ class RepositoriesManager {
69
69
  const profiler = logger.startTimer();
70
70
  const { prefix = "e2e-tests" } = config;
71
71
  const repositoryName = `${prefix}-${randomString()}`;
72
- const response = await this.wroomClient.post(null, "/authentication/newrepository", {
72
+ const response = await this.wroomClient.post(null, "authentication/newrepository", {
73
73
  domain: repositoryName,
74
- framework: "next",
74
+ framework: "vue",
75
75
  plan: "personal",
76
76
  isAnnual: "false",
77
77
  role: "developer"
@@ -95,7 +95,7 @@ class RepositoriesManager {
95
95
  */
96
96
  async deleteRepository(repository) {
97
97
  const profiler = logger.startTimer();
98
- const post = async () => this.wroomClient.post(repository, "./app/settings/delete", {
98
+ const post = async () => this.wroomClient.post(repository, "app/settings/delete", {
99
99
  confirm: repository,
100
100
  password: this.credentials.password
101
101
  });
@@ -1 +1 @@
1
- {"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { Credentials } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param urlConfig - If provided as an object:\n *\n * - {@link UrlConfig.baseURL}: The Prismic base URL.\n * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.\n * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.\n *\n * If provided as a string: It is treated as the base URL for Prismic. Other\n * URLs (Custom Types API, Auth API) will be derived from it.\n * @param auth - The authentication credentials\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\turlConfig: UrlConfig | string,\n\tauth: Credentials,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(urlConfig, auth);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly urls: UrlConfig;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param prismicUrl - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turls: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urls === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turls = this.inferUrls(urls);\n\t\t}\n\t\tthis.urls = urls;\n\t\tthis.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.urls.authenticationApi,\n\t\t\tthis.credentials,\n\t\t);\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"/authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"next\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tprofiler.done({ message: `created repository '${repositoryName}'` });\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"./app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.credentials.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param name - The name of the repository.\n\t */\n\tgetRepositoryManager(name: string): RepositoryManager {\n\t\tconst customTypeClient = createCustomTypesApiClient(\n\t\t\tthis.urls.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\n\t\treturn new RepositoryManager(name, this.wroomClient, customTypeClient);\n\t}\n}\n\nexport type UrlConfig = {\n\t/** Prismic base url */\n\tbaseURL: string;\n\t/** Custom types api base url */\n\tcustomTypesApi: string;\n\t/** Auth service api base url */\n\tauthenticationApi: string;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,MACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,SAAS,UAAU;AAEtB,aAAA,KAAK,UAAU,IAAI;AAAA,IAC1B;AACD,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,WAAW,OAAO;AAExB,UAAM,OAAO,YACZ,KAAK,YAAY,KAAK,YAAY,yBAAyB;AAAA,MAC1D,SAAS;AAAA,MACT,UAAU,KAAK,YAAY;AAAA,IAAA,CAC3B;AACI,UAAA,WAAW,MAAM;AACnB,QAAA,SAAS,WAAW,KAAK;AAGtB,YAAA,QAAQ,MAAM;AAChB,UAAA,MAAM,WAAW,KAAK;AACzB,wBAAgB,QAAQ;AACxB,cAAM,IAAI,MAAM,+BAA+B,UAAU,EAAE;AAAA,MAC3D;AAAA,IACD;AACI,SAAA,aAAa,OAAO,UAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuB,UAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAW,cAAc,cAAc;AAChC,YAAA,KAAK,iBAAiB,UAAU;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqB,MAAY;AAChC,UAAM,mBAAmB,2BACxB,KAAK,KAAK,gBACV,MACA,KAAK,UAAU;AAGhB,WAAO,IAAI,kBAAkB,MAAM,KAAK,aAAa,gBAAgB;AAAA,EACtE;AACA;"}
1
+ {"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { Credentials } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param urlConfig - If provided as an object:\n *\n * - {@link UrlConfig.baseURL}: The Prismic base URL.\n * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.\n * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.\n *\n * If provided as a string: It is treated as the base URL for Prismic. Other\n * URLs (Custom Types API, Auth API) will be derived from it.\n * @param auth - The authentication credentials\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\turlConfig: UrlConfig | string,\n\tauth: Credentials,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(urlConfig, auth);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly urls: UrlConfig;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param urlConfig - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turlConfig: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urlConfig === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig = this.inferUrls(urlConfig);\n\t\t}\n\t\tthis.urls = urlConfig;\n\t\tthis.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.urls.authenticationApi,\n\t\t\tthis.credentials,\n\t\t);\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"vue\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tprofiler.done({ message: `created repository '${repositoryName}'` });\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.credentials.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param name - The name of the repository.\n\t */\n\tgetRepositoryManager(name: string): RepositoryManager {\n\t\tconst customTypeClient = createCustomTypesApiClient(\n\t\t\tthis.urls.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\n\t\treturn new RepositoryManager(name, this.wroomClient, customTypeClient);\n\t}\n}\n\nexport type UrlConfig = {\n\t/** Prismic base url */\n\tbaseURL: string;\n\t/** Custom types api base url */\n\tcustomTypesApi: string;\n\t/** Auth service api base url */\n\tauthenticationApi: string;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,WACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,cAAc,UAAU;AAEtB,kBAAA,KAAK,UAAU,SAAS;AAAA,IACpC;AACD,SAAK,OAAO;AACZ,SAAK,cAAc,IAAI,YAAY,KAAK,KAAK,SAAS,KAAK,WAAW;AACtE,SAAK,aAAa,8BACjB,KAAK,KAAK,mBACV,KAAK,WAAW;AAAA,EAElB;AAA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AA,WAAW,MAAM;AACnB,QAAA,SAAS,WAAW,KAAK;AAGtB,YAAA,QAAQ,MAAM;AAChB,UAAA,MAAM,WAAW,KAAK;AACzB,wBAAgB,QAAQ;AACxB,cAAM,IAAI,MAAM,+BAA+B,UAAU,EAAE;AAAA,MAC3D;AAAA,IACD;AACI,SAAA,aAAa,OAAO,UAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuB,UAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAW,cAAc,cAAc;AAChC,YAAA,KAAK,iBAAiB,UAAU;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqB,MAAY;AAChC,UAAM,mBAAmB,2BACxB,KAAK,KAAK,gBACV,MACA,KAAK,UAAU;AAGhB,WAAO,IAAI,kBAAkB,MAAM,KAAK,aAAa,gBAAgB;AAAA,EACtE;AACA;"}
@@ -17,15 +17,15 @@ class RepositoryManager {
17
17
  this.customTypesApiClient = customTypesApiClient;
18
18
  }
19
19
  async configure(config) {
20
+ if (config.defaultLocale) {
21
+ await this.setDefaultLocale(config.defaultLocale);
22
+ }
20
23
  if (config.locales) {
21
24
  await this.createLocales(config.locales);
22
25
  }
23
26
  if (config.customLocale) {
24
27
  await this.createCustomLocale(config.customLocale);
25
28
  }
26
- if (config.defaultLocale) {
27
- await this.setDefaultLocale(config.defaultLocale);
28
- }
29
29
  if (config.slices) {
30
30
  await this.createSlices(config.slices);
31
31
  }
@@ -59,7 +59,7 @@ class RepositoryManager {
59
59
  log.logHttpResponse(response);
60
60
  throw new Error(`Could not add locales ${locales.join(", ")}`);
61
61
  }
62
- profiler.done({ message: `standard locales '${locales}' set` });
62
+ profiler.done({ message: `locales '${locales}' created` });
63
63
  }
64
64
  /**
65
65
  * Set additional custom locale for a repository in Wroom, does not fail if
@@ -73,7 +73,7 @@ class RepositoryManager {
73
73
  const profiler = log.logger.startTimer();
74
74
  const response = await this.wroomClient.post(this.name, "app/settings/multilanguages/custom", locale);
75
75
  const { data, status } = response;
76
- const success = status === 200 || status === 400 && data.includes("code is already used");
76
+ const success = status === 200 || status === 400 && JSON.stringify(data).includes("code is already used");
77
77
  if (!success) {
78
78
  log.logHttpResponse(response);
79
79
  throw new Error(`Could not create custom locale ${locale}`);
@@ -111,8 +111,14 @@ class RepositoryManager {
111
111
  */
112
112
  async setDefaultLocale(locale) {
113
113
  const profiler = log.logger.startTimer();
114
- const response = await this.wroomClient.post(this.name, `/app/settings/multilanguages/${locale}/defineAsMaster`);
115
- this.failIfNot200(response, `Could not set default locale to ${locale}`);
114
+ const response = await this.wroomClient.post(this.name, `/app/settings/multilanguages/${locale}/createMasterLang`);
115
+ const { data, status } = response;
116
+ const success = status === 200 || status === 400 && // returns 400 if master lang is already set
117
+ JSON.stringify(data).includes("Unable to set as master language");
118
+ if (!success) {
119
+ log.logHttpResponse(response);
120
+ throw new Error(`Could not set default locale to ${locale}`);
121
+ }
116
122
  profiler.done({ message: `default locale set to '${locale}'` });
117
123
  }
118
124
  /**
@@ -124,7 +130,7 @@ class RepositoryManager {
124
130
  */
125
131
  async createRelease(label) {
126
132
  const profiler = log.logger.startTimer();
127
- const response = await this.wroomClient.post(this.name, "./app/releases", {
133
+ const response = await this.wroomClient.post(this.name, "app/releases", {
128
134
  label
129
135
  });
130
136
  this.failIfNot200(response, `Could not create release ${label}`);
@@ -139,7 +145,7 @@ class RepositoryManager {
139
145
  */
140
146
  async deleteRelease(id) {
141
147
  const profiler = log.logger.startTimer();
142
- const response = await this.wroomClient.post(this.name, `./app/releases/${id}/delete`, {});
148
+ const response = await this.wroomClient.post(this.name, `app/releases/${id}/delete`, {});
143
149
  this.failIfNot200(response, `Could not delete release with id ${id}`);
144
150
  profiler.done({ message: `release '${id}' deleted` });
145
151
  }
@@ -150,7 +156,7 @@ class RepositoryManager {
150
156
  */
151
157
  async createPreview(data) {
152
158
  const profiler = log.logger.startTimer();
153
- const response = await this.wroomClient.post(this.name, `./previews/new`, data);
159
+ const response = await this.wroomClient.post(this.name, `previews/new`, data);
154
160
  this.failIfNot200(response, `Could not create preview ${data.name}`);
155
161
  profiler.done({ message: `preview '${data.name}' created` });
156
162
  return response.data;
@@ -162,7 +168,7 @@ class RepositoryManager {
162
168
  */
163
169
  async deletePreview(id) {
164
170
  const profiler = log.logger.startTimer();
165
- const response = await this.wroomClient.post(this.name, `./previews/delete/${id}`, {});
171
+ const response = await this.wroomClient.post(this.name, `previews/delete/${id}`, {});
166
172
  this.failIfNot200(response, `Could not delete preview with id${id}`);
167
173
  profiler.done({ message: `preview '${id}' deleted` });
168
174
  }
@@ -1 +1 @@
1
- {"version":3,"file":"repository.cjs","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tif (config.locales) {\n\t\t\tawait this.createLocales(config.locales);\n\t\t}\n\n\t\tif (config.customLocale) {\n\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t}\n\n\t\tif (config.defaultLocale) {\n\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\tconst url = new URL(this.wroomClient.getBaseURL());\n\t\turl.hostname = `${this.name}.${url.hostname}`;\n\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `standard locales '${locales}' set` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && (data as string).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/defineAsMaster`,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not set default locale to ${locale}`);\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"./app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`./app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`./previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`./previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;;;;;;MAYa,kBAAiB;AAAA,EAC7B,YACU,MACQ,aACA,sBAAuC;AAF/C;AACQ;AACA;AAFR,SAAI,OAAJ;AACQ,SAAW,cAAX;AACA,SAAoB,uBAApB;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,QAAwB;AACvC,QAAI,OAAO,SAAS;AACb,YAAA,KAAK,cAAc,OAAO,OAAO;AAAA,IACvC;AAED,QAAI,OAAO,cAAc;AAClB,YAAA,KAAK,mBAAmB,OAAO,YAAY;AAAA,IACjD;AAED,QAAI,OAAO,eAAe;AACnB,YAAA,KAAK,iBAAiB,OAAO,aAAa;AAAA,IAChD;AAED,QAAI,OAAO,QAAQ;AACZ,YAAA,KAAK,aAAa,OAAO,MAAM;AAAA,IACrC;AAED,QAAI,OAAO,aAAa;AACjB,YAAA,KAAK,kBAAkB,OAAO,WAAW;AAAA,IAC/C;AAED,QAAI,OAAO,SAAS;AACb,YAAA,KAAK,cAAc,OAAO,OAAO;AAAA,IACvC;AAAA,EACF;AAAA;AAAA,EAEA,aAAU;AACT,UAAM,MAAM,IAAI,IAAI,KAAK,YAAY,YAAY;AACjD,QAAI,WAAW,GAAG,KAAK,IAAI,IAAI,IAAI,QAAQ;AAE3C,WAAO,IAAI;EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,cAAc,SAAiB;AAC9B,UAAA,WAAWA,WAAO;AAElB,UAAA,WAAW,MAAM,KAAK,YAAY,KACvC,KAAK,MACL,+BACA,EAAE,WAAW,QAAS,CAAA;AAGjB,UAAA,EAAE,MAAM,OAAW,IAAA;AACzB,UAAM,UACL,WAAW,OACV,WAAW,OACV,KAAgB,SAAS,4BAA4B;AACxD,QAAI,CAAC,SAAS;AACbC,UAAA,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AE,SAAS,YAAY,EAAE,aAAa;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,aAAyB;AAC1C,UAAA,KAAK,qBAAqB,kBAAkB,WAAW;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,QAAqB;AACjC,UAAA,KAAK,qBAAqB,aAAa,MAAM;AAAA,EACpD;AACA;;"}
1
+ {"version":3,"file":"repository.cjs","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tif (config.defaultLocale) {\n\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t}\n\n\t\tif (config.locales) {\n\t\t\tawait this.createLocales(config.locales);\n\t\t}\n\n\t\tif (config.customLocale) {\n\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\tconst url = new URL(this.wroomClient.getBaseURL());\n\t\turl.hostname = `${this.name}.${url.hostname}`;\n\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `locales '${locales}' created` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && JSON.stringify(data).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/createMasterLang`,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`);\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;;;;;;MAYa,kBAAiB;AAAA,EAC7B,YACU,MACQ,aACA,sBAAuC;AAF/C;AACQ;AACA;AAFR,SAAI,OAAJ;AACQ,SAAW,cAAX;AACA,SAAoB,uBAApB;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,QAAwB;AACvC,QAAI,OAAO,eAAe;AACnB,YAAA,KAAK,iBAAiB,OAAO,aAAa;AAAA,IAChD;AAED,QAAI,OAAO,SAAS;AACb,YAAA,KAAK,cAAc,OAAO,OAAO;AAAA,IACvC;AAED,QAAI,OAAO,cAAc;AAClB,YAAA,KAAK,mBAAmB,OAAO,YAAY;AAAA,IACjD;AAED,QAAI,OAAO,QAAQ;AACZ,YAAA,KAAK,aAAa,OAAO,MAAM;AAAA,IACrC;AAED,QAAI,OAAO,aAAa;AACjB,YAAA,KAAK,kBAAkB,OAAO,WAAW;AAAA,IAC/C;AAED,QAAI,OAAO,SAAS;AACb,YAAA,KAAK,cAAc,OAAO,OAAO;AAAA,IACvC;AAAA,EACF;AAAA;AAAA,EAEA,aAAU;AACT,UAAM,MAAM,IAAI,IAAI,KAAK,YAAY,YAAY;AACjD,QAAI,WAAW,GAAG,KAAK,IAAI,IAAI,IAAI,QAAQ;AAE3C,WAAO,IAAI;EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,cAAc,SAAiB;AAC9B,UAAA,WAAWA,WAAO;AAElB,UAAA,WAAW,MAAM,KAAK,YAAY,KACvC,KAAK,MACL,+BACA,EAAE,WAAW,QAAS,CAAA;AAGjB,UAAA,EAAE,MAAM,OAAW,IAAA;AACzB,UAAM,UACL,WAAW,OACV,WAAW,OACV,KAAgB,SAAS,4BAA4B;AACxD,QAAI,CAAC,SAAS;AACbC,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AA,EAOA,MAAM,cAAc,IAAU;AACvB,UAAA,WAAWA,WAAO;AAElB,UAAA,WAAW,MAAM,KAAK,YAAY,KACvC,KAAK,MACL,mBAAmB,EAAE,IACrB,CAAE,CAAA;AAGH,SAAK,aAAa,UAAU,mCAAmC,EAAE,EAAE;AACnE,aAAS,KAAK,EAAE,SAAS,YAAY,EAAE,aAAa;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,aAAyB;AAC1C,UAAA,KAAK,qBAAqB,kBAAkB,WAAW;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,QAAqB;AACjC,UAAA,KAAK,qBAAqB,aAAa,MAAM;AAAA,EACpD;AACA;;"}
@@ -15,15 +15,15 @@ class RepositoryManager {
15
15
  this.customTypesApiClient = customTypesApiClient;
16
16
  }
17
17
  async configure(config) {
18
+ if (config.defaultLocale) {
19
+ await this.setDefaultLocale(config.defaultLocale);
20
+ }
18
21
  if (config.locales) {
19
22
  await this.createLocales(config.locales);
20
23
  }
21
24
  if (config.customLocale) {
22
25
  await this.createCustomLocale(config.customLocale);
23
26
  }
24
- if (config.defaultLocale) {
25
- await this.setDefaultLocale(config.defaultLocale);
26
- }
27
27
  if (config.slices) {
28
28
  await this.createSlices(config.slices);
29
29
  }
@@ -57,7 +57,7 @@ class RepositoryManager {
57
57
  logHttpResponse(response);
58
58
  throw new Error(`Could not add locales ${locales.join(", ")}`);
59
59
  }
60
- profiler.done({ message: `standard locales '${locales}' set` });
60
+ profiler.done({ message: `locales '${locales}' created` });
61
61
  }
62
62
  /**
63
63
  * Set additional custom locale for a repository in Wroom, does not fail if
@@ -71,7 +71,7 @@ class RepositoryManager {
71
71
  const profiler = logger.startTimer();
72
72
  const response = await this.wroomClient.post(this.name, "app/settings/multilanguages/custom", locale);
73
73
  const { data, status } = response;
74
- const success = status === 200 || status === 400 && data.includes("code is already used");
74
+ const success = status === 200 || status === 400 && JSON.stringify(data).includes("code is already used");
75
75
  if (!success) {
76
76
  logHttpResponse(response);
77
77
  throw new Error(`Could not create custom locale ${locale}`);
@@ -109,8 +109,14 @@ class RepositoryManager {
109
109
  */
110
110
  async setDefaultLocale(locale) {
111
111
  const profiler = logger.startTimer();
112
- const response = await this.wroomClient.post(this.name, `/app/settings/multilanguages/${locale}/defineAsMaster`);
113
- this.failIfNot200(response, `Could not set default locale to ${locale}`);
112
+ const response = await this.wroomClient.post(this.name, `/app/settings/multilanguages/${locale}/createMasterLang`);
113
+ const { data, status } = response;
114
+ const success = status === 200 || status === 400 && // returns 400 if master lang is already set
115
+ JSON.stringify(data).includes("Unable to set as master language");
116
+ if (!success) {
117
+ logHttpResponse(response);
118
+ throw new Error(`Could not set default locale to ${locale}`);
119
+ }
114
120
  profiler.done({ message: `default locale set to '${locale}'` });
115
121
  }
116
122
  /**
@@ -122,7 +128,7 @@ class RepositoryManager {
122
128
  */
123
129
  async createRelease(label) {
124
130
  const profiler = logger.startTimer();
125
- const response = await this.wroomClient.post(this.name, "./app/releases", {
131
+ const response = await this.wroomClient.post(this.name, "app/releases", {
126
132
  label
127
133
  });
128
134
  this.failIfNot200(response, `Could not create release ${label}`);
@@ -137,7 +143,7 @@ class RepositoryManager {
137
143
  */
138
144
  async deleteRelease(id) {
139
145
  const profiler = logger.startTimer();
140
- const response = await this.wroomClient.post(this.name, `./app/releases/${id}/delete`, {});
146
+ const response = await this.wroomClient.post(this.name, `app/releases/${id}/delete`, {});
141
147
  this.failIfNot200(response, `Could not delete release with id ${id}`);
142
148
  profiler.done({ message: `release '${id}' deleted` });
143
149
  }
@@ -148,7 +154,7 @@ class RepositoryManager {
148
154
  */
149
155
  async createPreview(data) {
150
156
  const profiler = logger.startTimer();
151
- const response = await this.wroomClient.post(this.name, `./previews/new`, data);
157
+ const response = await this.wroomClient.post(this.name, `previews/new`, data);
152
158
  this.failIfNot200(response, `Could not create preview ${data.name}`);
153
159
  profiler.done({ message: `preview '${data.name}' created` });
154
160
  return response.data;
@@ -160,7 +166,7 @@ class RepositoryManager {
160
166
  */
161
167
  async deletePreview(id) {
162
168
  const profiler = logger.startTimer();
163
- const response = await this.wroomClient.post(this.name, `./previews/delete/${id}`, {});
169
+ const response = await this.wroomClient.post(this.name, `previews/delete/${id}`, {});
164
170
  this.failIfNot200(response, `Could not delete preview with id${id}`);
165
171
  profiler.done({ message: `preview '${id}' deleted` });
166
172
  }
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tif (config.locales) {\n\t\t\tawait this.createLocales(config.locales);\n\t\t}\n\n\t\tif (config.customLocale) {\n\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t}\n\n\t\tif (config.defaultLocale) {\n\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\tconst url = new URL(this.wroomClient.getBaseURL());\n\t\turl.hostname = `${this.name}.${url.hostname}`;\n\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `standard locales '${locales}' set` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && (data as string).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/defineAsMaster`,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not set default locale to ${locale}`);\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"./app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`./app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`./previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`./previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":[],"mappings":";;;;;;;MAYa,kBAAiB;AAAA,EAC7B,YACU,MACQ,aACA,sBA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jC,UAAA,KAAK,qBAAqB,aAAa,MAAM;AAAA,EACpD;AACA;"}
1
+ {"version":3,"file":"repository.js","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tif (config.defaultLocale) {\n\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t}\n\n\t\tif (config.locales) {\n\t\t\tawait this.createLocales(config.locales);\n\t\t}\n\n\t\tif (config.customLocale) {\n\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\tconst url = new URL(this.wroomClient.getBaseURL());\n\t\turl.hostname = `${this.name}.${url.hostname}`;\n\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `locales '${locales}' created` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && JSON.stringify(data).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/createMasterLang`,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`);\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":[],"mappings":";;;;;;;MAYa,kBAAiB;AAAA,EAC7B,YACU,MACQ,aACA,sBAAuC;AAF/C;AACQ;AACA;AAFR,SAAI,OAAJ;AAC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AOA,MAAM,kBAAkB,aAAyB;AAC1C,UAAA,KAAK,qBAAqB,kBAAkB,WAAW;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,QAAqB;AACjC,UAAA,KAAK,qBAAqB,aAAa,MAAM;AAAA,EACpD;AACA;"}
@@ -6,7 +6,7 @@ const extractCookie = (cookies, cookieName) => {
6
6
  const match = cookies.match(regex);
7
7
  return match ? match[1] : void 0;
8
8
  }
9
- if (cookies instanceof Array) {
9
+ if (Array.isArray(cookies)) {
10
10
  for (const cookie of cookies) {
11
11
  const match = cookie.match(regex);
12
12
  if (match) {
@@ -1 +1 @@
1
- {"version":3,"file":"cookies.cjs","sources":["../../../src/utils/cookies.ts"],"sourcesContent":["import { AxiosHeaderValue } from \"axios\";\n\n/**\n * Extract the value of a specific cookie from Axios cookies.\n *\n * @param cookies - Axios cookies, can be a string or an array\n * @param cookieName - The name of the cookie to extract.\n */\nexport const extractCookie = (\n\tcookies: AxiosHeaderValue | undefined,\n\tcookieName: string,\n): string | undefined => {\n\tconst regex = new RegExp(`${cookieName}=([^;]+)`, \"i\"); // 'i' flag for case-insensitivity\n\n\tif (typeof cookies === \"string\") {\n\t\tconst match = cookies.match(regex);\n\n\t\treturn match ? match[1] : undefined;\n\t}\n\tif (cookies instanceof Array) {\n\t\tfor (const cookie of cookies) {\n\t\t\tconst match = cookie.match(regex);\n\t\t\tif (match) {\n\t\t\t\treturn match[1];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn undefined;\n};\n"],"names":[],"mappings":";;AAQa,MAAA,gBAAgB,CAC5B,SACA,eACuB;AACvB,QAAM,QAAQ,IAAI,OAAO,GAAG,UAAU,YAAY,GAAG;AAEjD,MAAA,OAAO,YAAY,UAAU;AAC1B,UAAA,QAAQ,QAAQ,MAAM,KAAK;AAE1B,WAAA,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC1B;AACD,MAAI,mBAAmB,OAAO;AAC7B,eAAW,UAAU,SAAS;AACvB,YAAA,QAAQ,OAAO,MAAM,KAAK;AAChC,UAAI,OAAO;AACV,eAAO,MAAM,CAAC;AAAA,MACd;AAAA,IACD;AAAA,EACD;AAEM,SAAA;AACR;;"}
1
+ {"version":3,"file":"cookies.cjs","sources":["../../../src/utils/cookies.ts"],"sourcesContent":["import { AxiosHeaderValue } from \"axios\";\n\n/**\n * Extract the value of a specific cookie from Axios cookies.\n *\n * @param cookies - Axios cookies, can be a string or an array\n * @param cookieName - The name of the cookie to extract.\n */\nexport const extractCookie = (\n\tcookies: AxiosHeaderValue | undefined,\n\tcookieName: string,\n): string | undefined => {\n\tconst regex = new RegExp(`${cookieName}=([^;]+)`, \"i\"); // 'i' flag for case-insensitivity\n\n\tif (typeof cookies === \"string\") {\n\t\tconst match = cookies.match(regex);\n\n\t\treturn match ? match[1] : undefined;\n\t}\n\tif (Array.isArray(cookies)) {\n\t\tfor (const cookie of cookies) {\n\t\t\tconst match = cookie.match(regex);\n\t\t\tif (match) {\n\t\t\t\treturn match[1];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn undefined;\n};\n"],"names":[],"mappings":";;AAQa,MAAA,gBAAgB,CAC5B,SACA,eACuB;AACvB,QAAM,QAAQ,IAAI,OAAO,GAAG,UAAU,YAAY,GAAG;AAEjD,MAAA,OAAO,YAAY,UAAU;AAC1B,UAAA,QAAQ,QAAQ,MAAM,KAAK;AAE1B,WAAA,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC1B;AACG,MAAA,MAAM,QAAQ,OAAO,GAAG;AAC3B,eAAW,UAAU,SAAS;AACvB,YAAA,QAAQ,OAAO,MAAM,KAAK;AAChC,UAAI,OAAO;AACV,eAAO,MAAM,CAAC;AAAA,MACd;AAAA,IACD;AAAA,EACD;AAEM,SAAA;AACR;;"}
@@ -4,7 +4,7 @@ const extractCookie = (cookies, cookieName) => {
4
4
  const match = cookies.match(regex);
5
5
  return match ? match[1] : void 0;
6
6
  }
7
- if (cookies instanceof Array) {
7
+ if (Array.isArray(cookies)) {
8
8
  for (const cookie of cookies) {
9
9
  const match = cookie.match(regex);
10
10
  if (match) {
@@ -1 +1 @@
1
- {"version":3,"file":"cookies.js","sources":["../../../src/utils/cookies.ts"],"sourcesContent":["import { AxiosHeaderValue } from \"axios\";\n\n/**\n * Extract the value of a specific cookie from Axios cookies.\n *\n * @param cookies - Axios cookies, can be a string or an array\n * @param cookieName - The name of the cookie to extract.\n */\nexport const extractCookie = (\n\tcookies: AxiosHeaderValue | undefined,\n\tcookieName: string,\n): string | undefined => {\n\tconst regex = new RegExp(`${cookieName}=([^;]+)`, \"i\"); // 'i' flag for case-insensitivity\n\n\tif (typeof cookies === \"string\") {\n\t\tconst match = cookies.match(regex);\n\n\t\treturn match ? match[1] : undefined;\n\t}\n\tif (cookies instanceof Array) {\n\t\tfor (const cookie of cookies) {\n\t\t\tconst match = cookie.match(regex);\n\t\t\tif (match) {\n\t\t\t\treturn match[1];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn undefined;\n};\n"],"names":[],"mappings":"AAQa,MAAA,gBAAgB,CAC5B,SACA,eACuB;AACvB,QAAM,QAAQ,IAAI,OAAO,GAAG,UAAU,YAAY,GAAG;AAEjD,MAAA,OAAO,YAAY,UAAU;AAC1B,UAAA,QAAQ,QAAQ,MAAM,KAAK;AAE1B,WAAA,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC1B;AACD,MAAI,mBAAmB,OAAO;AAC7B,eAAW,UAAU,SAAS;AACvB,YAAA,QAAQ,OAAO,MAAM,KAAK;AAChC,UAAI,OAAO;AACV,eAAO,MAAM,CAAC;AAAA,MACd;AAAA,IACD;AAAA,EACD;AAEM,SAAA;AACR;"}
1
+ {"version":3,"file":"cookies.js","sources":["../../../src/utils/cookies.ts"],"sourcesContent":["import { AxiosHeaderValue } from \"axios\";\n\n/**\n * Extract the value of a specific cookie from Axios cookies.\n *\n * @param cookies - Axios cookies, can be a string or an array\n * @param cookieName - The name of the cookie to extract.\n */\nexport const extractCookie = (\n\tcookies: AxiosHeaderValue | undefined,\n\tcookieName: string,\n): string | undefined => {\n\tconst regex = new RegExp(`${cookieName}=([^;]+)`, \"i\"); // 'i' flag for case-insensitivity\n\n\tif (typeof cookies === \"string\") {\n\t\tconst match = cookies.match(regex);\n\n\t\treturn match ? match[1] : undefined;\n\t}\n\tif (Array.isArray(cookies)) {\n\t\tfor (const cookie of cookies) {\n\t\t\tconst match = cookie.match(regex);\n\t\t\tif (match) {\n\t\t\t\treturn match[1];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn undefined;\n};\n"],"names":[],"mappings":"AAQa,MAAA,gBAAgB,CAC5B,SACA,eACuB;AACvB,QAAM,QAAQ,IAAI,OAAO,GAAG,UAAU,YAAY,GAAG;AAEjD,MAAA,OAAO,YAAY,UAAU;AAC1B,UAAA,QAAQ,QAAQ,MAAM,KAAK;AAE1B,WAAA,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC1B;AACG,MAAA,MAAM,QAAQ,OAAO,GAAG;AAC3B,eAAW,UAAU,SAAS;AACvB,YAAA,QAAQ,OAAO,MAAM,KAAK;AAChC,UAAI,OAAO;AACV,eAAO,MAAM,CAAC;AAAA,MACd;AAAA,IACD;AAAA,EACD;AAEM,SAAA;AACR;"}
@@ -3,8 +3,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const winston = require("winston");
4
4
  const logHttpResponse = (response) => {
5
5
  const { status, data } = response;
6
- const { url = "" } = response.config;
7
- logger.info(`Call to ${url} failed, received [${status}] ${data}`);
6
+ const { baseURL = "", url = "" } = response.config;
7
+ const fullUrl = url.startsWith("http") ? url : `${baseURL}/${url}`;
8
+ logger.info(`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`);
8
9
  };
9
10
  const { combine, printf } = winston.format;
10
11
  const customFormat = printf(({ message, durationMs }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"log.cjs","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { url = \"\" } = response.config;\n\tlogger.info(`Call to ${url} failed, received [${status}] ${data}`);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":["format","createLogger","transports"],"mappings":";;;AAGa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,KAAS,IAAA;AACzB,QAAM,EAAE,MAAM,OAAO,SAAS;AAC9B,SAAO,KAAK,WAAW,GAAG,sBAAsB,MAAM,KAAK,IAAI,EAAE;AAClE;AAEA,MAAM,EAAE,SAAS,OAAW,IAAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EAClC;AAEM,SAAA;AACR,CAAC;AAEM,MAAM,SAASC,QAAAA,aAAa;AAAA,EAClC,QAAQ,QAAQ,IAAI,gCAAgC,MAAM;AAAA,EAC1D,OAAO,QAAQ,IAAI,mCAAmC,KAAK;AAAA,EAC3D,QAAQ,QAAQ,YAAY;AAAA,EAC5B,YAAY,CAAC,IAAIC,mBAAW,SAAS;AACrC,CAAA;;;"}
1
+ {"version":3,"file":"log.cjs","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { baseURL = \"\", url = \"\" } = response.config;\n\t// make sure the url always shows baseURL + path.\n\t// Depending on how the AxiosInstance was called, the url already contains the baseURL\n\tconst fullUrl = url.startsWith(\"http\") ? url : `${baseURL}/${url}`;\n\n\tlogger.info(\n\t\t`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,\n\t);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":["format","createLogger","transports"],"mappings":";;;AAGa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,KAAS,IAAA;AACzB,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,SAAS;AAGtC,QAAA,UAAU,IAAI,WAAW,MAAM,IAAI,MAAM,GAAG,OAAO,IAAI,GAAG;AAEzD,SAAA,KACN,WAAW,OAAO,sBAAsB,MAAM,KAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAE3E;AAEA,MAAM,EAAE,SAAS,OAAW,IAAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EAClC;AAEM,SAAA;AACR,CAAC;AAEM,MAAM,SAASC,QAAAA,aAAa;AAAA,EAClC,QAAQ,QAAQ,IAAI,gCAAgC,MAAM;AAAA,EAC1D,OAAO,QAAQ,IAAI,mCAAmC,KAAK;AAAA,EAC3D,QAAQ,QAAQ,YAAY;AAAA,EAC5B,YAAY,CAAC,IAAIC,mBAAW,SAAS;AACrC,CAAA;;;"}
package/dist/utils/log.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { createLogger, transports, format } from "winston";
2
2
  const logHttpResponse = (response) => {
3
3
  const { status, data } = response;
4
- const { url = "" } = response.config;
5
- logger.info(`Call to ${url} failed, received [${status}] ${data}`);
4
+ const { baseURL = "", url = "" } = response.config;
5
+ const fullUrl = url.startsWith("http") ? url : `${baseURL}/${url}`;
6
+ logger.info(`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`);
6
7
  };
7
8
  const { combine, printf } = format;
8
9
  const customFormat = printf(({ message, durationMs }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { url = \"\" } = response.config;\n\tlogger.info(`Call to ${url} failed, received [${status}] ${data}`);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":[],"mappings":";AAGa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,KAAS,IAAA;AACzB,QAAM,EAAE,MAAM,OAAO,SAAS;AAC9B,SAAO,KAAK,WAAW,GAAG,sBAAsB,MAAM,KAAK,IAAI,EAAE;AAClE;AAEA,MAAM,EAAE,SAAS,OAAW,IAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EAClC;AAEM,SAAA;AACR,CAAC;AAEM,MAAM,SAAS,aAAa;AAAA,EAClC,QAAQ,QAAQ,IAAI,gCAAgC,MAAM;AAAA,EAC1D,OAAO,QAAQ,IAAI,mCAAmC,KAAK;AAAA,EAC3D,QAAQ,QAAQ,YAAY;AAAA,EAC5B,YAAY,CAAC,IAAI,WAAW,SAAS;AACrC,CAAA;"}
1
+ {"version":3,"file":"log.js","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { baseURL = \"\", url = \"\" } = response.config;\n\t// make sure the url always shows baseURL + path.\n\t// Depending on how the AxiosInstance was called, the url already contains the baseURL\n\tconst fullUrl = url.startsWith(\"http\") ? url : `${baseURL}/${url}`;\n\n\tlogger.info(\n\t\t`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,\n\t);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":[],"mappings":";AAGa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,KAAS,IAAA;AACzB,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,SAAS;AAGtC,QAAA,UAAU,IAAI,WAAW,MAAM,IAAI,MAAM,GAAG,OAAO,IAAI,GAAG;AAEzD,SAAA,KACN,WAAW,OAAO,sBAAsB,MAAM,KAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAE3E;AAEA,MAAM,EAAE,SAAS,OAAW,IAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EAClC;AAEM,SAAA;AACR,CAAC;AAEM,MAAM,SAAS,aAAa;AAAA,EAClC,QAAQ,QAAQ,IAAI,gCAAgC,MAAM;AAAA,EAC1D,OAAO,QAAQ,IAAI,mCAAmC,KAAK;AAAA,EAC3D,QAAQ,QAAQ,YAAY;AAAA,EAC5B,YAAY,CAAC,IAAI,WAAW,SAAS;AACrC,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -8,7 +8,7 @@ export type AuthenticationClient = {
8
8
  getToken: () => Promise<string>;
9
9
  };
10
10
 
11
- /** Client for interacting with an authentication service to generate API tokens. */
11
+ /** Client for interacting with the authentication service to manage tokens */
12
12
  export const createAuthenticationApiClient = (
13
13
  baseURL: string,
14
14
  auth: Credentials,
@@ -23,7 +23,7 @@ export const createAuthenticationApiClient = (
23
23
  async function login(): Promise<string> {
24
24
  const profiler = logger.startTimer();
25
25
 
26
- const result = await client.post("/login", {
26
+ const result = await client.post("login", {
27
27
  email: auth.email,
28
28
  password: auth.password,
29
29
  });
@@ -49,18 +49,18 @@ export class RepositoriesManager {
49
49
  );
50
50
 
51
51
  /**
52
- * @param prismicUrl - The base URL of the Wroom app.
52
+ * @param urlConfig - The base URL of the Wroom app.
53
53
  * @param credentials - Authentication credentials (email and password)
54
54
  */
55
55
  constructor(
56
- urls: UrlConfig | string,
56
+ urlConfig: UrlConfig | string,
57
57
  private readonly credentials: Credentials,
58
58
  ) {
59
- if (typeof urls === "string") {
59
+ if (typeof urlConfig === "string") {
60
60
  // When a string is provided, treat it as the 'base' property
61
- urls = this.inferUrls(urls);
61
+ urlConfig = this.inferUrls(urlConfig);
62
62
  }
63
- this.urls = urls;
63
+ this.urls = urlConfig;
64
64
  this.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);
65
65
  this.authClient = createAuthenticationApiClient(
66
66
  this.urls.authenticationApi,
@@ -111,10 +111,10 @@ export class RepositoriesManager {
111
111
 
112
112
  const response = await this.wroomClient.post(
113
113
  null,
114
- "/authentication/newrepository",
114
+ "authentication/newrepository",
115
115
  {
116
116
  domain: repositoryName,
117
- framework: "next",
117
+ framework: "vue",
118
118
  plan: "personal",
119
119
  isAnnual: "false",
120
120
  role: "developer",
@@ -145,7 +145,7 @@ export class RepositoriesManager {
145
145
  const profiler = logger.startTimer();
146
146
 
147
147
  const post = async () =>
148
- this.wroomClient.post(repository, "./app/settings/delete", {
148
+ this.wroomClient.post(repository, "app/settings/delete", {
149
149
  confirm: repository,
150
150
  password: this.credentials.password,
151
151
  });
@@ -18,6 +18,10 @@ export class RepositoryManager {
18
18
  ) {}
19
19
 
20
20
  async configure(config: RepositoryConfig): Promise<void> {
21
+ if (config.defaultLocale) {
22
+ await this.setDefaultLocale(config.defaultLocale);
23
+ }
24
+
21
25
  if (config.locales) {
22
26
  await this.createLocales(config.locales);
23
27
  }
@@ -26,10 +30,6 @@ export class RepositoryManager {
26
30
  await this.createCustomLocale(config.customLocale);
27
31
  }
28
32
 
29
- if (config.defaultLocale) {
30
- await this.setDefaultLocale(config.defaultLocale);
31
- }
32
-
33
33
  if (config.slices) {
34
34
  await this.createSlices(config.slices);
35
35
  }
@@ -76,7 +76,7 @@ export class RepositoryManager {
76
76
  logHttpResponse(response);
77
77
  throw new Error(`Could not add locales ${locales.join(", ")}`);
78
78
  }
79
- profiler.done({ message: `standard locales '${locales}' set` });
79
+ profiler.done({ message: `locales '${locales}' created` });
80
80
  }
81
81
 
82
82
  /**
@@ -99,7 +99,7 @@ export class RepositoryManager {
99
99
  const { data, status } = response;
100
100
  const success =
101
101
  status === 200 ||
102
- (status === 400 && (data as string).includes("code is already used"));
102
+ (status === 400 && JSON.stringify(data).includes("code is already used"));
103
103
  if (!success) {
104
104
  logHttpResponse(response);
105
105
  throw new Error(`Could not create custom locale ${locale}`);
@@ -147,10 +147,19 @@ export class RepositoryManager {
147
147
 
148
148
  const response = await this.wroomClient.post(
149
149
  this.name,
150
- `/app/settings/multilanguages/${locale}/defineAsMaster`,
150
+ `/app/settings/multilanguages/${locale}/createMasterLang`,
151
151
  );
152
152
 
153
- this.failIfNot200(response, `Could not set default locale to ${locale}`);
153
+ const { data, status } = response;
154
+ const success =
155
+ status === 200 ||
156
+ (status === 400 &&
157
+ // returns 400 if master lang is already set
158
+ JSON.stringify(data).includes("Unable to set as master language"));
159
+ if (!success) {
160
+ logHttpResponse(response);
161
+ throw new Error(`Could not set default locale to ${locale}`);
162
+ }
154
163
  profiler.done({ message: `default locale set to '${locale}'` });
155
164
  }
156
165
 
@@ -164,7 +173,7 @@ export class RepositoryManager {
164
173
  async createRelease(label: string): Promise<{ id: string }> {
165
174
  const profiler = logger.startTimer();
166
175
 
167
- const response = await this.wroomClient.post(this.name, "./app/releases", {
176
+ const response = await this.wroomClient.post(this.name, "app/releases", {
168
177
  label,
169
178
  });
170
179
  this.failIfNot200(response, `Could not create release ${label}`);
@@ -184,7 +193,7 @@ export class RepositoryManager {
184
193
 
185
194
  const response = await this.wroomClient.post(
186
195
  this.name,
187
- `./app/releases/${id}/delete`,
196
+ `app/releases/${id}/delete`,
188
197
  {},
189
198
  );
190
199
 
@@ -202,7 +211,7 @@ export class RepositoryManager {
202
211
 
203
212
  const response = await this.wroomClient.post(
204
213
  this.name,
205
- `./previews/new`,
214
+ `previews/new`,
206
215
  data,
207
216
  );
208
217
 
@@ -222,7 +231,7 @@ export class RepositoryManager {
222
231
 
223
232
  const response = await this.wroomClient.post(
224
233
  this.name,
225
- `./previews/delete/${id}`,
234
+ `previews/delete/${id}`,
226
235
  {},
227
236
  );
228
237
 
@@ -17,7 +17,7 @@ export const extractCookie = (
17
17
 
18
18
  return match ? match[1] : undefined;
19
19
  }
20
- if (cookies instanceof Array) {
20
+ if (Array.isArray(cookies)) {
21
21
  for (const cookie of cookies) {
22
22
  const match = cookie.match(regex);
23
23
  if (match) {
package/src/utils/log.ts CHANGED
@@ -3,8 +3,14 @@ import { createLogger, format, transports } from "winston";
3
3
 
4
4
  export const logHttpResponse = (response: AxiosResponse): void => {
5
5
  const { status, data } = response;
6
- const { url = "" } = response.config;
7
- logger.info(`Call to ${url} failed, received [${status}] ${data}`);
6
+ const { baseURL = "", url = "" } = response.config;
7
+ // make sure the url always shows baseURL + path.
8
+ // Depending on how the AxiosInstance was called, the url already contains the baseURL
9
+ const fullUrl = url.startsWith("http") ? url : `${baseURL}/${url}`;
10
+
11
+ logger.info(
12
+ `Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,
13
+ );
8
14
  };
9
15
 
10
16
  const { combine, printf } = format;