@prismicio/e2e-tests-utils 1.17.0 → 1.18.0-canary.7615426
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -27
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/clients/apiClient.cjs +38 -38
- package/dist/clients/apiClient.cjs.map +1 -1
- package/dist/clients/apiClient.d.cts +30 -0
- package/dist/clients/apiClient.d.cts.map +1 -0
- package/dist/clients/apiClient.d.ts +23 -23
- package/dist/clients/apiClient.d.ts.map +1 -0
- package/dist/clients/apiClient.js +38 -38
- package/dist/clients/apiClient.js.map +1 -1
- package/dist/clients/assetApi.cjs +81 -93
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.cts +105 -0
- package/dist/clients/assetApi.d.cts.map +1 -0
- package/dist/clients/assetApi.d.ts +96 -97
- package/dist/clients/assetApi.d.ts.map +1 -0
- package/dist/clients/assetApi.js +79 -91
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/authenticationApi.cjs +66 -73
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.cts +20 -0
- package/dist/clients/authenticationApi.d.cts.map +1 -0
- package/dist/clients/authenticationApi.d.ts +18 -13
- package/dist/clients/authenticationApi.d.ts.map +1 -0
- package/dist/clients/authenticationApi.js +65 -72
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +94 -103
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.d.cts +116 -0
- package/dist/clients/contentApi.d.cts.map +1 -0
- package/dist/clients/contentApi.d.ts +102 -98
- package/dist/clients/contentApi.d.ts.map +1 -0
- package/dist/clients/contentApi.js +94 -103
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +123 -145
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.cts +122 -0
- package/dist/clients/coreApi.d.cts.map +1 -0
- package/dist/clients/coreApi.d.ts +111 -109
- package/dist/clients/coreApi.d.ts.map +1 -0
- package/dist/clients/coreApi.js +122 -144
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +90 -91
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.d.cts +46 -0
- package/dist/clients/customTypesApi.d.cts.map +1 -0
- package/dist/clients/customTypesApi.d.ts +45 -44
- package/dist/clients/customTypesApi.d.ts.map +1 -0
- package/dist/clients/customTypesApi.js +87 -90
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/integrationFields.cjs +96 -87
- package/dist/clients/integrationFields.cjs.map +1 -1
- package/dist/clients/integrationFields.d.cts +30 -0
- package/dist/clients/integrationFields.d.cts.map +1 -0
- package/dist/clients/integrationFields.d.ts +27 -22
- package/dist/clients/integrationFields.d.ts.map +1 -0
- package/dist/clients/integrationFields.js +93 -86
- package/dist/clients/integrationFields.js.map +1 -1
- package/dist/clients/manageV2.cjs +154 -171
- package/dist/clients/manageV2.cjs.map +1 -1
- package/dist/clients/manageV2.d.cts +105 -0
- package/dist/clients/manageV2.d.cts.map +1 -0
- package/dist/clients/manageV2.d.ts +103 -111
- package/dist/clients/manageV2.d.ts.map +1 -0
- package/dist/clients/manageV2.js +149 -169
- package/dist/clients/manageV2.js.map +1 -1
- package/dist/clients/migrationApi.cjs +37 -36
- package/dist/clients/migrationApi.cjs.map +1 -1
- package/dist/clients/migrationApi.d.cts +48 -0
- package/dist/clients/migrationApi.d.cts.map +1 -0
- package/dist/clients/migrationApi.d.ts +45 -39
- package/dist/clients/migrationApi.d.ts.map +1 -0
- package/dist/clients/migrationApi.js +35 -34
- package/dist/clients/migrationApi.js.map +1 -1
- package/dist/clients/wroom.cjs +101 -122
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.cts +48 -0
- package/dist/clients/wroom.d.cts.map +1 -0
- package/dist/clients/wroom.d.ts +46 -47
- package/dist/clients/wroom.d.ts.map +1 -0
- package/dist/clients/wroom.js +99 -122
- package/dist/clients/wroom.js.map +1 -1
- package/dist/index.cjs +13 -15
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +5 -14
- package/dist/managers/repositories.cjs +159 -169
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.cts +67 -0
- package/dist/managers/repositories.d.cts.map +1 -0
- package/dist/managers/repositories.d.ts +56 -63
- package/dist/managers/repositories.d.ts.map +1 -0
- package/dist/managers/repositories.js +148 -159
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +529 -613
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.cts +308 -0
- package/dist/managers/repository.d.cts.map +1 -0
- package/dist/managers/repository.d.ts +303 -306
- package/dist/managers/repository.d.ts.map +1 -0
- package/dist/managers/repository.js +529 -613
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.cts +41 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +35 -37
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/cookies.cjs +19 -17
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js +20 -18
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/envVariableManager.cjs +33 -34
- package/dist/utils/envVariableManager.cjs.map +1 -1
- package/dist/utils/envVariableManager.js +34 -35
- package/dist/utils/envVariableManager.js.map +1 -1
- package/dist/utils/log.cjs +18 -19
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.js +18 -21
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/random.cjs +13 -6
- package/dist/utils/random.cjs.map +1 -1
- package/dist/utils/random.js +13 -6
- package/dist/utils/random.js.map +1 -1
- package/dist/utils/strings.cjs +13 -7
- package/dist/utils/strings.cjs.map +1 -1
- package/dist/utils/strings.js +14 -8
- package/dist/utils/strings.js.map +1 -1
- package/dist/utils/urls.cjs +21 -10
- package/dist/utils/urls.cjs.map +1 -1
- package/dist/utils/urls.js +22 -12
- package/dist/utils/urls.js.map +1 -1
- package/package.json +42 -67
- package/src/clients/apiClient.ts +16 -21
- package/src/clients/assetApi.ts +75 -82
- package/src/clients/authenticationApi.ts +54 -27
- package/src/clients/contentApi.ts +109 -129
- package/src/clients/coreApi.ts +113 -117
- package/src/clients/customTypesApi.ts +60 -70
- package/src/clients/integrationFields.ts +59 -74
- package/src/clients/manageV2.ts +72 -96
- package/src/clients/migrationApi.ts +35 -39
- package/src/clients/wroom.ts +42 -56
- package/src/index.ts +7 -7
- package/src/managers/repositories.ts +85 -108
- package/src/managers/repository.ts +306 -367
- package/src/types.ts +31 -31
- package/src/utils/cookies.ts +8 -8
- package/src/utils/envVariableManager.ts +15 -15
- package/src/utils/log.ts +17 -21
- package/src/utils/random.ts +5 -6
- package/src/utils/strings.ts +7 -9
- package/src/utils/urls.ts +10 -12
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/cookies.d.ts +0 -8
- package/dist/utils/envVariableManager.d.ts +0 -16
- package/dist/utils/log.d.ts +0 -5
- package/dist/utils/random.d.ts +0 -8
- package/dist/utils/strings.d.ts +0 -11
- 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
|
|
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:
|
|
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:
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=apiClient.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.cjs","sources":["
|
|
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
|
-
*
|
|
5
|
+
* The authentication token. Can be a string or a function that returns a promise resolving to the
|
|
6
|
+
* token.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
type AuthServerToken = string | (() => Promise<string>);
|
|
7
9
|
/**
|
|
8
|
-
* Abstract class for Prismic api clients that use the Prismic authentication
|
|
9
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
//#
|
|
37
|
+
//#endregion
|
|
38
|
+
export { AuthenticatedApiClient };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=apiClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.js","sources":["
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=assetApi.cjs.map
|