@xuda.io/account_module 1.2.1785 → 1.2.1787

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.
Files changed (2) hide show
  1. package/index.mjs +65 -62
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2070,6 +2070,30 @@ setTimeout(async () => {
2070
2070
 
2071
2071
  //////// CONTACTS //////////////
2072
2072
 
2073
+ function identifyPersonalProvider(domain) {
2074
+ const providers = {
2075
+ 'gmail.com': 'Google Gmail',
2076
+ 'googlemail.com': 'Google Gmail',
2077
+ 'outlook.com': 'Microsoft Outlook',
2078
+ 'hotmail.com': 'Microsoft Hotmail',
2079
+ 'live.com': 'Microsoft Live',
2080
+ 'yahoo.com': 'Yahoo Mail',
2081
+ 'ymail.com': 'Yahoo Mail',
2082
+ 'aol.com': 'AOL Mail',
2083
+ 'icloud.com': 'Apple iCloud',
2084
+ 'me.com': 'Apple iCloud',
2085
+ 'mac.com': 'Apple iCloud',
2086
+ 'protonmail.com': 'ProtonMail',
2087
+ 'proton.me': 'ProtonMail',
2088
+ 'zoho.com': 'Zoho Mail',
2089
+ 'yandex.com': 'Yandex Mail',
2090
+ 'mail.com': 'Mail.com',
2091
+ 'gmx.com': 'GMX Mail',
2092
+ };
2093
+
2094
+ return providers[domain.toLowerCase()];
2095
+ }
2096
+
2073
2097
  export const add_contact = async function (req, job_id, headers) {
2074
2098
  try {
2075
2099
  const { profile_id, uid, email, name, stat, contact_uid, context, source, team_req_id, metadata = {} } = req;
@@ -2095,35 +2119,12 @@ export const add_contact = async function (req, job_id, headers) {
2095
2119
  return { code: -1, data: 'contact already exist', contact_id: user_contacts.docs[0]._id };
2096
2120
  }
2097
2121
 
2098
- function identifyPersonalProvider(domain) {
2099
- const providers = {
2100
- 'gmail.com': 'Google Gmail',
2101
- 'googlemail.com': 'Google Gmail',
2102
- 'outlook.com': 'Microsoft Outlook',
2103
- 'hotmail.com': 'Microsoft Hotmail',
2104
- 'live.com': 'Microsoft Live',
2105
- 'yahoo.com': 'Yahoo Mail',
2106
- 'ymail.com': 'Yahoo Mail',
2107
- 'aol.com': 'AOL Mail',
2108
- 'icloud.com': 'Apple iCloud',
2109
- 'me.com': 'Apple iCloud',
2110
- 'mac.com': 'Apple iCloud',
2111
- 'protonmail.com': 'ProtonMail',
2112
- 'proton.me': 'ProtonMail',
2113
- 'zoho.com': 'Zoho Mail',
2114
- 'yandex.com': 'Yandex Mail',
2115
- 'mail.com': 'Mail.com',
2116
- 'gmx.com': 'GMX Mail',
2117
- };
2118
-
2119
- return providers[domain.toLowerCase()];
2120
- }
2121
-
2122
2122
  /////////////////
2123
2123
 
2124
2124
  let is_spam = false;
2125
2125
  // let email_type_info;
2126
2126
  let account_type_info;
2127
+ let business_info;
2127
2128
  let account_type;
2128
2129
  let cached_contact;
2129
2130
  let business_has_person;
@@ -2157,12 +2158,13 @@ export const add_contact = async function (req, job_id, headers) {
2157
2158
  const is_business = await ai_module.is_business_contact(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2158
2159
  account_type = is_business ? 'business' : 'personal';
2159
2160
  if (is_business) {
2160
- const business_info = await ai_module.get_business_info(uid, '', contact_obj.email, account_profile_info);
2161
+ business_info = await ai_module.get_business_info(uid, '', contact_obj.email, account_profile_info);
2161
2162
  if (business_info.business_name !== 'Not available') {
2162
2163
  //&& !identifyPersonalProvider(business_info.business_domain)
2163
2164
  business_has_person = await ai_module.is_business_contact_has_person(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2164
2165
  } else {
2165
2166
  account_type = 'personal';
2167
+ business_info = undefined;
2166
2168
  }
2167
2169
  }
2168
2170
  if (_.isEmpty(cached_contact) && account_type === 'business' && !business_has_person) {
@@ -2199,54 +2201,55 @@ export const add_contact = async function (req, job_id, headers) {
2199
2201
  metadata,
2200
2202
  is_spam: cached_contact?.is_spam || is_spam,
2201
2203
  business_has_person: cached_contact?.business_has_person || business_has_person,
2204
+ business_info: cached_contact?.business_info || business_info,
2202
2205
 
2203
2206
  account_profiles: [account_profile_obj._id],
2204
2207
  account_type: cached_contact?.account_type || account_type,
2205
2208
  // account_type_info: cached_contact?.account_type_info || account_type_info,
2206
2209
  // email_type_info: cached_contact?.email_type_info || email_type_info,
2207
2210
  };
2208
- if (!_.isEmpty(cached_contact?.business_info)) {
2209
- contact_obj.business_info = _.cloneDeep(cached_contact.business_info);
2210
- } else {
2211
- if (!is_spam) {
2212
- if (account_type === 'business') {
2213
- contact_obj.business_info = await ai_module.get_business_info(uid, contact_obj.name, contact_obj.email, account_profile_info);
2214
- save_xuda_cache(uid, 'contact', contact_obj.domain, null, contact_obj);
2215
-
2216
- // const business_info = await ai_module.get_business_info(uid, contact_obj.name, contact_obj.email, account_profile_info);
2217
- // if (business_info) {
2218
- // const { business_size, business_category, business_sub_category, business_country, business_bio, business_name } = business_info;
2219
- // contact_obj.mainCategory = business_category;
2220
- // contact_obj.subCategory = business_sub_category;
2221
- // contact_obj.business_size = business_size;
2222
- // contact_obj.country = business_country;
2223
- // contact_obj.bio = business_bio;
2224
- // contact_obj.business_name = business_name;
2225
-
2226
- // if (!contact_obj.name) {
2227
- // contact_obj.name = business_name;
2228
- // }
2229
- // }
2230
- }
2211
+ // if (!_.isEmpty(cached_contact?.business_info)) {
2212
+ // contact_obj.business_info = _.cloneDeep(cached_contact.business_info);
2213
+ // } else {
2214
+ if (!is_spam) {
2215
+ // if (account_type === 'business') {
2216
+ // contact_obj.business_info = await ai_module.get_business_info(uid, contact_obj.name, contact_obj.email, account_profile_info);
2217
+ // save_xuda_cache(uid, 'contact', contact_obj.domain, null, contact_obj);
2218
+
2219
+ // // const business_info = await ai_module.get_business_info(uid, contact_obj.name, contact_obj.email, account_profile_info);
2220
+ // // if (business_info) {
2221
+ // // const { business_size, business_category, business_sub_category, business_country, business_bio, business_name } = business_info;
2222
+ // // contact_obj.mainCategory = business_category;
2223
+ // // contact_obj.subCategory = business_sub_category;
2224
+ // // contact_obj.business_size = business_size;
2225
+ // // contact_obj.country = business_country;
2226
+ // // contact_obj.bio = business_bio;
2227
+ // // contact_obj.business_name = business_name;
2228
+
2229
+ // // if (!contact_obj.name) {
2230
+ // // contact_obj.name = business_name;
2231
+ // // }
2232
+ // // }
2233
+ // }
2231
2234
 
2232
- if (account_type === 'personal' || contact_obj?.business_has_person) {
2233
- contact_obj.person_info = await ai_module.get_person_info(uid, contact_obj.name, contact_obj.email, account_profile_info, metadata?.summarized_body);
2234
- if (!contact_obj.name) {
2235
- contact_obj.name = await ai_module.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
2236
- }
2237
- }
2238
- } else {
2235
+ if (account_type === 'personal' || contact_obj?.business_has_person) {
2236
+ contact_obj.person_info = await ai_module.get_person_info(uid, contact_obj.name, contact_obj.email, account_profile_info, metadata?.summarized_body);
2239
2237
  if (!contact_obj.name) {
2240
- contact_obj.name = '';
2238
+ contact_obj.name = await ai_module.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
2241
2239
  }
2242
2240
  }
2243
-
2244
- // if (account_type === 'personal') {
2245
- // if (!contact_obj.name) {
2246
- // contact_obj.name = await ai_module.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
2247
- // }
2248
- // }
2241
+ } else {
2242
+ if (!contact_obj.name) {
2243
+ contact_obj.name = '';
2244
+ }
2249
2245
  }
2246
+
2247
+ // if (account_type === 'personal') {
2248
+ // if (!contact_obj.name) {
2249
+ // contact_obj.name = await ai_module.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
2250
+ // }
2251
+ // }
2252
+ // }
2250
2253
  // else {
2251
2254
  // // get from cache
2252
2255
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1785",
3
+ "version": "1.2.1787",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {