@prismicio/e2e-tests-utils 2.0.0-alpha.0 → 2.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/clients/assetApi.cjs +48 -0
  2. package/dist/clients/assetApi.cjs.map +1 -0
  3. package/dist/clients/assetApi.d.ts +54 -0
  4. package/dist/clients/assetApi.js +48 -0
  5. package/dist/clients/assetApi.js.map +1 -0
  6. package/dist/clients/authenticationApi.cjs +3 -10
  7. package/dist/clients/authenticationApi.cjs.map +1 -1
  8. package/dist/clients/authenticationApi.js +3 -10
  9. package/dist/clients/authenticationApi.js.map +1 -1
  10. package/dist/clients/manageV2.cjs +19 -6
  11. package/dist/clients/manageV2.cjs.map +1 -1
  12. package/dist/clients/manageV2.d.ts +15 -5
  13. package/dist/clients/manageV2.js +19 -6
  14. package/dist/clients/manageV2.js.map +1 -1
  15. package/dist/clients/wroom.cjs +10 -16
  16. package/dist/clients/wroom.cjs.map +1 -1
  17. package/dist/clients/wroom.d.ts +6 -6
  18. package/dist/clients/wroom.js +10 -16
  19. package/dist/clients/wroom.js.map +1 -1
  20. package/dist/managers/repositories.cjs +10 -3
  21. package/dist/managers/repositories.cjs.map +1 -1
  22. package/dist/managers/repositories.js +10 -3
  23. package/dist/managers/repositories.js.map +1 -1
  24. package/dist/managers/repository.cjs +65 -9
  25. package/dist/managers/repository.cjs.map +1 -1
  26. package/dist/managers/repository.d.ts +41 -9
  27. package/dist/managers/repository.js +65 -9
  28. package/dist/managers/repository.js.map +1 -1
  29. package/dist/types.d.ts +3 -0
  30. package/dist/utils/authentication.cjs +38 -0
  31. package/dist/utils/authentication.cjs.map +1 -0
  32. package/dist/utils/authentication.d.ts +4 -0
  33. package/dist/utils/authentication.js +38 -0
  34. package/dist/utils/authentication.js.map +1 -0
  35. package/package.json +3 -2
  36. package/src/clients/assetApi.ts +76 -0
  37. package/src/clients/authenticationApi.ts +7 -10
  38. package/src/clients/manageV2.ts +22 -6
  39. package/src/clients/wroom.ts +14 -17
  40. package/src/managers/repositories.ts +17 -1
  41. package/src/managers/repository.ts +102 -8
  42. package/src/types.ts +3 -0
  43. package/src/utils/authentication.ts +58 -0
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const log = require("../utils/log.cjs");
4
+ const apiClient = require("./apiClient.cjs");
5
+ class AssetApiClient extends apiClient.AuthenticatedApiClient {
6
+ /**
7
+ * @example To instantiate the class:
8
+ *
9
+ * ```js
10
+ * new AssetApiClient("https://asset-api.prismic.io", {
11
+ * authToken: "my-secret-token",
12
+ * repository: "my-repo-name",
13
+ * });
14
+ * ```
15
+ *
16
+ * @param baseURL - The API base URL, such as https://asset-api.prismic.io
17
+ * @param config - Optional configuration
18
+ *
19
+ * - {@link config.authToken}: API token generated from the auth service or a
20
+ * function to fetch it when it's needed.
21
+ * - {@link config.repository}: Repository name.
22
+ */
23
+ constructor(baseURL, config) {
24
+ super(baseURL, config.authToken, { repository: config.repository });
25
+ }
26
+ /**
27
+ * Uploads an asset file to the server.
28
+ *
29
+ * @param data - The payload containing the file and filename.
30
+ *
31
+ * @returns The API response containing asset information.
32
+ *
33
+ * @throws An error if the upload fails.
34
+ */
35
+ async createAsset(data) {
36
+ const context = await this.getContext();
37
+ const result = await context.post("assets", {
38
+ multipart: { file: data }
39
+ });
40
+ if (200 !== result.status()) {
41
+ await log.logPlaywrightApiResponse(result);
42
+ throw new Error("Could not upload the asset with the asset API.");
43
+ }
44
+ return result.json();
45
+ }
46
+ }
47
+ exports.AssetApiClient = AssetApiClient;
48
+ //# sourceMappingURL=assetApi.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assetApi.cjs","sources":["../../../src/clients/assetApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface AssetApiCreatePayload {\n\tname: string;\n\tmimeType: string;\n\tbuffer: Buffer;\n}\n\nexport interface AssetApiCreateResponse {\n\tid: string;\n\turl: string;\n\tfilename: string;\n\tsize: number;\n\twidth: number;\n\theight: number;\n\tlast_modified: number;\n\tkind: string;\n\textension: string;\n\tcreated_at: number;\n\tuploader_id: string;\n\ttags: string[];\n}\n\nexport class AssetApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new AssetApiClient(\"https://asset-api.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * \trepository: \"my-repo-name\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - The API base URL, such as https://asset-api.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.authToken}: API token generated from the auth service or a\n\t * function to fetch it when it's needed.\n\t * - {@link config.repository}: Repository name.\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Uploads an asset file to the server.\n\t *\n\t * @param data - The payload containing the file and filename.\n\t *\n\t * @returns The API response containing asset information.\n\t *\n\t * @throws An error if the upload fails.\n\t */\n\tasync createAsset(\n\t\tdata: AssetApiCreatePayload,\n\t): Promise<AssetApiCreateResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.post(\"assets\", {\n\t\t\tmultipart: { file: data },\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not upload the asset with the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":["AuthenticatedApiClient","logPlaywrightApiResponse"],"mappings":";;;;AAyBM,MAAO,uBAAuBA,UAAAA,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzD,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YACL,MAA2B;AAErB,UAAA,UAAU,MAAM,KAAK;AAE3B,UAAM,SAAS,MAAM,QAAQ,KAAK,UAAU;AAAA,MAC3C,WAAW,EAAE,MAAM,KAAM;AAAA,IAAA,CACzB;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAMC,IAAAA,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,gDAAgD;AAAA,IACjE;AAEA,WAAO,OAAO;EACf;AACA;;"}
@@ -0,0 +1,54 @@
1
+ /// <reference types="node" />
2
+ import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
3
+ export interface AssetApiCreatePayload {
4
+ name: string;
5
+ mimeType: string;
6
+ buffer: Buffer;
7
+ }
8
+ export interface AssetApiCreateResponse {
9
+ id: string;
10
+ url: string;
11
+ filename: string;
12
+ size: number;
13
+ width: number;
14
+ height: number;
15
+ last_modified: number;
16
+ kind: string;
17
+ extension: string;
18
+ created_at: number;
19
+ uploader_id: string;
20
+ tags: string[];
21
+ }
22
+ export declare class AssetApiClient extends AuthenticatedApiClient {
23
+ /**
24
+ * @example To instantiate the class:
25
+ *
26
+ * ```js
27
+ * new AssetApiClient("https://asset-api.prismic.io", {
28
+ * authToken: "my-secret-token",
29
+ * repository: "my-repo-name",
30
+ * });
31
+ * ```
32
+ *
33
+ * @param baseURL - The API base URL, such as https://asset-api.prismic.io
34
+ * @param config - Optional configuration
35
+ *
36
+ * - {@link config.authToken}: API token generated from the auth service or a
37
+ * function to fetch it when it's needed.
38
+ * - {@link config.repository}: Repository name.
39
+ */
40
+ constructor(baseURL: string, config: {
41
+ authToken: AuthServerToken;
42
+ repository: string;
43
+ });
44
+ /**
45
+ * Uploads an asset file to the server.
46
+ *
47
+ * @param data - The payload containing the file and filename.
48
+ *
49
+ * @returns The API response containing asset information.
50
+ *
51
+ * @throws An error if the upload fails.
52
+ */
53
+ createAsset(data: AssetApiCreatePayload): Promise<AssetApiCreateResponse>;
54
+ }
@@ -0,0 +1,48 @@
1
+ import { logPlaywrightApiResponse } from "../utils/log.js";
2
+ import { AuthenticatedApiClient } from "./apiClient.js";
3
+ class AssetApiClient extends AuthenticatedApiClient {
4
+ /**
5
+ * @example To instantiate the class:
6
+ *
7
+ * ```js
8
+ * new AssetApiClient("https://asset-api.prismic.io", {
9
+ * authToken: "my-secret-token",
10
+ * repository: "my-repo-name",
11
+ * });
12
+ * ```
13
+ *
14
+ * @param baseURL - The API base URL, such as https://asset-api.prismic.io
15
+ * @param config - Optional configuration
16
+ *
17
+ * - {@link config.authToken}: API token generated from the auth service or a
18
+ * function to fetch it when it's needed.
19
+ * - {@link config.repository}: Repository name.
20
+ */
21
+ constructor(baseURL, config) {
22
+ super(baseURL, config.authToken, { repository: config.repository });
23
+ }
24
+ /**
25
+ * Uploads an asset file to the server.
26
+ *
27
+ * @param data - The payload containing the file and filename.
28
+ *
29
+ * @returns The API response containing asset information.
30
+ *
31
+ * @throws An error if the upload fails.
32
+ */
33
+ async createAsset(data) {
34
+ const context = await this.getContext();
35
+ const result = await context.post("assets", {
36
+ multipart: { file: data }
37
+ });
38
+ if (200 !== result.status()) {
39
+ await logPlaywrightApiResponse(result);
40
+ throw new Error("Could not upload the asset with the asset API.");
41
+ }
42
+ return result.json();
43
+ }
44
+ }
45
+ export {
46
+ AssetApiClient
47
+ };
48
+ //# sourceMappingURL=assetApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assetApi.js","sources":["../../../src/clients/assetApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface AssetApiCreatePayload {\n\tname: string;\n\tmimeType: string;\n\tbuffer: Buffer;\n}\n\nexport interface AssetApiCreateResponse {\n\tid: string;\n\turl: string;\n\tfilename: string;\n\tsize: number;\n\twidth: number;\n\theight: number;\n\tlast_modified: number;\n\tkind: string;\n\textension: string;\n\tcreated_at: number;\n\tuploader_id: string;\n\ttags: string[];\n}\n\nexport class AssetApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new AssetApiClient(\"https://asset-api.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * \trepository: \"my-repo-name\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - The API base URL, such as https://asset-api.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.authToken}: API token generated from the auth service or a\n\t * function to fetch it when it's needed.\n\t * - {@link config.repository}: Repository name.\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Uploads an asset file to the server.\n\t *\n\t * @param data - The payload containing the file and filename.\n\t *\n\t * @returns The API response containing asset information.\n\t *\n\t * @throws An error if the upload fails.\n\t */\n\tasync createAsset(\n\t\tdata: AssetApiCreatePayload,\n\t): Promise<AssetApiCreateResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.post(\"assets\", {\n\t\t\tmultipart: { file: data },\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not upload the asset with the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":[],"mappings":";;AAyBM,MAAO,uBAAuB,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzD,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YACL,MAA2B;AAErB,UAAA,UAAU,MAAM,KAAK;AAE3B,UAAM,SAAS,MAAM,QAAQ,KAAK,UAAU;AAAA,MAC3C,WAAW,EAAE,MAAM,KAAM;AAAA,IAAA,CACzB;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,gDAAgD;AAAA,IACjE;AAEA,WAAO,OAAO;EACf;AACA;"}
@@ -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  };
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  const test = require("@playwright/test");
10
+ const authentication = require("../utils/authentication.cjs");
10
11
  const log = require("../utils/log.cjs");
11
12
  class AuthenticationApiClient {
12
13
  constructor(baseURL, auth) {
@@ -27,16 +28,8 @@ class AuthenticationApiClient {
27
28
  }
28
29
  async login() {
29
30
  const profiler = log.logger.startTimer();
30
- const context = await this.getContext();
31
- const result = await context.post("login", {
32
- data: {
33
- email: this.auth.email,
34
- password: this.auth.password
35
- }
36
- });
37
- const token = await result.text();
38
- if (!result.ok() || !token) {
39
- log.logPlaywrightApiResponse(result);
31
+ const { token } = await authentication.login(this.baseURL, this.auth.email, this.auth.password);
32
+ if (!token) {
40
33
  throw new Error("Authentication failed, no token received.");
41
34
  }
42
35
  profiler.done({
@@ -1 +1 @@
1
- {"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"login\", {\n\t\t\tdata: {\n\t\t\t\temail: this.auth.email,\n\t\t\t\tpassword: this.auth.password,\n\t\t\t},\n\t\t});\n\n\t\tconst token = await result.text();\n\t\tif (!result.ok() || !token) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":["request","logger","logPlaywrightApiResponse"],"mappings":";;;;;;;;;;MAOa,wBAAuB;AAAA,EAInC,YACkB,SACA,MAAgB;AADhB;AACA;AALV;AACA;AAGU,SAAO,UAAP;AACA,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;AAE7B,WAAA;AAAA,EACR;AACA;;"}
1
+ {"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { login as authenticateWithLambda } from \"../utils/authentication\";\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { token } = await authenticateWithLambda(\n\t\t\tthis.baseURL,\n\t\t\tthis.auth.email,\n\t\t\tthis.auth.password,\n\t\t);\n\n\t\tif (!token) {\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":["request","logger","authenticateWithLambda","logPlaywrightApiResponse"],"mappings":";;;;;;;;;;;MAQa,wBAAuB;AAAA,EAInC,YACkB,SACA,MAAgB;AADhB;AACA;AALV;AACA;AAGU,SAAO,UAAP;AACA,SAAI,OAAJ;AAAA,EACf;AAAA,EAEK,MAAM,aAAU;AACnB,QAAA,CAAC,KAAK,UAAU;AACd,WAAA,WAAW,MAAMA,KAAA,QAAQ,WAAW;AAAA,QACxC,SAAS,KAAK;AAAA,MAAA,CACd;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAEQ,MAAM,QAAK;AACZ,UAAA,WAAWC,WAAO;AAExB,UAAM,EAAE,MAAU,IAAA,MAAMC,eACvB,MAAA,KAAK,SACL,KAAK,KAAK,OACV,KAAK,KAAK,QAAQ;AAGnB,QAAI,CAAC,OAAO;AACL,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK,KAAK;AAAA,IAAA,CACpD;AAEM,WAAA;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,WAAQ;AACT,QAAA,CAAC,KAAK,WAAW;AACf,WAAA,YAAY,MAAM,KAAK;IAC7B;AAEA,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,MAAM,wBAAwB,YAAkB;AAC3C,QAAA,CAAC,KAAK,WAAW;AACf,WAAA,YAAY,MAAM,KAAK;IAC7B;AAEM,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,mBAAmB;AAAA,MACnD,SAAS;AAAA,QACR,eAAe,UAAU,KAAK,SAAS;AAAA,QACvC;AAAA,MACA;AAAA,IAAA,CACD;AAEG,QAAA,CAAC,OAAO,MAAM;AACjBC,UAAA,yBAAyB,MAAM;AACzB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE/D;AACA,UAAM,SAAS,MAAM,OAAO,KAAA,GAAQ;AAE7B,WAAA;AAAA,EACR;AACA;;"}
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { request } from "@playwright/test";
8
+ import { login } from "../utils/authentication.js";
8
9
  import { logger, logPlaywrightApiResponse } from "../utils/log.js";
9
10
  class AuthenticationApiClient {
10
11
  constructor(baseURL, auth) {
@@ -25,16 +26,8 @@ class AuthenticationApiClient {
25
26
  }
26
27
  async login() {
27
28
  const profiler = logger.startTimer();
28
- const context = await this.getContext();
29
- const result = await context.post("login", {
30
- data: {
31
- email: this.auth.email,
32
- password: this.auth.password
33
- }
34
- });
35
- const token = await result.text();
36
- if (!result.ok() || !token) {
37
- logPlaywrightApiResponse(result);
29
+ const { token } = await login(this.baseURL, this.auth.email, this.auth.password);
30
+ if (!token) {
38
31
  throw new Error("Authentication failed, no token received.");
39
32
  }
40
33
  profiler.done({
@@ -1 +1 @@
1
- {"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"login\", {\n\t\t\tdata: {\n\t\t\t\temail: this.auth.email,\n\t\t\t\tpassword: this.auth.password,\n\t\t\t},\n\t\t});\n\n\t\tconst token = await result.text();\n\t\tif (!result.ok() || !token) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;MAOa,wBAAuB;AAAA,EAInC,YACkB,SACA,MAAgB;AADhB;AACA;AALV;AACA;AAGU,SAAO,UAAP;AACA,SAAI,OAAJ;AAAA,EACf;AAAA,EAEK,MAAM,aAAU;AACnB,QAAA,CAAC,KAAK,UAAU;AACd,WAAA,WAAW,MAAM,QAAQ,WAAW;AAAA,QACxC,SAAS,KAAK;AAAA,MAAA,CACd;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAEQ,MAAM,QAAK;AACZ,UAAA,WAAW,OAAO;AAElB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,SAAS;AAAA,MAC1C,MAAM;AAAA,QACL,OAAO,KAAK,KAAK;AAAA,QACjB,UAAU,KAAK,KAAK;AAAA,MACpB;AAAA,IAAA,CACD;AAEK,UAAA,QAAQ,MAAM,OAAO;AAC3B,QAAI,CAAC,OAAO,QAAQ,CAAC,OAAO;AAC3B,+BAAyB,MAAM;AACzB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK,KAAK;AAAA,IAAA,CACpD;AAEM,WAAA;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,WAAQ;AACT,QAAA,CAAC,KAAK,WAAW;AACf,WAAA,YAAY,MAAM,KAAK;IAC7B;AAEA,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,MAAM,wBAAwB,YAAkB;AAC3C,QAAA,CAAC,KAAK,WAAW;AACf,WAAA,YAAY,MAAM,KAAK;IAC7B;AAEM,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,mBAAmB;AAAA,MACnD,SAAS;AAAA,QACR,eAAe,UAAU,KAAK,SAAS;AAAA,QACvC;AAAA,MACA;AAAA,IAAA,CACD;AAEG,QAAA,CAAC,OAAO,MAAM;AACjB,+BAAyB,MAAM;AACzB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE/D;AACA,UAAM,SAAS,MAAM,OAAO,KAAA,GAAQ;AAE7B,WAAA;AAAA,EACR;AACA;"}
1
+ {"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { login as authenticateWithLambda } from \"../utils/authentication\";\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { token } = await authenticateWithLambda(\n\t\t\tthis.baseURL,\n\t\t\tthis.auth.email,\n\t\t\tthis.auth.password,\n\t\t);\n\n\t\tif (!token) {\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":["authenticateWithLambda"],"mappings":";;;;;;;;;MAQa,wBAAuB;AAAA,EAInC,YACkB,SACA,MAAgB;AADhB;AACA;AALV;AACA;AAGU,SAAO,UAAP;AACA,SAAI,OAAJ;AAAA,EACf;AAAA,EAEK,MAAM,aAAU;AACnB,QAAA,CAAC,KAAK,UAAU;AACd,WAAA,WAAW,MAAM,QAAQ,WAAW;AAAA,QACxC,SAAS,KAAK;AAAA,MAAA,CACd;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAEQ,MAAM,QAAK;AACZ,UAAA,WAAW,OAAO;AAExB,UAAM,EAAE,MAAU,IAAA,MAAMA,MACvB,KAAK,SACL,KAAK,KAAK,OACV,KAAK,KAAK,QAAQ;AAGnB,QAAI,CAAC,OAAO;AACL,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK,KAAK;AAAA,IAAA,CACpD;AAEM,WAAA;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,WAAQ;AACT,QAAA,CAAC,KAAK,WAAW;AACf,WAAA,YAAY,MAAM,KAAK;IAC7B;AAEA,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,MAAM,wBAAwB,YAAkB;AAC3C,QAAA,CAAC,KAAK,WAAW;AACf,WAAA,YAAY,MAAM,KAAK;IAC7B;AAEM,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,mBAAmB;AAAA,MACnD,SAAS;AAAA,QACR,eAAe,UAAU,KAAK,SAAS;AAAA,QACvC;AAAA,MACA;AAAA,IAAA,CACD;AAEG,QAAA,CAAC,OAAO,MAAM;AACjB,+BAAyB,MAAM;AACzB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE/D;AACA,UAAM,SAAS,MAAM,OAAO,KAAA,GAAQ;AAE7B,WAAA;AAAA,EACR;AACA;"}
@@ -20,8 +20,8 @@ class ManageV2Client {
20
20
  // Not private to have it available on tests
21
21
  __publicField(this, "token", null);
22
22
  /**
23
- * The function `toggleRolePerLocal` enable or disable the role per local
24
- * feature
23
+ * The function `toggleRolePerLocal` enables or disables the RolesPerLocale
24
+ * workflow
25
25
  *
26
26
  * @param repository - The Repository name
27
27
  * @param enabled - The feature new status
@@ -33,6 +33,20 @@ class ManageV2Client {
33
33
  author: ManageV2StaticAuthor
34
34
  });
35
35
  }));
36
+ /**
37
+ * The function `toggleCustomRoles` enables or disables the CustomRoles
38
+ * workflow
39
+ *
40
+ * @param repository - The Repository name
41
+ * @param enabled - The feature new status
42
+ */
43
+ __publicField(this, "toggleCustomRoles", this.assertTokenExist((params) => {
44
+ return this.client.post("/repository/toggleCustomRoles", {
45
+ domain: params.repository,
46
+ enabled: params.enabled,
47
+ author: ManageV2StaticAuthor
48
+ });
49
+ }));
36
50
  /**
37
51
  * The function `changePlan` changes the plan of a repository the database
38
52
  *
@@ -88,7 +102,7 @@ class ManageV2Client {
88
102
  });
89
103
  this.client.interceptors.response.use((response) => {
90
104
  const cookies$1 = response.headers["set-cookie"];
91
- if (cookies$1 && cookies.extractCookie(cookies$1, "SESSION")) {
105
+ if (cookies$1 && cookies.extractCookie(cookies$1, "prismic-auth")) {
92
106
  this.client.defaults.headers["Cookie"] = cookies$1;
93
107
  }
94
108
  return response;
@@ -98,9 +112,8 @@ class ManageV2Client {
98
112
  * The function generates a JWT token using the provided configuration
99
113
  * parameters.
100
114
  *
101
- * @param {ManageV2Config} config - The `config` parameter in the
102
- * `generateToken` function is of type `ManageV2Config`. It contains the
103
- * following properties:
115
+ * @param config - The `config` parameter in the `generateToken` function is
116
+ * of type `ManageV2Config`. It contains the following properties:
104
117
  *
105
118
  * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
106
119
  * function. The token is signed using the provided `config.secret` with the
@@ -1 +1 @@
1
- {"version":3,"file":"manageV2.cjs","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration\n\t * parameters.\n\t *\n\t * @param {ManageV2Config} config - The `config` parameter in the\n\t * `generateToken` function is of type `ManageV2Config`. It contains the\n\t * following properties:\n\t *\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken`\n\t * function. The token is signed using the provided `config.secret` with the\n\t * HS256 algorithm and includes the specified audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t});\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a\n\t * given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a\n\t * parameter. This function `f` should accept a parameter of type\n\t * `Parameters` and return a Promise that resolves to an AxiosResponse. The\n\t * `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t *\n\t * @returns A function is being returned that takes a parameter of type\n\t * Parameters and checks if the token is null. If the token is null, an\n\t * error is thrown. Otherwise, the function f is called with the provided\n\t * parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(\n\t\tf: (_: Parameters) => Promise<AxiosResponse>,\n\t) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Undefined configuration for ManageV2 while trying to use it's routes\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\treturn f(params);\n\t\t\t}\n\t\t};\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enable or disable the role per local\n\t * feature\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that\n\t * the database and Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string;\n\t\t\tnewPlanId: string;\n\t\t\tbypassManualBilling?: boolean;\n\t\t}) => {\n\t\t\treturn this.client.post(\n\t\t\t\t`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,\n\t\t\t\t{\n\t\t\t\t\tdomain: repository,\n\t\t\t\t\tnewPlan: newPlanId,\n\t\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t);\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email\n\t * to the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the\n\t * email from the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n}\n"],"names":["cookies","extractCookie"],"mappings":";;;;;;;;;;;AAOA,MAAM,uBAAuB;MAMhB,eAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1B,YAAY,SAAiB,QAAmC;AAPvD;AACD;AAAA,iCAAuB;AA0F/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAAqB,KAAK,iBACzB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,oCAAoC;AAAA,QAC3D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,KAAK,iBACjB,CAAC,EACA,YACA,WACA,sBAAsB,YAKlB;AACJ,aAAO,KAAK,OAAO,KAClB,8CAA8C,mBAAmB,IACjE;A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AAA,CACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBQ,iBACP,GAA4C;AAE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MAChB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAiFA;;"}
1
+ {"version":3,"file":"manageV2.cjs","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"prismic-auth\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration\n\t * parameters.\n\t *\n\t * @param config - The `config` parameter in the `generateToken` function is\n\t * of type `ManageV2Config`. It contains the following properties:\n\t *\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken`\n\t * function. The token is signed using the provided `config.secret` with the\n\t * HS256 algorithm and includes the specified audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t});\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a\n\t * given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a\n\t * parameter. This function `f` should accept a parameter of type\n\t * `Parameters` and return a Promise that resolves to an AxiosResponse. The\n\t * `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t *\n\t * @returns A function is being returned that takes a parameter of type\n\t * Parameters and checks if the token is null. If the token is null, an\n\t * error is thrown. Otherwise, the function f is called with the provided\n\t * parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(\n\t\tf: (_: Parameters) => Promise<AxiosResponse>,\n\t) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Undefined configuration for ManageV2 while trying to use it's routes\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\treturn f(params);\n\t\t\t}\n\t\t};\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enables or disables the RolesPerLocale\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `toggleCustomRoles` enables or disables the CustomRoles\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleCustomRoles = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleCustomRoles\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that\n\t * the database and Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string;\n\t\t\tnewPlanId: string;\n\t\t\tbypassManualBilling?: boolean;\n\t\t}) => {\n\t\t\treturn this.client.post(\n\t\t\t\t`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,\n\t\t\t\t{\n\t\t\t\t\tdomain: repository,\n\t\t\t\t\tnewPlan: newPlanId,\n\t\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t);\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email\n\t * to the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the\n\t * email from the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n}\n"],"names":["cookies","extractCookie"],"mappings":";;;;;;;;;;;AAOA,MAAM,uBAAuB;MAMhB,eAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1B,YAAY,SAAiB,QAAmC;AAPvD;AACD;AAAA,iCAAuB;AAyF/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAAqB,KAAK,iBACzB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,oCAAoC;AAAA,QAC3D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CAAoB,KAAK,iBACxB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,iCAAiC;AAAA,QACxD,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,KAAK,iBACjB,CAAC,EACA,YACA,WACA,sBAAsB,YAKlB;AACJ,aAAO,KAAK,OAAO,KAClB,8CAA8C,mBAAmB,IACjE;AAAA,QACC,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CAEF;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MAChB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAkGA;;"}
@@ -16,9 +16,8 @@ export declare class ManageV2Client {
16
16
  * The function generates a JWT token using the provided configuration
17
17
  * parameters.
18
18
  *
19
- * @param {ManageV2Config} config - The `config` parameter in the
20
- * `generateToken` function is of type `ManageV2Config`. It contains the
21
- * following properties:
19
+ * @param config - The `config` parameter in the `generateToken` function is
20
+ * of type `ManageV2Config`. It contains the following properties:
22
21
  *
23
22
  * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
24
23
  * function. The token is signed using the provided `config.secret` with the
@@ -43,8 +42,8 @@ export declare class ManageV2Client {
43
42
  private assertTokenExist;
44
43
  getBaseURL(): string;
45
44
  /**
46
- * The function `toggleRolePerLocal` enable or disable the role per local
47
- * feature
45
+ * The function `toggleRolePerLocal` enables or disables the RolesPerLocale
46
+ * workflow
48
47
  *
49
48
  * @param repository - The Repository name
50
49
  * @param enabled - The feature new status
@@ -53,6 +52,17 @@ export declare class ManageV2Client {
53
52
  repository: string;
54
53
  enabled: boolean;
55
54
  }) => Promise<AxiosResponse<any, any>>;
55
+ /**
56
+ * The function `toggleCustomRoles` enables or disables the CustomRoles
57
+ * workflow
58
+ *
59
+ * @param repository - The Repository name
60
+ * @param enabled - The feature new status
61
+ */
62
+ toggleCustomRoles: (params: {
63
+ repository: string;
64
+ enabled: boolean;
65
+ }) => Promise<AxiosResponse<any, any>>;
56
66
  /**
57
67
  * The function `changePlan` changes the plan of a repository the database
58
68
  *
@@ -18,8 +18,8 @@ class ManageV2Client {
18
18
  // Not private to have it available on tests
19
19
  __publicField(this, "token", null);
20
20
  /**
21
- * The function `toggleRolePerLocal` enable or disable the role per local
22
- * feature
21
+ * The function `toggleRolePerLocal` enables or disables the RolesPerLocale
22
+ * workflow
23
23
  *
24
24
  * @param repository - The Repository name
25
25
  * @param enabled - The feature new status
@@ -31,6 +31,20 @@ class ManageV2Client {
31
31
  author: ManageV2StaticAuthor
32
32
  });
33
33
  }));
34
+ /**
35
+ * The function `toggleCustomRoles` enables or disables the CustomRoles
36
+ * workflow
37
+ *
38
+ * @param repository - The Repository name
39
+ * @param enabled - The feature new status
40
+ */
41
+ __publicField(this, "toggleCustomRoles", this.assertTokenExist((params) => {
42
+ return this.client.post("/repository/toggleCustomRoles", {
43
+ domain: params.repository,
44
+ enabled: params.enabled,
45
+ author: ManageV2StaticAuthor
46
+ });
47
+ }));
34
48
  /**
35
49
  * The function `changePlan` changes the plan of a repository the database
36
50
  *
@@ -86,7 +100,7 @@ class ManageV2Client {
86
100
  });
87
101
  this.client.interceptors.response.use((response) => {
88
102
  const cookies = response.headers["set-cookie"];
89
- if (cookies && extractCookie(cookies, "SESSION")) {
103
+ if (cookies && extractCookie(cookies, "prismic-auth")) {
90
104
  this.client.defaults.headers["Cookie"] = cookies;
91
105
  }
92
106
  return response;
@@ -96,9 +110,8 @@ class ManageV2Client {
96
110
  * The function generates a JWT token using the provided configuration
97
111
  * parameters.
98
112
  *
99
- * @param {ManageV2Config} config - The `config` parameter in the
100
- * `generateToken` function is of type `ManageV2Config`. It contains the
101
- * following properties:
113
+ * @param config - The `config` parameter in the `generateToken` function is
114
+ * of type `ManageV2Config`. It contains the following properties:
102
115
  *
103
116
  * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
104
117
  * function. The token is signed using the provided `config.secret` with the
@@ -1 +1 @@
1
- {"version":3,"file":"manageV2.js","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration\n\t * parameters.\n\t *\n\t * @param {ManageV2Config} config - The `config` parameter in the\n\t * `generateToken` function is of type `ManageV2Config`. It contains the\n\t * following properties:\n\t *\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken`\n\t * function. The token is signed using the provided `config.secret` with the\n\t * HS256 algorithm and includes the specified audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t});\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a\n\t * given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a\n\t * parameter. This function `f` should accept a parameter of type\n\t * `Parameters` and return a Promise that resolves to an AxiosResponse. The\n\t * `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t *\n\t * @returns A function is being returned that takes a parameter of type\n\t * Parameters and checks if the token is null. If the token is null, an\n\t * error is thrown. Otherwise, the function f is called with the provided\n\t * parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(\n\t\tf: (_: Parameters) => Promise<AxiosResponse>,\n\t) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Undefined configuration for ManageV2 while trying to use it's routes\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\treturn f(params);\n\t\t\t}\n\t\t};\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enable or disable the role per local\n\t * feature\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that\n\t * the database and Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string;\n\t\t\tnewPlanId: string;\n\t\t\tbypassManualBilling?: boolean;\n\t\t}) => {\n\t\t\treturn this.client.post(\n\t\t\t\t`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,\n\t\t\t\t{\n\t\t\t\t\tdomain: repository,\n\t\t\t\t\tnewPlan: newPlanId,\n\t\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t);\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email\n\t * to the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the\n\t * email from the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n}\n"],"names":[],"mappings":";;;;;;;;;AAOA,MAAM,uBAAuB;MAMhB,eAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1B,YAAY,SAAiB,QAAmC;AAPvD;AACD;AAAA,iCAAuB;AA0F/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAAqB,KAAK,iBACzB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,oCAAoC;AAAA,QAC3D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,KAAK,iBACjB,CAAC,EACA,YACA,WACA,sBAAsB,YAKlB;AACJ,aAAO,KAAK,OAAO,KAClB,8CAA8C,mBAAmB,IACjE;AAAA,QACC,QAAQ;AAAA,QACR,SA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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBQ,iBACP,GAA4C;AAE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MAChB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAiFA;"}
1
+ {"version":3,"file":"manageV2.js","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"prismic-auth\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration\n\t * parameters.\n\t *\n\t * @param config - The `config` parameter in the `generateToken` function is\n\t * of type `ManageV2Config`. It contains the following properties:\n\t *\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken`\n\t * function. The token is signed using the provided `config.secret` with the\n\t * HS256 algorithm and includes the specified audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t});\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a\n\t * given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a\n\t * parameter. This function `f` should accept a parameter of type\n\t * `Parameters` and return a Promise that resolves to an AxiosResponse. The\n\t * `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t *\n\t * @returns A function is being returned that takes a parameter of type\n\t * Parameters and checks if the token is null. If the token is null, an\n\t * error is thrown. Otherwise, the function f is called with the provided\n\t * parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(\n\t\tf: (_: Parameters) => Promise<AxiosResponse>,\n\t) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Undefined configuration for ManageV2 while trying to use it's routes\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\treturn f(params);\n\t\t\t}\n\t\t};\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enables or disables the RolesPerLocale\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `toggleCustomRoles` enables or disables the CustomRoles\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleCustomRoles = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleCustomRoles\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that\n\t * the database and Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string;\n\t\t\tnewPlanId: string;\n\t\t\tbypassManualBilling?: boolean;\n\t\t}) => {\n\t\t\treturn this.client.post(\n\t\t\t\t`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,\n\t\t\t\t{\n\t\t\t\t\tdomain: repository,\n\t\t\t\t\tnewPlan: newPlanId,\n\t\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t);\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email\n\t * to the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the\n\t * email from the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n}\n"],"names":[],"mappings":";;;;;;;;;AAOA,MAAM,uBAAuB;MAMhB,eAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1B,YAAY,SAAiB,QAAmC;AAPvD;AACD;AAAA,iCAAuB;AAyF/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAAqB,KAAK,iBACzB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,oCAAoC;AAAA,QAC3D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CAAoB,KAAK,iBACxB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,iCAAiC;AAAA,QACxD,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,KAAK,iBACjB,CAAC,EACA,YACA,WACA,sBAAsB,YAKlB;AACJ,aAAO,KAAK,OAAO,KAClB,8CAA8C,mBAAmB,IACjE;AAAA,QACC,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CAEF;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+CAAsB,KAAK,iBAC1B,CAAC,EAAE,YAAY,YAAkD;AACzD,aAAA,K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,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MAChB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAkGA;"}
@@ -7,8 +7,8 @@ var __publicField = (obj, key, value) => {
7
7
  };
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  const axios = require("axios");
10
+ const authentication = require("../utils/authentication.cjs");
10
11
  const cookies = require("../utils/cookies.cjs");
11
- const log = require("../utils/log.cjs");
12
12
  const urls = require("../utils/urls.cjs");
13
13
  class WroomClient {
14
14
  /**
@@ -76,9 +76,9 @@ class WroomClient {
76
76
  /**
77
77
  * Update the role of a user in the repository
78
78
  *
79
- * @param {string} repository - The repository name
80
- * @param {string} email - The email of the user
81
- * @param {string} role - The new role to be given
79
+ * @param repository - The repository name
80
+ * @param email - The email of the user
81
+ * @param role - The new role to be given
82
82
  *
83
83
  * @returns The Axios Reponse
84
84
  */
@@ -90,9 +90,9 @@ class WroomClient {
90
90
  /**
91
91
  * Update the role of a user in the repository
92
92
  *
93
- * @param {string} repository - The repository name
94
- * @param {string} email - The email of the user
95
- * @param {string} rolePerLocal - The role per local object
93
+ * @param repository - The repository name
94
+ * @param email - The email of the user
95
+ * @param rolePerLocal - The role per local object
96
96
  *
97
97
  * @returns The Axios Reponse
98
98
  */
@@ -107,17 +107,11 @@ class WroomClient {
107
107
  * @throws Error if the login to Wroom fails.
108
108
  */
109
109
  async login() {
110
- const profiler = log.logger.startTimer();
111
- const response = await this.client.post("/authentication/signin", {
112
- email: this.auth.email,
113
- password: this.auth.password
114
- });
115
- if (response.status !== 200) {
116
- log.logHttpResponse(response);
117
- throw new Error("Could not login to Prismic, check your credentials");
110
+ const { cookies: cookies$1 } = await authentication.login(this.getBaseURL(), this.auth.email, this.auth.password);
111
+ if (cookies$1 && cookies.extractCookie(cookies$1, "prismic-auth")) {
112
+ this.client.defaults.headers["Cookie"] = cookies$1;
118
113
  }
119
114
  this.loggedIn = true;
120
- profiler.done({ message: "logged in to Prismic" });
121
115
  }
122
116
  }
123
117
  exports.WroomClient = WroomClient;
@@ -1 +1 @@
1
- {"version":3,"file":"wroom.cjs","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/**\n * Client for interacting with the Wroom service to perform operations on\n * repositories.\n */\nexport class WroomClient {\n\tprivate readonly client: AxiosInstance;\n\tprivate loggedIn = false;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param auth - Authentication credentials.\n\t * @param cluster - Cluster where to create the repository (only work in\n\t * staging)\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t\tcluster?: string,\n\t) {\n\t\tconst clusterHeader = cluster\n\t\t\t? {\n\t\t\t\t\t\"X-Prismic-Cluster\": cluster,\n\t\t\t\t}\n\t\t\t: {};\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\txsrfCookieName: \"X_XSRF\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\t...clusterHeader,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"prismic-auth\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/** authenticated GET request on the wroom backend */\n\tasync get(repository: string | null, path: string): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\n\t\treturn this.client.get(url);\n\t}\n\n\t/** authenticated POST request on the wroom backend */\n\tasync post(\n\t\trepository: string | null,\n\t\tpath: string,\n\t\tdata?: unknown,\n\t): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\t\tconst response = await this.client.post(url.toString(), data, {\n\t\t\tparams: {\n\t\t\t\t_: extractCookie(this.client.defaults.headers[\"Cookie\"], \"X_XSRF\"),\n\t\t\t},\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param {string} repository - The repository name\n\t * @param {string} email - The email of the user\n\t * @param {string} role - The new role to be given\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRole(\n\t\trepository: string,\n\t\temail: string,\n\t\trole: string,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email, profile: role });\n\t\tconst path = `/app/settings/users/profiles?${params.toString()}`;\n\n\t\treturn this.post(repository, path);\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param {string} repository - The repository name\n\t * @param {string} email - The email of the user\n\t * @param {string} rolePerLocal - The role per local object\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRolePerLocal(\n\t\trepository: string,\n\t\temail: string,\n\t\trolePerLocal: Record<string, string>,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email });\n\t\tconst path = `/app/settings/users/rolesperlocale?${params.toString()}`;\n\n\t\treturn this.post(repository, path, rolePerLocal);\n\t}\n\n\t/**\n\t * Authenticate Wroom to call Wroom unofficial endpoints.\n\t *\n\t * @throws Error if the login to Wroom fails.\n\t */\n\tprivate async login(): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst response = await this.client.post<string>(\"/authentication/signin\", {\n\t\t\temail: this.auth.email,\n\t\t\tpassword: this.auth.password,\n\t\t});\n\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\"Could not login to Prismic, check your credentials\");\n\t\t}\n\t\tthis.loggedIn = true;\n\t\tprofiler.done({ message: \"logged in to Prismic\" });\n\t}\n}\n"],"names":["cookies","extractCookie","getRepositoryUrl","logger","logHttpResponse"],"mappings":";;;;;;;;;;;;MAYa,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvB,YACC,SACiB,MACjB,SAAgB;AADC;AAXD;AACT,oCAAW;AAUD,SAAI,OAAJ;AAGjB,UAAM,gBAAgB,UACnB;AAAA,MACA,qBAAqB;AAAA,QAErB;AAEE,SAAA,SAAS,MAAM,OAAO;AAAA,MAC1B;AAAA,MACA,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,gBAAgB;AAAA,MAChB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAGD,SAAK,OAAO,aAAa,SAAS,IAAI,CAAC,aAAY;AAC5C,YAAAA,YAAU,SAAS,QAAQ,YAAY;AAC7C,UAAIA,aAAWC,QAAAA,cAAcD,WAAS,cAAc,GAAG;AACtD,aAAK,OAAO,SAAS,QAAQ,QAAQ,IAAIA;AAAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACP;AAAA,EACF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAAA;AAAA,EAGA,MAAM,IAAI,YAA2B,MAAY;AAC5C,QAAA,CAAC,KAAK,UAAU;AACnB,YAAM,KAAK;IACZ;AAEI,QAAA,MAAM,IAAI,IAAI,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ACzE,OAAO,KAAK,KAAK;AAAA,MACjB,UAAU,KAAK,KAAK;AAAA,IAAA,CACpB;AAEG,QAAA,SAAS,WAAW,KAAK;AAC5BC,UAAA,gBAAgB,QAAQ;AAClB,YAAA,IAAI,MAAM,oDAAoD;AAAA,IACrE;AACA,SAAK,WAAW;AAChB,aAAS,KAAK,EAAE,SAAS,uBAAwB,CAAA;AAAA,EAClD;AACA;;"}
1
+ {"version":3,"file":"wroom.cjs","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { login } from \"../utils/authentication\";\nimport { extractCookie } from \"../utils/cookies\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/**\n * Client for interacting with the Wroom service to perform operations on\n * repositories.\n */\nexport class WroomClient {\n\tprivate readonly client: AxiosInstance;\n\tprivate loggedIn = false;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param auth - Authentication credentials.\n\t * @param cluster - Cluster where to create the repository (only work in\n\t * staging)\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t\tcluster?: string,\n\t) {\n\t\tconst clusterHeader = cluster\n\t\t\t? {\n\t\t\t\t\t\"X-Prismic-Cluster\": cluster,\n\t\t\t\t}\n\t\t\t: {};\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\txsrfCookieName: \"X_XSRF\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\t...clusterHeader,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"prismic-auth\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/** authenticated GET request on the wroom backend */\n\tasync get(repository: string | null, path: string): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\n\t\treturn this.client.get(url);\n\t}\n\n\t/** authenticated POST request on the wroom backend */\n\tasync post(\n\t\trepository: string | null,\n\t\tpath: string,\n\t\tdata?: unknown,\n\t): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\t\tconst response = await this.client.post(url.toString(), data, {\n\t\t\tparams: {\n\t\t\t\t_: extractCookie(this.client.defaults.headers[\"Cookie\"], \"X_XSRF\"),\n\t\t\t},\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param repository - The repository name\n\t * @param email - The email of the user\n\t * @param role - The new role to be given\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRole(\n\t\trepository: string,\n\t\temail: string,\n\t\trole: string,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email, profile: role });\n\t\tconst path = `/app/settings/users/profiles?${params.toString()}`;\n\n\t\treturn this.post(repository, path);\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param repository - The repository name\n\t * @param email - The email of the user\n\t * @param rolePerLocal - The role per local object\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRolePerLocal(\n\t\trepository: string,\n\t\temail: string,\n\t\trolePerLocal: Record<string, string>,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email });\n\t\tconst path = `/app/settings/users/rolesperlocale?${params.toString()}`;\n\n\t\treturn this.post(repository, path, rolePerLocal);\n\t}\n\n\t/**\n\t * Authenticate Wroom to call Wroom unofficial endpoints.\n\t *\n\t * @throws Error if the login to Wroom fails.\n\t */\n\tprivate async login(): Promise<void> {\n\t\tconst { cookies } = await login(\n\t\t\tthis.getBaseURL(),\n\t\t\tthis.auth.email,\n\t\t\tthis.auth.password,\n\t\t);\n\t\tif (cookies && extractCookie(cookies, \"prismic-auth\")) {\n\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t}\n\t\tthis.loggedIn = true;\n\t}\n}\n"],"names":["cookies","extractCookie","getRepositoryUrl","login"],"mappings":";;;;;;;;;;;;MAYa,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvB,YACC,SACiB,MACjB,SAAgB;AADC;AAXD;AACT,oCAAW;AAUD,SAAI,OAAJ;AAGjB,UAAM,gBAAgB,UACnB;AAAA,MACA,qBAAqB;AAAA,QAErB;AAEE,SAAA,SAAS,MAAM,OAAO;AAAA,MAC1B;AAAA,MACA,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,gBAAgB;AAAA,MAChB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAGD,SAAK,OAAO,aAAa,SAAS,IAAI,CAAC,aAAY;AAC5C,YAAAA,YAAU,SAAS,QAAQ,YAAY;AAC7C,UAAIA,aAAWC,QAAAA,cAAcD,WAAS,cAAc,GAAG;AACtD,aAAK,OAAO,SAAS,QAAQ,QAAQ,IAAIA;AAAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACP;AAAA,EACF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAAA;AAAA,EAGA,MAAM,IAAI,YAA2B,MAAY;AAC5C,QAAA,CAAC,KAAK,UAAU;AACnB,YA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MAAMG,eACzB,MAAA,KAAK,WAAY,GACjB,KAAK,KAAK,OACV,KAAK,KAAK,QAAQ;AAEnB,QAAIH,aAAWC,QAAAA,cAAcD,WAAS,cAAc,GAAG;AACtD,WAAK,OAAO,SAAS,QAAQ,QAAQ,IAAIA;AAAAA,IAC1C;AACA,SAAK,WAAW;AAAA,EACjB;AACA;;"}
@@ -23,9 +23,9 @@ export declare class WroomClient {
23
23
  /**
24
24
  * Update the role of a user in the repository
25
25
  *
26
- * @param {string} repository - The repository name
27
- * @param {string} email - The email of the user
28
- * @param {string} role - The new role to be given
26
+ * @param repository - The repository name
27
+ * @param email - The email of the user
28
+ * @param role - The new role to be given
29
29
  *
30
30
  * @returns The Axios Reponse
31
31
  */
@@ -33,9 +33,9 @@ export declare class WroomClient {
33
33
  /**
34
34
  * Update the role of a user in the repository
35
35
  *
36
- * @param {string} repository - The repository name
37
- * @param {string} email - The email of the user
38
- * @param {string} rolePerLocal - The role per local object
36
+ * @param repository - The repository name
37
+ * @param email - The email of the user
38
+ * @param rolePerLocal - The role per local object
39
39
  *
40
40
  * @returns The Axios Reponse
41
41
  */