@prismicio/e2e-tests-utils 1.3.0 → 1.3.1

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 (52) hide show
  1. package/dist/clients/authenticationApi.cjs.map +1 -1
  2. package/dist/clients/authenticationApi.js.map +1 -1
  3. package/dist/clients/contentApi.cjs +141 -0
  4. package/dist/clients/contentApi.cjs.map +1 -0
  5. package/dist/clients/contentApi.d.ts +106 -0
  6. package/dist/clients/contentApi.js +141 -0
  7. package/dist/clients/contentApi.js.map +1 -0
  8. package/dist/clients/coreApi.cjs +12 -2
  9. package/dist/clients/coreApi.cjs.map +1 -1
  10. package/dist/clients/coreApi.d.ts +1 -0
  11. package/dist/clients/coreApi.js +12 -2
  12. package/dist/clients/coreApi.js.map +1 -1
  13. package/dist/clients/customTypesApi.cjs +1 -0
  14. package/dist/clients/customTypesApi.cjs.map +1 -1
  15. package/dist/clients/customTypesApi.js +1 -0
  16. package/dist/clients/customTypesApi.js.map +1 -1
  17. package/dist/clients/manageV2.cjs.map +1 -1
  18. package/dist/clients/manageV2.js.map +1 -1
  19. package/dist/clients/migrationApi.cjs +36 -0
  20. package/dist/clients/migrationApi.cjs.map +1 -0
  21. package/dist/clients/migrationApi.d.ts +20 -0
  22. package/dist/clients/migrationApi.js +36 -0
  23. package/dist/clients/migrationApi.js.map +1 -0
  24. package/dist/clients/wroom.cjs.map +1 -1
  25. package/dist/clients/wroom.js.map +1 -1
  26. package/dist/index.cjs +4 -0
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/managers/repositories.cjs +8 -4
  32. package/dist/managers/repositories.cjs.map +1 -1
  33. package/dist/managers/repositories.js +8 -4
  34. package/dist/managers/repositories.js.map +1 -1
  35. package/dist/managers/repository.cjs +49 -1
  36. package/dist/managers/repository.cjs.map +1 -1
  37. package/dist/managers/repository.d.ts +26 -1
  38. package/dist/managers/repository.js +49 -1
  39. package/dist/managers/repository.js.map +1 -1
  40. package/dist/types.d.ts +2 -0
  41. package/dist/utils/cookies.cjs.map +1 -1
  42. package/dist/utils/cookies.js.map +1 -1
  43. package/dist/utils/log.cjs.map +1 -1
  44. package/dist/utils/log.js.map +1 -1
  45. package/package.json +7 -2
  46. package/src/clients/contentApi.ts +235 -0
  47. package/src/clients/coreApi.ts +14 -1
  48. package/src/clients/migrationApi.ts +69 -0
  49. package/src/index.ts +2 -0
  50. package/src/managers/repositories.ts +9 -2
  51. package/src/managers/repository.ts +67 -0
  52. package/src/types.ts +2 -0
@@ -1 +1 @@
1
- {"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n\tgetMachine2MachineToken: (repository: string) => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: AuthConfig,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(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 ${auth.email} from auth service`,\n\t\t});\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken(): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\t\tconst result = await client.get<{ token: string; timestamp: number }>(\n\t\t\t\"machine2machine\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t\t\t\trepository,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (![200].includes(result.status) || !result.data.token) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\n\t\treturn result.data.token;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t\tgetMachine2MachineToken,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAYa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAWA,WAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpDC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK;AAAA,IAAA,CAC/C;AAED,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAGA,iBAAe,wBAAwB,YAAkB;AACxD,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AACD,UAAM,SAAS,MAAM,OAAO,IAC3B,mBACA;AAAA,MACC,SAAS;AAAA,QACR,eAAe,UAAU,SAAS;AAAA,QAClC;AAAA,MACA;AAAA,IAAA,CACD;AAGE,QAAA,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,KAAK,CAAC,OAAO,KAAK,OAAO;AACzDA,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE9D;AAED,WAAO,OAAO,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
1
+ {"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n\tgetMachine2MachineToken: (repository: string) => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: AuthConfig,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(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 ${auth.email} from auth service`,\n\t\t});\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken(): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\t\tconst result = await client.get<{ token: string; timestamp: number }>(\n\t\t\t\"machine2machine\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t\t\t\trepository,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (![200].includes(result.status) || !result.data.token) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\n\t\treturn result.data.token;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t\tgetMachine2MachineToken,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAYa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAWA,WAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpDC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK;AAAA,IAAA,CAC/C;AAED,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IACnB;AAEO,WAAA;AAAA,EACR;AAGA,iBAAe,wBAAwB,YAAkB;AACxD,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IACnB;AACA,UAAM,SAAS,MAAM,OAAO,IAC3B,mBACA;AAAA,MACC,SAAS;AAAA,QACR,eAAe,UAAU,SAAS;AAAA,QAClC;AAAA,MACA;AAAA,IAAA,CACD;AAGE,QAAA,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,KAAK,CAAC,OAAO,KAAK,OAAO;AACzDA,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE/D;AAEA,WAAO,OAAO,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n\tgetMachine2MachineToken: (repository: string) => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: AuthConfig,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(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 ${auth.email} from auth service`,\n\t\t});\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken(): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\t\tconst result = await client.get<{ token: string; timestamp: number }>(\n\t\t\t\"machine2machine\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t\t\t\trepository,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (![200].includes(result.status) || !result.data.token) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\n\t\treturn result.data.token;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t\tgetMachine2MachineToken,\n\t};\n};\n"],"names":[],"mappings":";;AAYa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAW,OAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK;AAAA,IAAA,CAC/C;AAED,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAGA,iBAAe,wBAAwB,YAAkB;AACxD,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AACD,UAAM,SAAS,MAAM,OAAO,IAC3B,mBACA;AAAA,MACC,SAAS;AAAA,QACR,eAAe,UAAU,SAAS;AAAA,QAClC;AAAA,MACA;AAAA,IAAA,CACD;AAGE,QAAA,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,KAAK,CAAC,OAAO,KAAK,OAAO;AACzD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE9D;AAED,WAAO,OAAO,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n\tgetMachine2MachineToken: (repository: string) => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: AuthConfig,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(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 ${auth.email} from auth service`,\n\t\t});\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken(): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\t\tconst result = await client.get<{ token: string; timestamp: number }>(\n\t\t\t\"machine2machine\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t\t\t\trepository,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (![200].includes(result.status) || !result.data.token) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\n\t\treturn result.data.token;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t\tgetMachine2MachineToken,\n\t};\n};\n"],"names":[],"mappings":";;AAYa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAW,OAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,aAAS,KAAK;AAAA,MACb,SAAS,4BAA4B,KAAK,KAAK;AAAA,IAAA,CAC/C;AAED,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IACnB;AAEO,WAAA;AAAA,EACR;AAGA,iBAAe,wBAAwB,YAAkB;AACxD,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IACnB;AACA,UAAM,SAAS,MAAM,OAAO,IAC3B,mBACA;AAAA,MACC,SAAS;AAAA,QACR,eAAe,UAAU,SAAS;AAAA,QAClC;AAAA,MACA;AAAA,IAAA,CACD;AAGE,QAAA,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,KAAK,CAAC,OAAO,KAAK,OAAO;AACzD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MACT,6DAA6D;AAAA,IAE/D;AAEA,WAAO,OAAO,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => {
5
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ return value;
7
+ };
8
+ var __accessCheck = (obj, member, msg) => {
9
+ if (!member.has(obj))
10
+ throw TypeError("Cannot " + msg);
11
+ };
12
+ var __privateGet = (obj, member, getter) => {
13
+ __accessCheck(obj, member, "read from private field");
14
+ return getter ? getter.call(obj) : member.get(obj);
15
+ };
16
+ var __privateAdd = (obj, member, value) => {
17
+ if (member.has(obj))
18
+ throw TypeError("Cannot add the same private member more than once");
19
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
+ };
21
+ var __privateSet = (obj, member, value, setter) => {
22
+ __accessCheck(obj, member, "write to private field");
23
+ setter ? setter.call(obj, value) : member.set(obj, value);
24
+ return value;
25
+ };
26
+ var __privateMethod = (obj, member, method) => {
27
+ __accessCheck(obj, member, "access private method");
28
+ return method;
29
+ };
30
+ var _version, _accessToken, _context, context_fn;
31
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
32
+ const test = require("@playwright/test");
33
+ class ContentApiClient {
34
+ /**
35
+ * @example To instantiate the class:
36
+ *
37
+ * ```js
38
+ * new ContentApiClient("https://my-repo.cdn.prismic.io", {
39
+ * version: "v2",
40
+ * accessToken: "my-secret-token",
41
+ * });
42
+ * ```
43
+ *
44
+ * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
45
+ * @param config - Optional configuration
46
+ *
47
+ * - {@link config.version}: Api version, default is "v2"
48
+ * - {@link config.accessToken}: Access token for the content api -
49
+ * https://prismic.io/docs/access-token
50
+ */
51
+ constructor(baseURL, config = {}) {
52
+ __privateAdd(this, _context);
53
+ __publicField(this, "baseURL");
54
+ __privateAdd(this, _version, void 0);
55
+ __privateAdd(this, _accessToken, void 0);
56
+ this.baseURL = baseURL;
57
+ __privateSet(this, _version, config.version || "v2");
58
+ __privateSet(this, _accessToken, config.accessToken);
59
+ }
60
+ async get(path, params, headers) {
61
+ const context = await __privateMethod(this, _context, context_fn).call(this);
62
+ const securityParams = {
63
+ ...__privateGet(this, _accessToken) ? { access_token: __privateGet(this, _accessToken) } : {}
64
+ };
65
+ return context.get(path, {
66
+ params: { ...securityParams, ...params },
67
+ headers
68
+ });
69
+ }
70
+ async getAsJson(url, params, headers) {
71
+ const response = await this.get(url, params, headers);
72
+ return response.json();
73
+ }
74
+ /** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
75
+ async graphql(ref, query) {
76
+ return this.getAsJson("/graphql", { query }, { "Prismic-ref": ref });
77
+ }
78
+ async getRefs() {
79
+ const data = await this.getAsJson(`/api/${__privateGet(this, _version)}`);
80
+ return data.refs;
81
+ }
82
+ async getMasterRef() {
83
+ const refs = await this.getRefs();
84
+ const masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);
85
+ if (!masterRef) {
86
+ throw "No master ref found";
87
+ }
88
+ return masterRef.ref;
89
+ }
90
+ async getRefByReleaseID(releaseID) {
91
+ const refs = await this.getRefs();
92
+ const release = refs.find(({ id }) => id === releaseID);
93
+ if (!release) {
94
+ throw `No ref found for release ${releaseID}`;
95
+ }
96
+ return release.ref;
97
+ }
98
+ /** Search documents from the `/api/v<version>/documents/search` endpoint. */
99
+ async search(filters) {
100
+ let ref = filters == null ? void 0 : filters.ref;
101
+ if (!ref) {
102
+ ref = await this.getMasterRef();
103
+ }
104
+ return this.getAsJson(`/api/${__privateGet(this, _version)}/documents/search`, {
105
+ ...filters,
106
+ ref
107
+ });
108
+ }
109
+ /**
110
+ * Search for a single document by its it, using the
111
+ * `/api/v<version>/documents/search` endpoint and a default filter.
112
+ */
113
+ async searchByID(id, filters) {
114
+ return this.search({ ...filters, q: `[[at(document.id, "${id}")]]` });
115
+ }
116
+ /** Retrieve a single document or undefined if not found. */
117
+ async getDocumentByID(id, filters) {
118
+ const data = await this.searchByID(id, filters);
119
+ switch (data.results_size) {
120
+ case 0:
121
+ return;
122
+ case 1:
123
+ return data.results[0];
124
+ default:
125
+ throw new Error(`Too many documents returned with the same id ${id}`);
126
+ }
127
+ }
128
+ }
129
+ _version = new WeakMap();
130
+ _accessToken = new WeakMap();
131
+ _context = new WeakSet();
132
+ context_fn = function() {
133
+ return test.request.newContext({
134
+ baseURL: this.baseURL,
135
+ // reset any Authorization header set globally with Playwright
136
+ // didn't find a way to delete it
137
+ extraHTTPHeaders: { Authorization: "" }
138
+ });
139
+ };
140
+ exports.ContentApiClient = ContentApiClient;
141
+ //# sourceMappingURL=contentApi.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentApi.cjs","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse, request } from \"@playwright/test\";\n\nexport interface ContentApiError {\n\ttype: string;\n\tmessage: string;\n}\nexport interface ContentApiSearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: ContentApiDocument[];\n}\n\nexport interface ContentApiDocument {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface ContentApiGraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface ContentApiRef {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\ninterface ContentApiRepoConfigResponse {\n\trefs: ContentApiRef[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\ntype SearchQueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. The @prismicio/client package could\n * have been used but had too many abstractions (caching, error handling) that\n * we didn't want for test execution. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient {\n\t#version: ApiVersions;\n\t#accessToken: string | undefined;\n\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new ContentApiClient(\"https://my-repo.cdn.prismic.io\", {\n\t * \tversion: \"v2\",\n\t * \taccessToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\tthis.#version = config.version || \"v2\";\n\t\tthis.#accessToken = config.accessToken;\n\t}\n\n\t#context() {\n\t\treturn request.newContext({\n\t\t\tbaseURL: this.baseURL,\n\t\t\t// reset any Authorization header set globally with Playwright\n\t\t\t// didn't find a way to delete it\n\t\t\textraHTTPHeaders: { Authorization: \"\" },\n\t\t});\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.#context();\n\t\tconst securityParams = {\n\t\t\t...(this.#accessToken ? { access_token: this.#accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(\n\t\tref: string,\n\t\tquery: string,\n\t): Promise<ContentApiGraphQLResponse> {\n\t\treturn this.getAsJson<ContentApiGraphQLResponse>(\n\t\t\t\"/graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<ContentApiRef[]> {\n\t\tconst data = await this.getAsJson<ContentApiRepoConfigResponse>(\n\t\t\t`/api/${this.#version}`,\n\t\t);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<ContentApiSearchResponse>(\n\t\t\t`/api/${this.#version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiSearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiDocument | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":["request"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuFa,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB5B,YACkB,SACjB,SAA0D,IAAE;AAM7D;AAPkB;AArBlB;AACA;AAoBkB,SAAO,UAAP;AAGZ,uBAAA,UAAW,OAAO,WAAW;AAClC,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,mBAAK,SAAQ,qBACrB;AAAA,MACC,GAAG;AAAA,MACH;AAAA,IAAA,CACA;AAAA,EAEH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WACL,IACA,SAA2B;AAEpB,WAAA,KAAK,OAAO,EAAE,GAAG,SAAS,GAAG,sBAAsB,EAAE,OAAA,CAAQ;AAAA,EACrE;AAAA;AAAA,EAGA,MAAM,gBACL,IACA,SAA2B;AAE3B,UAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO;AAC9C,YAAQ,KAAK,cAAc;AAAA,MAC1B,KAAK;AACJ;AAAA,MACD,KAAK;AACG,eAAA,KAAK,QAAQ,CAAC;AAAA,MACtB;AACC,cAAM,IAAI,MAAM,gDAAgD,EAAE,EAAE;AAAA,IACtE;AAAA,EACD;AACA;AAlJA;AACA;AA2BA;AAAA,aAAQ,WAAA;AACP,SAAOA,KAAAA,QAAQ,WAAW;AAAA,IACzB,SAAS,KAAK;AAAA;AAAA;AAAA,IAGd,kBAAkB,EAAE,eAAe,GAAI;AAAA,EAAA,CACvC;AACF;;"}
@@ -0,0 +1,106 @@
1
+ import { APIResponse } from "@playwright/test";
2
+ export interface ContentApiError {
3
+ type: string;
4
+ message: string;
5
+ }
6
+ export interface ContentApiSearchResponse {
7
+ page: number;
8
+ results_per_page: number;
9
+ results_size: number;
10
+ total_results_size: number;
11
+ total_pages: number;
12
+ next_page: string | null;
13
+ prev_page: string | null;
14
+ results: ContentApiDocument[];
15
+ }
16
+ export interface ContentApiDocument {
17
+ id: string;
18
+ uid: string | null;
19
+ url: string | null;
20
+ type: string;
21
+ href: string;
22
+ tags: string[];
23
+ first_publication_date: string;
24
+ last_publication_date: string;
25
+ slugs: string[];
26
+ linked_documents: unknown[];
27
+ lang: string;
28
+ alternate_languages: string[];
29
+ data: Record<string, any>;
30
+ }
31
+ export interface ContentApiGraphQLResponse {
32
+ data: Record<string, any>;
33
+ errors?: {
34
+ message: string;
35
+ locations: any;
36
+ }[];
37
+ }
38
+ export interface ContentApiRef {
39
+ id: string;
40
+ ref: string;
41
+ label: string;
42
+ isMasterRef?: boolean;
43
+ }
44
+ type SearchQueryParams = {
45
+ ref?: string;
46
+ query?: string;
47
+ q?: string;
48
+ graphQuery?: string;
49
+ fetchLinks?: string;
50
+ orderings?: string;
51
+ pageSize?: number;
52
+ page?: number;
53
+ lang?: string;
54
+ after?: string;
55
+ routes?: string;
56
+ };
57
+ type ApiVersions = "v1" | "v2";
58
+ /**
59
+ * Client to query the Prismic content api. Uses Playwright to benefit from
60
+ * network request traces in your reports. The @prismicio/client package could
61
+ * have been used but had too many abstractions (caching, error handling) that
62
+ * we didn't want for test execution. See api docs:
63
+ * https://prismic.io/docs/rest-api-technical-reference
64
+ */
65
+ export declare class ContentApiClient {
66
+ #private;
67
+ private readonly baseURL;
68
+ /**
69
+ * @example To instantiate the class:
70
+ *
71
+ * ```js
72
+ * new ContentApiClient("https://my-repo.cdn.prismic.io", {
73
+ * version: "v2",
74
+ * accessToken: "my-secret-token",
75
+ * });
76
+ * ```
77
+ *
78
+ * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
79
+ * @param config - Optional configuration
80
+ *
81
+ * - {@link config.version}: Api version, default is "v2"
82
+ * - {@link config.accessToken}: Access token for the content api -
83
+ * https://prismic.io/docs/access-token
84
+ */
85
+ constructor(baseURL: string, config?: {
86
+ version?: ApiVersions;
87
+ accessToken?: string;
88
+ });
89
+ get(path: string, params?: SearchQueryParams, headers?: Record<string, string>): Promise<APIResponse>;
90
+ getAsJson<T>(url: string, params?: SearchQueryParams, headers?: Record<string, string>): Promise<T>;
91
+ /** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
92
+ graphql(ref: string, query: string): Promise<ContentApiGraphQLResponse>;
93
+ getRefs(): Promise<ContentApiRef[]>;
94
+ getMasterRef(): Promise<string>;
95
+ getRefByReleaseID(releaseID: string): Promise<string>;
96
+ /** Search documents from the `/api/v<version>/documents/search` endpoint. */
97
+ search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse>;
98
+ /**
99
+ * Search for a single document by its it, using the
100
+ * `/api/v<version>/documents/search` endpoint and a default filter.
101
+ */
102
+ searchByID(id: string, filters?: SearchQueryParams): Promise<ContentApiSearchResponse>;
103
+ /** Retrieve a single document or undefined if not found. */
104
+ getDocumentByID(id: string, filters?: SearchQueryParams): Promise<ContentApiDocument | undefined>;
105
+ }
106
+ export {};
@@ -0,0 +1,141 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ var __accessCheck = (obj, member, msg) => {
8
+ if (!member.has(obj))
9
+ throw TypeError("Cannot " + msg);
10
+ };
11
+ var __privateGet = (obj, member, getter) => {
12
+ __accessCheck(obj, member, "read from private field");
13
+ return getter ? getter.call(obj) : member.get(obj);
14
+ };
15
+ var __privateAdd = (obj, member, value) => {
16
+ if (member.has(obj))
17
+ throw TypeError("Cannot add the same private member more than once");
18
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
19
+ };
20
+ var __privateSet = (obj, member, value, setter) => {
21
+ __accessCheck(obj, member, "write to private field");
22
+ setter ? setter.call(obj, value) : member.set(obj, value);
23
+ return value;
24
+ };
25
+ var __privateMethod = (obj, member, method) => {
26
+ __accessCheck(obj, member, "access private method");
27
+ return method;
28
+ };
29
+ var _version, _accessToken, _context, context_fn;
30
+ import { request } from "@playwright/test";
31
+ class ContentApiClient {
32
+ /**
33
+ * @example To instantiate the class:
34
+ *
35
+ * ```js
36
+ * new ContentApiClient("https://my-repo.cdn.prismic.io", {
37
+ * version: "v2",
38
+ * accessToken: "my-secret-token",
39
+ * });
40
+ * ```
41
+ *
42
+ * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
43
+ * @param config - Optional configuration
44
+ *
45
+ * - {@link config.version}: Api version, default is "v2"
46
+ * - {@link config.accessToken}: Access token for the content api -
47
+ * https://prismic.io/docs/access-token
48
+ */
49
+ constructor(baseURL, config = {}) {
50
+ __privateAdd(this, _context);
51
+ __publicField(this, "baseURL");
52
+ __privateAdd(this, _version, void 0);
53
+ __privateAdd(this, _accessToken, void 0);
54
+ this.baseURL = baseURL;
55
+ __privateSet(this, _version, config.version || "v2");
56
+ __privateSet(this, _accessToken, config.accessToken);
57
+ }
58
+ async get(path, params, headers) {
59
+ const context = await __privateMethod(this, _context, context_fn).call(this);
60
+ const securityParams = {
61
+ ...__privateGet(this, _accessToken) ? { access_token: __privateGet(this, _accessToken) } : {}
62
+ };
63
+ return context.get(path, {
64
+ params: { ...securityParams, ...params },
65
+ headers
66
+ });
67
+ }
68
+ async getAsJson(url, params, headers) {
69
+ const response = await this.get(url, params, headers);
70
+ return response.json();
71
+ }
72
+ /** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
73
+ async graphql(ref, query) {
74
+ return this.getAsJson("/graphql", { query }, { "Prismic-ref": ref });
75
+ }
76
+ async getRefs() {
77
+ const data = await this.getAsJson(`/api/${__privateGet(this, _version)}`);
78
+ return data.refs;
79
+ }
80
+ async getMasterRef() {
81
+ const refs = await this.getRefs();
82
+ const masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);
83
+ if (!masterRef) {
84
+ throw "No master ref found";
85
+ }
86
+ return masterRef.ref;
87
+ }
88
+ async getRefByReleaseID(releaseID) {
89
+ const refs = await this.getRefs();
90
+ const release = refs.find(({ id }) => id === releaseID);
91
+ if (!release) {
92
+ throw `No ref found for release ${releaseID}`;
93
+ }
94
+ return release.ref;
95
+ }
96
+ /** Search documents from the `/api/v<version>/documents/search` endpoint. */
97
+ async search(filters) {
98
+ let ref = filters == null ? void 0 : filters.ref;
99
+ if (!ref) {
100
+ ref = await this.getMasterRef();
101
+ }
102
+ return this.getAsJson(`/api/${__privateGet(this, _version)}/documents/search`, {
103
+ ...filters,
104
+ ref
105
+ });
106
+ }
107
+ /**
108
+ * Search for a single document by its it, using the
109
+ * `/api/v<version>/documents/search` endpoint and a default filter.
110
+ */
111
+ async searchByID(id, filters) {
112
+ return this.search({ ...filters, q: `[[at(document.id, "${id}")]]` });
113
+ }
114
+ /** Retrieve a single document or undefined if not found. */
115
+ async getDocumentByID(id, filters) {
116
+ const data = await this.searchByID(id, filters);
117
+ switch (data.results_size) {
118
+ case 0:
119
+ return;
120
+ case 1:
121
+ return data.results[0];
122
+ default:
123
+ throw new Error(`Too many documents returned with the same id ${id}`);
124
+ }
125
+ }
126
+ }
127
+ _version = new WeakMap();
128
+ _accessToken = new WeakMap();
129
+ _context = new WeakSet();
130
+ context_fn = function() {
131
+ return request.newContext({
132
+ baseURL: this.baseURL,
133
+ // reset any Authorization header set globally with Playwright
134
+ // didn't find a way to delete it
135
+ extraHTTPHeaders: { Authorization: "" }
136
+ });
137
+ };
138
+ export {
139
+ ContentApiClient
140
+ };
141
+ //# sourceMappingURL=contentApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentApi.js","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse, request } from \"@playwright/test\";\n\nexport interface ContentApiError {\n\ttype: string;\n\tmessage: string;\n}\nexport interface ContentApiSearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: ContentApiDocument[];\n}\n\nexport interface ContentApiDocument {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface ContentApiGraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface ContentApiRef {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\ninterface ContentApiRepoConfigResponse {\n\trefs: ContentApiRef[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\ntype SearchQueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. The @prismicio/client package could\n * have been used but had too many abstractions (caching, error handling) that\n * we didn't want for test execution. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient {\n\t#version: ApiVersions;\n\t#accessToken: string | undefined;\n\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new ContentApiClient(\"https://my-repo.cdn.prismic.io\", {\n\t * \tversion: \"v2\",\n\t * \taccessToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\tthis.#version = config.version || \"v2\";\n\t\tthis.#accessToken = config.accessToken;\n\t}\n\n\t#context() {\n\t\treturn request.newContext({\n\t\t\tbaseURL: this.baseURL,\n\t\t\t// reset any Authorization header set globally with Playwright\n\t\t\t// didn't find a way to delete it\n\t\t\textraHTTPHeaders: { Authorization: \"\" },\n\t\t});\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.#context();\n\t\tconst securityParams = {\n\t\t\t...(this.#accessToken ? { access_token: this.#accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(\n\t\tref: string,\n\t\tquery: string,\n\t): Promise<ContentApiGraphQLResponse> {\n\t\treturn this.getAsJson<ContentApiGraphQLResponse>(\n\t\t\t\"/graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<ContentApiRef[]> {\n\t\tconst data = await this.getAsJson<ContentApiRepoConfigResponse>(\n\t\t\t`/api/${this.#version}`,\n\t\t);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<ContentApiSearchResponse>(\n\t\t\t`/api/${this.#version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiSearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiDocument | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuFa,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB5B,YACkB,SACjB,SAA0D,IAAE;AAM7D;AAPkB;AArBlB;AACA;AAoBkB,SAAO,UAAP;AAGZ,uBAAA,UAAW,OAAO,WAAW;AAClC,uBAAK,cAAe,OAAO;AAAA,EAC5B;AAAA,EAWA,MAAM,IACL,MACA,QACA,SAAgC;AAE1B,UAAA,UAAU,MAAM,sBAAK,sBAAL;AACtB,UAAM,iBA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IACA,SAA2B;AAEpB,WAAA,KAAK,OAAO,EAAE,GAAG,SAAS,GAAG,sBAAsB,EAAE,OAAA,CAAQ;AAAA,EACrE;AAAA;AAAA,EAGA,MAAM,gBACL,IACA,SAA2B;AAE3B,UAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO;AAC9C,YAAQ,KAAK,cAAc;AAAA,MAC1B,KAAK;AACJ;AAAA,MACD,KAAK;AACG,eAAA,KAAK,QAAQ,CAAC;AAAA,MACtB;AACC,cAAM,IAAI,MAAM,gDAAgD,EAAE,EAAE;AAAA,IACtE;AAAA,EACD;AACA;AAlJA;AACA;AA2BA;AAAA,aAAQ,WAAA;AACP,SAAO,QAAQ,WAAW;AAAA,IACzB,SAAS,KAAK;AAAA;AAAA;AAAA,IAGd,kBAAkB,EAAE,eAAe,GAAI;AAAA,EAAA,CACvC;AACF;"}
@@ -19,15 +19,25 @@ const createCoreApiClient = (baseURL, authClient) => {
19
19
  async function getLanguages() {
20
20
  const profiler = log.logger.startTimer();
21
21
  const result = await client.get("core/repository");
22
- if (![200].includes(result.status) || !result.data.languages) {
22
+ if (200 !== result.status || !result.data.languages) {
23
23
  log.logHttpResponse(result);
24
24
  throw new Error("Could not get languages from the core api.");
25
25
  }
26
26
  profiler.done({ message: "retrieved languages configuration" });
27
27
  return result.data.languages;
28
28
  }
29
+ async function publishDraft(documentId) {
30
+ const result = await client.patch(`core/documents/${documentId}/draft`, {
31
+ status: "published"
32
+ });
33
+ if (204 !== result.status) {
34
+ log.logHttpResponse(result);
35
+ throw new Error(`Could not publish document with id ${documentId}`);
36
+ }
37
+ }
29
38
  return {
30
- getLanguages
39
+ getLanguages,
40
+ publishDraft
31
41
  };
32
42
  };
33
43
  exports.createCoreApiClient = createCoreApiClient;
@@ -1 +1 @@
1
- {"version":3,"file":"coreApi.cjs","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\ntype Language = {\n\tid: string;\n\tname: string;\n\tis_master: boolean;\n};\n\nexport type CoreClient = {\n\tgetLanguages(): Promise<Language[]>;\n};\n\n/** Client for interacting with the core API */\nexport const createCoreApiClient = (\n\tbaseURL: string,\n\tauthClient: AuthenticationClient,\n): CoreClient => {\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\tasync function getLanguages(): Promise<Language[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst result = await client.get<{ languages: Language[] }>(\n\t\t\t\"core/repository\",\n\t\t);\n\n\t\tif (![200].includes(result.status) || !result.data.languages) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get languages from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved languages configuration\" });\n\n\t\treturn result.data.languages;\n\t}\n\n\treturn {\n\t\tgetLanguages,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAiBa,MAAA,sBAAsB,CAClC,SACA,eACe;AACT,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACtC;AAEM,WAAA;AAAA,EAAA,CACP;AAED,iBAAe,eAAY;AACpB,UAAA,WAAWA,WAAO;AACxB,UAAM,SAAS,MAAM,OAAO,IAC3B,iBAAiB;AAGd,QAAA,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,KAAK,CAAC,OAAO,KAAK,WAAW;AAC7DC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,4CAA4C;AAAA,IAC5D;AAED,aAAS,KAAK,EAAE,SAAS,oCAAqC,CAAA;AAE9D,WAAO,OAAO,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
1
+ {"version":3,"file":"coreApi.cjs","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\ntype Language = {\n\tid: string;\n\tname: string;\n\tis_master: boolean;\n};\n\nexport type CoreClient = {\n\tgetLanguages(): Promise<Language[]>;\n\tpublishDraft(documentId: string): Promise<void>;\n};\n\n/** Client for interacting with the core API */\nexport const createCoreApiClient = (\n\tbaseURL: string,\n\tauthClient: AuthenticationClient,\n): CoreClient => {\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\tasync function getLanguages(): Promise<Language[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst result = await client.get<{ languages: Language[] }>(\n\t\t\t\"core/repository\",\n\t\t);\n\n\t\tif (200 !== result.status || !result.data.languages) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get languages from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved languages configuration\" });\n\n\t\treturn result.data.languages;\n\t}\n\n\tasync function publishDraft(documentId: string): Promise<void> {\n\t\tconst result = await client.patch(`core/documents/${documentId}/draft`, {\n\t\t\tstatus: \"published\",\n\t\t});\n\n\t\tif (204 !== result.status) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(`Could not publish document with id ${documentId}`);\n\t\t}\n\t}\n\n\treturn {\n\t\tgetLanguages,\n\t\tpublishDraft,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAkBa,MAAA,sBAAsB,CAClC,SACA,eACe;AACT,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AAEO,WAAA;AAAA,EAAA,CACP;AAED,iBAAe,eAAY;AACpB,UAAA,WAAWA,WAAO;AACxB,UAAM,SAAS,MAAM,OAAO,IAC3B,iBAAiB;AAGlB,QAAI,QAAQ,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW;AACpDC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,4CAA4C;AAAA,IAC7D;AAEA,aAAS,KAAK,EAAE,SAAS,oCAAqC,CAAA;AAE9D,WAAO,OAAO,KAAK;AAAA,EACpB;AAEA,iBAAe,aAAa,YAAkB;AAC7C,UAAM,SAAS,MAAM,OAAO,MAAM,kBAAkB,UAAU,UAAU;AAAA,MACvE,QAAQ;AAAA,IAAA,CACR;AAEG,QAAA,QAAQ,OAAO,QAAQ;AAC1BA,UAAA,gBAAgB,MAAM;AACtB,YAAM,IAAI,MAAM,sCAAsC,UAAU,EAAE;AAAA,IACnE;AAAA,EACD;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
@@ -6,6 +6,7 @@ type Language = {
6
6
  };
7
7
  export type CoreClient = {
8
8
  getLanguages(): Promise<Language[]>;
9
+ publishDraft(documentId: string): Promise<void>;
9
10
  };
10
11
  /** Client for interacting with the core API */
11
12
  export declare const createCoreApiClient: (baseURL: string, authClient: AuthenticationClient) => CoreClient;
@@ -17,15 +17,25 @@ const createCoreApiClient = (baseURL, authClient) => {
17
17
  async function getLanguages() {
18
18
  const profiler = logger.startTimer();
19
19
  const result = await client.get("core/repository");
20
- if (![200].includes(result.status) || !result.data.languages) {
20
+ if (200 !== result.status || !result.data.languages) {
21
21
  logHttpResponse(result);
22
22
  throw new Error("Could not get languages from the core api.");
23
23
  }
24
24
  profiler.done({ message: "retrieved languages configuration" });
25
25
  return result.data.languages;
26
26
  }
27
+ async function publishDraft(documentId) {
28
+ const result = await client.patch(`core/documents/${documentId}/draft`, {
29
+ status: "published"
30
+ });
31
+ if (204 !== result.status) {
32
+ logHttpResponse(result);
33
+ throw new Error(`Could not publish document with id ${documentId}`);
34
+ }
35
+ }
27
36
  return {
28
- getLanguages
37
+ getLanguages,
38
+ publishDraft
29
39
  };
30
40
  };
31
41
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"coreApi.js","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\ntype Language = {\n\tid: string;\n\tname: string;\n\tis_master: boolean;\n};\n\nexport type CoreClient = {\n\tgetLanguages(): Promise<Language[]>;\n};\n\n/** Client for interacting with the core API */\nexport const createCoreApiClient = (\n\tbaseURL: string,\n\tauthClient: AuthenticationClient,\n): CoreClient => {\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\tasync function getLanguages(): Promise<Language[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst result = await client.get<{ languages: Language[] }>(\n\t\t\t\"core/repository\",\n\t\t);\n\n\t\tif (![200].includes(result.status) || !result.data.languages) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get languages from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved languages configuration\" });\n\n\t\treturn result.data.languages;\n\t}\n\n\treturn {\n\t\tgetLanguages,\n\t};\n};\n"],"names":[],"mappings":";;AAiBa,MAAA,sBAAsB,CAClC,SACA,eACe;AACT,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACtC;AAEM,WAAA;AAAA,EAAA,CACP;AAED,iBAAe,eAAY;AACpB,UAAA,WAAW,OAAO;AACxB,UAAM,SAAS,MAAM,OAAO,IAC3B,iBAAiB;AAGd,QAAA,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,KAAK,CAAC,OAAO,KAAK,WAAW;AAC7D,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,4CAA4C;AAAA,IAC5D;AAED,aAAS,KAAK,EAAE,SAAS,oCAAqC,CAAA;AAE9D,WAAO,OAAO,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"coreApi.js","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\ntype Language = {\n\tid: string;\n\tname: string;\n\tis_master: boolean;\n};\n\nexport type CoreClient = {\n\tgetLanguages(): Promise<Language[]>;\n\tpublishDraft(documentId: string): Promise<void>;\n};\n\n/** Client for interacting with the core API */\nexport const createCoreApiClient = (\n\tbaseURL: string,\n\tauthClient: AuthenticationClient,\n): CoreClient => {\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\tasync function getLanguages(): Promise<Language[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst result = await client.get<{ languages: Language[] }>(\n\t\t\t\"core/repository\",\n\t\t);\n\n\t\tif (200 !== result.status || !result.data.languages) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get languages from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved languages configuration\" });\n\n\t\treturn result.data.languages;\n\t}\n\n\tasync function publishDraft(documentId: string): Promise<void> {\n\t\tconst result = await client.patch(`core/documents/${documentId}/draft`, {\n\t\t\tstatus: \"published\",\n\t\t});\n\n\t\tif (204 !== result.status) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(`Could not publish document with id ${documentId}`);\n\t\t}\n\t}\n\n\treturn {\n\t\tgetLanguages,\n\t\tpublishDraft,\n\t};\n};\n"],"names":[],"mappings":";;AAkBa,MAAA,sBAAsB,CAClC,SACA,eACe;AACT,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AAEO,WAAA;AAAA,EAAA,CACP;AAED,iBAAe,eAAY;AACpB,UAAA,WAAW,OAAO;AACxB,UAAM,SAAS,MAAM,OAAO,IAC3B,iBAAiB;AAGlB,QAAI,QAAQ,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW;AACpD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,4CAA4C;AAAA,IAC7D;AAEA,aAAS,KAAK,EAAE,SAAS,oCAAqC,CAAA;AAE9D,WAAO,OAAO,KAAK;AAAA,EACpB;AAEA,iBAAe,aAAa,YAAkB;AAC7C,UAAM,SAAS,MAAM,OAAO,MAAM,kBAAkB,UAAU,UAAU;AAAA,MACvE,QAAQ;AAAA,IAAA,CACR;AAEG,QAAA,QAAQ,OAAO,QAAQ;AAC1B,sBAAgB,MAAM;AACtB,YAAM,IAAI,MAAM,sCAAsC,UAAU,EAAE;AAAA,IACnE;AAAA,EACD;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;"}
@@ -7,6 +7,7 @@ const createCustomTypesApiClient = (baseURL, repository, authClient) => {
7
7
  const client = axios.create({
8
8
  baseURL,
9
9
  validateStatus: () => true,
10
+ // Don't throw on 4XX errors
10
11
  headers: {
11
12
  repository
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tasync function upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.data;\n\t}\n\n\tasync function getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,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,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,cAAc,aAAa,SAAS;AAE5D,aAAO,aAAa,OAAO,UAAU,WAAW,SAAS;AAAA,IACzD,CAAA,CAAC;AAAA,EAEJ;AAOe,iBAAA,kBAAkB,cAA4B,IAAE;AACxD,UAAA,gBAAgB,eAAe,WAAW;AAAA,EACjD;AAOe,iBAAA,aAAa,SAAwB,IAAE;AAC/C,UAAA,gBAAgB,UAAU,MAAM;AAAA,EACvC;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
1
+ {"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tasync function upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.data;\n\t}\n\n\tasync function getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,IACA;AAAA,EAAA,CACD;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AAEO,WAAA;AAAA,EAAA,CACP;AAYc,iBAAA,OACd,UACA,WACA,MAAc;AAER,UAAA,WAAWA,WAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,SAAS,MAAM,OAAO,KAAK,MAAM,MAAM,EAAE,SAAS,CAAE,EAAA,CAAE;AACxD,QAAA,CAAC,CAAC,KAAK,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACxCC,UAAA,gBAAgB,MAAM;AACtB,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAEA,iBAAe,eACd,UAAsB;AAEtB,UAAM,SAAS,MAAM,OAAO,IAAI,QAAQ;AAExC,QAAI,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACnCA,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,WAAO,OAAO;AAAA,EACf;AAEe,iBAAA,cACd,aACA,OAAe;AAET,UAAA,aAAa,YAAY,KAC9B,CAAC,WAAqC,OAAO,OAAO,MAAM,EAAE;AAE7D,QAAI,CAAC,YAAY;AACT,aAAA;AAAA,IACR;AACA,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AACzB,aAAA;AAAA,IACR;AAEA;AAAA,EACD;AAGA,iBAAe,gBACd,UACA,aAAyB,IAAE;AAErB,UAAA,cAAc,MAAM,eAAe,QAAQ;AACjD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,cAAc,aAAa,SAAS;AAE5D,aAAO,aAAa,OAAO,UAAU,WAAW,SAAS;AAAA,IACzD,CAAA,CAAC;AAAA,EAEJ;AAOe,iBAAA,kBAAkB,cAA4B,IAAE;AACxD,UAAA,gBAAgB,eAAe,WAAW;AAAA,EACjD;AAOe,iBAAA,aAAa,SAAwB,IAAE;AAC/C,UAAA,gBAAgB,UAAU,MAAM;AAAA,EACvC;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
@@ -5,6 +5,7 @@ const createCustomTypesApiClient = (baseURL, repository, authClient) => {
5
5
  const client = axios.create({
6
6
  baseURL,
7
7
  validateStatus: () => true,
8
+ // Don't throw on 4XX errors
8
9
  headers: {
9
10
  repository
10
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tasync function upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.data;\n\t}\n\n\tasync function getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":[],"mappings":";;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;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e,QAAQ;AACjD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,cAAc,aAAa,SAAS;AAE5D,aAAO,aAAa,OAAO,UAAU,WAAW,SAAS;AAAA,IACzD,CAAA,CAAC;AAAA,EAEJ;AAOe,iBAAA,kBAAkB,cAA4B,IAAE;AACxD,UAAA,gBAAgB,eAAe,WAAW;AAAA,EACjD;AAOe,iBAAA,aAAa,SAAwB,IAAE;AAC/C,UAAA,gBAAgB,UAAU,MAAM;AAAA,EACvC;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\n\t});\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tasync function upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.data;\n\t}\n\n\tasync function getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":[],"mappings":";;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,IACA;AAAA,EAAA,CACD;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AAEO,WAAA;AAAA,EAAA,CACP;AAYc,iBAAA,OACd,UACA,WACA,MAAc;AAER,UAAA,WAAW,OAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,SAAS,MAAM,OAAO,KAAK,MAAM,MAAM,EAAE,SAAS,CAAE,EAAA,CAAE;AACxD,QAAA,CAAC,CAAC,KAAK,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACxC,sBAAgB,MAAM;AACtB,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AA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