-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.js
More file actions
53 lines (51 loc) · 1.33 KB
/
authentication.js
File metadata and controls
53 lines (51 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
const testAuth = async (z, bundle) => {
const apiHost = bundle.authData.apiHost || "https://cloud.yepcode.io";
const options = {
url: `${apiHost}/run/whoami`,
headers: {
"x-api-token": bundle.authData.apiToken,
},
};
return z
.request(options)
.then((response) => {
response.throwForStatus();
return response.data;
})
.catch((error) => {
if (error.message.includes("Invalid API token")) {
throw new z.errors.Error(
"Invalid API Token",
"AuthenticationError",
401
);
}
throw new z.errors.Error("Invalid API Host", "AuthenticationError", 401);
});
};
module.exports = {
type: "custom",
test: testAuth,
fields: [
{
computed: false,
key: "apiToken",
required: true,
label: "API Token",
type: "password",
helpText:
"Find your API Token in the YepCode dashboard under the 'Settings -> API Credentials' section.",
},
{
computed: false,
key: "apiHost",
required: false,
label: "API Host",
type: "string",
helpText:
"The YepCode API host to use (default: https://cloud.yepcode.io). It can be customized for YepCode On-Premise instances.",
default: "https://cloud.yepcode.io",
},
],
connectionLabel: "Connected to YepCode",
};