@credal/actions 0.2.107 → 0.2.109

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 (58) hide show
  1. package/dist/actions/actionMapper.js +7 -1
  2. package/dist/actions/autogen/templates.d.ts +1 -0
  3. package/dist/actions/autogen/templates.js +315 -1
  4. package/dist/actions/autogen/types.d.ts +612 -0
  5. package/dist/actions/autogen/types.js +133 -0
  6. package/dist/actions/groups.js +11 -1
  7. package/dist/actions/providers/confluence/updatePage.d.ts +3 -0
  8. package/dist/actions/providers/confluence/updatePage.js +46 -0
  9. package/dist/actions/providers/credal/callCopilot.d.ts +3 -0
  10. package/dist/actions/providers/credal/callCopilot.js +36 -0
  11. package/dist/actions/providers/generic/fillTemplateAction.d.ts +7 -0
  12. package/dist/actions/providers/generic/fillTemplateAction.js +18 -0
  13. package/dist/actions/providers/generic/genericApiCall.d.ts +3 -0
  14. package/dist/actions/providers/generic/genericApiCall.js +38 -0
  15. package/dist/actions/providers/github/getBranch.d.ts +7 -0
  16. package/dist/actions/providers/github/getBranch.js +67 -0
  17. package/dist/actions/providers/google-oauth/editAGoogleCalendarEvent.js +9 -1
  18. package/dist/actions/providers/google-oauth/getDriveContentById.d.ts +3 -0
  19. package/dist/actions/providers/google-oauth/getDriveContentById.js +161 -0
  20. package/dist/actions/providers/google-oauth/listCalendarEvents.js +3 -0
  21. package/dist/actions/providers/google-oauth/scheduleCalendarMeeting.d.ts +1 -0
  22. package/dist/actions/providers/google-oauth/scheduleCalendarMeeting.js +50 -4
  23. package/dist/actions/providers/google-oauth/searchAndGetDriveContentByKeywords.d.ts +3 -0
  24. package/dist/actions/providers/google-oauth/searchAndGetDriveContentByKeywords.js +47 -0
  25. package/dist/actions/providers/google-oauth/searchDriveAndGetContentByKeywords.d.ts +3 -0
  26. package/dist/actions/providers/google-oauth/searchDriveAndGetContentByKeywords.js +110 -0
  27. package/dist/actions/providers/google-oauth/searchDriveAndGetContentByQuery.d.ts +3 -0
  28. package/dist/actions/providers/google-oauth/searchDriveAndGetContentByQuery.js +78 -0
  29. package/dist/actions/providers/google-oauth/utils/extractContentFromDriveFileId.d.ts +15 -0
  30. package/dist/actions/providers/google-oauth/utils/extractContentFromDriveFileId.js +129 -0
  31. package/dist/actions/providers/googlemaps/nearbysearch.d.ts +3 -0
  32. package/dist/actions/providers/googlemaps/nearbysearch.js +96 -0
  33. package/dist/actions/providers/math/index.d.ts +1 -0
  34. package/dist/actions/providers/math/index.js +37 -0
  35. package/dist/actions/providers/slack/index.d.ts +1 -0
  36. package/dist/actions/providers/slack/index.js +37 -0
  37. package/dist/actions/providers/slack/listConversations.d.ts +3 -0
  38. package/dist/actions/providers/slack/listConversations.js +41 -0
  39. package/dist/actions/providers/snowflake/runSnowflakeQueryWriteResultsToS3.d.ts +3 -0
  40. package/dist/actions/providers/snowflake/runSnowflakeQueryWriteResultsToS3.js +154 -0
  41. package/dist/actions/providers/x/scrapeTweetDataWithNitter.d.ts +3 -0
  42. package/dist/actions/providers/x/scrapeTweetDataWithNitter.js +45 -0
  43. package/dist/actions/providers/zendesk/addCommentToTicket.js +2 -1
  44. package/dist/actions/providers/zendesk/assignTicket.js +2 -1
  45. package/dist/actions/providers/zendesk/createZendeskTicket.js +2 -1
  46. package/dist/actions/providers/zendesk/getTicketDetails.js +3 -2
  47. package/dist/actions/providers/zendesk/listTickets.js +2 -1
  48. package/dist/actions/providers/zendesk/searchZendeskByQuery.js +2 -1
  49. package/dist/actions/providers/zendesk/updateTicketStatus.js +2 -1
  50. package/dist/actions/util/axiosClient.d.ts +4 -1
  51. package/dist/actions/util/axiosClient.js +7 -3
  52. package/dist/utils/datetime.d.ts +1 -0
  53. package/dist/utils/datetime.js +7 -0
  54. package/package.json +1 -1
  55. package/dist/actions/providers/github/fetchFile.d.ts +0 -3
  56. package/dist/actions/providers/github/fetchFile.js +0 -131
  57. package/dist/actions/providers/github/getContents.d.ts +0 -3
  58. package/dist/actions/providers/github/getContents.js +0 -41
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.listConversations = void 0;
37
+ exports.listConversations = __importStar(require("./listConversations"));
@@ -0,0 +1,3 @@
1
+ import type { slackListConversationsFunction } from "../../autogen/types";
2
+ declare const slackListConversations: slackListConversationsFunction;
3
+ export default slackListConversations;
@@ -0,0 +1,41 @@
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 helpers_1 = require("./helpers");
14
+ const slackListConversations = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authParams, }) {
15
+ const client = new web_api_1.WebClient(authParams.authToken);
16
+ try {
17
+ const allChannels = yield (0, helpers_1.getSlackChannels)(client);
18
+ const filteredChannels = [];
19
+ for (const channel of allChannels) {
20
+ if (channel.name && channel.topic && channel.topic.value && channel.purpose && channel.purpose.value) {
21
+ const purpose = channel.purpose.value;
22
+ const topic = channel.topic.value;
23
+ const name = channel.name;
24
+ filteredChannels.push(Object.assign(Object.assign({}, channel), { purpose, topic, name }));
25
+ }
26
+ }
27
+ return {
28
+ channels: filteredChannels,
29
+ };
30
+ }
31
+ catch (error) {
32
+ if (error instanceof Error) {
33
+ // Enhance error with more context
34
+ throw new Error(`Failed to list Slack conversations: ${error.message}`);
35
+ }
36
+ else {
37
+ throw error;
38
+ }
39
+ }
40
+ });
41
+ exports.default = slackListConversations;
@@ -0,0 +1,3 @@
1
+ import { snowflakeRunSnowflakeQueryWriteResultsToS3Function } from "../../autogen/types";
2
+ declare const runSnowflakeQueryWriteResultsToS3: snowflakeRunSnowflakeQueryWriteResultsToS3Function;
3
+ export default runSnowflakeQueryWriteResultsToS3;
@@ -0,0 +1,154 @@
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 snowflake_sdk_1 = __importDefault(require("snowflake-sdk"));
16
+ const crypto_1 = __importDefault(require("crypto"));
17
+ const client_s3_1 = require("@aws-sdk/client-s3");
18
+ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
19
+ const uuid_1 = require("uuid");
20
+ // Only log errors.
21
+ snowflake_sdk_1.default.configure({ logLevel: "ERROR" });
22
+ const runSnowflakeQueryWriteResultsToS3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
23
+ const { databaseName, warehouse, query, user, accountName, s3BucketName, s3Region, outputFormat = "json" } = params;
24
+ const { apiKey: privateKey, awsAccessKeyId, awsSecretAccessKey } = authParams;
25
+ if (!privateKey) {
26
+ throw new Error("Snowflake private key is required");
27
+ }
28
+ if (!awsAccessKeyId || !awsSecretAccessKey) {
29
+ throw new Error("AWS credentials are required");
30
+ }
31
+ if (!accountName || !user || !databaseName || !warehouse || !query || !s3BucketName) {
32
+ throw new Error("Missing required parameters for Snowflake query or S3 destination");
33
+ }
34
+ const getPrivateKeyCorrectFormat = (privateKey) => {
35
+ const buffer = Buffer.from(privateKey);
36
+ const privateKeyObject = crypto_1.default.createPrivateKey({
37
+ key: buffer,
38
+ format: "pem",
39
+ passphrase: "password",
40
+ });
41
+ const privateKeyCorrectFormat = privateKeyObject.export({
42
+ format: "pem",
43
+ type: "pkcs8",
44
+ });
45
+ return privateKeyCorrectFormat.toString();
46
+ };
47
+ const executeQueryAndFormatData = () => __awaiter(void 0, void 0, void 0, function* () {
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ const queryResults = yield new Promise((resolve, reject) => {
50
+ connection.execute({
51
+ sqlText: query,
52
+ complete: (err, stmt, rows) => {
53
+ if (err) {
54
+ return reject(err);
55
+ }
56
+ return resolve(rows || []);
57
+ },
58
+ });
59
+ });
60
+ // Format the results based on the output format
61
+ let formattedData;
62
+ if (outputFormat.toLowerCase() === "csv") {
63
+ if (queryResults.length === 0) {
64
+ formattedData = "";
65
+ }
66
+ else {
67
+ const headers = Object.keys(queryResults[0]).join(",");
68
+ const rows = queryResults.map(row => Object.values(row)
69
+ .map(value => (typeof value === "object" && value !== null ? JSON.stringify(value) : value))
70
+ .join(","));
71
+ formattedData = [headers, ...rows].join("\n");
72
+ }
73
+ }
74
+ else {
75
+ // Default to JSON
76
+ formattedData = JSON.stringify(queryResults, null, 2);
77
+ }
78
+ return { formattedData, resultsLength: queryResults.length };
79
+ });
80
+ const uploadToS3AndGetURL = (formattedData) => __awaiter(void 0, void 0, void 0, function* () {
81
+ // Create S3 client
82
+ const s3Client = new client_s3_1.S3Client({
83
+ region: s3Region,
84
+ credentials: {
85
+ accessKeyId: awsAccessKeyId,
86
+ secretAccessKey: awsSecretAccessKey,
87
+ },
88
+ });
89
+ const contentType = outputFormat.toLowerCase() === "csv" ? "text/csv" : "application/json";
90
+ const fileExtension = outputFormat.toLowerCase() === "csv" ? "csv" : "json";
91
+ const finalKey = `${databaseName}/${(0, uuid_1.v4)()}.${fileExtension}`;
92
+ // Upload to S3 without ACL
93
+ const uploadCommand = new client_s3_1.PutObjectCommand({
94
+ Bucket: s3BucketName,
95
+ Key: finalKey,
96
+ Body: formattedData,
97
+ ContentType: contentType,
98
+ });
99
+ yield s3Client.send(uploadCommand);
100
+ // Generate a presigned URL (valid for an hour)
101
+ const getObjectCommand = new client_s3_1.GetObjectCommand({
102
+ Bucket: s3BucketName,
103
+ Key: finalKey,
104
+ });
105
+ const presignedUrl = yield (0, s3_request_presigner_1.getSignedUrl)(s3Client, getObjectCommand, { expiresIn: 3600 });
106
+ return presignedUrl;
107
+ });
108
+ // Process the private key
109
+ const privateKeyCorrectFormatString = getPrivateKeyCorrectFormat(privateKey);
110
+ // Set up a connection using snowflake-sdk
111
+ const connection = snowflake_sdk_1.default.createConnection({
112
+ account: accountName,
113
+ username: user,
114
+ privateKey: privateKeyCorrectFormatString,
115
+ authenticator: "SNOWFLAKE_JWT",
116
+ role: "ACCOUNTADMIN",
117
+ warehouse: warehouse,
118
+ database: databaseName,
119
+ });
120
+ try {
121
+ // Connect to Snowflake
122
+ yield new Promise((resolve, reject) => {
123
+ connection.connect((err, conn) => {
124
+ if (err) {
125
+ console.error("Unable to connect to Snowflake:", err.message);
126
+ return reject(err);
127
+ }
128
+ resolve(conn);
129
+ });
130
+ });
131
+ const { formattedData, resultsLength } = yield executeQueryAndFormatData();
132
+ const presignedUrl = yield uploadToS3AndGetURL(formattedData);
133
+ // Return fields to match schema definition
134
+ connection.destroy(err => {
135
+ if (err) {
136
+ console.log("Failed to disconnect from Snowflake:", err);
137
+ }
138
+ });
139
+ return {
140
+ bucketUrl: presignedUrl,
141
+ message: `Query results successfully written to S3. URL valid for 1 hour.`,
142
+ rowCount: resultsLength,
143
+ };
144
+ }
145
+ catch (error) {
146
+ connection.destroy(err => {
147
+ if (err) {
148
+ console.log("Failed to disconnect from Snowflake:", err);
149
+ }
150
+ });
151
+ throw Error(`An error occurred: ${error}`);
152
+ }
153
+ });
154
+ exports.default = runSnowflakeQueryWriteResultsToS3;
@@ -0,0 +1,3 @@
1
+ import { xScrapePostDataWithNitterFunction } from "../../autogen/types";
2
+ declare const scrapeTweetDataWithNitter: xScrapePostDataWithNitterFunction;
3
+ export default scrapeTweetDataWithNitter;
@@ -0,0 +1,45 @@
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 firecrawl_js_1 = __importDefault(require("@mendable/firecrawl-js"));
16
+ const scrapeTweetDataWithNitter = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
17
+ const tweetUrlRegex = /^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)\/([a-zA-Z0-9_]+)\/status\/(\d+)(?:\?.*)?$/;
18
+ if (!tweetUrlRegex.test(params.tweetUrl)) {
19
+ throw new Error("Invalid tweet URL. Expected format: https://twitter.com/username/status/id or https://x.com/username/status/id");
20
+ }
21
+ const nitterUrl = params.tweetUrl.replace(/^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)/i, "https://nitter.net");
22
+ // Initialize Firecrawl
23
+ if (!authParams.apiKey) {
24
+ throw new Error("API key is required for X+Nitter+Firecrawl");
25
+ }
26
+ const firecrawl = new firecrawl_js_1.default({
27
+ apiKey: authParams.apiKey,
28
+ });
29
+ try {
30
+ // Scrape the Nitter URL
31
+ const result = yield firecrawl.scrapeUrl(nitterUrl);
32
+ if (!result.success) {
33
+ throw new Error(`Failed to scrape tweet: ${result.error || "Unknown error"}`);
34
+ }
35
+ // Extract the tweet text from the scraped content - simple approach - in practice, you might need more robust parsing based on nitter html structure
36
+ const tweetContent = result.markdown;
37
+ return {
38
+ text: tweetContent || "Error scraping with firecrawl",
39
+ };
40
+ }
41
+ catch (error) {
42
+ throw new Error(`Error scraping tweet: ${error instanceof Error ? error.message : error}`);
43
+ }
44
+ });
45
+ exports.default = scrapeTweetDataWithNitter;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const addCommentToTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -16,6 +16,7 @@ const addCommentToTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({
16
16
  if (!authToken) {
17
17
  throw new Error(MISSING_AUTH_TOKEN);
18
18
  }
19
+ const axiosClient = createAxiosClientWithRetries({ timeout: 20000, retryCount: 5 });
19
20
  try {
20
21
  const response = yield axiosClient.request({
21
22
  url: url,
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const updateTicketStatus = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -16,6 +16,7 @@ const updateTicketStatus = (_a) => __awaiter(void 0, [_a], void 0, function* ({
16
16
  if (!authToken) {
17
17
  throw new Error(MISSING_AUTH_TOKEN);
18
18
  }
19
+ const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
19
20
  yield axiosClient.request({
20
21
  url: url,
21
22
  method: "PUT",
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const createZendeskTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -24,6 +24,7 @@ const createZendeskTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({
24
24
  if (!authToken) {
25
25
  throw new Error(MISSING_AUTH_TOKEN);
26
26
  }
27
+ const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
27
28
  const response = yield axiosClient.post(url, payload, {
28
29
  headers: {
29
30
  "Content-Type": "application/json",
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClientWithRetries } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const getZendeskTicketDetails = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -16,7 +16,8 @@ const getZendeskTicketDetails = (_a) => __awaiter(void 0, [_a], void 0, function
16
16
  if (!authToken) {
17
17
  throw new Error(MISSING_AUTH_TOKEN);
18
18
  }
19
- const response = yield axiosClientWithRetries.request({
19
+ const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
20
+ const response = yield axiosClient.request({
20
21
  url: url,
21
22
  method: "GET",
22
23
  headers: {
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const listZendeskTickets = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -21,6 +21,7 @@ const listZendeskTickets = (_a) => __awaiter(void 0, [_a], void 0, function* ({
21
21
  if (!authToken) {
22
22
  throw new Error(MISSING_AUTH_TOKEN);
23
23
  }
24
+ const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
24
25
  // Add query parameters for filtering
25
26
  const queryParams = new URLSearchParams();
26
27
  queryParams.append("created_after", formattedDate);
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const searchZendeskByQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -17,6 +17,7 @@ const searchZendeskByQuery = (_a) => __awaiter(void 0, [_a], void 0, function* (
17
17
  if (!authToken) {
18
18
  throw new Error(MISSING_AUTH_TOKEN);
19
19
  }
20
+ const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
20
21
  // Build search query parameters
21
22
  const queryParams = new URLSearchParams();
22
23
  queryParams.append("query", `type:${objectType} ${query}`);
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const updateTicketStatus = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
13
  const { authToken } = authParams;
@@ -16,6 +16,7 @@ const updateTicketStatus = (_a) => __awaiter(void 0, [_a], void 0, function* ({
16
16
  if (!authToken) {
17
17
  throw new Error(MISSING_AUTH_TOKEN);
18
18
  }
19
+ const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
19
20
  yield axiosClient.request({
20
21
  url: url,
21
22
  method: "PUT",
@@ -7,4 +7,7 @@ export declare class ApiError extends Error {
7
7
  export declare function isAxiosTimeoutError(error: unknown): boolean;
8
8
  export declare const axiosClient: AxiosInstance;
9
9
  export declare function createAxiosClientWithTimeout(timeout: number): AxiosInstance;
10
- export declare const axiosClientWithRetries: AxiosInstance;
10
+ export declare function createAxiosClientWithRetries(args: {
11
+ timeout: number;
12
+ retryCount: number;
13
+ }): AxiosInstance;
@@ -45,10 +45,11 @@ export const axiosClient = createAxiosClient();
45
45
  export function createAxiosClientWithTimeout(timeout) {
46
46
  return createAxiosClient(timeout);
47
47
  }
48
- function createAxiosClientWithRetries(timeout) {
48
+ export function createAxiosClientWithRetries(args) {
49
+ const { timeout, retryCount } = args;
49
50
  const instance = createAxiosClient(timeout);
50
51
  axiosRetry(instance, {
51
- retries: 3,
52
+ retries: retryCount,
52
53
  retryDelay: axiosRetry.exponentialDelay,
53
54
  retryCondition: error => {
54
55
  if (axiosRetry.isNetworkError(error) || !error.response)
@@ -56,7 +57,10 @@ function createAxiosClientWithRetries(timeout) {
56
57
  const status = error.response.status;
57
58
  return status === 408 || status === 429 || status >= 500;
58
59
  },
60
+ onRetry: (retryCount, error) => {
61
+ var _a, _b;
62
+ console.log(`Retry ${retryCount}: ${((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) || "Network Error"} - ${(_b = error.config) === null || _b === void 0 ? void 0 : _b.url}`);
63
+ },
59
64
  });
60
65
  return instance;
61
66
  }
62
- export const axiosClientWithRetries = createAxiosClientWithRetries();
@@ -1,2 +1,3 @@
1
1
  export declare function isBetweenDatetime(isoDatetime: string, isoStart: string, isoEnd: string): boolean;
2
2
  export declare function isValidIsoDatestring(isoDatetime: string): boolean;
3
+ export declare const getDayOfWeek: (dateString: string) => string;
@@ -8,3 +8,10 @@ export function isBetweenDatetime(isoDatetime, isoStart, isoEnd) {
8
8
  export function isValidIsoDatestring(isoDatetime) {
9
9
  return isValid(parseISO(isoDatetime));
10
10
  }
11
+ export const getDayOfWeek = (dateString) => {
12
+ if (!dateString)
13
+ return "";
14
+ const date = new Date(dateString);
15
+ const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
16
+ return days[date.getDay()];
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.107",
3
+ "version": "0.2.109",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -1,3 +0,0 @@
1
- import type { githubSearchRepositoryFunction } from "../../autogen/types.js";
2
- declare const searchRepository: githubSearchRepositoryFunction;
3
- export default searchRepository;
@@ -1,131 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
11
- // Limits on the number of results to return
12
- const MAX_CODE_RESULTS = 15;
13
- const MAX_COMMITS = 10;
14
- const MAX_FILES_PER_COMMIT = 5;
15
- const MAX_ISSUES_OR_PRS = 10;
16
- const MAX_FILES_PER_PR = 5;
17
- const MAX_PATCH_LINES = 20;
18
- const MAX_FRAGMENT_LINES = 20;
19
- const searchRepository = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
20
- const { Octokit } = yield import("octokit");
21
- if (!authParams.authToken) {
22
- throw new Error(MISSING_AUTH_TOKEN);
23
- }
24
- const octokit = new Octokit({ auth: authParams.authToken });
25
- const { organization, repository, query } = params;
26
- // Search CODE with text match metadata
27
- const codeResultsResponse = yield octokit.rest.search.code({
28
- q: `${query} in:file,path repo:${organization}/${repository}`,
29
- text_match: true,
30
- headers: {
31
- accept: "application/vnd.github.v3.text-match+json",
32
- },
33
- });
34
- const codeResults = codeResultsResponse.data.items.slice(0, MAX_CODE_RESULTS).map(item => ({
35
- name: item.name,
36
- path: item.path,
37
- sha: item.sha,
38
- url: item.url,
39
- repository: {
40
- full_name: item.repository.full_name,
41
- html_url: item.repository.html_url,
42
- },
43
- score: item.score,
44
- textMatches: item.text_matches
45
- ? item.text_matches.map(match => {
46
- var _a, _b, _c, _d;
47
- return ({
48
- object_url: (_a = match.object_url) !== null && _a !== void 0 ? _a : undefined,
49
- object_type: (_b = match.object_type) !== null && _b !== void 0 ? _b : undefined,
50
- fragment: (_c = match.fragment) === null || _c === void 0 ? void 0 : _c.split("\n").slice(0, MAX_FRAGMENT_LINES).join("\n"),
51
- matches: (_d = match.matches) !== null && _d !== void 0 ? _d : [],
52
- });
53
- })
54
- : [],
55
- }));
56
- // Search COMMITS
57
- const commitResults = yield octokit.rest.search.commits({
58
- q: `${query} repo:${organization}/${repository}`,
59
- headers: {
60
- accept: "application/vnd.github.cloak-preview+json",
61
- },
62
- });
63
- const commitSHAs = commitResults.data.items.slice(0, MAX_COMMITS).map(item => item.sha);
64
- const commitDetails = yield Promise.all(commitSHAs.map(sha => octokit.rest.repos.getCommit({ owner: organization, repo: repository, ref: sha })));
65
- const enrichedCommits = commitResults.data.items.slice(0, MAX_COMMITS).map(item => {
66
- var _a, _b;
67
- const full = commitDetails.find(c => c.data.sha === item.sha);
68
- return {
69
- sha: item.sha,
70
- url: item.url,
71
- commit: {
72
- message: item.commit.message,
73
- author: item.commit.author,
74
- },
75
- score: item.score,
76
- author: (_a = item.author) !== null && _a !== void 0 ? _a : undefined,
77
- files: ((_b = full === null || full === void 0 ? void 0 : full.data.files) === null || _b === void 0 ? void 0 : _b.slice(0, MAX_FILES_PER_COMMIT).map(f => {
78
- var _a;
79
- return ({
80
- filename: f.filename,
81
- status: f.status,
82
- patch: (_a = f.patch) === null || _a === void 0 ? void 0 : _a.split("\n").slice(0, MAX_PATCH_LINES).join("\n"),
83
- });
84
- })) || [],
85
- };
86
- });
87
- // Search ISSUES & PRs
88
- const issueResults = yield octokit.rest.search.issuesAndPullRequests({
89
- q: `${query} repo:${organization}/${repository}`,
90
- });
91
- const prItems = issueResults.data.items.filter(item => item.pull_request).slice(0, MAX_ISSUES_OR_PRS);
92
- const prNumbers = prItems.map(item => item.number);
93
- const prFiles = yield Promise.all(prNumbers.map(number => octokit.rest.pulls.listFiles({ owner: organization, repo: repository, pull_number: number })));
94
- const issuesAndPRs = issueResults.data.items
95
- .slice(0, MAX_ISSUES_OR_PRS)
96
- .map(item => {
97
- var _a, _b, _c, _d;
98
- const isPR = !!item.pull_request;
99
- const prIndex = prNumbers.indexOf(item.number);
100
- const files = isPR && prIndex !== -1
101
- ? prFiles[prIndex].data.slice(0, MAX_FILES_PER_PR).map(f => {
102
- var _a;
103
- return ({
104
- filename: f.filename,
105
- status: f.status,
106
- patch: (_a = f.patch) === null || _a === void 0 ? void 0 : _a.split("\n").slice(0, MAX_PATCH_LINES).join("\n"),
107
- });
108
- })
109
- : undefined;
110
- return {
111
- number: item.number,
112
- title: item.title,
113
- html_url: item.html_url,
114
- state: item.state,
115
- isPullRequest: isPR,
116
- body: item.body,
117
- user: {
118
- email: (_b = (_a = item.user) === null || _a === void 0 ? void 0 : _a.email) !== null && _b !== void 0 ? _b : undefined,
119
- name: (_d = (_c = item.user) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : undefined,
120
- },
121
- score: item.score,
122
- files,
123
- };
124
- });
125
- return {
126
- code: codeResults,
127
- commits: enrichedCommits,
128
- issuesAndPullRequests: issuesAndPRs,
129
- };
130
- });
131
- export default searchRepository;
@@ -1,3 +0,0 @@
1
- import type { githubSearchRepositoryFunction } from "../../autogen/types.js";
2
- declare const searchRepository: githubSearchRepositoryFunction;
3
- export default searchRepository;