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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/clients/apiClient.cjs +4 -1
  2. package/dist/clients/apiClient.cjs.map +1 -1
  3. package/dist/clients/apiClient.js +4 -1
  4. package/dist/clients/apiClient.js.map +1 -1
  5. package/dist/clients/assetApi.cjs.map +1 -1
  6. package/dist/clients/assetApi.d.ts +1 -0
  7. package/dist/clients/assetApi.js.map +1 -1
  8. package/dist/clients/authenticationApi.cjs +7 -11
  9. package/dist/clients/authenticationApi.cjs.map +1 -1
  10. package/dist/clients/authenticationApi.js +7 -11
  11. package/dist/clients/authenticationApi.js.map +1 -1
  12. package/dist/clients/contentApi.cjs +4 -1
  13. package/dist/clients/contentApi.cjs.map +1 -1
  14. package/dist/clients/contentApi.js +4 -1
  15. package/dist/clients/contentApi.js.map +1 -1
  16. package/dist/clients/coreApi.cjs.map +1 -1
  17. package/dist/clients/coreApi.js.map +1 -1
  18. package/dist/clients/customTypesApi.cjs.map +1 -1
  19. package/dist/clients/customTypesApi.js.map +1 -1
  20. package/dist/clients/manageV2.cjs +22 -6
  21. package/dist/clients/manageV2.cjs.map +1 -1
  22. package/dist/clients/manageV2.d.ts +16 -6
  23. package/dist/clients/manageV2.js +22 -6
  24. package/dist/clients/manageV2.js.map +1 -1
  25. package/dist/clients/migrationApi.cjs.map +1 -1
  26. package/dist/clients/migrationApi.js.map +1 -1
  27. package/dist/clients/wroom.cjs +15 -18
  28. package/dist/clients/wroom.cjs.map +1 -1
  29. package/dist/clients/wroom.d.ts +6 -6
  30. package/dist/clients/wroom.js +15 -18
  31. package/dist/clients/wroom.js.map +1 -1
  32. package/dist/managers/repositories.cjs +5 -2
  33. package/dist/managers/repositories.cjs.map +1 -1
  34. package/dist/managers/repositories.js +5 -2
  35. package/dist/managers/repositories.js.map +1 -1
  36. package/dist/managers/repository.cjs +30 -9
  37. package/dist/managers/repository.cjs.map +1 -1
  38. package/dist/managers/repository.d.ts +14 -8
  39. package/dist/managers/repository.js +30 -9
  40. package/dist/managers/repository.js.map +1 -1
  41. package/dist/utils/authentication.cjs +38 -0
  42. package/dist/utils/authentication.cjs.map +1 -0
  43. package/dist/utils/authentication.d.ts +4 -0
  44. package/dist/utils/authentication.js +38 -0
  45. package/dist/utils/authentication.js.map +1 -0
  46. package/dist/utils/cookies.cjs.map +1 -1
  47. package/dist/utils/cookies.js.map +1 -1
  48. package/dist/utils/envVariableManager.cjs +4 -1
  49. package/dist/utils/envVariableManager.cjs.map +1 -1
  50. package/dist/utils/envVariableManager.js +4 -1
  51. package/dist/utils/envVariableManager.js.map +1 -1
  52. package/dist/utils/log.cjs.map +1 -1
  53. package/dist/utils/log.js +1 -1
  54. package/dist/utils/log.js.map +1 -1
  55. package/dist/utils/urls.cjs.map +1 -1
  56. package/dist/utils/urls.js.map +1 -1
  57. package/package.json +3 -2
  58. package/src/clients/authenticationApi.ts +7 -10
  59. package/src/clients/manageV2.ts +21 -5
  60. package/src/clients/wroom.ts +15 -18
  61. package/src/managers/repositories.ts +1 -1
  62. package/src/managers/repository.ts +36 -8
  63. package/src/utils/authentication.ts +58 -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":";;;MAKa,mBAAkB;AAAA,EAC9B,YAAoB,cAAoB;AAApB;AAAA,SAAY,eAAZ;AAAA,EAAA;AAAA;AAAA,EAGpB,IAAI,OAAa;AACV,UAAA,iBAAiB,KAAK;AAC5B,mBAAe,KAAK,KAAK;AAEzB,SAAK,OAAO,cAAc;AAAA,EAAA;AAAA;AAAA,EAI3B,OAAO,OAAa;AACb,UAAA,iBAAiB,KAAK;AAC5B,UAAM,gBAAgB,eAAe,OAAO,CAAC,SAAS,SAAS,KAAK;AAEpE,SAAK,OAAO,aAAa;AAAA,EAAA;AAAA;AAAA,EAI1B,SAAM;AACL,UAAM,QAAQ,QAAQ,IAAI,KAAK,YAAY,KAAK;AAEzC,WAAA,KAAK,MAAM,KAAK;AAAA,EAAA;AAAA,EAGhB,OAAO,QAAgB;AAC9B,YAAQ,IAAI,KAAK,YAAY,IAAI,KAAK,UAAU,MAAM;AAAA,EAAA;AAEvD;"}
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;"}
@@ -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,KAAA,IAAS;AACzB,QAAM,EAAE,UAAU,IAAI,MAAM,GAAA,IAAO,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,OAAA,CAAQ,KAAK,KAAK,UACzE,MAAM,SAAS,KAAM,CAAA,CACrB,EAAE;AAEL;AAEA,MAAM,EAAE,SAAS,OAAA,IAAWA,QAAA;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EAAA;AAG5B,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,QAAA,WAAW,QAAS,CAAA;AACrC,CAAA;;;;"}
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
@@ -1,4 +1,4 @@
1
- import { format, createLogger, transports } from "winston";
1
+ import { createLogger, transports, format } from "winston";
2
2
  const logHttpResponse = (response) => {
3
3
  const { status, data } = response;
4
4
  const { baseURL = "", url = "" } = response.config;
@@ -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,KAAA,IAAS;AACzB,QAAM,EAAE,UAAU,IAAI,MAAM,GAAA,IAAO,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,OAAA,CAAQ,KAAK,KAAK,UACzE,MAAM,SAAS,KAAM,CAAA,CACrB,EAAE;AAEL;AAEA,MAAM,EAAE,SAAS,OAAA,IAAW;AAE5B,MAAM,eAAe,OAAO,CAAC,EAAE,SAAS,iBAAgB;AACjD,QAAA,UAAU,eAAe,OAAO;AACtC,MAAI,YAAY;AACR,WAAA,GAAG,OAAO,OAAO,UAAU;AAAA,EAAA;AAG5B,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,QAAS,CAAA;AACrC,CAAA;"}
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;"}
@@ -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,SAAQ;AACpB;AAQM,SAAU,oBAAoB,KAAW;AAC9C,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACvB,WAAO,MAAM;AAAA,EAAA;AAGP,SAAA;AACR;;;"}
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;;;"}
@@ -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,SAAQ;AACpB;AAQM,SAAU,oBAAoB,KAAW;AAC9C,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACvB,WAAO,MAAM;AAAA,EAAA;AAGP,SAAA;AACR;"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.10",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -96,5 +96,6 @@
96
96
  },
97
97
  "publishConfig": {
98
98
  "access": "restricted"
99
- }
99
+ },
100
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
100
101
  }
@@ -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 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
- });
31
+ const { token } = await authenticateWithLambda(
32
+ this.baseURL,
33
+ this.auth.email,
34
+ this.auth.password,
35
+ );
37
36
 
38
- const token = await result.text();
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
 
@@ -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 {ManageV2Config} config - The `config` parameter in the
51
- * `generateToken` function is of type `ManageV2Config`. It contains the
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` enable or disable the role per local
101
- * feature
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
  *
@@ -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
  /**
@@ -45,7 +45,7 @@ export class WroomClient {
45
45
  // cookies are not forwarded automatically in a non-browser env
46
46
  this.client.interceptors.response.use((response) => {
47
47
  const cookies = response.headers["set-cookie"];
48
- if (cookies && extractCookie(cookies, "SESSION")) {
48
+ if (cookies && extractCookie(cookies, "prismic-auth")) {
49
49
  this.client.defaults.headers["Cookie"] = cookies;
50
50
  }
51
51
 
@@ -97,9 +97,9 @@ export class WroomClient {
97
97
  /**
98
98
  * Update the role of a user in the repository
99
99
  *
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
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 {string} repository - The repository name
121
- * @param {string} email - The email of the user
122
- * @param {string} rolePerLocal - The role per local object
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 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");
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
  }
@@ -137,7 +137,7 @@ export class RepositoriesManager {
137
137
  "authentication/newrepository",
138
138
  {
139
139
  domain: repositoryName,
140
- framework: "vue",
140
+ framework: "next",
141
141
  plan: "personal",
142
142
  isAnnual: "false",
143
143
  role: "developer",
@@ -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 local feature
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 {string} newPlanId - The Id of the new Plan to apply
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 {string} email - The email of the user
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 {string} email - The email of the user
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 {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" }`
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,58 @@
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
+ }