@twentyhq/meet 0.0.0-stage → 1.0.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 (172) hide show
  1. package/README.md +48 -2
  2. package/dependencies/yarn.lock +1863 -0
  3. package/manifest.json +1901 -0
  4. package/package.json +44 -4
  5. package/public/gallery/meet-cover-image-1.png +0 -0
  6. package/public/gallery/meet-cover-image-2.png +0 -0
  7. package/public/gallery/meet-cover-image-3.png +0 -0
  8. package/public/logo.svg +1 -0
  9. package/src/constants/meet-call-summary-prompt.constant.ts +54 -0
  10. package/src/constants/meet.constant.ts +17 -0
  11. package/src/constants/universal-identifiers.ts +35 -0
  12. package/src/logic-functions/constants/calendar-event-matching.constant.ts +3 -0
  13. package/src/logic-functions/constants/google-docs-api.constant.ts +10 -0
  14. package/src/logic-functions/constants/google-drive-api.constant.ts +1 -0
  15. package/src/logic-functions/constants/google-pubsub-push.constant.ts +7 -0
  16. package/src/logic-functions/constants/google-user-info.constant.ts +2 -0
  17. package/src/logic-functions/constants/google-workspace-events.constant.ts +17 -0
  18. package/src/logic-functions/constants/meet-api.constant.ts +9 -0
  19. package/src/logic-functions/constants/meet-call-summary.constant.ts +3 -0
  20. package/src/logic-functions/constants/meet-import.constant.ts +7 -0
  21. package/src/logic-functions/constants/meet-recording-import.constant.ts +7 -0
  22. package/src/logic-functions/constants/restricted-field-placeholder.constant.ts +2 -0
  23. package/src/logic-functions/meet-events-resolver.mjs +1345 -0
  24. package/src/logic-functions/meet-events-resolver.mjs.map +7 -0
  25. package/src/logic-functions/meet-events-resolver.ts +89 -0
  26. package/src/logic-functions/meet-handle-event.mjs +665 -0
  27. package/src/logic-functions/meet-handle-event.mjs.map +7 -0
  28. package/src/logic-functions/meet-handle-event.ts +86 -0
  29. package/src/logic-functions/meet-identify-account.mjs +369 -0
  30. package/src/logic-functions/meet-identify-account.mjs.map +7 -0
  31. package/src/logic-functions/meet-identify-account.ts +42 -0
  32. package/src/logic-functions/meet-import-conference.mjs +1465 -0
  33. package/src/logic-functions/meet-import-conference.mjs.map +7 -0
  34. package/src/logic-functions/meet-import-conference.ts +101 -0
  35. package/src/logic-functions/meet-import-recording.mjs +794 -0
  36. package/src/logic-functions/meet-import-recording.mjs.map +7 -0
  37. package/src/logic-functions/meet-import-recording.ts +99 -0
  38. package/src/logic-functions/meet-queue-conference-imports.mjs +711 -0
  39. package/src/logic-functions/meet-queue-conference-imports.mjs.map +7 -0
  40. package/src/logic-functions/meet-queue-conference-imports.ts +62 -0
  41. package/src/logic-functions/meet-refresh-connections.mjs +457 -0
  42. package/src/logic-functions/meet-refresh-connections.mjs.map +7 -0
  43. package/src/logic-functions/meet-refresh-connections.ts +64 -0
  44. package/src/logic-functions/meet-register-connection.mjs +837 -0
  45. package/src/logic-functions/meet-register-connection.mjs.map +7 -0
  46. package/src/logic-functions/meet-register-connection.ts +81 -0
  47. package/src/logic-functions/meet-summarize-call-recording.mjs +645 -0
  48. package/src/logic-functions/meet-summarize-call-recording.mjs.map +7 -0
  49. package/src/logic-functions/meet-summarize-call-recording.ts +111 -0
  50. package/src/logic-functions/meet-unregister-connection.mjs +610 -0
  51. package/src/logic-functions/meet-unregister-connection.mjs.map +7 -0
  52. package/src/logic-functions/meet-unregister-connection.ts +57 -0
  53. package/src/logic-functions/types/calendar-event-candidate.type.ts +6 -0
  54. package/src/logic-functions/types/call-recording-for-summary.type.ts +5 -0
  55. package/src/logic-functions/types/call-recording-sync-fields.type.ts +12 -0
  56. package/src/logic-functions/types/call-recording-upsert-outcome.type.ts +4 -0
  57. package/src/logic-functions/types/google-doc-lists.type.ts +4 -0
  58. package/src/logic-functions/types/google-doc-markdown-segment.type.ts +5 -0
  59. package/src/logic-functions/types/google-doc-paragraph-element.type.ts +8 -0
  60. package/src/logic-functions/types/google-doc-paragraph.type.ts +7 -0
  61. package/src/logic-functions/types/google-doc-tab.type.ts +10 -0
  62. package/src/logic-functions/types/google-doc.type.ts +6 -0
  63. package/src/logic-functions/types/google-pubsub-push-body.type.ts +6 -0
  64. package/src/logic-functions/types/google-request-method.type.ts +1 -0
  65. package/src/logic-functions/types/google-user-info.type.ts +4 -0
  66. package/src/logic-functions/types/google-workspace-events-operation.type.ts +8 -0
  67. package/src/logic-functions/types/meet-call-summary-outcome.type.ts +6 -0
  68. package/src/logic-functions/types/meet-collection-page.type.ts +3 -0
  69. package/src/logic-functions/types/meet-conference-record.type.ts +7 -0
  70. package/src/logic-functions/types/meet-conference-sync-outcome.type.ts +5 -0
  71. package/src/logic-functions/types/meet-conference-sync-result.type.ts +7 -0
  72. package/src/logic-functions/types/meet-daily-job-name.type.ts +1 -0
  73. package/src/logic-functions/types/meet-event-data.type.ts +5 -0
  74. package/src/logic-functions/types/meet-event-outcome.type.ts +4 -0
  75. package/src/logic-functions/types/meet-event-subscription.type.ts +8 -0
  76. package/src/logic-functions/types/meet-event.type.ts +5 -0
  77. package/src/logic-functions/types/meet-exception-code.type.ts +12 -0
  78. package/src/logic-functions/types/meet-exception.type.ts +25 -0
  79. package/src/logic-functions/types/meet-participant.type.ts +8 -0
  80. package/src/logic-functions/types/meet-recording-import-outcome.type.ts +6 -0
  81. package/src/logic-functions/types/meet-recording.type.ts +7 -0
  82. package/src/logic-functions/types/meet-smart-note.type.ts +7 -0
  83. package/src/logic-functions/types/meet-space.type.ts +5 -0
  84. package/src/logic-functions/types/meet-transcript-entry.type.ts +8 -0
  85. package/src/logic-functions/types/meet-transcript.type.ts +7 -0
  86. package/src/logic-functions/types/transcript-entry.type.ts +7 -0
  87. package/src/logic-functions/utils/build-google-api-url-or-throw.util.ts +30 -0
  88. package/src/logic-functions/utils/build-google-doc-markdown-segment.util.ts +67 -0
  89. package/src/logic-functions/utils/build-meet-artifact-import-job.util.ts +25 -0
  90. package/src/logic-functions/utils/build-meet-call-recording-sync-fields.util.ts +48 -0
  91. package/src/logic-functions/utils/build-meet-call-summary-job.util.ts +19 -0
  92. package/src/logic-functions/utils/build-meet-call-summary-prompt.util.ts +50 -0
  93. package/src/logic-functions/utils/build-meet-conference-import-job.util.ts +26 -0
  94. package/src/logic-functions/utils/build-meet-conference-import-payload.util.ts +18 -0
  95. package/src/logic-functions/utils/build-meet-conference-record-filter.util.ts +8 -0
  96. package/src/logic-functions/utils/build-meet-daily-job.util.ts +17 -0
  97. package/src/logic-functions/utils/build-meet-recording-import-job.util.ts +20 -0
  98. package/src/logic-functions/utils/build-meet-url-or-throw.util.ts +15 -0
  99. package/src/logic-functions/utils/build-meet-user-target-resource.util.ts +2 -0
  100. package/src/logic-functions/utils/can-renew-meet-event-subscription.util.ts +18 -0
  101. package/src/logic-functions/utils/chunk-into-batches.util.ts +10 -0
  102. package/src/logic-functions/utils/claim-meet-event-subscription.util.ts +10 -0
  103. package/src/logic-functions/utils/compute-call-recording-id-for-meet-conference.util.ts +16 -0
  104. package/src/logic-functions/utils/convert-google-doc-paragraph-to-markdown.util.ts +62 -0
  105. package/src/logic-functions/utils/convert-google-doc-tab-to-markdown.util.ts +49 -0
  106. package/src/logic-functions/utils/create-meet-event-subscription-or-throw.util.ts +41 -0
  107. package/src/logic-functions/utils/delete-meet-event-subscription.util.ts +22 -0
  108. package/src/logic-functions/utils/enqueue-meet-conference-imports-or-throw.util.ts +39 -0
  109. package/src/logic-functions/utils/enqueue-meet-daily-jobs-or-throw.util.ts +35 -0
  110. package/src/logic-functions/utils/ensure-meet-event-subscription-or-throw.util.ts +51 -0
  111. package/src/logic-functions/utils/escape-markdown-text.util.ts +4 -0
  112. package/src/logic-functions/utils/escape-sql-like-pattern.util.ts +2 -0
  113. package/src/logic-functions/utils/extract-bearer-token.util.ts +23 -0
  114. package/src/logic-functions/utils/extract-meet-name-from-doc-title.util.ts +16 -0
  115. package/src/logic-functions/utils/fetch-meet-json.util.ts +107 -0
  116. package/src/logic-functions/utils/find-call-recording-for-summary.util.ts +38 -0
  117. package/src/logic-functions/utils/find-call-recording-video-state.util.ts +25 -0
  118. package/src/logic-functions/utils/find-meet-calendar-event.util.ts +74 -0
  119. package/src/logic-functions/utils/find-meet-conference-title.util.ts +38 -0
  120. package/src/logic-functions/utils/find-meet-event-subscription.util.ts +32 -0
  121. package/src/logic-functions/utils/find-meet-smart-notes-markdown.util.ts +32 -0
  122. package/src/logic-functions/utils/format-seconds-as-clock-timestamp.util.ts +20 -0
  123. package/src/logic-functions/utils/get-conference-record-name-from-artifact-name.util.ts +6 -0
  124. package/src/logic-functions/utils/get-connection-access-token-or-throw.util.ts +18 -0
  125. package/src/logic-functions/utils/get-google-doc-title.util.ts +31 -0
  126. package/src/logic-functions/utils/get-google-doc.util.ts +30 -0
  127. package/src/logic-functions/utils/get-google-drive-file-size-bytes-or-throw.util.ts +31 -0
  128. package/src/logic-functions/utils/get-meet-conference-record.util.ts +18 -0
  129. package/src/logic-functions/utils/get-meet-connection-subscription-key.util.ts +3 -0
  130. package/src/logic-functions/utils/get-meet-event-subscription-key.util.ts +2 -0
  131. package/src/logic-functions/utils/get-meet-participant-display-name.util.ts +20 -0
  132. package/src/logic-functions/utils/get-meet-recording-drive-file-id.util.ts +16 -0
  133. package/src/logic-functions/utils/get-meet-recording.util.ts +18 -0
  134. package/src/logic-functions/utils/get-meet-space.util.ts +15 -0
  135. package/src/logic-functions/utils/get-random-delay-milliseconds.util.ts +4 -0
  136. package/src/logic-functions/utils/is-google-doc-unreadable-error.util.ts +9 -0
  137. package/src/logic-functions/utils/is-google-pubsub-push-authorized.util.ts +31 -0
  138. package/src/logic-functions/utils/is-meet-ai-summary-enabled-for-member.util.ts +22 -0
  139. package/src/logic-functions/utils/is-transcript-entry-list.util.ts +16 -0
  140. package/src/logic-functions/utils/join-google-doc-markdown-segments.util.ts +102 -0
  141. package/src/logic-functions/utils/list-calendar-events-in-window.util.ts +142 -0
  142. package/src/logic-functions/utils/list-meet-collection.util.ts +79 -0
  143. package/src/logic-functions/utils/list-meet-conference-records.util.ts +22 -0
  144. package/src/logic-functions/utils/list-meet-participants.util.ts +15 -0
  145. package/src/logic-functions/utils/list-meet-recordings.util.ts +15 -0
  146. package/src/logic-functions/utils/list-meet-smart-notes.util.ts +15 -0
  147. package/src/logic-functions/utils/list-meet-transcript-entries.util.ts +15 -0
  148. package/src/logic-functions/utils/list-meet-transcripts.util.ts +15 -0
  149. package/src/logic-functions/utils/map-meet-transcript-entries.util.ts +64 -0
  150. package/src/logic-functions/utils/normalize-meeting-url.util.ts +18 -0
  151. package/src/logic-functions/utils/open-google-drive-file-download-or-throw.util.ts +36 -0
  152. package/src/logic-functions/utils/parse-meet-call-summary-response.util.ts +36 -0
  153. package/src/logic-functions/utils/parse-meet-event-data-or-throw.util.ts +36 -0
  154. package/src/logic-functions/utils/parse-meet-event-or-throw.util.ts +35 -0
  155. package/src/logic-functions/utils/parse-retry-after-milliseconds.util.ts +27 -0
  156. package/src/logic-functions/utils/put-stream-to-upload-url-or-throw.util.ts +73 -0
  157. package/src/logic-functions/utils/read-meet-event-subscription-or-throw.util.ts +24 -0
  158. package/src/logic-functions/utils/release-meet-event-subscription.util.ts +29 -0
  159. package/src/logic-functions/utils/renew-meet-event-subscription-or-throw.util.ts +32 -0
  160. package/src/logic-functions/utils/run-meet-call-summarizer-or-throw.util.ts +28 -0
  161. package/src/logic-functions/utils/save-call-recording-summary-if-empty.util.ts +29 -0
  162. package/src/logic-functions/utils/save-call-recording-video.util.ts +23 -0
  163. package/src/logic-functions/utils/should-generate-meet-ai-summary.util.ts +17 -0
  164. package/src/logic-functions/utils/sleep-for-milliseconds.util.ts +2 -0
  165. package/src/logic-functions/utils/split-surrounding-whitespace.util.ts +10 -0
  166. package/src/logic-functions/utils/store-meet-connection-subscription.util.ts +46 -0
  167. package/src/logic-functions/utils/sync-meet-conference-or-throw.util.ts +129 -0
  168. package/src/logic-functions/utils/upload-google-drive-file-as-call-recording-video-or-throw.util.ts +73 -0
  169. package/src/logic-functions/utils/upsert-call-recording-or-throw.util.ts +104 -0
  170. package/src/logic-functions/utils/verify-google-pubsub-push-token-or-throw.util.ts +71 -0
  171. package/src/logic-functions/utils/wait-for-google-workspace-events-operation-or-throw.util.ts +53 -0
  172. package/tsconfig.json +39 -0
@@ -0,0 +1,18 @@
1
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
2
+ import { buildMeetUrlOrThrow } from 'src/logic-functions/utils/build-meet-url-or-throw.util';
3
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
4
+
5
+ export const getMeetConferenceRecord = ({
6
+ accessToken,
7
+ conferenceRecordName,
8
+ }: {
9
+ accessToken: string;
10
+ conferenceRecordName: string;
11
+ }): Promise<MeetConferenceRecord> =>
12
+ fetchMeetJson<MeetConferenceRecord>({
13
+ accessToken,
14
+ url: buildMeetUrlOrThrow({
15
+ path: conferenceRecordName,
16
+ queryParameters: {},
17
+ }),
18
+ });
@@ -0,0 +1,3 @@
1
+ export const getMeetConnectionSubscriptionKey = (
2
+ connectedAccountId: string,
3
+ ) => `google-meet-connection-subscription:${connectedAccountId}`;
@@ -0,0 +1,2 @@
1
+ export const getMeetEventSubscriptionKey = (subscriptionName: string) =>
2
+ `google-meet-event-subscription:${subscriptionName}`;
@@ -0,0 +1,20 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ import { type MeetParticipant } from 'src/logic-functions/types/meet-participant.type';
4
+
5
+ export const getMeetParticipantDisplayName = ({
6
+ signedinUser,
7
+ anonymousUser,
8
+ phoneUser,
9
+ }: Pick<
10
+ MeetParticipant,
11
+ 'signedinUser' | 'anonymousUser' | 'phoneUser'
12
+ >): string | null => {
13
+ const displayName = (
14
+ signedinUser?.displayName ??
15
+ anonymousUser?.displayName ??
16
+ phoneUser?.displayName
17
+ )?.trim();
18
+
19
+ return isNonEmptyString(displayName) ? displayName : null;
20
+ };
@@ -0,0 +1,16 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ import { type MeetRecording } from 'src/logic-functions/types/meet-recording.type';
4
+
5
+ export const getMeetRecordingDriveFileId = ({
6
+ state,
7
+ driveDestination,
8
+ }: Pick<MeetRecording, 'state' | 'driveDestination'>):
9
+ | string
10
+ | undefined => {
11
+ const driveFileId = driveDestination?.file;
12
+
13
+ return state === 'FILE_GENERATED' && isNonEmptyString(driveFileId)
14
+ ? driveFileId
15
+ : undefined;
16
+ };
@@ -0,0 +1,18 @@
1
+ import { type MeetRecording } from 'src/logic-functions/types/meet-recording.type';
2
+ import { buildMeetUrlOrThrow } from 'src/logic-functions/utils/build-meet-url-or-throw.util';
3
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
4
+
5
+ export const getMeetRecording = ({
6
+ accessToken,
7
+ recordingName,
8
+ }: {
9
+ accessToken: string;
10
+ recordingName: string;
11
+ }): Promise<MeetRecording> =>
12
+ fetchMeetJson<MeetRecording>({
13
+ accessToken,
14
+ url: buildMeetUrlOrThrow({
15
+ path: recordingName,
16
+ queryParameters: {},
17
+ }),
18
+ });
@@ -0,0 +1,15 @@
1
+ import { type MeetSpace } from 'src/logic-functions/types/meet-space.type';
2
+ import { buildMeetUrlOrThrow } from 'src/logic-functions/utils/build-meet-url-or-throw.util';
3
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
4
+
5
+ export const getMeetSpace = ({
6
+ accessToken,
7
+ spaceName,
8
+ }: {
9
+ accessToken: string;
10
+ spaceName: string;
11
+ }): Promise<MeetSpace> =>
12
+ fetchMeetJson<MeetSpace>({
13
+ accessToken,
14
+ url: buildMeetUrlOrThrow({ path: spaceName, queryParameters: {} }),
15
+ });
@@ -0,0 +1,4 @@
1
+ import { randomInt } from 'crypto';
2
+
3
+ export const getRandomDelayMilliseconds = (maximumMilliseconds: number) =>
4
+ randomInt(maximumMilliseconds);
@@ -0,0 +1,9 @@
1
+ import { isDefined } from 'twenty-sdk/utils';
2
+
3
+ import { GOOGLE_DOC_UNREADABLE_STATUSES } from 'src/logic-functions/constants/google-docs-api.constant';
4
+ import { MeetException } from 'src/logic-functions/types/meet-exception.type';
5
+
6
+ export const isGoogleDocUnreadableError = (error: unknown): boolean =>
7
+ error instanceof MeetException &&
8
+ isDefined(error.httpStatus) &&
9
+ GOOGLE_DOC_UNREADABLE_STATUSES.has(error.httpStatus);
@@ -0,0 +1,31 @@
1
+ import { MeetException } from 'src/logic-functions/types/meet-exception.type';
2
+ import { verifyGooglePubsubPushTokenOrThrow } from 'src/logic-functions/utils/verify-google-pubsub-push-token-or-throw.util';
3
+
4
+ export const isGooglePubsubPushAuthorized = async ({
5
+ authorizationHeader,
6
+ audience,
7
+ serviceAccountEmail,
8
+ }: {
9
+ authorizationHeader: string | undefined;
10
+ audience: string;
11
+ serviceAccountEmail: string;
12
+ }): Promise<boolean> => {
13
+ try {
14
+ await verifyGooglePubsubPushTokenOrThrow({
15
+ authorizationHeader,
16
+ audience,
17
+ serviceAccountEmail,
18
+ });
19
+
20
+ return true;
21
+ } catch (error) {
22
+ if (
23
+ error instanceof MeetException &&
24
+ error.code === 'PUSH_TOKEN_INVALID'
25
+ ) {
26
+ return false;
27
+ }
28
+
29
+ throw error;
30
+ }
31
+ };
@@ -0,0 +1,22 @@
1
+ import { isDefined } from 'twenty-sdk/utils';
2
+
3
+ import { MEET_AI_SUMMARY_ENABLED_APP_VARIABLE_NAME } from 'src/constants/meet.constant';
4
+
5
+ export const isMeetAiSummaryEnabledForMember = ({
6
+ memberApplicationVariables,
7
+ userWorkspaceId,
8
+ }: {
9
+ memberApplicationVariables: {
10
+ userWorkspaceId: string;
11
+ variables: { key: string; value: string }[];
12
+ }[];
13
+ userWorkspaceId: string;
14
+ }): boolean => {
15
+ const aiSummaryEnabledValue = memberApplicationVariables
16
+ .find((member) => member.userWorkspaceId === userWorkspaceId)
17
+ ?.variables.find(
18
+ ({ key }) => key === MEET_AI_SUMMARY_ENABLED_APP_VARIABLE_NAME,
19
+ )?.value;
20
+
21
+ return isDefined(aiSummaryEnabledValue) && aiSummaryEnabledValue !== 'false';
22
+ };
@@ -0,0 +1,16 @@
1
+ import { isArray, isObject } from '@sniptt/guards';
2
+
3
+ import { type TranscriptEntry } from 'src/logic-functions/types/transcript-entry.type';
4
+
5
+ export const isTranscriptEntryList = (
6
+ value: unknown,
7
+ ): value is TranscriptEntry[] =>
8
+ isArray(value) &&
9
+ value.every(
10
+ (entry) =>
11
+ isObject(entry) &&
12
+ 'participant' in entry &&
13
+ isObject(entry.participant) &&
14
+ 'words' in entry &&
15
+ isArray(entry.words),
16
+ );
@@ -0,0 +1,102 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ import { type GoogleDocMarkdownSegment } from 'src/logic-functions/types/google-doc-markdown-segment.type';
4
+ import { splitSurroundingWhitespace } from 'src/logic-functions/utils/split-surrounding-whitespace.util';
5
+
6
+ const BOLD_MARKER = '**';
7
+ const ITALIC_MARKER = '*';
8
+
9
+ type JoinedMarkdown = {
10
+ markdown: string;
11
+ isBold: boolean;
12
+ isItalic: boolean;
13
+ };
14
+
15
+ const closeMarkerBeforeTrailingWhitespace = ({
16
+ markdown,
17
+ marker,
18
+ shouldClose,
19
+ }: {
20
+ markdown: string;
21
+ marker: string;
22
+ shouldClose: boolean;
23
+ }): string => {
24
+ if (!shouldClose) {
25
+ return markdown;
26
+ }
27
+
28
+ const { trailing } = splitSurroundingWhitespace(markdown);
29
+
30
+ return `${markdown.slice(0, markdown.length - trailing.length)}${marker}${trailing}`;
31
+ };
32
+
33
+ const switchEmphasis = ({
34
+ joined,
35
+ isBold,
36
+ isItalic,
37
+ }: {
38
+ joined: JoinedMarkdown;
39
+ isBold: boolean;
40
+ isItalic: boolean;
41
+ }): { closedMarkdown: string; openingMarkers: string } => {
42
+ const shouldCloseBold =
43
+ joined.isBold && (!isBold || joined.isItalic !== isItalic);
44
+ const shouldOpenItalic = isItalic && !joined.isItalic;
45
+ const shouldOpenBold = isBold && (!joined.isBold || shouldCloseBold);
46
+ const closedMarkdown = closeMarkerBeforeTrailingWhitespace({
47
+ markdown: closeMarkerBeforeTrailingWhitespace({
48
+ markdown: joined.markdown,
49
+ marker: BOLD_MARKER,
50
+ shouldClose: shouldCloseBold,
51
+ }),
52
+ marker: ITALIC_MARKER,
53
+ shouldClose: joined.isItalic && !isItalic,
54
+ });
55
+
56
+ return {
57
+ closedMarkdown,
58
+ openingMarkers: `${shouldOpenItalic ? ITALIC_MARKER : ''}${shouldOpenBold ? BOLD_MARKER : ''}`,
59
+ };
60
+ };
61
+
62
+ const appendSegment = ({
63
+ joined,
64
+ segment,
65
+ }: {
66
+ joined: JoinedMarkdown;
67
+ segment: GoogleDocMarkdownSegment;
68
+ }): JoinedMarkdown => {
69
+ const { leading, content, trailing } = splitSurroundingWhitespace(
70
+ segment.markdown,
71
+ );
72
+
73
+ if (!isNonEmptyString(content)) {
74
+ return { ...joined, markdown: `${joined.markdown}${segment.markdown}` };
75
+ }
76
+
77
+ const isBold = segment.isBold ?? false;
78
+ const isItalic = segment.isItalic ?? false;
79
+ const { closedMarkdown, openingMarkers } = switchEmphasis({
80
+ joined,
81
+ isBold,
82
+ isItalic,
83
+ });
84
+
85
+ return {
86
+ markdown: `${closedMarkdown}${leading}${openingMarkers}${content}${trailing}`,
87
+ isBold,
88
+ isItalic,
89
+ };
90
+ };
91
+
92
+ export const joinGoogleDocMarkdownSegments = (
93
+ segments: GoogleDocMarkdownSegment[],
94
+ ): string => {
95
+ const joined = segments.reduce<JoinedMarkdown>(
96
+ (joinedSoFar, segment) => appendSegment({ joined: joinedSoFar, segment }),
97
+ { markdown: '', isBold: false, isItalic: false },
98
+ );
99
+
100
+ return switchEmphasis({ joined, isBold: false, isItalic: false })
101
+ .closedMarkdown;
102
+ };
@@ -0,0 +1,142 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { type CoreApiClient } from 'twenty-client-sdk/core';
3
+ import { isDefined } from 'twenty-sdk/utils';
4
+
5
+ import {
6
+ CALENDAR_EVENT_PAGE_SIZE,
7
+ MAX_CALENDAR_EVENT_PAGES,
8
+ } from 'src/logic-functions/constants/calendar-event-matching.constant';
9
+ import { RESTRICTED_FIELD_PLACEHOLDER } from 'src/logic-functions/constants/restricted-field-placeholder.constant';
10
+ import { type CalendarEventCandidate } from 'src/logic-functions/types/calendar-event-candidate.type';
11
+ import { escapeSqlLikePattern } from 'src/logic-functions/utils/escape-sql-like-pattern.util';
12
+
13
+ type CalendarEventsPage = {
14
+ calendarEvents?: {
15
+ edges?: Array<{
16
+ node: {
17
+ id: string;
18
+ title?: string | null;
19
+ startsAt?: string | null;
20
+ conferenceLink?: CalendarEventCandidate['conferenceLink'];
21
+ };
22
+ }>;
23
+ pageInfo?: { hasNextPage?: boolean; endCursor?: string | null };
24
+ };
25
+ };
26
+
27
+ // A partial list could match the wrong event, so an unreadable window yields undefined.
28
+ const listCalendarEventPages = async ({
29
+ coreApiClient,
30
+ earliestStart,
31
+ latestStart,
32
+ conferenceLinkFragment,
33
+ cursor,
34
+ pageIndex,
35
+ }: {
36
+ coreApiClient: Pick<CoreApiClient, 'query'>;
37
+ earliestStart: string;
38
+ latestStart: string;
39
+ conferenceLinkFragment: string;
40
+ cursor: string | undefined;
41
+ pageIndex: number;
42
+ }): Promise<CalendarEventCandidate[] | undefined> => {
43
+ if (pageIndex >= MAX_CALENDAR_EVENT_PAGES) {
44
+ return undefined;
45
+ }
46
+
47
+ const queryResult: CalendarEventsPage = await coreApiClient.query({
48
+ calendarEvents: {
49
+ __args: {
50
+ filter: {
51
+ and: [
52
+ { startsAt: { gte: earliestStart } },
53
+ { startsAt: { lte: latestStart } },
54
+ { isCanceled: { eq: false } },
55
+ {
56
+ conferenceLink: {
57
+ primaryLinkUrl: {
58
+ ilike: `%${escapeSqlLikePattern(conferenceLinkFragment)}%`,
59
+ },
60
+ },
61
+ },
62
+ ],
63
+ },
64
+ first: CALENDAR_EVENT_PAGE_SIZE,
65
+ ...(isNonEmptyString(cursor) ? { after: cursor } : {}),
66
+ },
67
+ edges: {
68
+ node: {
69
+ id: true,
70
+ title: true,
71
+ startsAt: true,
72
+ conferenceLink: { primaryLinkUrl: true },
73
+ },
74
+ },
75
+ pageInfo: { hasNextPage: true, endCursor: true },
76
+ },
77
+ });
78
+ const nodes = (queryResult.calendarEvents?.edges ?? []).map(
79
+ ({ node }) => node,
80
+ );
81
+ const calendarEvents = nodes.flatMap(
82
+ ({ id, title, startsAt, conferenceLink }) =>
83
+ isNonEmptyString(startsAt)
84
+ ? [
85
+ {
86
+ id,
87
+ title:
88
+ title === RESTRICTED_FIELD_PLACEHOLDER ? null : (title ?? null),
89
+ startsAt,
90
+ conferenceLink: conferenceLink ?? null,
91
+ },
92
+ ]
93
+ : [],
94
+ );
95
+
96
+ if (calendarEvents.length !== nodes.length) {
97
+ return undefined;
98
+ }
99
+
100
+ const pageInfo = queryResult.calendarEvents?.pageInfo;
101
+
102
+ if (!(pageInfo?.hasNextPage ?? false)) {
103
+ return calendarEvents;
104
+ }
105
+
106
+ if (!isNonEmptyString(pageInfo?.endCursor)) {
107
+ return undefined;
108
+ }
109
+
110
+ const followingCalendarEvents = await listCalendarEventPages({
111
+ coreApiClient,
112
+ earliestStart,
113
+ latestStart,
114
+ conferenceLinkFragment,
115
+ cursor: pageInfo.endCursor,
116
+ pageIndex: pageIndex + 1,
117
+ });
118
+
119
+ return isDefined(followingCalendarEvents)
120
+ ? [...calendarEvents, ...followingCalendarEvents]
121
+ : undefined;
122
+ };
123
+
124
+ export const listCalendarEventsInWindow = ({
125
+ coreApiClient,
126
+ earliestStart,
127
+ latestStart,
128
+ conferenceLinkFragment,
129
+ }: {
130
+ coreApiClient: Pick<CoreApiClient, 'query'>;
131
+ earliestStart: string;
132
+ latestStart: string;
133
+ conferenceLinkFragment: string;
134
+ }): Promise<CalendarEventCandidate[] | undefined> =>
135
+ listCalendarEventPages({
136
+ coreApiClient,
137
+ earliestStart,
138
+ latestStart,
139
+ conferenceLinkFragment,
140
+ cursor: undefined,
141
+ pageIndex: 0,
142
+ });
@@ -0,0 +1,79 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ import {
4
+ MEET_LIST_PAGE_SIZE,
5
+ MAX_MEET_LIST_PAGES,
6
+ } from 'src/logic-functions/constants/meet-api.constant';
7
+ import { type MeetCollectionPage } from 'src/logic-functions/types/meet-collection-page.type';
8
+ import { MeetException } from 'src/logic-functions/types/meet-exception.type';
9
+ import { buildMeetUrlOrThrow } from 'src/logic-functions/utils/build-meet-url-or-throw.util';
10
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
11
+
12
+ type MeetCollectionRequest<TCollectionKey extends string> = {
13
+ accessToken: string;
14
+ path: string;
15
+ collectionKey: TCollectionKey;
16
+ filter?: string;
17
+ };
18
+
19
+ const listMeetCollectionPagesOrThrow = async <
20
+ TCollectionKey extends string,
21
+ TItem,
22
+ >({
23
+ accessToken,
24
+ path,
25
+ collectionKey,
26
+ filter,
27
+ pageToken,
28
+ pageIndex,
29
+ }: MeetCollectionRequest<TCollectionKey> & {
30
+ pageToken: string | undefined;
31
+ pageIndex: number;
32
+ }): Promise<TItem[]> => {
33
+ if (pageIndex >= MAX_MEET_LIST_PAGES) {
34
+ throw new MeetException({
35
+ message: `Google Meet ${collectionKey} pagination exceeded its limit`,
36
+ code: 'PAGINATION_LIMIT_EXCEEDED',
37
+ });
38
+ }
39
+
40
+ const page = await fetchMeetJson<
41
+ MeetCollectionPage<TCollectionKey, TItem>
42
+ >({
43
+ accessToken,
44
+ url: buildMeetUrlOrThrow({
45
+ path,
46
+ queryParameters: {
47
+ filter,
48
+ pageSize: String(MEET_LIST_PAGE_SIZE),
49
+ pageToken,
50
+ },
51
+ }),
52
+ });
53
+ const items: TItem[] = page[collectionKey] ?? [];
54
+
55
+ if (!isNonEmptyString(page.nextPageToken)) {
56
+ return items;
57
+ }
58
+
59
+ return [
60
+ ...items,
61
+ ...(await listMeetCollectionPagesOrThrow<TCollectionKey, TItem>({
62
+ accessToken,
63
+ path,
64
+ collectionKey,
65
+ filter,
66
+ pageToken: page.nextPageToken,
67
+ pageIndex: pageIndex + 1,
68
+ })),
69
+ ];
70
+ };
71
+
72
+ export const listMeetCollection = <TCollectionKey extends string, TItem>(
73
+ request: MeetCollectionRequest<TCollectionKey>,
74
+ ): Promise<TItem[]> =>
75
+ listMeetCollectionPagesOrThrow<TCollectionKey, TItem>({
76
+ ...request,
77
+ pageToken: undefined,
78
+ pageIndex: 0,
79
+ });
@@ -0,0 +1,22 @@
1
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
2
+ import { buildMeetConferenceRecordFilter } from 'src/logic-functions/utils/build-meet-conference-record-filter.util';
3
+ import { listMeetCollection } from 'src/logic-functions/utils/list-meet-collection.util';
4
+
5
+ export const listMeetConferenceRecords = ({
6
+ accessToken,
7
+ startedAfter,
8
+ startedBefore,
9
+ }: {
10
+ accessToken: string;
11
+ startedAfter: Date;
12
+ startedBefore: Date;
13
+ }): Promise<MeetConferenceRecord[]> =>
14
+ listMeetCollection<'conferenceRecords', MeetConferenceRecord>({
15
+ accessToken,
16
+ path: 'conferenceRecords',
17
+ collectionKey: 'conferenceRecords',
18
+ filter: buildMeetConferenceRecordFilter({
19
+ startedAfter,
20
+ startedBefore,
21
+ }),
22
+ });
@@ -0,0 +1,15 @@
1
+ import { type MeetParticipant } from 'src/logic-functions/types/meet-participant.type';
2
+ import { listMeetCollection } from 'src/logic-functions/utils/list-meet-collection.util';
3
+
4
+ export const listMeetParticipants = ({
5
+ accessToken,
6
+ conferenceRecordName,
7
+ }: {
8
+ accessToken: string;
9
+ conferenceRecordName: string;
10
+ }): Promise<MeetParticipant[]> =>
11
+ listMeetCollection<'participants', MeetParticipant>({
12
+ accessToken,
13
+ path: `${conferenceRecordName}/participants`,
14
+ collectionKey: 'participants',
15
+ });
@@ -0,0 +1,15 @@
1
+ import { type MeetRecording } from 'src/logic-functions/types/meet-recording.type';
2
+ import { listMeetCollection } from 'src/logic-functions/utils/list-meet-collection.util';
3
+
4
+ export const listMeetRecordings = ({
5
+ accessToken,
6
+ conferenceRecordName,
7
+ }: {
8
+ accessToken: string;
9
+ conferenceRecordName: string;
10
+ }): Promise<MeetRecording[]> =>
11
+ listMeetCollection<'recordings', MeetRecording>({
12
+ accessToken,
13
+ path: `${conferenceRecordName}/recordings`,
14
+ collectionKey: 'recordings',
15
+ });
@@ -0,0 +1,15 @@
1
+ import { type MeetSmartNote } from 'src/logic-functions/types/meet-smart-note.type';
2
+ import { listMeetCollection } from 'src/logic-functions/utils/list-meet-collection.util';
3
+
4
+ export const listMeetSmartNotes = ({
5
+ accessToken,
6
+ conferenceRecordName,
7
+ }: {
8
+ accessToken: string;
9
+ conferenceRecordName: string;
10
+ }): Promise<MeetSmartNote[]> =>
11
+ listMeetCollection<'smartNotes', MeetSmartNote>({
12
+ accessToken,
13
+ path: `${conferenceRecordName}/smartNotes`,
14
+ collectionKey: 'smartNotes',
15
+ });
@@ -0,0 +1,15 @@
1
+ import { type MeetTranscriptEntry } from 'src/logic-functions/types/meet-transcript-entry.type';
2
+ import { listMeetCollection } from 'src/logic-functions/utils/list-meet-collection.util';
3
+
4
+ export const listMeetTranscriptEntries = ({
5
+ accessToken,
6
+ transcriptName,
7
+ }: {
8
+ accessToken: string;
9
+ transcriptName: string;
10
+ }): Promise<MeetTranscriptEntry[]> =>
11
+ listMeetCollection<'transcriptEntries', MeetTranscriptEntry>({
12
+ accessToken,
13
+ path: `${transcriptName}/entries`,
14
+ collectionKey: 'transcriptEntries',
15
+ });
@@ -0,0 +1,15 @@
1
+ import { type MeetTranscript } from 'src/logic-functions/types/meet-transcript.type';
2
+ import { listMeetCollection } from 'src/logic-functions/utils/list-meet-collection.util';
3
+
4
+ export const listMeetTranscripts = ({
5
+ accessToken,
6
+ conferenceRecordName,
7
+ }: {
8
+ accessToken: string;
9
+ conferenceRecordName: string;
10
+ }): Promise<MeetTranscript[]> =>
11
+ listMeetCollection<'transcripts', MeetTranscript>({
12
+ accessToken,
13
+ path: `${conferenceRecordName}/transcripts`,
14
+ collectionKey: 'transcripts',
15
+ });