@credal/actions 0.2.184 → 0.2.186
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/actionMapper.js +36 -1
- package/dist/actions/autogen/templates.d.ts +5 -0
- package/dist/actions/autogen/templates.js +281 -1
- package/dist/actions/autogen/types.d.ts +255 -33
- package/dist/actions/autogen/types.js +99 -0
- package/dist/actions/providers/google-oauth/deleteRowFromSpreadsheet.d.ts +7 -0
- package/dist/actions/providers/google-oauth/deleteRowFromSpreadsheet.js +56 -0
- package/dist/actions/providers/google-oauth/updateRowsInSpreadsheet.d.ts +7 -0
- package/dist/actions/providers/google-oauth/updateRowsInSpreadsheet.js +63 -0
- package/dist/actions/providers/salesforce/executeReport.d.ts +3 -0
- package/dist/actions/providers/salesforce/executeReport.js +36 -0
- package/dist/actions/providers/salesforce/getReportMetadata.d.ts +3 -0
- package/dist/actions/providers/salesforce/getReportMetadata.js +54 -0
- package/dist/actions/providers/salesforce/listReports.d.ts +3 -0
- package/dist/actions/providers/salesforce/listReports.js +36 -0
- package/dist/utils/google.js +76 -28
- package/package.json +3 -1
|
@@ -0,0 +1,36 @@
|
|
|
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 { ApiError, axiosClient } from "../../util/axiosClient.js";
|
|
11
|
+
const executeReport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
12
|
+
const { authToken, baseUrl } = authParams;
|
|
13
|
+
const { reportId, includeDetails } = params;
|
|
14
|
+
if (!authToken || !baseUrl) {
|
|
15
|
+
return { success: false, error: "authToken and baseUrl are required for Salesforce API" };
|
|
16
|
+
}
|
|
17
|
+
const url = `${baseUrl}/services/data/v65.0/analytics/reports/${reportId}${includeDetails ? "?includeDetails=true" : ""}`;
|
|
18
|
+
try {
|
|
19
|
+
yield axiosClient.get(url, { headers: { Authorization: `Bearer ${authToken}` } });
|
|
20
|
+
return {
|
|
21
|
+
success: true,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error("Error executing Salesforce report:", error);
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: error instanceof ApiError
|
|
29
|
+
? Array.isArray(error.data) && error.data.length > 0
|
|
30
|
+
? error.data[0].message
|
|
31
|
+
: error.message
|
|
32
|
+
: "An unknown error occurred",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export default executeReport;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { ApiError, axiosClient } from "../../util/axiosClient.js";
|
|
11
|
+
const getReportMetadata = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
12
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
13
|
+
const { authToken, baseUrl } = authParams;
|
|
14
|
+
const { reportId } = params;
|
|
15
|
+
if (!authToken || !baseUrl) {
|
|
16
|
+
return { success: false, error: "authToken and baseUrl are required for Salesforce API" };
|
|
17
|
+
}
|
|
18
|
+
const url = `${baseUrl}/services/data/v65.0/analytics/reports/${reportId}/describe`;
|
|
19
|
+
try {
|
|
20
|
+
const response = yield axiosClient.get(url, { headers: { Authorization: `Bearer ${authToken}` } });
|
|
21
|
+
const fullMetadata = response.data;
|
|
22
|
+
const filteredMetadata = {
|
|
23
|
+
reportType: ((_b = fullMetadata.reportMetadata) === null || _b === void 0 ? void 0 : _b.reportType)
|
|
24
|
+
? {
|
|
25
|
+
type: fullMetadata.reportMetadata.reportType.type,
|
|
26
|
+
label: fullMetadata.reportMetadata.reportType.label,
|
|
27
|
+
}
|
|
28
|
+
: undefined,
|
|
29
|
+
detailColumns: (_c = fullMetadata.reportMetadata) === null || _c === void 0 ? void 0 : _c.detailColumns,
|
|
30
|
+
reportFilters: (_d = fullMetadata.reportMetadata) === null || _d === void 0 ? void 0 : _d.reportFilters,
|
|
31
|
+
reportBooleanFilter: (_e = fullMetadata.reportMetadata) === null || _e === void 0 ? void 0 : _e.reportBooleanFilter,
|
|
32
|
+
standardDateFilter: (_f = fullMetadata.reportMetadata) === null || _f === void 0 ? void 0 : _f.standardDateFilter,
|
|
33
|
+
groupingsDown: (_g = fullMetadata.reportMetadata) === null || _g === void 0 ? void 0 : _g.groupingsDown,
|
|
34
|
+
groupingsAcross: (_h = fullMetadata.reportMetadata) === null || _h === void 0 ? void 0 : _h.groupingsAcross,
|
|
35
|
+
scope: (_j = fullMetadata.reportMetadata) === null || _j === void 0 ? void 0 : _j.scope,
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
metadata: filteredMetadata,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error("Error retrieving Salesforce report metadata:", error);
|
|
44
|
+
return {
|
|
45
|
+
success: false,
|
|
46
|
+
error: error instanceof ApiError
|
|
47
|
+
? Array.isArray(error.data) && error.data.length > 0
|
|
48
|
+
? error.data[0].message
|
|
49
|
+
: error.message
|
|
50
|
+
: "An unknown error occurred",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
export default getReportMetadata;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { ApiError, axiosClient } from "../../util/axiosClient.js";
|
|
11
|
+
const listReports = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authParams, }) {
|
|
12
|
+
const { authToken, baseUrl } = authParams;
|
|
13
|
+
if (!authToken || !baseUrl) {
|
|
14
|
+
return { success: false, error: "authToken and baseUrl are required for Salesforce API" };
|
|
15
|
+
}
|
|
16
|
+
const url = `${baseUrl}/services/data/v65.0/analytics/reports`;
|
|
17
|
+
try {
|
|
18
|
+
const response = yield axiosClient.get(url, { headers: { Authorization: `Bearer ${authToken}` } });
|
|
19
|
+
return {
|
|
20
|
+
success: true,
|
|
21
|
+
reports: response.data,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error("Error listing Salesforce reports:", error);
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: error instanceof ApiError
|
|
29
|
+
? Array.isArray(error.data) && error.data.length > 0
|
|
30
|
+
? error.data[0].message
|
|
31
|
+
: error.message
|
|
32
|
+
: "An unknown error occurred",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export default listReports;
|
package/dist/utils/google.js
CHANGED
|
@@ -7,6 +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 Papa from "papaparse";
|
|
10
11
|
import { isAxiosTimeoutError } from "../actions/util/axiosClient.js";
|
|
11
12
|
// Helper function to parse Google Docs content to plain text
|
|
12
13
|
export function parseGoogleDocFromRawContentToPlainText(snapshotRawContent) {
|
|
@@ -113,46 +114,91 @@ export function parseGoogleDocFromRawContentToPlainText(snapshotRawContent) {
|
|
|
113
114
|
const validDocSections = docSections.filter(section => section.heading || section.paragraphs.length > 0);
|
|
114
115
|
return validDocSections.map(section => section.paragraphs.join(" ")).join("\n");
|
|
115
116
|
}
|
|
117
|
+
// Helper to convert 0-based column index to Excel-style column letter (0 -> "A", 25 -> "Z", 26 -> "AA")
|
|
118
|
+
function columnIndexToLetter(index) {
|
|
119
|
+
let letter = "";
|
|
120
|
+
while (index >= 0) {
|
|
121
|
+
letter = String.fromCharCode((index % 26) + 65) + letter;
|
|
122
|
+
index = Math.floor(index / 26) - 1;
|
|
123
|
+
}
|
|
124
|
+
return letter;
|
|
125
|
+
}
|
|
126
|
+
// Helper to parse CSV string into the JSON sheet format
|
|
127
|
+
function parseCSVToSheetJson(csvData, sheetName = "Sheet1") {
|
|
128
|
+
const headers = [];
|
|
129
|
+
const rows = [];
|
|
130
|
+
const parsed = Papa.parse(csvData, {
|
|
131
|
+
skipEmptyLines: true,
|
|
132
|
+
});
|
|
133
|
+
parsed.data.forEach((values, rowIndex) => {
|
|
134
|
+
values.forEach((value, colIndex) => {
|
|
135
|
+
const column = columnIndexToLetter(colIndex);
|
|
136
|
+
if (rowIndex === 0) {
|
|
137
|
+
// Headers: keep all cells (including empty) to preserve column positions
|
|
138
|
+
headers.push({ column, header: value.trim() });
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// Rows: skip empty or whitespace-only cells
|
|
142
|
+
const trimmedValue = value.trim();
|
|
143
|
+
if (!trimmedValue)
|
|
144
|
+
return;
|
|
145
|
+
rows.push({ column, row: rowIndex + 1, value: trimmedValue });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
return JSON.stringify([{ sheetName, headers, rows }]);
|
|
150
|
+
}
|
|
116
151
|
export function parseGoogleSheetsFromRawContentToPlainText(snapshotRawContent) {
|
|
117
152
|
var _a;
|
|
118
153
|
if (!snapshotRawContent.sheets)
|
|
119
|
-
return "";
|
|
120
|
-
const
|
|
154
|
+
return "[]";
|
|
155
|
+
const sheetsData = [];
|
|
121
156
|
for (const sheet of snapshotRawContent.sheets) {
|
|
122
157
|
if (!sheet.data || !((_a = sheet.properties) === null || _a === void 0 ? void 0 : _a.title))
|
|
123
158
|
continue;
|
|
124
|
-
const
|
|
125
|
-
const
|
|
159
|
+
const sheetName = sheet.properties.title;
|
|
160
|
+
const headers = [];
|
|
161
|
+
const rows = [];
|
|
162
|
+
// Helper to extract cell value
|
|
163
|
+
const getCellValue = (cell) => {
|
|
164
|
+
var _a, _b, _c;
|
|
165
|
+
if (cell.formattedValue)
|
|
166
|
+
return cell.formattedValue;
|
|
167
|
+
if ((_a = cell.userEnteredValue) === null || _a === void 0 ? void 0 : _a.stringValue)
|
|
168
|
+
return cell.userEnteredValue.stringValue;
|
|
169
|
+
if (((_b = cell.userEnteredValue) === null || _b === void 0 ? void 0 : _b.numberValue) !== undefined)
|
|
170
|
+
return cell.userEnteredValue.numberValue.toString();
|
|
171
|
+
if (((_c = cell.userEnteredValue) === null || _c === void 0 ? void 0 : _c.boolValue) !== undefined)
|
|
172
|
+
return cell.userEnteredValue.boolValue.toString();
|
|
173
|
+
return "";
|
|
174
|
+
};
|
|
126
175
|
for (const gridData of sheet.data) {
|
|
127
176
|
if (!gridData.rowData)
|
|
128
177
|
continue;
|
|
129
|
-
|
|
178
|
+
gridData.rowData.forEach((rowData, rowIndex) => {
|
|
130
179
|
if (!rowData.values)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
sheetRows.push(cellValues.join(" | "));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
180
|
+
return;
|
|
181
|
+
rowData.values.forEach((cell, colIndex) => {
|
|
182
|
+
const column = columnIndexToLetter(colIndex);
|
|
183
|
+
const value = getCellValue(cell).trim();
|
|
184
|
+
if (rowIndex === 0) {
|
|
185
|
+
// Headers: keep all cells (including empty) to preserve column positions
|
|
186
|
+
headers.push({ column, header: value });
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
// Rows: skip empty or whitespace-only cells
|
|
190
|
+
if (!value)
|
|
191
|
+
return;
|
|
192
|
+
rows.push({ column, row: rowIndex + 1, value });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
150
196
|
}
|
|
151
|
-
if (
|
|
152
|
-
|
|
197
|
+
if (headers.length > 0 || rows.length > 0) {
|
|
198
|
+
sheetsData.push({ sheetName, headers, rows });
|
|
153
199
|
}
|
|
154
200
|
}
|
|
155
|
-
return
|
|
201
|
+
return JSON.stringify(sheetsData);
|
|
156
202
|
}
|
|
157
203
|
export function parseGoogleSlidesFromRawContentToPlainText(snapshotRawContent) {
|
|
158
204
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -297,11 +343,13 @@ export function getGoogleSheetContent(fileId, authToken, axiosClient, sharedDriv
|
|
|
297
343
|
headers: { Authorization: `Bearer ${authToken}` },
|
|
298
344
|
responseType: "text",
|
|
299
345
|
});
|
|
300
|
-
|
|
346
|
+
// Clean up trailing commas and convert to JSON format
|
|
347
|
+
const cleanedCsv = exportRes.data
|
|
301
348
|
.split("\n")
|
|
302
349
|
.map((line) => line.replace(/,+$/, ""))
|
|
303
350
|
.map((line) => line.replace(/,{2,}/g, ","))
|
|
304
351
|
.join("\n");
|
|
352
|
+
return parseCSVToSheetJson(cleanedCsv);
|
|
305
353
|
}
|
|
306
354
|
catch (exportError) {
|
|
307
355
|
// Check if it's a 404 or permission error
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credal/actions",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.186",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI Actions by Credal AI",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@types/jsonwebtoken": "^9.0.9",
|
|
37
37
|
"@types/node": "^24.0.0",
|
|
38
38
|
"@types/node-forge": "^1.3.11",
|
|
39
|
+
"@types/papaparse": "^5.5.2",
|
|
39
40
|
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
|
40
41
|
"@typescript-eslint/parser": "^8.18.0",
|
|
41
42
|
"eslint": "^9.16.0",
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
"node-forge": "^1.3.3",
|
|
74
75
|
"officeparser": "^5.2.2",
|
|
75
76
|
"p-limit": "^7.1.1",
|
|
77
|
+
"papaparse": "^5.5.3",
|
|
76
78
|
"resend": "^4.7.0",
|
|
77
79
|
"snowflake-sdk": "^2.0.2",
|
|
78
80
|
"ts-node": "^10.9.2",
|