@twentyhq/teams 1.1.2 → 1.2.0

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 (50) hide show
  1. package/dependencies/yarn.lock +723 -3
  2. package/manifest.json +46 -29
  3. package/package.json +4 -2
  4. package/src/features/chat/logic-functions/teams-activities-enqueue.mjs +366 -152
  5. package/src/features/chat/logic-functions/teams-activities-enqueue.mjs.map +4 -4
  6. package/src/features/chat/logic-functions/teams-activities-enqueue.ts +1 -1
  7. package/src/features/chat/logic-functions/teams-activities-resolver.mjs +500 -40
  8. package/src/features/chat/logic-functions/teams-activities-resolver.mjs.map +4 -4
  9. package/src/features/chat/logic-functions/teams-activities-resolver.ts +13 -2
  10. package/src/features/chat/logic-functions/teams-list-unlinked-users.mjs +95 -61
  11. package/src/features/chat/logic-functions/teams-list-unlinked-users.mjs.map +4 -4
  12. package/src/features/chat/logic-functions/teams-match-user-links.mjs +105 -86
  13. package/src/features/chat/logic-functions/teams-match-user-links.mjs.map +4 -4
  14. package/src/features/chat/logic-functions/teams-register-connection.mjs +119 -101
  15. package/src/features/chat/logic-functions/teams-register-connection.mjs.map +4 -4
  16. package/src/features/chat/logic-functions/teams-register-connection.ts +1 -1
  17. package/src/features/chat/logic-functions/teams-search-users.mjs +96 -62
  18. package/src/features/chat/logic-functions/teams-search-users.mjs.map +4 -4
  19. package/src/features/chat/logic-functions/teams-set-user-link.mjs +88 -54
  20. package/src/features/chat/logic-functions/teams-set-user-link.mjs.map +4 -4
  21. package/src/features/chat/logic-functions/teams-tenant-release.mjs +72 -41
  22. package/src/features/chat/logic-functions/teams-tenant-release.mjs.map +4 -4
  23. package/src/features/transcripts/logic-functions/teams-count-transcript-history.mjs +99 -68
  24. package/src/features/transcripts/logic-functions/teams-count-transcript-history.mjs.map +4 -4
  25. package/src/features/transcripts/logic-functions/teams-import-transcript-history.mjs +99 -68
  26. package/src/features/transcripts/logic-functions/teams-import-transcript-history.mjs.map +4 -4
  27. package/src/features/transcripts/logic-functions/teams-import-transcript.mjs +96 -65
  28. package/src/features/transcripts/logic-functions/teams-import-transcript.mjs.map +4 -4
  29. package/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.mjs +89 -58
  30. package/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.mjs.map +4 -4
  31. package/src/features/transcripts/logic-functions/teams-sync-transcript.mjs +96 -65
  32. package/src/features/transcripts/logic-functions/teams-sync-transcript.mjs.map +4 -4
  33. package/src/features/transcripts/logic-functions/teams-transcript-history-count.mjs +0 -1
  34. package/src/features/transcripts/logic-functions/teams-transcript-history-count.mjs.map +2 -2
  35. package/src/features/transcripts/logic-functions/teams-transcript-history-import.mjs +0 -1
  36. package/src/features/transcripts/logic-functions/teams-transcript-history-import.mjs.map +2 -2
  37. package/src/features/transcripts/logic-functions/teams-transcript-history-status.mjs +0 -1
  38. package/src/features/transcripts/logic-functions/teams-transcript-history-status.mjs.map +2 -2
  39. package/src/features/transcripts/logic-functions/teams-transcripts-webhook.mjs +104 -73
  40. package/src/features/transcripts/logic-functions/teams-transcripts-webhook.mjs.map +4 -4
  41. package/src/features/transcripts/logic-functions/teams-uninstall.mjs +72 -41
  42. package/src/features/transcripts/logic-functions/teams-uninstall.mjs.map +4 -4
  43. package/src/front-components/settings.front-component.mjs +113 -113
  44. package/src/front-components/settings.front-component.mjs.map +4 -4
  45. package/src/logic-functions/teams-health-check.mjs +46 -25
  46. package/src/logic-functions/teams-health-check.mjs.map +4 -4
  47. package/src/logic-functions/teams-health-check.ts +21 -6
  48. package/src/logic-functions/teams-post-install.mjs +1270 -0
  49. package/src/logic-functions/teams-post-install.mjs.map +7 -0
  50. package/src/logic-functions/teams-post-install.ts +15 -0
@@ -124,10 +124,10 @@ var require_convenience = __commonJS({
124
124
  return structural_1.isArray(term) && term.length > 0;
125
125
  };
126
126
  exports.isNonEmptyArray = isNonEmptyArray;
127
- var isNonEmptyString18 = (term) => {
127
+ var isNonEmptyString19 = (term) => {
128
128
  return primitives_1.isString(term) && term.length > 0;
129
129
  };
130
- exports.isNonEmptyString = isNonEmptyString18;
130
+ exports.isNonEmptyString = isNonEmptyString19;
131
131
  var isNumberOrNaN = (term) => {
132
132
  return typeof term === "number";
133
133
  };
@@ -216,7 +216,7 @@ var defineLogicFunction = __defineFactoryStub;
216
216
  var TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER = "06c3e7ae-c2b6-428d-9c2b-d8b5b809be53";
217
217
 
218
218
  // src/features/chat/logic-functions/utils/register-teams-connection.ts
219
- var import_guards15 = __toESM(require_build());
219
+ var import_guards16 = __toESM(require_build());
220
220
 
221
221
  // node_modules/twenty-sdk/dist/logic-function/index.mjs
222
222
  var import_guards = __toESM(require_build(), 1);
@@ -484,10 +484,10 @@ var deleteTeamsTenantClaimConflict = async ({
484
484
  };
485
485
 
486
486
  // src/features/chat/logic-functions/utils/fetch-teams-tenant-id.ts
487
- var import_guards5 = __toESM(require_build());
487
+ var import_guards6 = __toESM(require_build());
488
488
 
489
489
  // src/features/transcripts/logic-functions/utils/fetch-graph-response.ts
490
- var import_guards4 = __toESM(require_build());
490
+ var import_guards5 = __toESM(require_build());
491
491
 
492
492
  // node_modules/twenty-sdk/dist/utils/index.mjs
493
493
  var import_guards3 = __toESM(require_build(), 1);
@@ -528,62 +528,93 @@ var resolveGraphUrlOrThrow = (url) => {
528
528
  return resolvedUrl.toString();
529
529
  };
530
530
 
531
- // src/features/transcripts/logic-functions/utils/sleep-for-milliseconds.ts
531
+ // src/utils/parse-retry-after-ms.ts
532
+ var import_guards4 = __toESM(require_build());
533
+ var parseRetryAfterMs = (retryAfter) => {
534
+ if (!(0, import_guards4.isNonEmptyString)(retryAfter)) {
535
+ return void 0;
536
+ }
537
+ const retryAfterSeconds = Number(retryAfter);
538
+ if (Number.isFinite(retryAfterSeconds)) {
539
+ return Math.max(retryAfterSeconds * 1e3, 0);
540
+ }
541
+ const retryAtMs = Date.parse(retryAfter);
542
+ return Number.isNaN(retryAtMs) ? void 0 : Math.max(retryAtMs - Date.now(), 0);
543
+ };
544
+
545
+ // src/utils/sleep-for-milliseconds.ts
532
546
  var sleepForMilliseconds = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
533
547
 
548
+ // src/utils/fetch-with-retries.ts
549
+ var fetchWithRetries = async ({
550
+ sendRequest,
551
+ maxAttempts,
552
+ isRetryableStatus,
553
+ getRetryDelayMs,
554
+ retryAbortSignal
555
+ }) => {
556
+ const sendAttempt = async ({
557
+ attempt,
558
+ waitedMs
559
+ }) => {
560
+ const response = await sendRequest();
561
+ if (response.ok || !isRetryableStatus(response.status) || attempt + 1 >= maxAttempts) {
562
+ return response;
563
+ }
564
+ const delayMs = getRetryDelayMs({
565
+ attempt,
566
+ retryAfterMs: parseRetryAfterMs(response.headers.get("retry-after")),
567
+ waitedMs
568
+ });
569
+ if (!o(delayMs)) {
570
+ return response;
571
+ }
572
+ await sleepForMilliseconds(delayMs);
573
+ if (o(retryAbortSignal) && retryAbortSignal.aborted) {
574
+ return response;
575
+ }
576
+ await response.body?.cancel();
577
+ return sendAttempt({ attempt: attempt + 1, waitedMs: waitedMs + delayMs });
578
+ };
579
+ return sendAttempt({ attempt: 0, waitedMs: 0 });
580
+ };
581
+
534
582
  // src/features/transcripts/logic-functions/utils/fetch-graph-response.ts
535
- var fetchGraphResponseWithRetries = async ({
583
+ var fetchGraphResponse = async ({
536
584
  accessToken,
537
585
  url,
538
586
  accept,
539
587
  method,
540
- body,
541
- attempt
588
+ body
542
589
  }) => {
543
- const response = await fetch(url, {
544
- method,
545
- redirect: "error",
546
- headers: {
547
- Authorization: `Bearer ${accessToken}`,
548
- Accept: accept,
549
- ...o(body) ? { "Content-Type": "application/json" } : {}
550
- },
551
- body: o(body) ? JSON.stringify(body) : void 0
590
+ const resolvedUrl = resolveGraphUrlOrThrow(url);
591
+ const response = await fetchWithRetries({
592
+ sendRequest: () => fetch(resolvedUrl, {
593
+ method,
594
+ redirect: "error",
595
+ headers: {
596
+ Authorization: `Bearer ${accessToken}`,
597
+ Accept: accept,
598
+ ...o(body) ? { "Content-Type": "application/json" } : {}
599
+ },
600
+ body: o(body) ? JSON.stringify(body) : void 0
601
+ }),
602
+ maxAttempts: GRAPH_REQUEST_MAX_ATTEMPTS,
603
+ isRetryableStatus: (status) => GRAPH_RETRYABLE_STATUSES.has(status),
604
+ getRetryDelayMs: ({ attempt, retryAfterMs }) => o(retryAfterMs) && retryAfterMs > 0 ? retryAfterMs : GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt
552
605
  });
553
606
  if (response.ok) {
554
607
  return response;
555
608
  }
556
- if (GRAPH_RETRYABLE_STATUSES.has(response.status) && attempt + 1 < GRAPH_REQUEST_MAX_ATTEMPTS) {
557
- const retryAfterSeconds = Number(response.headers.get("Retry-After"));
558
- await sleepForMilliseconds(
559
- retryAfterSeconds > 0 ? retryAfterSeconds * 1e3 : GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt
560
- );
561
- return fetchGraphResponseWithRetries({
562
- accessToken,
563
- url,
564
- accept,
565
- method,
566
- body,
567
- attempt: attempt + 1
568
- });
569
- }
570
609
  const errorBody = await response.json().catch(() => ({}));
571
- const innerErrorCode = (0, import_guards4.isNonEmptyString)(errorBody.error?.innerError?.code) ? errorBody.error.innerError.code : void 0;
572
- const message = (0, import_guards4.isNonEmptyString)(errorBody.error?.message) ? errorBody.error.message : response.statusText;
610
+ const innerErrorCode = (0, import_guards5.isNonEmptyString)(errorBody.error?.innerError?.code) ? errorBody.error.innerError.code : void 0;
611
+ const message = (0, import_guards5.isNonEmptyString)(errorBody.error?.message) ? errorBody.error.message : response.statusText;
573
612
  throw new GraphRequestError({
574
- message: `Microsoft Graph request failed (${response.status}${(0, import_guards4.isNonEmptyString)(innerErrorCode) ? ` ${innerErrorCode}` : ""}): ${message}`,
613
+ message: `Microsoft Graph request failed (${response.status}${(0, import_guards5.isNonEmptyString)(innerErrorCode) ? ` ${innerErrorCode}` : ""}): ${message}`,
575
614
  status: response.status,
576
615
  innerErrorCode
577
616
  });
578
617
  };
579
- var fetchGraphResponse = ({
580
- url,
581
- ...request
582
- }) => fetchGraphResponseWithRetries({
583
- ...request,
584
- url: resolveGraphUrlOrThrow(url),
585
- attempt: 0
586
- });
587
618
 
588
619
  // src/features/transcripts/logic-functions/utils/fetch-graph-json.ts
589
620
  var fetchGraphJson = async ({
@@ -610,39 +641,24 @@ var fetchTeamsTenantId = async (accessToken) => {
610
641
  url: "organization?$select=id"
611
642
  });
612
643
  const tenantId = page.value?.[0]?.id;
613
- if (!(0, import_guards5.isNonEmptyString)(tenantId)) {
644
+ if (!(0, import_guards6.isNonEmptyString)(tenantId)) {
614
645
  throw new Error("Microsoft Graph returned no organization to claim");
615
646
  }
616
647
  return tenantId;
617
648
  };
618
649
 
619
- // src/constants/release-flags.ts
620
- var RELEASE_FLAGS = {
621
- IS_CHAT_ASSISTANT_RELEASED: false,
622
- IS_TRANSCRIPT_HISTORY_IMPORT_RELEASED: false
623
- };
624
-
625
650
  // src/features/chat/constants/chat-enabled-application-variable-key.ts
626
651
  var CHAT_ENABLED_APPLICATION_VARIABLE_KEY = "TEAMS_CHAT_ENABLED";
627
652
 
628
- // src/utils/is-feature-enabled.ts
629
- var isFeatureEnabled = ({
630
- isAvailable,
631
- settingValue
632
- }) => isAvailable && settingValue === "true";
633
-
634
653
  // src/features/chat/logic-functions/utils/is-teams-chat-enabled.ts
635
- var isTeamsChatEnabled = () => isFeatureEnabled({
636
- isAvailable: RELEASE_FLAGS.IS_CHAT_ASSISTANT_RELEASED,
637
- settingValue: process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY]
638
- });
654
+ var isTeamsChatEnabled = () => process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY] === "true";
639
655
 
640
656
  // src/features/chat/logic-functions/utils/match-teams-directory-by-email.ts
641
- var import_guards13 = __toESM(require_build());
657
+ var import_guards14 = __toESM(require_build());
642
658
  import { CoreApiClient } from "twenty-client-sdk/core";
643
659
 
644
660
  // src/features/chat/logic-functions/data/find-workspace-member-ids-by-emails.ts
645
- var import_guards6 = __toESM(require_build());
661
+ var import_guards7 = __toESM(require_build());
646
662
 
647
663
  // src/features/chat/logic-functions/utils/escape-sql-like-pattern.ts
648
664
  var escapeSqlLikePattern = (value) => value.replace(/[\\%_]/g, (wildcard) => `\\${wildcard}`);
@@ -684,7 +700,7 @@ var findWorkspaceMemberIdsByEmails = async ({
684
700
  });
685
701
  for (const edge of queryResult.workspaceMembers?.edges ?? []) {
686
702
  const node = edge?.node;
687
- if (!(0, import_guards6.isNonEmptyString)(node?.id) || !(0, import_guards6.isNonEmptyString)(node.userEmail)) {
703
+ if (!(0, import_guards7.isNonEmptyString)(node?.id) || !(0, import_guards7.isNonEmptyString)(node.userEmail)) {
688
704
  continue;
689
705
  }
690
706
  const email = node.userEmail.toLowerCase();
@@ -696,7 +712,7 @@ var findWorkspaceMemberIdsByEmails = async ({
696
712
  workspaceMemberIdByEmail.set(email, node.id);
697
713
  }
698
714
  const pageInfo = queryResult.workspaceMembers?.pageInfo;
699
- if (!pageInfo?.hasNextPage || !(0, import_guards6.isNonEmptyString)(pageInfo.endCursor)) {
715
+ if (!pageInfo?.hasNextPage || !(0, import_guards7.isNonEmptyString)(pageInfo.endCursor)) {
700
716
  break;
701
717
  }
702
718
  after = pageInfo.endCursor;
@@ -712,7 +728,7 @@ var findWorkspaceMemberIdsByEmails = async ({
712
728
  };
713
729
 
714
730
  // src/features/chat/logic-functions/data/list-linked-teams-user-aad-object-ids.ts
715
- var import_guards7 = __toESM(require_build());
731
+ var import_guards8 = __toESM(require_build());
716
732
  var LINKS_PER_PAGE = 200;
717
733
  var MAX_PAGES = 50;
718
734
  var listLinkedTeamsUserAadObjectIdsOrThrow = async ({
@@ -727,7 +743,7 @@ var listLinkedTeamsUserAadObjectIdsOrThrow = async ({
727
743
  __args: {
728
744
  filter: { teamsTenantId: { eq: teamsTenantId } },
729
745
  first: LINKS_PER_PAGE,
730
- ...(0, import_guards7.isNonEmptyString)(after) ? { after } : {}
746
+ ...(0, import_guards8.isNonEmptyString)(after) ? { after } : {}
731
747
  },
732
748
  edges: { node: { teamsUserAadObjectId: true } },
733
749
  pageInfo: { hasNextPage: true, endCursor: true }
@@ -735,12 +751,12 @@ var listLinkedTeamsUserAadObjectIdsOrThrow = async ({
735
751
  });
736
752
  for (const edge of queryResult.teamsUserLinks?.edges ?? []) {
737
753
  const teamsUserAadObjectId = edge?.node?.teamsUserAadObjectId;
738
- if ((0, import_guards7.isNonEmptyString)(teamsUserAadObjectId)) {
754
+ if ((0, import_guards8.isNonEmptyString)(teamsUserAadObjectId)) {
739
755
  linkedAadObjectIds.add(teamsUserAadObjectId);
740
756
  }
741
757
  }
742
758
  const pageInfo = queryResult.teamsUserLinks?.pageInfo;
743
- if (!pageInfo?.hasNextPage || !(0, import_guards7.isNonEmptyString)(pageInfo.endCursor)) {
759
+ if (!pageInfo?.hasNextPage || !(0, import_guards8.isNonEmptyString)(pageInfo.endCursor)) {
744
760
  return linkedAadObjectIds;
745
761
  }
746
762
  after = pageInfo.endCursor;
@@ -751,11 +767,11 @@ var listLinkedTeamsUserAadObjectIdsOrThrow = async ({
751
767
  };
752
768
 
753
769
  // src/features/chat/logic-functions/utils/collect-graph-users.ts
754
- var import_guards9 = __toESM(require_build());
770
+ var import_guards10 = __toESM(require_build());
755
771
 
756
772
  // src/features/chat/logic-functions/utils/is-linkable-graph-user.ts
757
- var import_guards8 = __toESM(require_build());
758
- var isLinkableGraphUser = (user) => (0, import_guards8.isNonEmptyString)(user.id) && ((0, import_guards8.isNonEmptyString)(user.mail) || (0, import_guards8.isNonEmptyString)(user.userPrincipalName));
773
+ var import_guards9 = __toESM(require_build());
774
+ var isLinkableGraphUser = (user) => (0, import_guards9.isNonEmptyString)(user.id) && ((0, import_guards9.isNonEmptyString)(user.mail) || (0, import_guards9.isNonEmptyString)(user.userPrincipalName));
759
775
 
760
776
  // src/features/chat/logic-functions/utils/collect-graph-users.ts
761
777
  var DEFAULT_MAX_PAGES = 5;
@@ -770,7 +786,7 @@ var collectGraphUsers = async ({
770
786
  const seenAadObjectIds = /* @__PURE__ */ new Set();
771
787
  let nextUrl = url;
772
788
  for (let page = 0; page < maxPages; page += 1) {
773
- if (!(0, import_guards9.isNonEmptyString)(nextUrl)) {
789
+ if (!(0, import_guards10.isNonEmptyString)(nextUrl)) {
774
790
  return { users, isTruncated: false };
775
791
  }
776
792
  const pageResult = await fetchGraphJson({
@@ -792,24 +808,24 @@ var collectGraphUsers = async ({
792
808
  users.push(user);
793
809
  }
794
810
  if (o(maxUsers) && users.length >= maxUsers) {
795
- return { users, isTruncated: (0, import_guards9.isNonEmptyString)(nextUrl) };
811
+ return { users, isTruncated: (0, import_guards10.isNonEmptyString)(nextUrl) };
796
812
  }
797
813
  }
798
- return { users, isTruncated: (0, import_guards9.isNonEmptyString)(nextUrl) };
814
+ return { users, isTruncated: (0, import_guards10.isNonEmptyString)(nextUrl) };
799
815
  };
800
816
 
801
817
  // src/features/chat/logic-functions/utils/get-teams-directory-user-email.ts
802
- var import_guards10 = __toESM(require_build());
818
+ var import_guards11 = __toESM(require_build());
803
819
  var GUEST_USER_PRINCIPAL_NAME_MARKER = "#EXT#";
804
820
  var getTeamsDirectoryUserEmail = (user) => {
805
- if ((0, import_guards10.isNonEmptyString)(user.userPrincipalName) && user.userPrincipalName.includes(GUEST_USER_PRINCIPAL_NAME_MARKER)) {
821
+ if ((0, import_guards11.isNonEmptyString)(user.userPrincipalName) && user.userPrincipalName.includes(GUEST_USER_PRINCIPAL_NAME_MARKER)) {
806
822
  return void 0;
807
823
  }
808
- return [user.mail, user.userPrincipalName].find(import_guards10.isNonEmptyString);
824
+ return [user.mail, user.userPrincipalName].find(import_guards11.isNonEmptyString);
809
825
  };
810
826
 
811
827
  // src/features/chat/logic-functions/utils/link-teams-directory-candidates.ts
812
- var import_guards11 = __toESM(require_build());
828
+ var import_guards12 = __toESM(require_build());
813
829
 
814
830
  // src/features/chat/logic-functions/constants/teams-user-link-source.ts
815
831
  var TEAMS_USER_LINK_SOURCE = {
@@ -872,7 +888,7 @@ var toTeamsUserLinkDraft = ({
872
888
  teamsTenantId,
873
889
  teamsUserAadObjectId: candidate.teamsUserAadObjectId,
874
890
  workspaceMemberId: candidate.workspaceMemberId,
875
- name: (0, import_guards11.isNonEmptyString)(candidate.displayName) ? candidate.displayName : candidate.teamsUserAadObjectId,
891
+ name: (0, import_guards12.isNonEmptyString)(candidate.displayName) ? candidate.displayName : candidate.teamsUserAadObjectId,
876
892
  source: TEAMS_USER_LINK_SOURCE.AUTO
877
893
  });
878
894
  var createCandidatesOneByOne = async ({
@@ -943,7 +959,7 @@ var linkTeamsDirectoryCandidates = async ({
943
959
  };
944
960
 
945
961
  // src/features/chat/logic-functions/utils/plan-teams-directory-match.ts
946
- var import_guards12 = __toESM(require_build());
962
+ var import_guards13 = __toESM(require_build());
947
963
  var planDirectoryUser = ({
948
964
  user,
949
965
  workspaceMemberIdByEmail,
@@ -953,7 +969,7 @@ var planDirectoryUser = ({
953
969
  return { status: "alreadyLinked" };
954
970
  }
955
971
  const email = getTeamsDirectoryUserEmail(user);
956
- const workspaceMemberId = (0, import_guards12.isNonEmptyString)(email) ? workspaceMemberIdByEmail.get(email.toLowerCase()) : void 0;
972
+ const workspaceMemberId = (0, import_guards13.isNonEmptyString)(email) ? workspaceMemberIdByEmail.get(email.toLowerCase()) : void 0;
957
973
  if (!o(workspaceMemberId)) {
958
974
  return { status: "unmatched" };
959
975
  }
@@ -962,7 +978,7 @@ var planDirectoryUser = ({
962
978
  candidate: {
963
979
  teamsUserAadObjectId: user.id,
964
980
  workspaceMemberId,
965
- displayName: (0, import_guards12.isNonEmptyString)(user.displayName) ? user.displayName : void 0
981
+ displayName: (0, import_guards13.isNonEmptyString)(user.displayName) ? user.displayName : void 0
966
982
  }
967
983
  };
968
984
  };
@@ -1023,7 +1039,7 @@ var runTeamsDirectoryMatch = async ({
1023
1039
  ]);
1024
1040
  const { workspaceMemberIdByEmail, ambiguousEmailCount } = await findWorkspaceMemberIdsByEmails({
1025
1041
  client,
1026
- emails: directory.users.map(getTeamsDirectoryUserEmail).filter(import_guards13.isNonEmptyString)
1042
+ emails: directory.users.map(getTeamsDirectoryUserEmail).filter(import_guards14.isNonEmptyString)
1027
1043
  });
1028
1044
  const { candidates, alreadyLinkedCount, unmatchedCount } = planTeamsDirectoryMatch({
1029
1045
  users: directory.users,
@@ -1068,7 +1084,7 @@ var matchTeamsDirectoryByEmail = async ({
1068
1084
  };
1069
1085
 
1070
1086
  // src/features/chat/logic-functions/utils/release-teams-connection-tenant.ts
1071
- var import_guards14 = __toESM(require_build());
1087
+ var import_guards15 = __toESM(require_build());
1072
1088
 
1073
1089
  // src/features/transcripts/constants/teams-provider-name.ts
1074
1090
  var TEAMS_PROVIDER_NAME = "microsoft-teams";
@@ -1105,7 +1121,7 @@ var releaseTeamsConnectionTenant = async ({
1105
1121
  }) => {
1106
1122
  const connectedAccountTenantKvKey = buildTeamsConnectedAccountTenantKvKey(connectedAccountId);
1107
1123
  const tenantId = await ge.get(connectedAccountTenantKvKey);
1108
- if (!(0, import_guards14.isNonEmptyString)(tenantId)) {
1124
+ if (!(0, import_guards15.isNonEmptyString)(tenantId)) {
1109
1125
  return { releasedTenantId: null };
1110
1126
  }
1111
1127
  const connectionIds = await listTeamsConnectionIds();
@@ -1165,10 +1181,10 @@ var matchTeamsDirectoryOnConnect = async ({
1165
1181
  };
1166
1182
  var registerTeamsConnection = async ({
1167
1183
  connectedAccountId,
1168
- workspaceId
1184
+ workspaceId,
1185
+ shouldMatchDirectory = true
1169
1186
  }) => {
1170
- const isChatEnabled = isTeamsChatEnabled();
1171
- const connection = isChatEnabled ? await x(connectedAccountId) : void 0;
1187
+ const connection = await x(connectedAccountId);
1172
1188
  if (connection?.scope !== "WORKSPACE") {
1173
1189
  await releaseTeamsConnectionTenant({ connectedAccountId });
1174
1190
  await deleteTeamsTenantClaimConflict({ connectedAccountId });
@@ -1178,7 +1194,7 @@ var registerTeamsConnection = async ({
1178
1194
  const tenantId = await fetchTeamsTenantId(accessToken);
1179
1195
  const connectedAccountTenantKvKey = buildTeamsConnectedAccountTenantKvKey(connectedAccountId);
1180
1196
  const previousTenantId = await ge.get(connectedAccountTenantKvKey);
1181
- if ((0, import_guards15.isNonEmptyString)(previousTenantId) && previousTenantId !== tenantId) {
1197
+ if ((0, import_guards16.isNonEmptyString)(previousTenantId) && previousTenantId !== tenantId) {
1182
1198
  await releaseTeamsConnectionTenant({ connectedAccountId });
1183
1199
  }
1184
1200
  await ge.set(connectedAccountTenantKvKey, tenantId);
@@ -1192,12 +1208,14 @@ var registerTeamsConnection = async ({
1192
1208
  return { claimedTenantId: null, conflictingTenantId: tenantId };
1193
1209
  }
1194
1210
  await deleteTeamsTenantClaimConflict({ connectedAccountId });
1195
- await matchTeamsDirectoryOnConnect({ connection, accessToken, tenantId });
1211
+ if (shouldMatchDirectory && isTeamsChatEnabled()) {
1212
+ await matchTeamsDirectoryOnConnect({ connection, accessToken, tenantId });
1213
+ }
1196
1214
  return { claimedTenantId: tenantId };
1197
1215
  };
1198
1216
 
1199
1217
  // src/features/transcripts/logic-functions/utils/register-teams-transcript-subscription.ts
1200
- var import_guards19 = __toESM(require_build());
1218
+ var import_guards20 = __toESM(require_build());
1201
1219
 
1202
1220
  // src/features/transcripts/logic-functions/constants/teams-transcript-subscription-kv-key-prefix.ts
1203
1221
  var TEAMS_TRANSCRIPT_SUBSCRIPTION_KV_KEY_PREFIX = "teams-transcript-subscription";
@@ -1220,17 +1238,17 @@ var TEAMS_COUNT_TRANSCRIPT_HISTORY_UNIVERSAL_IDENTIFIER = "1a853a42-2366-4344-b6
1220
1238
  var TEAMS_TRANSCRIPTS_WEBHOOK_CONNECTION_QUERY_PARAMETER = "connectedAccountId";
1221
1239
 
1222
1240
  // src/utils/get-server-route-url.ts
1223
- var import_guards16 = __toESM(require_build());
1241
+ var import_guards17 = __toESM(require_build());
1224
1242
  var getServerRouteUrl = ({
1225
1243
  apiUrl,
1226
1244
  logicFunctionUniversalIdentifier
1227
1245
  }) => {
1228
1246
  const serverRoutesUrl = process.env.TWENTY_SERVER_ROUTES_URL;
1229
1247
  const serverRouteUrl = new URL(
1230
- (0, import_guards16.isNonEmptyString)(serverRoutesUrl) ? serverRoutesUrl : apiUrl
1248
+ (0, import_guards17.isNonEmptyString)(serverRoutesUrl) ? serverRoutesUrl : apiUrl
1231
1249
  );
1232
1250
  const basePath = serverRouteUrl.pathname.replace(/\/+$/, "");
1233
- serverRouteUrl.pathname = (0, import_guards16.isNonEmptyString)(serverRoutesUrl) ? `${basePath}/${logicFunctionUniversalIdentifier}` : `${basePath}/webhooks/server/${logicFunctionUniversalIdentifier}`;
1251
+ serverRouteUrl.pathname = (0, import_guards17.isNonEmptyString)(serverRoutesUrl) ? `${basePath}/${logicFunctionUniversalIdentifier}` : `${basePath}/webhooks/server/${logicFunctionUniversalIdentifier}`;
1234
1252
  return serverRouteUrl;
1235
1253
  };
1236
1254
 
@@ -1251,7 +1269,7 @@ var buildTeamsTranscriptsWebhookUrl = ({
1251
1269
  };
1252
1270
 
1253
1271
  // src/features/transcripts/logic-functions/utils/create-teams-transcript-subscription.ts
1254
- var import_guards17 = __toESM(require_build());
1272
+ var import_guards18 = __toESM(require_build());
1255
1273
  import { randomBytes } from "node:crypto";
1256
1274
 
1257
1275
  // src/features/transcripts/logic-functions/constants/graph-created-change-type.ts
@@ -1269,7 +1287,7 @@ var createTeamsTranscriptSubscription = async ({
1269
1287
  accessToken,
1270
1288
  url: "me?$select=id"
1271
1289
  });
1272
- if (!(0, import_guards17.isNonEmptyString)(user.id)) {
1290
+ if (!(0, import_guards18.isNonEmptyString)(user.id)) {
1273
1291
  throw new Error("Microsoft Graph returned no user for the connection");
1274
1292
  }
1275
1293
  const clientState = randomBytes(32).toString("base64url");
@@ -1289,7 +1307,7 @@ var createTeamsTranscriptSubscription = async ({
1289
1307
  clientState
1290
1308
  }
1291
1309
  });
1292
- if (!(0, import_guards17.isNonEmptyString)(subscription.id) || !(0, import_guards17.isNonEmptyString)(subscription.expirationDateTime)) {
1310
+ if (!(0, import_guards18.isNonEmptyString)(subscription.id) || !(0, import_guards18.isNonEmptyString)(subscription.expirationDateTime)) {
1293
1311
  throw new Error(
1294
1312
  "Microsoft Graph returned an invalid transcript subscription"
1295
1313
  );
@@ -1327,7 +1345,7 @@ var isTeamsConnectionListed = async (connectedAccountId) => (await listTeamsConn
1327
1345
  );
1328
1346
 
1329
1347
  // src/features/transcripts/logic-functions/utils/renew-teams-transcript-subscription.ts
1330
- var import_guards18 = __toESM(require_build());
1348
+ var import_guards19 = __toESM(require_build());
1331
1349
  var renewTeamsTranscriptSubscription = async ({
1332
1350
  accessToken,
1333
1351
  subscriptionId
@@ -1342,7 +1360,7 @@ var renewTeamsTranscriptSubscription = async ({
1342
1360
  ).toISOString()
1343
1361
  }
1344
1362
  });
1345
- if (!(0, import_guards18.isNonEmptyString)(subscription.expirationDateTime)) {
1363
+ if (!(0, import_guards19.isNonEmptyString)(subscription.expirationDateTime)) {
1346
1364
  throw new Error(
1347
1365
  "Microsoft Graph returned an invalid transcript subscription"
1348
1366
  );
@@ -1417,7 +1435,7 @@ var registerTeamsTranscriptSubscription = async ({
1417
1435
  return { transcriptSubscriptionId: null };
1418
1436
  }
1419
1437
  const apiUrl = process.env.TWENTY_API_URL;
1420
- if (!(0, import_guards19.isNonEmptyString)(apiUrl)) {
1438
+ if (!(0, import_guards20.isNonEmptyString)(apiUrl)) {
1421
1439
  throw new Error(
1422
1440
  "TWENTY_API_URL is required to subscribe to Teams transcripts"
1423
1441
  );
@@ -1663,7 +1681,7 @@ var teamsRegisterConnectionHandler = async (payload, context) => {
1663
1681
  var teams_register_connection_default = defineLogicFunction({
1664
1682
  universalIdentifier: TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER,
1665
1683
  name: "teams-register-connection",
1666
- description: "Runs when a Microsoft Teams connection is added. For a workspace-shared connection with chat enabled, reads the Microsoft tenant id from Graph and claims it for this workspace under the server-scoped teams-tenant:<tenant_id> key, so activities from that tenant route here. When another workspace already holds that tenant, records the conflict for the health check instead of claiming. Then links every directory user whose email matches a workspace member, which is why this hook needs the same budget as the on-demand match route. Personal connections are left alone. With transcripts enabled, also subscribes to the transcripts of the meetings the account organizes, so Microsoft Graph notifies the app when one is ready, and starts importing the last 31 days of transcripts once per connection, again on a reconnect when that import failed or stalled.",
1684
+ description: "Runs when a Microsoft Teams connection is added. For a workspace-shared connection, reads the Microsoft tenant id from Graph and claims it for this workspace under the server-scoped teams-tenant:<tenant_id> key, whatever the Enable chat setting, so activities from that tenant route here. When another workspace already holds that tenant, records the conflict for the health check instead of claiming. With chat enabled, then links every directory user whose email matches a workspace member, which is why this hook needs the same budget as the on-demand match route. Personal connections are left alone. With transcripts enabled, also subscribes to the transcripts of the meetings the account organizes, so Microsoft Graph notifies the app when one is ready, and starts importing the last 31 days of transcripts once per connection, again on a reconnect when that import failed or stalled.",
1667
1685
  timeoutSeconds: 120,
1668
1686
  handler: teamsRegisterConnectionHandler
1669
1687
  });