@prismicio/e2e-tests-utils 1.18.0-canary.933a809 → 1.18.0-canary.a65987f
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/authenticationApi.cjs +14 -0
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.cts.map +1 -1
- package/dist/clients/authenticationApi.d.ts.map +1 -1
- package/dist/clients/authenticationApi.js +14 -0
- package/dist/clients/authenticationApi.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/authenticationApi.ts +30 -1
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
const require_log = require("../utils/log.cjs");
|
|
2
2
|
let _playwright_test = require("@playwright/test");
|
|
3
3
|
//#region src/clients/authenticationApi.ts
|
|
4
|
+
const AUTH_API_TOKENS_ENV = "PRISMIC_E2E_TEST_UTILS_AUTH_API_TOKENS";
|
|
5
|
+
function getAuthApiTokenFromEnv(email) {
|
|
6
|
+
const value = process.env[AUTH_API_TOKENS_ENV];
|
|
7
|
+
if (!value) return;
|
|
8
|
+
for (const entry of value.split(",")) {
|
|
9
|
+
const separatorIndex = entry.indexOf(":");
|
|
10
|
+
if (separatorIndex === -1) continue;
|
|
11
|
+
const entryEmail = entry.slice(0, separatorIndex).trim();
|
|
12
|
+
const token = entry.slice(separatorIndex + 1).trim();
|
|
13
|
+
if (entryEmail === email && token) return token;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
/** Client for interacting with the authentication service to manage tokens */
|
|
5
17
|
var AuthenticationApiClient = class {
|
|
6
18
|
baseURL;
|
|
@@ -10,6 +22,8 @@ var AuthenticationApiClient = class {
|
|
|
10
22
|
constructor(baseURL, auth) {
|
|
11
23
|
this.baseURL = baseURL;
|
|
12
24
|
this.auth = auth;
|
|
25
|
+
this.authToken = getAuthApiTokenFromEnv(auth.email);
|
|
26
|
+
if (this.authToken) require_log.logger.info(`using user token for ${auth.email} from ${AUTH_API_TOKENS_ENV}`);
|
|
13
27
|
}
|
|
14
28
|
async getContext() {
|
|
15
29
|
if (!this._context) this._context = await _playwright_test.request.newContext({ baseURL: this.baseURL });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.cjs","names":["request","logger"],"sources":["../../src/clients/authenticationApi.ts"],"sourcesContent":["import type { APIRequestContext } from \"@playwright/test\"\nimport { request } from \"@playwright/test\"\n\nimport type { AuthConfig } from \"../types\"\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(\"Machine2Machine token generation failed, no token received.\")\n\t\t}\n\t\tconst token = (await result.json()).token\n\n\t\treturn token\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"authenticationApi.cjs","names":["request","logger"],"sources":["../../src/clients/authenticationApi.ts"],"sourcesContent":["import type { APIRequestContext } from \"@playwright/test\"\nimport { request } from \"@playwright/test\"\n\nimport type { AuthConfig } from \"../types\"\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\"\n\nconst AUTH_API_TOKENS_ENV = \"PRISMIC_E2E_TEST_UTILS_AUTH_API_TOKENS\"\n\nfunction getAuthApiTokenFromEnv(email: string): string | undefined {\n\tconst value = process.env[AUTH_API_TOKENS_ENV]\n\tif (!value) {\n\t\treturn undefined\n\t}\n\n\tfor (const entry of value.split(\",\")) {\n\t\tconst separatorIndex = entry.indexOf(\":\")\n\t\tif (separatorIndex === -1) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst entryEmail = entry.slice(0, separatorIndex).trim()\n\t\tconst token = entry.slice(separatorIndex + 1).trim()\n\t\tif (entryEmail === email && token) {\n\t\t\treturn token\n\t\t}\n\t}\n\n\treturn undefined\n}\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\t\tthis.authToken = getAuthApiTokenFromEnv(auth.email)\n\t\tif (this.authToken) {\n\t\t\tlogger.info(`using user token for ${auth.email} from ${AUTH_API_TOKENS_ENV}`)\n\t\t}\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(\"Machine2Machine token generation failed, no token received.\")\n\t\t}\n\t\tconst token = (await result.json()).token\n\n\t\treturn token\n\t}\n}\n"],"mappings":";;;AAMA,MAAM,sBAAsB;AAE5B,SAAS,uBAAuB,OAAmC;CAClE,MAAM,QAAQ,QAAQ,IAAI;CAC1B,IAAI,CAAC,OACJ;CAGD,KAAK,MAAM,SAAS,MAAM,MAAM,GAAG,GAAG;EACrC,MAAM,iBAAiB,MAAM,QAAQ,GAAG;EACxC,IAAI,mBAAmB,IACtB;EAGD,MAAM,aAAa,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,KAAK;EACvD,MAAM,QAAQ,MAAM,MAAM,iBAAiB,CAAC,CAAC,CAAC,KAAK;EACnD,IAAI,eAAe,SAAS,OAC3B,OAAO;CAET;AAGD;;AAGA,IAAa,0BAAb,MAAqC;CAKlB;CACA;CALlB;CACA;CAEA,YACC,SACA,MACC;EAFgB,KAAA,UAAA;EACA,KAAA,OAAA;EAEjB,KAAK,YAAY,uBAAuB,KAAK,KAAK;EAClD,IAAI,KAAK,WACR,YAAA,OAAO,KAAK,wBAAwB,KAAK,MAAM,QAAQ,qBAAqB;CAE9E;CAEA,MAAc,aAAyC;EACtD,IAAI,CAAC,KAAK,UACT,KAAK,WAAW,MAAMA,iBAAAA,QAAQ,WAAW,EACxC,SAAS,KAAK,QACf,CAAC;EAGF,OAAO,KAAK;CACb;CAEA,MAAc,QAAyB;EACtC,MAAM,WAAWC,YAAAA,OAAO,WAAW;EAGnC,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,KAAK,SAAS,EAC1C,MAAM;GACL,OAAO,KAAK,KAAK;GACjB,UAAU,KAAK,KAAK;EACrB,EACD,CAAC;EAED,MAAM,QAAQ,MAAM,OAAO,KAAK;EAChC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO;GAC3B,YAAA,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,2CAA2C;EAC5D;EAEA,SAAS,KAAK,EACb,SAAS,4BAA4B,KAAK,KAAK,MAAM,oBACtD,CAAC;EAED,OAAO;CACR;;CAGA,MAAM,WAA4B;EACjC,IAAI,CAAC,KAAK,WACT,KAAK,YAAY,MAAM,KAAK,MAAM;EAGnC,OAAO,KAAK;CACb;;CAGA,MAAM,wBAAwB,YAAqC;EAClE,IAAI,CAAC,KAAK,WACT,KAAK,YAAY,MAAM,KAAK,MAAM;EAInC,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,IAAI,mBAAmB,EACnD,SAAS;GACR,eAAe,UAAU,KAAK;GAC9B;EACD,EACD,CAAC;EAED,IAAI,CAAC,OAAO,GAAG,GAAG;GACjB,YAAA,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,6DAA6D;EAC9E;EAGA,QAFe,MAAM,OAAO,KAAK,EAAA,CAAG;CAGrC;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.d.cts","names":[],"sources":["../../src/clients/authenticationApi.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"authenticationApi.d.cts","names":[],"sources":["../../src/clients/authenticationApi.ts"],"mappings":";;;;cA+Ba,uBAAA;EAAA,iBAKM,OAAA;EAAA,iBACA,IAAA;EAAA,QALV,SAAA;EAAA,QACA,QAAA;cAGU,OAAA,UACA,IAAA,EAAM,UAAA;EAAA,QAQV,UAAA;EAAA,QAUA,KAAA;EAkC4C;EATpD,QAAA,IAAY,OAAA;EA3CA;EAoDZ,uBAAA,CAAwB,UAAA,WAAqB,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.d.ts","names":[],"sources":["../../src/clients/authenticationApi.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"authenticationApi.d.ts","names":[],"sources":["../../src/clients/authenticationApi.ts"],"mappings":";;;;cA+Ba,uBAAA;EAAA,iBAKM,OAAA;EAAA,iBACA,IAAA;EAAA,QALV,SAAA;EAAA,QACA,QAAA;cAGU,OAAA,UACA,IAAA,EAAM,UAAA;EAAA,QAQV,UAAA;EAAA,QAUA,KAAA;EAkC4C;EATpD,QAAA,IAAY,OAAA;EA3CA;EAoDZ,uBAAA,CAAwB,UAAA,WAAqB,OAAA;AAAA"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { logPlaywrightApiResponse, logger } from "../utils/log.js";
|
|
2
2
|
import { request } from "@playwright/test";
|
|
3
3
|
//#region src/clients/authenticationApi.ts
|
|
4
|
+
const AUTH_API_TOKENS_ENV = "PRISMIC_E2E_TEST_UTILS_AUTH_API_TOKENS";
|
|
5
|
+
function getAuthApiTokenFromEnv(email) {
|
|
6
|
+
const value = process.env[AUTH_API_TOKENS_ENV];
|
|
7
|
+
if (!value) return;
|
|
8
|
+
for (const entry of value.split(",")) {
|
|
9
|
+
const separatorIndex = entry.indexOf(":");
|
|
10
|
+
if (separatorIndex === -1) continue;
|
|
11
|
+
const entryEmail = entry.slice(0, separatorIndex).trim();
|
|
12
|
+
const token = entry.slice(separatorIndex + 1).trim();
|
|
13
|
+
if (entryEmail === email && token) return token;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
/** Client for interacting with the authentication service to manage tokens */
|
|
5
17
|
var AuthenticationApiClient = class {
|
|
6
18
|
baseURL;
|
|
@@ -10,6 +22,8 @@ var AuthenticationApiClient = class {
|
|
|
10
22
|
constructor(baseURL, auth) {
|
|
11
23
|
this.baseURL = baseURL;
|
|
12
24
|
this.auth = auth;
|
|
25
|
+
this.authToken = getAuthApiTokenFromEnv(auth.email);
|
|
26
|
+
if (this.authToken) logger.info(`using user token for ${auth.email} from ${AUTH_API_TOKENS_ENV}`);
|
|
13
27
|
}
|
|
14
28
|
async getContext() {
|
|
15
29
|
if (!this._context) this._context = await request.newContext({ baseURL: this.baseURL });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.js","names":[],"sources":["../../src/clients/authenticationApi.ts"],"sourcesContent":["import type { APIRequestContext } from \"@playwright/test\"\nimport { request } from \"@playwright/test\"\n\nimport type { AuthConfig } from \"../types\"\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(\"Machine2Machine token generation failed, no token received.\")\n\t\t}\n\t\tconst token = (await result.json()).token\n\n\t\treturn token\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"authenticationApi.js","names":[],"sources":["../../src/clients/authenticationApi.ts"],"sourcesContent":["import type { APIRequestContext } from \"@playwright/test\"\nimport { request } from \"@playwright/test\"\n\nimport type { AuthConfig } from \"../types\"\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\"\n\nconst AUTH_API_TOKENS_ENV = \"PRISMIC_E2E_TEST_UTILS_AUTH_API_TOKENS\"\n\nfunction getAuthApiTokenFromEnv(email: string): string | undefined {\n\tconst value = process.env[AUTH_API_TOKENS_ENV]\n\tif (!value) {\n\t\treturn undefined\n\t}\n\n\tfor (const entry of value.split(\",\")) {\n\t\tconst separatorIndex = entry.indexOf(\":\")\n\t\tif (separatorIndex === -1) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst entryEmail = entry.slice(0, separatorIndex).trim()\n\t\tconst token = entry.slice(separatorIndex + 1).trim()\n\t\tif (entryEmail === email && token) {\n\t\t\treturn token\n\t\t}\n\t}\n\n\treturn undefined\n}\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\t\tthis.authToken = getAuthApiTokenFromEnv(auth.email)\n\t\tif (this.authToken) {\n\t\t\tlogger.info(`using user token for ${auth.email} from ${AUTH_API_TOKENS_ENV}`)\n\t\t}\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(\"Machine2Machine token generation failed, no token received.\")\n\t\t}\n\t\tconst token = (await result.json()).token\n\n\t\treturn token\n\t}\n}\n"],"mappings":";;;AAMA,MAAM,sBAAsB;AAE5B,SAAS,uBAAuB,OAAmC;CAClE,MAAM,QAAQ,QAAQ,IAAI;CAC1B,IAAI,CAAC,OACJ;CAGD,KAAK,MAAM,SAAS,MAAM,MAAM,GAAG,GAAG;EACrC,MAAM,iBAAiB,MAAM,QAAQ,GAAG;EACxC,IAAI,mBAAmB,IACtB;EAGD,MAAM,aAAa,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,KAAK;EACvD,MAAM,QAAQ,MAAM,MAAM,iBAAiB,CAAC,CAAC,CAAC,KAAK;EACnD,IAAI,eAAe,SAAS,OAC3B,OAAO;CAET;AAGD;;AAGA,IAAa,0BAAb,MAAqC;CAKlB;CACA;CALlB;CACA;CAEA,YACC,SACA,MACC;EAFgB,KAAA,UAAA;EACA,KAAA,OAAA;EAEjB,KAAK,YAAY,uBAAuB,KAAK,KAAK;EAClD,IAAI,KAAK,WACR,OAAO,KAAK,wBAAwB,KAAK,MAAM,QAAQ,qBAAqB;CAE9E;CAEA,MAAc,aAAyC;EACtD,IAAI,CAAC,KAAK,UACT,KAAK,WAAW,MAAM,QAAQ,WAAW,EACxC,SAAS,KAAK,QACf,CAAC;EAGF,OAAO,KAAK;CACb;CAEA,MAAc,QAAyB;EACtC,MAAM,WAAW,OAAO,WAAW;EAGnC,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,KAAK,SAAS,EAC1C,MAAM;GACL,OAAO,KAAK,KAAK;GACjB,UAAU,KAAK,KAAK;EACrB,EACD,CAAC;EAED,MAAM,QAAQ,MAAM,OAAO,KAAK;EAChC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO;GAC3B,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,2CAA2C;EAC5D;EAEA,SAAS,KAAK,EACb,SAAS,4BAA4B,KAAK,KAAK,MAAM,oBACtD,CAAC;EAED,OAAO;CACR;;CAGA,MAAM,WAA4B;EACjC,IAAI,CAAC,KAAK,WACT,KAAK,YAAY,MAAM,KAAK,MAAM;EAGnC,OAAO,KAAK;CACb;;CAGA,MAAM,wBAAwB,YAAqC;EAClE,IAAI,CAAC,KAAK,WACT,KAAK,YAAY,MAAM,KAAK,MAAM;EAInC,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,IAAI,mBAAmB,EACnD,SAAS;GACR,eAAe,UAAU,KAAK;GAC9B;EACD,EACD,CAAC;EAED,IAAI,CAAC,OAAO,GAAG,GAAG;GACjB,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,6DAA6D;EAC9E;EAGA,QAFe,MAAM,OAAO,KAAK,EAAA,CAAG;CAGrC;AACD"}
|
package/package.json
CHANGED
|
@@ -4,6 +4,30 @@ import { request } from "@playwright/test"
|
|
|
4
4
|
import type { AuthConfig } from "../types"
|
|
5
5
|
import { logPlaywrightApiResponse, logger } from "../utils/log"
|
|
6
6
|
|
|
7
|
+
const AUTH_API_TOKENS_ENV = "PRISMIC_E2E_TEST_UTILS_AUTH_API_TOKENS"
|
|
8
|
+
|
|
9
|
+
function getAuthApiTokenFromEnv(email: string): string | undefined {
|
|
10
|
+
const value = process.env[AUTH_API_TOKENS_ENV]
|
|
11
|
+
if (!value) {
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const entry of value.split(",")) {
|
|
16
|
+
const separatorIndex = entry.indexOf(":")
|
|
17
|
+
if (separatorIndex === -1) {
|
|
18
|
+
continue
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const entryEmail = entry.slice(0, separatorIndex).trim()
|
|
22
|
+
const token = entry.slice(separatorIndex + 1).trim()
|
|
23
|
+
if (entryEmail === email && token) {
|
|
24
|
+
return token
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
/** Client for interacting with the authentication service to manage tokens */
|
|
8
32
|
export class AuthenticationApiClient {
|
|
9
33
|
private authToken?: string
|
|
@@ -12,7 +36,12 @@ export class AuthenticationApiClient {
|
|
|
12
36
|
constructor(
|
|
13
37
|
private readonly baseURL: string,
|
|
14
38
|
private readonly auth: AuthConfig,
|
|
15
|
-
) {
|
|
39
|
+
) {
|
|
40
|
+
this.authToken = getAuthApiTokenFromEnv(auth.email)
|
|
41
|
+
if (this.authToken) {
|
|
42
|
+
logger.info(`using user token for ${auth.email} from ${AUTH_API_TOKENS_ENV}`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
16
45
|
|
|
17
46
|
private async getContext(): Promise<APIRequestContext> {
|
|
18
47
|
if (!this._context) {
|