@credal/actions 0.1.24 → 0.1.26
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 +6 -0
- package/dist/actions/autogen/templates.d.ts +1 -0
- package/dist/actions/autogen/templates.js +52 -1
- package/dist/actions/autogen/types.d.ts +41 -0
- package/dist/actions/autogen/types.js +15 -1
- package/dist/actions/groups.js +3 -3
- package/dist/actions/parse.js +2 -0
- package/dist/actions/providers/confluence/updatePage.js +14 -15
- package/dist/actions/providers/googlemaps/nearbysearch.d.ts +3 -0
- package/dist/actions/providers/googlemaps/nearbysearch.js +96 -0
- package/dist/actions/providers/snowflake/runSnowflakeQuery.d.ts +3 -0
- package/dist/actions/providers/snowflake/runSnowflakeQuery.js +118 -0
- package/dist/actions/providers/snowflake/runSnowflakeQueryWriteResultsToS3.d.ts +3 -0
- package/dist/actions/providers/snowflake/runSnowflakeQueryWriteResultsToS3.js +154 -0
- package/dist/actions/providers/x/scrapeTweetDataWithNitter.d.ts +3 -0
- package/dist/actions/providers/x/scrapeTweetDataWithNitter.js +45 -0
- package/package.json +1 -1
- package/dist/actions/providers/workday/requestTimeOff.d.ts +0 -23
- package/dist/actions/providers/workday/requestTimeOff.js +0 -88
@@ -27,6 +27,7 @@ const symbolLookup_1 = __importDefault(require("./providers/finnhub/symbolLookup
|
|
27
27
|
const getBasicFinancials_1 = __importDefault(require("./providers/finnhub/getBasicFinancials"));
|
28
28
|
const overwritePage_1 = __importDefault(require("./providers/confluence/overwritePage"));
|
29
29
|
const fetchPageContent_1 = __importDefault(require("./providers/confluence/fetchPageContent"));
|
30
|
+
const runSnowflakeQuery_1 = __importDefault(require("./providers/snowflake/runSnowflakeQuery"));
|
30
31
|
exports.ActionMapper = {
|
31
32
|
math: {
|
32
33
|
add: {
|
@@ -98,6 +99,11 @@ exports.ActionMapper = {
|
|
98
99
|
paramsSchema: types_1.snowflakeGetRowByFieldValueParamsSchema,
|
99
100
|
outputSchema: types_1.snowflakeGetRowByFieldValueOutputSchema,
|
100
101
|
},
|
102
|
+
runSnowflakeQuery: {
|
103
|
+
fn: runSnowflakeQuery_1.default,
|
104
|
+
paramsSchema: types_1.snowflakeRunSnowflakeQueryParamsSchema,
|
105
|
+
outputSchema: types_1.snowflakeRunSnowflakeQueryOutputSchema,
|
106
|
+
},
|
101
107
|
},
|
102
108
|
linkedin: {
|
103
109
|
createShareLinkedinPostUrl: {
|
@@ -13,6 +13,7 @@ export declare const linkedinCreateShareLinkedinPostUrlDefinition: ActionTemplat
|
|
13
13
|
export declare const xCreateShareXPostUrlDefinition: ActionTemplate;
|
14
14
|
export declare const mongoInsertMongoDocDefinition: ActionTemplate;
|
15
15
|
export declare const snowflakeGetRowByFieldValueDefinition: ActionTemplate;
|
16
|
+
export declare const snowflakeRunSnowflakeQueryDefinition: ActionTemplate;
|
16
17
|
export declare const openstreetmapGetLatitudeLongitudeFromLocationDefinition: ActionTemplate;
|
17
18
|
export declare const nwsGetForecastForLocationDefinition: ActionTemplate;
|
18
19
|
export declare const firecrawlScrapeUrlDefinition: ActionTemplate;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.finnhubGetBasicFinancialsDefinition = exports.finnhubSymbolLookupDefinition = exports.googleOauthCreateNewGoogleDocDefinition = exports.resendSendEmailDefinition = exports.firecrawlScrapeTweetDataWithNitterDefinition = exports.firecrawlScrapeUrlDefinition = exports.nwsGetForecastForLocationDefinition = exports.openstreetmapGetLatitudeLongitudeFromLocationDefinition = exports.snowflakeGetRowByFieldValueDefinition = exports.mongoInsertMongoDocDefinition = exports.xCreateShareXPostUrlDefinition = exports.linkedinCreateShareLinkedinPostUrlDefinition = exports.zendeskCreateZendeskTicketDefinition = exports.credalCallCopilotDefinition = exports.googlemapsNearbysearchRestaurantsDefinition = exports.googlemapsValidateAddressDefinition = exports.jiraCreateJiraTicketDefinition = exports.confluenceFetchPageContentDefinition = exports.confluenceOverwritePageDefinition = exports.mathAddDefinition = exports.slackListConversationsDefinition = exports.slackSendMessageDefinition = void 0;
|
3
|
+
exports.finnhubGetBasicFinancialsDefinition = exports.finnhubSymbolLookupDefinition = exports.googleOauthCreateNewGoogleDocDefinition = exports.resendSendEmailDefinition = exports.firecrawlScrapeTweetDataWithNitterDefinition = exports.firecrawlScrapeUrlDefinition = exports.nwsGetForecastForLocationDefinition = exports.openstreetmapGetLatitudeLongitudeFromLocationDefinition = exports.snowflakeRunSnowflakeQueryDefinition = exports.snowflakeGetRowByFieldValueDefinition = exports.mongoInsertMongoDocDefinition = exports.xCreateShareXPostUrlDefinition = exports.linkedinCreateShareLinkedinPostUrlDefinition = exports.zendeskCreateZendeskTicketDefinition = exports.credalCallCopilotDefinition = exports.googlemapsNearbysearchRestaurantsDefinition = exports.googlemapsValidateAddressDefinition = exports.jiraCreateJiraTicketDefinition = exports.confluenceFetchPageContentDefinition = exports.confluenceOverwritePageDefinition = exports.mathAddDefinition = exports.slackListConversationsDefinition = exports.slackSendMessageDefinition = void 0;
|
4
4
|
exports.slackSendMessageDefinition = {
|
5
5
|
description: "Sends a message to a Slack channel",
|
6
6
|
scopes: ["chat:write"],
|
@@ -773,6 +773,57 @@ exports.snowflakeGetRowByFieldValueDefinition = {
|
|
773
773
|
name: "getRowByFieldValue",
|
774
774
|
provider: "snowflake",
|
775
775
|
};
|
776
|
+
exports.snowflakeRunSnowflakeQueryDefinition = {
|
777
|
+
description: "Execute a Snowflake query and return output.",
|
778
|
+
scopes: [],
|
779
|
+
parameters: {
|
780
|
+
type: "object",
|
781
|
+
required: ["databaseName", "warehouse", "query", "user", "accountName"],
|
782
|
+
properties: {
|
783
|
+
databaseName: {
|
784
|
+
type: "string",
|
785
|
+
description: "The name of the database to query",
|
786
|
+
},
|
787
|
+
warehouse: {
|
788
|
+
type: "string",
|
789
|
+
description: "The warehouse to use for executing the query",
|
790
|
+
},
|
791
|
+
query: {
|
792
|
+
type: "string",
|
793
|
+
description: "The SQL query to execute",
|
794
|
+
},
|
795
|
+
user: {
|
796
|
+
type: "string",
|
797
|
+
description: "The username to authenticate with",
|
798
|
+
},
|
799
|
+
accountName: {
|
800
|
+
type: "string",
|
801
|
+
description: "The name of the Snowflake account",
|
802
|
+
},
|
803
|
+
outputFormat: {
|
804
|
+
type: "string",
|
805
|
+
description: "The format of the output",
|
806
|
+
enum: ["json", "csv"],
|
807
|
+
},
|
808
|
+
},
|
809
|
+
},
|
810
|
+
output: {
|
811
|
+
type: "object",
|
812
|
+
required: ["content", "rowCount"],
|
813
|
+
properties: {
|
814
|
+
content: {
|
815
|
+
type: "string",
|
816
|
+
description: "The content of the query result (json)",
|
817
|
+
},
|
818
|
+
rowCount: {
|
819
|
+
type: "number",
|
820
|
+
description: "The number of rows returned by the query",
|
821
|
+
},
|
822
|
+
},
|
823
|
+
},
|
824
|
+
name: "runSnowflakeQuery",
|
825
|
+
provider: "snowflake",
|
826
|
+
};
|
776
827
|
exports.openstreetmapGetLatitudeLongitudeFromLocationDefinition = {
|
777
828
|
description: "Get the latitude and longitude of a location",
|
778
829
|
scopes: [],
|
@@ -13,6 +13,8 @@ export declare const AuthParamsSchema: z.ZodObject<{
|
|
13
13
|
emailReplyTo: z.ZodOptional<z.ZodString>;
|
14
14
|
emailBcc: z.ZodOptional<z.ZodString>;
|
15
15
|
cloudId: z.ZodOptional<z.ZodString>;
|
16
|
+
awsAccessKeyId: z.ZodOptional<z.ZodString>;
|
17
|
+
awsSecretAccessKey: z.ZodOptional<z.ZodString>;
|
16
18
|
}, "strip", z.ZodTypeAny, {
|
17
19
|
authToken?: string | undefined;
|
18
20
|
baseUrl?: string | undefined;
|
@@ -23,6 +25,8 @@ export declare const AuthParamsSchema: z.ZodObject<{
|
|
23
25
|
emailReplyTo?: string | undefined;
|
24
26
|
emailBcc?: string | undefined;
|
25
27
|
cloudId?: string | undefined;
|
28
|
+
awsAccessKeyId?: string | undefined;
|
29
|
+
awsSecretAccessKey?: string | undefined;
|
26
30
|
}, {
|
27
31
|
authToken?: string | undefined;
|
28
32
|
baseUrl?: string | undefined;
|
@@ -33,6 +37,8 @@ export declare const AuthParamsSchema: z.ZodObject<{
|
|
33
37
|
emailReplyTo?: string | undefined;
|
34
38
|
emailBcc?: string | undefined;
|
35
39
|
cloudId?: string | undefined;
|
40
|
+
awsAccessKeyId?: string | undefined;
|
41
|
+
awsSecretAccessKey?: string | undefined;
|
36
42
|
}>;
|
37
43
|
export type AuthParamsType = z.infer<typeof AuthParamsSchema>;
|
38
44
|
export declare const slackSendMessageParamsSchema: z.ZodObject<{
|
@@ -763,6 +769,41 @@ export declare const snowflakeGetRowByFieldValueOutputSchema: z.ZodObject<{
|
|
763
769
|
}>;
|
764
770
|
export type snowflakeGetRowByFieldValueOutputType = z.infer<typeof snowflakeGetRowByFieldValueOutputSchema>;
|
765
771
|
export type snowflakeGetRowByFieldValueFunction = ActionFunction<snowflakeGetRowByFieldValueParamsType, AuthParamsType, snowflakeGetRowByFieldValueOutputType>;
|
772
|
+
export declare const snowflakeRunSnowflakeQueryParamsSchema: z.ZodObject<{
|
773
|
+
databaseName: z.ZodString;
|
774
|
+
warehouse: z.ZodString;
|
775
|
+
query: z.ZodString;
|
776
|
+
user: z.ZodString;
|
777
|
+
accountName: z.ZodString;
|
778
|
+
outputFormat: z.ZodOptional<z.ZodEnum<["json", "csv"]>>;
|
779
|
+
}, "strip", z.ZodTypeAny, {
|
780
|
+
query: string;
|
781
|
+
databaseName: string;
|
782
|
+
accountName: string;
|
783
|
+
user: string;
|
784
|
+
warehouse: string;
|
785
|
+
outputFormat?: "json" | "csv" | undefined;
|
786
|
+
}, {
|
787
|
+
query: string;
|
788
|
+
databaseName: string;
|
789
|
+
accountName: string;
|
790
|
+
user: string;
|
791
|
+
warehouse: string;
|
792
|
+
outputFormat?: "json" | "csv" | undefined;
|
793
|
+
}>;
|
794
|
+
export type snowflakeRunSnowflakeQueryParamsType = z.infer<typeof snowflakeRunSnowflakeQueryParamsSchema>;
|
795
|
+
export declare const snowflakeRunSnowflakeQueryOutputSchema: z.ZodObject<{
|
796
|
+
content: z.ZodString;
|
797
|
+
rowCount: z.ZodNumber;
|
798
|
+
}, "strip", z.ZodTypeAny, {
|
799
|
+
content: string;
|
800
|
+
rowCount: number;
|
801
|
+
}, {
|
802
|
+
content: string;
|
803
|
+
rowCount: number;
|
804
|
+
}>;
|
805
|
+
export type snowflakeRunSnowflakeQueryOutputType = z.infer<typeof snowflakeRunSnowflakeQueryOutputSchema>;
|
806
|
+
export type snowflakeRunSnowflakeQueryFunction = ActionFunction<snowflakeRunSnowflakeQueryParamsType, AuthParamsType, snowflakeRunSnowflakeQueryOutputType>;
|
766
807
|
export declare const openstreetmapGetLatitudeLongitudeFromLocationParamsSchema: z.ZodObject<{
|
767
808
|
location: z.ZodString;
|
768
809
|
}, "strip", z.ZodTypeAny, {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.finnhubGetBasicFinancialsOutputSchema = exports.finnhubGetBasicFinancialsParamsSchema = exports.finnhubSymbolLookupOutputSchema = exports.finnhubSymbolLookupParamsSchema = exports.googleOauthCreateNewGoogleDocOutputSchema = exports.googleOauthCreateNewGoogleDocParamsSchema = exports.resendSendEmailOutputSchema = exports.resendSendEmailParamsSchema = exports.firecrawlScrapeTweetDataWithNitterOutputSchema = exports.firecrawlScrapeTweetDataWithNitterParamsSchema = exports.firecrawlScrapeUrlOutputSchema = exports.firecrawlScrapeUrlParamsSchema = exports.nwsGetForecastForLocationOutputSchema = exports.nwsGetForecastForLocationParamsSchema = exports.openstreetmapGetLatitudeLongitudeFromLocationOutputSchema = exports.openstreetmapGetLatitudeLongitudeFromLocationParamsSchema = exports.snowflakeGetRowByFieldValueOutputSchema = exports.snowflakeGetRowByFieldValueParamsSchema = exports.mongoInsertMongoDocOutputSchema = exports.mongoInsertMongoDocParamsSchema = exports.xCreateShareXPostUrlOutputSchema = exports.xCreateShareXPostUrlParamsSchema = exports.linkedinCreateShareLinkedinPostUrlOutputSchema = exports.linkedinCreateShareLinkedinPostUrlParamsSchema = exports.zendeskCreateZendeskTicketOutputSchema = exports.zendeskCreateZendeskTicketParamsSchema = exports.credalCallCopilotOutputSchema = exports.credalCallCopilotParamsSchema = exports.googlemapsNearbysearchRestaurantsOutputSchema = exports.googlemapsNearbysearchRestaurantsParamsSchema = exports.googlemapsValidateAddressOutputSchema = exports.googlemapsValidateAddressParamsSchema = exports.jiraCreateJiraTicketOutputSchema = exports.jiraCreateJiraTicketParamsSchema = exports.confluenceFetchPageContentOutputSchema = exports.confluenceFetchPageContentParamsSchema = exports.confluenceOverwritePageOutputSchema = exports.confluenceOverwritePageParamsSchema = exports.mathAddOutputSchema = exports.mathAddParamsSchema = exports.slackListConversationsOutputSchema = exports.slackListConversationsParamsSchema = exports.slackSendMessageOutputSchema = exports.slackSendMessageParamsSchema = exports.AuthParamsSchema = void 0;
|
3
|
+
exports.finnhubGetBasicFinancialsOutputSchema = exports.finnhubGetBasicFinancialsParamsSchema = exports.finnhubSymbolLookupOutputSchema = exports.finnhubSymbolLookupParamsSchema = exports.googleOauthCreateNewGoogleDocOutputSchema = exports.googleOauthCreateNewGoogleDocParamsSchema = exports.resendSendEmailOutputSchema = exports.resendSendEmailParamsSchema = exports.firecrawlScrapeTweetDataWithNitterOutputSchema = exports.firecrawlScrapeTweetDataWithNitterParamsSchema = exports.firecrawlScrapeUrlOutputSchema = exports.firecrawlScrapeUrlParamsSchema = exports.nwsGetForecastForLocationOutputSchema = exports.nwsGetForecastForLocationParamsSchema = exports.openstreetmapGetLatitudeLongitudeFromLocationOutputSchema = exports.openstreetmapGetLatitudeLongitudeFromLocationParamsSchema = exports.snowflakeRunSnowflakeQueryOutputSchema = exports.snowflakeRunSnowflakeQueryParamsSchema = exports.snowflakeGetRowByFieldValueOutputSchema = exports.snowflakeGetRowByFieldValueParamsSchema = exports.mongoInsertMongoDocOutputSchema = exports.mongoInsertMongoDocParamsSchema = exports.xCreateShareXPostUrlOutputSchema = exports.xCreateShareXPostUrlParamsSchema = exports.linkedinCreateShareLinkedinPostUrlOutputSchema = exports.linkedinCreateShareLinkedinPostUrlParamsSchema = exports.zendeskCreateZendeskTicketOutputSchema = exports.zendeskCreateZendeskTicketParamsSchema = exports.credalCallCopilotOutputSchema = exports.credalCallCopilotParamsSchema = exports.googlemapsNearbysearchRestaurantsOutputSchema = exports.googlemapsNearbysearchRestaurantsParamsSchema = exports.googlemapsValidateAddressOutputSchema = exports.googlemapsValidateAddressParamsSchema = exports.jiraCreateJiraTicketOutputSchema = exports.jiraCreateJiraTicketParamsSchema = exports.confluenceFetchPageContentOutputSchema = exports.confluenceFetchPageContentParamsSchema = exports.confluenceOverwritePageOutputSchema = exports.confluenceOverwritePageParamsSchema = exports.mathAddOutputSchema = exports.mathAddParamsSchema = exports.slackListConversationsOutputSchema = exports.slackListConversationsParamsSchema = exports.slackSendMessageOutputSchema = exports.slackSendMessageParamsSchema = exports.AuthParamsSchema = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
5
|
exports.AuthParamsSchema = zod_1.z.object({
|
6
6
|
authToken: zod_1.z.string().optional(),
|
@@ -12,6 +12,8 @@ exports.AuthParamsSchema = zod_1.z.object({
|
|
12
12
|
emailReplyTo: zod_1.z.string().optional(),
|
13
13
|
emailBcc: zod_1.z.string().optional(),
|
14
14
|
cloudId: zod_1.z.string().optional(),
|
15
|
+
awsAccessKeyId: zod_1.z.string().optional(),
|
16
|
+
awsSecretAccessKey: zod_1.z.string().optional(),
|
15
17
|
});
|
16
18
|
exports.slackSendMessageParamsSchema = zod_1.z.object({
|
17
19
|
channelName: zod_1.z.string().describe("The name of the Slack channel to send the message to (e.g. general, alerts)"),
|
@@ -247,6 +249,18 @@ exports.snowflakeGetRowByFieldValueOutputSchema = zod_1.z.object({
|
|
247
249
|
})
|
248
250
|
.describe("The row from the Snowflake table"),
|
249
251
|
});
|
252
|
+
exports.snowflakeRunSnowflakeQueryParamsSchema = zod_1.z.object({
|
253
|
+
databaseName: zod_1.z.string().describe("The name of the database to query"),
|
254
|
+
warehouse: zod_1.z.string().describe("The warehouse to use for executing the query"),
|
255
|
+
query: zod_1.z.string().describe("The SQL query to execute"),
|
256
|
+
user: zod_1.z.string().describe("The username to authenticate with"),
|
257
|
+
accountName: zod_1.z.string().describe("The name of the Snowflake account"),
|
258
|
+
outputFormat: zod_1.z.enum(["json", "csv"]).describe("The format of the output").optional(),
|
259
|
+
});
|
260
|
+
exports.snowflakeRunSnowflakeQueryOutputSchema = zod_1.z.object({
|
261
|
+
content: zod_1.z.string().describe("The content of the query result (json)"),
|
262
|
+
rowCount: zod_1.z.number().describe("The number of rows returned by the query"),
|
263
|
+
});
|
250
264
|
exports.openstreetmapGetLatitudeLongitudeFromLocationParamsSchema = zod_1.z.object({
|
251
265
|
location: zod_1.z.string().describe("The location to get the latitude and longitude of"),
|
252
266
|
});
|
package/dist/actions/groups.js
CHANGED
@@ -39,9 +39,9 @@ exports.ACTION_GROUPS = {
|
|
39
39
|
description: "Action for inserting a document into a MongoDB collection",
|
40
40
|
actions: [templates_1.mongoInsertMongoDocDefinition],
|
41
41
|
},
|
42
|
-
|
43
|
-
description: "Action for getting
|
44
|
-
actions: [templates_1.snowflakeGetRowByFieldValueDefinition],
|
42
|
+
SNOWFLAKE_ACTIONS: {
|
43
|
+
description: "Action for getting content from a Snowflake table",
|
44
|
+
actions: [templates_1.snowflakeGetRowByFieldValueDefinition, templates_1.snowflakeRunSnowflakeQueryDefinition],
|
45
45
|
},
|
46
46
|
JIRA_CREATE_TICKET: {
|
47
47
|
description: "Action for creating a Jira ticket",
|
package/dist/actions/parse.js
CHANGED
@@ -8,30 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const
|
16
|
-
function
|
17
|
-
|
12
|
+
const axiosClient_1 = require("../../util/axiosClient");
|
13
|
+
function getConfluenceRequestConfig(baseUrl, username, apiToken) {
|
14
|
+
return {
|
18
15
|
baseURL: baseUrl,
|
19
16
|
headers: {
|
20
17
|
Accept: "application/json",
|
21
|
-
// Tokens are associated with a specific user.
|
22
18
|
Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
|
23
19
|
},
|
24
|
-
}
|
25
|
-
return api;
|
20
|
+
};
|
26
21
|
}
|
27
22
|
const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
28
|
-
const { pageId,
|
29
|
-
const { baseUrl, authToken } = authParams;
|
30
|
-
|
23
|
+
const { pageId, content, title } = params;
|
24
|
+
const { baseUrl, authToken, username } = authParams;
|
25
|
+
if (!baseUrl || !authToken || !username) {
|
26
|
+
throw new Error("Missing required authentication information");
|
27
|
+
}
|
28
|
+
const config = getConfluenceRequestConfig(baseUrl, username, authToken);
|
31
29
|
// Get current version number
|
32
|
-
const response = yield
|
30
|
+
const response = yield axiosClient_1.axiosClient.get(`/api/v2/pages/${pageId}`, config);
|
33
31
|
const currVersion = response.data.version.number;
|
34
|
-
|
32
|
+
const payload = {
|
35
33
|
id: pageId,
|
36
34
|
status: "current",
|
37
35
|
title,
|
@@ -42,6 +40,7 @@ const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* (
|
|
42
40
|
version: {
|
43
41
|
number: currVersion + 1,
|
44
42
|
},
|
45
|
-
}
|
43
|
+
};
|
44
|
+
yield axiosClient_1.axiosClient.put(`/api/v2/pages/${pageId}`, payload, config);
|
46
45
|
});
|
47
46
|
exports.default = confluenceUpdatePage;
|
@@ -0,0 +1,96 @@
|
|
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
|
+
const types_1 = require("../../autogen/types");
|
17
|
+
const INCLUDED_TYPES = [
|
18
|
+
"monument",
|
19
|
+
"museum",
|
20
|
+
"art_gallery",
|
21
|
+
"sculpture",
|
22
|
+
"cultural_landmark",
|
23
|
+
"historical_place",
|
24
|
+
"performing_arts_theater",
|
25
|
+
"university",
|
26
|
+
"aquarium",
|
27
|
+
"botanical_garden",
|
28
|
+
"comedy_club",
|
29
|
+
"park",
|
30
|
+
"movie_theater",
|
31
|
+
"national_park",
|
32
|
+
"garden",
|
33
|
+
"night_club",
|
34
|
+
"tourist_attraction",
|
35
|
+
"water_park",
|
36
|
+
"zoo",
|
37
|
+
"bar",
|
38
|
+
"restaurant",
|
39
|
+
"food_court",
|
40
|
+
"bakery",
|
41
|
+
"cafe",
|
42
|
+
"coffee_shop",
|
43
|
+
"pub",
|
44
|
+
"wine_bar",
|
45
|
+
"spa",
|
46
|
+
"beach",
|
47
|
+
"market",
|
48
|
+
"shopping_mall",
|
49
|
+
"stadium",
|
50
|
+
];
|
51
|
+
const nearbysearch = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
52
|
+
const url = `https://places.googleapis.com/v1/places:searchNearby`;
|
53
|
+
const fieldMask = [
|
54
|
+
"places.displayName",
|
55
|
+
"places.formattedAddress",
|
56
|
+
"places.priceLevel",
|
57
|
+
"places.rating",
|
58
|
+
"places.primaryTypeDisplayName",
|
59
|
+
"places.editorialSummary",
|
60
|
+
"places.regularOpeningHours",
|
61
|
+
].join(",");
|
62
|
+
const response = yield axios_1.default.post(url, {
|
63
|
+
maxResultCount: 20,
|
64
|
+
includedTypes: INCLUDED_TYPES,
|
65
|
+
locationRestriction: {
|
66
|
+
circle: {
|
67
|
+
center: {
|
68
|
+
latitude: params.latitude,
|
69
|
+
longitude: params.longitude,
|
70
|
+
},
|
71
|
+
radius: 10000,
|
72
|
+
},
|
73
|
+
},
|
74
|
+
}, {
|
75
|
+
headers: {
|
76
|
+
"X-Goog-Api-Key": authParams.apiKey,
|
77
|
+
"X-Goog-FieldMask": fieldMask,
|
78
|
+
"Content-Type": "application/json",
|
79
|
+
},
|
80
|
+
});
|
81
|
+
return types_1.googlemapsNearbysearchOutputSchema.parse({
|
82
|
+
results: response.data.places.map((place) => {
|
83
|
+
var _a, _b;
|
84
|
+
return ({
|
85
|
+
name: place.displayName.text,
|
86
|
+
address: place.formattedAddress,
|
87
|
+
priceLevel: place.priceLevel,
|
88
|
+
rating: place.rating,
|
89
|
+
primaryType: place.primaryTypeDisplayName.text,
|
90
|
+
editorialSummary: ((_a = place.editorialSummary) === null || _a === void 0 ? void 0 : _a.text) || "",
|
91
|
+
openingHours: ((_b = place.regularOpeningHours) === null || _b === void 0 ? void 0 : _b.weekdayDescriptions.join("\n")) || "",
|
92
|
+
});
|
93
|
+
}),
|
94
|
+
});
|
95
|
+
});
|
96
|
+
exports.default = nearbysearch;
|
@@ -0,0 +1,118 @@
|
|
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 snowflake_sdk_1 = __importDefault(require("snowflake-sdk"));
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
17
|
+
// Only log errors.
|
18
|
+
snowflake_sdk_1.default.configure({ logLevel: "ERROR" });
|
19
|
+
const runSnowflakeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
20
|
+
const { databaseName, warehouse, query, user, accountName, outputFormat = "json" } = params;
|
21
|
+
const { apiKey: privateKey } = authParams;
|
22
|
+
if (!privateKey) {
|
23
|
+
throw new Error("Snowflake private key is required");
|
24
|
+
}
|
25
|
+
if (!accountName || !user || !databaseName || !warehouse || !query) {
|
26
|
+
throw new Error("Missing required parameters for Snowflake query");
|
27
|
+
}
|
28
|
+
const getPrivateKeyCorrectFormat = (privateKey) => {
|
29
|
+
const buffer = Buffer.from(privateKey);
|
30
|
+
const privateKeyObject = crypto_1.default.createPrivateKey({
|
31
|
+
key: buffer,
|
32
|
+
format: "pem",
|
33
|
+
passphrase: "password",
|
34
|
+
});
|
35
|
+
const privateKeyCorrectFormat = privateKeyObject.export({
|
36
|
+
format: "pem",
|
37
|
+
type: "pkcs8",
|
38
|
+
});
|
39
|
+
return privateKeyCorrectFormat.toString();
|
40
|
+
};
|
41
|
+
const executeQueryAndFormatData = () => __awaiter(void 0, void 0, void 0, function* () {
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
43
|
+
const queryResults = yield new Promise((resolve, reject) => {
|
44
|
+
connection.execute({
|
45
|
+
sqlText: query,
|
46
|
+
complete: (err, stmt, rows) => {
|
47
|
+
if (err) {
|
48
|
+
return reject(err);
|
49
|
+
}
|
50
|
+
return resolve(rows || []);
|
51
|
+
},
|
52
|
+
});
|
53
|
+
});
|
54
|
+
// Format the results based on the output format
|
55
|
+
let formattedData;
|
56
|
+
if (outputFormat.toLowerCase() === "csv") {
|
57
|
+
if (queryResults.length === 0) {
|
58
|
+
formattedData = "";
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
const headers = Object.keys(queryResults[0]).join(",");
|
62
|
+
const rows = queryResults.map(row => Object.values(row)
|
63
|
+
.map(value => (typeof value === "object" && value !== null ? JSON.stringify(value) : value))
|
64
|
+
.join(","));
|
65
|
+
formattedData = [headers, ...rows].join("\n");
|
66
|
+
}
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
// Default to JSON
|
70
|
+
formattedData = JSON.stringify(queryResults).replace(/\s+/g, "");
|
71
|
+
}
|
72
|
+
return { formattedData, resultsLength: queryResults.length };
|
73
|
+
});
|
74
|
+
// Process the private key
|
75
|
+
const privateKeyCorrectFormatString = getPrivateKeyCorrectFormat(privateKey);
|
76
|
+
// Set up a connection using snowflake-sdk
|
77
|
+
const connection = snowflake_sdk_1.default.createConnection({
|
78
|
+
account: accountName,
|
79
|
+
username: user,
|
80
|
+
privateKey: privateKeyCorrectFormatString,
|
81
|
+
authenticator: "SNOWFLAKE_JWT",
|
82
|
+
role: "ACCOUNTADMIN",
|
83
|
+
warehouse: warehouse,
|
84
|
+
database: databaseName,
|
85
|
+
});
|
86
|
+
try {
|
87
|
+
// Connect to Snowflake
|
88
|
+
yield new Promise((resolve, reject) => {
|
89
|
+
connection.connect((err, conn) => {
|
90
|
+
if (err) {
|
91
|
+
console.error("Unable to connect to Snowflake:", err.message);
|
92
|
+
return reject(err);
|
93
|
+
}
|
94
|
+
resolve(conn);
|
95
|
+
});
|
96
|
+
});
|
97
|
+
const { formattedData, resultsLength } = yield executeQueryAndFormatData();
|
98
|
+
// Return fields to match schema definition
|
99
|
+
connection.destroy(err => {
|
100
|
+
if (err) {
|
101
|
+
console.log("Failed to disconnect from Snowflake:", err);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
rowCount: resultsLength,
|
106
|
+
content: formattedData,
|
107
|
+
};
|
108
|
+
}
|
109
|
+
catch (error) {
|
110
|
+
connection.destroy(err => {
|
111
|
+
if (err) {
|
112
|
+
console.log("Failed to disconnect from Snowflake:", err);
|
113
|
+
}
|
114
|
+
});
|
115
|
+
throw Error(`An error occurred: ${error}`);
|
116
|
+
}
|
117
|
+
});
|
118
|
+
exports.default = runSnowflakeQuery;
|
@@ -0,0 +1,154 @@
|
|
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 snowflake_sdk_1 = __importDefault(require("snowflake-sdk"));
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
17
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
18
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
19
|
+
const uuid_1 = require("uuid");
|
20
|
+
// Only log errors.
|
21
|
+
snowflake_sdk_1.default.configure({ logLevel: "ERROR" });
|
22
|
+
const runSnowflakeQueryWriteResultsToS3 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
23
|
+
const { databaseName, warehouse, query, user, accountName, s3BucketName, s3Region, outputFormat = "json" } = params;
|
24
|
+
const { apiKey: privateKey, awsAccessKeyId, awsSecretAccessKey } = authParams;
|
25
|
+
if (!privateKey) {
|
26
|
+
throw new Error("Snowflake private key is required");
|
27
|
+
}
|
28
|
+
if (!awsAccessKeyId || !awsSecretAccessKey) {
|
29
|
+
throw new Error("AWS credentials are required");
|
30
|
+
}
|
31
|
+
if (!accountName || !user || !databaseName || !warehouse || !query || !s3BucketName) {
|
32
|
+
throw new Error("Missing required parameters for Snowflake query or S3 destination");
|
33
|
+
}
|
34
|
+
const getPrivateKeyCorrectFormat = (privateKey) => {
|
35
|
+
const buffer = Buffer.from(privateKey);
|
36
|
+
const privateKeyObject = crypto_1.default.createPrivateKey({
|
37
|
+
key: buffer,
|
38
|
+
format: "pem",
|
39
|
+
passphrase: "password",
|
40
|
+
});
|
41
|
+
const privateKeyCorrectFormat = privateKeyObject.export({
|
42
|
+
format: "pem",
|
43
|
+
type: "pkcs8",
|
44
|
+
});
|
45
|
+
return privateKeyCorrectFormat.toString();
|
46
|
+
};
|
47
|
+
const executeQueryAndFormatData = () => __awaiter(void 0, void 0, void 0, function* () {
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
49
|
+
const queryResults = yield new Promise((resolve, reject) => {
|
50
|
+
connection.execute({
|
51
|
+
sqlText: query,
|
52
|
+
complete: (err, stmt, rows) => {
|
53
|
+
if (err) {
|
54
|
+
return reject(err);
|
55
|
+
}
|
56
|
+
return resolve(rows || []);
|
57
|
+
},
|
58
|
+
});
|
59
|
+
});
|
60
|
+
// Format the results based on the output format
|
61
|
+
let formattedData;
|
62
|
+
if (outputFormat.toLowerCase() === "csv") {
|
63
|
+
if (queryResults.length === 0) {
|
64
|
+
formattedData = "";
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
const headers = Object.keys(queryResults[0]).join(",");
|
68
|
+
const rows = queryResults.map(row => Object.values(row)
|
69
|
+
.map(value => (typeof value === "object" && value !== null ? JSON.stringify(value) : value))
|
70
|
+
.join(","));
|
71
|
+
formattedData = [headers, ...rows].join("\n");
|
72
|
+
}
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
// Default to JSON
|
76
|
+
formattedData = JSON.stringify(queryResults, null, 2);
|
77
|
+
}
|
78
|
+
return { formattedData, resultsLength: queryResults.length };
|
79
|
+
});
|
80
|
+
const uploadToS3AndGetURL = (formattedData) => __awaiter(void 0, void 0, void 0, function* () {
|
81
|
+
// Create S3 client
|
82
|
+
const s3Client = new client_s3_1.S3Client({
|
83
|
+
region: s3Region,
|
84
|
+
credentials: {
|
85
|
+
accessKeyId: awsAccessKeyId,
|
86
|
+
secretAccessKey: awsSecretAccessKey,
|
87
|
+
},
|
88
|
+
});
|
89
|
+
const contentType = outputFormat.toLowerCase() === "csv" ? "text/csv" : "application/json";
|
90
|
+
const fileExtension = outputFormat.toLowerCase() === "csv" ? "csv" : "json";
|
91
|
+
const finalKey = `${databaseName}/${(0, uuid_1.v4)()}.${fileExtension}`;
|
92
|
+
// Upload to S3 without ACL
|
93
|
+
const uploadCommand = new client_s3_1.PutObjectCommand({
|
94
|
+
Bucket: s3BucketName,
|
95
|
+
Key: finalKey,
|
96
|
+
Body: formattedData,
|
97
|
+
ContentType: contentType,
|
98
|
+
});
|
99
|
+
yield s3Client.send(uploadCommand);
|
100
|
+
// Generate a presigned URL (valid for an hour)
|
101
|
+
const getObjectCommand = new client_s3_1.GetObjectCommand({
|
102
|
+
Bucket: s3BucketName,
|
103
|
+
Key: finalKey,
|
104
|
+
});
|
105
|
+
const presignedUrl = yield (0, s3_request_presigner_1.getSignedUrl)(s3Client, getObjectCommand, { expiresIn: 3600 });
|
106
|
+
return presignedUrl;
|
107
|
+
});
|
108
|
+
// Process the private key
|
109
|
+
const privateKeyCorrectFormatString = getPrivateKeyCorrectFormat(privateKey);
|
110
|
+
// Set up a connection using snowflake-sdk
|
111
|
+
const connection = snowflake_sdk_1.default.createConnection({
|
112
|
+
account: accountName,
|
113
|
+
username: user,
|
114
|
+
privateKey: privateKeyCorrectFormatString,
|
115
|
+
authenticator: "SNOWFLAKE_JWT",
|
116
|
+
role: "ACCOUNTADMIN",
|
117
|
+
warehouse: warehouse,
|
118
|
+
database: databaseName,
|
119
|
+
});
|
120
|
+
try {
|
121
|
+
// Connect to Snowflake
|
122
|
+
yield new Promise((resolve, reject) => {
|
123
|
+
connection.connect((err, conn) => {
|
124
|
+
if (err) {
|
125
|
+
console.error("Unable to connect to Snowflake:", err.message);
|
126
|
+
return reject(err);
|
127
|
+
}
|
128
|
+
resolve(conn);
|
129
|
+
});
|
130
|
+
});
|
131
|
+
const { formattedData, resultsLength } = yield executeQueryAndFormatData();
|
132
|
+
const presignedUrl = yield uploadToS3AndGetURL(formattedData);
|
133
|
+
// Return fields to match schema definition
|
134
|
+
connection.destroy(err => {
|
135
|
+
if (err) {
|
136
|
+
console.log("Failed to disconnect from Snowflake:", err);
|
137
|
+
}
|
138
|
+
});
|
139
|
+
return {
|
140
|
+
bucketUrl: presignedUrl,
|
141
|
+
message: `Query results successfully written to S3. URL valid for 1 hour.`,
|
142
|
+
rowCount: resultsLength,
|
143
|
+
};
|
144
|
+
}
|
145
|
+
catch (error) {
|
146
|
+
connection.destroy(err => {
|
147
|
+
if (err) {
|
148
|
+
console.log("Failed to disconnect from Snowflake:", err);
|
149
|
+
}
|
150
|
+
});
|
151
|
+
throw Error(`An error occurred: ${error}`);
|
152
|
+
}
|
153
|
+
});
|
154
|
+
exports.default = runSnowflakeQueryWriteResultsToS3;
|
@@ -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
|
+
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 firecrawl_js_1 = __importDefault(require("@mendable/firecrawl-js"));
|
16
|
+
const scrapeTweetDataWithNitter = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
17
|
+
const tweetUrlRegex = /^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)\/([a-zA-Z0-9_]+)\/status\/(\d+)(?:\?.*)?$/;
|
18
|
+
if (!tweetUrlRegex.test(params.tweetUrl)) {
|
19
|
+
throw new Error("Invalid tweet URL. Expected format: https://twitter.com/username/status/id or https://x.com/username/status/id");
|
20
|
+
}
|
21
|
+
const nitterUrl = params.tweetUrl.replace(/^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)/i, "https://nitter.net");
|
22
|
+
// Initialize Firecrawl
|
23
|
+
if (!authParams.apiKey) {
|
24
|
+
throw new Error("API key is required for X+Nitter+Firecrawl");
|
25
|
+
}
|
26
|
+
const firecrawl = new firecrawl_js_1.default({
|
27
|
+
apiKey: authParams.apiKey,
|
28
|
+
});
|
29
|
+
try {
|
30
|
+
// Scrape the Nitter URL
|
31
|
+
const result = yield firecrawl.scrapeUrl(nitterUrl);
|
32
|
+
if (!result.success) {
|
33
|
+
throw new Error(`Failed to scrape tweet: ${result.error || "Unknown error"}`);
|
34
|
+
}
|
35
|
+
// Extract the tweet text from the scraped content - simple approach - in practice, you might need more robust parsing based on nitter html structure
|
36
|
+
const tweetContent = result.markdown;
|
37
|
+
return {
|
38
|
+
text: tweetContent || "Error scraping with firecrawl",
|
39
|
+
};
|
40
|
+
}
|
41
|
+
catch (error) {
|
42
|
+
throw new Error(`Error scraping tweet: ${error instanceof Error ? error.message : error}`);
|
43
|
+
}
|
44
|
+
});
|
45
|
+
exports.default = scrapeTweetDataWithNitter;
|
package/package.json
CHANGED
@@ -1,23 +0,0 @@
|
|
1
|
-
declare const axios: any;
|
2
|
-
declare const WORKDAY_BASE_URL = "https://your-workday-url/ccx/service/YOUR_TENANT/Absence_Management/v43.2";
|
3
|
-
declare const TOKEN_URL = "https://your-workday-url/oauth2/YOUR_TENANT/token";
|
4
|
-
declare const CLIENT_ID = "your-client-id";
|
5
|
-
declare const CLIENT_SECRET = "your-client-secret";
|
6
|
-
/**
|
7
|
-
* Fetches an OAuth 2.0 access token from Workday.
|
8
|
-
*/
|
9
|
-
declare function getAccessToken(): Promise<any>;
|
10
|
-
/**
|
11
|
-
* Submits a time-off request to Workday.
|
12
|
-
* @param {Object} params - Time-off details.
|
13
|
-
* @param {string} params.workerId - Worker's ID in Workday.
|
14
|
-
* @param {string} params.startDate - Start date (YYYY-MM-DD).
|
15
|
-
* @param {string} params.endDate - End date (YYYY-MM-DD).
|
16
|
-
* @param {string} params.timeOffType - Time-off type (e.g., "SICK_LEAVE").
|
17
|
-
*/
|
18
|
-
declare function submitTimeOff({ workerId, startDate, endDate, timeOffType }: {
|
19
|
-
workerId: any;
|
20
|
-
startDate: any;
|
21
|
-
endDate: any;
|
22
|
-
timeOffType: any;
|
23
|
-
}): Promise<any>;
|
@@ -1,88 +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
|
-
const axios = require("axios");
|
12
|
-
const WORKDAY_BASE_URL = "https://your-workday-url/ccx/service/YOUR_TENANT/Absence_Management/v43.2";
|
13
|
-
const TOKEN_URL = "https://your-workday-url/oauth2/YOUR_TENANT/token"; // OAuth token endpoint
|
14
|
-
const CLIENT_ID = "your-client-id";
|
15
|
-
const CLIENT_SECRET = "your-client-secret";
|
16
|
-
/**
|
17
|
-
* Fetches an OAuth 2.0 access token from Workday.
|
18
|
-
*/
|
19
|
-
function getAccessToken() {
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
21
|
-
var _a;
|
22
|
-
try {
|
23
|
-
const response = yield axios.post(TOKEN_URL, new URLSearchParams({ grant_type: "client_credentials" }), {
|
24
|
-
auth: {
|
25
|
-
username: CLIENT_ID,
|
26
|
-
password: CLIENT_SECRET
|
27
|
-
},
|
28
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
29
|
-
});
|
30
|
-
return response.data.access_token;
|
31
|
-
}
|
32
|
-
catch (error) {
|
33
|
-
console.error("Error fetching access token:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
|
34
|
-
throw error;
|
35
|
-
}
|
36
|
-
});
|
37
|
-
}
|
38
|
-
/**
|
39
|
-
* Submits a time-off request to Workday.
|
40
|
-
* @param {Object} params - Time-off details.
|
41
|
-
* @param {string} params.workerId - Worker's ID in Workday.
|
42
|
-
* @param {string} params.startDate - Start date (YYYY-MM-DD).
|
43
|
-
* @param {string} params.endDate - End date (YYYY-MM-DD).
|
44
|
-
* @param {string} params.timeOffType - Time-off type (e.g., "SICK_LEAVE").
|
45
|
-
*/
|
46
|
-
function submitTimeOff(_a) {
|
47
|
-
return __awaiter(this, arguments, void 0, function* ({ workerId, startDate, endDate, timeOffType }) {
|
48
|
-
var _b;
|
49
|
-
try {
|
50
|
-
const token = yield getAccessToken(); // Get OAuth token
|
51
|
-
const requestBody = {
|
52
|
-
"wd:Enter_Time_Off_Request": {
|
53
|
-
"wd:Worker_Reference": {
|
54
|
-
"wd:ID": [{ "_": workerId, "$": { "wd:type": "WID" } }]
|
55
|
-
},
|
56
|
-
"wd:Time_Off_Entries": [
|
57
|
-
{
|
58
|
-
"wd:Start_Date": startDate,
|
59
|
-
"wd:End_Date": endDate,
|
60
|
-
"wd:Time_Off_Type_Reference": {
|
61
|
-
"wd:ID": [{ "_": timeOffType, "$": { "wd:type": "Time_Off_Type_ID" } }]
|
62
|
-
}
|
63
|
-
}
|
64
|
-
]
|
65
|
-
}
|
66
|
-
};
|
67
|
-
const response = yield axios.post(`${WORKDAY_BASE_URL}/Enter_Time_Off`, requestBody, {
|
68
|
-
headers: {
|
69
|
-
"Authorization": `Bearer ${token}`,
|
70
|
-
"Content-Type": "application/json"
|
71
|
-
}
|
72
|
-
});
|
73
|
-
console.log("Time-off request submitted successfully:", response.data);
|
74
|
-
return response.data;
|
75
|
-
}
|
76
|
-
catch (error) {
|
77
|
-
console.error("Error submitting time-off request:", ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || error.message);
|
78
|
-
throw error;
|
79
|
-
}
|
80
|
-
});
|
81
|
-
}
|
82
|
-
// Example Usage:
|
83
|
-
submitTimeOff({
|
84
|
-
workerId: "12345",
|
85
|
-
startDate: "2025-03-10",
|
86
|
-
endDate: "2025-03-12",
|
87
|
-
timeOffType: "SICK_LEAVE"
|
88
|
-
}).then(console.log).catch(console.error);
|