@prismicio/e2e-tests-utils 1.18.0 → 1.19.0
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 -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 +529 -616
- 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 -307
- package/dist/managers/repository.d.ts.map +1 -0
- package/dist/managers/repository.js +529 -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 +109 -129
- package/src/clients/coreApi.ts +113 -117
- package/src/clients/customTypesApi.ts +54 -76
- 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 +303 -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
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AxiosInstance } from "axios"
|
|
2
|
+
import axios from "axios"
|
|
2
3
|
|
|
3
|
-
import { IntegrationFieldConfig, IntegrationFieldData } from "../types"
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { CustomTypesApiClient } from "./customTypesApi";
|
|
9
|
-
import { WroomClient } from "./wroom";
|
|
4
|
+
import type { IntegrationFieldConfig, IntegrationFieldData } from "../types"
|
|
5
|
+
import { logHttpResponse } from "../utils/log"
|
|
6
|
+
import { slugify } from "../utils/strings"
|
|
7
|
+
import type { CustomTypesApiClient } from "./customTypesApi"
|
|
8
|
+
import type { WroomClient } from "./wroom"
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
|
-
* Client for interacting with Integration Fields routes to create integration
|
|
13
|
-
*
|
|
11
|
+
* Client for interacting with Integration Fields routes to create integration field catalogs and
|
|
12
|
+
* add them to custom type fields.
|
|
14
13
|
*/
|
|
15
14
|
export class IntegrationFieldsClient {
|
|
16
|
-
private readonly baseURL: string
|
|
17
|
-
private readonly customTypesApiClient: CustomTypesApiClient
|
|
18
|
-
private readonly wroomClient: WroomClient
|
|
19
|
-
private readonly repository: string
|
|
20
|
-
private readonly tokens: Record<string, string> = {}
|
|
15
|
+
private readonly baseURL: string
|
|
16
|
+
private readonly customTypesApiClient: CustomTypesApiClient
|
|
17
|
+
private readonly wroomClient: WroomClient
|
|
18
|
+
private readonly repository: string
|
|
19
|
+
private readonly tokens: Record<string, string> = {}
|
|
21
20
|
|
|
22
21
|
constructor(
|
|
23
22
|
baseURL: string,
|
|
24
23
|
config: {
|
|
25
|
-
customTypesApiClient: CustomTypesApiClient
|
|
26
|
-
wroomClient: WroomClient
|
|
27
|
-
repository: string
|
|
24
|
+
customTypesApiClient: CustomTypesApiClient
|
|
25
|
+
wroomClient: WroomClient
|
|
26
|
+
repository: string
|
|
28
27
|
},
|
|
29
28
|
) {
|
|
30
|
-
this.baseURL = baseURL
|
|
31
|
-
this.customTypesApiClient = config.customTypesApiClient
|
|
32
|
-
this.wroomClient = config.wroomClient
|
|
33
|
-
this.repository = config.repository
|
|
29
|
+
this.baseURL = baseURL
|
|
30
|
+
this.customTypesApiClient = config.customTypesApiClient
|
|
31
|
+
this.wroomClient = config.wroomClient
|
|
32
|
+
this.repository = config.repository
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
private async getClient(catalogId: string): Promise<AxiosInstance> {
|
|
37
|
-
const token = this.tokens[catalogId] || (await this.createToken(catalogId))
|
|
36
|
+
const token = this.tokens[catalogId] || (await this.createToken(catalogId))
|
|
38
37
|
|
|
39
38
|
const client = axios.create({
|
|
40
39
|
baseURL: `${this.baseURL}/if/`,
|
|
@@ -44,17 +43,17 @@ export class IntegrationFieldsClient {
|
|
|
44
43
|
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
45
44
|
Authorization: `Bearer ${token}`,
|
|
46
45
|
},
|
|
47
|
-
})
|
|
46
|
+
})
|
|
48
47
|
|
|
49
|
-
return client
|
|
48
|
+
return client
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
private async addCatalog({
|
|
53
52
|
name,
|
|
54
53
|
description,
|
|
55
54
|
}: {
|
|
56
|
-
name: string
|
|
57
|
-
description: string
|
|
55
|
+
name: string
|
|
56
|
+
description: string
|
|
58
57
|
}): Promise<string> {
|
|
59
58
|
const response = await this.wroomClient.post(
|
|
60
59
|
this.repository,
|
|
@@ -63,60 +62,52 @@ export class IntegrationFieldsClient {
|
|
|
63
62
|
"catalog-name": name,
|
|
64
63
|
"catalog-description": description,
|
|
65
64
|
},
|
|
66
|
-
)
|
|
65
|
+
)
|
|
67
66
|
|
|
68
|
-
const { data, status } = response
|
|
67
|
+
const { data, status } = response
|
|
69
68
|
const success =
|
|
70
69
|
status === 200 ||
|
|
71
|
-
(status === 400 &&
|
|
72
|
-
(data as string).includes("Already existing integration field"));
|
|
70
|
+
(status === 400 && (data as string).includes("Already existing integration field"))
|
|
73
71
|
if (!success) {
|
|
74
|
-
logHttpResponse(response)
|
|
75
|
-
throw new Error(`Could not add integration field catalog ${name}`)
|
|
72
|
+
logHttpResponse(response)
|
|
73
|
+
throw new Error(`Could not add integration field catalog ${name}`)
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
return `${this.repository}--${slugify(name)}
|
|
76
|
+
return `${this.repository}--${slugify(name)}`
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
private async createToken(catalogId: string): Promise<string> {
|
|
82
80
|
const response = await this.wroomClient.post(
|
|
83
81
|
this.repository,
|
|
84
82
|
`app/settings/integrationfields/pushcustom/${catalogId}/token`,
|
|
85
|
-
)
|
|
83
|
+
)
|
|
86
84
|
|
|
87
|
-
const { data: tokenData, status } = response
|
|
85
|
+
const { data: tokenData, status } = response
|
|
88
86
|
if (status !== 201) {
|
|
89
|
-
logHttpResponse(response)
|
|
90
|
-
throw new Error(
|
|
91
|
-
`Could not create token for integration field catalog ${catalogId}`,
|
|
92
|
-
);
|
|
87
|
+
logHttpResponse(response)
|
|
88
|
+
throw new Error(`Could not create token for integration field catalog ${catalogId}`)
|
|
93
89
|
}
|
|
94
90
|
|
|
95
|
-
const token = tokenData[0]
|
|
96
|
-
this.tokens[catalogId] = token
|
|
91
|
+
const token = tokenData[0]
|
|
92
|
+
this.tokens[catalogId] = token
|
|
97
93
|
|
|
98
|
-
return token
|
|
94
|
+
return token
|
|
99
95
|
}
|
|
100
96
|
|
|
101
97
|
private async addDataToCatalog({
|
|
102
98
|
catalogId,
|
|
103
99
|
data,
|
|
104
100
|
}: {
|
|
105
|
-
catalogId: string
|
|
106
|
-
data: IntegrationFieldData[]
|
|
101
|
+
catalogId: string
|
|
102
|
+
data: IntegrationFieldData[]
|
|
107
103
|
}): Promise<void> {
|
|
108
|
-
const client = await this.getClient(catalogId)
|
|
109
|
-
const response = await client.post(
|
|
110
|
-
`/write/${catalogId}`,
|
|
111
|
-
JSON.stringify(data),
|
|
112
|
-
);
|
|
104
|
+
const client = await this.getClient(catalogId)
|
|
105
|
+
const response = await client.post(`/write/${catalogId}`, JSON.stringify(data))
|
|
113
106
|
|
|
114
|
-
const { status } = response
|
|
107
|
+
const { status } = response
|
|
115
108
|
if (status !== 200) {
|
|
116
|
-
logHttpResponse(response)
|
|
117
|
-
throw new Error(
|
|
118
|
-
`Could not add data to integration field catalog ${catalogId}`,
|
|
119
|
-
);
|
|
109
|
+
logHttpResponse(response)
|
|
110
|
+
throw new Error(`Could not add data to integration field catalog ${catalogId}`)
|
|
120
111
|
}
|
|
121
112
|
}
|
|
122
113
|
|
|
@@ -125,35 +116,29 @@ export class IntegrationFieldsClient {
|
|
|
125
116
|
customTypeId,
|
|
126
117
|
fieldId,
|
|
127
118
|
}: {
|
|
128
|
-
catalogId: string
|
|
129
|
-
customTypeId: string
|
|
130
|
-
fieldId: string
|
|
119
|
+
catalogId: string
|
|
120
|
+
customTypeId: string
|
|
121
|
+
fieldId: string
|
|
131
122
|
}): Promise<void> {
|
|
132
|
-
const customType =
|
|
133
|
-
await this.customTypesApiClient.getTypeById(customTypeId);
|
|
123
|
+
const customType = await this.customTypesApiClient.getTypeById(customTypeId)
|
|
134
124
|
|
|
135
|
-
const field = customType.json.Main[fieldId]
|
|
125
|
+
const field = customType.json.Main[fieldId]
|
|
136
126
|
if (!field || field.type !== "IntegrationFields") {
|
|
137
|
-
throw new Error(
|
|
138
|
-
`Field ${fieldId} not found or is not an Integration Field`,
|
|
139
|
-
);
|
|
127
|
+
throw new Error(`Field ${fieldId} not found or is not an Integration Field`)
|
|
140
128
|
}
|
|
141
129
|
|
|
142
|
-
field.config = { ...
|
|
130
|
+
field.config = { ...field.config, catalog: catalogId }
|
|
143
131
|
|
|
144
|
-
await this.customTypesApiClient.createCustomTypes([customType])
|
|
132
|
+
await this.customTypesApiClient.createCustomTypes([customType])
|
|
145
133
|
}
|
|
146
134
|
|
|
147
|
-
async setupIntegrationFields(
|
|
148
|
-
integrationFields: IntegrationFieldConfig[],
|
|
149
|
-
): Promise<void> {
|
|
135
|
+
async setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {
|
|
150
136
|
for (const integrationField of integrationFields) {
|
|
151
|
-
const { name, description, customTypeId, fieldId, data } =
|
|
152
|
-
integrationField;
|
|
137
|
+
const { name, description, customTypeId, fieldId, data } = integrationField
|
|
153
138
|
|
|
154
|
-
const catalogId = await this.addCatalog({ name, description })
|
|
155
|
-
await this.addDataToCatalog({ catalogId, data })
|
|
156
|
-
await this.addToCustomType({ catalogId, customTypeId, fieldId })
|
|
139
|
+
const catalogId = await this.addCatalog({ name, description })
|
|
140
|
+
await this.addDataToCatalog({ catalogId, data })
|
|
141
|
+
await this.addToCustomType({ catalogId, customTypeId, fieldId })
|
|
157
142
|
}
|
|
158
143
|
}
|
|
159
144
|
}
|
package/src/clients/manageV2.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from "axios"
|
|
2
|
+
import axios from "axios"
|
|
3
|
+
import jwt from "jsonwebtoken"
|
|
3
4
|
|
|
4
|
-
import { ManageV2Config } from "../types"
|
|
5
|
+
import type { ManageV2Config } from "../types"
|
|
6
|
+
import { extractCookie } from "../utils/cookies"
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const ManageV2StaticAuthor = "prismic-e2e-tests-utils"
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Client for interacting with ManageV2 routes to perform operations on
|
|
12
|
-
* repositories.
|
|
13
|
-
*/
|
|
10
|
+
/** Client for interacting with ManageV2 routes to perform operations on repositories. */
|
|
14
11
|
export class ManageV2Client {
|
|
15
|
-
readonly client: AxiosInstance
|
|
16
|
-
private token: string | null = null
|
|
12
|
+
readonly client: AxiosInstance // Not private to have it available on tests
|
|
13
|
+
private token: string | null = null
|
|
17
14
|
|
|
18
15
|
/**
|
|
19
16
|
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
20
17
|
* @param config - ManageV2 configuration variable to call ManageV2.
|
|
21
18
|
*/
|
|
22
19
|
constructor(baseUrl: string, config?: ManageV2Config | undefined) {
|
|
23
|
-
this.token = config ? this.generateToken(config) : null
|
|
20
|
+
this.token = config ? this.generateToken(config) : null
|
|
24
21
|
|
|
25
22
|
this.client = axios.create({
|
|
26
23
|
baseURL: `${baseUrl}/manageroutes/`,
|
|
@@ -30,109 +27,91 @@ export class ManageV2Client {
|
|
|
30
27
|
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
31
28
|
Authorization: `Bearer ${this.token}`,
|
|
32
29
|
},
|
|
33
|
-
})
|
|
30
|
+
})
|
|
34
31
|
|
|
35
32
|
// cookies are not forwarded automatically in a non-browser env
|
|
36
33
|
this.client.interceptors.response.use((response) => {
|
|
37
|
-
const cookies = response.headers["set-cookie"]
|
|
34
|
+
const cookies = response.headers["set-cookie"]
|
|
38
35
|
if (cookies && extractCookie(cookies, "SESSION")) {
|
|
39
|
-
this.client.defaults.headers["Cookie"] = cookies
|
|
36
|
+
this.client.defaults.headers["Cookie"] = cookies
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
return response
|
|
43
|
-
})
|
|
39
|
+
return response
|
|
40
|
+
})
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
|
-
* The function generates a JWT token using the provided configuration
|
|
48
|
-
* parameters.
|
|
49
|
-
*
|
|
50
|
-
* @param {ManageV2Config} config - The `config` parameter in the
|
|
51
|
-
* `generateToken` function is of type `ManageV2Config`. It contains the
|
|
52
|
-
* following properties:
|
|
44
|
+
* The function generates a JWT token using the provided configuration parameters.
|
|
53
45
|
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
*
|
|
46
|
+
* @param {ManageV2Config} config - The `config` parameter in the `generateToken` function is of
|
|
47
|
+
* type `ManageV2Config`. It contains the following properties:
|
|
48
|
+
* @returns A JSON Web Token (JWT) is being returned by the `generateToken` function. The token is
|
|
49
|
+
* signed using the provided `config.secret` with the HS256 algorithm and includes the specified
|
|
50
|
+
* audience and issuer values.
|
|
57
51
|
*/
|
|
58
52
|
private generateToken(config: ManageV2Config): string {
|
|
59
53
|
return jwt.sign({}, config.secret, {
|
|
60
54
|
algorithm: "HS256",
|
|
61
55
|
audience: config.audience,
|
|
62
56
|
issuer: "prismic.io",
|
|
63
|
-
})
|
|
57
|
+
})
|
|
64
58
|
}
|
|
65
59
|
|
|
66
60
|
/**
|
|
67
|
-
* The function `assertTokenExist` checks if a token exists before executing a
|
|
68
|
-
* given function.
|
|
61
|
+
* The function `assertTokenExist` checks if a token exists before executing a given function.
|
|
69
62
|
*
|
|
70
|
-
* @param f - The `assertTokenExist` function takes a function `f` as a
|
|
71
|
-
*
|
|
72
|
-
* `
|
|
73
|
-
* `assertTokenExist` function ensures that a token is not null before
|
|
63
|
+
* @param f - The `assertTokenExist` function takes a function `f` as a parameter. This function
|
|
64
|
+
* `f` should accept a parameter of type `Parameters` and return a Promise that resolves to an
|
|
65
|
+
* AxiosResponse. The `assertTokenExist` function ensures that a token is not null before
|
|
74
66
|
* calling the provided
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* error is thrown. Otherwise, the function f is called with the provided
|
|
79
|
-
* parameters.
|
|
67
|
+
* @returns A function is being returned that takes a parameter of type Parameters and checks if
|
|
68
|
+
* the token is null. If the token is null, an error is thrown. Otherwise, the function f is
|
|
69
|
+
* called with the provided parameters.
|
|
80
70
|
*/
|
|
81
|
-
private assertTokenExist<Parameters>(
|
|
82
|
-
f: (_: Parameters) => Promise<AxiosResponse>,
|
|
83
|
-
) {
|
|
71
|
+
private assertTokenExist<Parameters>(f: (_: Parameters) => Promise<AxiosResponse>) {
|
|
84
72
|
return (params: Parameters) => {
|
|
85
73
|
if (this.token === null) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
"Undefined configuration for ManageV2 while trying to use it's routes",
|
|
88
|
-
);
|
|
74
|
+
throw new Error("Undefined configuration for ManageV2 while trying to use it's routes")
|
|
89
75
|
} else {
|
|
90
|
-
return f(params)
|
|
76
|
+
return f(params)
|
|
91
77
|
}
|
|
92
|
-
}
|
|
78
|
+
}
|
|
93
79
|
}
|
|
94
80
|
|
|
95
81
|
getBaseURL(): string {
|
|
96
|
-
return this.client.getUri()
|
|
82
|
+
return this.client.getUri()
|
|
97
83
|
}
|
|
98
84
|
|
|
99
85
|
/**
|
|
100
|
-
* The function `toggleRolePerLocal` enables or disables the RolesPerLocale
|
|
101
|
-
* workflow
|
|
86
|
+
* The function `toggleRolePerLocal` enables or disables the RolesPerLocale workflow
|
|
102
87
|
*
|
|
103
88
|
* @param repository - The Repository name
|
|
104
89
|
* @param enabled - The feature new status
|
|
105
90
|
*/
|
|
106
|
-
toggleRolePerLocal = this.assertTokenExist(
|
|
107
|
-
(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
},
|
|
114
|
-
);
|
|
91
|
+
toggleRolePerLocal = this.assertTokenExist((params: { repository: string; enabled: boolean }) => {
|
|
92
|
+
return this.client.post("/repository/toggleRolesPerLocale", {
|
|
93
|
+
domain: params.repository,
|
|
94
|
+
enabled: params.enabled,
|
|
95
|
+
author: ManageV2StaticAuthor,
|
|
96
|
+
})
|
|
97
|
+
})
|
|
115
98
|
|
|
116
99
|
/**
|
|
117
|
-
* The function `toggleCustomRoles` enables or disables the CustomRoles
|
|
118
|
-
* workflow
|
|
100
|
+
* The function `toggleCustomRoles` enables or disables the CustomRoles workflow
|
|
119
101
|
*
|
|
120
102
|
* @param repository - The Repository name
|
|
121
103
|
* @param enabled - The feature new status
|
|
122
104
|
*/
|
|
123
|
-
toggleCustomRoles = this.assertTokenExist(
|
|
124
|
-
(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
},
|
|
131
|
-
);
|
|
105
|
+
toggleCustomRoles = this.assertTokenExist((params: { repository: string; enabled: boolean }) => {
|
|
106
|
+
return this.client.post("/repository/toggleCustomRoles", {
|
|
107
|
+
domain: params.repository,
|
|
108
|
+
enabled: params.enabled,
|
|
109
|
+
author: ManageV2StaticAuthor,
|
|
110
|
+
})
|
|
111
|
+
})
|
|
132
112
|
|
|
133
113
|
/**
|
|
134
|
-
* The function `toggleIntegrationFields` enables or disables the Integration
|
|
135
|
-
* Fields feature
|
|
114
|
+
* The function `toggleIntegrationFields` enables or disables the Integration Fields feature
|
|
136
115
|
*
|
|
137
116
|
* @param repository - The Repository name
|
|
138
117
|
* @param enabled - The feature new status
|
|
@@ -143,17 +122,17 @@ export class ManageV2Client {
|
|
|
143
122
|
domain: params.repository,
|
|
144
123
|
enabled: params.enabled,
|
|
145
124
|
author: ManageV2StaticAuthor,
|
|
146
|
-
})
|
|
125
|
+
})
|
|
147
126
|
},
|
|
148
|
-
)
|
|
127
|
+
)
|
|
149
128
|
|
|
150
129
|
/**
|
|
151
130
|
* The function `changePlan` changes the plan of a repository the database
|
|
152
131
|
*
|
|
153
132
|
* @param repository - The Repository name
|
|
154
133
|
* @param newPlanId - The new planId
|
|
155
|
-
* @param bypassManualBilling - Beware that using this will not verify that
|
|
156
|
-
*
|
|
134
|
+
* @param bypassManualBilling - Beware that using this will not verify that the database and
|
|
135
|
+
* Stripe are in sync
|
|
157
136
|
*/
|
|
158
137
|
changePlan = this.assertTokenExist(
|
|
159
138
|
({
|
|
@@ -161,24 +140,21 @@ export class ManageV2Client {
|
|
|
161
140
|
newPlanId,
|
|
162
141
|
bypassManualBilling = false,
|
|
163
142
|
}: {
|
|
164
|
-
repository: string
|
|
165
|
-
newPlanId: string
|
|
166
|
-
bypassManualBilling?: boolean
|
|
143
|
+
repository: string
|
|
144
|
+
newPlanId: string
|
|
145
|
+
bypassManualBilling?: boolean
|
|
167
146
|
}) => {
|
|
168
|
-
return this.client.post(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
author: ManageV2StaticAuthor,
|
|
174
|
-
},
|
|
175
|
-
);
|
|
147
|
+
return this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {
|
|
148
|
+
domain: repository,
|
|
149
|
+
newPlan: newPlanId,
|
|
150
|
+
author: ManageV2StaticAuthor,
|
|
151
|
+
})
|
|
176
152
|
},
|
|
177
|
-
)
|
|
153
|
+
)
|
|
178
154
|
|
|
179
155
|
/**
|
|
180
|
-
* The function `addUserToRepository` adds a user corresponding to the email
|
|
181
|
-
*
|
|
156
|
+
* The function `addUserToRepository` adds a user corresponding to the email to the given
|
|
157
|
+
* repository
|
|
182
158
|
*
|
|
183
159
|
* @param repository - The Repository name
|
|
184
160
|
* @param email - The user email
|
|
@@ -189,13 +165,13 @@ export class ManageV2Client {
|
|
|
189
165
|
domain: repository,
|
|
190
166
|
email: email,
|
|
191
167
|
author: ManageV2StaticAuthor,
|
|
192
|
-
})
|
|
168
|
+
})
|
|
193
169
|
},
|
|
194
|
-
)
|
|
170
|
+
)
|
|
195
171
|
|
|
196
172
|
/**
|
|
197
|
-
* The function `removeUserFromRepository` removes a user corresponding to the
|
|
198
|
-
*
|
|
173
|
+
* The function `removeUserFromRepository` removes a user corresponding to the email from the
|
|
174
|
+
* given repository
|
|
199
175
|
*
|
|
200
176
|
* @param repository - The Repository name
|
|
201
177
|
* @param email - The user email
|
|
@@ -206,7 +182,7 @@ export class ManageV2Client {
|
|
|
206
182
|
domain: repository,
|
|
207
183
|
email: email,
|
|
208
184
|
author: ManageV2StaticAuthor,
|
|
209
|
-
})
|
|
185
|
+
})
|
|
210
186
|
},
|
|
211
|
-
)
|
|
187
|
+
)
|
|
212
188
|
}
|
|
@@ -1,62 +1,58 @@
|
|
|
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 type MigrationApiDocumentPayload = {
|
|
6
|
-
uid?: string | null
|
|
7
|
-
type: string
|
|
8
|
-
lang: string
|
|
9
|
-
title: string
|
|
10
|
-
tags?: string[]
|
|
11
|
-
alternate_language_id?: string
|
|
12
|
-
data: Record<string, unknown
|
|
6
|
+
uid?: string | null
|
|
7
|
+
type: string
|
|
8
|
+
lang: string
|
|
9
|
+
title: string
|
|
10
|
+
tags?: string[]
|
|
11
|
+
alternate_language_id?: string
|
|
12
|
+
data: Record<string, unknown>
|
|
13
13
|
// if true, the document will be part of the documents list instead of in the migration release
|
|
14
|
-
inDocuments?: boolean
|
|
15
|
-
}
|
|
14
|
+
inDocuments?: boolean
|
|
15
|
+
}
|
|
16
16
|
export type MigrationApiDocumentResponse = {
|
|
17
|
-
id: string
|
|
18
|
-
type: string
|
|
19
|
-
lang: string
|
|
20
|
-
title: string
|
|
21
|
-
uid?: string
|
|
22
|
-
}
|
|
17
|
+
id: string
|
|
18
|
+
type: string
|
|
19
|
+
lang: string
|
|
20
|
+
title: string
|
|
21
|
+
uid?: string
|
|
22
|
+
}
|
|
23
23
|
|
|
24
24
|
export class MigrationApiClient extends AuthenticatedApiClient {
|
|
25
25
|
/**
|
|
26
|
-
* @example
|
|
26
|
+
* @example
|
|
27
|
+
* To instantiate the class:
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* ```js
|
|
30
|
+
* new MigrationApiClient("https://migration.prismic.io", {
|
|
30
31
|
* authToken: "my-secret-token",
|
|
31
32
|
* repository: "my-repo-name",
|
|
32
|
-
*
|
|
33
|
-
*
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
34
35
|
*
|
|
35
|
-
* @param baseURL -
|
|
36
|
+
* @param baseURL - The api base URL like https://migration.prismic.io
|
|
36
37
|
* @param config - Optional configuration
|
|
37
38
|
*
|
|
38
|
-
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
39
|
-
*
|
|
39
|
+
* - {@link config.authToken}: Api token generated from the auth service or a function to fetch it
|
|
40
|
+
* when it's needed.
|
|
40
41
|
* - {@link config.repository}: Repository name.
|
|
41
42
|
*/
|
|
42
|
-
constructor(
|
|
43
|
-
baseURL:
|
|
44
|
-
config: { authToken: AuthServerToken; repository: string },
|
|
45
|
-
) {
|
|
46
|
-
super(baseURL, config.authToken, { repository: config.repository });
|
|
43
|
+
constructor(baseURL: string, config: { authToken: AuthServerToken; repository: string }) {
|
|
44
|
+
super(baseURL, config.authToken, { repository: config.repository })
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
async createDocument(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const context = await this.getContext();
|
|
53
|
-
const result = await context.post("documents", { data });
|
|
47
|
+
async createDocument(data: MigrationApiDocumentPayload): Promise<MigrationApiDocumentResponse> {
|
|
48
|
+
const context = await this.getContext()
|
|
49
|
+
const result = await context.post("documents", { data })
|
|
54
50
|
|
|
55
51
|
if (201 !== result.status()) {
|
|
56
|
-
await logPlaywrightApiResponse(result)
|
|
57
|
-
throw new Error("Could not create a document with the migration api.")
|
|
52
|
+
await logPlaywrightApiResponse(result)
|
|
53
|
+
throw new Error("Could not create a document with the migration api.")
|
|
58
54
|
}
|
|
59
55
|
|
|
60
|
-
return result.json()
|
|
56
|
+
return result.json()
|
|
61
57
|
}
|
|
62
58
|
}
|