gm-mcp 2.0.4 → 2.0.5

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.
@@ -1,5 +1,15 @@
1
1
  import { Gimo } from "./types";
2
+ import { PayPeriod } from "./types/pay-period";
3
+ import { TimeSheet } from "./types/time-keeper";
2
4
  export declare function getAccessToken(): Promise<string>;
3
5
  export declare function findCustomerEWAByPhonenumber(phoneNumber: string): Promise<Gimo.CustomerEWA | null>;
6
+ export declare function getPayPeriods(params: {
7
+ orgId: number;
8
+ parnterId: number;
9
+ }): Promise<PayPeriod[]>;
10
+ export declare function getTimeSheets(params: {
11
+ payPeriodId: number;
12
+ employeeId: number;
13
+ }): Promise<TimeSheet[]>;
4
14
  export declare function getEmployeeByCustomerId(customerId: number): Promise<Gimo.EmployeeInfo>;
5
15
  export declare function findCustomerEWAById(id: number): Promise<Gimo.CustomerEWA>;
@@ -14,6 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAccessToken = getAccessToken;
16
16
  exports.findCustomerEWAByPhonenumber = findCustomerEWAByPhonenumber;
17
+ exports.getPayPeriods = getPayPeriods;
18
+ exports.getTimeSheets = getTimeSheets;
17
19
  exports.getEmployeeByCustomerId = getEmployeeByCustomerId;
18
20
  exports.findCustomerEWAById = findCustomerEWAById;
19
21
  const axios_1 = __importDefault(require("axios"));
@@ -51,6 +53,46 @@ function findCustomerEWAByPhonenumber(phoneNumber) {
51
53
  return findCustomerEWAById(foundedCustomer.customer_id);
52
54
  });
53
55
  }
56
+ function getPayPeriods(params) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const { orgId, parnterId } = params;
59
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/partners/${parnterId}/pay-periods`;
60
+ const access_token = yield getAccessToken();
61
+ const customer = yield axios_1.default
62
+ .get(url, {
63
+ headers: {
64
+ Authorization: "Bearer " + access_token,
65
+ },
66
+ params: {
67
+ orgId,
68
+ sort: "start_date,desc",
69
+ },
70
+ })
71
+ .then((res) => res.data);
72
+ // Select first customer
73
+ return customer || null;
74
+ });
75
+ }
76
+ function getTimeSheets(params) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const { payPeriodId, employeeId } = params;
79
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v2/admin/time-sheets/by-period`;
80
+ const access_token = yield getAccessToken();
81
+ const customer = yield axios_1.default
82
+ .get(url, {
83
+ headers: {
84
+ Authorization: "Bearer " + access_token,
85
+ },
86
+ params: {
87
+ employeeId,
88
+ payPeriodId,
89
+ },
90
+ })
91
+ .then((res) => res.data);
92
+ // Select first customer
93
+ return customer || null;
94
+ });
95
+ }
54
96
  function getEmployeeByCustomerId(customerId) {
55
97
  return __awaiter(this, void 0, void 0, function* () {
56
98
  const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/customers/${customerId}/employee-info`;
@@ -0,0 +1,41 @@
1
+ export interface PayPeriod {
2
+ id: number;
3
+ start_date: string;
4
+ end_date: string;
5
+ principal_due_date: string;
6
+ limit_total_enable: boolean;
7
+ limit_total_allowed: any;
8
+ limit_total_accumulated: number;
9
+ config: Config;
10
+ config_name: string;
11
+ created_at: string;
12
+ }
13
+ export interface Config {
14
+ id: number;
15
+ active: boolean;
16
+ code: string;
17
+ name: string;
18
+ note: string;
19
+ limit_total_enable: boolean;
20
+ limit_total_allowed: any;
21
+ partner_id: number;
22
+ partner_name: string;
23
+ organization_structure_id: number;
24
+ organization_structure_name: string;
25
+ config_type: string;
26
+ month_start_day: number;
27
+ month_start_at: string;
28
+ cycle_start_at: any;
29
+ cycle_day_num: any;
30
+ created_at: string;
31
+ amount_for_preview: number;
32
+ editable: boolean;
33
+ marker: string;
34
+ duration_type: string;
35
+ extend: number;
36
+ time: string;
37
+ pay_period_num_from_current: number;
38
+ path: any;
39
+ version_number: number;
40
+ previous_config_id: any;
41
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export interface TimeSheet {
2
+ id: string;
3
+ employee_id: number;
4
+ employee_full_name: any;
5
+ employee_code: any;
6
+ date: string;
7
+ value: number;
8
+ created_at: string;
9
+ check_in: string;
10
+ check_out: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -65,7 +65,7 @@ const BASE_REQUIRED_CRITERIA = {
65
65
  longest_overdue_bill: "<=10 days",
66
66
  outstanding_balance: "0",
67
67
  parnter_contract_expirity: "Not yet expired",
68
- time_keepper: "Comming ...",
68
+ time_sheet: "The data exists",
69
69
  geofencing_status: "??",
70
70
  };
71
71
  const EWA_02_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
@@ -78,6 +78,15 @@ function accessibleTool(phoneNumber) {
78
78
  throw "Customer not found";
79
79
  }
80
80
  const { employee, partner } = yield (0, gimo_service_1.getEmployeeByCustomerId)(customer.customer_id);
81
+ let periods = [];
82
+ let timeSheets = [];
83
+ if (employee) {
84
+ const payPeriods = yield (0, gimo_service_1.getPayPeriods)({ orgId: employee === null || employee === void 0 ? void 0 : employee.organization_id, parnterId: employee.partner_id });
85
+ if (payPeriods === null || payPeriods === void 0 ? void 0 : payPeriods.length) {
86
+ periods = payPeriods;
87
+ timeSheets = yield (0, gimo_service_1.getTimeSheets)({ payPeriodId: payPeriods[0].id, employeeId: employee.id });
88
+ }
89
+ }
81
90
  const { debt_collection, onboard_method } = partner || {};
82
91
  const productType = getProductType({
83
92
  debt_collection_type: debt_collection || "",
@@ -89,6 +98,7 @@ function accessibleTool(phoneNumber) {
89
98
  seniority: employee === null || employee === void 0 ? void 0 : employee.seniority,
90
99
  working_status: exports.EMPLOYEE_STATUS_MAPS[(employee === null || employee === void 0 ? void 0 : employee.status) || "ACTIVE"],
91
100
  product_type: productType,
101
+ time_sheet: (timeSheets === null || timeSheets === void 0 ? void 0 : timeSheets.length) ? "The data exists" : "The data does't exists",
92
102
  };
93
103
  const getRequriedCriteria = (productType) => {
94
104
  if (productType === PRODUCT_TYPE.EWA_01) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-mcp",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Mcp server for Gm",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,6 +1,8 @@
1
1
  import axios from "axios";
2
2
  import { Gimo } from "./types";
3
3
  import { getEnv } from "../env";
4
+ import { PayPeriod } from "./types/pay-period";
5
+ import { TimeSheet } from "./types/time-keeper";
4
6
 
5
7
  export async function getAccessToken() {
6
8
  const url = `${getEnv().DASH_URL}/api/v1/auth/admin/login`;
@@ -33,6 +35,44 @@ export async function findCustomerEWAByPhonenumber(phoneNumber: string) {
33
35
  return findCustomerEWAById(foundedCustomer.customer_id);
34
36
  }
35
37
 
38
+ export async function getPayPeriods(params: { orgId: number; parnterId: number }) {
39
+ const { orgId, parnterId } = params;
40
+ const url = `${getEnv().DASH_URL}/api/v1/admin/partners/${parnterId}/pay-periods`;
41
+ const access_token = await getAccessToken();
42
+ const customer = await axios
43
+ .get<PayPeriod[]>(url, {
44
+ headers: {
45
+ Authorization: "Bearer " + access_token,
46
+ },
47
+ params: {
48
+ orgId,
49
+ sort: "start_date,desc",
50
+ },
51
+ })
52
+ .then((res) => res.data);
53
+ // Select first customer
54
+ return customer || null;
55
+ }
56
+
57
+ export async function getTimeSheets(params: { payPeriodId: number; employeeId: number }) {
58
+ const { payPeriodId, employeeId } = params;
59
+ const url = `${getEnv().DASH_URL}/api/v2/admin/time-sheets/by-period`;
60
+ const access_token = await getAccessToken();
61
+ const customer = await axios
62
+ .get<TimeSheet[]>(url, {
63
+ headers: {
64
+ Authorization: "Bearer " + access_token,
65
+ },
66
+ params: {
67
+ employeeId,
68
+ payPeriodId,
69
+ },
70
+ })
71
+ .then((res) => res.data);
72
+ // Select first customer
73
+ return customer || null;
74
+ }
75
+
36
76
  export async function getEmployeeByCustomerId(customerId: number) {
37
77
  const url = `${getEnv().DASH_URL}/api/v1/admin/customers/${customerId}/employee-info`;
38
78
  const access_token = await getAccessToken();
@@ -0,0 +1,42 @@
1
+ export interface PayPeriod {
2
+ id: number;
3
+ start_date: string;
4
+ end_date: string;
5
+ principal_due_date: string;
6
+ limit_total_enable: boolean;
7
+ limit_total_allowed: any;
8
+ limit_total_accumulated: number;
9
+ config: Config;
10
+ config_name: string;
11
+ created_at: string;
12
+ }
13
+
14
+ export interface Config {
15
+ id: number;
16
+ active: boolean;
17
+ code: string;
18
+ name: string;
19
+ note: string;
20
+ limit_total_enable: boolean;
21
+ limit_total_allowed: any;
22
+ partner_id: number;
23
+ partner_name: string;
24
+ organization_structure_id: number;
25
+ organization_structure_name: string;
26
+ config_type: string;
27
+ month_start_day: number;
28
+ month_start_at: string;
29
+ cycle_start_at: any;
30
+ cycle_day_num: any;
31
+ created_at: string;
32
+ amount_for_preview: number;
33
+ editable: boolean;
34
+ marker: string;
35
+ duration_type: string;
36
+ extend: number;
37
+ time: string;
38
+ pay_period_num_from_current: number;
39
+ path: any;
40
+ version_number: number;
41
+ previous_config_id: any;
42
+ }
@@ -0,0 +1,11 @@
1
+ export interface TimeSheet {
2
+ id: string;
3
+ employee_id: number;
4
+ employee_full_name: any;
5
+ employee_code: any;
6
+ date: string;
7
+ value: number;
8
+ created_at: string;
9
+ check_in: string;
10
+ check_out: string;
11
+ }
@@ -1,5 +1,12 @@
1
1
  import { CallToolResult } from "@modelcontextprotocol/sdk/types";
2
- import { findCustomerEWAByPhonenumber, getEmployeeByCustomerId } from "../services/gimo.service";
2
+ import {
3
+ findCustomerEWAByPhonenumber,
4
+ getEmployeeByCustomerId,
5
+ getPayPeriods,
6
+ getTimeSheets,
7
+ } from "../services/gimo.service";
8
+ import { PayPeriod } from "../services/types/pay-period";
9
+ import { TimeSheet } from "../services/types/time-keeper";
3
10
 
4
11
  const PRODUCT_TYPE = {
5
12
  EWA_01: "EWA_01",
@@ -59,7 +66,7 @@ const BASE_REQUIRED_CRITERIA = {
59
66
  longest_overdue_bill: "<=10 days",
60
67
  outstanding_balance: "0",
61
68
  parnter_contract_expirity: "Not yet expired",
62
- time_keepper: "Comming ...",
69
+ time_sheet: "The data exists",
63
70
  geofencing_status: "??",
64
71
  };
65
72
 
@@ -80,6 +87,15 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
80
87
  throw "Customer not found";
81
88
  }
82
89
  const { employee, partner } = await getEmployeeByCustomerId(customer.customer_id);
90
+ let periods: PayPeriod[] = [];
91
+ let timeSheets: TimeSheet[] = [];
92
+ if (employee) {
93
+ const payPeriods = await getPayPeriods({ orgId: employee?.organization_id, parnterId: employee.partner_id });
94
+ if (payPeriods?.length) {
95
+ periods = payPeriods;
96
+ timeSheets = await getTimeSheets({ payPeriodId: payPeriods[0].id, employeeId: employee.id });
97
+ }
98
+ }
83
99
  const { debt_collection, onboard_method } = partner || {};
84
100
 
85
101
  const productType = getProductType({
@@ -93,6 +109,7 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
93
109
  seniority: employee?.seniority,
94
110
  working_status: EMPLOYEE_STATUS_MAPS[employee?.status || "ACTIVE"],
95
111
  product_type: productType,
112
+ time_sheet: timeSheets?.length ? "The data exists" : "The data does't exists",
96
113
  };
97
114
 
98
115
  const getRequriedCriteria = (productType: keyof typeof PRODUCT_TYPE | null) => {