@twentyhq/teams 1.1.2 → 1.2.1

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 +378 -162
  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
@@ -42,7 +42,7 @@ export default defineLogicFunction({
42
42
  universalIdentifier: TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER,
43
43
  name: 'teams-register-connection',
44
44
  description:
45
- '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.',
45
+ '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.',
46
46
  timeoutSeconds: 120,
47
47
  handler: teamsRegisterConnectionHandler,
48
48
  });
@@ -124,10 +124,10 @@ var require_convenience = __commonJS({
124
124
  return structural_1.isArray(term) && term.length > 0;
125
125
  };
126
126
  exports.isNonEmptyArray = isNonEmptyArray2;
127
- var isNonEmptyString8 = (term) => {
127
+ var isNonEmptyString9 = (term) => {
128
128
  return primitives_1.isString(term) && term.length > 0;
129
129
  };
130
- exports.isNonEmptyString = isNonEmptyString8;
130
+ exports.isNonEmptyString = isNonEmptyString9;
131
131
  var isNumberOrNaN = (term) => {
132
132
  return typeof term === "number";
133
133
  };
@@ -219,7 +219,7 @@ var TEAMS_USER_LINKS_SEARCH_ROUTE_PATH = "/teams-user-links/search";
219
219
  var TEAMS_SEARCH_USERS_UNIVERSAL_IDENTIFIER = "f64b6580-718a-4e4a-874c-2026822cbd16";
220
220
 
221
221
  // src/features/chat/logic-functions/handlers/teams-search-users-handler.ts
222
- var import_guards9 = __toESM(require_build());
222
+ var import_guards10 = __toESM(require_build());
223
223
 
224
224
  // src/features/chat/logic-functions/utils/build-teams-user-search-url.ts
225
225
  var escapeODataStringLiteral = (value) => value.replace(/'/g, "''");
@@ -239,14 +239,14 @@ var buildTeamsUserSearchUrl = ({
239
239
  };
240
240
 
241
241
  // src/features/chat/logic-functions/utils/collect-graph-users.ts
242
- var import_guards4 = __toESM(require_build());
242
+ var import_guards5 = __toESM(require_build());
243
243
 
244
244
  // node_modules/twenty-sdk/dist/utils/index.mjs
245
245
  var import_guards = __toESM(require_build(), 1);
246
246
  var o = (n2) => !(0, import_guards.isUndefined)(n2) && !(0, import_guards.isNull)(n2);
247
247
 
248
248
  // src/features/transcripts/logic-functions/utils/fetch-graph-response.ts
249
- var import_guards2 = __toESM(require_build());
249
+ var import_guards3 = __toESM(require_build());
250
250
 
251
251
  // src/features/transcripts/logic-functions/constants/graph-request-max-attempts.ts
252
252
  var GRAPH_REQUEST_MAX_ATTEMPTS = 4;
@@ -283,62 +283,93 @@ var resolveGraphUrlOrThrow = (url) => {
283
283
  return resolvedUrl.toString();
284
284
  };
285
285
 
286
- // src/features/transcripts/logic-functions/utils/sleep-for-milliseconds.ts
286
+ // src/utils/parse-retry-after-ms.ts
287
+ var import_guards2 = __toESM(require_build());
288
+ var parseRetryAfterMs = (retryAfter) => {
289
+ if (!(0, import_guards2.isNonEmptyString)(retryAfter)) {
290
+ return void 0;
291
+ }
292
+ const retryAfterSeconds = Number(retryAfter);
293
+ if (Number.isFinite(retryAfterSeconds)) {
294
+ return Math.max(retryAfterSeconds * 1e3, 0);
295
+ }
296
+ const retryAtMs = Date.parse(retryAfter);
297
+ return Number.isNaN(retryAtMs) ? void 0 : Math.max(retryAtMs - Date.now(), 0);
298
+ };
299
+
300
+ // src/utils/sleep-for-milliseconds.ts
287
301
  var sleepForMilliseconds = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
288
302
 
303
+ // src/utils/fetch-with-retries.ts
304
+ var fetchWithRetries = async ({
305
+ sendRequest,
306
+ maxAttempts,
307
+ isRetryableStatus,
308
+ getRetryDelayMs,
309
+ retryAbortSignal
310
+ }) => {
311
+ const sendAttempt = async ({
312
+ attempt,
313
+ waitedMs
314
+ }) => {
315
+ const response = await sendRequest();
316
+ if (response.ok || !isRetryableStatus(response.status) || attempt + 1 >= maxAttempts) {
317
+ return response;
318
+ }
319
+ const delayMs = getRetryDelayMs({
320
+ attempt,
321
+ retryAfterMs: parseRetryAfterMs(response.headers.get("retry-after")),
322
+ waitedMs
323
+ });
324
+ if (!o(delayMs)) {
325
+ return response;
326
+ }
327
+ await sleepForMilliseconds(delayMs);
328
+ if (o(retryAbortSignal) && retryAbortSignal.aborted) {
329
+ return response;
330
+ }
331
+ await response.body?.cancel();
332
+ return sendAttempt({ attempt: attempt + 1, waitedMs: waitedMs + delayMs });
333
+ };
334
+ return sendAttempt({ attempt: 0, waitedMs: 0 });
335
+ };
336
+
289
337
  // src/features/transcripts/logic-functions/utils/fetch-graph-response.ts
290
- var fetchGraphResponseWithRetries = async ({
338
+ var fetchGraphResponse = async ({
291
339
  accessToken,
292
340
  url,
293
341
  accept,
294
342
  method,
295
- body,
296
- attempt
343
+ body
297
344
  }) => {
298
- const response = await fetch(url, {
299
- method,
300
- redirect: "error",
301
- headers: {
302
- Authorization: `Bearer ${accessToken}`,
303
- Accept: accept,
304
- ...o(body) ? { "Content-Type": "application/json" } : {}
305
- },
306
- body: o(body) ? JSON.stringify(body) : void 0
345
+ const resolvedUrl = resolveGraphUrlOrThrow(url);
346
+ const response = await fetchWithRetries({
347
+ sendRequest: () => fetch(resolvedUrl, {
348
+ method,
349
+ redirect: "error",
350
+ headers: {
351
+ Authorization: `Bearer ${accessToken}`,
352
+ Accept: accept,
353
+ ...o(body) ? { "Content-Type": "application/json" } : {}
354
+ },
355
+ body: o(body) ? JSON.stringify(body) : void 0
356
+ }),
357
+ maxAttempts: GRAPH_REQUEST_MAX_ATTEMPTS,
358
+ isRetryableStatus: (status) => GRAPH_RETRYABLE_STATUSES.has(status),
359
+ getRetryDelayMs: ({ attempt, retryAfterMs }) => o(retryAfterMs) && retryAfterMs > 0 ? retryAfterMs : GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt
307
360
  });
308
361
  if (response.ok) {
309
362
  return response;
310
363
  }
311
- if (GRAPH_RETRYABLE_STATUSES.has(response.status) && attempt + 1 < GRAPH_REQUEST_MAX_ATTEMPTS) {
312
- const retryAfterSeconds = Number(response.headers.get("Retry-After"));
313
- await sleepForMilliseconds(
314
- retryAfterSeconds > 0 ? retryAfterSeconds * 1e3 : GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt
315
- );
316
- return fetchGraphResponseWithRetries({
317
- accessToken,
318
- url,
319
- accept,
320
- method,
321
- body,
322
- attempt: attempt + 1
323
- });
324
- }
325
364
  const errorBody = await response.json().catch(() => ({}));
326
- const innerErrorCode = (0, import_guards2.isNonEmptyString)(errorBody.error?.innerError?.code) ? errorBody.error.innerError.code : void 0;
327
- const message = (0, import_guards2.isNonEmptyString)(errorBody.error?.message) ? errorBody.error.message : response.statusText;
365
+ const innerErrorCode = (0, import_guards3.isNonEmptyString)(errorBody.error?.innerError?.code) ? errorBody.error.innerError.code : void 0;
366
+ const message = (0, import_guards3.isNonEmptyString)(errorBody.error?.message) ? errorBody.error.message : response.statusText;
328
367
  throw new GraphRequestError({
329
- message: `Microsoft Graph request failed (${response.status}${(0, import_guards2.isNonEmptyString)(innerErrorCode) ? ` ${innerErrorCode}` : ""}): ${message}`,
368
+ message: `Microsoft Graph request failed (${response.status}${(0, import_guards3.isNonEmptyString)(innerErrorCode) ? ` ${innerErrorCode}` : ""}): ${message}`,
330
369
  status: response.status,
331
370
  innerErrorCode
332
371
  });
333
372
  };
334
- var fetchGraphResponse = ({
335
- url,
336
- ...request
337
- }) => fetchGraphResponseWithRetries({
338
- ...request,
339
- url: resolveGraphUrlOrThrow(url),
340
- attempt: 0
341
- });
342
373
 
343
374
  // src/features/transcripts/logic-functions/utils/fetch-graph-json.ts
344
375
  var fetchGraphJson = async ({
@@ -359,8 +390,8 @@ var fetchGraphJson = async ({
359
390
  };
360
391
 
361
392
  // src/features/chat/logic-functions/utils/is-linkable-graph-user.ts
362
- var import_guards3 = __toESM(require_build());
363
- var isLinkableGraphUser = (user) => (0, import_guards3.isNonEmptyString)(user.id) && ((0, import_guards3.isNonEmptyString)(user.mail) || (0, import_guards3.isNonEmptyString)(user.userPrincipalName));
393
+ var import_guards4 = __toESM(require_build());
394
+ var isLinkableGraphUser = (user) => (0, import_guards4.isNonEmptyString)(user.id) && ((0, import_guards4.isNonEmptyString)(user.mail) || (0, import_guards4.isNonEmptyString)(user.userPrincipalName));
364
395
 
365
396
  // src/features/chat/logic-functions/utils/collect-graph-users.ts
366
397
  var DEFAULT_MAX_PAGES = 5;
@@ -375,7 +406,7 @@ var collectGraphUsers = async ({
375
406
  const seenAadObjectIds = /* @__PURE__ */ new Set();
376
407
  let nextUrl = url;
377
408
  for (let page = 0; page < maxPages; page += 1) {
378
- if (!(0, import_guards4.isNonEmptyString)(nextUrl)) {
409
+ if (!(0, import_guards5.isNonEmptyString)(nextUrl)) {
379
410
  return { users, isTruncated: false };
380
411
  }
381
412
  const pageResult = await fetchGraphJson({
@@ -397,10 +428,10 @@ var collectGraphUsers = async ({
397
428
  users.push(user);
398
429
  }
399
430
  if (o(maxUsers) && users.length >= maxUsers) {
400
- return { users, isTruncated: (0, import_guards4.isNonEmptyString)(nextUrl) };
431
+ return { users, isTruncated: (0, import_guards5.isNonEmptyString)(nextUrl) };
401
432
  }
402
433
  }
403
- return { users, isTruncated: (0, import_guards4.isNonEmptyString)(nextUrl) };
434
+ return { users, isTruncated: (0, import_guards5.isNonEmptyString)(nextUrl) };
404
435
  };
405
436
 
406
437
  // src/features/chat/logic-functions/utils/current-user-has-roles-permission.ts
@@ -423,12 +454,12 @@ var currentUserHasRolesPermission = async () => {
423
454
  };
424
455
 
425
456
  // src/features/chat/logic-functions/utils/get-teams-workspace-graph-access.ts
426
- var import_guards7 = __toESM(require_build());
457
+ var import_guards8 = __toESM(require_build());
427
458
 
428
459
  // node_modules/twenty-sdk/dist/logic-function/index.mjs
429
- var import_guards5 = __toESM(require_build(), 1);
460
+ var import_guards6 = __toESM(require_build(), 1);
430
461
  import { MetadataApiClient as a } from "twenty-client-sdk/metadata";
431
- var s = (e3) => !(0, import_guards5.isUndefined)(e3) && !(0, import_guards5.isNull)(e3);
462
+ var s = (e3) => !(0, import_guards6.isUndefined)(e3) && !(0, import_guards6.isNull)(e3);
432
463
  var c = (t3) => {
433
464
  let n2 = { type: "unknown" };
434
465
  switch (t3.type) {
@@ -457,7 +488,7 @@ var c = (t3) => {
457
488
  default:
458
489
  n2.type = "unknown";
459
490
  }
460
- return Array.isArray(t3.enum) && (n2.enum = t3.enum.filter((e3) => typeof e3 == "string")), t3.multiline === true && (n2.multiline = true), (0, import_guards5.isNonEmptyString)(t3.label) && (n2.label = t3.label), (0, import_guards5.isNonEmptyString)(t3.objectUniversalIdentifier) && (n2.objectUniversalIdentifier = t3.objectUniversalIdentifier), n2;
491
+ return Array.isArray(t3.enum) && (n2.enum = t3.enum.filter((e3) => typeof e3 == "string")), t3.multiline === true && (n2.multiline = true), (0, import_guards6.isNonEmptyString)(t3.label) && (n2.label = t3.label), (0, import_guards6.isNonEmptyString)(t3.objectUniversalIdentifier) && (n2.objectUniversalIdentifier = t3.objectUniversalIdentifier), n2;
461
492
  };
462
493
  var l = (e3) => [c(e3)];
463
494
  l({
@@ -612,19 +643,22 @@ var TEAMS_CONNECTED_ACCOUNT_TENANT_KV_KEY_PREFIX = "teams-connected-account-tena
612
643
  var buildTeamsConnectedAccountTenantKvKey = (connectedAccountId) => `${TEAMS_CONNECTED_ACCOUNT_TENANT_KV_KEY_PREFIX}:${connectedAccountId}`;
613
644
 
614
645
  // src/features/chat/logic-functions/utils/fetch-teams-tenant-id.ts
615
- var import_guards6 = __toESM(require_build());
646
+ var import_guards7 = __toESM(require_build());
616
647
  var fetchTeamsTenantId = async (accessToken) => {
617
648
  const page = await fetchGraphJson({
618
649
  accessToken,
619
650
  url: "organization?$select=id"
620
651
  });
621
652
  const tenantId = page.value?.[0]?.id;
622
- if (!(0, import_guards6.isNonEmptyString)(tenantId)) {
653
+ if (!(0, import_guards7.isNonEmptyString)(tenantId)) {
623
654
  throw new Error("Microsoft Graph returned no organization to claim");
624
655
  }
625
656
  return tenantId;
626
657
  };
627
658
 
659
+ // src/features/chat/logic-functions/utils/is-working-teams-workspace-connection.ts
660
+ var isWorkingTeamsWorkspaceConnection = (connection) => connection.scope === "WORKSPACE" && !o(connection.authFailedAt);
661
+
628
662
  // src/features/transcripts/constants/teams-oauth-config.ts
629
663
  var TEAMS_GRAPH_DIRECTORY_SCOPE = "https://graph.microsoft.com/User.ReadBasic.All";
630
664
 
@@ -663,9 +697,9 @@ var getTeamsWorkspaceGraphAccess = async () => {
663
697
  try {
664
698
  const connections = await listTeamsConnections();
665
699
  const workspaceConnections = connections.filter(
666
- (candidate) => candidate.scope === "WORKSPACE" && !o(candidate.authFailedAt)
700
+ isWorkingTeamsWorkspaceConnection
667
701
  );
668
- if (!(0, import_guards7.isNonEmptyArray)(workspaceConnections)) {
702
+ if (!(0, import_guards8.isNonEmptyArray)(workspaceConnections)) {
669
703
  return { success: false, error: NOT_CONNECTED_ERROR_MESSAGE };
670
704
  }
671
705
  const connection = workspaceConnections.find(
@@ -678,7 +712,7 @@ var getTeamsWorkspaceGraphAccess = async () => {
678
712
  const storedTenantId = await ge.get(
679
713
  buildTeamsConnectedAccountTenantKvKey(connection.id)
680
714
  );
681
- const tenantId = (0, import_guards7.isNonEmptyString)(storedTenantId) ? storedTenantId : await fetchTeamsTenantId(accessToken);
715
+ const tenantId = (0, import_guards8.isNonEmptyString)(storedTenantId) ? storedTenantId : await fetchTeamsTenantId(accessToken);
682
716
  return { success: true, accessToken, tenantId };
683
717
  } catch (error) {
684
718
  return { success: false, error: toErrorMessage(error) };
@@ -689,11 +723,11 @@ var getTeamsWorkspaceGraphAccess = async () => {
689
723
  var toTeamsGraphUsersErrorMessage = (error) => error instanceof GraphRequestError && error.status === 403 ? "Microsoft did not allow reading the organization directory. Reconnect Microsoft Teams from the app settings to grant directory access, or ask a tenant administrator to allow it." : toErrorMessage(error);
690
724
 
691
725
  // src/features/chat/logic-functions/utils/to-teams-user-search-option.ts
692
- var import_guards8 = __toESM(require_build());
726
+ var import_guards9 = __toESM(require_build());
693
727
  var toTeamsUserSearchOption = (user) => ({
694
728
  teamsUserAadObjectId: user.id,
695
- displayName: (0, import_guards8.isNonEmptyString)(user.displayName) ? user.displayName : void 0,
696
- email: (0, import_guards8.isNonEmptyString)(user.mail) ? user.mail : user.userPrincipalName
729
+ displayName: (0, import_guards9.isNonEmptyString)(user.displayName) ? user.displayName : void 0,
730
+ email: (0, import_guards9.isNonEmptyString)(user.mail) ? user.mail : user.userPrincipalName
697
731
  });
698
732
 
699
733
  // src/features/chat/logic-functions/handlers/teams-search-users-handler.ts
@@ -706,8 +740,8 @@ var teamsSearchUsersHandler = async (payload) => {
706
740
  error: "Only members with the roles permission can search Teams users."
707
741
  };
708
742
  }
709
- const query = (0, import_guards9.isNonEmptyString)(payload.body?.query) ? payload.body.query.trim() : "";
710
- if (!(0, import_guards9.isNonEmptyString)(query)) {
743
+ const query = (0, import_guards10.isNonEmptyString)(payload.body?.query) ? payload.body.query.trim() : "";
744
+ if (!(0, import_guards10.isNonEmptyString)(query)) {
711
745
  return { success: true, teamsUsers: [] };
712
746
  }
713
747
  const graphAccess = await getTeamsWorkspaceGraphAccess();