@prismicio/e2e-tests-utils 2.0.0-alpha.2 → 2.0.0-alpha.5
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 +4 -1
- package/dist/clients/apiClient.cjs.map +1 -1
- package/dist/clients/apiClient.js +4 -1
- package/dist/clients/apiClient.js.map +1 -1
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.ts +1 -0
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/authenticationApi.cjs +7 -11
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.js +7 -11
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +4 -1
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.js +4 -1
- 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 +22 -6
- package/dist/clients/manageV2.cjs.map +1 -1
- package/dist/clients/manageV2.d.ts +16 -6
- package/dist/clients/manageV2.js +22 -6
- 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 +14 -17
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.ts +6 -6
- package/dist/clients/wroom.js +14 -17
- package/dist/clients/wroom.js.map +1 -1
- package/dist/managers/repositories.cjs +5 -2
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.js +5 -2
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +30 -9
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +14 -8
- package/dist/managers/repository.js +30 -9
- package/dist/managers/repository.js.map +1 -1
- package/dist/utils/authentication.cjs +37 -0
- package/dist/utils/authentication.cjs.map +1 -0
- package/dist/utils/authentication.d.ts +4 -0
- package/dist/utils/authentication.js +37 -0
- package/dist/utils/authentication.js.map +1 -0
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/envVariableManager.cjs +4 -1
- package/dist/utils/envVariableManager.cjs.map +1 -1
- package/dist/utils/envVariableManager.js +4 -1
- 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 +1 -1
- package/src/clients/authenticationApi.ts +7 -10
- package/src/clients/manageV2.ts +21 -5
- package/src/clients/wroom.ts +14 -17
- package/src/managers/repositories.ts +1 -1
- package/src/managers/repository.ts +36 -8
- package/src/utils/authentication.ts +51 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVariableManager.js","sources":["../../../src/utils/envVariableManager.ts"],"sourcesContent":["/**\n * Manage a list of strings within an environment variable. This is useful to\n * share data across different test phases (setup, teardown, test execution) as\n * most test frameworks run these in independent states\n */\nexport class EnvVariableManager {\n\tconstructor(private variableName: string) {}\n\n\t/** add a string and persist it in the environment variable */\n\tadd(value: string): void {\n\t\tconst existingValues = this.getAll();\n\t\texistingValues.push(value);\n\n\t\tthis.setAll(existingValues);\n\t}\n\n\t/** remove a string from the environment variable */\n\tremove(value: string): void {\n\t\tconst existingValues = this.getAll();\n\t\tconst updatedValues = existingValues.filter((item) => item !== value);\n\n\t\tthis.setAll(updatedValues);\n\t}\n\n\t/** return all items stored in the environment variable */\n\tgetAll(): string[] {\n\t\tconst value = process.env[this.variableName] || \"[]\";\n\n\t\treturn JSON.parse(value);\n\t}\n\n\tprivate setAll(values: string[]): void {\n\t\tprocess.env[this.variableName] = JSON.stringify(values);\n\t}\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"envVariableManager.js","sources":["../../../src/utils/envVariableManager.ts"],"sourcesContent":["/**\n * Manage a list of strings within an environment variable. This is useful to\n * share data across different test phases (setup, teardown, test execution) as\n * most test frameworks run these in independent states\n */\nexport class EnvVariableManager {\n\tconstructor(private variableName: string) {}\n\n\t/** add a string and persist it in the environment variable */\n\tadd(value: string): void {\n\t\tconst existingValues = this.getAll();\n\t\texistingValues.push(value);\n\n\t\tthis.setAll(existingValues);\n\t}\n\n\t/** remove a string from the environment variable */\n\tremove(value: string): void {\n\t\tconst existingValues = this.getAll();\n\t\tconst updatedValues = existingValues.filter((item) => item !== value);\n\n\t\tthis.setAll(updatedValues);\n\t}\n\n\t/** return all items stored in the environment variable */\n\tgetAll(): string[] {\n\t\tconst value = process.env[this.variableName] || \"[]\";\n\n\t\treturn JSON.parse(value);\n\t}\n\n\tprivate setAll(values: string[]): void {\n\t\tprocess.env[this.variableName] = JSON.stringify(values);\n\t}\n}\n"],"names":[],"mappings":";;;;;;MAKa,mBAAkB;AAAA,EAC9B,YAAoB,cAAoB;AAApB;AAAA,SAAY,eAAZ;AAAA,EAAuB;AAAA;AAAA,EAG3C,IAAI,OAAa;AACV,UAAA,iBAAiB,KAAK;AAC5B,mBAAe,KAAK,KAAK;AAEzB,SAAK,OAAO,cAAc;AAAA,EAC3B;AAAA;AAAA,EAGA,OAAO,OAAa;AACb,UAAA,iBAAiB,KAAK;AAC5B,UAAM,gBAAgB,eAAe,OAAO,CAAC,SAAS,SAAS,KAAK;AAEpE,SAAK,OAAO,aAAa;AAAA,EAC1B;AAAA;AAAA,EAGA,SAAM;AACL,UAAM,QAAQ,QAAQ,IAAI,KAAK,YAAY,KAAK;AAEzC,WAAA,KAAK,MAAM,KAAK;AAAA,EACxB;AAAA,EAEQ,OAAO,QAAgB;AAC9B,YAAQ,IAAI,KAAK,YAAY,IAAI,KAAK,UAAU,MAAM;AAAA,EACvD;AACA;"}
|
package/dist/utils/log.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.cjs","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { APIResponse } from \"@playwright/test\";\nimport { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { baseURL = \"\", url = \"\" } = response.config;\n\t// make sure the url always shows baseURL + path.\n\t// Depending on how the AxiosInstance was called, the url already contains the baseURL\n\tconst fullUrl = url.startsWith(\"http\") ? url : `${baseURL}/${url}`;\n\n\tlogger.info(\n\t\t`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,\n\t);\n};\n\nexport const logPlaywrightApiResponse = async (\n\tresponse: APIResponse,\n): Promise<void> => {\n\tlogger.info(\n\t\t`Call to ${response.url()} failed, received [${response.status()}] ${JSON.stringify(\n\t\t\tawait response.text(),\n\t\t)}`,\n\t);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":["format","createLogger","transports"],"mappings":";;;AAIa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"log.cjs","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { APIResponse } from \"@playwright/test\";\nimport { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { baseURL = \"\", url = \"\" } = response.config;\n\t// make sure the url always shows baseURL + path.\n\t// Depending on how the AxiosInstance was called, the url already contains the baseURL\n\tconst fullUrl = url.startsWith(\"http\") ? url : `${baseURL}/${url}`;\n\n\tlogger.info(\n\t\t`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,\n\t);\n};\n\nexport const logPlaywrightApiResponse = async (\n\tresponse: APIResponse,\n): Promise<void> => {\n\tlogger.info(\n\t\t`Call to ${response.url()} failed, received [${response.status()}] ${JSON.stringify(\n\t\t\tawait response.text(),\n\t\t)}`,\n\t);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":["format","createLogger","transports"],"mappings":";;;AAIa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,KAAS,IAAA;AACzB,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,SAAS;AAGtC,QAAA,UAAU,IAAI,WAAW,MAAM,IAAI,MAAM,GAAG,OAAO,IAAI,GAAG;AAEzD,SAAA,KACN,WAAW,OAAO,sBAAsB,MAAM,KAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAE3E;AAEa,MAAA,2BAA2B,OACvC,aACkB;AAClB,SAAO,KACN,WAAW,SAAS,IAAK,CAAA,sBAAsB,SAAS,OAAQ,CAAA,KAAK,KAAK,UACzE,MAAM,SAAS,KAAM,CAAA,CACrB,EAAE;AAEL;AAEA,MAAM,EAAE,SAAS,OAAW,IAAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EACnC;AAEO,SAAA;AACR,CAAC;AAEM,MAAM,SAASC,QAAAA,aAAa;AAAA,EAClC,QAAQ,QAAQ,IAAI,gCAAgC,MAAM;AAAA,EAC1D,OAAO,QAAQ,IAAI,mCAAmC,KAAK;AAAA,EAC3D,QAAQ,QAAQ,YAAY;AAAA,EAC5B,YAAY,CAAC,IAAIC,mBAAW,SAAS;AACrC,CAAA;;;;"}
|
package/dist/utils/log.js
CHANGED
package/dist/utils/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { APIResponse } from \"@playwright/test\";\nimport { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { baseURL = \"\", url = \"\" } = response.config;\n\t// make sure the url always shows baseURL + path.\n\t// Depending on how the AxiosInstance was called, the url already contains the baseURL\n\tconst fullUrl = url.startsWith(\"http\") ? url : `${baseURL}/${url}`;\n\n\tlogger.info(\n\t\t`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,\n\t);\n};\n\nexport const logPlaywrightApiResponse = async (\n\tresponse: APIResponse,\n): Promise<void> => {\n\tlogger.info(\n\t\t`Call to ${response.url()} failed, received [${response.status()}] ${JSON.stringify(\n\t\t\tawait response.text(),\n\t\t)}`,\n\t);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":[],"mappings":";AAIa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"log.js","sources":["../../../src/utils/log.ts"],"sourcesContent":["import { APIResponse } from \"@playwright/test\";\nimport { AxiosResponse } from \"axios\";\nimport { createLogger, format, transports } from \"winston\";\n\nexport const logHttpResponse = (response: AxiosResponse): void => {\n\tconst { status, data } = response;\n\tconst { baseURL = \"\", url = \"\" } = response.config;\n\t// make sure the url always shows baseURL + path.\n\t// Depending on how the AxiosInstance was called, the url already contains the baseURL\n\tconst fullUrl = url.startsWith(\"http\") ? url : `${baseURL}/${url}`;\n\n\tlogger.info(\n\t\t`Call to ${fullUrl} failed, received [${status}] ${JSON.stringify(data)}`,\n\t);\n};\n\nexport const logPlaywrightApiResponse = async (\n\tresponse: APIResponse,\n): Promise<void> => {\n\tlogger.info(\n\t\t`Call to ${response.url()} failed, received [${response.status()}] ${JSON.stringify(\n\t\t\tawait response.text(),\n\t\t)}`,\n\t);\n};\n\nconst { combine, printf } = format;\n\nconst customFormat = printf(({ message, durationMs }) => {\n\tconst baseMsg = `[test data] ${message}`;\n\tif (durationMs) {\n\t\treturn `${baseMsg} in ${durationMs}ms`;\n\t}\n\n\treturn baseMsg;\n});\n\nexport const logger = createLogger({\n\tsilent: process.env[\"prismic_e2e_tests_utils_silent\"] === \"true\",\n\tlevel: process.env[\"prismic_e2e_tests_utils_log_level\"] || \"info\",\n\tformat: combine(customFormat),\n\ttransports: [new transports.Console()],\n});\n"],"names":[],"mappings":";AAIa,MAAA,kBAAkB,CAAC,aAAiC;AAC1D,QAAA,EAAE,QAAQ,KAAS,IAAA;AACzB,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,SAAS;AAGtC,QAAA,UAAU,IAAI,WAAW,MAAM,IAAI,MAAM,GAAG,OAAO,IAAI,GAAG;AAEzD,SAAA,KACN,WAAW,OAAO,sBAAsB,MAAM,KAAK,KAAK,UAAU,IAAI,CAAC,EAAE;AAE3E;AAEa,MAAA,2BAA2B,OACvC,aACkB;AAClB,SAAO,KACN,WAAW,SAAS,IAAK,CAAA,sBAAsB,SAAS,OAAQ,CAAA,KAAK,KAAK,UACzE,MAAM,SAAS,KAAM,CAAA,CACrB,EAAE;AAEL;AAEA,MAAM,EAAE,SAAS,OAAW,IAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EACnC;AAEO,SAAA;AACR,CAAC;AAEM,MAAM,SAAS,aAAa;AAAA,EAClC,QAAQ,QAAQ,IAAI,gCAAgC,MAAM;AAAA,EAC1D,OAAO,QAAQ,IAAI,mCAAmC,KAAK;AAAA,EAC3D,QAAQ,QAAQ,YAAY;AAAA,EAC5B,YAAY,CAAC,IAAI,WAAW,SAAS;AACrC,CAAA;"}
|
package/dist/utils/urls.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.cjs","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport function getRepositoryUrl(baseUrl: string, repository: string): string {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n}\n\n/**\n * Prevent issues when building urls using `URL` that contain sub path without\n * trailing slashes.\n *\n * @returns the original url with a trailing slash, if needed.\n */\nexport function appendTrailingSlash(url: string): string {\n\tif (!url.endsWith(\"/\")) {\n\t\treturn url + \"/\";\n\t}\n\n\treturn url;\n}\n"],"names":[],"mappings":";;AAQgB,SAAA,iBAAiB,SAAiB,YAAkB;AAC7D,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI
|
|
1
|
+
{"version":3,"file":"urls.cjs","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport function getRepositoryUrl(baseUrl: string, repository: string): string {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n}\n\n/**\n * Prevent issues when building urls using `URL` that contain sub path without\n * trailing slashes.\n *\n * @returns the original url with a trailing slash, if needed.\n */\nexport function appendTrailingSlash(url: string): string {\n\tif (!url.endsWith(\"/\")) {\n\t\treturn url + \"/\";\n\t}\n\n\treturn url;\n}\n"],"names":[],"mappings":";;AAQgB,SAAA,iBAAiB,SAAiB,YAAkB;AAC7D,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI;AACZ;AAQM,SAAU,oBAAoB,KAAW;AAC9C,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACvB,WAAO,MAAM;AAAA,EACd;AAEO,SAAA;AACR;;;"}
|
package/dist/utils/urls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.js","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport function getRepositoryUrl(baseUrl: string, repository: string): string {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n}\n\n/**\n * Prevent issues when building urls using `URL` that contain sub path without\n * trailing slashes.\n *\n * @returns the original url with a trailing slash, if needed.\n */\nexport function appendTrailingSlash(url: string): string {\n\tif (!url.endsWith(\"/\")) {\n\t\treturn url + \"/\";\n\t}\n\n\treturn url;\n}\n"],"names":[],"mappings":"AAQgB,SAAA,iBAAiB,SAAiB,YAAkB;AAC7D,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI
|
|
1
|
+
{"version":3,"file":"urls.js","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport function getRepositoryUrl(baseUrl: string, repository: string): string {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n}\n\n/**\n * Prevent issues when building urls using `URL` that contain sub path without\n * trailing slashes.\n *\n * @returns the original url with a trailing slash, if needed.\n */\nexport function appendTrailingSlash(url: string): string {\n\tif (!url.endsWith(\"/\")) {\n\t\treturn url + \"/\";\n\t}\n\n\treturn url;\n}\n"],"names":[],"mappings":"AAQgB,SAAA,iBAAiB,SAAiB,YAAkB;AAC7D,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI;AACZ;AAQM,SAAU,oBAAoB,KAAW;AAC9C,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACvB,WAAO,MAAM;AAAA,EACd;AAEO,SAAA;AACR;"}
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { APIRequestContext, request } from "@playwright/test";
|
|
|
2
2
|
|
|
3
3
|
import { AuthConfig } from "../types";
|
|
4
4
|
|
|
5
|
+
import { login as authenticateWithLambda } from "../utils/authentication";
|
|
5
6
|
import { logPlaywrightApiResponse, logger } from "../utils/log";
|
|
6
7
|
|
|
7
8
|
/** Client for interacting with the authentication service to manage tokens */
|
|
@@ -27,17 +28,13 @@ export class AuthenticationApiClient {
|
|
|
27
28
|
private async login(): Promise<string> {
|
|
28
29
|
const profiler = logger.startTimer();
|
|
29
30
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
});
|
|
31
|
+
const { token } = await authenticateWithLambda(
|
|
32
|
+
this.baseURL,
|
|
33
|
+
this.auth.email,
|
|
34
|
+
this.auth.password,
|
|
35
|
+
);
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
if (!result.ok() || !token) {
|
|
40
|
-
logPlaywrightApiResponse(result);
|
|
37
|
+
if (!token) {
|
|
41
38
|
throw new Error("Authentication failed, no token received.");
|
|
42
39
|
}
|
|
43
40
|
|
package/src/clients/manageV2.ts
CHANGED
|
@@ -47,9 +47,8 @@ export class ManageV2Client {
|
|
|
47
47
|
* The function generates a JWT token using the provided configuration
|
|
48
48
|
* parameters.
|
|
49
49
|
*
|
|
50
|
-
* @param
|
|
51
|
-
*
|
|
52
|
-
* following properties:
|
|
50
|
+
* @param config - The `config` parameter in the `generateToken` function is
|
|
51
|
+
* of type `ManageV2Config`. It contains the following properties:
|
|
53
52
|
*
|
|
54
53
|
* @returns A JSON Web Token (JWT) is being returned by the `generateToken`
|
|
55
54
|
* function. The token is signed using the provided `config.secret` with the
|
|
@@ -97,8 +96,8 @@ export class ManageV2Client {
|
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
/**
|
|
100
|
-
* The function `toggleRolePerLocal`
|
|
101
|
-
*
|
|
99
|
+
* The function `toggleRolePerLocal` enables or disables the RolesPerLocale
|
|
100
|
+
* workflow
|
|
102
101
|
*
|
|
103
102
|
* @param repository - The Repository name
|
|
104
103
|
* @param enabled - The feature new status
|
|
@@ -113,6 +112,23 @@ export class ManageV2Client {
|
|
|
113
112
|
},
|
|
114
113
|
);
|
|
115
114
|
|
|
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
|
+
|
|
116
132
|
/**
|
|
117
133
|
* The function `changePlan` changes the plan of a repository the database
|
|
118
134
|
*
|
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";
|
|
5
6
|
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
|
|
101
|
-
* @param
|
|
102
|
-
* @param
|
|
100
|
+
* @param repository - The repository name
|
|
101
|
+
* @param email - The email of the user
|
|
102
|
+
* @param 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
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
120
|
+
* @param repository - The repository name
|
|
121
|
+
* @param email - The email of the user
|
|
122
|
+
* @param rolePerLocal - The role per local object
|
|
123
123
|
*
|
|
124
124
|
* @returns The Axios Reponse
|
|
125
125
|
*/
|
|
@@ -140,17 +140,14 @@ 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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
logHttpResponse(response);
|
|
151
|
-
throw new Error("Could not login to Prismic, check your credentials");
|
|
143
|
+
const { cookies } = await login(
|
|
144
|
+
this.getBaseURL(),
|
|
145
|
+
this.auth.email,
|
|
146
|
+
this.auth.password,
|
|
147
|
+
);
|
|
148
|
+
if (cookies && extractCookie(cookies, "prismic-auth")) {
|
|
149
|
+
this.client.defaults.headers["Cookie"] = cookies;
|
|
152
150
|
}
|
|
153
151
|
this.loggedIn = true;
|
|
154
|
-
profiler.done({ message: "logged in to Prismic" });
|
|
155
152
|
}
|
|
156
153
|
}
|
|
@@ -87,6 +87,10 @@ 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
|
+
}
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
@@ -497,7 +501,7 @@ export class RepositoryManager {
|
|
|
497
501
|
}
|
|
498
502
|
|
|
499
503
|
/**
|
|
500
|
-
* Toggle the Role per
|
|
504
|
+
* Toggle the Role per Locale workflow
|
|
501
505
|
*
|
|
502
506
|
* @param enabled - The feature new status
|
|
503
507
|
*/
|
|
@@ -520,10 +524,34 @@ export class RepositoryManager {
|
|
|
520
524
|
});
|
|
521
525
|
}
|
|
522
526
|
|
|
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
|
+
|
|
523
551
|
/**
|
|
524
552
|
* Change the Repository Plan
|
|
525
553
|
*
|
|
526
|
-
* @param
|
|
554
|
+
* @param newPlanId - The Id of the new Plan to apply
|
|
527
555
|
*/
|
|
528
556
|
async changePlan(newPlanId: string): Promise<void> {
|
|
529
557
|
const profiler = logger.startTimer();
|
|
@@ -543,7 +571,7 @@ export class RepositoryManager {
|
|
|
543
571
|
/**
|
|
544
572
|
* Add a new user to the repository
|
|
545
573
|
*
|
|
546
|
-
* @param
|
|
574
|
+
* @param email - The email of the user
|
|
547
575
|
*/
|
|
548
576
|
async addUser(email: string): Promise<void> {
|
|
549
577
|
const profiler = logger.startTimer();
|
|
@@ -570,7 +598,7 @@ export class RepositoryManager {
|
|
|
570
598
|
/**
|
|
571
599
|
* Remove a user from the repository
|
|
572
600
|
*
|
|
573
|
-
* @param
|
|
601
|
+
* @param email - The email of the user
|
|
574
602
|
*/
|
|
575
603
|
async removeUser(email: string): Promise<void> {
|
|
576
604
|
const profiler = logger.startTimer();
|
|
@@ -592,10 +620,9 @@ export class RepositoryManager {
|
|
|
592
620
|
/**
|
|
593
621
|
* Update the role of a user in a repository
|
|
594
622
|
*
|
|
595
|
-
* @param
|
|
596
|
-
* @param
|
|
597
|
-
*
|
|
598
|
-
* "Writer" }`
|
|
623
|
+
* @param email - The email of the user
|
|
624
|
+
* @param role - The new Role of the user, either a string for basic workflow
|
|
625
|
+
* or an object such as `{ "lang_id": "Writer" }`
|
|
599
626
|
*
|
|
600
627
|
* Example of roles are
|
|
601
628
|
*
|
|
@@ -699,6 +726,7 @@ export type RepositoryConfig = {
|
|
|
699
726
|
customTypes?: CustomType[];
|
|
700
727
|
preview?: Preview;
|
|
701
728
|
rolePerLocal?: boolean;
|
|
729
|
+
customRoles?: boolean;
|
|
702
730
|
};
|
|
703
731
|
|
|
704
732
|
export type Preview = {
|
|
@@ -0,0 +1,51 @@
|
|
|
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<{ access_token: string }>(url, payload, {
|
|
20
|
+
headers: {
|
|
21
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
22
|
+
Authorization:
|
|
23
|
+
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (response.status !== 200) {
|
|
28
|
+
logHttpResponse(response);
|
|
29
|
+
throw new Error("Could not obtain OAuth token, check your credentials");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
profiler.done({ message: "logged in via OAuth" });
|
|
33
|
+
const token = response.data.access_token;
|
|
34
|
+
|
|
35
|
+
return { token, cookies: response.headers["set-cookie"] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function transformUrl(baseUrl: string, subdomainPrefix: string): string {
|
|
39
|
+
try {
|
|
40
|
+
const url = new URL(baseUrl);
|
|
41
|
+
const domainParts = url.hostname.split(".");
|
|
42
|
+
|
|
43
|
+
// Insert the custom subdomain prefix before the existing hostname
|
|
44
|
+
const transformedHostname = `${subdomainPrefix}.${domainParts.join(".")}`;
|
|
45
|
+
|
|
46
|
+
// Construct the new URL with the modified hostname
|
|
47
|
+
return `${url.protocol}//${transformedHostname}`;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new Error(`Invalid URL: ${baseUrl}`);
|
|
50
|
+
}
|
|
51
|
+
}
|