gm-mcp 2.0.2 → 2.0.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.
@@ -1,4 +1,5 @@
1
1
  import { Gimo } from "./types";
2
2
  export declare function getAccessToken(): Promise<string>;
3
3
  export declare function findCustomerEWAByPhonenumber(phoneNumber: string): Promise<Gimo.CustomerEWA | null>;
4
+ export declare function getEmployeeByCustomerId(customerId: number): Promise<Gimo.EmployeeInfo>;
4
5
  export declare function findCustomerEWAById(id: number): Promise<Gimo.CustomerEWA>;
@@ -14,6 +14,7 @@ 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.getEmployeeByCustomerId = getEmployeeByCustomerId;
17
18
  exports.findCustomerEWAById = findCustomerEWAById;
18
19
  const axios_1 = __importDefault(require("axios"));
19
20
  const env_1 = require("../env");
@@ -50,6 +51,21 @@ function findCustomerEWAByPhonenumber(phoneNumber) {
50
51
  return findCustomerEWAById(foundedCustomer.customer_id);
51
52
  });
52
53
  }
54
+ function getEmployeeByCustomerId(customerId) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/customers/${customerId}/employee-info`;
57
+ const access_token = yield getAccessToken();
58
+ const customer = yield axios_1.default
59
+ .get(url, {
60
+ headers: {
61
+ Authorization: "Bearer " + access_token,
62
+ },
63
+ })
64
+ .then((res) => res.data);
65
+ // Select first customer
66
+ return customer || null;
67
+ });
68
+ }
53
69
  function findCustomerEWAById(id) {
54
70
  return __awaiter(this, void 0, void 0, function* () {
55
71
  const customerApiUrl = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/customers/ewa/${id}`;
@@ -125,7 +125,42 @@ export declare namespace Gimo {
125
125
  };
126
126
  link_employees?: LinkedEmployee[];
127
127
  partner_id?: number;
128
- partner?: any;
128
+ partner?: Partner;
129
+ }
130
+ interface Partner {
131
+ id: number;
132
+ name: string;
133
+ full_name: string;
134
+ description: string;
135
+ code: string;
136
+ short_code: string;
137
+ debt_collection: string;
138
+ agreement_number: string;
139
+ short_name: string;
140
+ contact_name: any;
141
+ contact_number: any;
142
+ contact_email: any;
143
+ active: boolean;
144
+ has_income_from_attendance: boolean;
145
+ has_multi_income: any;
146
+ has_income_from_api: any;
147
+ has_income_from_manual: boolean;
148
+ contacts: any[];
149
+ workspace: any;
150
+ organizations: any;
151
+ tax_number: string;
152
+ enable_referral_program: boolean;
153
+ address: string;
154
+ thumbnail: string;
155
+ referral_program_start_date: string;
156
+ referral_program_end_date: string;
157
+ referral_program_status: boolean;
158
+ onboard_method: string;
159
+ debt_payment_method: string;
160
+ allow_access_from_app: boolean;
161
+ not_allow_access_message: any;
162
+ created_at: string;
163
+ employee_card_images: string[];
129
164
  }
130
165
  interface LinkedEmployee {
131
166
  employee_id: number;
@@ -1,2 +1,6 @@
1
1
  import { CallToolResult } from "@modelcontextprotocol/sdk/types";
2
+ export declare const DEBT_COLLECTION_TYPE: {
3
+ readonly PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE";
4
+ readonly DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT";
5
+ };
2
6
  export declare function accessibleTool(phoneNumber: string): Promise<CallToolResult>;
@@ -9,8 +9,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DEBT_COLLECTION_TYPE = void 0;
12
13
  exports.accessibleTool = accessibleTool;
13
14
  const gimo_service_1 = require("../services/gimo.service");
15
+ const PRODUCT_TYPE = {
16
+ EWA_01: "EWA_01",
17
+ EWA_02: "EWA_02",
18
+ EWA_03: "EWA_03",
19
+ EWA_04: "EWA_04",
20
+ };
21
+ const PARTNER_ONBOARD_METHOD = {
22
+ /// truyen thong
23
+ TRADITIONAL: "TRADITIONAL",
24
+ /// cong doan
25
+ UNION: "UNION",
26
+ /// chung minh thu nhap
27
+ EARNING_PROVE: "EARNING_PROVE",
28
+ };
29
+ exports.DEBT_COLLECTION_TYPE = {
30
+ PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE",
31
+ DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT",
32
+ };
33
+ function getProductType(options) {
34
+ const { partner_onboard_method, debt_collection_type } = options;
35
+ if (debt_collection_type === exports.DEBT_COLLECTION_TYPE.PARTNER_IN_CHARGE) {
36
+ return PRODUCT_TYPE.EWA_01;
37
+ }
38
+ if (debt_collection_type === exports.DEBT_COLLECTION_TYPE.DIRECT_FROM_CUSTOMER_ACCOUNT) {
39
+ if (partner_onboard_method === PARTNER_ONBOARD_METHOD.EARNING_PROVE) {
40
+ return PRODUCT_TYPE.EWA_03;
41
+ }
42
+ if (partner_onboard_method === PARTNER_ONBOARD_METHOD.UNION) {
43
+ return PRODUCT_TYPE.EWA_02;
44
+ }
45
+ // if (partner_onboard_method === PARTNER_ONBOARD_METHOD.TRADITIONAL) {
46
+ // return PRODUCT_TYPE.EWA_02;
47
+ // }
48
+ }
49
+ return null;
50
+ }
14
51
  function accessibleTool(phoneNumber) {
15
52
  return __awaiter(this, void 0, void 0, function* () {
16
53
  try {
@@ -18,19 +55,28 @@ function accessibleTool(phoneNumber) {
18
55
  if (!customer) {
19
56
  throw "Customer not found";
20
57
  }
58
+ const { employee, partner } = yield (0, gimo_service_1.getEmployeeByCustomerId)(customer.customer_id);
59
+ const { debt_collection, onboard_method } = partner || {};
60
+ const productType = getProductType({
61
+ debt_collection_type: debt_collection || "",
62
+ partner_onboard_method: onboard_method || "",
63
+ });
21
64
  const currentInformation = {
22
65
  ewa_status: customer === null || customer === void 0 ? void 0 : customer.ewa_status,
23
66
  dda: customer === null || customer === void 0 ? void 0 : customer.dda_status,
24
- seniority: 1,
67
+ seniority: employee === null || employee === void 0 ? void 0 : employee.seniority,
68
+ working_status: employee === null || employee === void 0 ? void 0 : employee.status,
69
+ product_type: productType,
25
70
  };
26
- const validInformation = {
27
- ewa_status: "active",
71
+ const requiredCriteria = {
72
+ ewa_status: "ACTIVE",
28
73
  dda: "REGISTERED",
29
- seniority: ">= 0.3 năm",
74
+ seniority: ">= 0.3 year",
75
+ working_status: "ACTIVE",
30
76
  };
31
77
  const returnData = {
32
78
  current_information: currentInformation,
33
- valid_information: validInformation,
79
+ valid_information: requiredCriteria,
34
80
  };
35
81
  return { content: [{ type: "text", text: JSON.stringify(returnData) }] };
36
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-mcp",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Mcp server for Gm",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -33,6 +33,20 @@ export async function findCustomerEWAByPhonenumber(phoneNumber: string) {
33
33
  return findCustomerEWAById(foundedCustomer.customer_id);
34
34
  }
35
35
 
36
+ export async function getEmployeeByCustomerId(customerId: number) {
37
+ const url = `${getEnv().DASH_URL}/api/v1/admin/customers/${customerId}/employee-info`;
38
+ const access_token = await getAccessToken();
39
+ const customer = await axios
40
+ .get<Gimo.EmployeeInfo>(url, {
41
+ headers: {
42
+ Authorization: "Bearer " + access_token,
43
+ },
44
+ })
45
+ .then((res) => res.data);
46
+ // Select first customer
47
+ return customer || null;
48
+ }
49
+
36
50
  export async function findCustomerEWAById(id: number) {
37
51
  const customerApiUrl = `${getEnv().DASH_URL}/api/v1/admin/customers/ewa/${id}`;
38
52
  const access_token = await getAccessToken();
@@ -128,7 +128,43 @@ export namespace Gimo {
128
128
  employee?: EmployeeV1 & { onboard_id?: number };
129
129
  link_employees?: LinkedEmployee[];
130
130
  partner_id?: number;
131
- partner?: any;
131
+ partner?: Partner;
132
+ }
133
+
134
+ export interface Partner {
135
+ id: number;
136
+ name: string;
137
+ full_name: string;
138
+ description: string;
139
+ code: string;
140
+ short_code: string;
141
+ debt_collection: string;
142
+ agreement_number: string;
143
+ short_name: string;
144
+ contact_name: any;
145
+ contact_number: any;
146
+ contact_email: any;
147
+ active: boolean;
148
+ has_income_from_attendance: boolean;
149
+ has_multi_income: any;
150
+ has_income_from_api: any;
151
+ has_income_from_manual: boolean;
152
+ contacts: any[];
153
+ workspace: any;
154
+ organizations: any;
155
+ tax_number: string;
156
+ enable_referral_program: boolean;
157
+ address: string;
158
+ thumbnail: string;
159
+ referral_program_start_date: string;
160
+ referral_program_end_date: string;
161
+ referral_program_status: boolean;
162
+ onboard_method: string;
163
+ debt_payment_method: string;
164
+ allow_access_from_app: boolean;
165
+ not_allow_access_message: any;
166
+ created_at: string;
167
+ employee_card_images: string[];
132
168
  }
133
169
  export interface LinkedEmployee {
134
170
  employee_id: number;
@@ -1,5 +1,45 @@
1
1
  import { CallToolResult } from "@modelcontextprotocol/sdk/types";
2
- import { findCustomerEWAByPhonenumber } from "../services/gimo.service";
2
+ import { findCustomerEWAByPhonenumber, getEmployeeByCustomerId } from "../services/gimo.service";
3
+
4
+ const PRODUCT_TYPE = {
5
+ EWA_01: "EWA_01",
6
+ EWA_02: "EWA_02",
7
+ EWA_03: "EWA_03",
8
+ EWA_04: "EWA_04",
9
+ } as const;
10
+
11
+ const PARTNER_ONBOARD_METHOD = {
12
+ /// truyen thong
13
+ TRADITIONAL: "TRADITIONAL",
14
+ /// cong doan
15
+ UNION: "UNION",
16
+ /// chung minh thu nhap
17
+ EARNING_PROVE: "EARNING_PROVE",
18
+ } as const;
19
+
20
+ export const DEBT_COLLECTION_TYPE = {
21
+ PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE",
22
+ DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT",
23
+ } as const;
24
+
25
+ function getProductType(options: { partner_onboard_method: string; debt_collection_type: string }) {
26
+ const { partner_onboard_method, debt_collection_type } = options;
27
+ if (debt_collection_type === DEBT_COLLECTION_TYPE.PARTNER_IN_CHARGE) {
28
+ return PRODUCT_TYPE.EWA_01;
29
+ }
30
+ if (debt_collection_type === DEBT_COLLECTION_TYPE.DIRECT_FROM_CUSTOMER_ACCOUNT) {
31
+ if (partner_onboard_method === PARTNER_ONBOARD_METHOD.EARNING_PROVE) {
32
+ return PRODUCT_TYPE.EWA_03;
33
+ }
34
+ if (partner_onboard_method === PARTNER_ONBOARD_METHOD.UNION) {
35
+ return PRODUCT_TYPE.EWA_02;
36
+ }
37
+ // if (partner_onboard_method === PARTNER_ONBOARD_METHOD.TRADITIONAL) {
38
+ // return PRODUCT_TYPE.EWA_02;
39
+ // }
40
+ }
41
+ return null;
42
+ }
3
43
 
4
44
  export async function accessibleTool(phoneNumber: string): Promise<CallToolResult> {
5
45
  try {
@@ -7,21 +47,32 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
7
47
  if (!customer) {
8
48
  throw "Customer not found";
9
49
  }
50
+ const { employee, partner } = await getEmployeeByCustomerId(customer.customer_id);
51
+ const { debt_collection, onboard_method } = partner || {};
52
+
53
+ const productType = getProductType({
54
+ debt_collection_type: debt_collection || "",
55
+ partner_onboard_method: onboard_method || "",
56
+ });
57
+
10
58
  const currentInformation = {
11
59
  ewa_status: customer?.ewa_status,
12
60
  dda: customer?.dda_status,
13
- seniority: 1,
61
+ seniority: employee?.seniority,
62
+ working_status: employee?.status,
63
+ product_type: productType,
14
64
  };
15
65
 
16
- const validInformation: Record<string, string> = {
17
- ewa_status: "active",
66
+ const requiredCriteria: Record<string, any> = {
67
+ ewa_status: "ACTIVE",
18
68
  dda: "REGISTERED",
19
- seniority: ">= 0.3 năm",
69
+ seniority: ">= 0.3 year",
70
+ working_status: "ACTIVE",
20
71
  };
21
72
 
22
73
  const returnData = {
23
74
  current_information: currentInformation,
24
- valid_information: validInformation,
75
+ valid_information: requiredCriteria,
25
76
  };
26
77
 
27
78
  return { content: [{ type: "text", text: JSON.stringify(returnData) }] };