@prismicio/e2e-tests-utils 1.18.0 → 1.19.0-pr.37.6283e4a

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 (159) hide show
  1. package/README.md +24 -27
  2. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/clients/apiClient.cjs +38 -38
  4. package/dist/clients/apiClient.cjs.map +1 -1
  5. package/dist/clients/apiClient.d.cts +30 -0
  6. package/dist/clients/apiClient.d.cts.map +1 -0
  7. package/dist/clients/apiClient.d.ts +23 -23
  8. package/dist/clients/apiClient.d.ts.map +1 -0
  9. package/dist/clients/apiClient.js +38 -38
  10. package/dist/clients/apiClient.js.map +1 -1
  11. package/dist/clients/assetApi.cjs +81 -93
  12. package/dist/clients/assetApi.cjs.map +1 -1
  13. package/dist/clients/assetApi.d.cts +105 -0
  14. package/dist/clients/assetApi.d.cts.map +1 -0
  15. package/dist/clients/assetApi.d.ts +96 -97
  16. package/dist/clients/assetApi.d.ts.map +1 -0
  17. package/dist/clients/assetApi.js +79 -91
  18. package/dist/clients/assetApi.js.map +1 -1
  19. package/dist/clients/authenticationApi.cjs +66 -73
  20. package/dist/clients/authenticationApi.cjs.map +1 -1
  21. package/dist/clients/authenticationApi.d.cts +20 -0
  22. package/dist/clients/authenticationApi.d.cts.map +1 -0
  23. package/dist/clients/authenticationApi.d.ts +18 -13
  24. package/dist/clients/authenticationApi.d.ts.map +1 -0
  25. package/dist/clients/authenticationApi.js +65 -72
  26. package/dist/clients/authenticationApi.js.map +1 -1
  27. package/dist/clients/contentApi.cjs +94 -103
  28. package/dist/clients/contentApi.cjs.map +1 -1
  29. package/dist/clients/contentApi.d.cts +116 -0
  30. package/dist/clients/contentApi.d.cts.map +1 -0
  31. package/dist/clients/contentApi.d.ts +102 -98
  32. package/dist/clients/contentApi.d.ts.map +1 -0
  33. package/dist/clients/contentApi.js +94 -103
  34. package/dist/clients/contentApi.js.map +1 -1
  35. package/dist/clients/coreApi.cjs +154 -145
  36. package/dist/clients/coreApi.cjs.map +1 -1
  37. package/dist/clients/coreApi.d.cts +142 -0
  38. package/dist/clients/coreApi.d.cts.map +1 -0
  39. package/dist/clients/coreApi.d.ts +131 -109
  40. package/dist/clients/coreApi.d.ts.map +1 -0
  41. package/dist/clients/coreApi.js +153 -144
  42. package/dist/clients/coreApi.js.map +1 -1
  43. package/dist/clients/customTypesApi.cjs +90 -99
  44. package/dist/clients/customTypesApi.cjs.map +1 -1
  45. package/dist/clients/customTypesApi.d.cts +46 -0
  46. package/dist/clients/customTypesApi.d.cts.map +1 -0
  47. package/dist/clients/customTypesApi.d.ts +45 -45
  48. package/dist/clients/customTypesApi.d.ts.map +1 -0
  49. package/dist/clients/customTypesApi.js +87 -98
  50. package/dist/clients/customTypesApi.js.map +1 -1
  51. package/dist/clients/integrationFields.cjs +96 -87
  52. package/dist/clients/integrationFields.cjs.map +1 -1
  53. package/dist/clients/integrationFields.d.cts +30 -0
  54. package/dist/clients/integrationFields.d.cts.map +1 -0
  55. package/dist/clients/integrationFields.d.ts +27 -22
  56. package/dist/clients/integrationFields.d.ts.map +1 -0
  57. package/dist/clients/integrationFields.js +93 -86
  58. package/dist/clients/integrationFields.js.map +1 -1
  59. package/dist/clients/manageV2.cjs +154 -171
  60. package/dist/clients/manageV2.cjs.map +1 -1
  61. package/dist/clients/manageV2.d.cts +105 -0
  62. package/dist/clients/manageV2.d.cts.map +1 -0
  63. package/dist/clients/manageV2.d.ts +103 -111
  64. package/dist/clients/manageV2.d.ts.map +1 -0
  65. package/dist/clients/manageV2.js +149 -169
  66. package/dist/clients/manageV2.js.map +1 -1
  67. package/dist/clients/migrationApi.cjs +37 -36
  68. package/dist/clients/migrationApi.cjs.map +1 -1
  69. package/dist/clients/migrationApi.d.cts +48 -0
  70. package/dist/clients/migrationApi.d.cts.map +1 -0
  71. package/dist/clients/migrationApi.d.ts +45 -39
  72. package/dist/clients/migrationApi.d.ts.map +1 -0
  73. package/dist/clients/migrationApi.js +35 -34
  74. package/dist/clients/migrationApi.js.map +1 -1
  75. package/dist/clients/wroom.cjs +101 -122
  76. package/dist/clients/wroom.cjs.map +1 -1
  77. package/dist/clients/wroom.d.cts +48 -0
  78. package/dist/clients/wroom.d.cts.map +1 -0
  79. package/dist/clients/wroom.d.ts +46 -47
  80. package/dist/clients/wroom.d.ts.map +1 -0
  81. package/dist/clients/wroom.js +99 -122
  82. package/dist/clients/wroom.js.map +1 -1
  83. package/dist/index.cjs +13 -15
  84. package/dist/index.d.cts +8 -0
  85. package/dist/index.d.ts +8 -7
  86. package/dist/index.js +5 -14
  87. package/dist/managers/repositories.cjs +159 -169
  88. package/dist/managers/repositories.cjs.map +1 -1
  89. package/dist/managers/repositories.d.cts +67 -0
  90. package/dist/managers/repositories.d.cts.map +1 -0
  91. package/dist/managers/repositories.d.ts +56 -63
  92. package/dist/managers/repositories.d.ts.map +1 -0
  93. package/dist/managers/repositories.js +148 -159
  94. package/dist/managers/repositories.js.map +1 -1
  95. package/dist/managers/repository.cjs +591 -616
  96. package/dist/managers/repository.cjs.map +1 -1
  97. package/dist/managers/repository.d.cts +338 -0
  98. package/dist/managers/repository.d.cts.map +1 -0
  99. package/dist/managers/repository.d.ts +333 -307
  100. package/dist/managers/repository.d.ts.map +1 -0
  101. package/dist/managers/repository.js +591 -616
  102. package/dist/managers/repository.js.map +1 -1
  103. package/dist/types.d.cts +41 -0
  104. package/dist/types.d.cts.map +1 -0
  105. package/dist/types.d.ts +35 -37
  106. package/dist/types.d.ts.map +1 -0
  107. package/dist/utils/cookies.cjs +19 -17
  108. package/dist/utils/cookies.cjs.map +1 -1
  109. package/dist/utils/cookies.js +20 -18
  110. package/dist/utils/cookies.js.map +1 -1
  111. package/dist/utils/envVariableManager.cjs +33 -34
  112. package/dist/utils/envVariableManager.cjs.map +1 -1
  113. package/dist/utils/envVariableManager.js +34 -35
  114. package/dist/utils/envVariableManager.js.map +1 -1
  115. package/dist/utils/log.cjs +18 -19
  116. package/dist/utils/log.cjs.map +1 -1
  117. package/dist/utils/log.js +18 -21
  118. package/dist/utils/log.js.map +1 -1
  119. package/dist/utils/random.cjs +13 -6
  120. package/dist/utils/random.cjs.map +1 -1
  121. package/dist/utils/random.js +13 -6
  122. package/dist/utils/random.js.map +1 -1
  123. package/dist/utils/strings.cjs +13 -7
  124. package/dist/utils/strings.cjs.map +1 -1
  125. package/dist/utils/strings.js +14 -8
  126. package/dist/utils/strings.js.map +1 -1
  127. package/dist/utils/urls.cjs +21 -10
  128. package/dist/utils/urls.cjs.map +1 -1
  129. package/dist/utils/urls.js +22 -12
  130. package/dist/utils/urls.js.map +1 -1
  131. package/package.json +42 -67
  132. package/src/clients/apiClient.ts +16 -21
  133. package/src/clients/assetApi.ts +75 -82
  134. package/src/clients/authenticationApi.ts +54 -27
  135. package/src/clients/contentApi.ts +111 -129
  136. package/src/clients/coreApi.ts +165 -117
  137. package/src/clients/customTypesApi.ts +54 -74
  138. package/src/clients/integrationFields.ts +59 -74
  139. package/src/clients/manageV2.ts +72 -96
  140. package/src/clients/migrationApi.ts +35 -39
  141. package/src/clients/wroom.ts +42 -56
  142. package/src/index.ts +7 -7
  143. package/src/managers/repositories.ts +85 -108
  144. package/src/managers/repository.ts +393 -368
  145. package/src/types.ts +31 -31
  146. package/src/utils/cookies.ts +8 -8
  147. package/src/utils/envVariableManager.ts +15 -15
  148. package/src/utils/log.ts +17 -21
  149. package/src/utils/random.ts +5 -6
  150. package/src/utils/strings.ts +7 -9
  151. package/src/utils/urls.ts +10 -12
  152. package/dist/index.cjs.map +0 -1
  153. package/dist/index.js.map +0 -1
  154. package/dist/utils/cookies.d.ts +0 -8
  155. package/dist/utils/envVariableManager.d.ts +0 -16
  156. package/dist/utils/log.d.ts +0 -5
  157. package/dist/utils/random.d.ts +0 -8
  158. package/dist/utils/strings.d.ts +0 -11
  159. package/dist/utils/urls.d.ts +0 -16
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  This library comprises utility functions tailored for end-to-end tests at Prismic, with a primary focus on tasks like repository creation, configuration, and deletion.
4
4
 
5
5
  #### Purpose
6
+
6
7
  In the context of testing, it's essential to operate in a controlled environment where the necessary conditions are defined explicitly. To avoid redundant logic across various services for setting up test data, this library consolidates and provides the required functionalities.
7
8
 
8
9
  ## Installation
@@ -18,24 +19,24 @@ npm install --save-dev @prismicio/e2e-tests-utils
18
19
  Useful to run the tests on a clean repository with a controlled configuration, for example in a CI.
19
20
 
20
21
  ```typescript
21
- import { createRepositoriesManager } from "@prismicio/e2e-tests-utils";
22
- import type { RepositoryConfig } from "@prismicio/e2e-tests-utils";
22
+ import { createRepositoriesManager } from "@prismicio/e2e-tests-utils"
23
+ import type { RepositoryConfig } from "@prismicio/e2e-tests-utils"
23
24
 
24
25
  const config: RepositoryConfig = {
25
26
  locales: ["en-gb", "fr-fr"],
26
27
  defaultLocale: "en-gb",
27
28
  // ... see RepositoryConfig for other options
28
- };
29
- const authConfig = { email, password };
29
+ }
30
+ const authConfig = { email, password }
30
31
 
31
- const testUtils = createRepositoriesManager({ urlConfig :"https://prismic.io", authConfig});
32
- const repository = await testUtils.createRepository(config);
32
+ const testUtils = createRepositoriesManager({ urlConfig: "https://prismic.io", authConfig })
33
+ const repository = await testUtils.createRepository(config)
33
34
 
34
35
  // A repository is now available with a unique name and configured as required
35
36
  repository.getBaseURL() // https://my-unique-repo-name.prismic.io
36
37
 
37
38
  // run your tests, delete the repository
38
- await testUtils.tearDown();
39
+ await testUtils.tearDown()
39
40
  ```
40
41
 
41
42
  ### Create Custom Types
@@ -44,20 +45,17 @@ Use Custom Types and Shared slices typed from the `@prismicio/types-internal` li
44
45
  If the custom types already exists on the repository, they will be updated.
45
46
 
46
47
  ```typescript
47
- import { createRepositoriesManager } from "@prismicio/e2e-tests-utils";
48
+ import { createRepositoriesManager } from "@prismicio/e2e-tests-utils"
48
49
 
49
- import {
50
- CustomType,
51
- SharedSlice,
52
- } from "@prismicio/types-internal/lib/customtypes";
50
+ import { DynamicCustomTypeModel, SharedSliceModel } from "@prismicio/types-internal"
53
51
 
54
- const slice: SharedSlice = {
52
+ const slice: SharedSliceModel = {
55
53
  id: "test_slice",
56
54
  type: "SharedSlice",
57
55
  name: "A slice demo",
58
56
  // ...
59
- };
60
- const customType: CustomType = {
57
+ }
58
+ const customType: DynamicCustomTypeModel = {
61
59
  id: "test_ct",
62
60
  label: "A custom type",
63
61
  // ...
@@ -76,21 +74,21 @@ const customType: CustomType = {
76
74
  },
77
75
  },
78
76
  },
79
- };
77
+ }
80
78
 
81
79
  // Create them individually
82
- await repository.createSlices([slice]);
83
- await repository.createCustomTypes([customType]);
80
+ await repository.createSlices([slice])
81
+ await repository.createCustomTypes([customType])
84
82
 
85
83
  // Or create them via the RepositoryConfig object
86
- const config = { slices: [slice], customTypes: [customType] };
87
- await testUtils.createRepository(config);
84
+ const config = { slices: [slice], customTypes: [customType] }
85
+ await testUtils.createRepository(config)
88
86
  ```
89
87
 
90
88
  ### Retrieve an API token (jwt)
91
89
 
92
90
  ```typescript
93
- const token = await testUtils.getUserApiToken();
91
+ const token = await testUtils.getUserApiToken()
94
92
  ```
95
93
 
96
94
  ### Get API clients
@@ -98,21 +96,20 @@ const token = await testUtils.getUserApiToken();
98
96
  The library provides a few api clients for Prismic services. For example the Content Api.
99
97
 
100
98
  ```typescript
101
- const contentApi = repository.getContentApiClient();
102
- const document = await contentApi.getDocumentByID(documentId);
99
+ const contentApi = repository.getContentApiClient()
100
+ const document = await contentApi.getDocumentByID(documentId)
103
101
  ```
104
102
 
105
103
  The `@prismicio/client` package could have been used but had too many abstractions (caching, error handling) that we don't necessarly want for test execution.
106
104
 
107
-
108
105
  ### Retrieve a RepositoryManager of an existing repository
109
106
 
110
107
  ```typescript
111
- const repository = await testUtils.getRepositoryManager(name);
108
+ const repository = await testUtils.getRepositoryManager(name)
112
109
  // configure multiple settings and once
113
- await repository.configure(settings);
110
+ await repository.configure(settings)
114
111
  // or configure them individually
115
- await repository.createRelease("next release");
112
+ await repository.createRelease("next release")
116
113
  ```
117
114
 
118
115
  ### How does the library know which endpoints urls to use under the hood (authentication server, custom types api)?
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
@@ -1,40 +1,40 @@
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;
1
+ const require_urls = require("../utils/urls.cjs");
2
+ let _playwright_test = require("@playwright/test");
3
+ //#region src/clients/apiClient.ts
4
+ /**
5
+ * Abstract class for Prismic api clients that use the Prismic authentication server. This class
6
+ * takes care or creating the Playwright context with the necessary authorization headers.
7
+ *
8
+ * This class performs requests with Playwright instead of a library like Axios which has the
9
+ * advantage of tracing all the network details in the Playwright reports making test failures
10
+ * investigation easier for projects that use Playwright.
11
+ */
12
+ var AuthenticatedApiClient = class {
13
+ baseURL;
14
+ token;
15
+ headers;
16
+ _context;
17
+ constructor(baseURL, token, headers) {
18
+ this.baseURL = baseURL;
19
+ this.token = token;
20
+ this.headers = headers;
21
+ }
22
+ /** Returns a Playwright ApiRequestContext instance with the necessary authorization headers. */
23
+ async getContext() {
24
+ if (!this._context) {
25
+ const token = typeof this.token === "string" ? this.token : await this.token();
26
+ this._context = await _playwright_test.request.newContext({
27
+ baseURL: require_urls.appendTrailingSlash(this.baseURL),
28
+ extraHTTPHeaders: {
29
+ Authorization: `Bearer ${token}`,
30
+ ...this.headers
31
+ }
32
+ });
33
+ }
34
+ return this._context;
35
+ }
7
36
  };
8
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
- const test = require("@playwright/test");
10
- const urls = require("../utils/urls.cjs");
11
- class AuthenticatedApiClient {
12
- constructor(baseURL, token, headers) {
13
- __publicField(this, "baseURL");
14
- __publicField(this, "token");
15
- __publicField(this, "headers");
16
- __publicField(this, "_context");
17
- this.baseURL = baseURL;
18
- this.token = token;
19
- this.headers = headers;
20
- }
21
- /**
22
- * Returns a Playwright ApiRequestContext instance with the necessary
23
- * authorization headers.
24
- */
25
- async getContext() {
26
- if (!this._context) {
27
- const token = typeof this.token === "string" ? this.token : await this.token();
28
- this._context = await test.request.newContext({
29
- baseURL: urls.appendTrailingSlash(this.baseURL),
30
- extraHTTPHeaders: {
31
- Authorization: `Bearer ${token}`,
32
- ...this.headers
33
- }
34
- });
35
- }
36
- return this._context;
37
- }
38
- }
37
+ //#endregion
39
38
  exports.AuthenticatedApiClient = AuthenticatedApiClient;
40
- //# sourceMappingURL=apiClient.cjs.map
39
+
40
+ //# sourceMappingURL=apiClient.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiClient.cjs","sources":["../../../src/clients/apiClient.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { appendTrailingSlash } from \"../utils/urls\";\n\n/**\n * The authentication token. Can be a string or a function that returns a\n * promise resolving to the token.\n */\nexport type AuthServerToken = string | (() => Promise<string>);\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication\n * server. This class takes care or creating the Playwright context with the\n * necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios\n * which has the advantage of tracing all the network details in the Playwright\n * reports making test failures investigation easier for projects that use\n * Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/**\n\t * Returns a Playwright ApiRequestContext instance with the necessary\n\t * authorization headers.\n\t */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token =\n\t\t\t\ttypeof this.token === \"string\" ? this.token : await this.token();\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n}\n"],"names":["request","appendTrailingSlash"],"mappings":";;;;;;;;;;MAoBsB,uBAAsB;AAAA,EAG3C,YACkB,SACA,OACA,SAA+C;AAF/C;AACA;AACA;AALV;AAGU,SAAO,UAAP;AACA,SAAK,QAAL;AACA,SAAO,UAAP;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,aAAU;AACrB,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,QACL,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK;AAErD,WAAA,WAAW,MAAMA,KAAA,QAAQ,WAAW;AAAA,QACxC,SAASC,KAAAA,oBAAoB,KAAK,OAAO;AAAA,QACzC,kBAAkB;AAAA,UACjB,eAAe,UAAU,KAAK;AAAA,UAC9B,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AACA;;"}
1
+ {"version":3,"file":"apiClient.cjs","names":["request","appendTrailingSlash"],"sources":["../../src/clients/apiClient.ts"],"sourcesContent":["import type { APIRequestContext } from \"@playwright/test\"\nimport { request } from \"@playwright/test\"\n\nimport { appendTrailingSlash } from \"../utils/urls\"\n\n/**\n * The authentication token. Can be a string or a function that returns a promise resolving to the\n * token.\n */\nexport type AuthServerToken = string | (() => Promise<string>)\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication server. This class\n * takes care or creating the Playwright context with the necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios which has the\n * advantage of tracing all the network details in the Playwright reports making test failures\n * investigation easier for projects that use Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/** Returns a Playwright ApiRequestContext instance with the necessary authorization headers. */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token = typeof this.token === \"string\" ? this.token : await this.token()\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\treturn this._context\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAsB,yBAAtB,MAA6C;CAI1B;CACA;CACA;CALlB;CAEA,YACC,SACA,OACA,SACC;EAHgB,KAAA,UAAA;EACA,KAAA,QAAA;EACA,KAAA,UAAA;CACf;;CAGH,MAAgB,aAAyC;EACxD,IAAI,CAAC,KAAK,UAAU;GACnB,MAAM,QAAQ,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK,MAAM;GAE7E,KAAK,WAAW,MAAMA,iBAAAA,QAAQ,WAAW;IACxC,SAASC,aAAAA,oBAAoB,KAAK,OAAO;IACzC,kBAAkB;KACjB,eAAe,UAAU;KACzB,GAAG,KAAK;IACT;GACD,CAAC;EACF;EAEA,OAAO,KAAK;CACb;AACD"}
@@ -0,0 +1,30 @@
1
+ import { APIRequestContext } from "@playwright/test";
2
+
3
+ //#region src/clients/apiClient.d.ts
4
+ /**
5
+ * The authentication token. Can be a string or a function that returns a promise resolving to the
6
+ * token.
7
+ */
8
+ type AuthServerToken = string | (() => Promise<string>);
9
+ /**
10
+ * Abstract class for Prismic api clients that use the Prismic authentication server. This class
11
+ * takes care or creating the Playwright context with the necessary authorization headers.
12
+ *
13
+ * This class performs requests with Playwright instead of a library like Axios which has the
14
+ * advantage of tracing all the network details in the Playwright reports making test failures
15
+ * investigation easier for projects that use Playwright.
16
+ */
17
+ declare abstract class AuthenticatedApiClient {
18
+ private readonly baseURL;
19
+ private readonly token;
20
+ private readonly headers?;
21
+ private _context?;
22
+ constructor(baseURL: string, token: AuthServerToken, headers?: {
23
+ [key: string]: string;
24
+ } | undefined);
25
+ /** Returns a Playwright ApiRequestContext instance with the necessary authorization headers. */
26
+ protected getContext(): Promise<APIRequestContext>;
27
+ }
28
+ //#endregion
29
+ export { AuthServerToken, AuthenticatedApiClient };
30
+ //# sourceMappingURL=apiClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiClient.d.cts","names":[],"sources":["../../src/clients/apiClient.ts"],"mappings":";;;;;AASA;;KAAY,eAAA,mBAAkC,OAAO;;AAAA;AAUrD;;;;;;uBAAsB,sBAAA;EAAA,iBAIH,OAAA;EAAA,iBACA,KAAA;EAAA,iBACA,OAAA;EAAA,QALV,QAAA;cAGU,OAAA,UACA,KAAA,EAAO,eAAA,EACP,OAAA;IAAA,CAAa,GAAA;EAAA;EADN;EAAA,UAKT,UAAA,IAAc,OAAA,CAAQ,iBAAA;AAAA"}
@@ -1,30 +1,30 @@
1
1
  import { APIRequestContext } from "@playwright/test";
2
+
3
+ //#region src/clients/apiClient.d.ts
2
4
  /**
3
- * The authentication token. Can be a string or a function that returns a
4
- * promise resolving to the token.
5
+ * The authentication token. Can be a string or a function that returns a promise resolving to the
6
+ * token.
5
7
  */
6
- export type AuthServerToken = string | (() => Promise<string>);
8
+ type AuthServerToken = string | (() => Promise<string>);
7
9
  /**
8
- * Abstract class for Prismic api clients that use the Prismic authentication
9
- * server. This class takes care or creating the Playwright context with the
10
- * necessary authorization headers.
10
+ * Abstract class for Prismic api clients that use the Prismic authentication server. This class
11
+ * takes care or creating the Playwright context with the necessary authorization headers.
11
12
  *
12
- * This class performs requests with Playwright instead of a library like Axios
13
- * which has the advantage of tracing all the network details in the Playwright
14
- * reports making test failures investigation easier for projects that use
15
- * Playwright.
13
+ * This class performs requests with Playwright instead of a library like Axios which has the
14
+ * advantage of tracing all the network details in the Playwright reports making test failures
15
+ * investigation easier for projects that use Playwright.
16
16
  */
17
- export declare abstract class AuthenticatedApiClient {
18
- private readonly baseURL;
19
- private readonly token;
20
- private readonly headers?;
21
- private _context?;
22
- constructor(baseURL: string, token: AuthServerToken, headers?: {
23
- [key: string]: string;
24
- } | undefined);
25
- /**
26
- * Returns a Playwright ApiRequestContext instance with the necessary
27
- * authorization headers.
28
- */
29
- protected getContext(): Promise<APIRequestContext>;
17
+ declare abstract class AuthenticatedApiClient {
18
+ private readonly baseURL;
19
+ private readonly token;
20
+ private readonly headers?;
21
+ private _context?;
22
+ constructor(baseURL: string, token: AuthServerToken, headers?: {
23
+ [key: string]: string;
24
+ } | undefined);
25
+ /** Returns a Playwright ApiRequestContext instance with the necessary authorization headers. */
26
+ protected getContext(): Promise<APIRequestContext>;
30
27
  }
28
+ //#endregion
29
+ export { AuthServerToken, AuthenticatedApiClient };
30
+ //# sourceMappingURL=apiClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiClient.d.ts","names":[],"sources":["../../src/clients/apiClient.ts"],"mappings":";;;;;AASA;;KAAY,eAAA,mBAAkC,OAAO;;AAAA;AAUrD;;;;;;uBAAsB,sBAAA;EAAA,iBAIH,OAAA;EAAA,iBACA,KAAA;EAAA,iBACA,OAAA;EAAA,QALV,QAAA;cAGU,OAAA,UACA,KAAA,EAAO,eAAA,EACP,OAAA;IAAA,CAAa,GAAA;EAAA;EADN;EAAA,UAKT,UAAA,IAAc,OAAA,CAAQ,iBAAA;AAAA"}
@@ -1,40 +1,40 @@
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
- import { request } from "@playwright/test";
8
1
  import { appendTrailingSlash } from "../utils/urls.js";
9
- class AuthenticatedApiClient {
10
- constructor(baseURL, token, headers) {
11
- __publicField(this, "baseURL");
12
- __publicField(this, "token");
13
- __publicField(this, "headers");
14
- __publicField(this, "_context");
15
- this.baseURL = baseURL;
16
- this.token = token;
17
- this.headers = headers;
18
- }
19
- /**
20
- * Returns a Playwright ApiRequestContext instance with the necessary
21
- * authorization headers.
22
- */
23
- async getContext() {
24
- if (!this._context) {
25
- const token = typeof this.token === "string" ? this.token : await this.token();
26
- this._context = await request.newContext({
27
- baseURL: appendTrailingSlash(this.baseURL),
28
- extraHTTPHeaders: {
29
- Authorization: `Bearer ${token}`,
30
- ...this.headers
31
- }
32
- });
33
- }
34
- return this._context;
35
- }
36
- }
37
- export {
38
- AuthenticatedApiClient
2
+ import { request } from "@playwright/test";
3
+ //#region src/clients/apiClient.ts
4
+ /**
5
+ * Abstract class for Prismic api clients that use the Prismic authentication server. This class
6
+ * takes care or creating the Playwright context with the necessary authorization headers.
7
+ *
8
+ * This class performs requests with Playwright instead of a library like Axios which has the
9
+ * advantage of tracing all the network details in the Playwright reports making test failures
10
+ * investigation easier for projects that use Playwright.
11
+ */
12
+ var AuthenticatedApiClient = class {
13
+ baseURL;
14
+ token;
15
+ headers;
16
+ _context;
17
+ constructor(baseURL, token, headers) {
18
+ this.baseURL = baseURL;
19
+ this.token = token;
20
+ this.headers = headers;
21
+ }
22
+ /** Returns a Playwright ApiRequestContext instance with the necessary authorization headers. */
23
+ async getContext() {
24
+ if (!this._context) {
25
+ const token = typeof this.token === "string" ? this.token : await this.token();
26
+ this._context = await request.newContext({
27
+ baseURL: appendTrailingSlash(this.baseURL),
28
+ extraHTTPHeaders: {
29
+ Authorization: `Bearer ${token}`,
30
+ ...this.headers
31
+ }
32
+ });
33
+ }
34
+ return this._context;
35
+ }
39
36
  };
40
- //# sourceMappingURL=apiClient.js.map
37
+ //#endregion
38
+ export { AuthenticatedApiClient };
39
+
40
+ //# sourceMappingURL=apiClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiClient.js","sources":["../../../src/clients/apiClient.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { appendTrailingSlash } from \"../utils/urls\";\n\n/**\n * The authentication token. Can be a string or a function that returns a\n * promise resolving to the token.\n */\nexport type AuthServerToken = string | (() => Promise<string>);\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication\n * server. This class takes care or creating the Playwright context with the\n * necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios\n * which has the advantage of tracing all the network details in the Playwright\n * reports making test failures investigation easier for projects that use\n * Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/**\n\t * Returns a Playwright ApiRequestContext instance with the necessary\n\t * authorization headers.\n\t */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token =\n\t\t\t\ttypeof this.token === \"string\" ? this.token : await this.token();\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;MAoBsB,uBAAsB;AAAA,EAG3C,YACkB,SACA,OACA,SAA+C;AAF/C;AACA;AACA;AALV;AAGU,SAAO,UAAP;AACA,SAAK,QAAL;AACA,SAAO,UAAP;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,aAAU;AACrB,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,QACL,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK;AAErD,WAAA,WAAW,MAAM,QAAQ,WAAW;AAAA,QACxC,SAAS,oBAAoB,KAAK,OAAO;AAAA,QACzC,kBAAkB;AAAA,UACjB,eAAe,UAAU,KAAK;AAAA,UAC9B,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AACA;"}
1
+ {"version":3,"file":"apiClient.js","names":[],"sources":["../../src/clients/apiClient.ts"],"sourcesContent":["import type { APIRequestContext } from \"@playwright/test\"\nimport { request } from \"@playwright/test\"\n\nimport { appendTrailingSlash } from \"../utils/urls\"\n\n/**\n * The authentication token. Can be a string or a function that returns a promise resolving to the\n * token.\n */\nexport type AuthServerToken = string | (() => Promise<string>)\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication server. This class\n * takes care or creating the Playwright context with the necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios which has the\n * advantage of tracing all the network details in the Playwright reports making test failures\n * investigation easier for projects that use Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/** Returns a Playwright ApiRequestContext instance with the necessary authorization headers. */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token = typeof this.token === \"string\" ? this.token : await this.token()\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\treturn this._context\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAsB,yBAAtB,MAA6C;CAI1B;CACA;CACA;CALlB;CAEA,YACC,SACA,OACA,SACC;EAHgB,KAAA,UAAA;EACA,KAAA,QAAA;EACA,KAAA,UAAA;CACf;;CAGH,MAAgB,aAAyC;EACxD,IAAI,CAAC,KAAK,UAAU;GACnB,MAAM,QAAQ,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK,MAAM;GAE7E,KAAK,WAAW,MAAM,QAAQ,WAAW;IACxC,SAAS,oBAAoB,KAAK,OAAO;IACzC,kBAAkB;KACjB,eAAe,UAAU;KACzB,GAAG,KAAK;IACT;GACD,CAAC;EACF;EAEA,OAAO,KAAK;CACb;AACD"}
@@ -1,94 +1,82 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const log = require("../utils/log.cjs");
4
- const apiClient = require("./apiClient.cjs");
5
- class AssetApiClient extends apiClient.AuthenticatedApiClient {
6
- /**
7
- * @example To instantiate the class:
8
- *
9
- * ```js
10
- * new AssetApiClient("https://asset-api.prismic.io", {
11
- * authToken: "my-secret-token",
12
- * repository: "my-repo-name",
13
- * });
14
- * ```
15
- *
16
- * @param baseURL - The API base URL, such as https://asset-api.prismic.io
17
- * @param config - Optional configuration
18
- *
19
- * - {@link config.authToken}: API token generated from the auth service or a
20
- * function to fetch it when it's needed.
21
- * - {@link config.repository}: Repository name.
22
- */
23
- constructor(baseURL, config) {
24
- super(baseURL, config.authToken, { repository: config.repository });
25
- }
26
- /**
27
- * Uploads an asset file to the server.
28
- *
29
- * @param data - The payload containing the file and filename.
30
- *
31
- * @returns The API response containing asset information.
32
- *
33
- * @throws An error if the upload fails.
34
- */
35
- async createAsset(data) {
36
- const context = await this.getContext();
37
- const result = await context.post("assets", {
38
- multipart: { file: data }
39
- });
40
- if (200 !== result.status()) {
41
- await log.logPlaywrightApiResponse(result);
42
- throw new Error("Could not upload the asset with the asset API.");
43
- }
44
- return result.json();
45
- }
46
- /**
47
- * Patch an existing asset.
48
- *
49
- * @param args - Asset id + the payload
50
- *
51
- * @returns The API response containing asset information.
52
- *
53
- * @throws An error if the upload fails.
54
- */
55
- async patchAsset(args) {
56
- const context = await this.getContext();
57
- const { assetId, ...data } = args;
58
- const result = await context.patch(`assets/${assetId}`, { data });
59
- if (200 !== result.status()) {
60
- await log.logPlaywrightApiResponse(result);
61
- throw new Error("Could not search the asset API.");
62
- }
63
- return result.json();
64
- }
65
- /**
66
- * Searches for assets.
67
- *
68
- * @param params - Optional parameters to refine search results.
69
- *
70
- * @returns The API response containing assets.
71
- */
72
- async search(params) {
73
- const context = await this.getContext();
74
- const { ids, ...rest } = params ?? {};
75
- const query = new URLSearchParams();
76
- for (const [key, value] of Object.entries(rest)) {
77
- if (value !== void 0) {
78
- query.set(key, String(value));
79
- }
80
- }
81
- for (const id of ids ?? []) {
82
- query.append("ids", id);
83
- }
84
- const url = query.size ? `assets?${query}` : "assets";
85
- const result = await context.get(url);
86
- if (200 !== result.status()) {
87
- await log.logPlaywrightApiResponse(result);
88
- throw new Error("Could not search the asset API.");
89
- }
90
- return result.json();
91
- }
92
- }
1
+ const require_log = require("../utils/log.cjs");
2
+ const require_apiClient = require("./apiClient.cjs");
3
+ //#region src/clients/assetApi.ts
4
+ var AssetApiClient = class extends require_apiClient.AuthenticatedApiClient {
5
+ /**
6
+ * @example
7
+ * To instantiate the class:
8
+ *
9
+ * ```js
10
+ * new AssetApiClient("https://asset-api.prismic.io", {
11
+ * authToken: "my-secret-token",
12
+ * repository: "my-repo-name",
13
+ * });
14
+ * ```
15
+ *
16
+ * @param baseURL - The API base URL, such as https://asset-api.prismic.io
17
+ * @param config - Optional configuration
18
+ *
19
+ * - {@link config.authToken}: API token generated from the auth service or a function to fetch it
20
+ * when it's needed.
21
+ * - {@link config.repository}: Repository name.
22
+ */
23
+ constructor(baseURL, config) {
24
+ super(baseURL, config.authToken, { repository: config.repository });
25
+ }
26
+ /**
27
+ * Uploads an asset file to the server.
28
+ *
29
+ * @param data - The payload containing the file and filename.
30
+ * @returns The API response containing asset information.
31
+ * @throws An error if the upload fails.
32
+ */
33
+ async createAsset(data) {
34
+ const result = await (await this.getContext()).post("assets", { multipart: { file: data } });
35
+ if (200 !== result.status()) {
36
+ await require_log.logPlaywrightApiResponse(result);
37
+ throw new Error("Could not upload the asset with the asset API.");
38
+ }
39
+ return result.json();
40
+ }
41
+ /**
42
+ * Patch an existing asset.
43
+ *
44
+ * @param args - Asset id + the payload
45
+ * @returns The API response containing asset information.
46
+ * @throws An error if the upload fails.
47
+ */
48
+ async patchAsset(args) {
49
+ const context = await this.getContext();
50
+ const { assetId, ...data } = args;
51
+ const result = await context.patch(`assets/${assetId}`, { data });
52
+ if (200 !== result.status()) {
53
+ await require_log.logPlaywrightApiResponse(result);
54
+ throw new Error("Could not search the asset API.");
55
+ }
56
+ return result.json();
57
+ }
58
+ /**
59
+ * Searches for assets.
60
+ *
61
+ * @param params - Optional parameters to refine search results.
62
+ * @returns The API response containing assets.
63
+ */
64
+ async search(params) {
65
+ const context = await this.getContext();
66
+ const { ids, ...rest } = params ?? {};
67
+ const query = new URLSearchParams();
68
+ for (const [key, value] of Object.entries(rest)) if (value !== void 0) query.set(key, String(value));
69
+ for (const id of ids ?? []) query.append("ids", id);
70
+ const url = query.size ? `assets?${query}` : "assets";
71
+ const result = await context.get(url);
72
+ if (200 !== result.status()) {
73
+ await require_log.logPlaywrightApiResponse(result);
74
+ throw new Error("Could not search the asset API.");
75
+ }
76
+ return result.json();
77
+ }
78
+ };
79
+ //#endregion
93
80
  exports.AssetApiClient = AssetApiClient;
94
- //# sourceMappingURL=assetApi.cjs.map
81
+
82
+ //# sourceMappingURL=assetApi.cjs.map