@prismicio/e2e-tests-utils 2.0.0-alpha.10 → 2.0.0-alpha.2
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/dist/clients/apiClient.cjs +1 -4
- package/dist/clients/apiClient.cjs.map +1 -1
- package/dist/clients/apiClient.js +1 -4
- package/dist/clients/apiClient.js.map +1 -1
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.ts +0 -1
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/authenticationApi.cjs +11 -7
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.js +11 -7
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +1 -4
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.js +1 -4
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/manageV2.cjs +6 -22
- package/dist/clients/manageV2.cjs.map +1 -1
- package/dist/clients/manageV2.d.ts +6 -16
- package/dist/clients/manageV2.js +6 -22
- package/dist/clients/manageV2.js.map +1 -1
- package/dist/clients/migrationApi.cjs.map +1 -1
- package/dist/clients/migrationApi.js.map +1 -1
- package/dist/clients/wroom.cjs +17 -14
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.ts +6 -6
- package/dist/clients/wroom.js +17 -14
- package/dist/clients/wroom.js.map +1 -1
- package/dist/managers/repositories.cjs +2 -5
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.js +2 -5
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +9 -30
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +8 -14
- package/dist/managers/repository.js +9 -30
- package/dist/managers/repository.js.map +1 -1
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/envVariableManager.cjs +1 -4
- package/dist/utils/envVariableManager.cjs.map +1 -1
- package/dist/utils/envVariableManager.js +1 -4
- package/dist/utils/envVariableManager.js.map +1 -1
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.js +1 -1
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/urls.cjs.map +1 -1
- package/dist/utils/urls.js.map +1 -1
- package/package.json +2 -3
- package/src/clients/authenticationApi.ts +10 -7
- package/src/clients/manageV2.ts +5 -21
- package/src/clients/wroom.ts +17 -14
- package/src/managers/repositories.ts +1 -1
- package/src/managers/repository.ts +8 -36
- package/dist/utils/authentication.cjs +0 -38
- package/dist/utils/authentication.cjs.map +0 -1
- package/dist/utils/authentication.d.ts +0 -4
- package/dist/utils/authentication.js +0 -38
- package/dist/utils/authentication.js.map +0 -1
- package/src/utils/authentication.ts +0 -58
|
@@ -2,7 +2,6 @@ import { APIRequestContext, request } from "@playwright/test";
|
|
|
2
2
|
|
|
3
3
|
import { AuthConfig } from "../types";
|
|
4
4
|
|
|
5
|
-
import { login as authenticateWithLambda } from "../utils/authentication";
|
|
6
5
|
import { logPlaywrightApiResponse, logger } from "../utils/log";
|
|
7
6
|
|
|
8
7
|
/** Client for interacting with the authentication service to manage tokens */
|
|
@@ -28,13 +27,17 @@ export class AuthenticationApiClient {
|
|
|
28
27
|
private async login(): Promise<string> {
|
|
29
28
|
const profiler = logger.startTimer();
|
|
30
29
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
});
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
const token = await result.text();
|
|
39
|
+
if (!result.ok() || !token) {
|
|
40
|
+
logPlaywrightApiResponse(result);
|
|
38
41
|
throw new Error("Authentication failed, no token received.");
|
|
39
42
|
}
|
|
40
43
|
|
package/src/clients/manageV2.ts
CHANGED
|
@@ -47,8 +47,9 @@ export class ManageV2Client {
|
|
|
47
47
|
* The function generates a JWT token using the provided configuration
|
|
48
48
|
* parameters.
|
|
49
49
|
*
|
|
50
|
-
* @param config - The `config` parameter in the
|
|
51
|
-
* of type `ManageV2Config`. It contains the
|
|
50
|
+
* @param {ManageV2Config} config - The `config` parameter in the
|
|
51
|
+
* `generateToken` function is of type `ManageV2Config`. It contains the
|
|
52
|
+
* following properties:
|
|
52
53
|
*
|
|
53
54
|
* @returns A JSON Web Token (JWT) is being returned by the `generateToken`
|
|
54
55
|
* function. The token is signed using the provided `config.secret` with the
|
|
@@ -96,8 +97,8 @@ export class ManageV2Client {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
/**
|
|
99
|
-
* The function `toggleRolePerLocal`
|
|
100
|
-
*
|
|
100
|
+
* The function `toggleRolePerLocal` enable or disable the role per local
|
|
101
|
+
* feature
|
|
101
102
|
*
|
|
102
103
|
* @param repository - The Repository name
|
|
103
104
|
* @param enabled - The feature new status
|
|
@@ -112,23 +113,6 @@ export class ManageV2Client {
|
|
|
112
113
|
},
|
|
113
114
|
);
|
|
114
115
|
|
|
115
|
-
/**
|
|
116
|
-
* The function `toggleCustomRoles` enables or disables the CustomRoles
|
|
117
|
-
* workflow
|
|
118
|
-
*
|
|
119
|
-
* @param repository - The Repository name
|
|
120
|
-
* @param enabled - The feature new status
|
|
121
|
-
*/
|
|
122
|
-
toggleCustomRoles = this.assertTokenExist(
|
|
123
|
-
(params: { repository: string; enabled: boolean }) => {
|
|
124
|
-
return this.client.post("/repository/toggleCustomRoles", {
|
|
125
|
-
domain: params.repository,
|
|
126
|
-
enabled: params.enabled,
|
|
127
|
-
author: ManageV2StaticAuthor,
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
);
|
|
131
|
-
|
|
132
116
|
/**
|
|
133
117
|
* The function `changePlan` changes the plan of a repository the database
|
|
134
118
|
*
|
package/src/clients/wroom.ts
CHANGED
|
@@ -2,8 +2,8 @@ import axios, { AxiosInstance, AxiosResponse } from "axios";
|
|
|
2
2
|
|
|
3
3
|
import { AuthConfig } from "../types";
|
|
4
4
|
|
|
5
|
-
import { login } from "../utils/authentication";
|
|
6
5
|
import { extractCookie } from "../utils/cookies";
|
|
6
|
+
import { logHttpResponse, logger } from "../utils/log";
|
|
7
7
|
import { getRepositoryUrl } from "../utils/urls";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -97,9 +97,9 @@ export class WroomClient {
|
|
|
97
97
|
/**
|
|
98
98
|
* Update the role of a user in the repository
|
|
99
99
|
*
|
|
100
|
-
* @param repository - The repository name
|
|
101
|
-
* @param email - The email of the user
|
|
102
|
-
* @param role - The new role to be given
|
|
100
|
+
* @param {string} repository - The repository name
|
|
101
|
+
* @param {string} email - The email of the user
|
|
102
|
+
* @param {string} role - The new role to be given
|
|
103
103
|
*
|
|
104
104
|
* @returns The Axios Reponse
|
|
105
105
|
*/
|
|
@@ -117,9 +117,9 @@ export class WroomClient {
|
|
|
117
117
|
/**
|
|
118
118
|
* Update the role of a user in the repository
|
|
119
119
|
*
|
|
120
|
-
* @param repository - The repository name
|
|
121
|
-
* @param email - The email of the user
|
|
122
|
-
* @param rolePerLocal - The role per local object
|
|
120
|
+
* @param {string} repository - The repository name
|
|
121
|
+
* @param {string} email - The email of the user
|
|
122
|
+
* @param {string} rolePerLocal - The role per local object
|
|
123
123
|
*
|
|
124
124
|
* @returns The Axios Reponse
|
|
125
125
|
*/
|
|
@@ -140,14 +140,17 @@ export class WroomClient {
|
|
|
140
140
|
* @throws Error if the login to Wroom fails.
|
|
141
141
|
*/
|
|
142
142
|
private async login(): Promise<void> {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
this.auth.email,
|
|
146
|
-
this.auth.password,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
const profiler = logger.startTimer();
|
|
144
|
+
const response = await this.client.post<string>("/authentication/signin", {
|
|
145
|
+
email: this.auth.email,
|
|
146
|
+
password: this.auth.password,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (response.status !== 200) {
|
|
150
|
+
logHttpResponse(response);
|
|
151
|
+
throw new Error("Could not login to Prismic, check your credentials");
|
|
150
152
|
}
|
|
151
153
|
this.loggedIn = true;
|
|
154
|
+
profiler.done({ message: "logged in to Prismic" });
|
|
152
155
|
}
|
|
153
156
|
}
|
|
@@ -87,10 +87,6 @@ export class RepositoryManager {
|
|
|
87
87
|
if (config.rolePerLocal) {
|
|
88
88
|
await this.toggleRolePerLocal(true);
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
if (config.customRoles) {
|
|
92
|
-
await this.toggleCustomRoles(true);
|
|
93
|
-
}
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
@@ -501,7 +497,7 @@ export class RepositoryManager {
|
|
|
501
497
|
}
|
|
502
498
|
|
|
503
499
|
/**
|
|
504
|
-
* Toggle the Role per
|
|
500
|
+
* Toggle the Role per local feature
|
|
505
501
|
*
|
|
506
502
|
* @param enabled - The feature new status
|
|
507
503
|
*/
|
|
@@ -524,34 +520,10 @@ export class RepositoryManager {
|
|
|
524
520
|
});
|
|
525
521
|
}
|
|
526
522
|
|
|
527
|
-
/**
|
|
528
|
-
* Toggle the Custom Roles workflow
|
|
529
|
-
*
|
|
530
|
-
* @param enabled - The feature new status
|
|
531
|
-
*/
|
|
532
|
-
async toggleCustomRoles(enabled: boolean): Promise<void> {
|
|
533
|
-
const profiler = logger.startTimer();
|
|
534
|
-
|
|
535
|
-
const response = await this.manageV2Client.toggleCustomRoles({
|
|
536
|
-
repository: this.name,
|
|
537
|
-
enabled: enabled,
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
this.failIfNot200(
|
|
541
|
-
response,
|
|
542
|
-
`Could not ${enabled ? "enable" : "disable"} Custom Roles for ${
|
|
543
|
-
this.name
|
|
544
|
-
}`,
|
|
545
|
-
);
|
|
546
|
-
profiler.done({
|
|
547
|
-
message: `Custom Roles ${enabled ? "enabled" : "disabled"}`,
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
|
|
551
523
|
/**
|
|
552
524
|
* Change the Repository Plan
|
|
553
525
|
*
|
|
554
|
-
* @param newPlanId - The Id of the new Plan to apply
|
|
526
|
+
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
555
527
|
*/
|
|
556
528
|
async changePlan(newPlanId: string): Promise<void> {
|
|
557
529
|
const profiler = logger.startTimer();
|
|
@@ -571,7 +543,7 @@ export class RepositoryManager {
|
|
|
571
543
|
/**
|
|
572
544
|
* Add a new user to the repository
|
|
573
545
|
*
|
|
574
|
-
* @param email - The email of the user
|
|
546
|
+
* @param {string} email - The email of the user
|
|
575
547
|
*/
|
|
576
548
|
async addUser(email: string): Promise<void> {
|
|
577
549
|
const profiler = logger.startTimer();
|
|
@@ -598,7 +570,7 @@ export class RepositoryManager {
|
|
|
598
570
|
/**
|
|
599
571
|
* Remove a user from the repository
|
|
600
572
|
*
|
|
601
|
-
* @param email - The email of the user
|
|
573
|
+
* @param {string} email - The email of the user
|
|
602
574
|
*/
|
|
603
575
|
async removeUser(email: string): Promise<void> {
|
|
604
576
|
const profiler = logger.startTimer();
|
|
@@ -620,9 +592,10 @@ export class RepositoryManager {
|
|
|
620
592
|
/**
|
|
621
593
|
* Update the role of a user in a repository
|
|
622
594
|
*
|
|
623
|
-
* @param email - The email of the user
|
|
624
|
-
* @param role - The new Role of the user,
|
|
625
|
-
* or an object such as `{ "lang_id":
|
|
595
|
+
* @param {string} email - The email of the user
|
|
596
|
+
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
597
|
+
* either a string for basic workflow or an object such as `{ "lang_id":
|
|
598
|
+
* "Writer" }`
|
|
626
599
|
*
|
|
627
600
|
* Example of roles are
|
|
628
601
|
*
|
|
@@ -726,7 +699,6 @@ export type RepositoryConfig = {
|
|
|
726
699
|
customTypes?: CustomType[];
|
|
727
700
|
preview?: Preview;
|
|
728
701
|
rolePerLocal?: boolean;
|
|
729
|
-
customRoles?: boolean;
|
|
730
702
|
};
|
|
731
703
|
|
|
732
704
|
export type Preview = {
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const axios = require("axios");
|
|
4
|
-
const log = require("./log.cjs");
|
|
5
|
-
async function login(baseUrl, email, password) {
|
|
6
|
-
const profiler = log.logger.startTimer();
|
|
7
|
-
const payload = {
|
|
8
|
-
email,
|
|
9
|
-
password
|
|
10
|
-
};
|
|
11
|
-
const url = transformUrl(baseUrl, "auth.internal");
|
|
12
|
-
const response = await axios.post(`${url}/login-e2e`, payload, {
|
|
13
|
-
headers: {
|
|
14
|
-
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
15
|
-
Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c"
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
if (response.status !== 200) {
|
|
19
|
-
log.logHttpResponse(response);
|
|
20
|
-
throw new Error("Could not obtain OAuth token, check your credentials");
|
|
21
|
-
}
|
|
22
|
-
profiler.done({ message: "logged in via OAuth" });
|
|
23
|
-
const token = response.data.token;
|
|
24
|
-
return { token, cookies: response.headers["set-cookie"] };
|
|
25
|
-
}
|
|
26
|
-
function transformUrl(baseUrl, subdomainPrefix) {
|
|
27
|
-
try {
|
|
28
|
-
const url = new URL(baseUrl);
|
|
29
|
-
const domainParts = url.hostname.split(".");
|
|
30
|
-
const mainDomain = domainParts.slice(-2).join(".");
|
|
31
|
-
const transformedHostname = `${subdomainPrefix}.${mainDomain}`;
|
|
32
|
-
return `${url.protocol}//${transformedHostname}`;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new Error(`Invalid URL: ${baseUrl}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.login = login;
|
|
38
|
-
//# sourceMappingURL=authentication.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.cjs","sources":["../../../src/utils/authentication.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport { logHttpResponse, logger } from \"./log\";\n\nexport async function login(\n\tbaseUrl: string,\n\temail: string,\n\tpassword: string,\n): Promise<{ token: string; cookies: string[] | undefined }> {\n\tconst profiler = logger.startTimer();\n\n\tconst payload = {\n\t\temail,\n\t\tpassword,\n\t};\n\n\tconst url = transformUrl(baseUrl, \"auth.internal\");\n\n\tconst response = await axios.post<{ token: string }>(\n\t\t`${url}/login-e2e`,\n\t\tpayload,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization:\n\t\t\t\t\t\"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c\",\n\t\t\t},\n\t\t},\n\t);\n\n\tif (response.status !== 200) {\n\t\tlogHttpResponse(response);\n\t\tthrow new Error(\"Could not obtain OAuth token, check your credentials\");\n\t}\n\n\tprofiler.done({ message: \"logged in via OAuth\" });\n\tconst token = response.data.token;\n\n\treturn { token, cookies: response.headers[\"set-cookie\"] };\n}\n\nfunction transformUrl(baseUrl: string, subdomainPrefix: string): string {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\tconst domainParts = url.hostname.split(\".\");\n\n\t\t// Ensure we retain only the main domain (e.g., \"platform-wroom.com\")\n\t\tconst mainDomain = domainParts.slice(-2).join(\".\"); // Keeps last two parts of domain\n\n\t\t// Construct the new hostname with the custom prefix\n\t\tconst transformedHostname = `${subdomainPrefix}.${mainDomain}`;\n\n\t\t// Construct and return the full URL with the new hostname\n\t\treturn `${url.protocol}//${transformedHostname}`;\n\t} catch (error) {\n\t\tthrow new Error(`Invalid URL: ${baseUrl}`);\n\t}\n}\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAIsB,eAAA,MACrB,SACA,OACA,UAAgB;AAEV,QAAA,WAAWA,WAAO;AAExB,QAAM,UAAU;AAAA,IACf;AAAA,IACA;AAAA,EAAA;AAGK,QAAA,MAAM,aAAa,SAAS,eAAe;AAEjD,QAAM,WAAW,MAAM,MAAM,KAC5B,GAAG,GAAG,cACN,SACA;AAAA,IACC,SAAS;AAAA,MACR,cAAc;AAAA,MACd,eACC;AAAA,IACD;AAAA,EAAA,CACD;AAGE,MAAA,SAAS,WAAW,KAAK;AAC5BC,QAAA,gBAAgB,QAAQ;AAClB,UAAA,IAAI,MAAM,sDAAsD;AAAA,EACvE;AAEA,WAAS,KAAK,EAAE,SAAS,sBAAuB,CAAA;AAC1C,QAAA,QAAQ,SAAS,KAAK;AAE5B,SAAO,EAAE,OAAO,SAAS,SAAS,QAAQ,YAAY;AACvD;AAEA,SAAS,aAAa,SAAiB,iBAAuB;AACzD,MAAA;AACG,UAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,UAAM,cAAc,IAAI,SAAS,MAAM,GAAG;AAG1C,UAAM,aAAa,YAAY,MAAM,EAAE,EAAE,KAAK,GAAG;AAGjD,UAAM,sBAAsB,GAAG,eAAe,IAAI,UAAU;AAG5D,WAAO,GAAG,IAAI,QAAQ,KAAK,mBAAmB;AAAA,WACtC,OAAO;AACf,UAAM,IAAI,MAAM,gBAAgB,OAAO,EAAE;AAAA,EAC1C;AACD;;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { logger, logHttpResponse } from "./log.js";
|
|
3
|
-
async function login(baseUrl, email, password) {
|
|
4
|
-
const profiler = logger.startTimer();
|
|
5
|
-
const payload = {
|
|
6
|
-
email,
|
|
7
|
-
password
|
|
8
|
-
};
|
|
9
|
-
const url = transformUrl(baseUrl, "auth.internal");
|
|
10
|
-
const response = await axios.post(`${url}/login-e2e`, payload, {
|
|
11
|
-
headers: {
|
|
12
|
-
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
13
|
-
Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c"
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
if (response.status !== 200) {
|
|
17
|
-
logHttpResponse(response);
|
|
18
|
-
throw new Error("Could not obtain OAuth token, check your credentials");
|
|
19
|
-
}
|
|
20
|
-
profiler.done({ message: "logged in via OAuth" });
|
|
21
|
-
const token = response.data.token;
|
|
22
|
-
return { token, cookies: response.headers["set-cookie"] };
|
|
23
|
-
}
|
|
24
|
-
function transformUrl(baseUrl, subdomainPrefix) {
|
|
25
|
-
try {
|
|
26
|
-
const url = new URL(baseUrl);
|
|
27
|
-
const domainParts = url.hostname.split(".");
|
|
28
|
-
const mainDomain = domainParts.slice(-2).join(".");
|
|
29
|
-
const transformedHostname = `${subdomainPrefix}.${mainDomain}`;
|
|
30
|
-
return `${url.protocol}//${transformedHostname}`;
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw new Error(`Invalid URL: ${baseUrl}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
login
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=authentication.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sources":["../../../src/utils/authentication.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport { logHttpResponse, logger } from \"./log\";\n\nexport async function login(\n\tbaseUrl: string,\n\temail: string,\n\tpassword: string,\n): Promise<{ token: string; cookies: string[] | undefined }> {\n\tconst profiler = logger.startTimer();\n\n\tconst payload = {\n\t\temail,\n\t\tpassword,\n\t};\n\n\tconst url = transformUrl(baseUrl, \"auth.internal\");\n\n\tconst response = await axios.post<{ token: string }>(\n\t\t`${url}/login-e2e`,\n\t\tpayload,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization:\n\t\t\t\t\t\"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c\",\n\t\t\t},\n\t\t},\n\t);\n\n\tif (response.status !== 200) {\n\t\tlogHttpResponse(response);\n\t\tthrow new Error(\"Could not obtain OAuth token, check your credentials\");\n\t}\n\n\tprofiler.done({ message: \"logged in via OAuth\" });\n\tconst token = response.data.token;\n\n\treturn { token, cookies: response.headers[\"set-cookie\"] };\n}\n\nfunction transformUrl(baseUrl: string, subdomainPrefix: string): string {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\tconst domainParts = url.hostname.split(\".\");\n\n\t\t// Ensure we retain only the main domain (e.g., \"platform-wroom.com\")\n\t\tconst mainDomain = domainParts.slice(-2).join(\".\"); // Keeps last two parts of domain\n\n\t\t// Construct the new hostname with the custom prefix\n\t\tconst transformedHostname = `${subdomainPrefix}.${mainDomain}`;\n\n\t\t// Construct and return the full URL with the new hostname\n\t\treturn `${url.protocol}//${transformedHostname}`;\n\t} catch (error) {\n\t\tthrow new Error(`Invalid URL: ${baseUrl}`);\n\t}\n}\n"],"names":[],"mappings":";;AAIsB,eAAA,MACrB,SACA,OACA,UAAgB;AAEV,QAAA,WAAW,OAAO;AAExB,QAAM,UAAU;AAAA,IACf;AAAA,IACA;AAAA,EAAA;AAGK,QAAA,MAAM,aAAa,SAAS,eAAe;AAEjD,QAAM,WAAW,MAAM,MAAM,KAC5B,GAAG,GAAG,cACN,SACA;AAAA,IACC,SAAS;AAAA,MACR,cAAc;AAAA,MACd,eACC;AAAA,IACD;AAAA,EAAA,CACD;AAGE,MAAA,SAAS,WAAW,KAAK;AAC5B,oBAAgB,QAAQ;AAClB,UAAA,IAAI,MAAM,sDAAsD;AAAA,EACvE;AAEA,WAAS,KAAK,EAAE,SAAS,sBAAuB,CAAA;AAC1C,QAAA,QAAQ,SAAS,KAAK;AAE5B,SAAO,EAAE,OAAO,SAAS,SAAS,QAAQ,YAAY;AACvD;AAEA,SAAS,aAAa,SAAiB,iBAAuB;AACzD,MAAA;AACG,UAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,UAAM,cAAc,IAAI,SAAS,MAAM,GAAG;AAG1C,UAAM,aAAa,YAAY,MAAM,EAAE,EAAE,KAAK,GAAG;AAGjD,UAAM,sBAAsB,GAAG,eAAe,IAAI,UAAU;AAG5D,WAAO,GAAG,IAAI,QAAQ,KAAK,mBAAmB;AAAA,WACtC,OAAO;AACf,UAAM,IAAI,MAAM,gBAAgB,OAAO,EAAE;AAAA,EAC1C;AACD;"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
import { logHttpResponse, logger } from "./log";
|
|
4
|
-
|
|
5
|
-
export async function login(
|
|
6
|
-
baseUrl: string,
|
|
7
|
-
email: string,
|
|
8
|
-
password: string,
|
|
9
|
-
): Promise<{ token: string; cookies: string[] | undefined }> {
|
|
10
|
-
const profiler = logger.startTimer();
|
|
11
|
-
|
|
12
|
-
const payload = {
|
|
13
|
-
email,
|
|
14
|
-
password,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const url = transformUrl(baseUrl, "auth.internal");
|
|
18
|
-
|
|
19
|
-
const response = await axios.post<{ token: string }>(
|
|
20
|
-
`${url}/login-e2e`,
|
|
21
|
-
payload,
|
|
22
|
-
{
|
|
23
|
-
headers: {
|
|
24
|
-
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
25
|
-
Authorization:
|
|
26
|
-
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
if (response.status !== 200) {
|
|
32
|
-
logHttpResponse(response);
|
|
33
|
-
throw new Error("Could not obtain OAuth token, check your credentials");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
profiler.done({ message: "logged in via OAuth" });
|
|
37
|
-
const token = response.data.token;
|
|
38
|
-
|
|
39
|
-
return { token, cookies: response.headers["set-cookie"] };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function transformUrl(baseUrl: string, subdomainPrefix: string): string {
|
|
43
|
-
try {
|
|
44
|
-
const url = new URL(baseUrl);
|
|
45
|
-
const domainParts = url.hostname.split(".");
|
|
46
|
-
|
|
47
|
-
// Ensure we retain only the main domain (e.g., "platform-wroom.com")
|
|
48
|
-
const mainDomain = domainParts.slice(-2).join("."); // Keeps last two parts of domain
|
|
49
|
-
|
|
50
|
-
// Construct the new hostname with the custom prefix
|
|
51
|
-
const transformedHostname = `${subdomainPrefix}.${mainDomain}`;
|
|
52
|
-
|
|
53
|
-
// Construct and return the full URL with the new hostname
|
|
54
|
-
return `${url.protocol}//${transformedHostname}`;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
throw new Error(`Invalid URL: ${baseUrl}`);
|
|
57
|
-
}
|
|
58
|
-
}
|