@prismicio/e2e-tests-utils 1.1.2 → 1.2.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/src/types.ts CHANGED
@@ -1,27 +1 @@
1
- export type UrlConfig = {
2
- /** Prismic base url */
3
- baseURL: string;
4
- /** Custom types api base url */
5
- customTypesApi: string;
6
- /** Auth service api base url */
7
- authenticationApi: string;
8
- };
9
-
10
- export type AuthConfig = {
11
- email: string;
12
- password: string;
13
- };
14
-
15
- export type ManageV2Config = {
16
- secret: string;
17
- audience: string;
18
- };
19
-
20
- // Global configuration Object
21
- export type SetupConfiguration = {
22
- // If provided as a string: It is treated as the base URL for Prismic. Other
23
- // URLs (Custom Types API, Auth API) will be derived from it.
24
- urlConfig: UrlConfig | string;
25
- authConfig: AuthConfig;
26
- manageV2Config?: ManageV2Config;
27
- };
1
+ export type Credentials = { email: string; password: string };
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
8
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
- const axios = require("axios");
10
- const jwt = require("jsonwebtoken");
11
- const cookies = require("../utils/cookies.cjs");
12
- const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
13
- class ManageV2Client {
14
- /**
15
- * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
16
- * @param config - ManageV2 configuration variable to call ManageV2.
17
- */
18
- constructor(baseUrl, config) {
19
- __publicField(this, "client");
20
- // Not private to have it available on tests
21
- __publicField(this, "token", null);
22
- /**
23
- * The function `toggleRolePerLocal` enable or disable the role per local
24
- * feature
25
- *
26
- * @param repository - The Repository name
27
- * @param enabled - The feature new status
28
- */
29
- __publicField(this, "toggleRolePerLocal", this.assertTokenExist((params) => {
30
- return this.client.post("/repository/toggleRolesPerLocale", {
31
- domain: params.repository,
32
- enabled: params.enabled,
33
- author: ManageV2StaticAuthor
34
- });
35
- }));
36
- /**
37
- * The function `changePlan` changes the plan of a repository the database
38
- *
39
- * @param repository - The Repository name
40
- * @param newPlanId - The new planId
41
- * @param bypassManualBilling - Beware that using this will not verify that
42
- * the database and Stripe are in sync
43
- */
44
- __publicField(this, "changePlan", this.assertTokenExist(({ repository, newPlanId, bypassManualBilling = false }) => {
45
- return this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {
46
- domain: repository,
47
- newPlan: newPlanId,
48
- author: ManageV2StaticAuthor
49
- });
50
- }));
51
- /**
52
- * The function `addUserToRepository` adds a user corresponding to the email
53
- * to the given repository
54
- *
55
- * @param repository - The Repository name
56
- * @param email - The user email
57
- */
58
- __publicField(this, "addUserToRepository", this.assertTokenExist(({ repository, email }) => {
59
- return this.client.post("/repository/addUser", {
60
- domain: repository,
61
- email,
62
- author: ManageV2StaticAuthor
63
- });
64
- }));
65
- /**
66
- * The function `removeUserFromRepository` removes a user corresponding to the
67
- * email from the given repository
68
- *
69
- * @param repository - The Repository name
70
- * @param email - The user email
71
- */
72
- __publicField(this, "removeUserFromRepository", this.assertTokenExist(({ repository, email }) => {
73
- return this.client.post("/repository/removeUser", {
74
- domain: repository,
75
- email,
76
- author: ManageV2StaticAuthor
77
- });
78
- }));
79
- this.token = config ? this.generateToken(config) : null;
80
- this.client = axios.create({
81
- baseURL: `${baseUrl}/manageroutes/`,
82
- withCredentials: true,
83
- validateStatus: () => true,
84
- headers: {
85
- "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
86
- Authorization: `Bearer ${this.token}`
87
- }
88
- });
89
- this.client.interceptors.response.use((response) => {
90
- const cookies$1 = response.headers["set-cookie"];
91
- if (cookies$1 && cookies.extractCookie(cookies$1, "SESSION")) {
92
- this.client.defaults.headers["Cookie"] = cookies$1;
93
- }
94
- return response;
95
- });
96
- }
97
- /**
98
- * The function generates a JWT token using the provided configuration
99
- * parameters.
100
- *
101
- * @param {ManageV2Config} config - The `config` parameter in the
102
- * `generateToken` function is of type `ManageV2Config`. It contains the
103
- * following properties:
104
- *
105
- * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
106
- * function. The token is signed using the provided `config.secret` with the
107
- * HS256 algorithm and includes the specified audience and issuer values.
108
- */
109
- generateToken(config) {
110
- return jwt.sign({}, config.secret, {
111
- algorithm: "HS256",
112
- audience: config.audience,
113
- issuer: "prismic.io"
114
- });
115
- }
116
- /**
117
- * The function `assertTokenExist` checks if a token exists before executing a
118
- * given function.
119
- *
120
- * @param f - The `assertTokenExist` function takes a function `f` as a
121
- * parameter. This function `f` should accept a parameter of type
122
- * `Parameters` and return a Promise that resolves to an AxiosResponse. The
123
- * `assertTokenExist` function ensures that a token is not null before
124
- * calling the provided
125
- *
126
- * @returns A function is being returned that takes a parameter of type
127
- * Parameters and checks if the token is null. If the token is null, an
128
- * error is thrown. Otherwise, the function f is called with the provided
129
- * parameters.
130
- */
131
- assertTokenExist(f) {
132
- return (params) => {
133
- if (this.token === null) {
134
- throw new Error("Undefined configuration for ManageV2 while trying to use it's routes");
135
- } else {
136
- return f(params);
137
- }
138
- };
139
- }
140
- getBaseURL() {
141
- return this.client.getUri();
142
- }
143
- }
144
- exports.ManageV2Client = ManageV2Client;
145
- //# sourceMappingURL=manageV2.cjs.map
@@ -1 +0,0 @@
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;AAAA,QACC,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CAEF;AAUF;AAAA;AAAA;AAAA;AAAA;A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iBQ,iBACP,GAA4C;AAE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MACf;AAAA,IAAA;AAAA,EAEH;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAiFA;;"}
@@ -1,91 +0,0 @@
1
- import { AxiosInstance, AxiosResponse } from "axios";
2
- import { ManageV2Config } from "../types";
3
- /**
4
- * Client for interacting with ManageV2 routes to perform operations on
5
- * repositories.
6
- */
7
- export declare class ManageV2Client {
8
- readonly client: AxiosInstance;
9
- private token;
10
- /**
11
- * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
12
- * @param config - ManageV2 configuration variable to call ManageV2.
13
- */
14
- constructor(baseUrl: string, config?: ManageV2Config | undefined);
15
- /**
16
- * The function generates a JWT token using the provided configuration
17
- * parameters.
18
- *
19
- * @param {ManageV2Config} config - The `config` parameter in the
20
- * `generateToken` function is of type `ManageV2Config`. It contains the
21
- * following properties:
22
- *
23
- * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
24
- * function. The token is signed using the provided `config.secret` with the
25
- * HS256 algorithm and includes the specified audience and issuer values.
26
- */
27
- private generateToken;
28
- /**
29
- * The function `assertTokenExist` checks if a token exists before executing a
30
- * given function.
31
- *
32
- * @param f - The `assertTokenExist` function takes a function `f` as a
33
- * parameter. This function `f` should accept a parameter of type
34
- * `Parameters` and return a Promise that resolves to an AxiosResponse. The
35
- * `assertTokenExist` function ensures that a token is not null before
36
- * calling the provided
37
- *
38
- * @returns A function is being returned that takes a parameter of type
39
- * Parameters and checks if the token is null. If the token is null, an
40
- * error is thrown. Otherwise, the function f is called with the provided
41
- * parameters.
42
- */
43
- private assertTokenExist;
44
- getBaseURL(): string;
45
- /**
46
- * The function `toggleRolePerLocal` enable or disable the role per local
47
- * feature
48
- *
49
- * @param repository - The Repository name
50
- * @param enabled - The feature new status
51
- */
52
- toggleRolePerLocal: (params: {
53
- repository: string;
54
- enabled: boolean;
55
- }) => Promise<AxiosResponse<any, any>>;
56
- /**
57
- * The function `changePlan` changes the plan of a repository the database
58
- *
59
- * @param repository - The Repository name
60
- * @param newPlanId - The new planId
61
- * @param bypassManualBilling - Beware that using this will not verify that
62
- * the database and Stripe are in sync
63
- */
64
- changePlan: (params: {
65
- repository: string;
66
- newPlanId: string;
67
- bypassManualBilling?: boolean | undefined;
68
- }) => Promise<AxiosResponse<any, any>>;
69
- /**
70
- * The function `addUserToRepository` adds a user corresponding to the email
71
- * to the given repository
72
- *
73
- * @param repository - The Repository name
74
- * @param email - The user email
75
- */
76
- addUserToRepository: (params: {
77
- repository: string;
78
- email: string;
79
- }) => Promise<AxiosResponse<any, any>>;
80
- /**
81
- * The function `removeUserFromRepository` removes a user corresponding to the
82
- * email from the given repository
83
- *
84
- * @param repository - The Repository name
85
- * @param email - The user email
86
- */
87
- removeUserFromRepository: (params: {
88
- repository: string;
89
- email: string;
90
- }) => Promise<AxiosResponse<any, any>>;
91
- }
@@ -1,145 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import axios from "axios";
8
- import jwt from "jsonwebtoken";
9
- import { extractCookie } from "../utils/cookies.js";
10
- const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
11
- class ManageV2Client {
12
- /**
13
- * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
14
- * @param config - ManageV2 configuration variable to call ManageV2.
15
- */
16
- constructor(baseUrl, config) {
17
- __publicField(this, "client");
18
- // Not private to have it available on tests
19
- __publicField(this, "token", null);
20
- /**
21
- * The function `toggleRolePerLocal` enable or disable the role per local
22
- * feature
23
- *
24
- * @param repository - The Repository name
25
- * @param enabled - The feature new status
26
- */
27
- __publicField(this, "toggleRolePerLocal", this.assertTokenExist((params) => {
28
- return this.client.post("/repository/toggleRolesPerLocale", {
29
- domain: params.repository,
30
- enabled: params.enabled,
31
- author: ManageV2StaticAuthor
32
- });
33
- }));
34
- /**
35
- * The function `changePlan` changes the plan of a repository the database
36
- *
37
- * @param repository - The Repository name
38
- * @param newPlanId - The new planId
39
- * @param bypassManualBilling - Beware that using this will not verify that
40
- * the database and Stripe are in sync
41
- */
42
- __publicField(this, "changePlan", this.assertTokenExist(({ repository, newPlanId, bypassManualBilling = false }) => {
43
- return this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {
44
- domain: repository,
45
- newPlan: newPlanId,
46
- author: ManageV2StaticAuthor
47
- });
48
- }));
49
- /**
50
- * The function `addUserToRepository` adds a user corresponding to the email
51
- * to the given repository
52
- *
53
- * @param repository - The Repository name
54
- * @param email - The user email
55
- */
56
- __publicField(this, "addUserToRepository", this.assertTokenExist(({ repository, email }) => {
57
- return this.client.post("/repository/addUser", {
58
- domain: repository,
59
- email,
60
- author: ManageV2StaticAuthor
61
- });
62
- }));
63
- /**
64
- * The function `removeUserFromRepository` removes a user corresponding to the
65
- * email from the given repository
66
- *
67
- * @param repository - The Repository name
68
- * @param email - The user email
69
- */
70
- __publicField(this, "removeUserFromRepository", this.assertTokenExist(({ repository, email }) => {
71
- return this.client.post("/repository/removeUser", {
72
- domain: repository,
73
- email,
74
- author: ManageV2StaticAuthor
75
- });
76
- }));
77
- this.token = config ? this.generateToken(config) : null;
78
- this.client = axios.create({
79
- baseURL: `${baseUrl}/manageroutes/`,
80
- withCredentials: true,
81
- validateStatus: () => true,
82
- headers: {
83
- "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
84
- Authorization: `Bearer ${this.token}`
85
- }
86
- });
87
- this.client.interceptors.response.use((response) => {
88
- const cookies = response.headers["set-cookie"];
89
- if (cookies && extractCookie(cookies, "SESSION")) {
90
- this.client.defaults.headers["Cookie"] = cookies;
91
- }
92
- return response;
93
- });
94
- }
95
- /**
96
- * The function generates a JWT token using the provided configuration
97
- * parameters.
98
- *
99
- * @param {ManageV2Config} config - The `config` parameter in the
100
- * `generateToken` function is of type `ManageV2Config`. It contains the
101
- * following properties:
102
- *
103
- * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
104
- * function. The token is signed using the provided `config.secret` with the
105
- * HS256 algorithm and includes the specified audience and issuer values.
106
- */
107
- generateToken(config) {
108
- return jwt.sign({}, config.secret, {
109
- algorithm: "HS256",
110
- audience: config.audience,
111
- issuer: "prismic.io"
112
- });
113
- }
114
- /**
115
- * The function `assertTokenExist` checks if a token exists before executing a
116
- * given function.
117
- *
118
- * @param f - The `assertTokenExist` function takes a function `f` as a
119
- * parameter. This function `f` should accept a parameter of type
120
- * `Parameters` and return a Promise that resolves to an AxiosResponse. The
121
- * `assertTokenExist` function ensures that a token is not null before
122
- * calling the provided
123
- *
124
- * @returns A function is being returned that takes a parameter of type
125
- * Parameters and checks if the token is null. If the token is null, an
126
- * error is thrown. Otherwise, the function f is called with the provided
127
- * parameters.
128
- */
129
- assertTokenExist(f) {
130
- return (params) => {
131
- if (this.token === null) {
132
- throw new Error("Undefined configuration for ManageV2 while trying to use it's routes");
133
- } else {
134
- return f(params);
135
- }
136
- };
137
- }
138
- getBaseURL() {
139
- return this.client.getUri();
140
- }
141
- }
142
- export {
143
- ManageV2Client
144
- };
145
- //# sourceMappingURL=manageV2.js.map
@@ -1 +0,0 @@
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,SAAS;AAAA,QACT,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CAEF;AAUF;AAAA;AAAA;AAAA;AAAA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GAA4C;AAE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MACf;AAAA,IAAA;AAAA,EAEH;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAiFA;"}
@@ -1,178 +0,0 @@
1
- import axios, { AxiosInstance, AxiosResponse } from "axios";
2
- import jwt from "jsonwebtoken";
3
-
4
- import { ManageV2Config } from "../types";
5
-
6
- import { extractCookie } from "../utils/cookies";
7
-
8
- const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
9
-
10
- /**
11
- * Client for interacting with ManageV2 routes to perform operations on
12
- * repositories.
13
- */
14
- export class ManageV2Client {
15
- readonly client: AxiosInstance; // Not private to have it available on tests
16
- private token: string | null = null;
17
-
18
- /**
19
- * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
20
- * @param config - ManageV2 configuration variable to call ManageV2.
21
- */
22
- constructor(baseUrl: string, config?: ManageV2Config | undefined) {
23
- this.token = config ? this.generateToken(config) : null;
24
-
25
- this.client = axios.create({
26
- baseURL: `${baseUrl}/manageroutes/`,
27
- withCredentials: true,
28
- validateStatus: () => true,
29
- headers: {
30
- "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
31
- Authorization: `Bearer ${this.token}`,
32
- },
33
- });
34
-
35
- // cookies are not forwarded automatically in a non-browser env
36
- this.client.interceptors.response.use((response) => {
37
- const cookies = response.headers["set-cookie"];
38
- if (cookies && extractCookie(cookies, "SESSION")) {
39
- this.client.defaults.headers["Cookie"] = cookies;
40
- }
41
-
42
- return response;
43
- });
44
- }
45
-
46
- /**
47
- * The function generates a JWT token using the provided configuration
48
- * parameters.
49
- *
50
- * @param {ManageV2Config} config - The `config` parameter in the
51
- * `generateToken` function is of type `ManageV2Config`. It contains the
52
- * following properties:
53
- *
54
- * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
55
- * function. The token is signed using the provided `config.secret` with the
56
- * HS256 algorithm and includes the specified audience and issuer values.
57
- */
58
- private generateToken(config: ManageV2Config): string {
59
- return jwt.sign({}, config.secret, {
60
- algorithm: "HS256",
61
- audience: config.audience,
62
- issuer: "prismic.io",
63
- });
64
- }
65
-
66
- /**
67
- * The function `assertTokenExist` checks if a token exists before executing a
68
- * given function.
69
- *
70
- * @param f - The `assertTokenExist` function takes a function `f` as a
71
- * parameter. This function `f` should accept a parameter of type
72
- * `Parameters` and return a Promise that resolves to an AxiosResponse. The
73
- * `assertTokenExist` function ensures that a token is not null before
74
- * calling the provided
75
- *
76
- * @returns A function is being returned that takes a parameter of type
77
- * Parameters and checks if the token is null. If the token is null, an
78
- * error is thrown. Otherwise, the function f is called with the provided
79
- * parameters.
80
- */
81
- private assertTokenExist<Parameters>(
82
- f: (_: Parameters) => Promise<AxiosResponse>,
83
- ) {
84
- return (params: Parameters) => {
85
- if (this.token === null) {
86
- throw new Error(
87
- "Undefined configuration for ManageV2 while trying to use it's routes",
88
- );
89
- } else {
90
- return f(params);
91
- }
92
- };
93
- }
94
-
95
- getBaseURL(): string {
96
- return this.client.getUri();
97
- }
98
-
99
- /**
100
- * The function `toggleRolePerLocal` enable or disable the role per local
101
- * feature
102
- *
103
- * @param repository - The Repository name
104
- * @param enabled - The feature new status
105
- */
106
- toggleRolePerLocal = this.assertTokenExist(
107
- (params: { repository: string; enabled: boolean }) => {
108
- return this.client.post("/repository/toggleRolesPerLocale", {
109
- domain: params.repository,
110
- enabled: params.enabled,
111
- author: ManageV2StaticAuthor,
112
- });
113
- },
114
- );
115
-
116
- /**
117
- * The function `changePlan` changes the plan of a repository the database
118
- *
119
- * @param repository - The Repository name
120
- * @param newPlanId - The new planId
121
- * @param bypassManualBilling - Beware that using this will not verify that
122
- * the database and Stripe are in sync
123
- */
124
- changePlan = this.assertTokenExist(
125
- ({
126
- repository,
127
- newPlanId,
128
- bypassManualBilling = false,
129
- }: {
130
- repository: string;
131
- newPlanId: string;
132
- bypassManualBilling?: boolean;
133
- }) => {
134
- return this.client.post(
135
- `/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,
136
- {
137
- domain: repository,
138
- newPlan: newPlanId,
139
- author: ManageV2StaticAuthor,
140
- },
141
- );
142
- },
143
- );
144
-
145
- /**
146
- * The function `addUserToRepository` adds a user corresponding to the email
147
- * to the given repository
148
- *
149
- * @param repository - The Repository name
150
- * @param email - The user email
151
- */
152
- addUserToRepository = this.assertTokenExist(
153
- ({ repository, email }: { repository: string; email: string }) => {
154
- return this.client.post("/repository/addUser", {
155
- domain: repository,
156
- email: email,
157
- author: ManageV2StaticAuthor,
158
- });
159
- },
160
- );
161
-
162
- /**
163
- * The function `removeUserFromRepository` removes a user corresponding to the
164
- * email from the given repository
165
- *
166
- * @param repository - The Repository name
167
- * @param email - The user email
168
- */
169
- removeUserFromRepository = this.assertTokenExist(
170
- ({ repository, email }: { repository: string; email: string }) => {
171
- return this.client.post("/repository/removeUser", {
172
- domain: repository,
173
- email: email,
174
- author: ManageV2StaticAuthor,
175
- });
176
- },
177
- );
178
- }