gm-mcp 2.0.4 → 2.0.6

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,11 +65,13 @@ 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 ...",
69
- geofencing_status: "??",
68
+ time_sheet: "The data exists",
70
69
  };
71
70
  const EWA_02_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
72
71
  const EWA_03_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
72
+ const formatter = (record) => {
73
+ return Object.keys(record).map(key => `${key}: ${record[key]}`).join(',');
74
+ };
73
75
  function accessibleTool(phoneNumber) {
74
76
  return __awaiter(this, void 0, void 0, function* () {
75
77
  try {
@@ -78,6 +80,15 @@ function accessibleTool(phoneNumber) {
78
80
  throw "Customer not found";
79
81
  }
80
82
  const { employee, partner } = yield (0, gimo_service_1.getEmployeeByCustomerId)(customer.customer_id);
83
+ let periods = [];
84
+ let timeSheets = [];
85
+ if (employee) {
86
+ const payPeriods = yield (0, gimo_service_1.getPayPeriods)({ orgId: employee === null || employee === void 0 ? void 0 : employee.organization_id, parnterId: employee.partner_id });
87
+ if (payPeriods === null || payPeriods === void 0 ? void 0 : payPeriods.length) {
88
+ periods = payPeriods;
89
+ timeSheets = yield (0, gimo_service_1.getTimeSheets)({ payPeriodId: payPeriods[0].id, employeeId: employee.id });
90
+ }
91
+ }
81
92
  const { debt_collection, onboard_method } = partner || {};
82
93
  const productType = getProductType({
83
94
  debt_collection_type: debt_collection || "",
@@ -89,6 +100,7 @@ function accessibleTool(phoneNumber) {
89
100
  seniority: employee === null || employee === void 0 ? void 0 : employee.seniority,
90
101
  working_status: exports.EMPLOYEE_STATUS_MAPS[(employee === null || employee === void 0 ? void 0 : employee.status) || "ACTIVE"],
91
102
  product_type: productType,
103
+ time_sheet: (timeSheets === null || timeSheets === void 0 ? void 0 : timeSheets.length) ? "The data exists" : "The data does't exists",
92
104
  };
93
105
  const getRequriedCriteria = (productType) => {
94
106
  if (productType === PRODUCT_TYPE.EWA_01) {
@@ -107,7 +119,11 @@ function accessibleTool(phoneNumber) {
107
119
  current_information: currentInformation,
108
120
  valid_information: requiredCriteria,
109
121
  };
110
- return { content: [{ type: "text", text: JSON.stringify(returnData) }] };
122
+ const result = `
123
+ Customer ${customer.customer_full_name}, partner name ${customer.partner_name} has these informations: ${formatter(currentInformation)}
124
+ Eligibility Criteria for Salary Advances: ${formatter(requiredCriteria)}
125
+ `;
126
+ return { content: [{ type: "text", text: result }] };
111
127
  }
112
128
  catch (error) {
113
129
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-mcp",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
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,8 +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 ...",
63
- geofencing_status: "??",
69
+ time_sheet: "The data exists",
64
70
  };
65
71
 
66
72
  const EWA_02_CRITERIA = {
@@ -73,6 +79,10 @@ const EWA_03_CRITERIA = {
73
79
  dda: "REGISTERED",
74
80
  };
75
81
 
82
+ const formatter = (record:Record<string,any>) => {
83
+ return Object.keys(record).map(key => `${key}: ${record[key]}`).join(',')
84
+ }
85
+
76
86
  export async function accessibleTool(phoneNumber: string): Promise<CallToolResult> {
77
87
  try {
78
88
  const customer = await findCustomerEWAByPhonenumber(phoneNumber);
@@ -80,6 +90,15 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
80
90
  throw "Customer not found";
81
91
  }
82
92
  const { employee, partner } = await getEmployeeByCustomerId(customer.customer_id);
93
+ let periods: PayPeriod[] = [];
94
+ let timeSheets: TimeSheet[] = [];
95
+ if (employee) {
96
+ const payPeriods = await getPayPeriods({ orgId: employee?.organization_id, parnterId: employee.partner_id });
97
+ if (payPeriods?.length) {
98
+ periods = payPeriods;
99
+ timeSheets = await getTimeSheets({ payPeriodId: payPeriods[0].id, employeeId: employee.id });
100
+ }
101
+ }
83
102
  const { debt_collection, onboard_method } = partner || {};
84
103
 
85
104
  const productType = getProductType({
@@ -93,6 +112,7 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
93
112
  seniority: employee?.seniority,
94
113
  working_status: EMPLOYEE_STATUS_MAPS[employee?.status || "ACTIVE"],
95
114
  product_type: productType,
115
+ time_sheet: timeSheets?.length ? "The data exists" : "The data does't exists",
96
116
  };
97
117
 
98
118
  const getRequriedCriteria = (productType: keyof typeof PRODUCT_TYPE | null) => {
@@ -115,7 +135,12 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
115
135
  valid_information: requiredCriteria,
116
136
  };
117
137
 
118
- return { content: [{ type: "text", text: JSON.stringify(returnData) }] };
138
+ const result = `
139
+ Customer ${customer.customer_full_name}, partner name ${customer.partner_name} has these informations: ${formatter(currentInformation)}
140
+ Eligibility Criteria for Salary Advances: ${formatter(requiredCriteria)}
141
+ `
142
+
143
+ return { content: [{ type: "text", text: result }] };
119
144
  } catch (error) {
120
145
  return {
121
146
  content: [