@credal/actions 0.1.56 → 0.1.57

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.
@@ -1462,6 +1462,10 @@ exports.snowflakeRunSnowflakeQueryDefinition = {
1462
1462
  description: "The format of the output",
1463
1463
  enum: ["json", "csv"],
1464
1464
  },
1465
+ limit: {
1466
+ type: "number",
1467
+ description: "A limit on the number of rows to return",
1468
+ },
1465
1469
  },
1466
1470
  },
1467
1471
  output: {
@@ -1263,17 +1263,20 @@ export declare const snowflakeRunSnowflakeQueryParamsSchema: z.ZodObject<{
1263
1263
  query: z.ZodString;
1264
1264
  accountName: z.ZodString;
1265
1265
  outputFormat: z.ZodOptional<z.ZodEnum<["json", "csv"]>>;
1266
+ limit: z.ZodOptional<z.ZodNumber>;
1266
1267
  }, "strip", z.ZodTypeAny, {
1267
1268
  query: string;
1268
1269
  databaseName: string;
1269
1270
  accountName: string;
1270
1271
  warehouse: string;
1272
+ limit?: number | undefined;
1271
1273
  outputFormat?: "json" | "csv" | undefined;
1272
1274
  }, {
1273
1275
  query: string;
1274
1276
  databaseName: string;
1275
1277
  accountName: string;
1276
1278
  warehouse: string;
1279
+ limit?: number | undefined;
1277
1280
  outputFormat?: "json" | "csv" | undefined;
1278
1281
  }>;
1279
1282
  export type snowflakeRunSnowflakeQueryParamsType = z.infer<typeof snowflakeRunSnowflakeQueryParamsSchema>;
@@ -438,6 +438,7 @@ exports.snowflakeRunSnowflakeQueryParamsSchema = zod_1.z.object({
438
438
  query: zod_1.z.string().describe("The SQL query to execute"),
439
439
  accountName: zod_1.z.string().describe("The name of the Snowflake account"),
440
440
  outputFormat: zod_1.z.enum(["json", "csv"]).describe("The format of the output").optional(),
441
+ limit: zod_1.z.number().describe("A limit on the number of rows to return").optional(),
441
442
  });
442
443
  exports.snowflakeRunSnowflakeQueryOutputSchema = zod_1.z.object({
443
444
  format: zod_1.z.enum(["json", "csv"]).describe("The format of the output"),
@@ -36,7 +36,11 @@ const createRecord = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params
36
36
  console.error("Error creating Salesforce object:", error);
37
37
  return {
38
38
  success: false,
39
- error: error instanceof Error ? error.message : "An unknown error occurred",
39
+ error: error instanceof axiosClient_1.ApiError
40
+ ? error.data.length > 0
41
+ ? error.data[0].message
42
+ : error.message
43
+ : "An unknown error occurred",
40
44
  };
41
45
  }
42
46
  });
@@ -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;
@@ -17,7 +17,7 @@ const getSnowflakeConnection_1 = require("./auth/getSnowflakeConnection");
17
17
  const formatDataForCodeInterpreter_1 = require("../../util/formatDataForCodeInterpreter");
18
18
  snowflake_sdk_1.default.configure({ logLevel: "ERROR" });
19
19
  const runSnowflakeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
20
- const { databaseName, warehouse, query, accountName, outputFormat = "json" } = params;
20
+ const { databaseName, warehouse, query, accountName, outputFormat = "json", limit } = params;
21
21
  if (!accountName || !databaseName || !warehouse || !query) {
22
22
  throw new Error("Missing required parameters for Snowflake query");
23
23
  }
@@ -36,6 +36,9 @@ const runSnowflakeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ p
36
36
  });
37
37
  });
38
38
  // Format the results based on the output format
39
+ if (limit && queryResults.length - 1 > limit) {
40
+ queryResults.splice(limit + 1); // Include header
41
+ }
39
42
  const { formattedData, resultsLength } = (0, formatDataForCodeInterpreter_1.formatDataForCodeInterpreter)(queryResults, outputFormat);
40
43
  return { formattedData, resultsLength };
41
44
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "description": "AI Actions by Credal AI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,3 +0,0 @@
1
- import { confluenceUpdatePageFunction } from "../../../actions/autogen/types";
2
- declare const confluenceUpdatePage: confluenceUpdatePageFunction;
3
- export default confluenceUpdatePage;
@@ -1,47 +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
- 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;
@@ -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);