@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.
- package/README.md +48 -2
- package/dependencies/yarn.lock +1863 -0
- package/manifest.json +1901 -0
- package/package.json +44 -4
- package/public/gallery/meet-cover-image-1.png +0 -0
- package/public/gallery/meet-cover-image-2.png +0 -0
- package/public/gallery/meet-cover-image-3.png +0 -0
- package/public/logo.svg +1 -0
- package/src/constants/meet-call-summary-prompt.constant.ts +54 -0
- package/src/constants/meet.constant.ts +17 -0
- package/src/constants/universal-identifiers.ts +35 -0
- package/src/logic-functions/constants/calendar-event-matching.constant.ts +3 -0
- package/src/logic-functions/constants/google-docs-api.constant.ts +10 -0
- package/src/logic-functions/constants/google-drive-api.constant.ts +1 -0
- package/src/logic-functions/constants/google-pubsub-push.constant.ts +7 -0
- package/src/logic-functions/constants/google-user-info.constant.ts +2 -0
- package/src/logic-functions/constants/google-workspace-events.constant.ts +17 -0
- package/src/logic-functions/constants/meet-api.constant.ts +9 -0
- package/src/logic-functions/constants/meet-call-summary.constant.ts +3 -0
- package/src/logic-functions/constants/meet-import.constant.ts +7 -0
- package/src/logic-functions/constants/meet-recording-import.constant.ts +7 -0
- package/src/logic-functions/constants/restricted-field-placeholder.constant.ts +2 -0
- package/src/logic-functions/meet-events-resolver.mjs +1345 -0
- package/src/logic-functions/meet-events-resolver.mjs.map +7 -0
- package/src/logic-functions/meet-events-resolver.ts +89 -0
- package/src/logic-functions/meet-handle-event.mjs +665 -0
- package/src/logic-functions/meet-handle-event.mjs.map +7 -0
- package/src/logic-functions/meet-handle-event.ts +86 -0
- package/src/logic-functions/meet-identify-account.mjs +369 -0
- package/src/logic-functions/meet-identify-account.mjs.map +7 -0
- package/src/logic-functions/meet-identify-account.ts +42 -0
- package/src/logic-functions/meet-import-conference.mjs +1465 -0
- package/src/logic-functions/meet-import-conference.mjs.map +7 -0
- package/src/logic-functions/meet-import-conference.ts +101 -0
- package/src/logic-functions/meet-import-recording.mjs +794 -0
- package/src/logic-functions/meet-import-recording.mjs.map +7 -0
- package/src/logic-functions/meet-import-recording.ts +99 -0
- package/src/logic-functions/meet-queue-conference-imports.mjs +711 -0
- package/src/logic-functions/meet-queue-conference-imports.mjs.map +7 -0
- package/src/logic-functions/meet-queue-conference-imports.ts +62 -0
- package/src/logic-functions/meet-refresh-connections.mjs +457 -0
- package/src/logic-functions/meet-refresh-connections.mjs.map +7 -0
- package/src/logic-functions/meet-refresh-connections.ts +64 -0
- package/src/logic-functions/meet-register-connection.mjs +837 -0
- package/src/logic-functions/meet-register-connection.mjs.map +7 -0
- package/src/logic-functions/meet-register-connection.ts +81 -0
- package/src/logic-functions/meet-summarize-call-recording.mjs +645 -0
- package/src/logic-functions/meet-summarize-call-recording.mjs.map +7 -0
- package/src/logic-functions/meet-summarize-call-recording.ts +111 -0
- package/src/logic-functions/meet-unregister-connection.mjs +610 -0
- package/src/logic-functions/meet-unregister-connection.mjs.map +7 -0
- package/src/logic-functions/meet-unregister-connection.ts +57 -0
- package/src/logic-functions/types/calendar-event-candidate.type.ts +6 -0
- package/src/logic-functions/types/call-recording-for-summary.type.ts +5 -0
- package/src/logic-functions/types/call-recording-sync-fields.type.ts +12 -0
- package/src/logic-functions/types/call-recording-upsert-outcome.type.ts +4 -0
- package/src/logic-functions/types/google-doc-lists.type.ts +4 -0
- package/src/logic-functions/types/google-doc-markdown-segment.type.ts +5 -0
- package/src/logic-functions/types/google-doc-paragraph-element.type.ts +8 -0
- package/src/logic-functions/types/google-doc-paragraph.type.ts +7 -0
- package/src/logic-functions/types/google-doc-tab.type.ts +10 -0
- package/src/logic-functions/types/google-doc.type.ts +6 -0
- package/src/logic-functions/types/google-pubsub-push-body.type.ts +6 -0
- package/src/logic-functions/types/google-request-method.type.ts +1 -0
- package/src/logic-functions/types/google-user-info.type.ts +4 -0
- package/src/logic-functions/types/google-workspace-events-operation.type.ts +8 -0
- package/src/logic-functions/types/meet-call-summary-outcome.type.ts +6 -0
- package/src/logic-functions/types/meet-collection-page.type.ts +3 -0
- package/src/logic-functions/types/meet-conference-record.type.ts +7 -0
- package/src/logic-functions/types/meet-conference-sync-outcome.type.ts +5 -0
- package/src/logic-functions/types/meet-conference-sync-result.type.ts +7 -0
- package/src/logic-functions/types/meet-daily-job-name.type.ts +1 -0
- package/src/logic-functions/types/meet-event-data.type.ts +5 -0
- package/src/logic-functions/types/meet-event-outcome.type.ts +4 -0
- package/src/logic-functions/types/meet-event-subscription.type.ts +8 -0
- package/src/logic-functions/types/meet-event.type.ts +5 -0
- package/src/logic-functions/types/meet-exception-code.type.ts +12 -0
- package/src/logic-functions/types/meet-exception.type.ts +25 -0
- package/src/logic-functions/types/meet-participant.type.ts +8 -0
- package/src/logic-functions/types/meet-recording-import-outcome.type.ts +6 -0
- package/src/logic-functions/types/meet-recording.type.ts +7 -0
- package/src/logic-functions/types/meet-smart-note.type.ts +7 -0
- package/src/logic-functions/types/meet-space.type.ts +5 -0
- package/src/logic-functions/types/meet-transcript-entry.type.ts +8 -0
- package/src/logic-functions/types/meet-transcript.type.ts +7 -0
- package/src/logic-functions/types/transcript-entry.type.ts +7 -0
- package/src/logic-functions/utils/build-google-api-url-or-throw.util.ts +30 -0
- package/src/logic-functions/utils/build-google-doc-markdown-segment.util.ts +67 -0
- package/src/logic-functions/utils/build-meet-artifact-import-job.util.ts +25 -0
- package/src/logic-functions/utils/build-meet-call-recording-sync-fields.util.ts +48 -0
- package/src/logic-functions/utils/build-meet-call-summary-job.util.ts +19 -0
- package/src/logic-functions/utils/build-meet-call-summary-prompt.util.ts +50 -0
- package/src/logic-functions/utils/build-meet-conference-import-job.util.ts +26 -0
- package/src/logic-functions/utils/build-meet-conference-import-payload.util.ts +18 -0
- package/src/logic-functions/utils/build-meet-conference-record-filter.util.ts +8 -0
- package/src/logic-functions/utils/build-meet-daily-job.util.ts +17 -0
- package/src/logic-functions/utils/build-meet-recording-import-job.util.ts +20 -0
- package/src/logic-functions/utils/build-meet-url-or-throw.util.ts +15 -0
- package/src/logic-functions/utils/build-meet-user-target-resource.util.ts +2 -0
- package/src/logic-functions/utils/can-renew-meet-event-subscription.util.ts +18 -0
- package/src/logic-functions/utils/chunk-into-batches.util.ts +10 -0
- package/src/logic-functions/utils/claim-meet-event-subscription.util.ts +10 -0
- package/src/logic-functions/utils/compute-call-recording-id-for-meet-conference.util.ts +16 -0
- package/src/logic-functions/utils/convert-google-doc-paragraph-to-markdown.util.ts +62 -0
- package/src/logic-functions/utils/convert-google-doc-tab-to-markdown.util.ts +49 -0
- package/src/logic-functions/utils/create-meet-event-subscription-or-throw.util.ts +41 -0
- package/src/logic-functions/utils/delete-meet-event-subscription.util.ts +22 -0
- package/src/logic-functions/utils/enqueue-meet-conference-imports-or-throw.util.ts +39 -0
- package/src/logic-functions/utils/enqueue-meet-daily-jobs-or-throw.util.ts +35 -0
- package/src/logic-functions/utils/ensure-meet-event-subscription-or-throw.util.ts +51 -0
- package/src/logic-functions/utils/escape-markdown-text.util.ts +4 -0
- package/src/logic-functions/utils/escape-sql-like-pattern.util.ts +2 -0
- package/src/logic-functions/utils/extract-bearer-token.util.ts +23 -0
- package/src/logic-functions/utils/extract-meet-name-from-doc-title.util.ts +16 -0
- package/src/logic-functions/utils/fetch-meet-json.util.ts +107 -0
- package/src/logic-functions/utils/find-call-recording-for-summary.util.ts +38 -0
- package/src/logic-functions/utils/find-call-recording-video-state.util.ts +25 -0
- package/src/logic-functions/utils/find-meet-calendar-event.util.ts +74 -0
- package/src/logic-functions/utils/find-meet-conference-title.util.ts +38 -0
- package/src/logic-functions/utils/find-meet-event-subscription.util.ts +32 -0
- package/src/logic-functions/utils/find-meet-smart-notes-markdown.util.ts +32 -0
- package/src/logic-functions/utils/format-seconds-as-clock-timestamp.util.ts +20 -0
- package/src/logic-functions/utils/get-conference-record-name-from-artifact-name.util.ts +6 -0
- package/src/logic-functions/utils/get-connection-access-token-or-throw.util.ts +18 -0
- package/src/logic-functions/utils/get-google-doc-title.util.ts +31 -0
- package/src/logic-functions/utils/get-google-doc.util.ts +30 -0
- package/src/logic-functions/utils/get-google-drive-file-size-bytes-or-throw.util.ts +31 -0
- package/src/logic-functions/utils/get-meet-conference-record.util.ts +18 -0
- package/src/logic-functions/utils/get-meet-connection-subscription-key.util.ts +3 -0
- package/src/logic-functions/utils/get-meet-event-subscription-key.util.ts +2 -0
- package/src/logic-functions/utils/get-meet-participant-display-name.util.ts +20 -0
- package/src/logic-functions/utils/get-meet-recording-drive-file-id.util.ts +16 -0
- package/src/logic-functions/utils/get-meet-recording.util.ts +18 -0
- package/src/logic-functions/utils/get-meet-space.util.ts +15 -0
- package/src/logic-functions/utils/get-random-delay-milliseconds.util.ts +4 -0
- package/src/logic-functions/utils/is-google-doc-unreadable-error.util.ts +9 -0
- package/src/logic-functions/utils/is-google-pubsub-push-authorized.util.ts +31 -0
- package/src/logic-functions/utils/is-meet-ai-summary-enabled-for-member.util.ts +22 -0
- package/src/logic-functions/utils/is-transcript-entry-list.util.ts +16 -0
- package/src/logic-functions/utils/join-google-doc-markdown-segments.util.ts +102 -0
- package/src/logic-functions/utils/list-calendar-events-in-window.util.ts +142 -0
- package/src/logic-functions/utils/list-meet-collection.util.ts +79 -0
- package/src/logic-functions/utils/list-meet-conference-records.util.ts +22 -0
- package/src/logic-functions/utils/list-meet-participants.util.ts +15 -0
- package/src/logic-functions/utils/list-meet-recordings.util.ts +15 -0
- package/src/logic-functions/utils/list-meet-smart-notes.util.ts +15 -0
- package/src/logic-functions/utils/list-meet-transcript-entries.util.ts +15 -0
- package/src/logic-functions/utils/list-meet-transcripts.util.ts +15 -0
- package/src/logic-functions/utils/map-meet-transcript-entries.util.ts +64 -0
- package/src/logic-functions/utils/normalize-meeting-url.util.ts +18 -0
- package/src/logic-functions/utils/open-google-drive-file-download-or-throw.util.ts +36 -0
- package/src/logic-functions/utils/parse-meet-call-summary-response.util.ts +36 -0
- package/src/logic-functions/utils/parse-meet-event-data-or-throw.util.ts +36 -0
- package/src/logic-functions/utils/parse-meet-event-or-throw.util.ts +35 -0
- package/src/logic-functions/utils/parse-retry-after-milliseconds.util.ts +27 -0
- package/src/logic-functions/utils/put-stream-to-upload-url-or-throw.util.ts +73 -0
- package/src/logic-functions/utils/read-meet-event-subscription-or-throw.util.ts +24 -0
- package/src/logic-functions/utils/release-meet-event-subscription.util.ts +29 -0
- package/src/logic-functions/utils/renew-meet-event-subscription-or-throw.util.ts +32 -0
- package/src/logic-functions/utils/run-meet-call-summarizer-or-throw.util.ts +28 -0
- package/src/logic-functions/utils/save-call-recording-summary-if-empty.util.ts +29 -0
- package/src/logic-functions/utils/save-call-recording-video.util.ts +23 -0
- package/src/logic-functions/utils/should-generate-meet-ai-summary.util.ts +17 -0
- package/src/logic-functions/utils/sleep-for-milliseconds.util.ts +2 -0
- package/src/logic-functions/utils/split-surrounding-whitespace.util.ts +10 -0
- package/src/logic-functions/utils/store-meet-connection-subscription.util.ts +46 -0
- package/src/logic-functions/utils/sync-meet-conference-or-throw.util.ts +129 -0
- package/src/logic-functions/utils/upload-google-drive-file-as-call-recording-video-or-throw.util.ts +73 -0
- package/src/logic-functions/utils/upsert-call-recording-or-throw.util.ts +104 -0
- package/src/logic-functions/utils/verify-google-pubsub-push-token-or-throw.util.ts +71 -0
- package/src/logic-functions/utils/wait-for-google-workspace-events-operation-or-throw.util.ts +53 -0
- package/tsconfig.json +39 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { isNonEmptyArray, isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
3
|
+
import { isDefined } from 'twenty-sdk/utils';
|
|
4
|
+
|
|
5
|
+
import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
|
|
6
|
+
import { type MeetConferenceSyncResult } from 'src/logic-functions/types/meet-conference-sync-result.type';
|
|
7
|
+
import { buildMeetCallRecordingSyncFields } from 'src/logic-functions/utils/build-meet-call-recording-sync-fields.util';
|
|
8
|
+
import { computeCallRecordingIdForMeetConference } from 'src/logic-functions/utils/compute-call-recording-id-for-meet-conference.util';
|
|
9
|
+
import { findMeetCalendarEvent } from 'src/logic-functions/utils/find-meet-calendar-event.util';
|
|
10
|
+
import { findMeetConferenceTitle } from 'src/logic-functions/utils/find-meet-conference-title.util';
|
|
11
|
+
import { findMeetSmartNotesMarkdown } from 'src/logic-functions/utils/find-meet-smart-notes-markdown.util';
|
|
12
|
+
import { getMeetSpace } from 'src/logic-functions/utils/get-meet-space.util';
|
|
13
|
+
import { listMeetParticipants } from 'src/logic-functions/utils/list-meet-participants.util';
|
|
14
|
+
import { listMeetRecordings } from 'src/logic-functions/utils/list-meet-recordings.util';
|
|
15
|
+
import { listMeetSmartNotes } from 'src/logic-functions/utils/list-meet-smart-notes.util';
|
|
16
|
+
import { listMeetTranscriptEntries } from 'src/logic-functions/utils/list-meet-transcript-entries.util';
|
|
17
|
+
import { listMeetTranscripts } from 'src/logic-functions/utils/list-meet-transcripts.util';
|
|
18
|
+
import { mapMeetTranscriptEntries } from 'src/logic-functions/utils/map-meet-transcript-entries.util';
|
|
19
|
+
import { shouldGenerateMeetAiSummary } from 'src/logic-functions/utils/should-generate-meet-ai-summary.util';
|
|
20
|
+
import { upsertCallRecordingOrThrow } from 'src/logic-functions/utils/upsert-call-recording-or-throw.util';
|
|
21
|
+
|
|
22
|
+
export const syncMeetConferenceOrThrow = async ({
|
|
23
|
+
accessToken,
|
|
24
|
+
coreApiClient,
|
|
25
|
+
conferenceRecord,
|
|
26
|
+
}: {
|
|
27
|
+
accessToken: string;
|
|
28
|
+
coreApiClient: Pick<CoreApiClient, 'query' | 'mutation'>;
|
|
29
|
+
conferenceRecord: Pick<
|
|
30
|
+
MeetConferenceRecord,
|
|
31
|
+
'name' | 'startTime' | 'endTime' | 'space'
|
|
32
|
+
>;
|
|
33
|
+
}): Promise<MeetConferenceSyncResult> => {
|
|
34
|
+
const [transcripts, smartNotes, recordings] = await Promise.all([
|
|
35
|
+
listMeetTranscripts({
|
|
36
|
+
accessToken,
|
|
37
|
+
conferenceRecordName: conferenceRecord.name,
|
|
38
|
+
}),
|
|
39
|
+
listMeetSmartNotes({
|
|
40
|
+
accessToken,
|
|
41
|
+
conferenceRecordName: conferenceRecord.name,
|
|
42
|
+
}),
|
|
43
|
+
listMeetRecordings({
|
|
44
|
+
accessToken,
|
|
45
|
+
conferenceRecordName: conferenceRecord.name,
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
!isNonEmptyArray(transcripts) &&
|
|
51
|
+
!isNonEmptyArray(smartNotes) &&
|
|
52
|
+
!isNonEmptyArray(recordings)
|
|
53
|
+
) {
|
|
54
|
+
return { outcome: 'NO_ARTIFACT', shouldGenerateAiSummary: false };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const [participants, transcriptEntriesByTranscript, space, summaryMarkdown] =
|
|
58
|
+
await Promise.all([
|
|
59
|
+
listMeetParticipants({
|
|
60
|
+
accessToken,
|
|
61
|
+
conferenceRecordName: conferenceRecord.name,
|
|
62
|
+
}),
|
|
63
|
+
Promise.all(
|
|
64
|
+
transcripts.map(({ name }) =>
|
|
65
|
+
listMeetTranscriptEntries({
|
|
66
|
+
accessToken,
|
|
67
|
+
transcriptName: name,
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
isNonEmptyString(conferenceRecord.space)
|
|
72
|
+
? getMeetSpace({ accessToken, spaceName: conferenceRecord.space })
|
|
73
|
+
: undefined,
|
|
74
|
+
findMeetSmartNotesMarkdown({ accessToken, smartNotes }),
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
const calendarEvent = isDefined(space)
|
|
78
|
+
? await findMeetCalendarEvent({
|
|
79
|
+
coreApiClient,
|
|
80
|
+
conferenceRecord,
|
|
81
|
+
space,
|
|
82
|
+
})
|
|
83
|
+
: undefined;
|
|
84
|
+
|
|
85
|
+
const transcriptEntries = mapMeetTranscriptEntries({
|
|
86
|
+
conferenceRecord,
|
|
87
|
+
participants,
|
|
88
|
+
transcriptEntries: transcriptEntriesByTranscript.flat(),
|
|
89
|
+
});
|
|
90
|
+
// Google lists recordings by start time; a call keeps its first video.
|
|
91
|
+
const recordingToImport = recordings.find(
|
|
92
|
+
({ state }) => state === 'FILE_GENERATED',
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const outcome = await upsertCallRecordingOrThrow({
|
|
96
|
+
coreApiClient,
|
|
97
|
+
callRecordingId: computeCallRecordingIdForMeetConference(
|
|
98
|
+
conferenceRecord.name,
|
|
99
|
+
),
|
|
100
|
+
fields: buildMeetCallRecordingSyncFields({
|
|
101
|
+
conferenceRecord,
|
|
102
|
+
title: await findMeetConferenceTitle({
|
|
103
|
+
accessToken,
|
|
104
|
+
calendarEvent,
|
|
105
|
+
artifacts: [...transcripts, ...smartNotes],
|
|
106
|
+
}),
|
|
107
|
+
summaryMarkdown,
|
|
108
|
+
transcriptEntries,
|
|
109
|
+
hasRecordingFile: isDefined(recordingToImport),
|
|
110
|
+
calendarEvent,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (outcome === 'SKIPPED_DELETED') {
|
|
115
|
+
return { outcome, shouldGenerateAiSummary: false };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
outcome,
|
|
120
|
+
shouldGenerateAiSummary: shouldGenerateMeetAiSummary({
|
|
121
|
+
transcriptEntries,
|
|
122
|
+
summaryMarkdown,
|
|
123
|
+
smartNotes,
|
|
124
|
+
}),
|
|
125
|
+
...(isDefined(recordingToImport)
|
|
126
|
+
? { recordingNameToImport: recordingToImport.name }
|
|
127
|
+
: {}),
|
|
128
|
+
};
|
|
129
|
+
};
|
package/src/logic-functions/utils/upload-google-drive-file-as-call-recording-video-or-throw.util.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
import { MetadataApiClient } from 'twenty-client-sdk/metadata';
|
|
3
|
+
import { isDefined } from 'twenty-sdk/utils';
|
|
4
|
+
|
|
5
|
+
import { CALL_RECORDING_VIDEO_FIELD_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';
|
|
6
|
+
import {
|
|
7
|
+
MEET_RECORDING_FILE_FOLDER,
|
|
8
|
+
MEET_RECORDING_FILE_NAME,
|
|
9
|
+
MEET_RECORDING_TRANSFER_TIMEOUT_MILLISECONDS,
|
|
10
|
+
} from 'src/logic-functions/constants/meet-recording-import.constant';
|
|
11
|
+
import { MeetException } from 'src/logic-functions/types/meet-exception.type';
|
|
12
|
+
import { openGoogleDriveFileDownloadOrThrow } from 'src/logic-functions/utils/open-google-drive-file-download-or-throw.util';
|
|
13
|
+
import { putStreamToUploadUrlOrThrow } from 'src/logic-functions/utils/put-stream-to-upload-url-or-throw.util';
|
|
14
|
+
|
|
15
|
+
export const uploadGoogleDriveFileAsCallRecordingVideoOrThrow = async ({
|
|
16
|
+
accessToken,
|
|
17
|
+
driveFileId,
|
|
18
|
+
sizeBytes,
|
|
19
|
+
}: {
|
|
20
|
+
accessToken: string;
|
|
21
|
+
driveFileId: string;
|
|
22
|
+
sizeBytes: number;
|
|
23
|
+
}): Promise<string> => {
|
|
24
|
+
const metadataApiClient = new MetadataApiClient({ runAs: 'application' });
|
|
25
|
+
const { createFileUpload: uploadTarget } = await metadataApiClient.mutation({
|
|
26
|
+
createFileUpload: {
|
|
27
|
+
__args: {
|
|
28
|
+
filename: MEET_RECORDING_FILE_NAME,
|
|
29
|
+
size: sizeBytes,
|
|
30
|
+
fileFolder: MEET_RECORDING_FILE_FOLDER,
|
|
31
|
+
fieldMetadataUniversalIdentifier:
|
|
32
|
+
CALL_RECORDING_VIDEO_FIELD_UNIVERSAL_IDENTIFIER,
|
|
33
|
+
},
|
|
34
|
+
fileId: true,
|
|
35
|
+
uploadUrl: true,
|
|
36
|
+
contentType: true,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
!isDefined(uploadTarget) ||
|
|
42
|
+
!isNonEmptyString(uploadTarget.fileId) ||
|
|
43
|
+
!isNonEmptyString(uploadTarget.uploadUrl) ||
|
|
44
|
+
!isNonEmptyString(uploadTarget.contentType)
|
|
45
|
+
) {
|
|
46
|
+
throw new MeetException({
|
|
47
|
+
message: 'createFileUpload returned no upload target',
|
|
48
|
+
code: 'FILE_UPLOAD_FAILED',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const signal = AbortSignal.timeout(
|
|
53
|
+
MEET_RECORDING_TRANSFER_TIMEOUT_MILLISECONDS,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
await putStreamToUploadUrlOrThrow({
|
|
57
|
+
stream: await openGoogleDriveFileDownloadOrThrow({
|
|
58
|
+
accessToken,
|
|
59
|
+
driveFileId,
|
|
60
|
+
signal,
|
|
61
|
+
}),
|
|
62
|
+
sizeBytes,
|
|
63
|
+
uploadUrl: uploadTarget.uploadUrl,
|
|
64
|
+
contentType: uploadTarget.contentType,
|
|
65
|
+
signal,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await metadataApiClient.mutation({
|
|
69
|
+
completeFileUpload: { __args: { fileId: uploadTarget.fileId }, id: true },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return uploadTarget.fileId;
|
|
73
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
import { isDefined } from 'twenty-sdk/utils';
|
|
3
|
+
|
|
4
|
+
import { type CallRecordingSyncFields } from 'src/logic-functions/types/call-recording-sync-fields.type';
|
|
5
|
+
import { type CallRecordingUpsertOutcome } from 'src/logic-functions/types/call-recording-upsert-outcome.type';
|
|
6
|
+
|
|
7
|
+
const doesCallRecordingMatchOrThrow = async ({
|
|
8
|
+
coreApiClient,
|
|
9
|
+
filter,
|
|
10
|
+
}: {
|
|
11
|
+
coreApiClient: Pick<CoreApiClient, 'query'>;
|
|
12
|
+
filter: {
|
|
13
|
+
id: { eq: string };
|
|
14
|
+
deletedAt?: { is: 'NOT_NULL' };
|
|
15
|
+
};
|
|
16
|
+
}): Promise<boolean> => {
|
|
17
|
+
const queryResult = await coreApiClient.query({
|
|
18
|
+
callRecordings: {
|
|
19
|
+
__args: { filter, first: 1 },
|
|
20
|
+
edges: { node: { id: true } },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return isDefined(queryResult.callRecordings?.edges?.[0]?.node);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const updateCallRecordingOrThrow = async ({
|
|
28
|
+
coreApiClient,
|
|
29
|
+
callRecordingId,
|
|
30
|
+
fields,
|
|
31
|
+
}: {
|
|
32
|
+
coreApiClient: Pick<CoreApiClient, 'mutation'>;
|
|
33
|
+
callRecordingId: string;
|
|
34
|
+
fields: CallRecordingSyncFields;
|
|
35
|
+
}): Promise<void> => {
|
|
36
|
+
await coreApiClient.mutation({
|
|
37
|
+
updateCallRecording: {
|
|
38
|
+
__args: { id: callRecordingId, data: fields },
|
|
39
|
+
id: true,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const upsertCallRecordingOrThrow = async ({
|
|
45
|
+
coreApiClient,
|
|
46
|
+
callRecordingId,
|
|
47
|
+
fields,
|
|
48
|
+
}: {
|
|
49
|
+
coreApiClient: Pick<CoreApiClient, 'query' | 'mutation'>;
|
|
50
|
+
callRecordingId: string;
|
|
51
|
+
fields: CallRecordingSyncFields;
|
|
52
|
+
}): Promise<CallRecordingUpsertOutcome> => {
|
|
53
|
+
if (
|
|
54
|
+
await doesCallRecordingMatchOrThrow({
|
|
55
|
+
coreApiClient,
|
|
56
|
+
filter: { id: { eq: callRecordingId }, deletedAt: { is: 'NOT_NULL' } },
|
|
57
|
+
})
|
|
58
|
+
) {
|
|
59
|
+
return 'SKIPPED_DELETED';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
await doesCallRecordingMatchOrThrow({
|
|
64
|
+
coreApiClient,
|
|
65
|
+
filter: { id: { eq: callRecordingId } },
|
|
66
|
+
})
|
|
67
|
+
) {
|
|
68
|
+
await updateCallRecordingOrThrow({
|
|
69
|
+
coreApiClient,
|
|
70
|
+
callRecordingId,
|
|
71
|
+
fields,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return 'UPDATED';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
await coreApiClient.mutation({
|
|
79
|
+
createCallRecording: {
|
|
80
|
+
__args: { data: { id: callRecordingId, ...fields } },
|
|
81
|
+
id: true,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return 'CREATED';
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const wasCreatedConcurrently = await doesCallRecordingMatchOrThrow({
|
|
88
|
+
coreApiClient,
|
|
89
|
+
filter: { id: { eq: callRecordingId } },
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (!wasCreatedConcurrently) {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await updateCallRecordingOrThrow({
|
|
97
|
+
coreApiClient,
|
|
98
|
+
callRecordingId,
|
|
99
|
+
fields,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return 'UPDATED';
|
|
103
|
+
}
|
|
104
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
import {
|
|
3
|
+
createRemoteJWKSet,
|
|
4
|
+
errors,
|
|
5
|
+
type JWTVerifyGetKey,
|
|
6
|
+
jwtVerify,
|
|
7
|
+
} from 'jose';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
GOOGLE_PUBSUB_PUSH_TOKEN_CLOCK_TOLERANCE_SECONDS,
|
|
11
|
+
GOOGLE_SIGNING_KEYS_URL,
|
|
12
|
+
GOOGLE_TOKEN_ISSUERS,
|
|
13
|
+
} from 'src/logic-functions/constants/google-pubsub-push.constant';
|
|
14
|
+
import { MeetException } from 'src/logic-functions/types/meet-exception.type';
|
|
15
|
+
import { extractBearerToken } from 'src/logic-functions/utils/extract-bearer-token.util';
|
|
16
|
+
|
|
17
|
+
const getGoogleSigningKey = createRemoteJWKSet(
|
|
18
|
+
new URL(GOOGLE_SIGNING_KEYS_URL),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const verifyGooglePubsubPushTokenOrThrow = async ({
|
|
22
|
+
authorizationHeader,
|
|
23
|
+
audience,
|
|
24
|
+
serviceAccountEmail,
|
|
25
|
+
getSigningKey,
|
|
26
|
+
}: {
|
|
27
|
+
authorizationHeader: string | undefined;
|
|
28
|
+
audience: string;
|
|
29
|
+
serviceAccountEmail: string;
|
|
30
|
+
getSigningKey?: JWTVerifyGetKey;
|
|
31
|
+
}): Promise<void> => {
|
|
32
|
+
const token = extractBearerToken(authorizationHeader);
|
|
33
|
+
|
|
34
|
+
if (!isNonEmptyString(token)) {
|
|
35
|
+
throw new MeetException({
|
|
36
|
+
message: 'The Pub/Sub push request has no bearer token',
|
|
37
|
+
code: 'PUSH_TOKEN_INVALID',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { payload } = await jwtVerify(
|
|
42
|
+
token,
|
|
43
|
+
getSigningKey ?? getGoogleSigningKey,
|
|
44
|
+
{
|
|
45
|
+
issuer: GOOGLE_TOKEN_ISSUERS,
|
|
46
|
+
audience,
|
|
47
|
+
algorithms: ['RS256'],
|
|
48
|
+
clockTolerance: GOOGLE_PUBSUB_PUSH_TOKEN_CLOCK_TOLERANCE_SECONDS,
|
|
49
|
+
},
|
|
50
|
+
).catch((error: unknown) => {
|
|
51
|
+
if (error instanceof errors.JOSEError) {
|
|
52
|
+
throw new MeetException({
|
|
53
|
+
message: `The Pub/Sub push token is invalid: ${error.message}`,
|
|
54
|
+
code: 'PUSH_TOKEN_INVALID',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw error;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
payload.email !== serviceAccountEmail ||
|
|
63
|
+
payload.email_verified !== true
|
|
64
|
+
) {
|
|
65
|
+
throw new MeetException({
|
|
66
|
+
message:
|
|
67
|
+
'The Pub/Sub push token was not issued to the configured service account',
|
|
68
|
+
code: 'PUSH_TOKEN_INVALID',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
|
|
5
|
+
GOOGLE_WORKSPACE_EVENTS_OPERATION_MAX_POLLS,
|
|
6
|
+
GOOGLE_WORKSPACE_EVENTS_OPERATION_POLL_DELAY_MILLISECONDS,
|
|
7
|
+
} from 'src/logic-functions/constants/google-workspace-events.constant';
|
|
8
|
+
import { MeetException } from 'src/logic-functions/types/meet-exception.type';
|
|
9
|
+
import { type GoogleWorkspaceEventsOperation } from 'src/logic-functions/types/google-workspace-events-operation.type';
|
|
10
|
+
import { buildGoogleApiUrlOrThrow } from 'src/logic-functions/utils/build-google-api-url-or-throw.util';
|
|
11
|
+
import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
|
|
12
|
+
import { sleepForMilliseconds } from 'src/logic-functions/utils/sleep-for-milliseconds.util';
|
|
13
|
+
|
|
14
|
+
export const waitForGoogleWorkspaceEventsOperationOrThrow = async ({
|
|
15
|
+
accessToken,
|
|
16
|
+
operation,
|
|
17
|
+
pollCount,
|
|
18
|
+
}: {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
operation: GoogleWorkspaceEventsOperation;
|
|
21
|
+
pollCount: number;
|
|
22
|
+
}): Promise<GoogleWorkspaceEventsOperation> => {
|
|
23
|
+
if (operation.done) {
|
|
24
|
+
return operation;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (
|
|
28
|
+
!isNonEmptyString(operation.name) ||
|
|
29
|
+
pollCount >= GOOGLE_WORKSPACE_EVENTS_OPERATION_MAX_POLLS
|
|
30
|
+
) {
|
|
31
|
+
throw new MeetException({
|
|
32
|
+
message: `Google did not finish the event subscription operation ${operation.name ?? 'without a name'}`,
|
|
33
|
+
code: 'EVENT_SUBSCRIPTION_FAILED',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await sleepForMilliseconds(
|
|
38
|
+
GOOGLE_WORKSPACE_EVENTS_OPERATION_POLL_DELAY_MILLISECONDS,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return waitForGoogleWorkspaceEventsOperationOrThrow({
|
|
42
|
+
accessToken,
|
|
43
|
+
operation: await fetchMeetJson<GoogleWorkspaceEventsOperation>({
|
|
44
|
+
accessToken,
|
|
45
|
+
url: buildGoogleApiUrlOrThrow({
|
|
46
|
+
baseUrl: GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
|
|
47
|
+
path: operation.name,
|
|
48
|
+
queryParameters: {},
|
|
49
|
+
}),
|
|
50
|
+
}),
|
|
51
|
+
pollCount: pollCount + 1,
|
|
52
|
+
});
|
|
53
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": false,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": ".",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"emitDecoratorMetadata": true,
|
|
12
|
+
"experimentalDecorators": true,
|
|
13
|
+
"importHelpers": true,
|
|
14
|
+
"allowUnreachableCode": false,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"alwaysStrict": true,
|
|
17
|
+
"noImplicitAny": true,
|
|
18
|
+
"strictBindCallApply": false,
|
|
19
|
+
"target": "es2020",
|
|
20
|
+
"module": "esnext",
|
|
21
|
+
"lib": ["es2020", "es2022.intl", "dom"],
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
"skipDefaultLibCheck": true,
|
|
24
|
+
"resolveJsonModule": true,
|
|
25
|
+
"paths": {
|
|
26
|
+
"src/*": ["./src/*"],
|
|
27
|
+
"~/*": ["./*"]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"exclude": [
|
|
31
|
+
"**/__tests__/**",
|
|
32
|
+
"node_modules",
|
|
33
|
+
"dist",
|
|
34
|
+
"**/*.test.ts",
|
|
35
|
+
"**/*.test.tsx",
|
|
36
|
+
"**/*.spec.ts",
|
|
37
|
+
"**/*.integration-test.ts"
|
|
38
|
+
]
|
|
39
|
+
}
|