@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,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mathAddDefinition = exports.slackSendMessageDefinition = void 0;
4
+ exports.slackSendMessageDefinition = {
5
+ name: "send_message",
6
+ description: "Sends a message to a Slack channel",
7
+ parameters: {
8
+ "channel": {
9
+ "type": "string",
10
+ "description": "The Slack channel to send the message to (e.g., \\#general, \\#alerts)",
11
+ "required": true
12
+ },
13
+ "message": {
14
+ "type": "string",
15
+ "description": "The message content to send to Slack. Can include markdown formatting.",
16
+ "required": true
17
+ }
18
+ }
19
+ };
20
+ exports.mathAddDefinition = {
21
+ name: "add",
22
+ description: "Adds two numbers together",
23
+ parameters: {
24
+ "a": {
25
+ "type": "number",
26
+ "description": "The first number to add",
27
+ "required": true
28
+ },
29
+ "b": {
30
+ "type": "number",
31
+ "description": "The second number to add",
32
+ "required": true
33
+ }
34
+ }
35
+ };
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ACTION_GROUPS = void 0;
4
4
  const templates_1 = require("../actions/autogen/templates");
5
5
  exports.ACTION_GROUPS = {
6
+ ASANA: {
7
+ description: "Actions for interacting with Asana",
8
+ actions: [templates_1.asanaCommentTaskDefinition, templates_1.asanaCreateTaskDefinition, templates_1.asanaUpdateTaskDefinition],
9
+ },
6
10
  SLACK_LIST_CONVERSATIONS: {
7
11
  description: "Actions for interacting with Slack",
8
12
  actions: [templates_1.slackListConversationsDefinition, templates_1.slackSendMessageDefinition],
@@ -21,7 +25,14 @@ exports.ACTION_GROUPS = {
21
25
  },
22
26
  GOOGLE_DRIVE: {
23
27
  description: "Action for interacting with Google Drive",
24
- actions: [templates_1.googleOauthCreateNewGoogleDocDefinition],
28
+ actions: [
29
+ templates_1.googleOauthCreateNewGoogleDocDefinition,
30
+ templates_1.googleOauthUpdateDocDefinition,
31
+ templates_1.googleOauthCreateSpreadsheetDefinition,
32
+ templates_1.googleOauthUpdateSpreadsheetDefinition,
33
+ templates_1.googleOauthCreatePresentationDefinition,
34
+ templates_1.googleOauthUpdatePresentationDefinition,
35
+ ],
25
36
  },
26
37
  GOOGLE_CALENDAR: {
27
38
  description: "Actions for interacting with Google Calendar",
@@ -48,8 +59,16 @@ exports.ACTION_GROUPS = {
48
59
  actions: [templates_1.snowflakeGetRowByFieldValueDefinition, templates_1.snowflakeRunSnowflakeQueryDefinition],
49
60
  },
50
61
  JIRA_ACTIONS: {
51
- description: "Action for interating with Jira tickets",
52
- actions: [templates_1.jiraCreateJiraTicketDefinition, templates_1.jiraAssignJiraTicketDefinition, templates_1.jiraCommentJiraTicketDefinition],
62
+ description: "Action for interacting with Jira tickets",
63
+ actions: [
64
+ templates_1.jiraAssignJiraTicketDefinition,
65
+ templates_1.jiraCreateJiraTicketDefinition,
66
+ templates_1.jiraCommentJiraTicketDefinition,
67
+ templates_1.jiraGetJiraTicketDetailsDefinition,
68
+ templates_1.jiraGetJiraTicketHistoryDefinition,
69
+ templates_1.jiraUpdateJiraTicketDetailsDefinition,
70
+ templates_1.jiraUpdateJiraTicketStatusDefinition,
71
+ ],
53
72
  },
54
73
  OPENSTREETMAP_GET_LATITUDE_LONGITUDE_FROM_LOCATION: {
55
74
  description: "Action for getting the latitude and longitude of a location",
@@ -92,4 +111,8 @@ exports.ACTION_GROUPS = {
92
111
  description: "Actions for interacting with Microsoft 365",
93
112
  actions: [templates_1.microsoftMessageTeamsChatDefinition, templates_1.microsoftMessageTeamsChannelDefinition],
94
113
  },
114
+ GITHUB: {
115
+ description: "Actions for interacting with GitHub",
116
+ actions: [templates_1.githubCreateOrUpdateFileDefinition, templates_1.githubCreateBranchDefinition, templates_1.githubCreatePullRequestDefinition],
117
+ },
95
118
  };
@@ -0,0 +1,9 @@
1
+ import { type ActionFunction } from "./autogen/types";
2
+ import { z } from "zod";
3
+ interface ActionFunctionComponents {
4
+ fn: ActionFunction<any, any, any>;
5
+ paramsSchema: z.ZodSchema;
6
+ outputSchema: z.ZodSchema;
7
+ }
8
+ export declare const FunctionMapper: Record<string, Record<string, ActionFunctionComponents>>;
9
+ export {};
@@ -0,0 +1,33 @@
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
+ exports.FunctionMapper = void 0;
7
+ const add_1 = __importDefault(require("./providers/math/add"));
8
+ const list_conversations_1 = __importDefault(require("./providers/slack/list_conversations"));
9
+ const updatePage_1 = __importDefault(require("./providers/confluence/updatePage"));
10
+ const types_1 = require("./autogen/types");
11
+ exports.FunctionMapper = {
12
+ math: {
13
+ add: {
14
+ fn: add_1.default,
15
+ paramsSchema: types_1.mathAddParamsSchema,
16
+ outputSchema: types_1.mathAddOutputSchema,
17
+ },
18
+ },
19
+ slack: {
20
+ listConversations: {
21
+ fn: list_conversations_1.default,
22
+ paramsSchema: types_1.slackListConversationsParamsSchema,
23
+ outputSchema: types_1.slackListConversationsOutputSchema,
24
+ },
25
+ },
26
+ confluence: {
27
+ updatePage: {
28
+ fn: updatePage_1.default,
29
+ paramsSchema: types_1.confluenceUpdatePageParamsSchema,
30
+ outputSchema: types_1.confluenceUpdatePageOutputSchema,
31
+ },
32
+ },
33
+ };
@@ -0,0 +1,3 @@
1
+ import { asanaCommentTaskFunction } from "../../autogen/types";
2
+ declare const commentAsanaTask: asanaCommentTaskFunction;
3
+ export default commentAsanaTask;
@@ -0,0 +1,44 @@
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 commentAsanaTask = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
14
+ var _b, _c;
15
+ const { authToken } = authParams;
16
+ const { commentText, isPinned, taskId } = params;
17
+ if (!commentText || !authToken) {
18
+ return { success: false, error: "Comment text and valid authToken are required" };
19
+ }
20
+ try {
21
+ const response = yield axiosClient_1.axiosClient.post(`https://app.asana.com/api/1.0/tasks/${taskId}/stories`, {
22
+ data: Object.assign({ text: commentText }, (isPinned !== undefined && { is_pinned: isPinned })),
23
+ }, {
24
+ headers: { Authorization: `Bearer ${authToken}` },
25
+ });
26
+ // Validate response
27
+ const commentGid = (_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.gid;
28
+ if (!commentGid) {
29
+ throw new Error("Failed to create task: No valid comment ID returned from Asana");
30
+ }
31
+ return {
32
+ success: true,
33
+ commentUrl: `https://app.asana.com/0/0/${taskId}/${commentGid}/f`,
34
+ };
35
+ }
36
+ catch (error) {
37
+ console.error("Error creating Asana task:", error);
38
+ return {
39
+ success: false,
40
+ error: error instanceof Error ? error.message : "Unknown error",
41
+ };
42
+ }
43
+ });
44
+ exports.default = commentAsanaTask;
@@ -0,0 +1,3 @@
1
+ import { asanaCreateTaskFunction } from "../../autogen/types";
2
+ declare const createAsanaTask: asanaCreateTaskFunction;
3
+ export default createAsanaTask;
@@ -0,0 +1,93 @@
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 utils_1 = require("./utils");
14
+ const getTaskTemplates = (authToken, projectId) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const url = `https://app.asana.com/api/1.0/task_templates/?project=${projectId}`;
16
+ try {
17
+ const response = yield axiosClient_1.axiosClient.get(url, {
18
+ headers: { Authorization: `Bearer ${authToken}` },
19
+ });
20
+ return response.data.data;
21
+ }
22
+ catch (error) {
23
+ console.error("Error fetching Asana task templates:", error);
24
+ return [];
25
+ }
26
+ });
27
+ const createAsanaTask = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
28
+ var _b, _c;
29
+ const { authToken } = authParams;
30
+ const { name, projectId, description, customFields, taskTemplate, assignee, approvalStatus, dueAt } = params;
31
+ if (!name || !authToken || !projectId) {
32
+ return { success: false, error: "Task name, valid authToken, and projectId are required" };
33
+ }
34
+ const workspaceId = yield (0, utils_1.getWorkspaceIdFromProject)(projectId, authToken);
35
+ if (!workspaceId) {
36
+ return { success: false, error: "Project ID invalid: unable to get workspaceID" };
37
+ }
38
+ let assigneeId;
39
+ if (assignee && assignee.includes("@")) {
40
+ assigneeId = yield (0, utils_1.getUserIdByEmail)(authToken, workspaceId, assignee);
41
+ }
42
+ else {
43
+ assigneeId = assignee;
44
+ }
45
+ let templateId = null;
46
+ try {
47
+ if (taskTemplate) {
48
+ const templates = yield getTaskTemplates(authToken, projectId);
49
+ if (/^\d+$/.test(taskTemplate)) {
50
+ // Numeric: try ID match
51
+ if (templates.some((t) => t.gid === taskTemplate)) {
52
+ templateId = taskTemplate;
53
+ }
54
+ }
55
+ else {
56
+ // Try to find a template by name
57
+ const taskTemplateStr = taskTemplate.trim().toLowerCase();
58
+ const matchedTemplate = templates.find((t) => t.name.toLowerCase() === taskTemplateStr);
59
+ if (matchedTemplate) {
60
+ templateId = matchedTemplate.gid;
61
+ }
62
+ }
63
+ if (!templateId) {
64
+ return {
65
+ success: false,
66
+ error: `Task template '${taskTemplate}' not found. Available templates: ${templates.map((t) => t.name).join(", ")}`,
67
+ };
68
+ }
69
+ }
70
+ const response = yield axiosClient_1.axiosClient.post(`https://app.asana.com/api/1.0/tasks`, {
71
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ name, projects: [projectId] }, (description && { notes: description })), (customFields && { custom_fields: customFields })), (templateId && { task_template: templateId })), (assigneeId && { assignee: assigneeId })), (approvalStatus && { approval_status: approvalStatus })), (dueAt && { due_at: dueAt })),
72
+ }, {
73
+ headers: { Authorization: `Bearer ${authToken}` },
74
+ });
75
+ // Validate response
76
+ const taskGid = (_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.gid;
77
+ if (!taskGid) {
78
+ throw new Error("Failed to create task: No valid task ID returned from Asana");
79
+ }
80
+ return {
81
+ success: true,
82
+ taskUrl: `https://app.asana.com/0/${projectId}/${taskGid}`,
83
+ };
84
+ }
85
+ catch (error) {
86
+ console.error("Error creating Asana task:", error);
87
+ return {
88
+ success: false,
89
+ error: error instanceof Error ? error.message : "Unknown error",
90
+ };
91
+ }
92
+ });
93
+ exports.default = createAsanaTask;
@@ -0,0 +1,3 @@
1
+ import { asanaUpdateTaskFunction } from "../../autogen/types";
2
+ declare const updateAsanaTask: asanaUpdateTaskFunction;
3
+ export default updateAsanaTask;
@@ -0,0 +1,50 @@
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 utils_1 = require("./utils");
14
+ const updateAsanaTask = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
15
+ const { authToken } = authParams;
16
+ const { name, taskId, description, customFields, completed, assignee, approvalStatus, dueAt } = params;
17
+ if (!authToken || !taskId) {
18
+ return { success: false, error: "Valid authToken, and taskId are required" };
19
+ }
20
+ const { workspaceId, permalinkUrl } = yield (0, utils_1.getWorkspaceIdAndPermalinkFromTask)(taskId, authToken);
21
+ if (!workspaceId || !permalinkUrl) {
22
+ return { success: false, error: "Task ID invalid: unable to get workspaceID or permalink" };
23
+ }
24
+ let assigneeId;
25
+ if (assignee && assignee.includes("@")) {
26
+ assigneeId = yield (0, utils_1.getUserIdByEmail)(authToken, workspaceId, assignee);
27
+ }
28
+ else {
29
+ assigneeId = assignee;
30
+ }
31
+ try {
32
+ yield axiosClient_1.axiosClient.put(`https://app.asana.com/api/1.0/tasks/${taskId}`, {
33
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ workspace: workspaceId }, (name && { name })), (approvalStatus && completed === undefined && { approval_status: approvalStatus })), (assigneeId && { assignee: assigneeId })), (completed !== undefined && { completed })), (customFields && { custom_fields: customFields })), (description && { notes: description })), (dueAt && { due_at: dueAt })),
34
+ }, {
35
+ headers: { Authorization: `Bearer ${authToken}` },
36
+ });
37
+ return {
38
+ success: true,
39
+ taskUrl: permalinkUrl,
40
+ };
41
+ }
42
+ catch (error) {
43
+ console.error("Error updating Asana task:", error);
44
+ return {
45
+ success: false,
46
+ error: error instanceof Error ? error.message : "Unknown error",
47
+ };
48
+ }
49
+ });
50
+ exports.default = updateAsanaTask;
@@ -0,0 +1,6 @@
1
+ export declare function getWorkspaceIdFromProject(projectId: string, authToken: string): Promise<string | null>;
2
+ export declare function getWorkspaceIdAndPermalinkFromTask(taskId: string, authToken: string): Promise<{
3
+ workspaceId: string | null;
4
+ permalinkUrl: string | null;
5
+ }>;
6
+ export declare function getUserIdByEmail(authToken: string, workspaceId: string, email: string): Promise<any>;
@@ -0,0 +1,73 @@
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
+ exports.getWorkspaceIdFromProject = getWorkspaceIdFromProject;
13
+ exports.getWorkspaceIdAndPermalinkFromTask = getWorkspaceIdAndPermalinkFromTask;
14
+ exports.getUserIdByEmail = getUserIdByEmail;
15
+ const axiosClient_1 = require("../../util/axiosClient");
16
+ function getWorkspaceIdFromProject(projectId, authToken) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b, _c;
19
+ if (!projectId || !authToken) {
20
+ console.error("Project ID and authToken are required");
21
+ return null;
22
+ }
23
+ try {
24
+ const response = yield axiosClient_1.axiosClient.get(`https://app.asana.com/api/1.0/projects/${projectId}`, {
25
+ headers: { Authorization: `Bearer ${authToken}` },
26
+ });
27
+ return ((_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.workspace) === null || _c === void 0 ? void 0 : _c.gid) || null;
28
+ }
29
+ catch (error) {
30
+ console.error("Error fetching workspace ID from project:", error);
31
+ return null;
32
+ }
33
+ });
34
+ }
35
+ function getWorkspaceIdAndPermalinkFromTask(taskId, authToken) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ var _a, _b, _c, _d, _e;
38
+ if (!taskId || !authToken) {
39
+ console.error("Task ID and authToken are required");
40
+ return { workspaceId: null, permalinkUrl: null };
41
+ }
42
+ try {
43
+ const response = yield axiosClient_1.axiosClient.get(`https://app.asana.com/api/1.0/tasks/${taskId}`, {
44
+ headers: { Authorization: `Bearer ${authToken}` },
45
+ });
46
+ const workspaceId = ((_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.workspace) === null || _c === void 0 ? void 0 : _c.gid) || null;
47
+ const permalinkUrl = ((_e = (_d = response.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.permalink_url) || null; // Gets the task's URL
48
+ return { workspaceId, permalinkUrl };
49
+ }
50
+ catch (error) {
51
+ console.error("Error fetching workspace ID and permalink URL from task:", error);
52
+ return { workspaceId: null, permalinkUrl: null };
53
+ }
54
+ });
55
+ }
56
+ function getUserIdByEmail(authToken, workspaceId, email) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ // Get all users in the workspace
59
+ const url = `https://app.asana.com/api/1.0/workspaces/${workspaceId}/users?opt_fields=email,name,gid`;
60
+ try {
61
+ const response = yield axiosClient_1.axiosClient.get(url, {
62
+ headers: { Authorization: `Bearer ${authToken}` },
63
+ });
64
+ // Filter the users by email on the client side
65
+ const matchingUser = response.data.data.find((user) => user.email && user.email.toLowerCase() === email.toLowerCase());
66
+ return matchingUser ? matchingUser.gid : null;
67
+ }
68
+ catch (error) {
69
+ console.error("Error fetching users:", error);
70
+ return null;
71
+ }
72
+ });
73
+ }
@@ -8,30 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  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({
12
+ const axiosClient_1 = require("../../util/axiosClient");
13
+ function getConfluenceRequestConfig(baseUrl, username, apiToken) {
14
+ return {
18
15
  baseURL: baseUrl,
19
16
  headers: {
20
17
  Accept: "application/json",
21
- // Tokens are associated with a specific user.
22
18
  Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
23
19
  },
24
- });
25
- return api;
20
+ };
26
21
  }
27
22
  const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
28
23
  const { pageId, username, content, title } = params;
29
24
  const { baseUrl, authToken } = authParams;
30
- const api = getConfluenceApi(baseUrl, username, authToken);
25
+ const config = getConfluenceRequestConfig(baseUrl, username, authToken);
31
26
  // Get current version number
32
- const response = yield api.get(`/api/v2/pages/${pageId}`);
27
+ const response = yield axiosClient_1.axiosClient.get(`/api/v2/pages/${pageId}`, config);
33
28
  const currVersion = response.data.version.number;
34
- yield api.put(`/api/v2/pages/${pageId}`, {
29
+ const payload = {
35
30
  id: pageId,
36
31
  status: "current",
37
32
  title,
@@ -42,6 +37,7 @@ const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* (
42
37
  version: {
43
38
  number: currVersion + 1,
44
39
  },
45
- });
40
+ };
41
+ yield axiosClient_1.axiosClient.put(`/api/v2/pages/${pageId}`, payload, config);
46
42
  });
47
43
  exports.default = confluenceUpdatePage;
@@ -0,0 +1,6 @@
1
+ import { githubCreateBranchFunction } from "../../autogen/types";
2
+ /**
3
+ * Creates a new branch in a GitHub repository
4
+ */
5
+ declare const createBranch: githubCreateBranchFunction;
6
+ export default createBranch;
@@ -0,0 +1,68 @@
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 rest_1 = require("@octokit/rest");
13
+ const request_error_1 = require("@octokit/request-error");
14
+ /**
15
+ * Creates a new branch in a GitHub repository
16
+ */
17
+ const createBranch = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
18
+ if (!authParams.authToken) {
19
+ return { success: false, error: "authToken is required for GitHub API" };
20
+ }
21
+ const { repositoryOwner, repositoryName, branchName, baseRefOrHash } = params;
22
+ const octokit = new rest_1.Octokit({ auth: authParams.authToken });
23
+ try {
24
+ // Get the reference or commit SHA for the base branch or tag
25
+ const { data: baseRefData } = yield octokit.git
26
+ .getRef({
27
+ owner: repositoryOwner,
28
+ repo: repositoryName,
29
+ ref: baseRefOrHash,
30
+ })
31
+ .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
32
+ if (error.status === 404 && /^[a-f0-9]{40}$/i.test(baseRefOrHash)) {
33
+ // If baseRef is a full commit SHA and not a ref, use it directly
34
+ return { data: { object: { sha: baseRefOrHash } } };
35
+ }
36
+ else if (error.status === 404 && /^[a-f0-9]{7,39}$/i.test(baseRefOrHash)) {
37
+ // If baseRef is a short commit SHA, try to resolve it to a full SHA
38
+ const { data: commits } = yield octokit.repos.listCommits({
39
+ owner: repositoryOwner,
40
+ repo: repositoryName,
41
+ sha: baseRefOrHash,
42
+ per_page: 1,
43
+ });
44
+ if (commits.length > 0) {
45
+ return { data: { object: { sha: commits[0].sha } } };
46
+ }
47
+ }
48
+ throw error;
49
+ }));
50
+ // Create a new branch from the base reference
51
+ yield octokit.git.createRef({
52
+ owner: repositoryOwner,
53
+ repo: repositoryName,
54
+ ref: `refs/heads/${branchName}`,
55
+ sha: baseRefData.object.sha,
56
+ });
57
+ return { success: true };
58
+ }
59
+ catch (error) {
60
+ if (error instanceof request_error_1.RequestError) {
61
+ console.error("GitHub API error:", error.message);
62
+ return { success: false, error: error.message };
63
+ }
64
+ console.error("Unexpected error:", error);
65
+ return { success: false, error: error instanceof Error ? error.message : "An unexpected error occurred" };
66
+ }
67
+ });
68
+ exports.default = createBranch;
@@ -0,0 +1,6 @@
1
+ import { githubCreateOrUpdateFileFunction } from "../../autogen/types";
2
+ /**
3
+ * Creates or updates a file in a GitHub repository
4
+ */
5
+ declare const createOrUpdateFile: githubCreateOrUpdateFileFunction;
6
+ export default createOrUpdateFile;
@@ -0,0 +1,75 @@
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 rest_1 = require("@octokit/rest");
13
+ const request_error_1 = require("@octokit/request-error");
14
+ const zod_1 = require("zod");
15
+ /**
16
+ * Creates or updates a file in a GitHub repository
17
+ */
18
+ const createOrUpdateFile = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
19
+ if (!authParams.authToken) {
20
+ return { success: false, error: "authToken is required for GitHub API" };
21
+ }
22
+ const { repositoryOwner, repositoryName, filePath, branch, fileContent, commitMessage } = params;
23
+ const octokit = new rest_1.Octokit({ auth: authParams.authToken });
24
+ let fileSha = undefined;
25
+ let operationPreformed = undefined;
26
+ try {
27
+ const { data: fileData } = yield octokit.repos.getContent({
28
+ owner: repositoryOwner,
29
+ repo: repositoryName,
30
+ path: filePath,
31
+ ref: branch,
32
+ });
33
+ if (params.noOverwrite) {
34
+ return { success: false, error: "Path already exists and noOverwrite is set to true." };
35
+ }
36
+ if (Array.isArray(fileData)) {
37
+ console.error(`Error: Path is a directory, not a file. Path: ${filePath}`);
38
+ return { success: false, error: `Path is a directory, not a file. Path: ${filePath}` };
39
+ }
40
+ fileSha = fileData.sha;
41
+ operationPreformed = "updated";
42
+ }
43
+ catch (error) {
44
+ if (error instanceof request_error_1.RequestError && error.status === 404) {
45
+ console.log(`File not found, creating new file.`);
46
+ operationPreformed = "created";
47
+ }
48
+ else {
49
+ return { success: false, error: error instanceof Error ? error.message : "An unknown error occurred" };
50
+ }
51
+ }
52
+ try {
53
+ const { data: commitData } = yield octokit.repos.createOrUpdateFileContents({
54
+ owner: repositoryOwner,
55
+ repo: repositoryName,
56
+ path: filePath,
57
+ message: commitMessage,
58
+ content: Buffer.from(fileContent).toString("base64"),
59
+ branch,
60
+ sha: fileSha,
61
+ });
62
+ const OperationEnum = zod_1.z.enum(["created", "updated"]);
63
+ return {
64
+ success: true,
65
+ newCommitSha: commitData.commit.sha,
66
+ operation: OperationEnum.parse(operationPreformed),
67
+ };
68
+ }
69
+ catch (error) {
70
+ console.error("Error creating or updating file:", error);
71
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
72
+ return { success: false, error: errorMessage };
73
+ }
74
+ });
75
+ exports.default = createOrUpdateFile;
@@ -0,0 +1,6 @@
1
+ import { githubCreatePullRequestFunction } from "../../autogen/types";
2
+ /**
3
+ * Creates a pull request in a GitHub repository
4
+ */
5
+ declare const createPullRequest: githubCreatePullRequestFunction;
6
+ export default createPullRequest;