@credal/actions 0.1.57 → 0.1.59
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 +3 -1
- package/dist/actions/providers/confluence/fetchPageContent.js +8 -13
- package/dist/actions/providers/confluence/helpers.d.ts +2 -0
- package/dist/actions/providers/confluence/helpers.js +12 -0
- package/dist/actions/providers/confluence/overwritePage.js +9 -14
- package/dist/actions/providers/confluence/updatePage.d.ts +3 -0
- package/dist/actions/providers/confluence/updatePage.js +47 -0
- package/dist/actions/providers/workday/requestTimeOff.d.ts +23 -0
- package/dist/actions/providers/workday/requestTimeOff.js +88 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.d.ts +0 -3
- package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.js +0 -43
package/README.md
CHANGED
@@ -6,6 +6,8 @@ Easily add custom actions for your Credal Copilots. Read more about Credal's Age
|
|
6
6
|
|
7
7
|
## Adding or updating actions
|
8
8
|
|
9
|
+
We strongly encourage you to develop actions that rely on oauth based credentials. This is to ensure we respect the permissions of the underlying systems the actions library interacts with. In some situations, oauth is not a valid option and so API keys are a good fallback.
|
10
|
+
|
9
11
|
1. Add or update the action in `src/actions/schema.yaml`
|
10
12
|
2. Run `npm run generate:types` to generate the new types
|
11
13
|
3. Run `npm run prettier-format` to format the new files
|
@@ -25,7 +27,7 @@ const result = await runAction(
|
|
25
27
|
"listConversations",
|
26
28
|
"slack",
|
27
29
|
{ authToken: "xoxb-..." },
|
28
|
-
{}
|
30
|
+
{}
|
29
31
|
);
|
30
32
|
```
|
31
33
|
|
@@ -9,26 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
const helpers_1 = require("./helpers");
|
12
13
|
const axiosClient_1 = require("../../util/axiosClient");
|
13
|
-
function getConfluenceRequestConfig(baseUrl, username, apiToken) {
|
14
|
-
return {
|
15
|
-
baseURL: baseUrl,
|
16
|
-
headers: {
|
17
|
-
Accept: "application/json",
|
18
|
-
Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
|
19
|
-
},
|
20
|
-
};
|
21
|
-
}
|
22
14
|
const confluenceFetchPageContent = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
23
15
|
var _b, _c;
|
24
16
|
const { pageId } = params;
|
25
|
-
const {
|
26
|
-
if (!
|
17
|
+
const { authToken } = authParams;
|
18
|
+
if (!authToken) {
|
27
19
|
throw new Error("Missing required authentication parameters");
|
28
20
|
}
|
29
|
-
const
|
21
|
+
const cloudDetails = yield axiosClient_1.axiosClient.get("https://api.atlassian.com/oauth/token/accessible-resources");
|
22
|
+
const cloudId = cloudDetails.data[0].id;
|
23
|
+
const baseUrl = `https://api.atlassian.com/ex/confluence/${cloudId}/api/v2`;
|
24
|
+
const config = (0, helpers_1.getConfluenceRequestConfig)(baseUrl, authToken);
|
30
25
|
// Get page content and metadata
|
31
|
-
const response = yield axiosClient_1.axiosClient.get(`/
|
26
|
+
const response = yield axiosClient_1.axiosClient.get(`/pages/${pageId}?body-format=storage`, config);
|
32
27
|
// Extract needed data from response
|
33
28
|
const title = response.data.title;
|
34
29
|
const content = ((_c = (_b = response.data.body) === null || _b === void 0 ? void 0 : _b.storage) === null || _c === void 0 ? void 0 : _c.value) || "";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getConfluenceRequestConfig = getConfluenceRequestConfig;
|
4
|
+
function getConfluenceRequestConfig(baseUrl, authToken) {
|
5
|
+
return {
|
6
|
+
baseURL: baseUrl,
|
7
|
+
headers: {
|
8
|
+
Accept: "application/json",
|
9
|
+
Authorization: `Bearer ${authToken}`,
|
10
|
+
},
|
11
|
+
};
|
12
|
+
}
|
@@ -10,24 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
const axiosClient_1 = require("../../util/axiosClient");
|
13
|
-
|
14
|
-
return {
|
15
|
-
baseURL: baseUrl,
|
16
|
-
headers: {
|
17
|
-
Accept: "application/json",
|
18
|
-
Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
|
19
|
-
},
|
20
|
-
};
|
21
|
-
}
|
13
|
+
const helpers_1 = require("./helpers");
|
22
14
|
const confluenceOverwritePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
23
15
|
const { pageId, content, title } = params;
|
24
|
-
const {
|
25
|
-
if (!
|
16
|
+
const { authToken } = authParams;
|
17
|
+
if (!authToken) {
|
26
18
|
throw new Error("Missing required authentication parameters");
|
27
19
|
}
|
28
|
-
const
|
20
|
+
const cloudDetails = yield axiosClient_1.axiosClient.get("https://api.atlassian.com/oauth/token/accessible-resources");
|
21
|
+
const cloudId = cloudDetails.data[0].id;
|
22
|
+
const baseUrl = `https://api.atlassian.com/ex/confluence/${cloudId}/api/v2`;
|
23
|
+
const config = (0, helpers_1.getConfluenceRequestConfig)(baseUrl, authToken);
|
29
24
|
// Get current page content and version number
|
30
|
-
const response = yield axiosClient_1.axiosClient.get(`/
|
25
|
+
const response = yield axiosClient_1.axiosClient.get(`/pages/${pageId}?body-format=storage`, config);
|
31
26
|
const currVersion = response.data.version.number;
|
32
27
|
const payload = {
|
33
28
|
id: pageId,
|
@@ -41,6 +36,6 @@ const confluenceOverwritePage = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
41
36
|
number: currVersion + 1,
|
42
37
|
},
|
43
38
|
};
|
44
|
-
yield axiosClient_1.axiosClient.put(`/
|
39
|
+
yield axiosClient_1.axiosClient.put(`/pages/${pageId}`, payload, config);
|
45
40
|
});
|
46
41
|
exports.default = confluenceOverwritePage;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
16
|
+
function getConfluenceApi(baseUrl, username, apiToken) {
|
17
|
+
const api = axios_1.default.create({
|
18
|
+
baseURL: baseUrl,
|
19
|
+
headers: {
|
20
|
+
Accept: "application/json",
|
21
|
+
// Tokens are associated with a specific user.
|
22
|
+
Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
|
23
|
+
},
|
24
|
+
});
|
25
|
+
return api;
|
26
|
+
}
|
27
|
+
const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
28
|
+
const { pageId, username, content, title } = params;
|
29
|
+
const { baseUrl, authToken } = authParams;
|
30
|
+
const api = getConfluenceApi(baseUrl, username, authToken);
|
31
|
+
// Get current version number
|
32
|
+
const response = yield api.get(`/api/v2/pages/${pageId}`);
|
33
|
+
const currVersion = response.data.version.number;
|
34
|
+
yield api.put(`/api/v2/pages/${pageId}`, {
|
35
|
+
id: pageId,
|
36
|
+
status: "current",
|
37
|
+
title,
|
38
|
+
body: {
|
39
|
+
representation: "storage",
|
40
|
+
value: content,
|
41
|
+
},
|
42
|
+
version: {
|
43
|
+
number: currVersion + 1,
|
44
|
+
},
|
45
|
+
});
|
46
|
+
});
|
47
|
+
exports.default = confluenceUpdatePage;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
declare const axios: any;
|
2
|
+
declare const WORKDAY_BASE_URL = "https://your-workday-url/ccx/service/YOUR_TENANT/Absence_Management/v43.2";
|
3
|
+
declare const TOKEN_URL = "https://your-workday-url/oauth2/YOUR_TENANT/token";
|
4
|
+
declare const CLIENT_ID = "your-client-id";
|
5
|
+
declare const CLIENT_SECRET = "your-client-secret";
|
6
|
+
/**
|
7
|
+
* Fetches an OAuth 2.0 access token from Workday.
|
8
|
+
*/
|
9
|
+
declare function getAccessToken(): Promise<any>;
|
10
|
+
/**
|
11
|
+
* Submits a time-off request to Workday.
|
12
|
+
* @param {Object} params - Time-off details.
|
13
|
+
* @param {string} params.workerId - Worker's ID in Workday.
|
14
|
+
* @param {string} params.startDate - Start date (YYYY-MM-DD).
|
15
|
+
* @param {string} params.endDate - End date (YYYY-MM-DD).
|
16
|
+
* @param {string} params.timeOffType - Time-off type (e.g., "SICK_LEAVE").
|
17
|
+
*/
|
18
|
+
declare function submitTimeOff({ workerId, startDate, endDate, timeOffType }: {
|
19
|
+
workerId: any;
|
20
|
+
startDate: any;
|
21
|
+
endDate: any;
|
22
|
+
timeOffType: any;
|
23
|
+
}): Promise<any>;
|
@@ -0,0 +1,88 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
const axios = require("axios");
|
12
|
+
const WORKDAY_BASE_URL = "https://your-workday-url/ccx/service/YOUR_TENANT/Absence_Management/v43.2";
|
13
|
+
const TOKEN_URL = "https://your-workday-url/oauth2/YOUR_TENANT/token"; // OAuth token endpoint
|
14
|
+
const CLIENT_ID = "your-client-id";
|
15
|
+
const CLIENT_SECRET = "your-client-secret";
|
16
|
+
/**
|
17
|
+
* Fetches an OAuth 2.0 access token from Workday.
|
18
|
+
*/
|
19
|
+
function getAccessToken() {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
var _a;
|
22
|
+
try {
|
23
|
+
const response = yield axios.post(TOKEN_URL, new URLSearchParams({ grant_type: "client_credentials" }), {
|
24
|
+
auth: {
|
25
|
+
username: CLIENT_ID,
|
26
|
+
password: CLIENT_SECRET
|
27
|
+
},
|
28
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
29
|
+
});
|
30
|
+
return response.data.access_token;
|
31
|
+
}
|
32
|
+
catch (error) {
|
33
|
+
console.error("Error fetching access token:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
|
34
|
+
throw error;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Submits a time-off request to Workday.
|
40
|
+
* @param {Object} params - Time-off details.
|
41
|
+
* @param {string} params.workerId - Worker's ID in Workday.
|
42
|
+
* @param {string} params.startDate - Start date (YYYY-MM-DD).
|
43
|
+
* @param {string} params.endDate - End date (YYYY-MM-DD).
|
44
|
+
* @param {string} params.timeOffType - Time-off type (e.g., "SICK_LEAVE").
|
45
|
+
*/
|
46
|
+
function submitTimeOff(_a) {
|
47
|
+
return __awaiter(this, arguments, void 0, function* ({ workerId, startDate, endDate, timeOffType }) {
|
48
|
+
var _b;
|
49
|
+
try {
|
50
|
+
const token = yield getAccessToken(); // Get OAuth token
|
51
|
+
const requestBody = {
|
52
|
+
"wd:Enter_Time_Off_Request": {
|
53
|
+
"wd:Worker_Reference": {
|
54
|
+
"wd:ID": [{ "_": workerId, "$": { "wd:type": "WID" } }]
|
55
|
+
},
|
56
|
+
"wd:Time_Off_Entries": [
|
57
|
+
{
|
58
|
+
"wd:Start_Date": startDate,
|
59
|
+
"wd:End_Date": endDate,
|
60
|
+
"wd:Time_Off_Type_Reference": {
|
61
|
+
"wd:ID": [{ "_": timeOffType, "$": { "wd:type": "Time_Off_Type_ID" } }]
|
62
|
+
}
|
63
|
+
}
|
64
|
+
]
|
65
|
+
}
|
66
|
+
};
|
67
|
+
const response = yield axios.post(`${WORKDAY_BASE_URL}/Enter_Time_Off`, requestBody, {
|
68
|
+
headers: {
|
69
|
+
"Authorization": `Bearer ${token}`,
|
70
|
+
"Content-Type": "application/json"
|
71
|
+
}
|
72
|
+
});
|
73
|
+
console.log("Time-off request submitted successfully:", response.data);
|
74
|
+
return response.data;
|
75
|
+
}
|
76
|
+
catch (error) {
|
77
|
+
console.error("Error submitting time-off request:", ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || error.message);
|
78
|
+
throw error;
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}
|
82
|
+
// Example Usage:
|
83
|
+
submitTimeOff({
|
84
|
+
workerId: "12345",
|
85
|
+
startDate: "2025-03-10",
|
86
|
+
endDate: "2025-03-12",
|
87
|
+
timeOffType: "SICK_LEAVE"
|
88
|
+
}).then(console.log).catch(console.error);
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
export { runAction, getActionGroups, type ActionGroupsReturn } from "./app";
|
2
2
|
export { ACTION_GROUPS, type ActionGroups } from "./actions/groups";
|
3
|
+
export { ActionMapper } from "./actions/actionMapper";
|
3
4
|
export * from "./actions/autogen/templates";
|
4
5
|
export * from "./actions/autogen/types";
|
5
6
|
export * from "./actions/providers/math/index";
|
package/dist/index.js
CHANGED
@@ -15,12 +15,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
16
16
|
};
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.ACTION_GROUPS = exports.getActionGroups = exports.runAction = void 0;
|
18
|
+
exports.ActionMapper = exports.ACTION_GROUPS = exports.getActionGroups = exports.runAction = void 0;
|
19
19
|
var app_1 = require("./app");
|
20
20
|
Object.defineProperty(exports, "runAction", { enumerable: true, get: function () { return app_1.runAction; } });
|
21
21
|
Object.defineProperty(exports, "getActionGroups", { enumerable: true, get: function () { return app_1.getActionGroups; } });
|
22
22
|
var groups_1 = require("./actions/groups");
|
23
23
|
Object.defineProperty(exports, "ACTION_GROUPS", { enumerable: true, get: function () { return groups_1.ACTION_GROUPS; } });
|
24
|
+
var actionMapper_1 = require("./actions/actionMapper");
|
25
|
+
Object.defineProperty(exports, "ActionMapper", { enumerable: true, get: function () { return actionMapper_1.ActionMapper; } });
|
24
26
|
__exportStar(require("./actions/autogen/templates"), exports);
|
25
27
|
__exportStar(require("./actions/autogen/types"), exports);
|
26
28
|
__exportStar(require("./actions/providers/math/index"), exports);
|
package/package.json
CHANGED
@@ -1,43 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
const axiosClient_1 = require("../../util/axiosClient");
|
13
|
-
const getSalesforceRecordByQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
14
|
-
const { authToken, baseUrl } = authParams;
|
15
|
-
const { query, limit } = params;
|
16
|
-
if (!authToken || !baseUrl) {
|
17
|
-
return {
|
18
|
-
success: false,
|
19
|
-
error: "authToken and baseUrl are required for Salesforce API",
|
20
|
-
};
|
21
|
-
}
|
22
|
-
// The API limits the maximum number of records returned to 2000, the limit lets the user set a smaller custom limit
|
23
|
-
const url = `${baseUrl}/services/data/v56.0/query/?q=${encodeURIComponent(query + " LIMIT " + (limit != undefined && limit <= 2000 ? limit : 2000))}`;
|
24
|
-
try {
|
25
|
-
const response = yield axiosClient_1.axiosClient.get(url, {
|
26
|
-
headers: {
|
27
|
-
Authorization: `Bearer ${authToken}`,
|
28
|
-
},
|
29
|
-
});
|
30
|
-
return {
|
31
|
-
success: true,
|
32
|
-
records: response.data,
|
33
|
-
};
|
34
|
-
}
|
35
|
-
catch (error) {
|
36
|
-
console.error("Error retrieving Salesforce record:", error);
|
37
|
-
return {
|
38
|
-
success: false,
|
39
|
-
error: error instanceof Error ? error.message : "An unknown error occurred",
|
40
|
-
};
|
41
|
-
}
|
42
|
-
});
|
43
|
-
exports.default = getSalesforceRecordByQuery;
|