@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,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,120 +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)
|
|
501
456
|
}
|
|
502
457
|
|
|
503
458
|
async deleteCustomType(customTypeId: string): Promise<void> {
|
|
504
|
-
await this.customTypesApiClient.deleteCustomType(customTypeId)
|
|
459
|
+
await this.customTypesApiClient.deleteCustomType(customTypeId)
|
|
505
460
|
}
|
|
506
461
|
|
|
507
462
|
/**
|
|
508
463
|
* Create slices using the Custom types api.
|
|
509
464
|
*
|
|
510
|
-
* @param slices
|
|
465
|
+
* @param slices
|
|
511
466
|
*/
|
|
512
|
-
async createSlices(slices:
|
|
513
|
-
await this.customTypesApiClient.createSlices(slices)
|
|
467
|
+
async createSlices(slices: SharedSliceModel[]): Promise<void> {
|
|
468
|
+
await this.customTypesApiClient.createSlices(slices)
|
|
514
469
|
}
|
|
515
470
|
|
|
516
471
|
/**
|
|
517
472
|
* Create an access token to query private items of the Content api.
|
|
518
473
|
*
|
|
519
|
-
* @param appName -
|
|
520
|
-
* @param tokenScope -
|
|
521
|
-
*
|
|
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
|
|
522
477
|
*/
|
|
523
478
|
async createContentAPIToken(
|
|
524
479
|
appName: string,
|
|
525
480
|
tokenScope: "master" | "master+releases" = "master",
|
|
526
481
|
): Promise<string> {
|
|
527
|
-
const profiler = logger.startTimer()
|
|
482
|
+
const profiler = logger.startTimer()
|
|
528
483
|
type AuthorizedAppResponse = {
|
|
529
|
-
id: string
|
|
530
|
-
name: string
|
|
531
|
-
wroom_auths: { token: string; scope: "master" | "master+releases" }[]
|
|
532
|
-
}
|
|
533
|
-
const existingApps: AxiosResponse<AuthorizedAppResponse[]> =
|
|
534
|
-
|
|
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
|
+
)
|
|
535
492
|
|
|
536
493
|
this.failIfNot200(
|
|
537
494
|
existingApps,
|
|
538
495
|
`Could not get status of existing applications to generate a content api token`,
|
|
539
|
-
)
|
|
496
|
+
)
|
|
540
497
|
let app = existingApps.data.find(({ name, wroom_auths }) => {
|
|
541
|
-
return name === appName && wroom_auths.length > 0
|
|
542
|
-
})
|
|
498
|
+
return name === appName && wroom_auths.length > 0
|
|
499
|
+
})
|
|
543
500
|
|
|
544
501
|
if (!app) {
|
|
545
|
-
const response: AxiosResponse<AuthorizedAppResponse> =
|
|
546
|
-
|
|
502
|
+
const response: AxiosResponse<AuthorizedAppResponse> = await this.wroomClient.post(
|
|
503
|
+
this.name,
|
|
504
|
+
"settings/security/oauthapp",
|
|
505
|
+
{
|
|
547
506
|
app_name: appName,
|
|
548
|
-
}
|
|
507
|
+
},
|
|
508
|
+
)
|
|
549
509
|
|
|
550
|
-
this.failIfNot200(
|
|
551
|
-
|
|
552
|
-
`Could not create content api app ${appName}`,
|
|
553
|
-
);
|
|
554
|
-
app = response.data;
|
|
510
|
+
this.failIfNot200(response, `Could not create content api app ${appName}`)
|
|
511
|
+
app = response.data
|
|
555
512
|
}
|
|
556
513
|
|
|
557
|
-
let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope)
|
|
514
|
+
let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope)
|
|
558
515
|
if (!tokenInfo) {
|
|
559
|
-
const response = await this.wroomClient.post(
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
app: app.id,
|
|
564
|
-
scope: tokenScope,
|
|
565
|
-
},
|
|
566
|
-
);
|
|
516
|
+
const response = await this.wroomClient.post(this.name, "settings/security/authorizations", {
|
|
517
|
+
app: app.id,
|
|
518
|
+
scope: tokenScope,
|
|
519
|
+
})
|
|
567
520
|
this.failIfNot200(
|
|
568
521
|
response,
|
|
569
522
|
`Could not create content api access token for app ${appName} with scope ${tokenScope}`,
|
|
570
|
-
)
|
|
571
|
-
tokenInfo = response.data
|
|
523
|
+
)
|
|
524
|
+
tokenInfo = response.data
|
|
572
525
|
}
|
|
573
526
|
|
|
574
527
|
profiler.done({
|
|
575
528
|
message: `content api access token for app '${appName}' created`,
|
|
576
|
-
})
|
|
529
|
+
})
|
|
577
530
|
|
|
578
531
|
if (!tokenInfo?.token) {
|
|
579
|
-
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}`
|
|
580
533
|
}
|
|
581
534
|
|
|
582
|
-
return tokenInfo.token
|
|
535
|
+
return tokenInfo.token
|
|
583
536
|
}
|
|
584
537
|
|
|
585
538
|
/** Create a permanent access token to authenticate to Prismic public apis. */
|
|
586
539
|
async createPermanentAccessToken(): Promise<string> {
|
|
587
|
-
const profiler = logger.startTimer()
|
|
540
|
+
const profiler = logger.startTimer()
|
|
588
541
|
|
|
589
|
-
const token = await this.authApiClient.getMachine2MachineToken(this.name)
|
|
542
|
+
const token = await this.authApiClient.getMachine2MachineToken(this.name)
|
|
590
543
|
|
|
591
544
|
profiler.done({
|
|
592
545
|
message: `machine2machine token created`,
|
|
593
|
-
})
|
|
546
|
+
})
|
|
594
547
|
|
|
595
|
-
return token
|
|
548
|
+
return token
|
|
596
549
|
}
|
|
597
550
|
|
|
598
551
|
/**
|
|
@@ -601,22 +554,20 @@ export class RepositoryManager {
|
|
|
601
554
|
* @param enabled - The feature new status
|
|
602
555
|
*/
|
|
603
556
|
async toggleRolePerLocal(enabled: boolean): Promise<void> {
|
|
604
|
-
const profiler = logger.startTimer()
|
|
557
|
+
const profiler = logger.startTimer()
|
|
605
558
|
|
|
606
559
|
const response = await this.manageV2Client.toggleRolePerLocal({
|
|
607
560
|
repository: this.name,
|
|
608
561
|
enabled: enabled,
|
|
609
|
-
})
|
|
562
|
+
})
|
|
610
563
|
|
|
611
564
|
this.failIfNot200(
|
|
612
565
|
response,
|
|
613
|
-
`Could not ${enabled ? "enable" : "disable"} Role per local for ${
|
|
614
|
-
|
|
615
|
-
}`,
|
|
616
|
-
);
|
|
566
|
+
`Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`,
|
|
567
|
+
)
|
|
617
568
|
profiler.done({
|
|
618
569
|
message: `Role per local ${enabled ? "enabled" : "disabled"}`,
|
|
619
|
-
})
|
|
570
|
+
})
|
|
620
571
|
}
|
|
621
572
|
|
|
622
573
|
/**
|
|
@@ -625,22 +576,20 @@ export class RepositoryManager {
|
|
|
625
576
|
* @param enabled - The feature new status
|
|
626
577
|
*/
|
|
627
578
|
async toggleCustomRoles(enabled: boolean): Promise<void> {
|
|
628
|
-
const profiler = logger.startTimer()
|
|
579
|
+
const profiler = logger.startTimer()
|
|
629
580
|
|
|
630
581
|
const response = await this.manageV2Client.toggleCustomRoles({
|
|
631
582
|
repository: this.name,
|
|
632
583
|
enabled: enabled,
|
|
633
|
-
})
|
|
584
|
+
})
|
|
634
585
|
|
|
635
586
|
this.failIfNot200(
|
|
636
587
|
response,
|
|
637
|
-
`Could not ${enabled ? "enable" : "disable"} Custom Roles for ${
|
|
638
|
-
|
|
639
|
-
}`,
|
|
640
|
-
);
|
|
588
|
+
`Could not ${enabled ? "enable" : "disable"} Custom Roles for ${this.name}`,
|
|
589
|
+
)
|
|
641
590
|
profiler.done({
|
|
642
591
|
message: `Custom Roles ${enabled ? "enabled" : "disabled"}`,
|
|
643
|
-
})
|
|
592
|
+
})
|
|
644
593
|
}
|
|
645
594
|
|
|
646
595
|
/**
|
|
@@ -649,22 +598,20 @@ export class RepositoryManager {
|
|
|
649
598
|
* @param enabled - The feature new status
|
|
650
599
|
*/
|
|
651
600
|
async toggleIntegrationFields(enabled: boolean): Promise<void> {
|
|
652
|
-
const profiler = logger.startTimer()
|
|
601
|
+
const profiler = logger.startTimer()
|
|
653
602
|
|
|
654
603
|
const response = await this.manageV2Client.toggleIntegrationFields({
|
|
655
604
|
repository: this.name,
|
|
656
605
|
enabled: enabled,
|
|
657
|
-
})
|
|
606
|
+
})
|
|
658
607
|
|
|
659
608
|
this.failIfNot200(
|
|
660
609
|
response,
|
|
661
|
-
`Could not ${enabled ? "enable" : "disable"} Integration Fields for ${
|
|
662
|
-
|
|
663
|
-
}`,
|
|
664
|
-
);
|
|
610
|
+
`Could not ${enabled ? "enable" : "disable"} Integration Fields for ${this.name}`,
|
|
611
|
+
)
|
|
665
612
|
profiler.done({
|
|
666
613
|
message: `Integration Fields ${enabled ? "enabled" : "disabled"}`,
|
|
667
|
-
})
|
|
614
|
+
})
|
|
668
615
|
}
|
|
669
616
|
|
|
670
617
|
/**
|
|
@@ -673,18 +620,18 @@ export class RepositoryManager {
|
|
|
673
620
|
* @param {string} newPlanId - The Id of the new Plan to apply
|
|
674
621
|
*/
|
|
675
622
|
async changePlan(newPlanId: string): Promise<void> {
|
|
676
|
-
const profiler = logger.startTimer()
|
|
623
|
+
const profiler = logger.startTimer()
|
|
677
624
|
|
|
678
625
|
const response = await this.manageV2Client.changePlan({
|
|
679
626
|
repository: this.name,
|
|
680
627
|
newPlanId: newPlanId,
|
|
681
628
|
bypassManualBilling: true, // For now the library does not support Stripe features
|
|
682
|
-
})
|
|
629
|
+
})
|
|
683
630
|
|
|
684
|
-
this.failIfNot200(response, "Could not change the Repository Plan")
|
|
631
|
+
this.failIfNot200(response, "Could not change the Repository Plan")
|
|
685
632
|
profiler.done({
|
|
686
633
|
message: `Repository Plan changed to ${newPlanId}`,
|
|
687
|
-
})
|
|
634
|
+
})
|
|
688
635
|
}
|
|
689
636
|
|
|
690
637
|
/**
|
|
@@ -693,25 +640,24 @@ export class RepositoryManager {
|
|
|
693
640
|
* @param {string} email - The email of the user
|
|
694
641
|
*/
|
|
695
642
|
async addUser(email: string): Promise<void> {
|
|
696
|
-
const profiler = logger.startTimer()
|
|
643
|
+
const profiler = logger.startTimer()
|
|
697
644
|
|
|
698
645
|
const response = await this.manageV2Client.addUserToRepository({
|
|
699
646
|
repository: this.name,
|
|
700
647
|
email: email,
|
|
701
|
-
})
|
|
648
|
+
})
|
|
702
649
|
|
|
703
|
-
const { data, status } = response
|
|
650
|
+
const { data, status } = response
|
|
704
651
|
const success =
|
|
705
652
|
status === 200 ||
|
|
706
|
-
(status === 409 &&
|
|
707
|
-
JSON.stringify(data).includes("already a member of the repo"));
|
|
653
|
+
(status === 409 && JSON.stringify(data).includes("already a member of the repo"))
|
|
708
654
|
if (!success) {
|
|
709
|
-
logHttpResponse(response)
|
|
710
|
-
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`)
|
|
711
657
|
}
|
|
712
658
|
profiler.done({
|
|
713
659
|
message: `User ${email} was added to the repository`,
|
|
714
|
-
})
|
|
660
|
+
})
|
|
715
661
|
}
|
|
716
662
|
|
|
717
663
|
/**
|
|
@@ -720,29 +666,25 @@ export class RepositoryManager {
|
|
|
720
666
|
* @param {string} email - The email of the user
|
|
721
667
|
*/
|
|
722
668
|
async removeUser(email: string): Promise<void> {
|
|
723
|
-
const profiler = logger.startTimer()
|
|
669
|
+
const profiler = logger.startTimer()
|
|
724
670
|
|
|
725
671
|
const response = await this.manageV2Client.removeUserFromRepository({
|
|
726
672
|
repository: this.name,
|
|
727
673
|
email: email,
|
|
728
|
-
})
|
|
674
|
+
})
|
|
729
675
|
|
|
730
|
-
this.failIfNot200(
|
|
731
|
-
response,
|
|
732
|
-
`Could not remove the user ${email} from the repository`,
|
|
733
|
-
);
|
|
676
|
+
this.failIfNot200(response, `Could not remove the user ${email} from the repository`)
|
|
734
677
|
profiler.done({
|
|
735
678
|
message: `User ${email} was removed from the repository`,
|
|
736
|
-
})
|
|
679
|
+
})
|
|
737
680
|
}
|
|
738
681
|
|
|
739
682
|
/**
|
|
740
683
|
* Update the role of a user in a repository
|
|
741
684
|
*
|
|
742
685
|
* @param {string} email - The email of the user
|
|
743
|
-
* @param {string | Record<string, string>} role - The new Role of the user,
|
|
744
|
-
*
|
|
745
|
-
* "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" }`
|
|
746
688
|
*
|
|
747
689
|
* Example of roles are
|
|
748
690
|
*
|
|
@@ -751,150 +693,143 @@ export class RepositoryManager {
|
|
|
751
693
|
* - Contributor
|
|
752
694
|
* - Manager (publisher)
|
|
753
695
|
*/
|
|
754
|
-
async updateUserRole(
|
|
755
|
-
|
|
756
|
-
role: string | Record<string, string>,
|
|
757
|
-
): Promise<void> {
|
|
758
|
-
const profiler = logger.startTimer();
|
|
696
|
+
async updateUserRole(email: string, role: string | Record<string, string>): Promise<void> {
|
|
697
|
+
const profiler = logger.startTimer()
|
|
759
698
|
|
|
760
699
|
const response =
|
|
761
700
|
typeof role === "string"
|
|
762
701
|
? await this.wroomClient.updateRole(this.name, email, role)
|
|
763
|
-
: await this.wroomClient.updateRolePerLocal(this.name, email, role)
|
|
702
|
+
: await this.wroomClient.updateRolePerLocal(this.name, email, role)
|
|
764
703
|
|
|
765
704
|
this.failIfNot200(
|
|
766
705
|
response,
|
|
767
706
|
`Could not update the ${
|
|
768
707
|
typeof role === "string" ? "role" : "rolePerLocal"
|
|
769
708
|
} of the user ${email}`,
|
|
770
|
-
)
|
|
709
|
+
)
|
|
771
710
|
profiler.done({
|
|
772
711
|
message: `Updated User's ${
|
|
773
712
|
typeof role === "string" ? "role" : "rolePerLocal"
|
|
774
713
|
} for user ${email}`,
|
|
775
|
-
})
|
|
714
|
+
})
|
|
776
715
|
}
|
|
777
716
|
|
|
778
717
|
/**
|
|
779
|
-
* Creates a document using the core api. If the Core api format is too
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
* @example
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
* ```
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
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
|
|
812
752
|
*/
|
|
813
753
|
async createDocument(
|
|
814
754
|
document: CoreApiDocumentCreationPayload,
|
|
815
755
|
status: "draft" | "published",
|
|
816
756
|
): Promise<CoreApiDocumentCreationResponse> {
|
|
817
|
-
const profiler = logger.startTimer()
|
|
818
|
-
const result = await this.coreApiClient.createDraft(document)
|
|
757
|
+
const profiler = logger.startTimer()
|
|
758
|
+
const result = await this.coreApiClient.createDraft(document)
|
|
819
759
|
|
|
820
|
-
let message = `Document created with id '${result.id}'
|
|
760
|
+
let message = `Document created with id '${result.id}'`
|
|
821
761
|
if (status === "published") {
|
|
822
|
-
const contentApi = this.getContentApiClient()
|
|
823
|
-
const masterRef = await contentApi.getMasterRef()
|
|
824
|
-
await this.coreApiClient.publishDraft(result.id)
|
|
762
|
+
const contentApi = this.getContentApiClient()
|
|
763
|
+
const masterRef = await contentApi.getMasterRef()
|
|
764
|
+
await this.coreApiClient.publishDraft(result.id)
|
|
825
765
|
await expect
|
|
826
766
|
.poll(async () => contentApi.getMasterRef(), {
|
|
827
767
|
timeout: 10_000,
|
|
828
768
|
message: "Waiting for new master ref to be available",
|
|
829
769
|
})
|
|
830
|
-
.not.toBe(masterRef)
|
|
831
|
-
message += ", status 'published' and new master ref available"
|
|
770
|
+
.not.toBe(masterRef)
|
|
771
|
+
message += ", status 'published' and new master ref available"
|
|
832
772
|
}
|
|
833
773
|
profiler.done({
|
|
834
774
|
message,
|
|
835
|
-
})
|
|
775
|
+
})
|
|
836
776
|
|
|
837
|
-
return result
|
|
777
|
+
return result
|
|
838
778
|
}
|
|
839
779
|
|
|
840
780
|
/**
|
|
841
781
|
* Retrieves data for a specific document version.
|
|
842
782
|
*
|
|
843
783
|
* @param versionId - The document's version ID.
|
|
844
|
-
*
|
|
845
784
|
* @returns The document's version data.
|
|
846
785
|
*/
|
|
847
786
|
async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
|
|
848
|
-
return await this.coreApiClient.getDocumentData(versionId)
|
|
787
|
+
return await this.coreApiClient.getDocumentData(versionId)
|
|
849
788
|
}
|
|
850
789
|
|
|
851
|
-
async setupIntegrationFields(
|
|
852
|
-
|
|
853
|
-
): Promise<void> {
|
|
854
|
-
const profiler = logger.startTimer();
|
|
790
|
+
async setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {
|
|
791
|
+
const profiler = logger.startTimer()
|
|
855
792
|
|
|
856
793
|
if (!this.integrationFieldsClient) {
|
|
857
794
|
throw new Error(
|
|
858
795
|
"Integration Fields client not found. Did you provide a integration fields api url in the configuration?",
|
|
859
|
-
)
|
|
796
|
+
)
|
|
860
797
|
}
|
|
861
798
|
|
|
862
|
-
await this.integrationFieldsClient.setupIntegrationFields(
|
|
863
|
-
integrationFields,
|
|
864
|
-
);
|
|
799
|
+
await this.integrationFieldsClient.setupIntegrationFields(integrationFields)
|
|
865
800
|
profiler.done({
|
|
866
801
|
message: `Integration Fields setup`,
|
|
867
|
-
})
|
|
802
|
+
})
|
|
868
803
|
}
|
|
869
804
|
}
|
|
870
805
|
|
|
871
806
|
export type RepositoryConfig = {
|
|
872
|
-
customLocale?: CustomLocale
|
|
873
|
-
locales?: string[]
|
|
874
|
-
defaultLocale?: string
|
|
875
|
-
slices?:
|
|
876
|
-
customTypes?:
|
|
877
|
-
preview?: Preview
|
|
878
|
-
simulatorURL?: string
|
|
879
|
-
rolePerLocal?: boolean
|
|
880
|
-
customRoles?: boolean
|
|
881
|
-
integrationFields?: IntegrationFieldConfig[]
|
|
882
|
-
}
|
|
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
|
+
}
|
|
883
818
|
|
|
884
819
|
export type Preview = {
|
|
885
|
-
name: string
|
|
886
|
-
websiteURL: string
|
|
887
|
-
resolverPath: string
|
|
888
|
-
}
|
|
820
|
+
name: string
|
|
821
|
+
websiteURL: string
|
|
822
|
+
resolverPath: string
|
|
823
|
+
}
|
|
889
824
|
|
|
890
825
|
export type CustomLocale = {
|
|
891
826
|
lang: {
|
|
892
|
-
label: string
|
|
893
|
-
id: string
|
|
894
|
-
useStandardAnalyzer?: boolean
|
|
895
|
-
}
|
|
827
|
+
label: string
|
|
828
|
+
id: string
|
|
829
|
+
useStandardAnalyzer?: boolean
|
|
830
|
+
}
|
|
896
831
|
region: {
|
|
897
|
-
label: string
|
|
898
|
-
id: string
|
|
899
|
-
}
|
|
900
|
-
}
|
|
832
|
+
label: string
|
|
833
|
+
id: string
|
|
834
|
+
}
|
|
835
|
+
}
|