@prismicio/e2e-tests-utils 1.18.0 → 1.19.0-canary.d349d21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -27
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/clients/apiClient.cjs +38 -38
- package/dist/clients/apiClient.cjs.map +1 -1
- package/dist/clients/apiClient.d.cts +30 -0
- package/dist/clients/apiClient.d.cts.map +1 -0
- package/dist/clients/apiClient.d.ts +23 -23
- package/dist/clients/apiClient.d.ts.map +1 -0
- package/dist/clients/apiClient.js +38 -38
- package/dist/clients/apiClient.js.map +1 -1
- package/dist/clients/assetApi.cjs +81 -93
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.cts +105 -0
- package/dist/clients/assetApi.d.cts.map +1 -0
- package/dist/clients/assetApi.d.ts +96 -97
- package/dist/clients/assetApi.d.ts.map +1 -0
- package/dist/clients/assetApi.js +79 -91
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/authenticationApi.cjs +66 -73
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.cts +20 -0
- package/dist/clients/authenticationApi.d.cts.map +1 -0
- package/dist/clients/authenticationApi.d.ts +18 -13
- package/dist/clients/authenticationApi.d.ts.map +1 -0
- package/dist/clients/authenticationApi.js +65 -72
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +94 -103
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.d.cts +116 -0
- package/dist/clients/contentApi.d.cts.map +1 -0
- package/dist/clients/contentApi.d.ts +102 -98
- package/dist/clients/contentApi.d.ts.map +1 -0
- package/dist/clients/contentApi.js +94 -103
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +154 -145
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.cts +143 -0
- package/dist/clients/coreApi.d.cts.map +1 -0
- package/dist/clients/coreApi.d.ts +132 -109
- package/dist/clients/coreApi.d.ts.map +1 -0
- package/dist/clients/coreApi.js +153 -144
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +90 -99
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.d.cts +46 -0
- package/dist/clients/customTypesApi.d.cts.map +1 -0
- package/dist/clients/customTypesApi.d.ts +45 -45
- package/dist/clients/customTypesApi.d.ts.map +1 -0
- package/dist/clients/customTypesApi.js +87 -98
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/integrationFields.cjs +96 -87
- package/dist/clients/integrationFields.cjs.map +1 -1
- package/dist/clients/integrationFields.d.cts +30 -0
- package/dist/clients/integrationFields.d.cts.map +1 -0
- package/dist/clients/integrationFields.d.ts +27 -22
- package/dist/clients/integrationFields.d.ts.map +1 -0
- package/dist/clients/integrationFields.js +93 -86
- package/dist/clients/integrationFields.js.map +1 -1
- package/dist/clients/manageV2.cjs +154 -171
- package/dist/clients/manageV2.cjs.map +1 -1
- package/dist/clients/manageV2.d.cts +105 -0
- package/dist/clients/manageV2.d.cts.map +1 -0
- package/dist/clients/manageV2.d.ts +103 -111
- package/dist/clients/manageV2.d.ts.map +1 -0
- package/dist/clients/manageV2.js +149 -169
- package/dist/clients/manageV2.js.map +1 -1
- package/dist/clients/migrationApi.cjs +37 -36
- package/dist/clients/migrationApi.cjs.map +1 -1
- package/dist/clients/migrationApi.d.cts +48 -0
- package/dist/clients/migrationApi.d.cts.map +1 -0
- package/dist/clients/migrationApi.d.ts +45 -39
- package/dist/clients/migrationApi.d.ts.map +1 -0
- package/dist/clients/migrationApi.js +35 -34
- package/dist/clients/migrationApi.js.map +1 -1
- package/dist/clients/wroom.cjs +101 -122
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.cts +48 -0
- package/dist/clients/wroom.d.cts.map +1 -0
- package/dist/clients/wroom.d.ts +46 -47
- package/dist/clients/wroom.d.ts.map +1 -0
- package/dist/clients/wroom.js +99 -122
- package/dist/clients/wroom.js.map +1 -1
- package/dist/index.cjs +13 -15
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +5 -14
- package/dist/managers/repositories.cjs +159 -169
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.cts +67 -0
- package/dist/managers/repositories.d.cts.map +1 -0
- package/dist/managers/repositories.d.ts +56 -63
- package/dist/managers/repositories.d.ts.map +1 -0
- package/dist/managers/repositories.js +148 -159
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +595 -616
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.cts +341 -0
- package/dist/managers/repository.d.cts.map +1 -0
- package/dist/managers/repository.d.ts +336 -307
- package/dist/managers/repository.d.ts.map +1 -0
- package/dist/managers/repository.js +595 -616
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.cts +41 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +35 -37
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/cookies.cjs +19 -17
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js +20 -18
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/envVariableManager.cjs +33 -34
- package/dist/utils/envVariableManager.cjs.map +1 -1
- package/dist/utils/envVariableManager.js +34 -35
- package/dist/utils/envVariableManager.js.map +1 -1
- package/dist/utils/log.cjs +18 -19
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.js +18 -21
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/random.cjs +13 -6
- package/dist/utils/random.cjs.map +1 -1
- package/dist/utils/random.js +13 -6
- package/dist/utils/random.js.map +1 -1
- package/dist/utils/strings.cjs +13 -7
- package/dist/utils/strings.cjs.map +1 -1
- package/dist/utils/strings.js +14 -8
- package/dist/utils/strings.js.map +1 -1
- package/dist/utils/urls.cjs +21 -10
- package/dist/utils/urls.cjs.map +1 -1
- package/dist/utils/urls.js +22 -12
- package/dist/utils/urls.js.map +1 -1
- package/package.json +42 -67
- package/src/clients/apiClient.ts +16 -21
- package/src/clients/assetApi.ts +75 -82
- package/src/clients/authenticationApi.ts +54 -27
- package/src/clients/contentApi.ts +111 -129
- package/src/clients/coreApi.ts +166 -117
- package/src/clients/customTypesApi.ts +54 -74
- package/src/clients/integrationFields.ts +59 -74
- package/src/clients/manageV2.ts +72 -96
- package/src/clients/migrationApi.ts +35 -39
- package/src/clients/wroom.ts +42 -56
- package/src/index.ts +7 -7
- package/src/managers/repositories.ts +85 -108
- package/src/managers/repository.ts +410 -378
- 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,173 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
-
const axios = require("axios");
|
|
10
|
-
const jwt = require("jsonwebtoken");
|
|
11
|
-
const cookies = require("../utils/cookies.cjs");
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_cookies = require("../utils/cookies.cjs");
|
|
3
|
+
let axios = require("axios");
|
|
4
|
+
axios = require_runtime.__toESM(axios, 1);
|
|
5
|
+
let jsonwebtoken = require("jsonwebtoken");
|
|
6
|
+
jsonwebtoken = require_runtime.__toESM(jsonwebtoken, 1);
|
|
7
|
+
//#region src/clients/manageV2.ts
|
|
12
8
|
const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*/
|
|
159
|
-
assertTokenExist(f) {
|
|
160
|
-
return (params) => {
|
|
161
|
-
if (this.token === null) {
|
|
162
|
-
throw new Error("Undefined configuration for ManageV2 while trying to use it's routes");
|
|
163
|
-
} else {
|
|
164
|
-
return f(params);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
getBaseURL() {
|
|
169
|
-
return this.client.getUri();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
9
|
+
/** Client for interacting with ManageV2 routes to perform operations on repositories. */
|
|
10
|
+
var ManageV2Client = class {
|
|
11
|
+
client;
|
|
12
|
+
token = null;
|
|
13
|
+
/**
|
|
14
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
15
|
+
* @param config - ManageV2 configuration variable to call ManageV2.
|
|
16
|
+
*/
|
|
17
|
+
constructor(baseUrl, config) {
|
|
18
|
+
this.token = config ? this.generateToken(config) : null;
|
|
19
|
+
this.client = axios.default.create({
|
|
20
|
+
baseURL: `${baseUrl}/manageroutes/`,
|
|
21
|
+
withCredentials: true,
|
|
22
|
+
validateStatus: () => true,
|
|
23
|
+
headers: {
|
|
24
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
25
|
+
Authorization: `Bearer ${this.token}`
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.client.interceptors.response.use((response) => {
|
|
29
|
+
const cookies = response.headers["set-cookie"];
|
|
30
|
+
if (cookies && require_cookies.extractCookie(cookies, "SESSION")) this.client.defaults.headers["Cookie"] = cookies;
|
|
31
|
+
return response;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The function generates a JWT token using the provided configuration parameters.
|
|
36
|
+
*
|
|
37
|
+
* @param {ManageV2Config} config - The `config` parameter in the `generateToken` function is of
|
|
38
|
+
* type `ManageV2Config`. It contains the following properties:
|
|
39
|
+
* @returns A JSON Web Token (JWT) is being returned by the `generateToken` function. The token is
|
|
40
|
+
* signed using the provided `config.secret` with the HS256 algorithm and includes the specified
|
|
41
|
+
* audience and issuer values.
|
|
42
|
+
*/
|
|
43
|
+
generateToken(config) {
|
|
44
|
+
return jsonwebtoken.default.sign({}, config.secret, {
|
|
45
|
+
algorithm: "HS256",
|
|
46
|
+
audience: config.audience,
|
|
47
|
+
issuer: "prismic.io"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The function `assertTokenExist` checks if a token exists before executing a given function.
|
|
52
|
+
*
|
|
53
|
+
* @param f - The `assertTokenExist` function takes a function `f` as a parameter. This function
|
|
54
|
+
* `f` should accept a parameter of type `Parameters` and return a Promise that resolves to an
|
|
55
|
+
* AxiosResponse. The `assertTokenExist` function ensures that a token is not null before
|
|
56
|
+
* calling the provided
|
|
57
|
+
* @returns A function is being returned that takes a parameter of type Parameters and checks if
|
|
58
|
+
* the token is null. If the token is null, an error is thrown. Otherwise, the function f is
|
|
59
|
+
* called with the provided parameters.
|
|
60
|
+
*/
|
|
61
|
+
assertTokenExist(f) {
|
|
62
|
+
return (params) => {
|
|
63
|
+
if (this.token === null) throw new Error("Undefined configuration for ManageV2 while trying to use it's routes");
|
|
64
|
+
else return f(params);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
getBaseURL() {
|
|
68
|
+
return this.client.getUri();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The function `toggleRolePerLocal` enables or disables the RolesPerLocale workflow
|
|
72
|
+
*
|
|
73
|
+
* @param repository - The Repository name
|
|
74
|
+
* @param enabled - The feature new status
|
|
75
|
+
*/
|
|
76
|
+
toggleRolePerLocal = this.assertTokenExist((params) => {
|
|
77
|
+
return this.client.post("/repository/toggleRolesPerLocale", {
|
|
78
|
+
domain: params.repository,
|
|
79
|
+
enabled: params.enabled,
|
|
80
|
+
author: ManageV2StaticAuthor
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* The function `toggleCustomRoles` enables or disables the CustomRoles workflow
|
|
85
|
+
*
|
|
86
|
+
* @param repository - The Repository name
|
|
87
|
+
* @param enabled - The feature new status
|
|
88
|
+
*/
|
|
89
|
+
toggleCustomRoles = this.assertTokenExist((params) => {
|
|
90
|
+
return this.client.post("/repository/toggleCustomRoles", {
|
|
91
|
+
domain: params.repository,
|
|
92
|
+
enabled: params.enabled,
|
|
93
|
+
author: ManageV2StaticAuthor
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* The function `toggleIntegrationFields` enables or disables the Integration Fields feature
|
|
98
|
+
*
|
|
99
|
+
* @param repository - The Repository name
|
|
100
|
+
* @param enabled - The feature new status
|
|
101
|
+
*/
|
|
102
|
+
toggleIntegrationFields = this.assertTokenExist((params) => {
|
|
103
|
+
return this.client.post("/repository/toggleIntegrationFields", {
|
|
104
|
+
domain: params.repository,
|
|
105
|
+
enabled: params.enabled,
|
|
106
|
+
author: ManageV2StaticAuthor
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* The function `changePlan` changes the plan of a repository the database
|
|
111
|
+
*
|
|
112
|
+
* @param repository - The Repository name
|
|
113
|
+
* @param newPlanId - The new planId
|
|
114
|
+
* @param bypassManualBilling - Beware that using this will not verify that the database and
|
|
115
|
+
* Stripe are in sync
|
|
116
|
+
*/
|
|
117
|
+
changePlan = this.assertTokenExist(({ repository, newPlanId, bypassManualBilling = false }) => {
|
|
118
|
+
return this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {
|
|
119
|
+
domain: repository,
|
|
120
|
+
newPlan: newPlanId,
|
|
121
|
+
author: ManageV2StaticAuthor
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* The function `addUserToRepository` adds a user corresponding to the email to the given
|
|
126
|
+
* repository
|
|
127
|
+
*
|
|
128
|
+
* @param repository - The Repository name
|
|
129
|
+
* @param email - The user email
|
|
130
|
+
*/
|
|
131
|
+
addUserToRepository = this.assertTokenExist(({ repository, email }) => {
|
|
132
|
+
return this.client.post("/repository/addUser", {
|
|
133
|
+
domain: repository,
|
|
134
|
+
email,
|
|
135
|
+
author: ManageV2StaticAuthor
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* The function `removeUserFromRepository` removes a user corresponding to the email from the
|
|
140
|
+
* given repository
|
|
141
|
+
*
|
|
142
|
+
* @param repository - The Repository name
|
|
143
|
+
* @param email - The user email
|
|
144
|
+
*/
|
|
145
|
+
removeUserFromRepository = this.assertTokenExist(({ repository, email }) => {
|
|
146
|
+
return this.client.post("/repository/removeUser", {
|
|
147
|
+
domain: repository,
|
|
148
|
+
email,
|
|
149
|
+
author: ManageV2StaticAuthor
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
172
154
|
exports.ManageV2Client = ManageV2Client;
|
|
173
|
-
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=manageV2.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manageV2.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"manageV2.cjs","names":["extractCookie","jwt"],"sources":["../../src/clients/manageV2.ts"],"sourcesContent":["import type { AxiosInstance, AxiosResponse } from \"axios\"\nimport axios from \"axios\"\nimport jwt from \"jsonwebtoken\"\n\nimport type { ManageV2Config } from \"../types\"\nimport { extractCookie } from \"../utils/cookies\"\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\"\n\n/** Client for interacting with ManageV2 routes to perform operations on repositories. */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance // Not private to have it available on tests\n\tprivate token: string | null = null\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t},\n\t\t})\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"]\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies\n\t\t\t}\n\n\t\t\treturn response\n\t\t})\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration parameters.\n\t *\n\t * @param {ManageV2Config} config - The `config` parameter in the `generateToken` function is of\n\t * type `ManageV2Config`. It contains the following properties:\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken` function. The token is\n\t * signed using the provided `config.secret` with the HS256 algorithm and includes the specified\n\t * audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t})\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a parameter. This function\n\t * `f` should accept a parameter of type `Parameters` and return a Promise that resolves to an\n\t * AxiosResponse. The `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t * @returns A function is being returned that takes a parameter of type Parameters and checks if\n\t * the token is null. If the token is null, an error is thrown. Otherwise, the function f is\n\t * called with the provided parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(f: (_: Parameters) => Promise<AxiosResponse>) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\"Undefined configuration for ManageV2 while trying to use it's routes\")\n\t\t\t} else {\n\t\t\t\treturn f(params)\n\t\t\t}\n\t\t}\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri()\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enables or disables the RolesPerLocale workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist((params: { repository: string; enabled: boolean }) => {\n\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\tdomain: params.repository,\n\t\t\tenabled: params.enabled,\n\t\t\tauthor: ManageV2StaticAuthor,\n\t\t})\n\t})\n\n\t/**\n\t * The function `toggleCustomRoles` enables or disables the CustomRoles workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleCustomRoles = this.assertTokenExist((params: { repository: string; enabled: boolean }) => {\n\t\treturn this.client.post(\"/repository/toggleCustomRoles\", {\n\t\t\tdomain: params.repository,\n\t\t\tenabled: params.enabled,\n\t\t\tauthor: ManageV2StaticAuthor,\n\t\t})\n\t})\n\n\t/**\n\t * The function `toggleIntegrationFields` enables or disables the Integration Fields feature\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleIntegrationFields = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleIntegrationFields\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t})\n\t\t},\n\t)\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that the database and\n\t * Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string\n\t\t\tnewPlanId: string\n\t\t\tbypassManualBilling?: boolean\n\t\t}) => {\n\t\t\treturn this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {\n\t\t\t\tdomain: repository,\n\t\t\t\tnewPlan: newPlanId,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t})\n\t\t},\n\t)\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email to the given\n\t * repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t})\n\t\t},\n\t)\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the email from the\n\t * given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t})\n\t\t},\n\t)\n}\n"],"mappings":";;;;;;;AAOA,MAAM,uBAAuB;;AAG7B,IAAa,iBAAb,MAA4B;CAC3B;CACA,QAA+B;;;;;CAM/B,YAAY,SAAiB,QAAqC;EACjE,KAAK,QAAQ,SAAS,KAAK,cAAc,MAAM,IAAI;EAEnD,KAAK,SAAS,MAAA,QAAM,OAAO;GAC1B,SAAS,GAAG,QAAQ;GACpB,iBAAiB;GACjB,sBAAsB;GACtB,SAAS;IACR,cAAc;IACd,eAAe,UAAU,KAAK;GAC/B;EACD,CAAC;EAGD,KAAK,OAAO,aAAa,SAAS,KAAK,aAAa;GACnD,MAAM,UAAU,SAAS,QAAQ;GACjC,IAAI,WAAWA,gBAAAA,cAAc,SAAS,SAAS,GAC9C,KAAK,OAAO,SAAS,QAAQ,YAAY;GAG1C,OAAO;EACR,CAAC;CACF;;;;;;;;;;CAWA,cAAsB,QAAgC;EACrD,OAAOC,aAAAA,QAAI,KAAK,CAAC,GAAG,OAAO,QAAQ;GAClC,WAAW;GACX,UAAU,OAAO;GACjB,QAAQ;EACT,CAAC;CACF;;;;;;;;;;;;CAaA,iBAAqC,GAA8C;EAClF,QAAQ,WAAuB;GAC9B,IAAI,KAAK,UAAU,MAClB,MAAM,IAAI,MAAM,sEAAsE;QAEtF,OAAO,EAAE,MAAM;EAEjB;CACD;CAEA,aAAqB;EACpB,OAAO,KAAK,OAAO,OAAO;CAC3B;;;;;;;CAQA,qBAAqB,KAAK,kBAAkB,WAAqD;EAChG,OAAO,KAAK,OAAO,KAAK,oCAAoC;GAC3D,QAAQ,OAAO;GACf,SAAS,OAAO;GAChB,QAAQ;EACT,CAAC;CACF,CAAC;;;;;;;CAQD,oBAAoB,KAAK,kBAAkB,WAAqD;EAC/F,OAAO,KAAK,OAAO,KAAK,iCAAiC;GACxD,QAAQ,OAAO;GACf,SAAS,OAAO;GAChB,QAAQ;EACT,CAAC;CACF,CAAC;;;;;;;CAQD,0BAA0B,KAAK,kBAC7B,WAAqD;EACrD,OAAO,KAAK,OAAO,KAAK,uCAAuC;GAC9D,QAAQ,OAAO;GACf,SAAS,OAAO;GAChB,QAAQ;EACT,CAAC;CACF,CACD;;;;;;;;;CAUA,aAAa,KAAK,kBAChB,EACA,YACA,WACA,sBAAsB,YAKjB;EACL,OAAO,KAAK,OAAO,KAAK,8CAA8C,uBAAuB;GAC5F,QAAQ;GACR,SAAS;GACT,QAAQ;EACT,CAAC;CACF,CACD;;;;;;;;CASA,sBAAsB,KAAK,kBACzB,EAAE,YAAY,YAAmD;EACjE,OAAO,KAAK,OAAO,KAAK,uBAAuB;GAC9C,QAAQ;GACD;GACP,QAAQ;EACT,CAAC;CACF,CACD;;;;;;;;CASA,2BAA2B,KAAK,kBAC9B,EAAE,YAAY,YAAmD;EACjE,OAAO,KAAK,OAAO,KAAK,0BAA0B;GACjD,QAAQ;GACD;GACP,QAAQ;EACT,CAAC;CACF,CACD;AACD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ManageV2Config } from "../types.cjs";
|
|
2
|
+
import { AxiosInstance, AxiosResponse } from "axios";
|
|
3
|
+
|
|
4
|
+
//#region src/clients/manageV2.d.ts
|
|
5
|
+
/** Client for interacting with ManageV2 routes to perform operations on repositories. */
|
|
6
|
+
declare class ManageV2Client {
|
|
7
|
+
readonly client: AxiosInstance;
|
|
8
|
+
private token;
|
|
9
|
+
/**
|
|
10
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
11
|
+
* @param config - ManageV2 configuration variable to call ManageV2.
|
|
12
|
+
*/
|
|
13
|
+
constructor(baseUrl: string, config?: ManageV2Config | undefined);
|
|
14
|
+
/**
|
|
15
|
+
* The function generates a JWT token using the provided configuration parameters.
|
|
16
|
+
*
|
|
17
|
+
* @param {ManageV2Config} config - The `config` parameter in the `generateToken` function is of
|
|
18
|
+
* type `ManageV2Config`. It contains the following properties:
|
|
19
|
+
* @returns A JSON Web Token (JWT) is being returned by the `generateToken` function. The token is
|
|
20
|
+
* signed using the provided `config.secret` with the HS256 algorithm and includes the specified
|
|
21
|
+
* audience and issuer values.
|
|
22
|
+
*/
|
|
23
|
+
private generateToken;
|
|
24
|
+
/**
|
|
25
|
+
* The function `assertTokenExist` checks if a token exists before executing a given function.
|
|
26
|
+
*
|
|
27
|
+
* @param f - The `assertTokenExist` function takes a function `f` as a parameter. This function
|
|
28
|
+
* `f` should accept a parameter of type `Parameters` and return a Promise that resolves to an
|
|
29
|
+
* AxiosResponse. The `assertTokenExist` function ensures that a token is not null before
|
|
30
|
+
* calling the provided
|
|
31
|
+
* @returns A function is being returned that takes a parameter of type Parameters and checks if
|
|
32
|
+
* the token is null. If the token is null, an error is thrown. Otherwise, the function f is
|
|
33
|
+
* called with the provided parameters.
|
|
34
|
+
*/
|
|
35
|
+
private assertTokenExist;
|
|
36
|
+
getBaseURL(): string;
|
|
37
|
+
/**
|
|
38
|
+
* The function `toggleRolePerLocal` enables or disables the RolesPerLocale workflow
|
|
39
|
+
*
|
|
40
|
+
* @param repository - The Repository name
|
|
41
|
+
* @param enabled - The feature new status
|
|
42
|
+
*/
|
|
43
|
+
toggleRolePerLocal: (params: {
|
|
44
|
+
repository: string;
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
}) => Promise<AxiosResponse<any, any, {}>>;
|
|
47
|
+
/**
|
|
48
|
+
* The function `toggleCustomRoles` enables or disables the CustomRoles workflow
|
|
49
|
+
*
|
|
50
|
+
* @param repository - The Repository name
|
|
51
|
+
* @param enabled - The feature new status
|
|
52
|
+
*/
|
|
53
|
+
toggleCustomRoles: (params: {
|
|
54
|
+
repository: string;
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
}) => Promise<AxiosResponse<any, any, {}>>;
|
|
57
|
+
/**
|
|
58
|
+
* The function `toggleIntegrationFields` enables or disables the Integration Fields feature
|
|
59
|
+
*
|
|
60
|
+
* @param repository - The Repository name
|
|
61
|
+
* @param enabled - The feature new status
|
|
62
|
+
*/
|
|
63
|
+
toggleIntegrationFields: (params: {
|
|
64
|
+
repository: string;
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
}) => Promise<AxiosResponse<any, any, {}>>;
|
|
67
|
+
/**
|
|
68
|
+
* The function `changePlan` changes the plan of a repository the database
|
|
69
|
+
*
|
|
70
|
+
* @param repository - The Repository name
|
|
71
|
+
* @param newPlanId - The new planId
|
|
72
|
+
* @param bypassManualBilling - Beware that using this will not verify that the database and
|
|
73
|
+
* Stripe are in sync
|
|
74
|
+
*/
|
|
75
|
+
changePlan: (params: {
|
|
76
|
+
repository: string;
|
|
77
|
+
newPlanId: string;
|
|
78
|
+
bypassManualBilling?: boolean;
|
|
79
|
+
}) => Promise<AxiosResponse<any, any, {}>>;
|
|
80
|
+
/**
|
|
81
|
+
* The function `addUserToRepository` adds a user corresponding to the email to the given
|
|
82
|
+
* repository
|
|
83
|
+
*
|
|
84
|
+
* @param repository - The Repository name
|
|
85
|
+
* @param email - The user email
|
|
86
|
+
*/
|
|
87
|
+
addUserToRepository: (params: {
|
|
88
|
+
repository: string;
|
|
89
|
+
email: string;
|
|
90
|
+
}) => Promise<AxiosResponse<any, any, {}>>;
|
|
91
|
+
/**
|
|
92
|
+
* The function `removeUserFromRepository` removes a user corresponding to the email from the
|
|
93
|
+
* given repository
|
|
94
|
+
*
|
|
95
|
+
* @param repository - The Repository name
|
|
96
|
+
* @param email - The user email
|
|
97
|
+
*/
|
|
98
|
+
removeUserFromRepository: (params: {
|
|
99
|
+
repository: string;
|
|
100
|
+
email: string;
|
|
101
|
+
}) => Promise<AxiosResponse<any, any, {}>>;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ManageV2Client };
|
|
105
|
+
//# sourceMappingURL=manageV2.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manageV2.d.cts","names":[],"sources":["../../src/clients/manageV2.ts"],"mappings":";;;;;cAUa,cAAA;EAAA,SACH,MAAA,EAAQ,aAAA;EAAA,QACT,KAAA;;;;;cAMI,OAAA,UAAiB,MAAA,GAAS,cAAA;;;;;;;;;;UAiC9B,aAAA;;;;;;;;;;;;UAmBA,gBAAA;EAUR,UAAA;;;;;;;EAUA,kBAAA,GAAkB,MAAA;;;;;;;;;;EAclB,iBAAA,GAAiB,MAAA;;;;;;;;;;EAcjB,uBAAA,GAAuB,MAAA;;;;EA4DvB;;;;;;;;EA1CA,UAAA,GAAU,MAAA;;;;;;;;;;;;EAyBV,mBAAA,GAAmB,MAAA;;;;;;;;;;;EAiBnB,wBAAA,GAAwB,MAAA"}
|