@twentyhq/call-recorder 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/.env.example +5 -0
- package/.nvmrc +1 -0
- package/.oxlintrc.json +20 -0
- package/.yarnrc.yml +1 -0
- package/AGENTS.md +67 -0
- package/CLAUDE.md +67 -0
- package/README.md +24 -0
- package/SETUP.md +95 -0
- package/package.json +42 -0
- package/public/gallery/call-recorder-cover.png +0 -0
- package/public/logo.svg +5 -0
- package/src/__tests__/global-setup.ts +100 -0
- package/src/__tests__/schema.integration-test.ts +104 -0
- package/src/application-config.ts +96 -0
- package/src/constants/__tests__/call-recording-field-universal-identifiers.test.ts +19 -0
- package/src/constants/app-description.ts +2 -0
- package/src/constants/app-display-name.ts +1 -0
- package/src/constants/application-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-reconciliation-logic-function-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-record-page-layout-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-recording-front-component-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-recording-page-layout-tab-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-recording-page-layout-widget-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-everyone-left-timeout-seconds-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-failure-reason-on-call-recording-field-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-join-early-minutes-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-name-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-noone-joined-timeout-seconds-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-preference-off-option-id.ts +2 -0
- package/src/constants/call-recorder-preference-on-calendar-event-field-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-preference-on-calendar-event-view-field-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-preference-on-option-id.ts +2 -0
- package/src/constants/call-recorder-preference.ts +4 -0
- package/src/constants/call-recorder-waiting-room-timeout-seconds-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recording-audio-field-universal-identifier.ts +2 -0
- package/src/constants/call-recording-video-field-universal-identifier.ts +2 -0
- package/src/constants/default-role-universal-identifier.ts +2 -0
- package/src/constants/process-recall-webhook-logic-function-universal-identifier.ts +2 -0
- package/src/constants/recall-webhook-logic-function-universal-identifier.ts +2 -0
- package/src/constants/stale-bot-state-logic-function-universal-identifier.ts +2 -0
- package/src/default-role.ts +69 -0
- package/src/fields/call-recorder-failure-reason-on-call-recording.field.ts +22 -0
- package/src/fields/call-recorder-preference-on-calendar-event.field.ts +41 -0
- package/src/front-components/calendar-event-recording.front-component.tsx +13 -0
- package/src/front-components/components/CalendarEventRecording.tsx +39 -0
- package/src/front-components/components/CalendarEventRecordingBody.tsx +96 -0
- package/src/front-components/components/CalendarEventRecordingContent.tsx +111 -0
- package/src/front-components/components/RecordingTranscript.tsx +92 -0
- package/src/front-components/components/RecordingVideoPlayer.tsx +52 -0
- package/src/front-components/components/TranscriptEntryList.tsx +61 -0
- package/src/front-components/components/TranscriptEntryListItem.tsx +115 -0
- package/src/front-components/components/TranscriptErrorBox.tsx +48 -0
- package/src/front-components/components/TranscriptSpeakerAvatar.tsx +141 -0
- package/src/front-components/components/TranscriptSpeakerChip.tsx +51 -0
- package/src/front-components/constants/recording-theme-css-variables.ts +40 -0
- package/src/front-components/hooks/use-calendar-event-participants.ts +172 -0
- package/src/front-components/hooks/use-calendar-event-recording.ts +155 -0
- package/src/front-components/types/calendar-event-participant-by-speaker-name.type.ts +6 -0
- package/src/front-components/types/calendar-event-recording-participant.type.ts +7 -0
- package/src/front-components/types/transcript-entry.type.ts +13 -0
- package/src/front-components/utils/__tests__/find-active-transcript-entry-index.test.ts +66 -0
- package/src/front-components/utils/__tests__/format-transcript-timestamp.test.ts +29 -0
- package/src/front-components/utils/__tests__/get-speaker-name-match-keys.test.ts +22 -0
- package/src/front-components/utils/__tests__/parse-transcript-entries.test.ts +162 -0
- package/src/front-components/utils/build-calendar-event-participant-by-speaker-name.util.ts +45 -0
- package/src/front-components/utils/find-active-transcript-entry-index.util.ts +77 -0
- package/src/front-components/utils/format-transcript-timestamp.util.ts +16 -0
- package/src/front-components/utils/get-absolute-avatar-url.util.ts +48 -0
- package/src/front-components/utils/get-calendar-event-participant-for-speaker-name.util.ts +24 -0
- package/src/front-components/utils/get-speaker-name-match-keys.util.ts +64 -0
- package/src/front-components/utils/get-video-file-extension.util.ts +23 -0
- package/src/front-components/utils/parse-transcript-entries.util.ts +85 -0
- package/src/logic-functions/__tests__/process-recall-webhook.test.ts +62 -0
- package/src/logic-functions/__tests__/recall-webhook.test.ts +180 -0
- package/src/logic-functions/constants/call-recorder-everyone-left-timeout-seconds-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-everyone-left-timeout-seconds.ts +1 -0
- package/src/logic-functions/constants/call-recorder-join-early-minutes-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-name-env-var-name.ts +1 -0
- package/src/logic-functions/constants/call-recorder-noone-joined-timeout-seconds-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-noone-joined-timeout-seconds.ts +1 -0
- package/src/logic-functions/constants/call-recorder-recording-retention-hours-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-waiting-room-timeout-seconds-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-waiting-room-timeout-seconds.ts +1 -0
- package/src/logic-functions/constants/call-recording-micro-credits-per-hour.ts +1 -0
- package/src/logic-functions/constants/call-recording-request-status.ts +5 -0
- package/src/logic-functions/constants/call-recording-status.ts +9 -0
- package/src/logic-functions/constants/default-call-recorder-join-early-minutes.ts +1 -0
- package/src/logic-functions/constants/default-call-recorder-name.ts +1 -0
- package/src/logic-functions/constants/default-call-recorder-recording-retention-hours.ts +2 -0
- package/src/logic-functions/constants/default-recall-region.ts +1 -0
- package/src/logic-functions/constants/milliseconds-per-minute.ts +1 -0
- package/src/logic-functions/constants/non-terminal-call-recording-statuses.ts +8 -0
- package/src/logic-functions/constants/recall-api-key-env-var-name.ts +1 -0
- package/src/logic-functions/constants/recall-api-max-attempts.ts +1 -0
- package/src/logic-functions/constants/recall-api-retry-delay-ms.ts +1 -0
- package/src/logic-functions/constants/recall-bot-automatic-leave.ts +74 -0
- package/src/logic-functions/constants/recall-bot-everyone-left-min-activate-after-seconds.ts +1 -0
- package/src/logic-functions/constants/recall-bot-recording-config.ts +34 -0
- package/src/logic-functions/constants/recall-region-env-var-name.ts +1 -0
- package/src/logic-functions/constants/recall-webhook-secret-env-var-name.ts +1 -0
- package/src/logic-functions/constants/restricted-field-placeholder.ts +3 -0
- package/src/logic-functions/constants/stale-bot-state-cron-pattern.ts +1 -0
- package/src/logic-functions/constants/twenty-page-size.ts +1 -0
- package/src/logic-functions/data/__tests__/complete-call-recording-ingestion.test.ts +55 -0
- package/src/logic-functions/data/__tests__/fetch-all-nodes.test.ts +43 -0
- package/src/logic-functions/data/__tests__/get-current-workspace-id.test.ts +38 -0
- package/src/logic-functions/data/__tests__/strip-restricted-field-value.test.ts +22 -0
- package/src/logic-functions/data/complete-call-recording-ingestion.util.ts +24 -0
- package/src/logic-functions/data/create-call-recording.util.ts +41 -0
- package/src/logic-functions/data/fetch-all-nodes.util.ts +44 -0
- package/src/logic-functions/data/fetch-calendar-events-by-filter.util.ts +80 -0
- package/src/logic-functions/data/fetch-calendar-events-by-ids.util.ts +20 -0
- package/src/logic-functions/data/fetch-calendar-events-by-starts-at-values.util.ts +19 -0
- package/src/logic-functions/data/find-call-recordings-by-calendar-event-ids.util.ts +17 -0
- package/src/logic-functions/data/find-call-recordings-by-filter.util.ts +102 -0
- package/src/logic-functions/data/find-call-recordings-by-ids.util.ts +17 -0
- package/src/logic-functions/data/find-open-scheduled-call-recordings.util.ts +14 -0
- package/src/logic-functions/data/get-current-workspace-id.util.ts +36 -0
- package/src/logic-functions/data/strip-restricted-field-value.util.ts +6 -0
- package/src/logic-functions/data/update-call-recording.util.ts +24 -0
- package/src/logic-functions/domain/__tests__/build-call-recorder-policy-result.test.ts +47 -0
- package/src/logic-functions/domain/__tests__/compute-call-recording-charge.test.ts +71 -0
- package/src/logic-functions/domain/__tests__/compute-call-recording-id-for-meeting.test.ts +37 -0
- package/src/logic-functions/domain/__tests__/compute-real-meeting-key.test.ts +88 -0
- package/src/logic-functions/domain/__tests__/is-call-recording-ingestion-complete.test.ts +59 -0
- package/src/logic-functions/domain/__tests__/is-call-recording-status-downgrade.test.ts +37 -0
- package/src/logic-functions/domain/__tests__/resolve-call-recorder-policy-result.test.ts +120 -0
- package/src/logic-functions/domain/__tests__/should-complete-call-recording-ingestion.test.ts +102 -0
- package/src/logic-functions/domain/aggregate-call-recorder-policy-results-by-meeting.util.ts +42 -0
- package/src/logic-functions/domain/build-call-recorder-policy-result.util.ts +53 -0
- package/src/logic-functions/domain/build-failed-transcript-marker.util.ts +13 -0
- package/src/logic-functions/domain/build-pending-transcript-marker.util.ts +13 -0
- package/src/logic-functions/domain/build-recall-routing-metadata.util.ts +12 -0
- package/src/logic-functions/domain/build-transcript-failure-reason.util.ts +7 -0
- package/src/logic-functions/domain/compute-call-recording-charge.util.ts +41 -0
- package/src/logic-functions/domain/compute-call-recording-id-for-meeting.util.ts +16 -0
- package/src/logic-functions/domain/compute-real-meeting-key.util.ts +48 -0
- package/src/logic-functions/domain/compute-recall-bot-join-at.util.ts +34 -0
- package/src/logic-functions/domain/is-call-recording-ingestion-complete.util.ts +19 -0
- package/src/logic-functions/domain/is-call-recording-status-downgrade.util.ts +37 -0
- package/src/logic-functions/domain/is-recall-recording-done-signal.util.ts +13 -0
- package/src/logic-functions/domain/map-recall-status-code-to-call-recording-status.util.ts +26 -0
- package/src/logic-functions/domain/parse-transcript-marker.util.ts +29 -0
- package/src/logic-functions/domain/resolve-call-recorder-policy-result.util.ts +72 -0
- package/src/logic-functions/domain/should-complete-call-recording-ingestion.util.ts +32 -0
- package/src/logic-functions/flows/__tests__/charge-completed-call-recording.test.ts +45 -0
- package/src/logic-functions/flows/__tests__/complete-and-charge-call-recording.test.ts +61 -0
- package/src/logic-functions/flows/__tests__/converge-diverged-call-recordings.test.ts +727 -0
- package/src/logic-functions/flows/__tests__/download-transcript.test.ts +74 -0
- package/src/logic-functions/flows/__tests__/handle-recall-webhook.test.ts +1301 -0
- package/src/logic-functions/flows/__tests__/heal-call-recordings-missing-bot.test.ts +225 -0
- package/src/logic-functions/flows/__tests__/ingest-call-recording-media.test.ts +153 -0
- package/src/logic-functions/flows/__tests__/reap-orphaned-call-recorders.test.ts +425 -0
- package/src/logic-functions/flows/__tests__/reconcile-call-recorder.test.ts +1007 -0
- package/src/logic-functions/flows/cancel-call-recording-request.util.ts +46 -0
- package/src/logic-functions/flows/charge-completed-call-recording.util.ts +31 -0
- package/src/logic-functions/flows/complete-and-charge-call-recording.util.ts +29 -0
- package/src/logic-functions/flows/converge-diverged-call-recordings-result.type.ts +8 -0
- package/src/logic-functions/flows/converge-diverged-call-recordings.util.ts +447 -0
- package/src/logic-functions/flows/download-transcript.util.ts +67 -0
- package/src/logic-functions/flows/ensure-call-recorder.util.ts +73 -0
- package/src/logic-functions/flows/handle-recall-webhook.util.ts +672 -0
- package/src/logic-functions/flows/heal-call-recordings-missing-bot.util.ts +82 -0
- package/src/logic-functions/flows/ingest-call-recording-media.util.ts +128 -0
- package/src/logic-functions/flows/persist-call-recording-progress.util.ts +58 -0
- package/src/logic-functions/flows/reap-orphaned-call-recorders.util.ts +183 -0
- package/src/logic-functions/flows/reconcile-call-recorder.util.ts +495 -0
- package/src/logic-functions/flows/reconcile-call-recording-transcript-artifact-result.type.ts +11 -0
- package/src/logic-functions/flows/reconcile-call-recording-transcript-artifact.util.ts +182 -0
- package/src/logic-functions/flows/reschedule-call-recording-bot.util.ts +69 -0
- package/src/logic-functions/process-recall-webhook.ts +23 -0
- package/src/logic-functions/recall-api/__tests__/extract-recall-bot-convergence.test.ts +153 -0
- package/src/logic-functions/recall-api/__tests__/extract-recall-media-urls.test.ts +67 -0
- package/src/logic-functions/recall-api/__tests__/recall-bot-api.test.ts +744 -0
- package/src/logic-functions/recall-api/__tests__/verify-recall-webhook-signature.test.ts +122 -0
- package/src/logic-functions/recall-api/cancel-recall-bot.util.ts +28 -0
- package/src/logic-functions/recall-api/create-async-recall-transcript.util.ts +47 -0
- package/src/logic-functions/recall-api/eject-recall-bot.util.ts +28 -0
- package/src/logic-functions/recall-api/extract-recall-bot-convergence.util.ts +149 -0
- package/src/logic-functions/recall-api/extract-recall-bot-id.util.ts +10 -0
- package/src/logic-functions/recall-api/extract-recall-media-urls.util.ts +30 -0
- package/src/logic-functions/recall-api/extract-twenty-workspace-id-from-recall-webhook.util.ts +8 -0
- package/src/logic-functions/recall-api/get-recall-api-config.util.ts +59 -0
- package/src/logic-functions/recall-api/get-recall-bot.util.ts +42 -0
- package/src/logic-functions/recall-api/get-recall-recording.util.ts +31 -0
- package/src/logic-functions/recall-api/get-recall-webhook-bot-metadata.util.ts +18 -0
- package/src/logic-functions/recall-api/list-recall-transcripts.util.ts +141 -0
- package/src/logic-functions/recall-api/list-scheduled-recall-bots.util.ts +106 -0
- package/src/logic-functions/recall-api/normalize-recall-timestamp.util.ts +14 -0
- package/src/logic-functions/recall-api/parse-recall-webhook-event.util.ts +88 -0
- package/src/logic-functions/recall-api/recall-bot-api-request.util.ts +165 -0
- package/src/logic-functions/recall-api/recall-transcript-summary.type.ts +5 -0
- package/src/logic-functions/recall-api/reschedule-recall-bot.util.ts +56 -0
- package/src/logic-functions/recall-api/retrieve-recall-transcript.util.ts +71 -0
- package/src/logic-functions/recall-api/schedule-recall-bot.util.ts +68 -0
- package/src/logic-functions/recall-api/verify-recall-webhook-signature.util.ts +109 -0
- package/src/logic-functions/recall-webhook.ts +90 -0
- package/src/logic-functions/reconcile-call-recorder-calendar-event.ts +178 -0
- package/src/logic-functions/reconcile-stale-bot-state.ts +106 -0
- package/src/logic-functions/types/calendar-event-record.type.ts +5 -0
- package/src/logic-functions/types/call-recorder-policy-calendar-event-input.type.ts +10 -0
- package/src/logic-functions/types/call-recorder-policy-input.type.ts +9 -0
- package/src/logic-functions/types/call-recorder-policy-not-required-reason.type.ts +5 -0
- package/src/logic-functions/types/call-recorder-policy-required-reason.type.ts +1 -0
- package/src/logic-functions/types/call-recorder-policy-result-for-calendar-event.type.ts +9 -0
- package/src/logic-functions/types/call-recorder-policy-result-for-meeting.type.ts +6 -0
- package/src/logic-functions/types/call-recorder-policy-result.type.ts +12 -0
- package/src/logic-functions/types/call-recorder-reconciliation-result.type.ts +16 -0
- package/src/logic-functions/types/call-recording-media-file.type.ts +1 -0
- package/src/logic-functions/types/call-recording-record.type.ts +15 -0
- package/src/logic-functions/types/call-recording-update-fields.type.ts +20 -0
- package/src/logic-functions/types/files-field-value.type.ts +1 -0
- package/src/logic-functions/types/meeting-recording.type.ts +7 -0
- package/src/logic-functions/types/recall-bot-operation-result.type.ts +19 -0
- package/src/logic-functions/types/recall-routing-metadata.type.ts +4 -0
- package/src/logic-functions/types/removed-call-recorder-occurrence.type.ts +6 -0
- package/src/logic-functions/types/transcript-marker.type.ts +6 -0
- package/src/logic-functions/utils/as-record.util.ts +6 -0
- package/src/logic-functions/utils/get-application-variable-value.util.ts +3 -0
- package/src/logic-functions/utils/get-record-at-path.util.ts +10 -0
- package/src/logic-functions/utils/get-string.util.ts +4 -0
- package/src/logic-functions/utils/get-unique-sorted-ids.util.ts +8 -0
- package/src/logic-functions/utils/is-non-empty-string.util.ts +5 -0
- package/src/page-layouts/calendar-event-recording-tab.ts +33 -0
- package/src/view-fields/call-recorder-preference-on-calendar-event.view-field.ts +27 -0
- package/tsconfig.json +42 -0
- package/tsconfig.spec.json +9 -0
- package/vitest.config.ts +31 -0
- package/vitest.unit.config.ts +14 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { reapOrphanedCallRecorders } from 'src/logic-functions/flows/reap-orphaned-call-recorders.util';
|
|
5
|
+
|
|
6
|
+
const listScheduledRecallBotsMock = vi.hoisted(() => vi.fn());
|
|
7
|
+
const cancelRecallBotMock = vi.hoisted(() => vi.fn());
|
|
8
|
+
const ejectRecallBotMock = vi.hoisted(() => vi.fn());
|
|
9
|
+
const getCurrentWorkspaceIdMock = vi.hoisted(() => vi.fn());
|
|
10
|
+
|
|
11
|
+
vi.mock('src/logic-functions/data/get-current-workspace-id.util', () => ({
|
|
12
|
+
getCurrentWorkspaceId: getCurrentWorkspaceIdMock,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
vi.mock(
|
|
16
|
+
'src/logic-functions/recall-api/list-scheduled-recall-bots.util',
|
|
17
|
+
() => ({
|
|
18
|
+
listScheduledRecallBots: listScheduledRecallBotsMock,
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
vi.mock('src/logic-functions/recall-api/cancel-recall-bot.util', () => ({
|
|
23
|
+
cancelRecallBot: cancelRecallBotMock,
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
vi.mock('src/logic-functions/recall-api/eject-recall-bot.util', () => ({
|
|
27
|
+
ejectRecallBot: ejectRecallBotMock,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const JOIN_AT_AFTER = '2026-01-01T08:00:00.000Z';
|
|
31
|
+
const JOIN_AT_BEFORE = '2026-01-02T12:00:00.000Z';
|
|
32
|
+
const CURRENT_WORKSPACE_ID = '123e4567-e89b-12d3-a456-426614174000';
|
|
33
|
+
const OTHER_WORKSPACE_ID = '123e4567-e89b-12d3-a456-426614174999';
|
|
34
|
+
|
|
35
|
+
type CallRecordingNode = {
|
|
36
|
+
id: string;
|
|
37
|
+
recordingRequestStatus?: string | null;
|
|
38
|
+
externalBotId?: string | null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
class FakeCoreApiClient {
|
|
42
|
+
constructor(private callRecordings: CallRecordingNode[]) {}
|
|
43
|
+
|
|
44
|
+
async query(query: any): Promise<any> {
|
|
45
|
+
const callRecordingIds = query.callRecordings.__args.filter.id.in;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
callRecordings: {
|
|
49
|
+
pageInfo: { hasNextPage: false, endCursor: undefined },
|
|
50
|
+
edges: this.callRecordings
|
|
51
|
+
.filter((callRecording) =>
|
|
52
|
+
callRecordingIds.includes(callRecording.id),
|
|
53
|
+
)
|
|
54
|
+
.map((node) => ({ node })),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const buildClient = (callRecordings: CallRecordingNode[]): CoreApiClient =>
|
|
61
|
+
new FakeCoreApiClient(callRecordings) as unknown as CoreApiClient;
|
|
62
|
+
|
|
63
|
+
const buildBot = ({
|
|
64
|
+
id,
|
|
65
|
+
twentyCallRecordingId,
|
|
66
|
+
twentyWorkspaceId,
|
|
67
|
+
}: {
|
|
68
|
+
id: string;
|
|
69
|
+
twentyCallRecordingId?: string;
|
|
70
|
+
twentyWorkspaceId?: string;
|
|
71
|
+
}) => ({
|
|
72
|
+
id,
|
|
73
|
+
metadata: {
|
|
74
|
+
...(twentyCallRecordingId === undefined ? {} : { twentyCallRecordingId }),
|
|
75
|
+
...(twentyWorkspaceId === undefined ? {} : { twentyWorkspaceId }),
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const buildCurrentWorkspaceBot = ({
|
|
80
|
+
id,
|
|
81
|
+
twentyCallRecordingId,
|
|
82
|
+
}: {
|
|
83
|
+
id: string;
|
|
84
|
+
twentyCallRecordingId: string;
|
|
85
|
+
}) =>
|
|
86
|
+
buildBot({
|
|
87
|
+
id,
|
|
88
|
+
twentyCallRecordingId,
|
|
89
|
+
twentyWorkspaceId: CURRENT_WORKSPACE_ID,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('reapOrphanedCallRecorders', () => {
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
95
|
+
getCurrentWorkspaceIdMock.mockReset();
|
|
96
|
+
getCurrentWorkspaceIdMock.mockReturnValue(CURRENT_WORKSPACE_ID);
|
|
97
|
+
listScheduledRecallBotsMock.mockReset();
|
|
98
|
+
cancelRecallBotMock.mockReset();
|
|
99
|
+
cancelRecallBotMock.mockResolvedValue({ ok: true });
|
|
100
|
+
ejectRecallBotMock.mockReset();
|
|
101
|
+
ejectRecallBotMock.mockResolvedValue({ ok: true });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('keeps bots that their call recording still references', async () => {
|
|
105
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
106
|
+
ok: true,
|
|
107
|
+
bots: [
|
|
108
|
+
buildCurrentWorkspaceBot({
|
|
109
|
+
id: 'claimed-bot',
|
|
110
|
+
twentyCallRecordingId: 'call-recording-1',
|
|
111
|
+
}),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await reapOrphanedCallRecorders({
|
|
116
|
+
client: buildClient([
|
|
117
|
+
{
|
|
118
|
+
id: 'call-recording-1',
|
|
119
|
+
recordingRequestStatus: 'REQUESTED',
|
|
120
|
+
externalBotId: 'claimed-bot',
|
|
121
|
+
},
|
|
122
|
+
]),
|
|
123
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
124
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(result).toEqual({
|
|
128
|
+
scannedBotCount: 1,
|
|
129
|
+
canceledExternalBotIds: [],
|
|
130
|
+
});
|
|
131
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('cancels bots whose call recording request was canceled locally', async () => {
|
|
135
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
136
|
+
ok: true,
|
|
137
|
+
bots: [
|
|
138
|
+
buildCurrentWorkspaceBot({
|
|
139
|
+
id: 'stale-cancel-bot',
|
|
140
|
+
twentyCallRecordingId: 'call-recording-1',
|
|
141
|
+
}),
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const result = await reapOrphanedCallRecorders({
|
|
146
|
+
client: buildClient([
|
|
147
|
+
{
|
|
148
|
+
id: 'call-recording-1',
|
|
149
|
+
recordingRequestStatus: 'CANCELED',
|
|
150
|
+
externalBotId: 'stale-cancel-bot',
|
|
151
|
+
},
|
|
152
|
+
]),
|
|
153
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
154
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
expect(result).toEqual({
|
|
158
|
+
scannedBotCount: 1,
|
|
159
|
+
canceledExternalBotIds: ['stale-cancel-bot'],
|
|
160
|
+
});
|
|
161
|
+
expect(cancelRecallBotMock).toHaveBeenCalledWith({
|
|
162
|
+
externalBotId: 'stale-cancel-bot',
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('cancels bots whose call recording references another bot', async () => {
|
|
167
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
168
|
+
ok: true,
|
|
169
|
+
bots: [
|
|
170
|
+
buildCurrentWorkspaceBot({
|
|
171
|
+
id: 'superseded-bot',
|
|
172
|
+
twentyCallRecordingId: 'call-recording-1',
|
|
173
|
+
}),
|
|
174
|
+
buildCurrentWorkspaceBot({
|
|
175
|
+
id: 'claimed-bot',
|
|
176
|
+
twentyCallRecordingId: 'call-recording-1',
|
|
177
|
+
}),
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const result = await reapOrphanedCallRecorders({
|
|
182
|
+
client: buildClient([
|
|
183
|
+
{
|
|
184
|
+
id: 'call-recording-1',
|
|
185
|
+
recordingRequestStatus: 'REQUESTED',
|
|
186
|
+
externalBotId: 'claimed-bot',
|
|
187
|
+
},
|
|
188
|
+
]),
|
|
189
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
190
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(result).toEqual({
|
|
194
|
+
scannedBotCount: 2,
|
|
195
|
+
canceledExternalBotIds: ['superseded-bot'],
|
|
196
|
+
});
|
|
197
|
+
expect(cancelRecallBotMock).toHaveBeenCalledTimes(1);
|
|
198
|
+
expect(cancelRecallBotMock).toHaveBeenCalledWith({
|
|
199
|
+
externalBotId: 'superseded-bot',
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('cancels bots whose call recording no longer exists', async () => {
|
|
204
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
205
|
+
ok: true,
|
|
206
|
+
bots: [
|
|
207
|
+
buildCurrentWorkspaceBot({
|
|
208
|
+
id: 'orphan-bot',
|
|
209
|
+
twentyCallRecordingId: 'call-recording-gone',
|
|
210
|
+
}),
|
|
211
|
+
],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const result = await reapOrphanedCallRecorders({
|
|
215
|
+
client: buildClient([]),
|
|
216
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
217
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(result).toEqual({
|
|
221
|
+
scannedBotCount: 1,
|
|
222
|
+
canceledExternalBotIds: ['orphan-bot'],
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('grants a grace round to requested recordings without a bot id yet', async () => {
|
|
227
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
228
|
+
ok: true,
|
|
229
|
+
bots: [
|
|
230
|
+
buildCurrentWorkspaceBot({
|
|
231
|
+
id: 'pending-bot',
|
|
232
|
+
twentyCallRecordingId: 'call-recording-1',
|
|
233
|
+
}),
|
|
234
|
+
],
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const result = await reapOrphanedCallRecorders({
|
|
238
|
+
client: buildClient([
|
|
239
|
+
{
|
|
240
|
+
id: 'call-recording-1',
|
|
241
|
+
recordingRequestStatus: 'REQUESTED',
|
|
242
|
+
externalBotId: null,
|
|
243
|
+
},
|
|
244
|
+
]),
|
|
245
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
246
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
expect(result).toEqual({
|
|
250
|
+
scannedBotCount: 1,
|
|
251
|
+
canceledExternalBotIds: [],
|
|
252
|
+
});
|
|
253
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('ignores bots that were not created by this app', async () => {
|
|
257
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
258
|
+
ok: true,
|
|
259
|
+
bots: [buildBot({ id: 'unrelated-bot' })],
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const result = await reapOrphanedCallRecorders({
|
|
263
|
+
client: buildClient([]),
|
|
264
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
265
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(result).toEqual({
|
|
269
|
+
scannedBotCount: 1,
|
|
270
|
+
canceledExternalBotIds: [],
|
|
271
|
+
});
|
|
272
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('ignores untagged bots even when they carry call recording metadata', async () => {
|
|
276
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
277
|
+
ok: true,
|
|
278
|
+
bots: [
|
|
279
|
+
buildBot({
|
|
280
|
+
id: 'untagged-bot',
|
|
281
|
+
twentyCallRecordingId: 'call-recording-gone',
|
|
282
|
+
}),
|
|
283
|
+
],
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const result = await reapOrphanedCallRecorders({
|
|
287
|
+
client: buildClient([]),
|
|
288
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
289
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
expect(result).toEqual({
|
|
293
|
+
scannedBotCount: 1,
|
|
294
|
+
canceledExternalBotIds: [],
|
|
295
|
+
});
|
|
296
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('ignores bots claimed by another workspace', async () => {
|
|
300
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
301
|
+
ok: true,
|
|
302
|
+
bots: [
|
|
303
|
+
buildBot({
|
|
304
|
+
id: 'other-workspace-bot',
|
|
305
|
+
twentyCallRecordingId: 'call-recording-gone',
|
|
306
|
+
twentyWorkspaceId: OTHER_WORKSPACE_ID,
|
|
307
|
+
}),
|
|
308
|
+
],
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const result = await reapOrphanedCallRecorders({
|
|
312
|
+
client: buildClient([]),
|
|
313
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
314
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(result).toEqual({
|
|
318
|
+
scannedBotCount: 1,
|
|
319
|
+
canceledExternalBotIds: [],
|
|
320
|
+
});
|
|
321
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('cancels orphaned bots claimed by this workspace', async () => {
|
|
325
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
326
|
+
ok: true,
|
|
327
|
+
bots: [
|
|
328
|
+
buildCurrentWorkspaceBot({
|
|
329
|
+
id: 'same-workspace-bot',
|
|
330
|
+
twentyCallRecordingId: 'call-recording-gone',
|
|
331
|
+
}),
|
|
332
|
+
],
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
const result = await reapOrphanedCallRecorders({
|
|
336
|
+
client: buildClient([]),
|
|
337
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
338
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
expect(result).toEqual({
|
|
342
|
+
scannedBotCount: 1,
|
|
343
|
+
canceledExternalBotIds: ['same-workspace-bot'],
|
|
344
|
+
});
|
|
345
|
+
expect(cancelRecallBotMock).toHaveBeenCalledWith({
|
|
346
|
+
externalBotId: 'same-workspace-bot',
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('ejects an orphaned bot that already joined when deletion is rejected', async () => {
|
|
351
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
352
|
+
ok: true,
|
|
353
|
+
bots: [
|
|
354
|
+
buildCurrentWorkspaceBot({
|
|
355
|
+
id: 'in-call-orphan',
|
|
356
|
+
twentyCallRecordingId: 'call-recording-gone',
|
|
357
|
+
}),
|
|
358
|
+
],
|
|
359
|
+
});
|
|
360
|
+
cancelRecallBotMock.mockResolvedValue({
|
|
361
|
+
ok: false,
|
|
362
|
+
status: 409,
|
|
363
|
+
errorMessage: 'Recall API responded with HTTP 409',
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const result = await reapOrphanedCallRecorders({
|
|
367
|
+
client: buildClient([]),
|
|
368
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
369
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
expect(result).toEqual({
|
|
373
|
+
scannedBotCount: 1,
|
|
374
|
+
canceledExternalBotIds: ['in-call-orphan'],
|
|
375
|
+
});
|
|
376
|
+
expect(ejectRecallBotMock).toHaveBeenCalledWith({
|
|
377
|
+
externalBotId: 'in-call-orphan',
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('reports nothing reaped when listing Recall bots fails', async () => {
|
|
382
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
383
|
+
ok: false,
|
|
384
|
+
status: 500,
|
|
385
|
+
errorMessage: 'Recall API responded with HTTP 500',
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const result = await reapOrphanedCallRecorders({
|
|
389
|
+
client: buildClient([]),
|
|
390
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
391
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
expect(result).toEqual({
|
|
395
|
+
scannedBotCount: 0,
|
|
396
|
+
canceledExternalBotIds: [],
|
|
397
|
+
});
|
|
398
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('skips reaping when the current workspace cannot be resolved', async () => {
|
|
402
|
+
getCurrentWorkspaceIdMock.mockReturnValue(undefined);
|
|
403
|
+
listScheduledRecallBotsMock.mockResolvedValue({
|
|
404
|
+
ok: true,
|
|
405
|
+
bots: [
|
|
406
|
+
buildCurrentWorkspaceBot({
|
|
407
|
+
id: 'same-workspace-bot',
|
|
408
|
+
twentyCallRecordingId: 'call-recording-gone',
|
|
409
|
+
}),
|
|
410
|
+
],
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const result = await reapOrphanedCallRecorders({
|
|
414
|
+
client: buildClient([]),
|
|
415
|
+
joinAtAfter: JOIN_AT_AFTER,
|
|
416
|
+
joinAtBefore: JOIN_AT_BEFORE,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
expect(result).toEqual({
|
|
420
|
+
scannedBotCount: 1,
|
|
421
|
+
canceledExternalBotIds: [],
|
|
422
|
+
});
|
|
423
|
+
expect(cancelRecallBotMock).not.toHaveBeenCalled();
|
|
424
|
+
});
|
|
425
|
+
});
|