@credal/actions 0.2.89 → 0.2.91
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.
- package/dist/actions/autogen/templates.js +6 -2
- package/dist/actions/autogen/types.d.ts +6 -3
- package/dist/actions/autogen/types.js +3 -4
- package/dist/actions/groups.js +1 -4
- package/dist/actions/providers/credal/callCopilot.d.ts +3 -0
- package/dist/actions/providers/credal/callCopilot.js +36 -0
- package/dist/actions/providers/google-oauth/createNewGoogleDoc.js +121 -16
- package/dist/actions/providers/google-oauth/getDriveFileContentById.js +5 -4
- package/dist/actions/providers/google-oauth/listGmailThreads.d.ts +3 -0
- package/dist/actions/providers/google-oauth/listGmailThreads.js +98 -0
- package/dist/actions/providers/google-oauth/searchDriveByKeywordsAndGetFileContent.js +2 -2
- package/dist/actions/providers/google-oauth/searchDriveByQueryAndGetFileContent.js +2 -2
- package/dist/actions/providers/google-oauth/searchGmailMessages.d.ts +3 -0
- package/dist/actions/providers/google-oauth/searchGmailMessages.js +91 -0
- package/dist/actions/providers/jamf/getComputerInventory.d.ts +3 -0
- package/dist/actions/providers/jamf/getComputerInventory.js +45 -0
- package/dist/actions/providers/jamf/getFileVaultRecoveryKey.d.ts +3 -0
- package/dist/actions/providers/jamf/getFileVaultRecoveryKey.js +40 -0
- package/dist/actions/providers/jamf/restartJamfComputerById.d.ts +3 -0
- package/dist/actions/providers/jamf/restartJamfComputerById.js +37 -0
- package/dist/actions/providers/jamf/types.d.ts +8 -0
- package/dist/actions/providers/jamf/types.js +7 -0
- package/dist/actions/providers/math/index.d.ts +1 -0
- package/dist/actions/providers/math/index.js +37 -0
- package/dist/actions/providers/salesforce/searchSalesforceRecords.js +1 -1
- package/dist/actions/providers/slack/archiveChannel.js +9 -5
- package/dist/actions/providers/slack/index.d.ts +1 -0
- package/dist/actions/providers/slack/index.js +37 -0
- package/dist/actions/providers/slack/listConversations.d.ts +3 -0
- package/dist/actions/providers/slack/listConversations.js +41 -0
- package/package.json +1 -1
- package/dist/actions/providers/github/fetchFile.d.ts +0 -3
- package/dist/actions/providers/github/fetchFile.js +0 -131
- package/dist/actions/providers/github/getContents.d.ts +0 -3
- package/dist/actions/providers/github/getContents.js +0 -41
|
@@ -3231,6 +3231,10 @@ export const googleOauthCreateNewGoogleDocDefinition = {
|
|
|
3231
3231
|
type: "string",
|
|
3232
3232
|
description: "The content to add to the new Google Doc",
|
|
3233
3233
|
},
|
|
3234
|
+
usesHtml: {
|
|
3235
|
+
type: "boolean",
|
|
3236
|
+
description: "Whether to interpret the content as HTML",
|
|
3237
|
+
},
|
|
3234
3238
|
},
|
|
3235
3239
|
},
|
|
3236
3240
|
output: {
|
|
@@ -6839,7 +6843,7 @@ export const googleOauthSearchDriveByKeywordsAndGetFileContentDefinition = {
|
|
|
6839
6843
|
properties: {
|
|
6840
6844
|
searchQuery: {
|
|
6841
6845
|
type: "string",
|
|
6842
|
-
description: "The query to
|
|
6846
|
+
description: "The query input to Google Drive search",
|
|
6843
6847
|
},
|
|
6844
6848
|
limit: {
|
|
6845
6849
|
type: "number",
|
|
@@ -6987,7 +6991,7 @@ export const googleOauthGetDriveFileContentByIdDefinition = {
|
|
|
6987
6991
|
scopes: ["drive.readonly"],
|
|
6988
6992
|
parameters: {
|
|
6989
6993
|
type: "object",
|
|
6990
|
-
required: ["fileId"
|
|
6994
|
+
required: ["fileId"],
|
|
6991
6995
|
properties: {
|
|
6992
6996
|
fileId: {
|
|
6993
6997
|
type: "string",
|
|
@@ -3137,12 +3137,15 @@ export type resendSendEmailHtmlFunction = ActionFunction<resendSendEmailHtmlPara
|
|
|
3137
3137
|
export declare const googleOauthCreateNewGoogleDocParamsSchema: z.ZodObject<{
|
|
3138
3138
|
title: z.ZodString;
|
|
3139
3139
|
content: z.ZodOptional<z.ZodString>;
|
|
3140
|
+
usesHtml: z.ZodOptional<z.ZodBoolean>;
|
|
3140
3141
|
}, "strip", z.ZodTypeAny, {
|
|
3141
3142
|
title: string;
|
|
3142
3143
|
content?: string | undefined;
|
|
3144
|
+
usesHtml?: boolean | undefined;
|
|
3143
3145
|
}, {
|
|
3144
3146
|
title: string;
|
|
3145
3147
|
content?: string | undefined;
|
|
3148
|
+
usesHtml?: boolean | undefined;
|
|
3146
3149
|
}>;
|
|
3147
3150
|
export type googleOauthCreateNewGoogleDocParamsType = z.infer<typeof googleOauthCreateNewGoogleDocParamsSchema>;
|
|
3148
3151
|
export declare const googleOauthCreateNewGoogleDocOutputSchema: z.ZodObject<{
|
|
@@ -4195,17 +4198,17 @@ export type googleOauthSearchDriveByQueryAndGetFileContentOutputType = z.infer<t
|
|
|
4195
4198
|
export type googleOauthSearchDriveByQueryAndGetFileContentFunction = ActionFunction<googleOauthSearchDriveByQueryAndGetFileContentParamsType, AuthParamsType, googleOauthSearchDriveByQueryAndGetFileContentOutputType>;
|
|
4196
4199
|
export declare const googleOauthGetDriveFileContentByIdParamsSchema: z.ZodObject<{
|
|
4197
4200
|
fileId: z.ZodString;
|
|
4198
|
-
limit: z.ZodNumber
|
|
4201
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
4199
4202
|
timeoutLimit: z.ZodOptional<z.ZodNumber>;
|
|
4200
4203
|
fileSizeLimit: z.ZodOptional<z.ZodNumber>;
|
|
4201
4204
|
}, "strip", z.ZodTypeAny, {
|
|
4202
|
-
limit: number;
|
|
4203
4205
|
fileId: string;
|
|
4206
|
+
limit?: number | undefined;
|
|
4204
4207
|
fileSizeLimit?: number | undefined;
|
|
4205
4208
|
timeoutLimit?: number | undefined;
|
|
4206
4209
|
}, {
|
|
4207
|
-
limit: number;
|
|
4208
4210
|
fileId: string;
|
|
4211
|
+
limit?: number | undefined;
|
|
4209
4212
|
fileSizeLimit?: number | undefined;
|
|
4210
4213
|
timeoutLimit?: number | undefined;
|
|
4211
4214
|
}>;
|
|
@@ -970,6 +970,7 @@ export const resendSendEmailHtmlOutputSchema = z.object({
|
|
|
970
970
|
export const googleOauthCreateNewGoogleDocParamsSchema = z.object({
|
|
971
971
|
title: z.string().describe("The title of the new Google Doc"),
|
|
972
972
|
content: z.string().describe("The content to add to the new Google Doc").optional(),
|
|
973
|
+
usesHtml: z.boolean().describe("Whether to interpret the content as HTML").optional(),
|
|
973
974
|
});
|
|
974
975
|
export const googleOauthCreateNewGoogleDocOutputSchema = z.object({
|
|
975
976
|
documentId: z.string().describe("The ID of the created Google Doc"),
|
|
@@ -2588,9 +2589,7 @@ export const googleOauthSearchDriveByQueryOutputSchema = z.object({
|
|
|
2588
2589
|
error: z.string().describe("Error message if search failed").optional(),
|
|
2589
2590
|
});
|
|
2590
2591
|
export const googleOauthSearchDriveByKeywordsAndGetFileContentParamsSchema = z.object({
|
|
2591
|
-
searchQuery: z
|
|
2592
|
-
.string()
|
|
2593
|
-
.describe("The query to search for in file contents, eg 'compliance policy' or 'data encryption'. The more relevant words the better."),
|
|
2592
|
+
searchQuery: z.string().describe("The query input to Google Drive search"),
|
|
2594
2593
|
limit: z.number().describe("The maximum number of files to return").optional(),
|
|
2595
2594
|
fileSizeLimit: z.number().describe("The maximum length of a file in characters").optional(),
|
|
2596
2595
|
searchDriveByDrive: z.boolean().describe("Search drive by drive or run a general search"),
|
|
@@ -2639,7 +2638,7 @@ export const googleOauthSearchDriveByQueryAndGetFileContentOutputSchema = z.obje
|
|
|
2639
2638
|
});
|
|
2640
2639
|
export const googleOauthGetDriveFileContentByIdParamsSchema = z.object({
|
|
2641
2640
|
fileId: z.string().describe("The ID of the file to get content from"),
|
|
2642
|
-
limit: z.number().describe("The character limit for the file content"),
|
|
2641
|
+
limit: z.number().describe("The character limit for the file content").optional(),
|
|
2643
2642
|
timeoutLimit: z
|
|
2644
2643
|
.number()
|
|
2645
2644
|
.describe("The timeout limit for the file content retrieval (default of 15 seconds)")
|
package/dist/actions/groups.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { genericFillTemplateDefinition, confluenceOverwritePageDefinition, googlemapsValidateAddressDefinition, mathAddDefinition, mongoInsertMongoDocDefinition, slackSendMessageDefinition, slackGetChannelMessagesDefinition, slackCreateChannelDefinition, slackArchiveChannelDefinition, snowflakeGetRowByFieldValueDefinition, zendeskCreateZendeskTicketDefinition, zendeskListZendeskTicketsDefinition, zendeskGetTicketDetailsDefinition, zendeskUpdateTicketStatusDefinition, zendeskAddCommentToTicketDefinition, zendeskAssignTicketDefinition, openstreetmapGetLatitudeLongitudeFromLocationDefinition, nwsGetForecastForLocationDefinition, jiraAssignJiraTicketDefinition, jiraCommentJiraTicketDefinition, jiraCreateJiraTicketDefinition, jiraGetJiraTicketDetailsDefinition, jiraGetJiraTicketHistoryDefinition, jiraUpdateJiraTicketDetailsDefinition, jiraUpdateJiraTicketStatusDefinition, jiraGetServiceDesksDefinition, jiraCreateServiceDeskRequestDefinition, googlemapsNearbysearchRestaurantsDefinition, firecrawlScrapeUrlDefinition, resendSendEmailDefinition, linkedinCreateShareLinkedinPostUrlDefinition, googleOauthCreateNewGoogleDocDefinition, xCreateShareXPostUrlDefinition, firecrawlScrapeTweetDataWithNitterDefinition, finnhubSymbolLookupDefinition, finnhubGetBasicFinancialsDefinition, confluenceFetchPageContentDefinition, snowflakeRunSnowflakeQueryDefinition, lookerEnableUserByEmailDefinition, googleOauthUpdateDocDefinition, googleOauthScheduleCalendarMeetingDefinition, googleOauthListCalendarsDefinition, googleOauthListCalendarEventsDefinition, googleOauthUpdateCalendarEventDefinition, googleOauthDeleteCalendarEventDefinition, googleOauthCreateSpreadsheetDefinition, googleOauthUpdateSpreadsheetDefinition, googleOauthCreatePresentationDefinition, googleOauthUpdatePresentationDefinition, googleOauthSearchDriveByKeywordsDefinition, googlemailSearchGmailMessagesDefinition, googlemailListGmailThreadsDefinition, googleOauthListGroupsDefinition, googleOauthGetGroupDefinition, googleOauthListGroupMembersDefinition, googleOauthHasGroupMemberDefinition, googleOauthAddGroupMemberDefinition, googleOauthDeleteGroupMemberDefinition, salesforceUpdateRecordDefinition, salesforceCreateCaseDefinition, salesforceGenerateSalesReportDefinition, salesforceGetRecordDefinition, salesforceGetSalesforceRecordsByQueryDefinition, microsoftMessageTeamsChatDefinition, microsoftMessageTeamsChannelDefinition, asanaCommentTaskDefinition, asanaCreateTaskDefinition, asanaUpdateTaskDefinition, asanaSearchTasksDefinition, githubCreateOrUpdateFileDefinition, githubCreateBranchDefinition, githubCreatePullRequestDefinition, microsoftUpdateSpreadsheetDefinition, microsoftUpdateDocumentDefinition, microsoftCreateDocumentDefinition, microsoftGetDocumentDefinition, salesforceFetchSalesforceSchemaByObjectDefinition, firecrawlDeepResearchDefinition, jiraGetJiraIssuesByQueryDefinition, githubListPullRequestsDefinition, salesforceCreateRecordDefinition, ashbyCreateNoteDefinition, ashbyGetCandidateInfoDefinition, ashbyListCandidatesDefinition, ashbyListCandidateNotesDefinition, ashbySearchCandidatesDefinition, ashbyCreateCandidateDefinition, ashbyUpdateCandidateDefinition, ashbyAddCandidateToProjectDefinition, bingGetTopNSearchResultUrlsDefinition, gongGetGongTranscriptsDefinition, kandjiGetFVRecoveryKeyForDeviceDefinition, asanaListAsanaTasksByProjectDefinition, notionSearchByTitleDefinition, asanaGetTasksDetailsDefinition, jamfGetJamfComputerInventoryDefinition, jamfGetJamfFileVaultRecoveryKeyDefinition, oktaListOktaUsersDefinition, oktaGetOktaUserDefinition, oktaListOktaUserGroupsDefinition, oktaListOktaGroupsDefinition, oktaGetOktaGroupDefinition, oktaListOktaGroupMembersDefinition, oktaRemoveUserFromGroupDefinition, oktaAddUserToGroupDefinition, oktaResetPasswordDefinition, oktaResetMFADefinition, oktaListMFADefinition, jamfGetJamfUserComputerIdDefinition, jamfLockJamfComputerByIdDefinition, oktaTriggerOktaWorkflowDefinition, jiraOrgAssignJiraTicketDefinition, jiraOrgCreateJiraTicketDefinition, jiraOrgCommentJiraTicketDefinition, jiraOrgGetJiraTicketDetailsDefinition, jiraOrgGetJiraTicketHistoryDefinition, jiraOrgUpdateJiraTicketDetailsDefinition, jiraOrgUpdateJiraTicketStatusDefinition, jiraOrgGetJiraIssuesByQueryDefinition, googleOauthGetDriveFileContentByIdDefinition, googleOauthSearchDriveByQueryDefinition,
|
|
1
|
+
import { genericFillTemplateDefinition, confluenceOverwritePageDefinition, googlemapsValidateAddressDefinition, mathAddDefinition, mongoInsertMongoDocDefinition, slackSendMessageDefinition, slackGetChannelMessagesDefinition, slackCreateChannelDefinition, slackArchiveChannelDefinition, snowflakeGetRowByFieldValueDefinition, zendeskCreateZendeskTicketDefinition, zendeskListZendeskTicketsDefinition, zendeskGetTicketDetailsDefinition, zendeskUpdateTicketStatusDefinition, zendeskAddCommentToTicketDefinition, zendeskAssignTicketDefinition, openstreetmapGetLatitudeLongitudeFromLocationDefinition, nwsGetForecastForLocationDefinition, jiraAssignJiraTicketDefinition, jiraCommentJiraTicketDefinition, jiraCreateJiraTicketDefinition, jiraGetJiraTicketDetailsDefinition, jiraGetJiraTicketHistoryDefinition, jiraUpdateJiraTicketDetailsDefinition, jiraUpdateJiraTicketStatusDefinition, jiraGetServiceDesksDefinition, jiraCreateServiceDeskRequestDefinition, googlemapsNearbysearchRestaurantsDefinition, firecrawlScrapeUrlDefinition, resendSendEmailDefinition, linkedinCreateShareLinkedinPostUrlDefinition, googleOauthCreateNewGoogleDocDefinition, xCreateShareXPostUrlDefinition, firecrawlScrapeTweetDataWithNitterDefinition, finnhubSymbolLookupDefinition, finnhubGetBasicFinancialsDefinition, confluenceFetchPageContentDefinition, snowflakeRunSnowflakeQueryDefinition, lookerEnableUserByEmailDefinition, googleOauthUpdateDocDefinition, googleOauthScheduleCalendarMeetingDefinition, googleOauthListCalendarsDefinition, googleOauthListCalendarEventsDefinition, googleOauthUpdateCalendarEventDefinition, googleOauthDeleteCalendarEventDefinition, googleOauthCreateSpreadsheetDefinition, googleOauthUpdateSpreadsheetDefinition, googleOauthCreatePresentationDefinition, googleOauthUpdatePresentationDefinition, googleOauthSearchDriveByKeywordsDefinition, googlemailSearchGmailMessagesDefinition, googlemailListGmailThreadsDefinition, googleOauthListGroupsDefinition, googleOauthGetGroupDefinition, googleOauthListGroupMembersDefinition, googleOauthHasGroupMemberDefinition, googleOauthAddGroupMemberDefinition, googleOauthDeleteGroupMemberDefinition, salesforceUpdateRecordDefinition, salesforceCreateCaseDefinition, salesforceGenerateSalesReportDefinition, salesforceGetRecordDefinition, salesforceGetSalesforceRecordsByQueryDefinition, microsoftMessageTeamsChatDefinition, microsoftMessageTeamsChannelDefinition, asanaCommentTaskDefinition, asanaCreateTaskDefinition, asanaUpdateTaskDefinition, asanaSearchTasksDefinition, githubCreateOrUpdateFileDefinition, githubCreateBranchDefinition, githubCreatePullRequestDefinition, microsoftUpdateSpreadsheetDefinition, microsoftUpdateDocumentDefinition, microsoftCreateDocumentDefinition, microsoftGetDocumentDefinition, salesforceFetchSalesforceSchemaByObjectDefinition, firecrawlDeepResearchDefinition, jiraGetJiraIssuesByQueryDefinition, githubListPullRequestsDefinition, salesforceCreateRecordDefinition, ashbyCreateNoteDefinition, ashbyGetCandidateInfoDefinition, ashbyListCandidatesDefinition, ashbyListCandidateNotesDefinition, ashbySearchCandidatesDefinition, ashbyCreateCandidateDefinition, ashbyUpdateCandidateDefinition, ashbyAddCandidateToProjectDefinition, bingGetTopNSearchResultUrlsDefinition, gongGetGongTranscriptsDefinition, kandjiGetFVRecoveryKeyForDeviceDefinition, asanaListAsanaTasksByProjectDefinition, notionSearchByTitleDefinition, asanaGetTasksDetailsDefinition, jamfGetJamfComputerInventoryDefinition, jamfGetJamfFileVaultRecoveryKeyDefinition, oktaListOktaUsersDefinition, oktaGetOktaUserDefinition, oktaListOktaUserGroupsDefinition, oktaListOktaGroupsDefinition, oktaGetOktaGroupDefinition, oktaListOktaGroupMembersDefinition, oktaRemoveUserFromGroupDefinition, oktaAddUserToGroupDefinition, oktaResetPasswordDefinition, oktaResetMFADefinition, oktaListMFADefinition, jamfGetJamfUserComputerIdDefinition, jamfLockJamfComputerByIdDefinition, oktaTriggerOktaWorkflowDefinition, jiraOrgAssignJiraTicketDefinition, jiraOrgCreateJiraTicketDefinition, jiraOrgCommentJiraTicketDefinition, jiraOrgGetJiraTicketDetailsDefinition, jiraOrgGetJiraTicketHistoryDefinition, jiraOrgUpdateJiraTicketDetailsDefinition, jiraOrgUpdateJiraTicketStatusDefinition, jiraOrgGetJiraIssuesByQueryDefinition, googleOauthGetDriveFileContentByIdDefinition, googleOauthSearchDriveByQueryDefinition, } from "./autogen/templates.js";
|
|
2
2
|
export const ACTION_GROUPS = {
|
|
3
3
|
GENERIC: {
|
|
4
4
|
description: "Generic utility actions",
|
|
@@ -47,7 +47,6 @@ export const ACTION_GROUPS = {
|
|
|
47
47
|
googleOauthUpdatePresentationDefinition,
|
|
48
48
|
googleOauthSearchDriveByKeywordsDefinition,
|
|
49
49
|
googleOauthSearchDriveByQueryDefinition,
|
|
50
|
-
googleOauthSearchDriveByQueryAndGetFileContentDefinition,
|
|
51
50
|
googleOauthGetDriveFileContentByIdDefinition,
|
|
52
51
|
],
|
|
53
52
|
},
|
|
@@ -199,8 +198,6 @@ export const ACTION_GROUPS = {
|
|
|
199
198
|
githubCreateBranchDefinition,
|
|
200
199
|
githubCreatePullRequestDefinition,
|
|
201
200
|
githubListPullRequestsDefinition,
|
|
202
|
-
githubGetFileContentDefinition,
|
|
203
|
-
githubListDirectoryDefinition,
|
|
204
201
|
],
|
|
205
202
|
},
|
|
206
203
|
ASHBY: {
|
|
@@ -0,0 +1,36 @@
|
|
|
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 sdk_1 = require("@credal/sdk");
|
|
13
|
+
const callCopilot = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
14
|
+
var _b;
|
|
15
|
+
const requestBody = {
|
|
16
|
+
agentId: params.agentId,
|
|
17
|
+
query: params.query,
|
|
18
|
+
userEmail: params.userEmail,
|
|
19
|
+
};
|
|
20
|
+
const baseUrl = (_b = authParams.baseUrl) !== null && _b !== void 0 ? _b : "https://app.credal.ai/api";
|
|
21
|
+
const client = new sdk_1.CredalClient({ environment: baseUrl, apiKey: authParams.apiKey });
|
|
22
|
+
const response = yield client.copilots.sendMessage({
|
|
23
|
+
agentId: requestBody.agentId,
|
|
24
|
+
message: requestBody.query,
|
|
25
|
+
userEmail: requestBody.userEmail,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
response: response.sendChatResult.type === "ai_response_result"
|
|
29
|
+
? response.sendChatResult.response.message
|
|
30
|
+
: "Error getting response",
|
|
31
|
+
referencedSources: response.sendChatResult.type === "ai_response_result" ? response.sendChatResult.referencedSources : [],
|
|
32
|
+
sourcesInDataContext: response.sendChatResult.type === "ai_response_result" ? response.sendChatResult.sourcesInDataContext : [],
|
|
33
|
+
webSearchResults: response.sendChatResult.type === "ai_response_result" ? response.sendChatResult.webSearchResults : [],
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
exports.default = callCopilot;
|
|
@@ -9,6 +9,99 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { axiosClient } from "../../util/axiosClient.js";
|
|
11
11
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
12
|
+
/**
|
|
13
|
+
* Parses HTML content and converts it to Google Docs API batch update requests
|
|
14
|
+
*/
|
|
15
|
+
function parseHtmlToDocRequests(htmlContent) {
|
|
16
|
+
const requests = [];
|
|
17
|
+
let currentIndex = 1;
|
|
18
|
+
// Strip HTML tags and extract text with basic formatting
|
|
19
|
+
const textWithFormatting = parseHtmlContent(htmlContent);
|
|
20
|
+
for (const item of textWithFormatting) {
|
|
21
|
+
// Insert text
|
|
22
|
+
requests.push({
|
|
23
|
+
insertText: {
|
|
24
|
+
location: { index: currentIndex },
|
|
25
|
+
text: item.text,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
// Apply formatting if present
|
|
29
|
+
if (item.formatting && Object.keys(item.formatting).length > 0) {
|
|
30
|
+
const endIndex = currentIndex + item.text.length;
|
|
31
|
+
requests.push({
|
|
32
|
+
updateTextStyle: {
|
|
33
|
+
range: { startIndex: currentIndex, endIndex },
|
|
34
|
+
textStyle: item.formatting,
|
|
35
|
+
fields: Object.keys(item.formatting).join(","),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
currentIndex += item.text.length;
|
|
40
|
+
}
|
|
41
|
+
return requests;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Basic HTML parser that extracts text and formatting
|
|
45
|
+
*/
|
|
46
|
+
function parseHtmlContent(html) {
|
|
47
|
+
var _a;
|
|
48
|
+
const result = [];
|
|
49
|
+
// Handle line breaks
|
|
50
|
+
html = html.replace(/<br\s*\/?>/gi, "\n");
|
|
51
|
+
html = html.replace(/<\/p>/gi, "\n");
|
|
52
|
+
html = html.replace(/<p[^>]*>/gi, "");
|
|
53
|
+
// Simple regex-based parsing for basic HTML tags
|
|
54
|
+
const segments = html.split(/(<[^>]+>)/);
|
|
55
|
+
const currentFormatting = {};
|
|
56
|
+
for (let i = 0; i < segments.length; i++) {
|
|
57
|
+
const segment = segments[i];
|
|
58
|
+
if (segment.startsWith("<")) {
|
|
59
|
+
// This is an HTML tag
|
|
60
|
+
if (segment.match(/<\s*b\s*>/i) || segment.match(/<\s*strong\s*>/i)) {
|
|
61
|
+
currentFormatting.bold = true;
|
|
62
|
+
}
|
|
63
|
+
else if (segment.match(/<\/\s*b\s*>/i) || segment.match(/<\/\s*strong\s*>/i)) {
|
|
64
|
+
delete currentFormatting.bold;
|
|
65
|
+
}
|
|
66
|
+
else if (segment.match(/<\s*i\s*>/i) || segment.match(/<\s*em\s*>/i)) {
|
|
67
|
+
currentFormatting.italic = true;
|
|
68
|
+
}
|
|
69
|
+
else if (segment.match(/<\/\s*i\s*>/i) || segment.match(/<\/\s*em\s*>/i)) {
|
|
70
|
+
delete currentFormatting.italic;
|
|
71
|
+
}
|
|
72
|
+
else if (segment.match(/<\s*u\s*>/i)) {
|
|
73
|
+
currentFormatting.underline = true;
|
|
74
|
+
}
|
|
75
|
+
else if (segment.match(/<\/\s*u\s*>/i)) {
|
|
76
|
+
delete currentFormatting.underline;
|
|
77
|
+
}
|
|
78
|
+
else if (segment.match(/<\s*h[1-6]\s*>/i)) {
|
|
79
|
+
const headingLevel = (_a = segment.match(/<\s*h([1-6])\s*>/i)) === null || _a === void 0 ? void 0 : _a[1];
|
|
80
|
+
currentFormatting.fontSize = { magnitude: 18 - (parseInt(headingLevel || "1") - 1) * 2, unit: "PT" };
|
|
81
|
+
currentFormatting.bold = true;
|
|
82
|
+
}
|
|
83
|
+
else if (segment.match(/<\/\s*h[1-6]\s*>/i)) {
|
|
84
|
+
delete currentFormatting.fontSize;
|
|
85
|
+
delete currentFormatting.bold;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (segment.trim()) {
|
|
89
|
+
// This is text content
|
|
90
|
+
result.push({
|
|
91
|
+
text: segment,
|
|
92
|
+
formatting: Object.keys(currentFormatting).length > 0 ? Object.assign({}, currentFormatting) : undefined,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// If no formatted content was found, return the plain text
|
|
97
|
+
if (result.length === 0) {
|
|
98
|
+
const plainText = html.replace(/<[^>]*>/g, "");
|
|
99
|
+
if (plainText.trim()) {
|
|
100
|
+
result.push({ text: plainText });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
12
105
|
/**
|
|
13
106
|
* Creates a new Google Doc document using OAuth authentication
|
|
14
107
|
*/
|
|
@@ -16,7 +109,7 @@ const createNewGoogleDoc = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
16
109
|
if (!authParams.authToken) {
|
|
17
110
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
18
111
|
}
|
|
19
|
-
const { title, content } = params;
|
|
112
|
+
const { title, content, usesHtml } = params;
|
|
20
113
|
const baseApiUrl = "https://docs.googleapis.com/v1/documents";
|
|
21
114
|
// Create the document with the provided title
|
|
22
115
|
const response = yield axiosClient.post(baseApiUrl, { title }, {
|
|
@@ -28,24 +121,36 @@ const createNewGoogleDoc = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
28
121
|
// If content is provided, update the document body with the content
|
|
29
122
|
if (content) {
|
|
30
123
|
const documentId = response.data.documentId;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
requests
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
124
|
+
if (usesHtml) {
|
|
125
|
+
// Parse HTML content and create requests for rich text formatting
|
|
126
|
+
const requests = parseHtmlToDocRequests(content);
|
|
127
|
+
yield axiosClient.post(`${baseApiUrl}/${documentId}:batchUpdate`, { requests }, {
|
|
128
|
+
headers: {
|
|
129
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Add plain text content to the document
|
|
136
|
+
yield axiosClient.post(`${baseApiUrl}/${documentId}:batchUpdate`, {
|
|
137
|
+
requests: [
|
|
138
|
+
{
|
|
139
|
+
insertText: {
|
|
140
|
+
location: {
|
|
141
|
+
index: 1, // Insert at the beginning of the document
|
|
142
|
+
},
|
|
143
|
+
text: content,
|
|
38
144
|
},
|
|
39
|
-
text: content,
|
|
40
145
|
},
|
|
146
|
+
],
|
|
147
|
+
}, {
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
150
|
+
"Content-Type": "application/json",
|
|
41
151
|
},
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
headers: {
|
|
45
|
-
Authorization: `Bearer ${authParams.authToken}`,
|
|
46
|
-
"Content-Type": "application/json",
|
|
47
|
-
},
|
|
48
|
-
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
49
154
|
}
|
|
50
155
|
return {
|
|
51
156
|
documentId: response.data.documentId,
|
|
@@ -19,7 +19,7 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
19
19
|
}
|
|
20
20
|
const BASE_URL = "https://www.googleapis.com/drive/v3/files/";
|
|
21
21
|
const headers = { Authorization: `Bearer ${authParams.authToken}` };
|
|
22
|
-
const { limit } = params;
|
|
22
|
+
const { limit: charLimit, fileId } = params;
|
|
23
23
|
const timeoutLimit = params.timeoutLimit !== undefined && params.timeoutLimit > 0 ? params.timeoutLimit * 1000 : 15000;
|
|
24
24
|
const axiosClient = createAxiosClientWithTimeout(timeoutLimit);
|
|
25
25
|
// helper to fetch drive metadata with fields we need (incl. shortcut details)
|
|
@@ -33,7 +33,7 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
33
33
|
});
|
|
34
34
|
try {
|
|
35
35
|
// 1) metadata (possibly a shortcut)
|
|
36
|
-
let meta = yield fetchMeta(
|
|
36
|
+
let meta = yield fetchMeta(fileId);
|
|
37
37
|
// 2) resolve shortcut transparently (re-point to target id + mime)
|
|
38
38
|
if (meta.mimeType === "application/vnd.google-apps.shortcut" && ((_b = meta.shortcutDetails) === null || _b === void 0 ? void 0 : _b.targetId)) {
|
|
39
39
|
meta = yield fetchMeta(meta.shortcutDetails.targetId);
|
|
@@ -111,8 +111,9 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
111
111
|
.replace(/\r?\n+/g, " ")
|
|
112
112
|
.replace(/ +/g, " ");
|
|
113
113
|
const originalLength = content.length;
|
|
114
|
-
if (
|
|
115
|
-
|
|
114
|
+
if (charLimit && content.length > charLimit) {
|
|
115
|
+
// TODO in the future do this around the most valuable snippet of the doc?
|
|
116
|
+
content = content.slice(0, charLimit);
|
|
116
117
|
}
|
|
117
118
|
return { success: true, content, fileName, fileLength: originalLength };
|
|
118
119
|
}
|
|
@@ -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("./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;
|
|
@@ -15,7 +15,7 @@ const searchDriveByKeywordsAndGetFileContent = (_a) => __awaiter(void 0, [_a], v
|
|
|
15
15
|
if (!authParams.authToken) {
|
|
16
16
|
return { success: false, error: MISSING_AUTH_TOKEN, files: [] };
|
|
17
17
|
}
|
|
18
|
-
const { searchQuery, limit, searchDriveByDrive, orderByQuery, fileSizeLimit } = params;
|
|
18
|
+
const { searchQuery, limit, searchDriveByDrive, orderByQuery, fileSizeLimit: maxChars } = params;
|
|
19
19
|
// First, perform the search
|
|
20
20
|
const query = searchQuery
|
|
21
21
|
.split(" ")
|
|
@@ -35,7 +35,7 @@ const searchDriveByKeywordsAndGetFileContent = (_a) => __awaiter(void 0, [_a], v
|
|
|
35
35
|
const contentPromises = files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
36
|
try {
|
|
37
37
|
const contentResult = yield getDriveFileContentById({
|
|
38
|
-
params: { fileId: file.id, limit:
|
|
38
|
+
params: { fileId: file.id, limit: maxChars },
|
|
39
39
|
authParams,
|
|
40
40
|
});
|
|
41
41
|
return {
|
|
@@ -15,7 +15,7 @@ const searchDriveByQueryAndGetFileContent = (_a) => __awaiter(void 0, [_a], void
|
|
|
15
15
|
if (!authParams.authToken) {
|
|
16
16
|
return { success: false, error: MISSING_AUTH_TOKEN, files: [] };
|
|
17
17
|
}
|
|
18
|
-
const { query, limit, searchDriveByDrive, orderByQuery, fileSizeLimit } = params;
|
|
18
|
+
const { query, limit, searchDriveByDrive, orderByQuery, fileSizeLimit: maxChars } = params;
|
|
19
19
|
// First, perform the search
|
|
20
20
|
const searchResult = yield searchDriveByQuery({
|
|
21
21
|
params: { query, limit, searchDriveByDrive, orderByQuery },
|
|
@@ -30,7 +30,7 @@ const searchDriveByQueryAndGetFileContent = (_a) => __awaiter(void 0, [_a], void
|
|
|
30
30
|
const contentPromises = files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
31
|
try {
|
|
32
32
|
const contentResult = yield getDriveFileContentById({
|
|
33
|
-
params: { fileId: file.id, limit:
|
|
33
|
+
params: { fileId: file.id, limit: maxChars },
|
|
34
34
|
authParams,
|
|
35
35
|
});
|
|
36
36
|
return {
|
|
@@ -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("./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;
|
|
@@ -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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const axiosClient_1 = require("../../util/axiosClient");
|
|
13
|
+
const getComputerInventory = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
14
|
+
const { authToken, baseUrl } = authParams;
|
|
15
|
+
const { section } = params;
|
|
16
|
+
if (!baseUrl) {
|
|
17
|
+
throw new Error("Base URL is required to fetch computer inventory");
|
|
18
|
+
}
|
|
19
|
+
const apiUrl = `${baseUrl}/v1/computer-inventory`;
|
|
20
|
+
const queryParams = {};
|
|
21
|
+
if (section) {
|
|
22
|
+
queryParams.section = section;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const response = yield axiosClient_1.axiosClient.get(apiUrl, {
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${authToken}`,
|
|
28
|
+
Accept: "application/json",
|
|
29
|
+
},
|
|
30
|
+
params: queryParams,
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
success: true,
|
|
34
|
+
data: response.data,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("Error retrieving computer inventory: ", error);
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
exports.default = getComputerInventory;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 getFileVaultRecoveryKey = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
14
|
+
const { authToken, baseUrl } = authParams;
|
|
15
|
+
const { computerId } = params;
|
|
16
|
+
if (!baseUrl || !computerId) {
|
|
17
|
+
throw new Error("Base URL and Computer ID are required to fetch FileVault2 recovery key");
|
|
18
|
+
}
|
|
19
|
+
const apiUrl = `${baseUrl}/JSSResource/computers/${computerId}/FileVault2RecoveryKey`;
|
|
20
|
+
try {
|
|
21
|
+
const response = yield axiosClient_1.axiosClient.get(apiUrl, {
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: `Bearer ${authToken}`,
|
|
24
|
+
Accept: "application/json",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
data: response.data,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error("Error retrieving FileVault2 recovery key: ", error);
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.default = getFileVaultRecoveryKey;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { axiosClient } from "../../util/axiosClient.js";
|
|
11
|
+
const restartJamfComputerById = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
12
|
+
const { authToken, subdomain } = authParams;
|
|
13
|
+
const { computerId } = params;
|
|
14
|
+
if (!subdomain || !authToken) {
|
|
15
|
+
throw new Error("Instance and authToken are required to fetch Jamf user computer ID");
|
|
16
|
+
}
|
|
17
|
+
const url = `https://${subdomain}.jamfcloud.com`;
|
|
18
|
+
try {
|
|
19
|
+
yield axiosClient.post(`${url}/api/command/v1/computers/${computerId}/restart`, {
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${authToken}`,
|
|
22
|
+
Accept: "application/json",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
success: true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error("Error restarting Jamf computer: ", error);
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export default restartJamfComputerById;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as add from "./add";
|
|
@@ -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.add = void 0;
|
|
37
|
+
exports.add = __importStar(require("./add"));
|
|
@@ -11,7 +11,7 @@ import { ApiError, axiosClient } from "../../util/axiosClient.js";
|
|
|
11
11
|
const searchSalesforceRecords = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
12
12
|
const { authToken, baseUrl } = authParams;
|
|
13
13
|
const { keyword, recordType, fieldsToSearch } = params;
|
|
14
|
-
const searchFields = Array.from(new Set([...fieldsToSearch, "Id"]));
|
|
14
|
+
const searchFields = Array.from(new Set([...fieldsToSearch, "Id", "CaseNumber"]));
|
|
15
15
|
if (!authToken || !baseUrl) {
|
|
16
16
|
return {
|
|
17
17
|
success: false,
|
|
@@ -11,19 +11,23 @@ import { WebClient } from "@slack/web-api";
|
|
|
11
11
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
12
12
|
import { getSlackChannels } from "./helpers.js";
|
|
13
13
|
const archiveChannel = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
14
|
+
var _b;
|
|
14
15
|
if (!authParams.authToken) {
|
|
15
16
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
16
17
|
}
|
|
17
18
|
try {
|
|
18
19
|
const client = new WebClient(authParams.authToken);
|
|
19
|
-
const { channelName } = params;
|
|
20
|
+
const { channelId: inputChannelId, channelName } = params;
|
|
21
|
+
if (!inputChannelId && !channelName) {
|
|
22
|
+
throw Error("Either channelId or channelName must be provided");
|
|
23
|
+
}
|
|
20
24
|
const allChannels = yield getSlackChannels(client);
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
25
|
+
const channelId = inputChannelId !== null && inputChannelId !== void 0 ? inputChannelId : (_b = allChannels.find(channel => channel.name == channelName)) === null || _b === void 0 ? void 0 : _b.id;
|
|
26
|
+
if (!channelId) {
|
|
23
27
|
throw Error(`Channel with name ${channelName} not found`);
|
|
24
28
|
}
|
|
25
|
-
yield client.conversations.join({ channel:
|
|
26
|
-
const result = yield client.conversations.archive({ channel:
|
|
29
|
+
yield client.conversations.join({ channel: channelId });
|
|
30
|
+
const result = yield client.conversations.archive({ channel: channelId });
|
|
27
31
|
if (!result.ok) {
|
|
28
32
|
return {
|
|
29
33
|
success: false,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as listConversations from "./listConversations";
|
|
@@ -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,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;
|
package/package.json
CHANGED
|
@@ -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,41 +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 commitResults = yield octokit.rest.repos.getCommit({ owner: organization, repo: repository, ref: sha });
|
|
35
|
-
return {
|
|
36
|
-
code: codeResults,
|
|
37
|
-
commits: enrichedCommits,
|
|
38
|
-
issuesAndPullRequests: issuesAndPRs,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
export default searchRepository;
|