@credal/actions 0.1.1 → 0.1.3
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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/actions/actionMapper.js +8 -0
- package/dist/actions/autogen/templates.d.ts +1 -0
- package/dist/actions/autogen/templates.js +45 -1
- package/dist/actions/autogen/types.d.ts +54 -13
- package/dist/actions/autogen/types.js +17 -4
- package/dist/actions/parse.js +2 -1
- package/dist/actions/providers/openstreetmap/getLatitudeLongitudeFromLocation.d.ts +3 -0
- package/dist/actions/providers/openstreetmap/getLatitudeLongitudeFromLocation.js +26 -0
- package/dist/actions/providers/workday/requestTimeOff.d.ts +23 -0
- package/dist/actions/providers/workday/requestTimeOff.js +88 -0
- package/package.json +1 -1
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Credal.ai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -15,6 +15,7 @@ const sendMessage_1 = __importDefault(require("./providers/slack/sendMessage"));
|
|
15
15
|
const getRowByFieldValue_1 = __importDefault(require("./providers/snowflake/getRowByFieldValue"));
|
16
16
|
const createZendeskTicket_1 = __importDefault(require("./providers/zendesk/createZendeskTicket"));
|
17
17
|
const createJiraTicket_1 = __importDefault(require("./providers/jira/createJiraTicket"));
|
18
|
+
const getLatitudeLongitudeFromLocation_1 = __importDefault(require("./providers/openstreetmap/getLatitudeLongitudeFromLocation"));
|
18
19
|
exports.ActionMapper = {
|
19
20
|
math: {
|
20
21
|
add: {
|
@@ -84,4 +85,11 @@ exports.ActionMapper = {
|
|
84
85
|
outputSchema: types_1.jiraCreateJiraTicketOutputSchema,
|
85
86
|
},
|
86
87
|
},
|
88
|
+
openstreetmap: {
|
89
|
+
getLatitudeLongitudeFromLocation: {
|
90
|
+
fn: getLatitudeLongitudeFromLocation_1.default,
|
91
|
+
paramsSchema: types_1.openstreetmapGetLatitudeLongitudeFromLocationParamsSchema,
|
92
|
+
outputSchema: types_1.openstreetmapGetLatitudeLongitudeFromLocationOutputSchema,
|
93
|
+
},
|
94
|
+
},
|
87
95
|
};
|
@@ -9,3 +9,4 @@ export declare const credalCallCopilotDefinition: ActionTemplate;
|
|
9
9
|
export declare const zendeskCreateZendeskTicketDefinition: ActionTemplate;
|
10
10
|
export declare const mongoInsertMongoDocDefinition: ActionTemplate;
|
11
11
|
export declare const snowflakeGetRowByFieldValueDefinition: ActionTemplate;
|
12
|
+
export declare const openstreetmapGetLatitudeLongitudeFromLocationDefinition: ActionTemplate;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.snowflakeGetRowByFieldValueDefinition = exports.mongoInsertMongoDocDefinition = exports.zendeskCreateZendeskTicketDefinition = exports.credalCallCopilotDefinition = exports.googlemapsValidateAddressDefinition = exports.jiraCreateJiraTicketDefinition = exports.confluenceUpdatePageDefinition = exports.mathAddDefinition = exports.slackListConversationsDefinition = exports.slackSendMessageDefinition = void 0;
|
3
|
+
exports.openstreetmapGetLatitudeLongitudeFromLocationDefinition = exports.snowflakeGetRowByFieldValueDefinition = exports.mongoInsertMongoDocDefinition = exports.zendeskCreateZendeskTicketDefinition = exports.credalCallCopilotDefinition = exports.googlemapsValidateAddressDefinition = exports.jiraCreateJiraTicketDefinition = exports.confluenceUpdatePageDefinition = 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"],
|
@@ -505,3 +505,47 @@ exports.snowflakeGetRowByFieldValueDefinition = {
|
|
505
505
|
name: "getRowByFieldValue",
|
506
506
|
provider: "snowflake",
|
507
507
|
};
|
508
|
+
exports.openstreetmapGetLatitudeLongitudeFromLocationDefinition = {
|
509
|
+
description: "Get the latitude and longitude of a location",
|
510
|
+
scopes: [],
|
511
|
+
parameters: {
|
512
|
+
type: "object",
|
513
|
+
required: ["location"],
|
514
|
+
properties: {
|
515
|
+
location: {
|
516
|
+
type: "string",
|
517
|
+
description: "The location to get the latitude and longitude of",
|
518
|
+
},
|
519
|
+
},
|
520
|
+
},
|
521
|
+
output: {
|
522
|
+
type: "object",
|
523
|
+
required: [],
|
524
|
+
properties: {
|
525
|
+
results: {
|
526
|
+
type: "array",
|
527
|
+
description: "The results of the query",
|
528
|
+
items: {
|
529
|
+
type: "object",
|
530
|
+
required: ["latitude", "longitude", "display_name"],
|
531
|
+
properties: {
|
532
|
+
latitude: {
|
533
|
+
type: "number",
|
534
|
+
description: "The latitude of the location",
|
535
|
+
},
|
536
|
+
longitude: {
|
537
|
+
type: "number",
|
538
|
+
description: "The longitude of the location",
|
539
|
+
},
|
540
|
+
display_name: {
|
541
|
+
type: "string",
|
542
|
+
description: "The display name of the location",
|
543
|
+
},
|
544
|
+
},
|
545
|
+
},
|
546
|
+
},
|
547
|
+
},
|
548
|
+
},
|
549
|
+
name: "getLatitudeLongitudeFromLocation",
|
550
|
+
provider: "openstreetmap",
|
551
|
+
};
|
@@ -281,15 +281,15 @@ export declare const googlemapsValidateAddressOutputSchema: z.ZodObject<{
|
|
281
281
|
} | undefined;
|
282
282
|
}>>;
|
283
283
|
uspsData: z.ZodOptional<z.ZodObject<{
|
284
|
-
standardizedAddress: z.ZodOptional<z.
|
284
|
+
standardizedAddress: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
285
285
|
deliveryPointValidation: z.ZodOptional<z.ZodString>;
|
286
286
|
uspsAddressPrecision: z.ZodOptional<z.ZodString>;
|
287
287
|
}, "strip", z.ZodTypeAny, {
|
288
|
-
standardizedAddress?:
|
288
|
+
standardizedAddress?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
289
289
|
deliveryPointValidation?: string | undefined;
|
290
290
|
uspsAddressPrecision?: string | undefined;
|
291
291
|
}, {
|
292
|
-
standardizedAddress?:
|
292
|
+
standardizedAddress?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
293
293
|
deliveryPointValidation?: string | undefined;
|
294
294
|
uspsAddressPrecision?: string | undefined;
|
295
295
|
}>>;
|
@@ -323,7 +323,7 @@ export declare const googlemapsValidateAddressOutputSchema: z.ZodObject<{
|
|
323
323
|
} | undefined;
|
324
324
|
} | undefined;
|
325
325
|
uspsData?: {
|
326
|
-
standardizedAddress?:
|
326
|
+
standardizedAddress?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
327
327
|
deliveryPointValidation?: string | undefined;
|
328
328
|
uspsAddressPrecision?: string | undefined;
|
329
329
|
} | undefined;
|
@@ -357,7 +357,7 @@ export declare const googlemapsValidateAddressOutputSchema: z.ZodObject<{
|
|
357
357
|
} | undefined;
|
358
358
|
} | undefined;
|
359
359
|
uspsData?: {
|
360
|
-
standardizedAddress?:
|
360
|
+
standardizedAddress?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
361
361
|
deliveryPointValidation?: string | undefined;
|
362
362
|
uspsAddressPrecision?: string | undefined;
|
363
363
|
} | undefined;
|
@@ -419,15 +419,19 @@ export type zendeskCreateZendeskTicketFunction = ActionFunction<zendeskCreateZen
|
|
419
419
|
export declare const mongoInsertMongoDocParamsSchema: z.ZodObject<{
|
420
420
|
databaseName: z.ZodString;
|
421
421
|
collectionName: z.ZodString;
|
422
|
-
document: z.
|
422
|
+
document: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
423
423
|
}, "strip", z.ZodTypeAny, {
|
424
424
|
databaseName: string;
|
425
425
|
collectionName: string;
|
426
|
-
document:
|
426
|
+
document: {} & {
|
427
|
+
[k: string]: any;
|
428
|
+
};
|
427
429
|
}, {
|
428
430
|
databaseName: string;
|
429
431
|
collectionName: string;
|
430
|
-
document:
|
432
|
+
document: {} & {
|
433
|
+
[k: string]: any;
|
434
|
+
};
|
431
435
|
}>;
|
432
436
|
export type mongoInsertMongoDocParamsType = z.infer<typeof mongoInsertMongoDocParamsSchema>;
|
433
437
|
export declare const mongoInsertMongoDocOutputSchema: z.ZodObject<{
|
@@ -468,24 +472,61 @@ export type snowflakeGetRowByFieldValueParamsType = z.infer<typeof snowflakeGetR
|
|
468
472
|
export declare const snowflakeGetRowByFieldValueOutputSchema: z.ZodObject<{
|
469
473
|
row: z.ZodObject<{
|
470
474
|
id: z.ZodOptional<z.ZodString>;
|
471
|
-
rowContents: z.ZodOptional<z.
|
475
|
+
rowContents: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
472
476
|
}, "strip", z.ZodTypeAny, {
|
473
477
|
id?: string | undefined;
|
474
|
-
rowContents?:
|
478
|
+
rowContents?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
475
479
|
}, {
|
476
480
|
id?: string | undefined;
|
477
|
-
rowContents?:
|
481
|
+
rowContents?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
478
482
|
}>;
|
479
483
|
}, "strip", z.ZodTypeAny, {
|
480
484
|
row: {
|
481
485
|
id?: string | undefined;
|
482
|
-
rowContents?:
|
486
|
+
rowContents?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
483
487
|
};
|
484
488
|
}, {
|
485
489
|
row: {
|
486
490
|
id?: string | undefined;
|
487
|
-
rowContents?:
|
491
|
+
rowContents?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
488
492
|
};
|
489
493
|
}>;
|
490
494
|
export type snowflakeGetRowByFieldValueOutputType = z.infer<typeof snowflakeGetRowByFieldValueOutputSchema>;
|
491
495
|
export type snowflakeGetRowByFieldValueFunction = ActionFunction<snowflakeGetRowByFieldValueParamsType, AuthParamsType, snowflakeGetRowByFieldValueOutputType>;
|
496
|
+
export declare const openstreetmapGetLatitudeLongitudeFromLocationParamsSchema: z.ZodObject<{
|
497
|
+
location: z.ZodString;
|
498
|
+
}, "strip", z.ZodTypeAny, {
|
499
|
+
location: string;
|
500
|
+
}, {
|
501
|
+
location: string;
|
502
|
+
}>;
|
503
|
+
export type openstreetmapGetLatitudeLongitudeFromLocationParamsType = z.infer<typeof openstreetmapGetLatitudeLongitudeFromLocationParamsSchema>;
|
504
|
+
export declare const openstreetmapGetLatitudeLongitudeFromLocationOutputSchema: z.ZodObject<{
|
505
|
+
results: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
506
|
+
latitude: z.ZodNumber;
|
507
|
+
longitude: z.ZodNumber;
|
508
|
+
display_name: z.ZodString;
|
509
|
+
}, "strip", z.ZodTypeAny, {
|
510
|
+
latitude: number;
|
511
|
+
longitude: number;
|
512
|
+
display_name: string;
|
513
|
+
}, {
|
514
|
+
latitude: number;
|
515
|
+
longitude: number;
|
516
|
+
display_name: string;
|
517
|
+
}>, "many">>;
|
518
|
+
}, "strip", z.ZodTypeAny, {
|
519
|
+
results?: {
|
520
|
+
latitude: number;
|
521
|
+
longitude: number;
|
522
|
+
display_name: string;
|
523
|
+
}[] | undefined;
|
524
|
+
}, {
|
525
|
+
results?: {
|
526
|
+
latitude: number;
|
527
|
+
longitude: number;
|
528
|
+
display_name: string;
|
529
|
+
}[] | undefined;
|
530
|
+
}>;
|
531
|
+
export type openstreetmapGetLatitudeLongitudeFromLocationOutputType = z.infer<typeof openstreetmapGetLatitudeLongitudeFromLocationOutputSchema>;
|
532
|
+
export type openstreetmapGetLatitudeLongitudeFromLocationFunction = ActionFunction<openstreetmapGetLatitudeLongitudeFromLocationParamsType, AuthParamsType, openstreetmapGetLatitudeLongitudeFromLocationOutputType>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.snowflakeGetRowByFieldValueOutputSchema = exports.snowflakeGetRowByFieldValueParamsSchema = exports.mongoInsertMongoDocOutputSchema = exports.mongoInsertMongoDocParamsSchema = exports.zendeskCreateZendeskTicketOutputSchema = exports.zendeskCreateZendeskTicketParamsSchema = exports.credalCallCopilotOutputSchema = exports.credalCallCopilotParamsSchema = exports.googlemapsValidateAddressOutputSchema = exports.googlemapsValidateAddressParamsSchema = exports.jiraCreateJiraTicketOutputSchema = exports.jiraCreateJiraTicketParamsSchema = exports.confluenceUpdatePageOutputSchema = exports.confluenceUpdatePageParamsSchema = exports.mathAddOutputSchema = exports.mathAddParamsSchema = exports.slackListConversationsOutputSchema = exports.slackListConversationsParamsSchema = exports.slackSendMessageOutputSchema = exports.slackSendMessageParamsSchema = exports.AuthParamsSchema = void 0;
|
3
|
+
exports.openstreetmapGetLatitudeLongitudeFromLocationOutputSchema = exports.openstreetmapGetLatitudeLongitudeFromLocationParamsSchema = exports.snowflakeGetRowByFieldValueOutputSchema = exports.snowflakeGetRowByFieldValueParamsSchema = exports.mongoInsertMongoDocOutputSchema = exports.mongoInsertMongoDocParamsSchema = exports.zendeskCreateZendeskTicketOutputSchema = exports.zendeskCreateZendeskTicketParamsSchema = exports.credalCallCopilotOutputSchema = exports.credalCallCopilotParamsSchema = exports.googlemapsValidateAddressOutputSchema = exports.googlemapsValidateAddressParamsSchema = exports.jiraCreateJiraTicketOutputSchema = exports.jiraCreateJiraTicketParamsSchema = exports.confluenceUpdatePageOutputSchema = exports.confluenceUpdatePageParamsSchema = 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(),
|
@@ -104,7 +104,7 @@ exports.googlemapsValidateAddressOutputSchema = zod_1.z.object({
|
|
104
104
|
.optional(),
|
105
105
|
uspsData: zod_1.z
|
106
106
|
.object({
|
107
|
-
standardizedAddress: zod_1.z.
|
107
|
+
standardizedAddress: zod_1.z.object({}).catchall(zod_1.z.any()).describe("The standardized USPS address.").optional(),
|
108
108
|
deliveryPointValidation: zod_1.z.string().describe("The USPS delivery point validation status.").optional(),
|
109
109
|
uspsAddressPrecision: zod_1.z.string().describe("The level of precision for the USPS address.").optional(),
|
110
110
|
})
|
@@ -132,7 +132,7 @@ exports.zendeskCreateZendeskTicketOutputSchema = zod_1.z.object({
|
|
132
132
|
exports.mongoInsertMongoDocParamsSchema = zod_1.z.object({
|
133
133
|
databaseName: zod_1.z.string().describe("Database to connect to"),
|
134
134
|
collectionName: zod_1.z.string().describe("Collection to insert the document into"),
|
135
|
-
document: zod_1.z.
|
135
|
+
document: zod_1.z.object({}).catchall(zod_1.z.any()).describe("The document to insert"),
|
136
136
|
});
|
137
137
|
exports.mongoInsertMongoDocOutputSchema = zod_1.z.object({
|
138
138
|
objectId: zod_1.z.string().describe("The new ID of the document inserted"),
|
@@ -150,7 +150,20 @@ exports.snowflakeGetRowByFieldValueOutputSchema = zod_1.z.object({
|
|
150
150
|
row: zod_1.z
|
151
151
|
.object({
|
152
152
|
id: zod_1.z.string().describe("The ID of the row").optional(),
|
153
|
-
rowContents: zod_1.z.
|
153
|
+
rowContents: zod_1.z.object({}).catchall(zod_1.z.any()).describe("The contents of the row").optional(),
|
154
154
|
})
|
155
155
|
.describe("The row from the Snowflake table"),
|
156
156
|
});
|
157
|
+
exports.openstreetmapGetLatitudeLongitudeFromLocationParamsSchema = zod_1.z.object({
|
158
|
+
location: zod_1.z.string().describe("The location to get the latitude and longitude of"),
|
159
|
+
});
|
160
|
+
exports.openstreetmapGetLatitudeLongitudeFromLocationOutputSchema = zod_1.z.object({
|
161
|
+
results: zod_1.z
|
162
|
+
.array(zod_1.z.object({
|
163
|
+
latitude: zod_1.z.number().describe("The latitude of the location"),
|
164
|
+
longitude: zod_1.z.number().describe("The longitude of the location"),
|
165
|
+
display_name: zod_1.z.string().describe("The display name of the location"),
|
166
|
+
}))
|
167
|
+
.describe("The results of the query")
|
168
|
+
.optional(),
|
169
|
+
});
|
package/dist/actions/parse.js
CHANGED
@@ -96,7 +96,8 @@ function addActionTypes(_a) {
|
|
96
96
|
}
|
97
97
|
function addTypesToFile(_a) {
|
98
98
|
return __awaiter(this, arguments, void 0, function* ({ file, obj, fallback, name, }) {
|
99
|
-
|
99
|
+
// Tool calling framework currently having trouble filling in records as opposed to objects
|
100
|
+
const zodSchema = obj ? (0, json_schema_to_zod_1.default)(obj).replace(/z\.record\(z\.any\(\)\)/g, "z.object({}).catchall(z.any())") : fallback;
|
100
101
|
const zodName = `${name}Schema`;
|
101
102
|
file.addVariableStatement({
|
102
103
|
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
@@ -0,0 +1,26 @@
|
|
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 getLatitudeLongitudeFromLocation = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, }) {
|
17
|
+
const { location } = params;
|
18
|
+
const url = `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(location)}&format=json`;
|
19
|
+
const response = yield axios_1.default.get(url, { headers: { "User-Agent": "Credal/1.0" } });
|
20
|
+
return response.data.map((result) => ({
|
21
|
+
latitude: parseFloat(result.lat),
|
22
|
+
longitude: parseFloat(result.lon),
|
23
|
+
displayName: result.display_name,
|
24
|
+
}));
|
25
|
+
});
|
26
|
+
exports.default = getLatitudeLongitudeFromLocation;
|
@@ -0,0 +1,23 @@
|
|
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>;
|
@@ -0,0 +1,88 @@
|
|
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);
|