@credal/actions 0.1.97 → 0.1.99

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 (37) hide show
  1. package/dist/actions/actionMapper.js +77 -3
  2. package/dist/actions/autogen/templates.d.ts +12 -0
  3. package/dist/actions/autogen/templates.js +735 -2
  4. package/dist/actions/autogen/types.d.ts +689 -4
  5. package/dist/actions/autogen/types.js +209 -3
  6. package/dist/actions/groups.js +22 -1
  7. package/dist/actions/providers/confluence/updatePage.d.ts +3 -0
  8. package/dist/actions/providers/confluence/updatePage.js +47 -0
  9. package/dist/actions/providers/google-oauth/addGroupMember.d.ts +3 -0
  10. package/dist/actions/providers/google-oauth/addGroupMember.js +37 -0
  11. package/dist/actions/providers/google-oauth/deleteCalendarEvent.d.ts +3 -0
  12. package/dist/actions/providers/google-oauth/deleteCalendarEvent.js +35 -0
  13. package/dist/actions/providers/google-oauth/deleteGroupMember.d.ts +3 -0
  14. package/dist/actions/providers/google-oauth/deleteGroupMember.js +33 -0
  15. package/dist/actions/providers/google-oauth/getGroup.d.ts +3 -0
  16. package/dist/actions/providers/google-oauth/getGroup.js +43 -0
  17. package/dist/actions/providers/google-oauth/hasGroupMember.d.ts +3 -0
  18. package/dist/actions/providers/google-oauth/hasGroupMember.js +37 -0
  19. package/dist/actions/providers/google-oauth/listCalendarEvents.d.ts +3 -0
  20. package/dist/actions/providers/google-oauth/listCalendarEvents.js +86 -0
  21. package/dist/actions/providers/google-oauth/listCalendars.d.ts +3 -0
  22. package/dist/actions/providers/google-oauth/listCalendars.js +63 -0
  23. package/dist/actions/providers/google-oauth/listGroupMembers.d.ts +3 -0
  24. package/dist/actions/providers/google-oauth/listGroupMembers.js +54 -0
  25. package/dist/actions/providers/google-oauth/listGroups.d.ts +3 -0
  26. package/dist/actions/providers/google-oauth/listGroups.js +56 -0
  27. package/dist/actions/providers/google-oauth/updateCalendarEvent.d.ts +3 -0
  28. package/dist/actions/providers/google-oauth/updateCalendarEvent.js +59 -0
  29. package/dist/actions/providers/google-oauth/utils/decodeMessage.d.ts +27 -0
  30. package/dist/actions/providers/google-oauth/utils/decodeMessage.js +41 -0
  31. package/dist/actions/providers/googlemail/listGmailThreads.d.ts +3 -0
  32. package/dist/actions/providers/googlemail/listGmailThreads.js +98 -0
  33. package/dist/actions/providers/googlemail/searchGmailMessages.d.ts +3 -0
  34. package/dist/actions/providers/googlemail/searchGmailMessages.js +91 -0
  35. package/package.json +1 -1
  36. package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.d.ts +0 -3
  37. package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.js +0 -43
@@ -0,0 +1,86 @@
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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const listCalendarEvents = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
15
+ if (!authParams.authToken) {
16
+ return { success: false, error: missingAuthConstants_1.MISSING_AUTH_TOKEN, events: [] };
17
+ }
18
+ const { calendarId, query, maxResults } = params;
19
+ const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events`;
20
+ const allEvents = [];
21
+ let pageToken = undefined;
22
+ let fetchedCount = 0;
23
+ const max = maxResults !== null && maxResults !== void 0 ? maxResults : 250; // Default to 250 if not specified, Google API max is 250
24
+ try {
25
+ while (fetchedCount < max) {
26
+ const res = yield axiosClient_1.axiosClient.get(url, {
27
+ headers: {
28
+ Authorization: `Bearer ${authParams.authToken}`,
29
+ },
30
+ params: {
31
+ q: query,
32
+ pageToken,
33
+ maxResults: Math.min(250, max - fetchedCount), // Google API max is 250
34
+ singleEvents: true,
35
+ orderBy: "startTime",
36
+ },
37
+ });
38
+ const { items = [], nextPageToken = undefined } = res.data;
39
+ if (!Array.isArray(items) || items.length <= 0)
40
+ break;
41
+ const batch = items.slice(0, max - fetchedCount);
42
+ allEvents.push(...batch.map(({ id, status, htmlLink, summary, description, location, start, end, attendees, organizer, hangoutLink, created, updated, }) => ({
43
+ id,
44
+ status,
45
+ url: htmlLink,
46
+ title: summary,
47
+ description,
48
+ location,
49
+ start: (start === null || start === void 0 ? void 0 : start.dateTime) || (start === null || start === void 0 ? void 0 : start.date) || "",
50
+ end: (end === null || end === void 0 ? void 0 : end.dateTime) || (end === null || end === void 0 ? void 0 : end.date) || "",
51
+ attendees: Array.isArray(attendees)
52
+ ? attendees.map(({ email, displayName, responseStatus }) => ({
53
+ email,
54
+ displayName,
55
+ responseStatus,
56
+ }))
57
+ : [],
58
+ organizer: organizer
59
+ ? {
60
+ email: organizer.email,
61
+ displayName: organizer.displayName,
62
+ }
63
+ : undefined,
64
+ hangoutLink,
65
+ created,
66
+ updated,
67
+ })));
68
+ fetchedCount = allEvents.length;
69
+ if (!nextPageToken || fetchedCount >= max)
70
+ break;
71
+ pageToken = nextPageToken;
72
+ }
73
+ return {
74
+ success: true,
75
+ events: allEvents,
76
+ };
77
+ }
78
+ catch (error) {
79
+ return {
80
+ success: false,
81
+ events: [],
82
+ error: error instanceof Error ? error.message : "Unknown error listing events",
83
+ };
84
+ }
85
+ });
86
+ exports.default = listCalendarEvents;
@@ -0,0 +1,3 @@
1
+ import type { googleOauthListCalendarsFunction } from "../../autogen/types";
2
+ declare const listCalendars: googleOauthListCalendarsFunction;
3
+ export default listCalendars;
@@ -0,0 +1,63 @@
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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const listCalendars = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
15
+ var _b;
16
+ if (!authParams.authToken) {
17
+ return { success: false, error: missingAuthConstants_1.MISSING_AUTH_TOKEN, calendars: [] };
18
+ }
19
+ const url = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
20
+ const allCalendars = [];
21
+ let pageToken = undefined;
22
+ let fetchedCount = 0;
23
+ const max = (_b = params.maxResults) !== null && _b !== void 0 ? _b : 250; // Default to 250 if not specified, Google API max is 250
24
+ try {
25
+ while (fetchedCount < max) {
26
+ const res = yield axiosClient_1.axiosClient.get(url, {
27
+ headers: {
28
+ Authorization: `Bearer ${authParams.authToken}`,
29
+ },
30
+ params: {
31
+ showDeleted: false,
32
+ showHidden: false,
33
+ pageToken,
34
+ maxResults: Math.min(250, max - fetchedCount), // Google API max is 250
35
+ },
36
+ });
37
+ const { items = [], nextPageToken = undefined } = res.data;
38
+ if (!Array.isArray(items) || items.length <= 0)
39
+ break;
40
+ const batch = items.slice(0, max - fetchedCount);
41
+ allCalendars.push(...batch.map(c => ({
42
+ id: c.id,
43
+ summary: c.summary,
44
+ })));
45
+ fetchedCount = allCalendars.length;
46
+ if (!nextPageToken || fetchedCount >= max)
47
+ break;
48
+ pageToken = nextPageToken;
49
+ }
50
+ return {
51
+ success: true,
52
+ calendars: allCalendars,
53
+ };
54
+ }
55
+ catch (error) {
56
+ return {
57
+ success: false,
58
+ calendars: [],
59
+ error: error instanceof Error ? error.message : "Unknown error listing calendars",
60
+ };
61
+ }
62
+ });
63
+ exports.default = listCalendars;
@@ -0,0 +1,3 @@
1
+ import type { googleOauthListGroupMembersFunction } from "../../autogen/types";
2
+ declare const listGroupMembers: googleOauthListGroupMembersFunction;
3
+ export default listGroupMembers;
@@ -0,0 +1,54 @@
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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const listGroupMembers = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
15
+ const { authToken } = authParams;
16
+ const { groupKey, maxResults } = params;
17
+ if (!authToken) {
18
+ return { success: false, members: [], error: missingAuthConstants_1.MISSING_AUTH_TOKEN };
19
+ }
20
+ try {
21
+ let members = [];
22
+ let pageToken = undefined;
23
+ const limit = Math.min(maxResults !== null && maxResults !== void 0 ? maxResults : 200, 200);
24
+ while (members.length < limit) {
25
+ const url = new URL(`https://admin.googleapis.com/admin/directory/v1/groups/${encodeURIComponent(groupKey)}/members`);
26
+ url.searchParams.set("maxResults", String(limit - members.length));
27
+ if (pageToken)
28
+ url.searchParams.set("pageToken", pageToken);
29
+ const response = yield axiosClient_1.axiosClient.get(url.toString(), {
30
+ headers: { Authorization: `Bearer ${authToken}` },
31
+ });
32
+ const data = response.data;
33
+ const batch = (data.members || []).map(({ id, email, role, type }) => ({
34
+ id,
35
+ email,
36
+ role,
37
+ type,
38
+ }));
39
+ members = members.concat(batch);
40
+ pageToken = data.nextPageToken;
41
+ if (!pageToken)
42
+ break;
43
+ }
44
+ return { success: true, members: members.slice(0, limit) };
45
+ }
46
+ catch (error) {
47
+ return {
48
+ success: false,
49
+ members: [],
50
+ error: error instanceof Error ? error.message : "Unknown error",
51
+ };
52
+ }
53
+ });
54
+ exports.default = listGroupMembers;
@@ -0,0 +1,3 @@
1
+ import type { googleOauthListGroupsFunction } from "../../autogen/types";
2
+ declare const listGroups: googleOauthListGroupsFunction;
3
+ export default listGroups;
@@ -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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const listGroups = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authParams, params, }) {
15
+ var _b;
16
+ const { authToken } = authParams;
17
+ const maxResults = (_b = params === null || params === void 0 ? void 0 : params.maxResults) !== null && _b !== void 0 ? _b : 200;
18
+ if (!authToken) {
19
+ return { success: false, groups: [], error: missingAuthConstants_1.MISSING_AUTH_TOKEN };
20
+ }
21
+ try {
22
+ let groups = [];
23
+ let pageToken = undefined;
24
+ const limit = Math.min(maxResults, 200);
25
+ while (groups.length < limit) {
26
+ const url = new URL("https://admin.googleapis.com/admin/directory/v1/groups");
27
+ url.searchParams.set("customer", "my_customer");
28
+ url.searchParams.set("maxResults", String(limit - groups.length));
29
+ if (pageToken)
30
+ url.searchParams.set("pageToken", pageToken);
31
+ const response = yield axiosClient_1.axiosClient.get(url.toString(), {
32
+ headers: { Authorization: `Bearer ${authToken}` },
33
+ });
34
+ const data = response.data;
35
+ const batch = (data.groups || []).map(({ id, email, name, description }) => ({
36
+ id,
37
+ email,
38
+ name,
39
+ description,
40
+ }));
41
+ groups = groups.concat(batch);
42
+ pageToken = data.nextPageToken;
43
+ if (!pageToken)
44
+ break;
45
+ }
46
+ return { success: true, groups: groups.slice(0, limit) };
47
+ }
48
+ catch (error) {
49
+ return {
50
+ success: false,
51
+ groups: [],
52
+ error: error instanceof Error ? error.message : "Unknown error",
53
+ };
54
+ }
55
+ });
56
+ exports.default = listGroups;
@@ -0,0 +1,3 @@
1
+ import type { googleOauthUpdateCalendarEventFunction } from "../../autogen/types";
2
+ declare const updateCalendarEvent: googleOauthUpdateCalendarEventFunction;
3
+ export default updateCalendarEvent;
@@ -0,0 +1,59 @@
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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const updateCalendarEvent = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
15
+ if (!authParams.authToken) {
16
+ return { success: false, error: missingAuthConstants_1.MISSING_AUTH_TOKEN, eventId: "", eventUrl: "" };
17
+ }
18
+ const { calendarId, eventId, updates } = params;
19
+ const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events/${encodeURIComponent(eventId)}`;
20
+ const body = {};
21
+ if (updates) {
22
+ if (updates.title != undefined)
23
+ body.summary = updates.title;
24
+ if (updates.description != undefined)
25
+ body.description = updates.description;
26
+ if (updates.start != undefined)
27
+ body.start = { dateTime: updates.start };
28
+ if (updates.end != undefined)
29
+ body.end = { dateTime: updates.end };
30
+ if (updates.location != undefined)
31
+ body.location = updates.location;
32
+ if (updates.attendees != undefined)
33
+ body.attendees = updates.attendees.map(email => ({ email }));
34
+ if (updates.status != undefined)
35
+ body.status = updates.status;
36
+ if (updates.organizer != undefined)
37
+ body.organizer = updates.organizer;
38
+ }
39
+ try {
40
+ const res = yield axiosClient_1.axiosClient.patch(url, body, {
41
+ headers: {
42
+ Authorization: `Bearer ${authParams.authToken}`,
43
+ },
44
+ });
45
+ const { id, htmlLink } = res.data;
46
+ return {
47
+ success: true,
48
+ eventId: id,
49
+ eventUrl: htmlLink,
50
+ };
51
+ }
52
+ catch (error) {
53
+ return {
54
+ success: false,
55
+ error: error instanceof Error ? error.message : "Unknown error updating event",
56
+ };
57
+ }
58
+ });
59
+ exports.default = updateCalendarEvent;
@@ -0,0 +1,27 @@
1
+ export interface GmailMessage {
2
+ payload: {
3
+ mimeType: string;
4
+ body?: {
5
+ data?: string;
6
+ size: number;
7
+ };
8
+ parts?: Array<{
9
+ partId: string;
10
+ mimeType: string;
11
+ body: {
12
+ data?: string;
13
+ size: number;
14
+ };
15
+ parts?: Array<{
16
+ partId: string;
17
+ mimeType: string;
18
+ body: {
19
+ data?: string;
20
+ size: number;
21
+ };
22
+ }>;
23
+ }>;
24
+ };
25
+ }
26
+ export declare function decodeGmailBase64(base64String: string): string;
27
+ export declare function getEmailContent(message: GmailMessage): string | null;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeGmailBase64 = decodeGmailBase64;
4
+ exports.getEmailContent = getEmailContent;
5
+ function decodeGmailBase64(base64String) {
6
+ // Gmail API uses URL-safe base64 encoding
7
+ const standardBase64 = base64String.replace(/-/g, "+").replace(/_/g, "/");
8
+ // Add padding if needed
9
+ const padded = standardBase64.padEnd(standardBase64.length + ((4 - (standardBase64.length % 4)) % 4), "=");
10
+ // Only works for Node.js environment
11
+ return Buffer.from(padded, "base64").toString("utf-8");
12
+ }
13
+ function getEmailContent(message) {
14
+ var _a;
15
+ let textContent = null;
16
+ // Function to recursively search for plain text content in parts
17
+ function searchParts(parts) {
18
+ var _a;
19
+ if (!parts)
20
+ return;
21
+ for (const part of parts) {
22
+ if (part.mimeType === "text/plain" && ((_a = part.body) === null || _a === void 0 ? void 0 : _a.data) && !textContent) {
23
+ textContent = decodeGmailBase64(part.body.data);
24
+ }
25
+ else if (part.parts) {
26
+ // Recursively search nested parts
27
+ searchParts(part.parts);
28
+ }
29
+ }
30
+ }
31
+ // 1. Check if content is directly in the payload body (simple emails)
32
+ if (((_a = message.payload.body) === null || _a === void 0 ? void 0 : _a.data) && message.payload.mimeType === "text/plain") {
33
+ return decodeGmailBase64(message.payload.body.data);
34
+ }
35
+ // 2. Search through parts for plain text content
36
+ if (message.payload.parts) {
37
+ searchParts(message.payload.parts);
38
+ }
39
+ // 3. Return plain text content or null
40
+ return textContent;
41
+ }
@@ -0,0 +1,3 @@
1
+ import type { googlemailListGmailThreadsFunction } from "../../autogen/types";
2
+ declare const listGmailThreads: googlemailListGmailThreadsFunction;
3
+ export default listGmailThreads;
@@ -0,0 +1,98 @@
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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const decodeMessage_1 = require("../google-oauth/utils/decodeMessage");
15
+ const listGmailThreads = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
16
+ if (!authParams.authToken) {
17
+ return { success: false, error: missingAuthConstants_1.MISSING_AUTH_TOKEN, threads: [] };
18
+ }
19
+ const { query, maxResults } = params;
20
+ const allThreads = [];
21
+ const errorMessages = [];
22
+ const max = maxResults !== null && maxResults !== void 0 ? maxResults : 100;
23
+ let fetched = 0;
24
+ let pageToken = undefined;
25
+ try {
26
+ while (fetched < max) {
27
+ const url = `https://gmail.googleapis.com/gmail/v1/users/me/threads?q=${encodeURIComponent(query)}` +
28
+ (pageToken ? `&pageToken=${encodeURIComponent(pageToken)}` : "") +
29
+ `&maxResults=${Math.min(100, max - fetched)}`;
30
+ const listRes = yield axiosClient_1.axiosClient.get(url, {
31
+ headers: {
32
+ Authorization: `Bearer ${authParams.authToken}`,
33
+ },
34
+ });
35
+ const { threads: threadList = [], nextPageToken } = listRes.data;
36
+ if (!Array.isArray(threadList) || threadList.length === 0)
37
+ break;
38
+ const remaining = max - allThreads.length;
39
+ const batch = threadList.slice(0, remaining);
40
+ const results = yield Promise.all(batch.map((thread) => __awaiter(void 0, void 0, void 0, function* () {
41
+ try {
42
+ const threadRes = yield axiosClient_1.axiosClient.get(`https://gmail.googleapis.com/gmail/v1/users/me/threads/${thread.id}?format=full`, {
43
+ headers: {
44
+ Authorization: `Bearer ${authParams.authToken}`,
45
+ },
46
+ });
47
+ const { id, historyId, messages } = threadRes.data;
48
+ return {
49
+ id,
50
+ historyId,
51
+ messages: Array.isArray(messages)
52
+ ? messages.map(msg => {
53
+ const { id, threadId, snippet, labelIds, internalDate } = msg;
54
+ const emailBody = (0, decodeMessage_1.getEmailContent)(msg) || "";
55
+ return {
56
+ id,
57
+ threadId,
58
+ snippet,
59
+ labelIds,
60
+ internalDate,
61
+ emailBody,
62
+ };
63
+ })
64
+ : [],
65
+ };
66
+ }
67
+ catch (err) {
68
+ errorMessages.push(err instanceof Error ? err.message : "Failed to fetch thread details");
69
+ return {
70
+ id: thread.id,
71
+ snippet: "",
72
+ historyId: "",
73
+ messages: [],
74
+ error: err instanceof Error ? err.message : "Failed to fetch thread details",
75
+ };
76
+ }
77
+ })));
78
+ allThreads.push(...results);
79
+ fetched = allThreads.length;
80
+ if (!nextPageToken || allThreads.length >= max)
81
+ break;
82
+ pageToken = nextPageToken;
83
+ }
84
+ return {
85
+ success: errorMessages.length === 0,
86
+ threads: allThreads,
87
+ error: errorMessages.join("; "),
88
+ };
89
+ }
90
+ catch (error) {
91
+ return {
92
+ success: false,
93
+ error: error instanceof Error ? error.message : "Unknown error listing Gmail threads",
94
+ threads: [],
95
+ };
96
+ }
97
+ });
98
+ exports.default = listGmailThreads;
@@ -0,0 +1,3 @@
1
+ import type { googlemailSearchGmailMessagesFunction } from "../../autogen/types";
2
+ declare const searchGmailMessages: googlemailSearchGmailMessagesFunction;
3
+ export default searchGmailMessages;
@@ -0,0 +1,91 @@
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 missingAuthConstants_1 = require("../../util/missingAuthConstants");
14
+ const decodeMessage_1 = require("../google-oauth/utils/decodeMessage");
15
+ const searchGmailMessages = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
16
+ if (!authParams.authToken) {
17
+ return { success: false, error: missingAuthConstants_1.MISSING_AUTH_TOKEN, messages: [] };
18
+ }
19
+ const { query, maxResults } = params;
20
+ const allMessages = [];
21
+ const max = maxResults !== null && maxResults !== void 0 ? maxResults : 100;
22
+ const errorMessages = [];
23
+ let pageToken = undefined;
24
+ let fetched = 0;
25
+ try {
26
+ while (fetched < max) {
27
+ const url = `https://gmail.googleapis.com/gmail/v1/users/me/messages?q=${encodeURIComponent(query)}` +
28
+ (pageToken ? `&pageToken=${encodeURIComponent(pageToken)}` : "") +
29
+ `&maxResults=${Math.min(100, max - fetched)}`;
30
+ const listRes = yield axiosClient_1.axiosClient.get(url, {
31
+ headers: {
32
+ Authorization: `Bearer ${authParams.authToken}`,
33
+ },
34
+ });
35
+ const { messages: messageList = [], nextPageToken } = listRes.data;
36
+ if (!Array.isArray(messageList) || messageList.length === 0)
37
+ break;
38
+ const remaining = max - allMessages.length;
39
+ const batch = messageList.slice(0, remaining);
40
+ const results = yield Promise.all(batch.map((msg) => __awaiter(void 0, void 0, void 0, function* () {
41
+ try {
42
+ const msgRes = yield axiosClient_1.axiosClient.get(`https://gmail.googleapis.com/gmail/v1/users/me/messages/${msg.id}?format=full`, {
43
+ headers: {
44
+ Authorization: `Bearer ${authParams.authToken}`,
45
+ },
46
+ });
47
+ const { id, threadId, snippet, labelIds, internalDate } = msgRes.data;
48
+ const emailBody = (0, decodeMessage_1.getEmailContent)(msgRes.data) || "";
49
+ return {
50
+ id,
51
+ threadId,
52
+ snippet,
53
+ labelIds,
54
+ internalDate,
55
+ emailBody,
56
+ };
57
+ }
58
+ catch (err) {
59
+ errorMessages.push(err instanceof Error ? err.message : "Failed to fetch message details");
60
+ return {
61
+ id: msg.id,
62
+ threadId: "",
63
+ snippet: "",
64
+ labelIds: [],
65
+ internalDate: "",
66
+ payload: {},
67
+ error: err instanceof Error ? err.message : "Failed to fetch message details",
68
+ };
69
+ }
70
+ })));
71
+ allMessages.push(...results);
72
+ fetched = allMessages.length;
73
+ if (!nextPageToken || allMessages.length >= max)
74
+ break;
75
+ pageToken = nextPageToken;
76
+ }
77
+ return {
78
+ success: errorMessages.length === 0,
79
+ messages: allMessages,
80
+ error: errorMessages.join("; "),
81
+ };
82
+ }
83
+ catch (error) {
84
+ return {
85
+ success: false,
86
+ error: error instanceof Error ? error.message : "Unknown error searching Gmail",
87
+ messages: [],
88
+ };
89
+ }
90
+ });
91
+ exports.default = searchGmailMessages;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.1.97",
3
+ "version": "0.1.99",
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 { salesforceGetSalesforceRecordsByQueryFunction } from "../../autogen/types";
2
- declare const getSalesforceRecordByQuery: salesforceGetSalesforceRecordsByQueryFunction;
3
- export default getSalesforceRecordByQuery;