@stackfactor/client-api 1.1.11 → 1.1.12-9.2
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/.eslintrc.json +13 -0
- package/{exports.js → exports.ts} +14 -0
- package/index.ts +1 -0
- package/lib/{actionNotifications.js → actionNotifications.ts} +21 -11
- package/lib/{address.js → address.ts} +4 -5
- package/lib/aiAssistant.ts +197 -0
- package/lib/avatar.ts +41 -0
- package/lib/axiosClient.ts +92 -0
- package/lib/{config.js → config.ts} +20 -9
- package/lib/{constants.js → constants.ts} +11 -41
- package/lib/{dashboard.js → dashboard.ts} +19 -10
- package/lib/{departmentTrainingPlans.js → departmentTrainingPlans.ts} +63 -32
- package/lib/{groups.js → groups.ts} +68 -29
- package/lib/{integration.js → integration.ts} +103 -47
- package/lib/{integrationConfiguration.js → integrationConfiguration.ts} +27 -22
- package/lib/integrations/{contentGenerator.js → contentGenerator.ts} +38 -18
- package/lib/{learningContent.js → learningContent.ts} +218 -62
- package/lib/{learningPath.js → learningPath.ts} +57 -30
- package/lib/{logger.js → logger.ts} +18 -8
- package/lib/microSkillsQuizes.ts +70 -0
- package/lib/quotas.ts +59 -0
- package/lib/{role.js → role.ts} +117 -69
- package/lib/{roleTemplate.js → roleTemplate.ts} +65 -30
- package/lib/security.ts +99 -0
- package/lib/{skill.js → skill.ts} +125 -87
- package/lib/{skillAssessments.js → skillAssessmentTestingSession.ts} +63 -16
- package/lib/skillAssessments.ts +192 -0
- package/lib/{skillTemplate.js → skillTemplate.ts} +73 -42
- package/lib/talentTransfromation.ts +126 -0
- package/lib/{teams.js → teams.ts} +73 -38
- package/lib/{tenants.js → tenants.ts} +17 -10
- package/lib/{trainingPlans.js → trainingPlans.ts} +159 -56
- package/lib/trainingPlansProficiencyLevels.ts +132 -0
- package/lib/{userInformation.js → userInformation.ts} +27 -26
- package/lib/{users.js → users.ts} +239 -140
- package/lib/utils.ts +64 -0
- package/package.json +12 -1
- package/index.js +0 -3
- package/lib/axiosClient.js +0 -85
- package/lib/skillAssessmentTestingSession.js +0 -148
- package/lib/utils.js +0 -48
package/lib/utils.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
//import dotenv from "dotenv";
|
|
3
|
+
// Load environment variables from .env file
|
|
4
|
+
//dotenv.config();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convert object to array
|
|
8
|
+
* @param {Object} data
|
|
9
|
+
* @returns {Array}
|
|
10
|
+
*/
|
|
11
|
+
const objectToArray = (data: object): any[] => {
|
|
12
|
+
if (typeof data === "object") {
|
|
13
|
+
return [...Object.values(data)];
|
|
14
|
+
} else throw new Error("Invalid type");
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the backend base API URL
|
|
19
|
+
* @returns {String}
|
|
20
|
+
*/
|
|
21
|
+
const getBaseUrl = (): string => {
|
|
22
|
+
if (process.env.REACT_APP_BACKEND_URL) {
|
|
23
|
+
return process.env.REACT_APP_BACKEND_URL;
|
|
24
|
+
} else {
|
|
25
|
+
switch (process.env.REACT_APP_NODE_ENV) {
|
|
26
|
+
case "development":
|
|
27
|
+
case null:
|
|
28
|
+
case undefined:
|
|
29
|
+
return "https://localhost/";
|
|
30
|
+
case "testing":
|
|
31
|
+
return "https://qaapi.stackfactor.ai/";
|
|
32
|
+
case "nonprod":
|
|
33
|
+
return "https://apiqa.stackfactor.ai/";
|
|
34
|
+
case "production":
|
|
35
|
+
return "https://api.stackfactor.ai/";
|
|
36
|
+
case "security":
|
|
37
|
+
return "https://csapi.stackfactor.ai/";
|
|
38
|
+
default:
|
|
39
|
+
throw new Error("Invalid environment");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Remove null properties
|
|
46
|
+
* @param {Object} object
|
|
47
|
+
* @returns {Object}
|
|
48
|
+
*/
|
|
49
|
+
const removeNullProperties = (object: { [key: string]: any }): object => {
|
|
50
|
+
Object.keys(object).forEach((key) => {
|
|
51
|
+
let value = object[key];
|
|
52
|
+
let hasProperties = value && Object.keys(value).length > 0;
|
|
53
|
+
if (value === null) {
|
|
54
|
+
delete object[key];
|
|
55
|
+
} else if (typeof value !== "string" && hasProperties) {
|
|
56
|
+
removeNullProperties(value);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return object;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const utils = { getBaseUrl, objectToArray, removeNullProperties };
|
|
63
|
+
|
|
64
|
+
export default utils;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackfactor/client-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.129.2",
|
|
4
4
|
"description": "Node.js library for the StackFactor API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"scripts": {
|
|
15
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
16
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
17
|
+
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
18
|
+
"build:watch": "tsc --watch",
|
|
19
|
+
"lint": "eslint lib/**/*.js",
|
|
15
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
21
|
},
|
|
17
22
|
"repository": {
|
|
@@ -30,5 +35,11 @@
|
|
|
30
35
|
"html2plaintext": "^2.1.4",
|
|
31
36
|
"https": "^1.0.0",
|
|
32
37
|
"node-html-parser": "^6.1.5"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/axios": "^0.14.4",
|
|
41
|
+
"@types/node": "^22.13.5",
|
|
42
|
+
"eslint": "^8.57.0",
|
|
43
|
+
"eslint-plugin-react": "^7.34.0"
|
|
33
44
|
}
|
|
34
45
|
}
|
package/index.js
DELETED
package/lib/axiosClient.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { RESPONSE_TYPE } from "./constants.js";
|
|
3
|
-
import https from "https";
|
|
4
|
-
import utils from "./utils.js";
|
|
5
|
-
|
|
6
|
-
const baseUrl = utils.getBaseUrl();
|
|
7
|
-
|
|
8
|
-
const client = axios.create({
|
|
9
|
-
baseURL: baseUrl,
|
|
10
|
-
httpsAgent: new https.Agent({
|
|
11
|
-
rejectUnauthorized: false,
|
|
12
|
-
}),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns the error as a string
|
|
17
|
-
* @param {Object} error
|
|
18
|
-
*/
|
|
19
|
-
const errorToString = (error) => {
|
|
20
|
-
if (error != null) {
|
|
21
|
-
if (error?.response?.data) {
|
|
22
|
-
let asString = "";
|
|
23
|
-
if (Array.isArray(error.response.data.errors)) {
|
|
24
|
-
error.response.data.errors.forEach((item, index) => {
|
|
25
|
-
asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
|
|
26
|
-
item.param
|
|
27
|
-
} ${item.value ? `value ${item.value.toString()}` : ""}`;
|
|
28
|
-
});
|
|
29
|
-
return asString;
|
|
30
|
-
} else if (error.response.data.error) {
|
|
31
|
-
return error.response.data.error.toString();
|
|
32
|
-
} else if (error.response.statusText) {
|
|
33
|
-
return error.response.statusText.toString();
|
|
34
|
-
} else {
|
|
35
|
-
return error.response.data.toString();
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
return error.message ? error.message : "Unknown error";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns the code of the error as a number
|
|
45
|
-
* @param {Object} error
|
|
46
|
-
* @returns {Number} The error code
|
|
47
|
-
*/
|
|
48
|
-
const getErrorType = (error) => {
|
|
49
|
-
if (error?.response?.status) {
|
|
50
|
-
return error.response.status;
|
|
51
|
-
} else return RESPONSE_TYPE.SERVICE_UNAVAILABLE;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Return the error information to include just the status and the message
|
|
56
|
-
* @param {Object} error
|
|
57
|
-
* @returns Object
|
|
58
|
-
*/
|
|
59
|
-
const getErrorInformation = (error) => {
|
|
60
|
-
return {
|
|
61
|
-
status: getErrorType(error),
|
|
62
|
-
message: errorToString(error),
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Returns true if an exception should be handled to the business and presentation layer
|
|
68
|
-
* @param {Boolean} returnAllExceptions - If set true all exceptions will be passed
|
|
69
|
-
* @param {Object} error - The error returned by the server
|
|
70
|
-
*/
|
|
71
|
-
const shouldReturnError = (returnAllExceptions, error) => {
|
|
72
|
-
if (getErrorType(error) === RESPONSE_TYPE.UNAUTHORIZED) {
|
|
73
|
-
return returnAllExceptions;
|
|
74
|
-
} else {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export {
|
|
80
|
-
client,
|
|
81
|
-
errorToString,
|
|
82
|
-
getErrorType,
|
|
83
|
-
getErrorInformation,
|
|
84
|
-
shouldReturnError,
|
|
85
|
-
};
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { client } from "./axiosClient.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* End an existing testing session
|
|
5
|
-
* @param {String} testingSessionId
|
|
6
|
-
* @param {String} token Authorization token
|
|
7
|
-
*/
|
|
8
|
-
export const endSession = (testingSessionId, token) => {
|
|
9
|
-
return new Promise(function (resolve, reject) {
|
|
10
|
-
let confirmationRequest = client.put(
|
|
11
|
-
"api/v1/skillassessmenttestingsession/endsession",
|
|
12
|
-
{ id: testingSessionId },
|
|
13
|
-
{
|
|
14
|
-
headers: { authorization: token },
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
confirmationRequest
|
|
18
|
-
.then((response) => {
|
|
19
|
-
resolve(response.data);
|
|
20
|
-
})
|
|
21
|
-
.catch((error) => {
|
|
22
|
-
reject(error);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* End an existing testing session
|
|
29
|
-
* @param {String} testingSessionId
|
|
30
|
-
* @param {Array<String>} selectedAnswers
|
|
31
|
-
* @param {String} token Authorization token
|
|
32
|
-
*/
|
|
33
|
-
export const getNextStep = (testingSessionId, selectedAnswers, token) => {
|
|
34
|
-
return new Promise(function (resolve, reject) {
|
|
35
|
-
let data = {
|
|
36
|
-
id: testingSessionId,
|
|
37
|
-
};
|
|
38
|
-
if (selectedAnswers) data.selectedAnswers = selectedAnswers;
|
|
39
|
-
let confirmationRequest = client.post(
|
|
40
|
-
`api/v1/skillassessmenttestingsession/getnextstep`,
|
|
41
|
-
data,
|
|
42
|
-
{
|
|
43
|
-
headers: { authorization: token },
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
confirmationRequest
|
|
47
|
-
.then((response) => {
|
|
48
|
-
resolve(response.data);
|
|
49
|
-
})
|
|
50
|
-
.catch((error) => {
|
|
51
|
-
reject(error);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get skill assessment by user and skill
|
|
58
|
-
* @param {String} userId
|
|
59
|
-
* @param {String} skillId
|
|
60
|
-
* @param {String} token
|
|
61
|
-
* @returns
|
|
62
|
-
*/
|
|
63
|
-
export const getSkillTestAssessment = (userId, skillId, token) => {
|
|
64
|
-
return new Promise(function (resolve, reject) {
|
|
65
|
-
let confirmationRequest = client.post(
|
|
66
|
-
`api/v1/skillassessmenttestingsession/getbyuserandskill`,
|
|
67
|
-
{
|
|
68
|
-
userId: userId,
|
|
69
|
-
skillId: skillId,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
headers: { authorization: token },
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
confirmationRequest
|
|
76
|
-
.then((response) => {
|
|
77
|
-
resolve(response.data);
|
|
78
|
-
})
|
|
79
|
-
.catch((error) => {
|
|
80
|
-
reject(error);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Pause skill assessment
|
|
87
|
-
* @param {String} testingSessionId
|
|
88
|
-
* @param {String} token
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
export const pause = (testingSessionId, token) => {
|
|
92
|
-
return new Promise(function (resolve, reject) {
|
|
93
|
-
let confirmationRequest = client.post(
|
|
94
|
-
`api/v1/skillassessmenttestingsession/pausesession`,
|
|
95
|
-
{
|
|
96
|
-
id: testingSessionId,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
headers: { authorization: token },
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
confirmationRequest
|
|
103
|
-
.then((response) => {
|
|
104
|
-
resolve(response.data);
|
|
105
|
-
})
|
|
106
|
-
.catch((error) => {
|
|
107
|
-
reject(error);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Start a new test skill test assessment session
|
|
114
|
-
* @param {String} skillId
|
|
115
|
-
* @param {Boolean} saveSession
|
|
116
|
-
* @param {String} token
|
|
117
|
-
*/
|
|
118
|
-
export const startSession = (skillId, saveSession, token) => {
|
|
119
|
-
return new Promise(function (resolve, reject) {
|
|
120
|
-
let confirmationRequest = client.post(
|
|
121
|
-
"api/v1/skillassessmenttestingsession/startsession",
|
|
122
|
-
{
|
|
123
|
-
saveSession: saveSession,
|
|
124
|
-
skillId: skillId,
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
headers: { authorization: token },
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
confirmationRequest
|
|
131
|
-
.then((response) => {
|
|
132
|
-
resolve(response.data);
|
|
133
|
-
})
|
|
134
|
-
.catch((error) => {
|
|
135
|
-
reject(error);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const skillAessementTestingSession = {
|
|
141
|
-
endSession,
|
|
142
|
-
getNextStep,
|
|
143
|
-
getSkillTestAssessment,
|
|
144
|
-
pause,
|
|
145
|
-
startSession,
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export default skillAessementTestingSession;
|
package/lib/utils.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
// Load environment variables from .env file
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Convert object to array
|
|
7
|
-
* @param {Object} data
|
|
8
|
-
* @returns {Array}
|
|
9
|
-
*/
|
|
10
|
-
export const objectToArray = (data) => {
|
|
11
|
-
if (typeof data === "object") {
|
|
12
|
-
return [...data];
|
|
13
|
-
} else throw new Error("Invalid type");
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns the backend base API URL
|
|
18
|
-
* @returns {String}
|
|
19
|
-
*/
|
|
20
|
-
export const getBaseUrl = () => {
|
|
21
|
-
if (!process.env.NODE_ENV || process.env.NODE_ENV === "production") {
|
|
22
|
-
return "https://api.stackfactor.io/";
|
|
23
|
-
} else {
|
|
24
|
-
return "http://localhost:3100/";
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Remove null properties
|
|
30
|
-
* @param {Object} object
|
|
31
|
-
* @returns {Object}
|
|
32
|
-
*/
|
|
33
|
-
export const removeNullProperties = (object) => {
|
|
34
|
-
Object.keys(object).forEach((key) => {
|
|
35
|
-
let value = object[key.toString()];
|
|
36
|
-
let hasProperties = value && Object.keys(value).length > 0;
|
|
37
|
-
if (value === null) {
|
|
38
|
-
delete object[key.toString()];
|
|
39
|
-
} else if (typeof value !== "string" && hasProperties) {
|
|
40
|
-
removeNullProperties(value);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return object;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const utils = { getBaseUrl, objectToArray, removeNullProperties };
|
|
47
|
-
|
|
48
|
-
export default utils;
|