@credal/actions 0.2.23 → 0.2.25

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.
@@ -850,7 +850,7 @@ export const jiraCreateJiraTicketDefinition = {
850
850
  },
851
851
  issueType: {
852
852
  type: "string",
853
- description: "The issue type of the new ticket",
853
+ description: "The issue type of the new ticket. Should be Epic, Story, Task, Bug, Sub-task, etc.",
854
854
  },
855
855
  reporter: {
856
856
  type: "string",
@@ -3413,6 +3413,14 @@ export const googleOauthListCalendarEventsDefinition = {
3413
3413
  type: "integer",
3414
3414
  description: "Maximum number of events to return, defaults to 250",
3415
3415
  },
3416
+ timeMin: {
3417
+ type: "string",
3418
+ description: "Optional lower bound (exclusive) for an event's end time to filter by. Must be an RFC3339 timestamp with mandatory time zone offset, for example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z.",
3419
+ },
3420
+ timeMax: {
3421
+ type: "string",
3422
+ description: "Optional upper bound (exclusive) for an event's start time to filter by. Must be an RFC3339 timestamp with mandatory time zone offset, for example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z.",
3423
+ },
3416
3424
  },
3417
3425
  },
3418
3426
  output: {
@@ -2132,14 +2132,20 @@ export declare const googleOauthListCalendarEventsParamsSchema: z.ZodObject<{
2132
2132
  calendarId: z.ZodString;
2133
2133
  query: z.ZodOptional<z.ZodString>;
2134
2134
  maxResults: z.ZodOptional<z.ZodNumber>;
2135
+ timeMin: z.ZodOptional<z.ZodString>;
2136
+ timeMax: z.ZodOptional<z.ZodString>;
2135
2137
  }, "strip", z.ZodTypeAny, {
2136
2138
  calendarId: string;
2137
2139
  query?: string | undefined;
2138
2140
  maxResults?: number | undefined;
2141
+ timeMin?: string | undefined;
2142
+ timeMax?: string | undefined;
2139
2143
  }, {
2140
2144
  calendarId: string;
2141
2145
  query?: string | undefined;
2142
2146
  maxResults?: number | undefined;
2147
+ timeMin?: string | undefined;
2148
+ timeMax?: string | undefined;
2143
2149
  }>;
2144
2150
  export type googleOauthListCalendarEventsParamsType = z.infer<typeof googleOauthListCalendarEventsParamsSchema>;
2145
2151
  export declare const googleOauthListCalendarEventsOutputSchema: z.ZodObject<{
@@ -289,7 +289,7 @@ export const jiraCreateJiraTicketParamsSchema = z.object({
289
289
  projectKey: z.string().describe("The key for the project you want to add it to"),
290
290
  summary: z.string().describe("The summary of the new ticket"),
291
291
  description: z.string().describe("The description for the new ticket"),
292
- issueType: z.string().describe("The issue type of the new ticket"),
292
+ issueType: z.string().describe("The issue type of the new ticket. Should be Epic, Story, Task, Bug, Sub-task, etc."),
293
293
  reporter: z.string().describe("The reporter for the new ticket creation").optional(),
294
294
  assignee: z.string().describe("The assignee for the new ticket creation").optional(),
295
295
  customFields: z
@@ -1221,6 +1221,14 @@ export const googleOauthListCalendarEventsParamsSchema = z.object({
1221
1221
  calendarId: z.string().describe("The ID of the calendar to list events from"),
1222
1222
  query: z.string().describe("Optional free-text search query to filter events").optional(),
1223
1223
  maxResults: z.number().int().describe("Maximum number of events to return, defaults to 250").optional(),
1224
+ timeMin: z
1225
+ .string()
1226
+ .describe("Optional lower bound (exclusive) for an event's end time to filter by. Must be an RFC3339 timestamp with mandatory time zone offset, for example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z.")
1227
+ .optional(),
1228
+ timeMax: z
1229
+ .string()
1230
+ .describe("Optional upper bound (exclusive) for an event's start time to filter by. Must be an RFC3339 timestamp with mandatory time zone offset, for example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z.")
1231
+ .optional(),
1224
1232
  });
1225
1233
  export const googleOauthListCalendarEventsOutputSchema = z.object({
1226
1234
  success: z.boolean().describe("Whether the events were listed successfully"),
@@ -13,7 +13,7 @@ const listCalendarEvents = (_a) => __awaiter(void 0, [_a], void 0, function* ({
13
13
  if (!authParams.authToken) {
14
14
  return { success: false, error: MISSING_AUTH_TOKEN, events: [] };
15
15
  }
16
- const { calendarId, query, maxResults } = params;
16
+ const { calendarId, query, maxResults, timeMin, timeMax } = params;
17
17
  const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events`;
18
18
  const allEvents = [];
19
19
  let pageToken = undefined;
@@ -31,6 +31,8 @@ const listCalendarEvents = (_a) => __awaiter(void 0, [_a], void 0, function* ({
31
31
  maxResults: Math.min(250, max - fetchedCount), // Google API max is 250
32
32
  singleEvents: true,
33
33
  orderBy: "startTime",
34
+ timeMin,
35
+ timeMax,
34
36
  },
35
37
  });
36
38
  const { items = [], nextPageToken = undefined } = res.data;
@@ -0,0 +1,3 @@
1
+ import type { googleOauthListGmailThreadsFunction } from "../../autogen/types";
2
+ declare const listGmailThreads: googleOauthListGmailThreadsFunction;
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("./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 { googleOauthSearchGmailMessagesFunction } from "../../autogen/types";
2
+ declare const searchGmailMessages: googleOauthSearchGmailMessagesFunction;
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("./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,3 @@
1
+ import type { jamfGetComputerInventoryFunction } from "../../autogen/types";
2
+ declare const getComputerInventory: jamfGetComputerInventoryFunction;
3
+ export default getComputerInventory;
@@ -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,3 @@
1
+ import type { jamfGetFileVaultRecoveryKeyFunction } from "../../autogen/types";
2
+ declare const getFileVaultRecoveryKey: jamfGetFileVaultRecoveryKeyFunction;
3
+ export default getFileVaultRecoveryKey;
@@ -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,3 @@
1
+ import type { jamfRestartJamfComputerByIdFunction } from "../../autogen/types.js";
2
+ declare const restartJamfComputerById: jamfRestartJamfComputerByIdFunction;
3
+ export default restartJamfComputerById;
@@ -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;
@@ -7,8 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { AxiosError } from "axios";
11
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { ApiError, axiosClient } from "../../util/axiosClient.js";
12
11
  const triggerOktaWorkflow = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authParams, params, }) {
13
12
  var _b, _c;
14
13
  const { authToken, subdomain } = authParams;
@@ -21,7 +20,7 @@ const triggerOktaWorkflow = (_a) => __awaiter(void 0, [_a], void 0, function* ({
21
20
  headers: Object.assign({ Accept: "application/json", "Content-Type": "application/json" }, (authToken && { Authorization: `Bearer ${authToken}` })),
22
21
  };
23
22
  const workflowUrl = `https://${subdomain}.workflows.okta.com/api/flo/${workflowId}/invoke`;
24
- const response = yield axiosClient.post(workflowUrl, workflowParameters || {}, requestConfig);
23
+ const response = yield axiosClient.post(workflowUrl, workflowParameters !== null && workflowParameters !== void 0 ? workflowParameters : {}, requestConfig);
25
24
  if (response.status >= 200 && response.status < 300) {
26
25
  return { success: true, output: response.data };
27
26
  }
@@ -31,14 +30,10 @@ const triggerOktaWorkflow = (_a) => __awaiter(void 0, [_a], void 0, function* ({
31
30
  }
32
31
  }
33
32
  catch (error) {
34
- console.error("Error triggering Okta workflow:", error);
35
33
  let errorMessage = "Unknown error while triggering workflow";
36
- if (error instanceof AxiosError && error.response) {
37
- const workflowError = error.response.data;
38
- errorMessage =
39
- (workflowError === null || workflowError === void 0 ? void 0 : workflowError.errorSummary) ||
40
- (workflowError === null || workflowError === void 0 ? void 0 : workflowError.message) ||
41
- `Workflow request failed with status ${error.response.status}`;
34
+ if (error instanceof ApiError && error.data) {
35
+ const workflowError = error.data.error;
36
+ errorMessage = workflowError + ` Status: ${error.status}`;
42
37
  }
43
38
  else if (error instanceof Error) {
44
39
  errorMessage = error.message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -1,3 +0,0 @@
1
- import { confluenceUpdatePageFunction } from "../../../actions/autogen/types";
2
- declare const confluenceUpdatePage: confluenceUpdatePageFunction;
3
- export default confluenceUpdatePage;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- function getConfluenceApi(baseUrl, username, apiToken) {
17
- const api = axios_1.default.create({
18
- baseURL: baseUrl,
19
- headers: {
20
- Accept: "application/json",
21
- // Tokens are associated with a specific user.
22
- Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
23
- },
24
- });
25
- return api;
26
- }
27
- const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
28
- const { pageId, username, content, title } = params;
29
- const { baseUrl, authToken } = authParams;
30
- const api = getConfluenceApi(baseUrl, username, authToken);
31
- // Get current version number
32
- const response = yield api.get(`/api/v2/pages/${pageId}`);
33
- const currVersion = response.data.version.number;
34
- yield api.put(`/api/v2/pages/${pageId}`, {
35
- id: pageId,
36
- status: "current",
37
- title,
38
- body: {
39
- representation: "storage",
40
- value: content,
41
- },
42
- version: {
43
- number: currVersion + 1,
44
- },
45
- });
46
- });
47
- exports.default = confluenceUpdatePage;