@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.
- 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 +154 -145
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.cts +142 -0
- package/dist/clients/coreApi.d.cts.map +1 -0
- package/dist/clients/coreApi.d.ts +131 -109
- package/dist/clients/coreApi.d.ts.map +1 -0
- package/dist/clients/coreApi.js +153 -144
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +90 -99
- 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 -45
- package/dist/clients/customTypesApi.d.ts.map +1 -0
- package/dist/clients/customTypesApi.js +87 -98
- 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 +591 -616
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.cts +338 -0
- package/dist/managers/repository.d.cts.map +1 -0
- package/dist/managers/repository.d.ts +333 -307
- package/dist/managers/repository.d.ts.map +1 -0
- package/dist/managers/repository.js +591 -616
- 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 +111 -129
- package/src/clients/coreApi.ts +165 -117
- package/src/clients/customTypesApi.ts +54 -74
- 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 +393 -368
- 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/src/clients/assetApi.ts
CHANGED
|
@@ -1,163 +1,156 @@
|
|
|
1
|
-
import { logPlaywrightApiResponse } from "../utils/log"
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { logPlaywrightApiResponse } from "../utils/log"
|
|
2
|
+
import type { AuthServerToken } from "./apiClient"
|
|
3
|
+
import { AuthenticatedApiClient } from "./apiClient"
|
|
4
4
|
|
|
5
5
|
export interface AssetApiCreatePayload {
|
|
6
|
-
name: string
|
|
7
|
-
mimeType: string
|
|
8
|
-
buffer: Buffer
|
|
6
|
+
name: string
|
|
7
|
+
mimeType: string
|
|
8
|
+
buffer: Buffer
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type AssetApiCreateResponse = AssetApiResponse
|
|
11
|
+
export type AssetApiCreateResponse = AssetApiResponse
|
|
12
12
|
export interface AssetApiResponse {
|
|
13
|
-
id: string
|
|
14
|
-
url: string
|
|
15
|
-
filename: string
|
|
16
|
-
size: number
|
|
17
|
-
width: number
|
|
18
|
-
height: number
|
|
19
|
-
last_modified: number
|
|
20
|
-
kind: string
|
|
21
|
-
extension: string
|
|
22
|
-
created_at: number
|
|
23
|
-
uploader_id: string
|
|
24
|
-
tags: string[]
|
|
13
|
+
id: string
|
|
14
|
+
url: string
|
|
15
|
+
filename: string
|
|
16
|
+
size: number
|
|
17
|
+
width: number
|
|
18
|
+
height: number
|
|
19
|
+
last_modified: number
|
|
20
|
+
kind: string
|
|
21
|
+
extension: string
|
|
22
|
+
created_at: number
|
|
23
|
+
uploader_id: string
|
|
24
|
+
tags: string[]
|
|
25
25
|
ai_metadata?: {
|
|
26
|
-
is_logo?: boolean
|
|
27
|
-
logo_company_industry?: string
|
|
28
|
-
logo_company_name?: string
|
|
29
|
-
description?: string
|
|
30
|
-
keywords?: string[]
|
|
31
|
-
}
|
|
26
|
+
is_logo?: boolean
|
|
27
|
+
logo_company_industry?: string
|
|
28
|
+
logo_company_name?: string
|
|
29
|
+
description?: string
|
|
30
|
+
keywords?: string[]
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
type AssetApiSearchParams = {
|
|
35
|
-
ids?: string[]
|
|
36
|
-
keyword?: string
|
|
37
|
-
limit?: number
|
|
38
|
-
assetType?: string
|
|
39
|
-
cursor?: string
|
|
40
|
-
}
|
|
35
|
+
ids?: string[]
|
|
36
|
+
keyword?: string
|
|
37
|
+
limit?: number
|
|
38
|
+
assetType?: string
|
|
39
|
+
cursor?: string
|
|
40
|
+
}
|
|
41
41
|
|
|
42
42
|
interface AssetApiSearchResponse {
|
|
43
|
-
items: AssetApiResponse[]
|
|
44
|
-
total: number
|
|
45
|
-
cursor: string
|
|
46
|
-
is_opensearch_result: boolean
|
|
43
|
+
items: AssetApiResponse[]
|
|
44
|
+
total: number
|
|
45
|
+
cursor: string
|
|
46
|
+
is_opensearch_result: boolean
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
interface PatchAssetArgs {
|
|
50
|
-
assetId: string
|
|
51
|
-
filename?: string
|
|
52
|
-
notes?: string
|
|
53
|
-
credits?: string
|
|
54
|
-
alt?: string
|
|
55
|
-
tags?: string[]
|
|
50
|
+
assetId: string
|
|
51
|
+
filename?: string
|
|
52
|
+
notes?: string
|
|
53
|
+
credits?: string
|
|
54
|
+
alt?: string
|
|
55
|
+
tags?: string[]
|
|
56
56
|
ai_metadata?: {
|
|
57
|
-
description?: string
|
|
58
|
-
keywords?: string[]
|
|
59
|
-
}
|
|
57
|
+
description?: string
|
|
58
|
+
keywords?: string[]
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export class AssetApiClient extends AuthenticatedApiClient {
|
|
63
63
|
/**
|
|
64
|
-
* @example
|
|
64
|
+
* @example
|
|
65
|
+
* To instantiate the class:
|
|
65
66
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
67
|
+
* ```js
|
|
68
|
+
* new AssetApiClient("https://asset-api.prismic.io", {
|
|
68
69
|
* authToken: "my-secret-token",
|
|
69
70
|
* repository: "my-repo-name",
|
|
70
|
-
*
|
|
71
|
-
*
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
72
73
|
*
|
|
73
74
|
* @param baseURL - The API base URL, such as https://asset-api.prismic.io
|
|
74
75
|
* @param config - Optional configuration
|
|
75
76
|
*
|
|
76
|
-
* - {@link config.authToken}: API token generated from the auth service or a
|
|
77
|
-
*
|
|
77
|
+
* - {@link config.authToken}: API token generated from the auth service or a function to fetch it
|
|
78
|
+
* when it's needed.
|
|
78
79
|
* - {@link config.repository}: Repository name.
|
|
79
80
|
*/
|
|
80
|
-
constructor(
|
|
81
|
-
baseURL:
|
|
82
|
-
config: { authToken: AuthServerToken; repository: string },
|
|
83
|
-
) {
|
|
84
|
-
super(baseURL, config.authToken, { repository: config.repository });
|
|
81
|
+
constructor(baseURL: string, config: { authToken: AuthServerToken; repository: string }) {
|
|
82
|
+
super(baseURL, config.authToken, { repository: config.repository })
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
/**
|
|
88
86
|
* Uploads an asset file to the server.
|
|
89
87
|
*
|
|
90
88
|
* @param data - The payload containing the file and filename.
|
|
91
|
-
*
|
|
92
89
|
* @returns The API response containing asset information.
|
|
93
|
-
*
|
|
94
90
|
* @throws An error if the upload fails.
|
|
95
91
|
*/
|
|
96
92
|
async createAsset(data: AssetApiCreatePayload): Promise<AssetApiResponse> {
|
|
97
|
-
const context = await this.getContext()
|
|
93
|
+
const context = await this.getContext()
|
|
98
94
|
|
|
99
95
|
const result = await context.post("assets", {
|
|
100
96
|
multipart: { file: data },
|
|
101
|
-
})
|
|
97
|
+
})
|
|
102
98
|
|
|
103
99
|
if (200 !== result.status()) {
|
|
104
|
-
await logPlaywrightApiResponse(result)
|
|
105
|
-
throw new Error("Could not upload the asset with the asset API.")
|
|
100
|
+
await logPlaywrightApiResponse(result)
|
|
101
|
+
throw new Error("Could not upload the asset with the asset API.")
|
|
106
102
|
}
|
|
107
103
|
|
|
108
|
-
return result.json()
|
|
104
|
+
return result.json()
|
|
109
105
|
}
|
|
110
106
|
|
|
111
107
|
/**
|
|
112
108
|
* Patch an existing asset.
|
|
113
109
|
*
|
|
114
110
|
* @param args - Asset id + the payload
|
|
115
|
-
*
|
|
116
111
|
* @returns The API response containing asset information.
|
|
117
|
-
*
|
|
118
112
|
* @throws An error if the upload fails.
|
|
119
113
|
*/
|
|
120
114
|
async patchAsset(args: PatchAssetArgs): Promise<AssetApiResponse> {
|
|
121
|
-
const context = await this.getContext()
|
|
122
|
-
const { assetId, ...data } = args
|
|
123
|
-
const result = await context.patch(`assets/${assetId}`, { data })
|
|
115
|
+
const context = await this.getContext()
|
|
116
|
+
const { assetId, ...data } = args
|
|
117
|
+
const result = await context.patch(`assets/${assetId}`, { data })
|
|
124
118
|
|
|
125
119
|
if (200 !== result.status()) {
|
|
126
|
-
await logPlaywrightApiResponse(result)
|
|
127
|
-
throw new Error("Could not search the asset API.")
|
|
120
|
+
await logPlaywrightApiResponse(result)
|
|
121
|
+
throw new Error("Could not search the asset API.")
|
|
128
122
|
}
|
|
129
123
|
|
|
130
|
-
return result.json()
|
|
124
|
+
return result.json()
|
|
131
125
|
}
|
|
132
126
|
|
|
133
127
|
/**
|
|
134
128
|
* Searches for assets.
|
|
135
129
|
*
|
|
136
130
|
* @param params - Optional parameters to refine search results.
|
|
137
|
-
*
|
|
138
131
|
* @returns The API response containing assets.
|
|
139
132
|
*/
|
|
140
133
|
async search(params?: AssetApiSearchParams): Promise<AssetApiSearchResponse> {
|
|
141
|
-
const context = await this.getContext()
|
|
142
|
-
const { ids, ...rest } = params ?? {}
|
|
143
|
-
const query = new URLSearchParams()
|
|
134
|
+
const context = await this.getContext()
|
|
135
|
+
const { ids, ...rest } = params ?? {}
|
|
136
|
+
const query = new URLSearchParams()
|
|
144
137
|
for (const [key, value] of Object.entries(rest)) {
|
|
145
138
|
if (value !== undefined) {
|
|
146
|
-
query.set(key, String(value))
|
|
139
|
+
query.set(key, String(value))
|
|
147
140
|
}
|
|
148
141
|
}
|
|
149
142
|
for (const id of ids ?? []) {
|
|
150
|
-
query.append("ids", id)
|
|
143
|
+
query.append("ids", id)
|
|
151
144
|
}
|
|
152
|
-
const url = query.size ? `assets?${query}` : "assets"
|
|
145
|
+
const url = query.size ? `assets?${query}` : "assets"
|
|
153
146
|
|
|
154
|
-
const result = await context.get(url)
|
|
147
|
+
const result = await context.get(url)
|
|
155
148
|
|
|
156
149
|
if (200 !== result.status()) {
|
|
157
|
-
await logPlaywrightApiResponse(result)
|
|
158
|
-
throw new Error("Could not search the asset API.")
|
|
150
|
+
await logPlaywrightApiResponse(result)
|
|
151
|
+
throw new Error("Could not search the asset API.")
|
|
159
152
|
}
|
|
160
153
|
|
|
161
|
-
return result.json()
|
|
154
|
+
return result.json()
|
|
162
155
|
}
|
|
163
156
|
}
|
|
@@ -1,84 +1,111 @@
|
|
|
1
|
-
import { APIRequestContext
|
|
1
|
+
import type { APIRequestContext } from "@playwright/test"
|
|
2
|
+
import { request } from "@playwright/test"
|
|
2
3
|
|
|
3
|
-
import { AuthConfig } from "../types"
|
|
4
|
+
import type { AuthConfig } from "../types"
|
|
5
|
+
import { logPlaywrightApiResponse, logger } from "../utils/log"
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
const AUTH_API_TOKENS_ENV = "PRISMIC_E2E_TEST_UTILS_AUTH_API_TOKENS"
|
|
8
|
+
|
|
9
|
+
function getAuthApiTokenFromEnv(email: string): string | undefined {
|
|
10
|
+
const value = process.env[AUTH_API_TOKENS_ENV]
|
|
11
|
+
if (!value) {
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const entry of value.split(",")) {
|
|
16
|
+
const separatorIndex = entry.indexOf(":")
|
|
17
|
+
if (separatorIndex === -1) {
|
|
18
|
+
continue
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const entryEmail = entry.slice(0, separatorIndex).trim()
|
|
22
|
+
const token = entry.slice(separatorIndex + 1).trim()
|
|
23
|
+
if (entryEmail === email && token) {
|
|
24
|
+
return token
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
6
30
|
|
|
7
31
|
/** Client for interacting with the authentication service to manage tokens */
|
|
8
32
|
export class AuthenticationApiClient {
|
|
9
|
-
private authToken?: string
|
|
10
|
-
private _context?: APIRequestContext
|
|
33
|
+
private authToken?: string
|
|
34
|
+
private _context?: APIRequestContext
|
|
11
35
|
|
|
12
36
|
constructor(
|
|
13
37
|
private readonly baseURL: string,
|
|
14
38
|
private readonly auth: AuthConfig,
|
|
15
|
-
) {
|
|
39
|
+
) {
|
|
40
|
+
this.authToken = getAuthApiTokenFromEnv(auth.email)
|
|
41
|
+
if (this.authToken) {
|
|
42
|
+
logger.info(`using user token for ${auth.email} from ${AUTH_API_TOKENS_ENV}`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
16
45
|
|
|
17
46
|
private async getContext(): Promise<APIRequestContext> {
|
|
18
47
|
if (!this._context) {
|
|
19
48
|
this._context = await request.newContext({
|
|
20
49
|
baseURL: this.baseURL,
|
|
21
|
-
})
|
|
50
|
+
})
|
|
22
51
|
}
|
|
23
52
|
|
|
24
|
-
return this._context
|
|
53
|
+
return this._context
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
private async login(): Promise<string> {
|
|
28
|
-
const profiler = logger.startTimer()
|
|
57
|
+
const profiler = logger.startTimer()
|
|
29
58
|
|
|
30
|
-
const context = await this.getContext()
|
|
59
|
+
const context = await this.getContext()
|
|
31
60
|
const result = await context.post("login", {
|
|
32
61
|
data: {
|
|
33
62
|
email: this.auth.email,
|
|
34
63
|
password: this.auth.password,
|
|
35
64
|
},
|
|
36
|
-
})
|
|
65
|
+
})
|
|
37
66
|
|
|
38
|
-
const token = await result.text()
|
|
67
|
+
const token = await result.text()
|
|
39
68
|
if (!result.ok() || !token) {
|
|
40
|
-
logPlaywrightApiResponse(result)
|
|
41
|
-
throw new Error("Authentication failed, no token received.")
|
|
69
|
+
logPlaywrightApiResponse(result)
|
|
70
|
+
throw new Error("Authentication failed, no token received.")
|
|
42
71
|
}
|
|
43
72
|
|
|
44
73
|
profiler.done({
|
|
45
74
|
message: `generated user token for ${this.auth.email} from auth service`,
|
|
46
|
-
})
|
|
75
|
+
})
|
|
47
76
|
|
|
48
|
-
return token
|
|
77
|
+
return token
|
|
49
78
|
}
|
|
50
79
|
|
|
51
80
|
/** Return an api user token. Creates one if needed. */
|
|
52
81
|
async getToken(): Promise<string> {
|
|
53
82
|
if (!this.authToken) {
|
|
54
|
-
this.authToken = await this.login()
|
|
83
|
+
this.authToken = await this.login()
|
|
55
84
|
}
|
|
56
85
|
|
|
57
|
-
return this.authToken
|
|
86
|
+
return this.authToken
|
|
58
87
|
}
|
|
59
88
|
|
|
60
89
|
/** Return an api user token. Creates one if needed. */
|
|
61
90
|
async getMachine2MachineToken(repository: string): Promise<string> {
|
|
62
91
|
if (!this.authToken) {
|
|
63
|
-
this.authToken = await this.login()
|
|
92
|
+
this.authToken = await this.login()
|
|
64
93
|
}
|
|
65
94
|
|
|
66
|
-
const context = await this.getContext()
|
|
95
|
+
const context = await this.getContext()
|
|
67
96
|
const result = await context.get("machine2machine", {
|
|
68
97
|
headers: {
|
|
69
98
|
Authorization: `Bearer ${this.authToken}`,
|
|
70
99
|
repository,
|
|
71
100
|
},
|
|
72
|
-
})
|
|
101
|
+
})
|
|
73
102
|
|
|
74
103
|
if (!result.ok()) {
|
|
75
|
-
logPlaywrightApiResponse(result)
|
|
76
|
-
throw new Error(
|
|
77
|
-
"Machine2Machine token generation failed, no token received.",
|
|
78
|
-
);
|
|
104
|
+
logPlaywrightApiResponse(result)
|
|
105
|
+
throw new Error("Machine2Machine token generation failed, no token received.")
|
|
79
106
|
}
|
|
80
|
-
const token = (await result.json()).token
|
|
107
|
+
const token = (await result.json()).token
|
|
81
108
|
|
|
82
|
-
return token
|
|
109
|
+
return token
|
|
83
110
|
}
|
|
84
111
|
}
|