@credal/actions 0.1.32 → 0.1.34

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.
Files changed (62) hide show
  1. package/dist/actions/actionMapper.js +101 -1
  2. package/dist/actions/autogen/definitions.d.ts +5 -0
  3. package/dist/actions/autogen/definitions.js +132 -0
  4. package/dist/actions/autogen/templates.d.ts +17 -1
  5. package/dist/actions/autogen/templates.js +3629 -119
  6. package/dist/actions/autogen/types.d.ts +755 -26
  7. package/dist/actions/autogen/types.js +1579 -12
  8. package/dist/actions/definitions.js +35 -0
  9. package/dist/actions/groups.js +26 -3
  10. package/dist/actions/invokeMapper.d.ts +9 -0
  11. package/dist/actions/invokeMapper.js +33 -0
  12. package/dist/actions/providers/asana/commentAsanaTask.d.ts +3 -0
  13. package/dist/actions/providers/asana/commentAsanaTask.js +44 -0
  14. package/dist/actions/providers/asana/createAsanaTask.d.ts +3 -0
  15. package/dist/actions/providers/asana/createAsanaTask.js +93 -0
  16. package/dist/actions/providers/asana/updateAsanaTask.d.ts +3 -0
  17. package/dist/actions/providers/asana/updateAsanaTask.js +50 -0
  18. package/dist/actions/providers/asana/utils.d.ts +6 -0
  19. package/dist/actions/providers/asana/utils.js +73 -0
  20. package/dist/actions/providers/confluence/updatePage.js +9 -13
  21. package/dist/actions/providers/github/createBranch.d.ts +6 -0
  22. package/dist/actions/providers/github/createBranch.js +68 -0
  23. package/dist/actions/providers/github/createOrUpdateFile.d.ts +6 -0
  24. package/dist/actions/providers/github/createOrUpdateFile.js +75 -0
  25. package/dist/actions/providers/github/createPullRequest.d.ts +6 -0
  26. package/dist/actions/providers/github/createPullRequest.js +48 -0
  27. package/dist/actions/providers/google-oauth/createPresentation.d.ts +6 -0
  28. package/dist/actions/providers/google-oauth/createPresentation.js +52 -0
  29. package/dist/actions/providers/google-oauth/createSpreadsheet.d.ts +6 -0
  30. package/dist/actions/providers/google-oauth/createSpreadsheet.js +62 -0
  31. package/dist/actions/providers/google-oauth/updateDoc.d.ts +7 -0
  32. package/dist/actions/providers/google-oauth/updateDoc.js +69 -0
  33. package/dist/actions/providers/google-oauth/updatePresentation.d.ts +7 -0
  34. package/dist/actions/providers/google-oauth/updatePresentation.js +64 -0
  35. package/dist/actions/providers/google-oauth/updateSpreadsheet.d.ts +7 -0
  36. package/dist/actions/providers/google-oauth/updateSpreadsheet.js +51 -0
  37. package/dist/actions/providers/googlemaps/nearbysearch.d.ts +3 -0
  38. package/dist/actions/providers/googlemaps/nearbysearch.js +96 -0
  39. package/dist/actions/providers/jira/commentJiraTicket.d.ts +2 -2
  40. package/dist/actions/providers/jira/commentJiraTicket.js +2 -2
  41. package/dist/actions/providers/jira/createTicket.d.ts +3 -0
  42. package/dist/actions/providers/jira/createTicket.js +34 -0
  43. package/dist/actions/providers/jira/getJiraTicketDetails.d.ts +3 -0
  44. package/dist/actions/providers/jira/getJiraTicketDetails.js +40 -0
  45. package/dist/actions/providers/jira/getJiraTicketHistory.d.ts +3 -0
  46. package/dist/actions/providers/jira/getJiraTicketHistory.js +41 -0
  47. package/dist/actions/providers/jira/updateJiraTicketDetails.d.ts +3 -0
  48. package/dist/actions/providers/jira/updateJiraTicketDetails.js +56 -0
  49. package/dist/actions/providers/jira/updateJiraTicketStatus.d.ts +3 -0
  50. package/dist/actions/providers/jira/updateJiraTicketStatus.js +57 -0
  51. package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.d.ts +3 -0
  52. package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.js +43 -0
  53. package/dist/actions/providers/slack/list_conversations.d.ts +3 -0
  54. package/dist/actions/providers/slack/list_conversations.js +60 -0
  55. package/dist/actions/providers/slack/summarizeChannel.d.ts +3 -0
  56. package/dist/actions/providers/slack/summarizeChannel.js +51 -0
  57. package/dist/actions/schema.js +6 -0
  58. package/dist/actions/types.js +2 -0
  59. package/dist/main.js +11 -0
  60. package/package.json +2 -1
  61. package/dist/actions/providers/workday/requestTimeOff.d.ts +0 -23
  62. package/dist/actions/providers/workday/requestTimeOff.js +0 -88
@@ -0,0 +1,56 @@
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 updateJiraTicketDetails = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
14
+ const { authToken, cloudId, baseUrl } = authParams;
15
+ const { issueId, summary, description, customFields } = params;
16
+ if (!cloudId || !issueId) {
17
+ throw new Error("Cloud ID and Issue ID are required to update a Jira ticket");
18
+ }
19
+ const apiUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${issueId}`;
20
+ const formattedDescription = description
21
+ ? {
22
+ type: "doc",
23
+ version: 1,
24
+ content: [
25
+ {
26
+ type: "paragraph",
27
+ content: [
28
+ {
29
+ type: "text",
30
+ text: description,
31
+ },
32
+ ],
33
+ },
34
+ ],
35
+ }
36
+ : undefined;
37
+ const payload = {
38
+ fields: Object.assign(Object.assign(Object.assign({}, (summary && { summary })), (formattedDescription && { description: formattedDescription })), (customFields && Object.assign({}, customFields))),
39
+ };
40
+ try {
41
+ yield axiosClient_1.axiosClient.put(apiUrl, payload, {
42
+ headers: {
43
+ Authorization: `Bearer ${authToken}`,
44
+ Accept: "application/json",
45
+ },
46
+ });
47
+ return {
48
+ ticketUrl: `${baseUrl}/browse/${issueId}`,
49
+ };
50
+ }
51
+ catch (error) {
52
+ console.error("Error updating Jira ticket:", error);
53
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
54
+ }
55
+ });
56
+ exports.default = updateJiraTicketDetails;
@@ -0,0 +1,3 @@
1
+ import { jiraUpdateJiraTicketStatusFunction } from "../../autogen/types";
2
+ declare const updateJiraTicketStatus: jiraUpdateJiraTicketStatusFunction;
3
+ export default updateJiraTicketStatus;
@@ -0,0 +1,57 @@
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 updateJiraTicketStatus = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
14
+ const { authToken, cloudId, baseUrl } = authParams;
15
+ if (!cloudId || !(params === null || params === void 0 ? void 0 : params.issueId) || !(params === null || params === void 0 ? void 0 : params.status)) {
16
+ throw new Error("Cloud ID, Issue ID, and Status Name are required to update a Jira ticket status");
17
+ }
18
+ const { issueId, status } = params;
19
+ const transitionsUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${issueId}/transitions`;
20
+ try {
21
+ // API takes transition ID, so fetch available transitions the find ID of transition that matches given status name
22
+ const transitionsResponse = yield axiosClient_1.axiosClient.get(transitionsUrl, {
23
+ headers: {
24
+ Authorization: `Bearer ${authToken}`,
25
+ Accept: "application/json",
26
+ },
27
+ });
28
+ const transitions = transitionsResponse.data.transitions;
29
+ if (!transitions || transitions.length === 0) {
30
+ throw new Error("No available transitions found for this issue.");
31
+ }
32
+ const transition = transitions.find((t) => t.name.toLowerCase() === status.trim().toLowerCase());
33
+ if (!transition) {
34
+ throw new Error(`Status '${status}' not found for this issue. Available statuses: ${transitions.map((t) => t.name).join(", ")}`);
35
+ }
36
+ // update status with transition ID
37
+ yield axiosClient_1.axiosClient.post(transitionsUrl, { transition: { id: transition.id } }, {
38
+ headers: {
39
+ Authorization: `Bearer ${authToken}`,
40
+ Accept: "application/json",
41
+ "Content-Type": "application/json",
42
+ },
43
+ });
44
+ return {
45
+ success: true,
46
+ ticketUrl: `${baseUrl}/browse/${issueId}`,
47
+ };
48
+ }
49
+ catch (error) {
50
+ console.error("Error updating Jira ticket status: ", error);
51
+ return {
52
+ success: false,
53
+ error: error instanceof Error ? error.message : "Unknown error",
54
+ };
55
+ }
56
+ });
57
+ exports.default = updateJiraTicketStatus;
@@ -0,0 +1,3 @@
1
+ import { salesforceGetSalesforceRecordsByQueryFunction } from "../../autogen/types";
2
+ declare const getSalesforceRecordByQuery: salesforceGetSalesforceRecordsByQueryFunction;
3
+ export default getSalesforceRecordByQuery;
@@ -0,0 +1,43 @@
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;
@@ -0,0 +1,3 @@
1
+ import { slackListConversationsFunction } from "../../../actions/autogen/types";
2
+ declare const slackListConversations: slackListConversationsFunction;
3
+ export default slackListConversations;
@@ -0,0 +1,60 @@
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 web_api_1 = require("@slack/web-api");
13
+ const slackListConversations = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authParams, }) {
14
+ var _b;
15
+ const client = new web_api_1.WebClient(authParams.authToken);
16
+ const allChannels = [];
17
+ let cursor;
18
+ const limit = 100;
19
+ try {
20
+ do {
21
+ const response = yield client.conversations.list({
22
+ exclude_archived: true,
23
+ limit: limit,
24
+ cursor: cursor,
25
+ });
26
+ if (!response.ok) {
27
+ throw new Error(`Slack API error: ${response.error}`);
28
+ }
29
+ // Add channels from this page to our results
30
+ if (response.channels && Array.isArray(response.channels)) {
31
+ allChannels.push(...response.channels);
32
+ }
33
+ // Get cursor for next page
34
+ cursor = (_b = response.response_metadata) === null || _b === void 0 ? void 0 : _b.next_cursor;
35
+ // If user specified a limit and we've hit it, stop paginating
36
+ if (limit && allChannels.length >= limit) {
37
+ allChannels.splice(limit); // Trim to exact limit
38
+ break;
39
+ }
40
+ } while (cursor && cursor.length > 0);
41
+ return {
42
+ channels: allChannels.map(channel => ({
43
+ id: channel.id,
44
+ name: channel.name,
45
+ topic: channel.topic.value,
46
+ purpose: channel.purpose.value,
47
+ })),
48
+ };
49
+ }
50
+ catch (error) {
51
+ if (error instanceof Error) {
52
+ // Enhance error with more context
53
+ throw new Error(`Failed to list Slack conversations: ${error.message}`);
54
+ }
55
+ else {
56
+ throw error;
57
+ }
58
+ }
59
+ });
60
+ exports.default = slackListConversations;
@@ -0,0 +1,3 @@
1
+ import { slackSummarizeChannelFunction } from "../../autogen/types";
2
+ declare const summarizeChannel: slackSummarizeChannelFunction;
3
+ export default summarizeChannel;
@@ -0,0 +1,51 @@
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 web_api_1 = require("@slack/web-api");
16
+ const helpers_1 = require("./helpers");
17
+ const openai_1 = __importDefault(require("openai"));
18
+ const summarizeChannel = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
19
+ var _b;
20
+ const client = new web_api_1.WebClient(authParams.authToken);
21
+ const { channelName } = params;
22
+ const allChannels = yield (0, helpers_1.getSlackChannels)(client);
23
+ const channel = allChannels.find(channel => channel.name === channelName && channel.is_private === false);
24
+ if (!channel || !channel.id) {
25
+ throw Error(`Channel with name ${channelName} not found`);
26
+ }
27
+ // summarize last 50 messages
28
+ const messages = yield client.conversations.history({
29
+ channel: channel.id,
30
+ limit: 50,
31
+ });
32
+ if (!messages.ok) {
33
+ throw Error(`Failed to fetch messages from channel ${channel.name}`);
34
+ }
35
+ const history = ((_b = messages.messages) === null || _b === void 0 ? void 0 : _b.reverse().map(message => message.user + ":" + message.text).join("\n")) || "";
36
+ const oai = new openai_1.default();
37
+ const completion = yield oai.chat.completions.create({
38
+ model: "gpt-4o-mini",
39
+ messages: [
40
+ {
41
+ role: "user",
42
+ content: "Summarize the following messages in the Slack channel:\n" + history,
43
+ },
44
+ ],
45
+ });
46
+ const summary = completion.choices[0].message.content || "";
47
+ return {
48
+ summary: summary,
49
+ };
50
+ });
51
+ exports.default = summarizeChannel;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createParametersObject = createParametersObject;
4
+ function createParametersObject(parameters) {
5
+ return Object.fromEntries(Object.entries(parameters).map(([key, param]) => [key, param.type]));
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/main.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const list_conversations_1 = __importDefault(require("./actions/providers/slack/list_conversations"));
7
+ const result = (0, list_conversations_1.default)({
8
+ accessToken: "xoxp-4172665288294-8092684180551-8154529379075-89f1f70cc06e5648e8f912ba96f56626"
9
+ }).then((result) => {
10
+ console.log(result);
11
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "AI Actions by Credal AI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -42,6 +42,7 @@
42
42
  "@credal/sdk": "^0.0.21",
43
43
  "@mendable/firecrawl-js": "^1.19.0",
44
44
  "@microsoft/microsoft-graph-client": "^3.0.7",
45
+ "@octokit/rest": "^21.1.1",
45
46
  "@slack/web-api": "^7.8.0",
46
47
  "@types/snowflake-sdk": "^1.6.24",
47
48
  "ajv": "^8.17.1",
@@ -1,23 +0,0 @@
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>;
@@ -1,88 +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
- 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);