Skip to content

Commit b268568

Browse files
committed
Update
1 parent 22bbd51 commit b268568

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/gsuite.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface GoogleContact {
66
email: string;
77
givenName: string;
88
familyName: string;
9-
displayName: string;
109
}
1110

1211
export interface ExistingContact {
@@ -302,6 +301,8 @@ const contactToAtomXml = (contact: GoogleContact): string => {
302301
);
303302
}
304303

304+
const fullName = `${escapeXml(contact.givenName)} ${escapeXml(contact.familyName)}`;
305+
305306
return `<?xml version="1.0" encoding="UTF-8"?>
306307
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
307308
xmlns:gd="http://schemas.google.com/g/2005">
@@ -310,7 +311,7 @@ const contactToAtomXml = (contact: GoogleContact): string => {
310311
<gd:name>
311312
<gd:givenName>${escapeXml(contact.givenName)}</gd:givenName>
312313
<gd:familyName>${escapeXml(contact.familyName)}</gd:familyName>
313-
<gd:fullName>${escapeXml(contact.displayName)}</gd:fullName>
314+
<gd:fullName>${fullName}</gd:fullName>
314315
</gd:name>
315316
${emails.join("\n")}
316317
</atom:entry>`;
@@ -325,8 +326,6 @@ const parseGDataEntry = (entry: any): ExistingContact | null => {
325326

326327
const primaryEmail =
327328
emails.find((e: any) => e.primary === "true")?.address || emails[0].address;
328-
const otherEmail =
329-
emails.find((e: any) => e.rel?.includes("other"))?.address || "";
330329
const name = entry.gd$name || {};
331330

332331
// Extract ID from entry ID (format: https://www.google.com/m8/feeds/contacts/{domain}/base/{id})
@@ -340,7 +339,6 @@ const parseGDataEntry = (entry: any): ExistingContact | null => {
340339
email: primaryEmail || "",
341340
givenName: name.gd$givenName?.$t || "",
342341
familyName: name.gd$familyName?.$t || "",
343-
displayName: name.gd$fullName?.$t || primaryEmail || "",
344342
},
345343
};
346344
};

src/sync.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const contactsDiffer = (
4242
return (
4343
entra.givenName !== google.givenName ||
4444
entra.familyName !== google.familyName ||
45-
entra.displayName !== google.displayName ||
4645
entra.email !== google.email
4746
);
4847
};
@@ -74,22 +73,34 @@ const syncContacts = async (
7473
// Build lookup map for Entra users
7574
const entraMap = new Map<string, GoogleContact>();
7675
let skippedNoName = 0;
76+
let skippedSameDomain = 0;
7777

7878
for (const user of entraUsers) {
79+
// Skip users with no name information
7980
if (!user.familyName || !user.displayName) {
80-
logger.info(
81+
logger.debug(
8182
{ email: user.email, upn: user.upn },
8283
"Skipping user with no first and/or last name information",
8384
);
8485
skippedNoName++;
8586
continue;
8687
}
8788

89+
// Skip users on the same domain (not external)
90+
const userDomain = extractDomain(user.email || user.upn);
91+
if (userDomain === domain) {
92+
logger.debug(
93+
{ email: user.email, upn: user.upn, domain: userDomain },
94+
"Skipping user on same domain (not external)",
95+
);
96+
skippedSameDomain++;
97+
continue;
98+
}
99+
88100
const contact: GoogleContact = {
89101
email: user.email,
90102
givenName: user.givenName,
91103
familyName: user.familyName,
92-
displayName: user.displayName,
93104
};
94105
entraMap.set(getPrimaryEmail(user), contact);
95106
}
@@ -101,6 +112,13 @@ const syncContacts = async (
101112
);
102113
}
103114

115+
if (skippedSameDomain > 0) {
116+
logger.info(
117+
{ skipped: skippedSameDomain, domain },
118+
"Skipped users on same domain (not external)",
119+
);
120+
}
121+
104122
// Determine what operations to perform
105123
const toCreate: GoogleContact[] = [];
106124
const toUpdate: Array<{ id: string; etag: string; contact: GoogleContact }> =

0 commit comments

Comments
 (0)