@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
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import { expect } from "@playwright/test"
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "
|
|
8
|
-
|
|
9
|
-
import { IntegrationFieldConfig } from "../types";
|
|
10
|
-
|
|
11
|
-
import { AssetApiClient } from "../clients/assetApi";
|
|
12
|
-
import { AuthenticationApiClient } from "../clients/authenticationApi";
|
|
13
|
-
import { ContentApiClient } from "../clients/contentApi";
|
|
14
|
-
import {
|
|
1
|
+
import { expect } from "@playwright/test"
|
|
2
|
+
import type { DynamicCustomTypeModel, SharedSliceModel } from "@prismicio/types-internal"
|
|
3
|
+
import type { AxiosResponse } from "axios"
|
|
4
|
+
|
|
5
|
+
import type { AssetApiClient } from "../clients/assetApi"
|
|
6
|
+
import type { AuthenticationApiClient } from "../clients/authenticationApi"
|
|
7
|
+
import { ContentApiClient } from "../clients/contentApi"
|
|
8
|
+
import type {
|
|
15
9
|
CoreApiClient,
|
|
16
10
|
CoreApiDocumentCreationPayload,
|
|
17
11
|
CoreApiDocumentCreationResponse,
|
|
@@ -19,14 +13,15 @@ import {
|
|
|
19
13
|
CoreApiDocumentsPayload,
|
|
20
14
|
CoreApiDocumentsResponse,
|
|
21
15
|
Release,
|
|
22
|
-
} from "../clients/coreApi"
|
|
23
|
-
import { CustomTypesApiClient } from "../clients/customTypesApi"
|
|
24
|
-
import { IntegrationFieldsClient } from "../clients/integrationFields"
|
|
25
|
-
import { ManageV2Client } from "../clients/manageV2"
|
|
26
|
-
import { MigrationApiClient } from "../clients/migrationApi"
|
|
27
|
-
import { WroomClient } from "../clients/wroom"
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
16
|
+
} from "../clients/coreApi"
|
|
17
|
+
import type { CustomTypesApiClient } from "../clients/customTypesApi"
|
|
18
|
+
import type { IntegrationFieldsClient } from "../clients/integrationFields"
|
|
19
|
+
import type { ManageV2Client } from "../clients/manageV2"
|
|
20
|
+
import type { MigrationApiClient } from "../clients/migrationApi"
|
|
21
|
+
import type { WroomClient } from "../clients/wroom"
|
|
22
|
+
import type { IntegrationFieldConfig } from "../types"
|
|
23
|
+
import { logHttpResponse, logger } from "../utils/log"
|
|
24
|
+
import { getRepositoryUrl } from "../utils/urls"
|
|
30
25
|
|
|
31
26
|
/** Utility to manage test data for a Prismic repository */
|
|
32
27
|
export class RepositoryManager {
|
|
@@ -39,25 +34,22 @@ export class RepositoryManager {
|
|
|
39
34
|
private readonly migrationApiClient: MigrationApiClient | undefined,
|
|
40
35
|
private readonly assetApiClient: AssetApiClient,
|
|
41
36
|
private readonly manageV2Client: ManageV2Client,
|
|
42
|
-
private readonly integrationFieldsClient:
|
|
43
|
-
| IntegrationFieldsClient
|
|
44
|
-
| undefined,
|
|
37
|
+
private readonly integrationFieldsClient: IntegrationFieldsClient | undefined,
|
|
45
38
|
) {}
|
|
46
39
|
|
|
47
40
|
async configure(config: RepositoryConfig): Promise<void> {
|
|
48
|
-
const hasLangConfig =
|
|
49
|
-
config.defaultLocale || config.locales || config.customLocale;
|
|
41
|
+
const hasLangConfig = config.defaultLocale || config.locales || config.customLocale
|
|
50
42
|
if (hasLangConfig) {
|
|
51
|
-
const languages = await this.coreApiClient.getLanguages()
|
|
52
|
-
let updateDefaultLocaleAtTheEnd = false
|
|
43
|
+
const languages = await this.coreApiClient.getLanguages()
|
|
44
|
+
let updateDefaultLocaleAtTheEnd = false
|
|
53
45
|
// if no locale exists on repo, the master locale needs to be set first
|
|
54
46
|
if (config.defaultLocale) {
|
|
55
|
-
const master = languages.find(({ is_master }) => is_master === true)
|
|
47
|
+
const master = languages.find(({ is_master }) => is_master === true)
|
|
56
48
|
if (!master) {
|
|
57
|
-
await this.setDefaultLocale(config.defaultLocale, "create")
|
|
49
|
+
await this.setDefaultLocale(config.defaultLocale, "create")
|
|
58
50
|
} else if (master.id !== config.defaultLocale) {
|
|
59
51
|
// update the master lang at the end, after it is created.
|
|
60
|
-
updateDefaultLocaleAtTheEnd = true
|
|
52
|
+
updateDefaultLocaleAtTheEnd = true
|
|
61
53
|
}
|
|
62
54
|
}
|
|
63
55
|
|
|
@@ -65,258 +57,238 @@ export class RepositoryManager {
|
|
|
65
57
|
// No need to add default locale and already existing languages
|
|
66
58
|
const localesToAdd = config.locales.filter(
|
|
67
59
|
(id) => !languages.some((language) => language.id === id),
|
|
68
|
-
)
|
|
60
|
+
)
|
|
69
61
|
if (localesToAdd.length > 0) {
|
|
70
|
-
await this.createLocales(localesToAdd)
|
|
62
|
+
await this.createLocales(localesToAdd)
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
65
|
|
|
74
66
|
if (config.customLocale) {
|
|
75
67
|
if (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {
|
|
76
|
-
await this.createCustomLocale(config.customLocale)
|
|
68
|
+
await this.createCustomLocale(config.customLocale)
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
|
|
80
72
|
if (config.defaultLocale && updateDefaultLocaleAtTheEnd) {
|
|
81
|
-
await this.setDefaultLocale(config.defaultLocale, "update")
|
|
73
|
+
await this.setDefaultLocale(config.defaultLocale, "update")
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
76
|
|
|
85
77
|
if (config.slices) {
|
|
86
|
-
await this.createSlices(config.slices)
|
|
78
|
+
await this.createSlices(config.slices)
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
if (config.customTypes) {
|
|
90
|
-
await this.createCustomTypes(config.customTypes)
|
|
82
|
+
await this.createCustomTypes(config.customTypes)
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
if (config.preview) {
|
|
94
|
-
await this.createPreview(config.preview)
|
|
86
|
+
await this.createPreview(config.preview)
|
|
95
87
|
}
|
|
96
88
|
|
|
97
89
|
if (config.simulatorURL) {
|
|
98
|
-
await this.setSimulatorURL(config.simulatorURL)
|
|
90
|
+
await this.setSimulatorURL(config.simulatorURL)
|
|
99
91
|
}
|
|
100
92
|
|
|
101
93
|
if (config.rolePerLocal) {
|
|
102
|
-
await this.toggleRolePerLocal(true)
|
|
94
|
+
await this.toggleRolePerLocal(true)
|
|
103
95
|
}
|
|
104
96
|
|
|
105
97
|
if (config.customRoles) {
|
|
106
|
-
await this.toggleCustomRoles(true)
|
|
98
|
+
await this.toggleCustomRoles(true)
|
|
107
99
|
}
|
|
108
100
|
|
|
109
101
|
if (config.integrationFields) {
|
|
110
|
-
await this.toggleIntegrationFields(true)
|
|
111
|
-
await this.setupIntegrationFields(config.integrationFields)
|
|
102
|
+
await this.toggleIntegrationFields(true)
|
|
103
|
+
await this.setupIntegrationFields(config.integrationFields)
|
|
112
104
|
}
|
|
113
105
|
}
|
|
114
106
|
|
|
115
|
-
/** @returns
|
|
107
|
+
/** @returns The repository base url, like https://my-repo.prismic.io */
|
|
116
108
|
getBaseURL(): string {
|
|
117
|
-
return getRepositoryUrl(this.wroomClient.getBaseURL(), this.name)
|
|
109
|
+
return getRepositoryUrl(this.wroomClient.getBaseURL(), this.name)
|
|
118
110
|
}
|
|
119
111
|
|
|
120
|
-
/** @returns
|
|
112
|
+
/** @returns The repository base cdn url, like https://my-repo.cdn.prismic.io */
|
|
121
113
|
getBaseCdnURL(): string {
|
|
122
|
-
return getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`)
|
|
114
|
+
return getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`)
|
|
123
115
|
}
|
|
124
116
|
|
|
125
117
|
/**
|
|
126
|
-
* @returns
|
|
127
|
-
*
|
|
128
|
-
*
|
|
118
|
+
* @returns A Content Type api client configured to target the repository CDN url. Uses Playwright
|
|
119
|
+
* for requests so if your project uses Playwright too, any network request will be present in
|
|
120
|
+
* Playwright test reports.
|
|
129
121
|
*/
|
|
130
|
-
getContentApiClient(config?: {
|
|
131
|
-
|
|
132
|
-
accessToken?: string;
|
|
133
|
-
}): ContentApiClient {
|
|
134
|
-
return new ContentApiClient(this.getBaseCdnURL(), config);
|
|
122
|
+
getContentApiClient(config?: { version?: "v1" | "v2"; accessToken?: string }): ContentApiClient {
|
|
123
|
+
return new ContentApiClient(this.getBaseCdnURL(), config)
|
|
135
124
|
}
|
|
136
125
|
|
|
137
126
|
/**
|
|
138
|
-
* @returns
|
|
127
|
+
* @returns An instance of the Migration api client, see
|
|
139
128
|
* https://prismic.io/docs/migration-api-technical-reference
|
|
140
129
|
*/
|
|
141
130
|
getMigrationApiClient(): MigrationApiClient {
|
|
142
131
|
if (!this.migrationApiClient) {
|
|
143
|
-
throw "No client found for the migration api. Did you provide a migration api url in the configuration?"
|
|
132
|
+
throw "No client found for the migration api. Did you provide a migration api url in the configuration?"
|
|
144
133
|
}
|
|
145
134
|
|
|
146
|
-
return this.migrationApiClient
|
|
135
|
+
return this.migrationApiClient
|
|
147
136
|
}
|
|
148
137
|
|
|
149
138
|
/**
|
|
150
|
-
* @returns
|
|
139
|
+
* @returns An instance of the Asset api client, see
|
|
151
140
|
* https://prismic.io/docs/asset-api-technical-reference
|
|
152
141
|
*/
|
|
153
142
|
getAssetApiClient(): AssetApiClient {
|
|
154
|
-
return this.assetApiClient
|
|
143
|
+
return this.assetApiClient
|
|
155
144
|
}
|
|
156
145
|
|
|
157
|
-
/** @returns
|
|
146
|
+
/** @returns The Wroom commit hash deployed on the current repository */
|
|
158
147
|
async getDeployedVersion(): Promise<string | undefined> {
|
|
159
148
|
const response = await this.wroomClient.get(
|
|
160
149
|
this.name,
|
|
161
150
|
"underground/834b34f16f451e00f268dd5c8c81d16e3c020275",
|
|
162
|
-
)
|
|
151
|
+
)
|
|
163
152
|
|
|
164
153
|
// Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute
|
|
165
|
-
return response.data.version
|
|
154
|
+
return response.data.version
|
|
166
155
|
}
|
|
167
156
|
|
|
168
157
|
/**
|
|
169
|
-
* Set additional standard locales for a repository in Wroom, does not fail if
|
|
170
|
-
*
|
|
158
|
+
* Set additional standard locales for a repository in Wroom, does not fail if the locales already
|
|
159
|
+
* exist.
|
|
171
160
|
*
|
|
172
161
|
* @param locales - An array of all locales to be added to the repository.
|
|
173
|
-
*
|
|
174
162
|
* @throws Error if setting the locales fails.
|
|
175
163
|
*/
|
|
176
164
|
async createLocales(locales: string[]): Promise<void> {
|
|
177
|
-
const profiler = logger.startTimer()
|
|
165
|
+
const profiler = logger.startTimer()
|
|
178
166
|
|
|
179
|
-
const response = await this.wroomClient.post(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
{ languages: locales },
|
|
183
|
-
);
|
|
167
|
+
const response = await this.wroomClient.post(this.name, "app/settings/multilanguages", {
|
|
168
|
+
languages: locales,
|
|
169
|
+
})
|
|
184
170
|
|
|
185
|
-
const { data, status } = response
|
|
171
|
+
const { data, status } = response
|
|
186
172
|
const success =
|
|
187
|
-
status === 200 ||
|
|
188
|
-
(status === 400 &&
|
|
189
|
-
(data as string).includes("already existing languages"));
|
|
173
|
+
status === 200 || (status === 400 && (data as string).includes("already existing languages"))
|
|
190
174
|
if (!success) {
|
|
191
|
-
logHttpResponse(response)
|
|
192
|
-
throw new Error(`Could not add locales ${locales.join(", ")}`)
|
|
175
|
+
logHttpResponse(response)
|
|
176
|
+
throw new Error(`Could not add locales ${locales.join(", ")}`)
|
|
193
177
|
}
|
|
194
|
-
profiler.done({ message: `locales '${locales}' created` })
|
|
178
|
+
profiler.done({ message: `locales '${locales}' created` })
|
|
195
179
|
}
|
|
196
180
|
|
|
197
181
|
/**
|
|
198
|
-
* Set additional custom locale for a repository in Wroom, does not fail if
|
|
199
|
-
*
|
|
182
|
+
* Set additional custom locale for a repository in Wroom, does not fail if the locales already
|
|
183
|
+
* exist.
|
|
200
184
|
*
|
|
201
185
|
* @param locale - The locale to be added to the repository.
|
|
202
|
-
*
|
|
203
186
|
* @throws Error if setting the locale fails.
|
|
204
187
|
*/
|
|
205
188
|
async createCustomLocale(locale: CustomLocale): Promise<void> {
|
|
206
|
-
const profiler = logger.startTimer()
|
|
189
|
+
const profiler = logger.startTimer()
|
|
207
190
|
|
|
208
191
|
const response = await this.wroomClient.post(
|
|
209
192
|
this.name,
|
|
210
193
|
"app/settings/multilanguages/custom",
|
|
211
194
|
locale,
|
|
212
|
-
)
|
|
195
|
+
)
|
|
213
196
|
|
|
214
|
-
const { data, status } = response
|
|
197
|
+
const { data, status } = response
|
|
215
198
|
const success =
|
|
216
|
-
status === 200 ||
|
|
217
|
-
(status === 400 && JSON.stringify(data).includes("code is already used"));
|
|
199
|
+
status === 200 || (status === 400 && JSON.stringify(data).includes("code is already used"))
|
|
218
200
|
if (!success) {
|
|
219
|
-
logHttpResponse(response)
|
|
220
|
-
throw new Error(`Could not create custom locale ${locale}`)
|
|
201
|
+
logHttpResponse(response)
|
|
202
|
+
throw new Error(`Could not create custom locale ${locale}`)
|
|
221
203
|
}
|
|
222
204
|
profiler.done({
|
|
223
205
|
message: `custom locale ${JSON.stringify(locale)} created`,
|
|
224
|
-
})
|
|
206
|
+
})
|
|
225
207
|
}
|
|
226
208
|
|
|
227
209
|
private failIfNot200(response: AxiosResponse, msg: string) {
|
|
228
210
|
if (response.status !== 200) {
|
|
229
|
-
logHttpResponse(response)
|
|
230
|
-
throw new Error(msg)
|
|
211
|
+
logHttpResponse(response)
|
|
212
|
+
throw new Error(msg)
|
|
231
213
|
}
|
|
232
214
|
}
|
|
233
215
|
|
|
234
216
|
/**
|
|
235
217
|
* Delete a locale from a repository.
|
|
236
218
|
*
|
|
237
|
-
* @param locale -
|
|
238
|
-
*
|
|
219
|
+
* @param locale - Locale to remove from the repository configuration.
|
|
239
220
|
* @throws Error if deleting the locale fails.
|
|
240
221
|
*/
|
|
241
222
|
async deleteLocale(locale: string): Promise<void> {
|
|
242
|
-
const profiler = logger.startTimer()
|
|
223
|
+
const profiler = logger.startTimer()
|
|
243
224
|
|
|
244
225
|
const response = await this.wroomClient.post(
|
|
245
226
|
this.name,
|
|
246
227
|
`app/settings/multilanguages/${locale}/delete`,
|
|
247
|
-
)
|
|
248
|
-
this.failIfNot200(response, `Could not delete locale ${locale}`)
|
|
249
|
-
profiler.done({ message: `locale '${locale}' deleted` })
|
|
228
|
+
)
|
|
229
|
+
this.failIfNot200(response, `Could not delete locale ${locale}`)
|
|
230
|
+
profiler.done({ message: `locale '${locale}' deleted` })
|
|
250
231
|
}
|
|
251
232
|
|
|
252
233
|
/**
|
|
253
|
-
* Create or update the default (master) locale for a repository in Wroom, the
|
|
254
|
-
*
|
|
234
|
+
* Create or update the default (master) locale for a repository in Wroom, the locale needs to
|
|
235
|
+
* exist in the repository.
|
|
255
236
|
*
|
|
256
237
|
* @param locale - The locale to be set as the default.
|
|
257
|
-
* @param endpoint - "createMasterLang" to create it, "defineAsMaster" to
|
|
258
|
-
* update it.
|
|
259
|
-
*
|
|
238
|
+
* @param endpoint - "createMasterLang" to create it, "defineAsMaster" to update it.
|
|
260
239
|
* @throws Error if setting the default locale fails.
|
|
261
240
|
*/
|
|
262
|
-
async setDefaultLocale(
|
|
263
|
-
|
|
264
|
-
action: "create" | "update",
|
|
265
|
-
): Promise<void> {
|
|
266
|
-
const profiler = logger.startTimer();
|
|
241
|
+
async setDefaultLocale(locale: string, action: "create" | "update"): Promise<void> {
|
|
242
|
+
const profiler = logger.startTimer()
|
|
267
243
|
|
|
268
244
|
const endpoint = {
|
|
269
245
|
create: "createMasterLang",
|
|
270
246
|
update: "defineAsMaster",
|
|
271
|
-
}
|
|
247
|
+
}
|
|
272
248
|
const response = await this.wroomClient.post(
|
|
273
249
|
this.name,
|
|
274
250
|
`/app/settings/multilanguages/${locale}/${endpoint[action]}`,
|
|
275
|
-
)
|
|
251
|
+
)
|
|
276
252
|
|
|
277
|
-
const { data, status } = response
|
|
253
|
+
const { data, status } = response
|
|
278
254
|
const success =
|
|
279
255
|
status === 200 ||
|
|
280
256
|
(status === 400 &&
|
|
281
257
|
// returns 400 if master lang is already set
|
|
282
|
-
JSON.stringify(data).includes("Unable to set as master language"))
|
|
258
|
+
JSON.stringify(data).includes("Unable to set as master language"))
|
|
283
259
|
if (!success) {
|
|
284
|
-
logHttpResponse(response)
|
|
285
|
-
throw new Error(`Could not set default locale to ${locale}`)
|
|
260
|
+
logHttpResponse(response)
|
|
261
|
+
throw new Error(`Could not set default locale to ${locale}`)
|
|
286
262
|
}
|
|
287
|
-
profiler.done({ message: `default locale set to '${locale}'` })
|
|
263
|
+
profiler.done({ message: `default locale set to '${locale}'` })
|
|
288
264
|
}
|
|
289
265
|
|
|
290
266
|
/**
|
|
291
267
|
* Retrieves documents.
|
|
292
268
|
*
|
|
293
269
|
* @param args - Configure which documents are retrieved.
|
|
294
|
-
*
|
|
295
270
|
* @returns A paginated set of documents.
|
|
296
271
|
*/
|
|
297
|
-
async getDocuments(
|
|
298
|
-
args
|
|
299
|
-
): Promise<CoreApiDocumentsResponse> {
|
|
300
|
-
return this.coreApiClient.getDocuments(args);
|
|
272
|
+
async getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse> {
|
|
273
|
+
return this.coreApiClient.getDocuments(args)
|
|
301
274
|
}
|
|
302
275
|
|
|
303
276
|
/**
|
|
304
277
|
* Creates a release.
|
|
305
278
|
*
|
|
306
279
|
* @param label - The label for the release.
|
|
307
|
-
*
|
|
308
280
|
* @returns A Promise that resolves when the release is created.
|
|
309
281
|
*/
|
|
310
282
|
async createRelease(label: string): Promise<{ id: string }> {
|
|
311
|
-
const profiler = logger.startTimer()
|
|
283
|
+
const profiler = logger.startTimer()
|
|
312
284
|
|
|
313
285
|
const response = await this.wroomClient.post(this.name, "app/releases", {
|
|
314
286
|
label,
|
|
315
|
-
})
|
|
316
|
-
this.failIfNot200(response, `Could not create release ${label}`)
|
|
317
|
-
profiler.done({ message: `release '${label}' created` })
|
|
287
|
+
})
|
|
288
|
+
this.failIfNot200(response, `Could not create release ${label}`)
|
|
289
|
+
profiler.done({ message: `release '${label}' created` })
|
|
318
290
|
|
|
319
|
-
return response.data
|
|
291
|
+
return response.data
|
|
320
292
|
}
|
|
321
293
|
|
|
322
294
|
/**
|
|
@@ -325,39 +297,38 @@ export class RepositoryManager {
|
|
|
325
297
|
* @returns The migration relese metadata.
|
|
326
298
|
*/
|
|
327
299
|
async getMigrationRelease(): Promise<Release> {
|
|
328
|
-
const releases = await this.coreApiClient.getReleases()
|
|
329
|
-
const migrationRelease = releases.find((release) => release.migration)
|
|
300
|
+
const releases = await this.coreApiClient.getReleases()
|
|
301
|
+
const migrationRelease = releases.find((release) => release.migration)
|
|
330
302
|
if (!migrationRelease) {
|
|
331
|
-
throw new Error(`The repository does not have a migration release`)
|
|
303
|
+
throw new Error(`The repository does not have a migration release`)
|
|
332
304
|
}
|
|
333
305
|
|
|
334
|
-
return migrationRelease
|
|
306
|
+
return migrationRelease
|
|
335
307
|
}
|
|
336
308
|
|
|
337
309
|
/**
|
|
338
310
|
* Publishes a release.
|
|
339
311
|
*
|
|
340
312
|
* @param id - The ID of the release.
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* master ref is available.
|
|
313
|
+
* @returns A Promise that resolves when the release is published and a new master ref is
|
|
314
|
+
* available.
|
|
344
315
|
*/
|
|
345
316
|
async publishRelease(id: string): Promise<void> {
|
|
346
|
-
const profiler = logger.startTimer()
|
|
317
|
+
const profiler = logger.startTimer()
|
|
347
318
|
|
|
348
|
-
const contentApi = this.getContentApiClient()
|
|
349
|
-
const masterRef = await contentApi.getMasterRef()
|
|
350
|
-
await this.coreApiClient.publishRelease(id)
|
|
319
|
+
const contentApi = this.getContentApiClient()
|
|
320
|
+
const masterRef = await contentApi.getMasterRef()
|
|
321
|
+
await this.coreApiClient.publishRelease(id)
|
|
351
322
|
await expect
|
|
352
323
|
.poll(async () => contentApi.getMasterRef(), {
|
|
353
324
|
timeout: 10_000,
|
|
354
325
|
message: "Waiting for new master ref to be available",
|
|
355
326
|
})
|
|
356
|
-
.not.toBe(masterRef)
|
|
327
|
+
.not.toBe(masterRef)
|
|
357
328
|
|
|
358
329
|
profiler.done({
|
|
359
330
|
message: `release '${id}' published and new master ref available`,
|
|
360
|
-
})
|
|
331
|
+
})
|
|
361
332
|
}
|
|
362
333
|
|
|
363
334
|
/**
|
|
@@ -366,16 +337,12 @@ export class RepositoryManager {
|
|
|
366
337
|
* @param id - The ID of the release to be deleted.
|
|
367
338
|
*/
|
|
368
339
|
async deleteRelease(id: string): Promise<void> {
|
|
369
|
-
const profiler = logger.startTimer()
|
|
340
|
+
const profiler = logger.startTimer()
|
|
370
341
|
|
|
371
|
-
const response = await this.wroomClient.post(
|
|
372
|
-
this.name,
|
|
373
|
-
`app/releases/${id}/delete`,
|
|
374
|
-
{},
|
|
375
|
-
);
|
|
342
|
+
const response = await this.wroomClient.post(this.name, `app/releases/${id}/delete`, {})
|
|
376
343
|
|
|
377
|
-
this.failIfNot200(response, `Could not delete release with id ${id}`)
|
|
378
|
-
profiler.done({ message: `release '${id}' deleted` })
|
|
344
|
+
this.failIfNot200(response, `Could not delete release with id ${id}`)
|
|
345
|
+
profiler.done({ message: `release '${id}' deleted` })
|
|
379
346
|
}
|
|
380
347
|
|
|
381
348
|
/**
|
|
@@ -384,18 +351,14 @@ export class RepositoryManager {
|
|
|
384
351
|
* @param data - The data for creating the preview.
|
|
385
352
|
*/
|
|
386
353
|
async createPreview(data: Preview): Promise<void> {
|
|
387
|
-
const profiler = logger.startTimer()
|
|
354
|
+
const profiler = logger.startTimer()
|
|
388
355
|
|
|
389
|
-
const response = await this.wroomClient.post(
|
|
390
|
-
this.name,
|
|
391
|
-
`previews/new`,
|
|
392
|
-
data,
|
|
393
|
-
);
|
|
356
|
+
const response = await this.wroomClient.post(this.name, `previews/new`, data)
|
|
394
357
|
|
|
395
|
-
this.failIfNot200(response, `Could not create preview ${data.name}`)
|
|
396
|
-
profiler.done({ message: `preview '${data.name}' created` })
|
|
358
|
+
this.failIfNot200(response, `Could not create preview ${data.name}`)
|
|
359
|
+
profiler.done({ message: `preview '${data.name}' created` })
|
|
397
360
|
|
|
398
|
-
return response.data
|
|
361
|
+
return response.data
|
|
399
362
|
}
|
|
400
363
|
|
|
401
364
|
/**
|
|
@@ -404,17 +367,17 @@ export class RepositoryManager {
|
|
|
404
367
|
* @param data - The simulator URL to set.
|
|
405
368
|
*/
|
|
406
369
|
async setSimulatorURL(simulatorURL: string): Promise<void> {
|
|
407
|
-
const profiler = logger.startTimer()
|
|
370
|
+
const profiler = logger.startTimer()
|
|
408
371
|
|
|
409
|
-
const repository = await this.coreApiClient.getRepository()
|
|
372
|
+
const repository = await this.coreApiClient.getRepository()
|
|
410
373
|
await this.coreApiClient.updateRepository({
|
|
411
374
|
...repository,
|
|
412
375
|
simulator_url: simulatorURL,
|
|
413
|
-
})
|
|
376
|
+
})
|
|
414
377
|
|
|
415
378
|
profiler.done({
|
|
416
379
|
message: `simulator preview '${simulatorURL}' created`,
|
|
417
|
-
})
|
|
380
|
+
})
|
|
418
381
|
}
|
|
419
382
|
|
|
420
383
|
/**
|
|
@@ -423,16 +386,12 @@ export class RepositoryManager {
|
|
|
423
386
|
* @param id - The ID of the preview to be deleted.
|
|
424
387
|
*/
|
|
425
388
|
async deletePreview(id: string): Promise<void> {
|
|
426
|
-
const profiler = logger.startTimer()
|
|
389
|
+
const profiler = logger.startTimer()
|
|
427
390
|
|
|
428
|
-
const response = await this.wroomClient.post(
|
|
429
|
-
this.name,
|
|
430
|
-
`previews/delete/${id}`,
|
|
431
|
-
{},
|
|
432
|
-
);
|
|
391
|
+
const response = await this.wroomClient.post(this.name, `previews/delete/${id}`, {})
|
|
433
392
|
|
|
434
|
-
this.failIfNot200(response, `Could not delete preview with id ${id}`)
|
|
435
|
-
profiler.done({ message: `preview '${id}' deleted` })
|
|
393
|
+
this.failIfNot200(response, `Could not delete preview with id ${id}`)
|
|
394
|
+
profiler.done({ message: `preview '${id}' deleted` })
|
|
436
395
|
}
|
|
437
396
|
|
|
438
397
|
/**
|
|
@@ -445,32 +404,28 @@ export class RepositoryManager {
|
|
|
445
404
|
url: string,
|
|
446
405
|
secret: string,
|
|
447
406
|
triggers: {
|
|
448
|
-
documentsPublished?: boolean
|
|
449
|
-
documentsUnpublished?: boolean
|
|
450
|
-
releasesCreated?: boolean
|
|
451
|
-
releasesUpdated?: boolean
|
|
452
|
-
tagsCreated?: boolean
|
|
453
|
-
tagsDeleted?: boolean
|
|
407
|
+
documentsPublished?: boolean
|
|
408
|
+
documentsUnpublished?: boolean
|
|
409
|
+
releasesCreated?: boolean
|
|
410
|
+
releasesUpdated?: boolean
|
|
411
|
+
tagsCreated?: boolean
|
|
412
|
+
tagsDeleted?: boolean
|
|
454
413
|
},
|
|
455
414
|
active: boolean,
|
|
456
415
|
): Promise<string> {
|
|
457
|
-
const profiler = logger.startTimer()
|
|
416
|
+
const profiler = logger.startTimer()
|
|
458
417
|
|
|
459
|
-
const response = await this.wroomClient.post(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
},
|
|
469
|
-
);
|
|
470
|
-
this.failIfNot200(response, `Could not create webhook ${name}`);
|
|
471
|
-
profiler.done({ message: `webhook '${name}' created` });
|
|
418
|
+
const response = await this.wroomClient.post(this.name, "app/settings/webhooks/create", {
|
|
419
|
+
name,
|
|
420
|
+
url,
|
|
421
|
+
secret,
|
|
422
|
+
active: active ? "on" : "off",
|
|
423
|
+
...triggers,
|
|
424
|
+
})
|
|
425
|
+
this.failIfNot200(response, `Could not create webhook ${name}`)
|
|
426
|
+
profiler.done({ message: `webhook '${name}' created` })
|
|
472
427
|
|
|
473
|
-
return response.data.created
|
|
428
|
+
return response.data.created
|
|
474
429
|
}
|
|
475
430
|
|
|
476
431
|
/**
|
|
@@ -479,116 +434,118 @@ export class RepositoryManager {
|
|
|
479
434
|
* @param id - The webhook ID.
|
|
480
435
|
*/
|
|
481
436
|
async deleteWebhook(id: string): Promise<void> {
|
|
482
|
-
const profiler = logger.startTimer()
|
|
437
|
+
const profiler = logger.startTimer()
|
|
483
438
|
|
|
484
439
|
const response = await this.wroomClient.post(
|
|
485
440
|
this.name,
|
|
486
441
|
`app/settings/webhooks/${id}/delete`,
|
|
487
442
|
{},
|
|
488
|
-
)
|
|
443
|
+
)
|
|
489
444
|
|
|
490
|
-
this.failIfNot200(response, `Could not delete webhook with id ${id}`)
|
|
491
|
-
profiler.done({ message: `webhook '${id}' deleted` })
|
|
445
|
+
this.failIfNot200(response, `Could not delete webhook with id ${id}`)
|
|
446
|
+
profiler.done({ message: `webhook '${id}' deleted` })
|
|
492
447
|
}
|
|
493
448
|
|
|
494
449
|
/**
|
|
495
450
|
* Create Custom Types using the Custom types api.
|
|
496
451
|
*
|
|
497
|
-
* @param customTypes
|
|
452
|
+
* @param customTypes
|
|
498
453
|
*/
|
|
499
|
-
async createCustomTypes(customTypes:
|
|
500
|
-
await this.customTypesApiClient.createCustomTypes(customTypes)
|
|
454
|
+
async createCustomTypes(customTypes: DynamicCustomTypeModel[]): Promise<void> {
|
|
455
|
+
await this.customTypesApiClient.createCustomTypes(customTypes)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async deleteCustomType(customTypeId: string): Promise<void> {
|
|
459
|
+
await this.customTypesApiClient.deleteCustomType(customTypeId)
|
|
501
460
|
}
|
|
502
461
|
|
|
503
462
|
/**
|
|
504
463
|
* Create slices using the Custom types api.
|
|
505
464
|
*
|
|
506
|
-
* @param slices
|
|
465
|
+
* @param slices
|
|
507
466
|
*/
|
|
508
|
-
async createSlices(slices:
|
|
509
|
-
await this.customTypesApiClient.createSlices(slices)
|
|
467
|
+
async createSlices(slices: SharedSliceModel[]): Promise<void> {
|
|
468
|
+
await this.customTypesApiClient.createSlices(slices)
|
|
510
469
|
}
|
|
511
470
|
|
|
512
471
|
/**
|
|
513
472
|
* Create an access token to query private items of the Content api.
|
|
514
473
|
*
|
|
515
|
-
* @param appName -
|
|
516
|
-
* @param tokenScope -
|
|
517
|
-
*
|
|
474
|
+
* @param appName - Mandatory authorized application name
|
|
475
|
+
* @param tokenScope - Access token scope. Use "master" to when your content api is fully private
|
|
476
|
+
* or "master+releases" to access private releases
|
|
518
477
|
*/
|
|
519
478
|
async createContentAPIToken(
|
|
520
479
|
appName: string,
|
|
521
480
|
tokenScope: "master" | "master+releases" = "master",
|
|
522
481
|
): Promise<string> {
|
|
523
|
-
const profiler = logger.startTimer()
|
|
482
|
+
const profiler = logger.startTimer()
|
|
524
483
|
type AuthorizedAppResponse = {
|
|
525
|
-
id: string
|
|
526
|
-
name: string
|
|
527
|
-
wroom_auths: { token: string; scope: "master" | "master+releases" }[]
|
|
528
|
-
}
|
|
529
|
-
const existingApps: AxiosResponse<AuthorizedAppResponse[]> =
|
|
530
|
-
|
|
484
|
+
id: string
|
|
485
|
+
name: string
|
|
486
|
+
wroom_auths: { token: string; scope: "master" | "master+releases" }[]
|
|
487
|
+
}
|
|
488
|
+
const existingApps: AxiosResponse<AuthorizedAppResponse[]> = await this.wroomClient.get(
|
|
489
|
+
this.name,
|
|
490
|
+
"settings/security/contentapi",
|
|
491
|
+
)
|
|
531
492
|
|
|
532
493
|
this.failIfNot200(
|
|
533
494
|
existingApps,
|
|
534
495
|
`Could not get status of existing applications to generate a content api token`,
|
|
535
|
-
)
|
|
496
|
+
)
|
|
536
497
|
let app = existingApps.data.find(({ name, wroom_auths }) => {
|
|
537
|
-
return name === appName && wroom_auths.length > 0
|
|
538
|
-
})
|
|
498
|
+
return name === appName && wroom_auths.length > 0
|
|
499
|
+
})
|
|
539
500
|
|
|
540
501
|
if (!app) {
|
|
541
|
-
const response: AxiosResponse<AuthorizedAppResponse> =
|
|
542
|
-
|
|
502
|
+
const response: AxiosResponse<AuthorizedAppResponse> = await this.wroomClient.post(
|
|
503
|
+
this.name,
|
|
504
|
+
"settings/security/oauthapp",
|
|
505
|
+
{
|
|
543
506
|
app_name: appName,
|
|
544
|
-
}
|
|
507
|
+
},
|
|
508
|
+
)
|
|
545
509
|
|
|
546
|
-
this.failIfNot200(
|
|
547
|
-
|
|
548
|
-
`Could not create content api app ${appName}`,
|
|
549
|
-
);
|
|
550
|
-
app = response.data;
|
|
510
|
+
this.failIfNot200(response, `Could not create content api app ${appName}`)
|
|
511
|
+
app = response.data
|
|
551
512
|
}
|
|
552
513
|
|
|
553
|
-
let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope)
|
|
514
|
+
let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope)
|
|
554
515
|
if (!tokenInfo) {
|
|
555
|
-
const response = await this.wroomClient.post(
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
app: app.id,
|
|
560
|
-
scope: tokenScope,
|
|
561
|
-
},
|
|
562
|
-
);
|
|
516
|
+
const response = await this.wroomClient.post(this.name, "settings/security/authorizations", {
|
|
517
|
+
app: app.id,
|
|
518
|
+
scope: tokenScope,
|
|
519
|
+
})
|
|
563
520
|
this.failIfNot200(
|
|
564
521
|
response,
|
|
565
522
|
`Could not create content api access token for app ${appName} with scope ${tokenScope}`,
|
|
566
|
-
)
|
|
567
|
-
tokenInfo = response.data
|
|
523
|
+
)
|
|
524
|
+
tokenInfo = response.data
|
|
568
525
|
}
|
|
569
526
|
|
|
570
527
|
profiler.done({
|
|
571
528
|
message: `content api access token for app '${appName}' created`,
|
|
572
|
-
})
|
|
529
|
+
})
|
|
573
530
|
|
|
574
531
|
if (!tokenInfo?.token) {
|
|
575
|
-
throw `Could not create content api access token for app ${appName} with scope ${tokenScope}
|
|
532
|
+
throw `Could not create content api access token for app ${appName} with scope ${tokenScope}`
|
|
576
533
|
}
|
|
577
534
|
|
|
578
|
-
return tokenInfo.token
|
|
535
|
+
return tokenInfo.token
|
|
579
536
|
}
|
|
580
537
|
|
|
581
538
|
/** Create a permanent access token to authenticate to Prismic public apis. */
|
|
582
539
|
async createPermanentAccessToken(): Promise<string> {
|
|
583
|
-
const profiler = logger.startTimer()
|
|
540
|
+
const profiler = logger.startTimer()
|
|
584
541
|
|
|
585
|
-
const token = await this.authApiClient.getMachine2MachineToken(this.name)
|
|
542
|
+
const token = await this.authApiClient.getMachine2MachineToken(this.name)
|
|
586
543
|
|
|
587
544
|
profiler.done({
|
|
588
545
|
message: `machine2machine token created`,
|
|
589
|
-
})
|
|
546
|
+
})
|
|
590
547
|
|
|
591
|
-
return token
|
|
548
|
+
return token
|
|
592
549
|
}
|
|
593
550
|
|
|
594
551
|
/**
|
|
@@ -597,22 +554,20 @@ export class RepositoryManager {
|
|
|
597
554
|
* @param enabled - The feature new status
|
|
598
555
|
*/
|
|
599
556
|
async toggleRolePerLocal(enabled: boolean): Promise<void> {
|
|
600
|
-
const profiler = logger.startTimer()
|
|
557
|
+
const profiler = logger.startTimer()
|
|
601
558
|
|
|
602
559
|
const response = await this.manageV2Client.toggleRolePerLocal({
|
|
603
560
|
repository: this.name,
|
|
604
561
|
enabled: enabled,
|
|
605
|
-
})
|
|
562
|
+
})
|
|
606
563
|
|
|
607
564
|
this.failIfNot200(
|
|
608
565
|
response,
|
|
609
|
-
`Could not ${enabled ? "enable" : "disable"} Role per local for ${
|
|
610
|
-
|
|
611
|
-
}`,
|
|
612
|
-
);
|
|
566
|
+
`Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`,
|
|
567
|
+
)
|
|
613
568
|
profiler.done({
|
|
614
569
|
message: `Role per local ${enabled ? "enabled" : "disabled"}`,
|
|
615
|
-
})
|
|
570
|
+
})
|
|
616
571
|
}
|
|
617
572
|
|
|
618
573
|
/**
|
|
@@ -621,22 +576,20 @@ export class RepositoryManager {
|
|
|
621
576
|
* @param enabled - The feature new status
|
|
622
577
|
*/
|
|
623
578
|
async toggleCustomRoles(enabled: boolean): Promise<void> {
|
|
624
|
-
const profiler = logger.startTimer()
|
|
579
|
+
const profiler = logger.startTimer()
|
|
625
580
|
|
|
626
581
|
const response = await this.manageV2Client.toggleCustomRoles({
|
|
627
582
|
repository: this.name,
|
|
628
583
|
enabled: enabled,
|
|
629
|
-
})
|
|
584
|
+
})
|
|
630
585
|
|
|
631
586
|
this.failIfNot200(
|
|
632
587
|
response,
|
|
633
|
-
`Could not ${enabled ? "enable" : "disable"} Custom Roles for ${
|
|
634
|
-
|
|
635
|
-
}`,
|
|
636
|
-
);
|
|
588
|
+
`Could not ${enabled ? "enable" : "disable"} Custom Roles for ${this.name}`,
|
|
589
|
+
)
|
|
637
590
|
profiler.done({
|
|
638
591
|
message: `Custom Roles ${enabled ? "enabled" : "disabled"}`,
|
|
639
|
-
})
|
|
592
|
+
})
|
|
640
593
|
}
|
|
641
594
|
|
|
642
595
|
/**
|
|
@@ -645,22 +598,20 @@ export class RepositoryManager {
|
|
|
645
598
|
* @param enabled - The feature new status
|
|
646
599
|
*/
|
|
647
600
|
async toggleIntegrationFields(enabled: boolean): Promise<void> {
|
|
648
|
-
const profiler = logger.startTimer()
|
|
601
|
+
const profiler = logger.startTimer()
|
|
649
602
|
|
|
650
603
|
const response = await this.manageV2Client.toggleIntegrationFields({
|
|
651
604
|
repository: this.name,
|
|
652
605
|
enabled: enabled,
|
|
653
|
-
})
|
|
606
|
+
})
|
|
654
607
|
|
|
655
608
|
this.failIfNot200(
|
|
656
609
|
response,
|
|
657
|
-
`Could not ${enabled ? "enable" : "disable"} Integration Fields for ${
|
|
658
|
-
|
|
659
|
-
}`,
|
|
660
|
-
);
|
|
610
|
+
`Could not ${enabled ? "enable" : "disable"} Integration Fields for ${this.name}`,
|
|
611
|
+
)
|
|
661
612
|
profiler.done({
|
|
662
613
|
message: `Integration Fields ${enabled ? "enabled" : "disabled"}`,
|
|
663
|
-
})
|
|
614
|
+
})
|
|
664
615
|
}
|
|
665
616
|
|
|
666
617
|
/**
|
|
@@ -669,18 +620,18 @@ export class RepositoryManager {
|
|
|
669
620
|
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
670
621
|
*/
|
|
671
622
|
async changePlan(newPlanId: string): Promise<void> {
|
|
672
|
-
const profiler = logger.startTimer()
|
|
623
|
+
const profiler = logger.startTimer()
|
|
673
624
|
|
|
674
625
|
const response = await this.manageV2Client.changePlan({
|
|
675
626
|
repository: this.name,
|
|
676
627
|
newPlanId: newPlanId,
|
|
677
628
|
bypassManualBilling: true, // For now the library does not support Stripe features
|
|
678
|
-
})
|
|
629
|
+
})
|
|
679
630
|
|
|
680
|
-
this.failIfNot200(response, "Could not change the Repository Plan")
|
|
631
|
+
this.failIfNot200(response, "Could not change the Repository Plan")
|
|
681
632
|
profiler.done({
|
|
682
633
|
message: `Repository Plan changed to ${newPlanId}`,
|
|
683
|
-
})
|
|
634
|
+
})
|
|
684
635
|
}
|
|
685
636
|
|
|
686
637
|
/**
|
|
@@ -689,25 +640,24 @@ export class RepositoryManager {
|
|
|
689
640
|
* @param {string} email - The email of the user
|
|
690
641
|
*/
|
|
691
642
|
async addUser(email: string): Promise<void> {
|
|
692
|
-
const profiler = logger.startTimer()
|
|
643
|
+
const profiler = logger.startTimer()
|
|
693
644
|
|
|
694
645
|
const response = await this.manageV2Client.addUserToRepository({
|
|
695
646
|
repository: this.name,
|
|
696
647
|
email: email,
|
|
697
|
-
})
|
|
648
|
+
})
|
|
698
649
|
|
|
699
|
-
const { data, status } = response
|
|
650
|
+
const { data, status } = response
|
|
700
651
|
const success =
|
|
701
652
|
status === 200 ||
|
|
702
|
-
(status === 409 &&
|
|
703
|
-
JSON.stringify(data).includes("already a member of the repo"));
|
|
653
|
+
(status === 409 && JSON.stringify(data).includes("already a member of the repo"))
|
|
704
654
|
if (!success) {
|
|
705
|
-
logHttpResponse(response)
|
|
706
|
-
throw new Error(`Could not add a new user ${email} to the repository`)
|
|
655
|
+
logHttpResponse(response)
|
|
656
|
+
throw new Error(`Could not add a new user ${email} to the repository`)
|
|
707
657
|
}
|
|
708
658
|
profiler.done({
|
|
709
659
|
message: `User ${email} was added to the repository`,
|
|
710
|
-
})
|
|
660
|
+
})
|
|
711
661
|
}
|
|
712
662
|
|
|
713
663
|
/**
|
|
@@ -716,29 +666,25 @@ export class RepositoryManager {
|
|
|
716
666
|
* @param {string} email - The email of the user
|
|
717
667
|
*/
|
|
718
668
|
async removeUser(email: string): Promise<void> {
|
|
719
|
-
const profiler = logger.startTimer()
|
|
669
|
+
const profiler = logger.startTimer()
|
|
720
670
|
|
|
721
671
|
const response = await this.manageV2Client.removeUserFromRepository({
|
|
722
672
|
repository: this.name,
|
|
723
673
|
email: email,
|
|
724
|
-
})
|
|
674
|
+
})
|
|
725
675
|
|
|
726
|
-
this.failIfNot200(
|
|
727
|
-
response,
|
|
728
|
-
`Could not remove the user ${email} from the repository`,
|
|
729
|
-
);
|
|
676
|
+
this.failIfNot200(response, `Could not remove the user ${email} from the repository`)
|
|
730
677
|
profiler.done({
|
|
731
678
|
message: `User ${email} was removed from the repository`,
|
|
732
|
-
})
|
|
679
|
+
})
|
|
733
680
|
}
|
|
734
681
|
|
|
735
682
|
/**
|
|
736
683
|
* Update the role of a user in a repository
|
|
737
684
|
*
|
|
738
685
|
* @param {string} email - The email of the user
|
|
739
|
-
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
740
|
-
*
|
|
741
|
-
* "Writer" }`
|
|
686
|
+
* @param {string | Record<string, string>} role - The new Role of the user, either a string for
|
|
687
|
+
* basic workflow or an object such as `{ "lang_id": "Writer" }`
|
|
742
688
|
*
|
|
743
689
|
* Example of roles are
|
|
744
690
|
*
|
|
@@ -747,150 +693,143 @@ export class RepositoryManager {
|
|
|
747
693
|
* - Contributor
|
|
748
694
|
* - Manager (publisher)
|
|
749
695
|
*/
|
|
750
|
-
async updateUserRole(
|
|
751
|
-
|
|
752
|
-
role: string | Record<string, string>,
|
|
753
|
-
): Promise<void> {
|
|
754
|
-
const profiler = logger.startTimer();
|
|
696
|
+
async updateUserRole(email: string, role: string | Record<string, string>): Promise<void> {
|
|
697
|
+
const profiler = logger.startTimer()
|
|
755
698
|
|
|
756
699
|
const response =
|
|
757
700
|
typeof role === "string"
|
|
758
701
|
? await this.wroomClient.updateRole(this.name, email, role)
|
|
759
|
-
: await this.wroomClient.updateRolePerLocal(this.name, email, role)
|
|
702
|
+
: await this.wroomClient.updateRolePerLocal(this.name, email, role)
|
|
760
703
|
|
|
761
704
|
this.failIfNot200(
|
|
762
705
|
response,
|
|
763
706
|
`Could not update the ${
|
|
764
707
|
typeof role === "string" ? "role" : "rolePerLocal"
|
|
765
708
|
} of the user ${email}`,
|
|
766
|
-
)
|
|
709
|
+
)
|
|
767
710
|
profiler.done({
|
|
768
711
|
message: `Updated User's ${
|
|
769
712
|
typeof role === "string" ? "role" : "rolePerLocal"
|
|
770
713
|
} for user ${email}`,
|
|
771
|
-
})
|
|
714
|
+
})
|
|
772
715
|
}
|
|
773
716
|
|
|
774
717
|
/**
|
|
775
|
-
* Creates a document using the core api. If the Core api format is too
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
* @example
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* ```
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
718
|
+
* Creates a document using the core api. If the Core api format is too specific, use the
|
|
719
|
+
* migration api client to create a document with the MigrationApiClient. See the
|
|
720
|
+
* `getMigrationApiClient()` method.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* To create a document by converting it from the Page Builder to
|
|
724
|
+
* Core api format
|
|
725
|
+
*
|
|
726
|
+
* ```js
|
|
727
|
+
* import { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';
|
|
728
|
+
*
|
|
729
|
+
* const document = {
|
|
730
|
+
* title: 'A new document',
|
|
731
|
+
* custom_type_id: 'home-page',
|
|
732
|
+
* locale: 'en-gb',
|
|
733
|
+
* integration_field_ids: [],
|
|
734
|
+
* tags: [],
|
|
735
|
+
* data: DocumentLegacy.encode({
|
|
736
|
+
* uid: {
|
|
737
|
+
* __TYPE__: UIDContentType,
|
|
738
|
+
* value: 'home-page',
|
|
739
|
+
* },
|
|
740
|
+
* })
|
|
741
|
+
* }
|
|
742
|
+
* await repository.createDocument(document, 'published');
|
|
743
|
+
* * ```
|
|
744
|
+
* ```
|
|
745
|
+
*
|
|
746
|
+
* @returns
|
|
747
|
+
*
|
|
748
|
+
* @param document - in the core api format.
|
|
749
|
+
*
|
|
750
|
+
* @param status - status of the document, if published, the function will
|
|
751
|
+
* wait for a new content api master ref to be created
|
|
808
752
|
*/
|
|
809
753
|
async createDocument(
|
|
810
754
|
document: CoreApiDocumentCreationPayload,
|
|
811
755
|
status: "draft" | "published",
|
|
812
756
|
): Promise<CoreApiDocumentCreationResponse> {
|
|
813
|
-
const profiler = logger.startTimer()
|
|
814
|
-
const result = await this.coreApiClient.createDraft(document)
|
|
757
|
+
const profiler = logger.startTimer()
|
|
758
|
+
const result = await this.coreApiClient.createDraft(document)
|
|
815
759
|
|
|
816
|
-
let message = `Document created with id '${result.id}'
|
|
760
|
+
let message = `Document created with id '${result.id}'`
|
|
817
761
|
if (status === "published") {
|
|
818
|
-
const contentApi = this.getContentApiClient()
|
|
819
|
-
const masterRef = await contentApi.getMasterRef()
|
|
820
|
-
await this.coreApiClient.publishDraft(result.id)
|
|
762
|
+
const contentApi = this.getContentApiClient()
|
|
763
|
+
const masterRef = await contentApi.getMasterRef()
|
|
764
|
+
await this.coreApiClient.publishDraft(result.id)
|
|
821
765
|
await expect
|
|
822
766
|
.poll(async () => contentApi.getMasterRef(), {
|
|
823
767
|
timeout: 10_000,
|
|
824
768
|
message: "Waiting for new master ref to be available",
|
|
825
769
|
})
|
|
826
|
-
.not.toBe(masterRef)
|
|
827
|
-
message += ", status 'published' and new master ref available"
|
|
770
|
+
.not.toBe(masterRef)
|
|
771
|
+
message += ", status 'published' and new master ref available"
|
|
828
772
|
}
|
|
829
773
|
profiler.done({
|
|
830
774
|
message,
|
|
831
|
-
})
|
|
775
|
+
})
|
|
832
776
|
|
|
833
|
-
return result
|
|
777
|
+
return result
|
|
834
778
|
}
|
|
835
779
|
|
|
836
780
|
/**
|
|
837
781
|
* Retrieves data for a specific document version.
|
|
838
782
|
*
|
|
839
783
|
* @param versionId - The document's version ID.
|
|
840
|
-
*
|
|
841
784
|
* @returns The document's version data.
|
|
842
785
|
*/
|
|
843
786
|
async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
|
|
844
|
-
return await this.coreApiClient.getDocumentData(versionId)
|
|
787
|
+
return await this.coreApiClient.getDocumentData(versionId)
|
|
845
788
|
}
|
|
846
789
|
|
|
847
|
-
async setupIntegrationFields(
|
|
848
|
-
|
|
849
|
-
): Promise<void> {
|
|
850
|
-
const profiler = logger.startTimer();
|
|
790
|
+
async setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {
|
|
791
|
+
const profiler = logger.startTimer()
|
|
851
792
|
|
|
852
793
|
if (!this.integrationFieldsClient) {
|
|
853
794
|
throw new Error(
|
|
854
795
|
"Integration Fields client not found. Did you provide a integration fields api url in the configuration?",
|
|
855
|
-
)
|
|
796
|
+
)
|
|
856
797
|
}
|
|
857
798
|
|
|
858
|
-
await this.integrationFieldsClient.setupIntegrationFields(
|
|
859
|
-
integrationFields,
|
|
860
|
-
);
|
|
799
|
+
await this.integrationFieldsClient.setupIntegrationFields(integrationFields)
|
|
861
800
|
profiler.done({
|
|
862
801
|
message: `Integration Fields setup`,
|
|
863
|
-
})
|
|
802
|
+
})
|
|
864
803
|
}
|
|
865
804
|
}
|
|
866
805
|
|
|
867
806
|
export type RepositoryConfig = {
|
|
868
|
-
customLocale?: CustomLocale
|
|
869
|
-
locales?: string[]
|
|
870
|
-
defaultLocale?: string
|
|
871
|
-
slices?:
|
|
872
|
-
customTypes?:
|
|
873
|
-
preview?: Preview
|
|
874
|
-
simulatorURL?: string
|
|
875
|
-
rolePerLocal?: boolean
|
|
876
|
-
customRoles?: boolean
|
|
877
|
-
integrationFields?: IntegrationFieldConfig[]
|
|
878
|
-
}
|
|
807
|
+
customLocale?: CustomLocale
|
|
808
|
+
locales?: string[]
|
|
809
|
+
defaultLocale?: string
|
|
810
|
+
slices?: SharedSliceModel[]
|
|
811
|
+
customTypes?: DynamicCustomTypeModel[]
|
|
812
|
+
preview?: Preview
|
|
813
|
+
simulatorURL?: string
|
|
814
|
+
rolePerLocal?: boolean
|
|
815
|
+
customRoles?: boolean
|
|
816
|
+
integrationFields?: IntegrationFieldConfig[]
|
|
817
|
+
}
|
|
879
818
|
|
|
880
819
|
export type Preview = {
|
|
881
|
-
name: string
|
|
882
|
-
websiteURL: string
|
|
883
|
-
resolverPath: string
|
|
884
|
-
}
|
|
820
|
+
name: string
|
|
821
|
+
websiteURL: string
|
|
822
|
+
resolverPath: string
|
|
823
|
+
}
|
|
885
824
|
|
|
886
825
|
export type CustomLocale = {
|
|
887
826
|
lang: {
|
|
888
|
-
label: string
|
|
889
|
-
id: string
|
|
890
|
-
useStandardAnalyzer?: boolean
|
|
891
|
-
}
|
|
827
|
+
label: string
|
|
828
|
+
id: string
|
|
829
|
+
useStandardAnalyzer?: boolean
|
|
830
|
+
}
|
|
892
831
|
region: {
|
|
893
|
-
label: string
|
|
894
|
-
id: string
|
|
895
|
-
}
|
|
896
|
-
}
|
|
832
|
+
label: string
|
|
833
|
+
id: string
|
|
834
|
+
}
|
|
835
|
+
}
|