Repository navigation
Conversation
|
🚀 Preview Environment Ready! Your preview environment is available at: https://regions-comics-kilometers-cabinet.trycloudflare.com This environment will automatically shut down after 5 hours. |
🤖 PR Review
🛡️ Security Review✅ No high-severity vulnerabilities detected. 🚦 Auto-approve🙋 Manual review recommended for the following reason(s):
Automated pre-review — human approval still required. |
🟡 Quality review · 4 findings
High-level — Personal Granola webhook sync stays inside the app and reuses its existing seams: connection hooks, kv, the shared resolver, signature parsing and the upsert path. The author has answered both earlier high-level findings (the duplicated eligibility check and the rollout gap), and the latest commit adds nothing new at the architecture or rollout level. 💬 4 inline comments on the diff. Reviewed against the |
|
|
||
| return undefined; | ||
| }); | ||
|
|
There was a problem hiding this comment.
🟡 Nit · High-level · one source of truth
The check for whether a personal Granola connection is usable now exists in three places that already disagree
granola-personal-reconcile.ts:51-58 and load-granola-personal-sync.util.ts:28-33 both check workspaceMemberId, but the existing load-granola-personal-folder-settings.util.ts:22-27 does not, so the settings screen and the sync path can disagree about the same connection. Move this check into one shared util next to listGranolaPersonalConnections and use it from all three files; the reconcile handler can then rely on loadGranolaPersonalSync and drop its own copy.
There was a problem hiding this comment.
Centralized connection eligibility in one lookup. Folder settings, webhook setup, and note imports now require the same active membership and usable personal key.
| return { success: true, skipped: true }; | ||
| } | ||
|
|
||
| const connection = isDefined(userWorkspaceId) |
There was a problem hiding this comment.
🟡 Nit · Low-level · Return early
The ternary on lines 40-50 has a multi-line promise-catch branch with a nested if, making it a big ternary that should be an early-return or separate helper.
Also on lines 41–50.
There was a problem hiding this comment.
Replaced the nested ternary with an explicit branch in the shared connection lookup.
| throw new Error('A personal Granola webhook requires selected folders.'); | ||
| } | ||
|
|
||
| const scopesForKey: (GranolaWebhookScope[] | undefined)[] = |
There was a problem hiding this comment.
🟡 Nit · Low-level · Return early
The multi-line ternary selecting between two scope-array lists is a big ternary that should be an early return or a simpler construct.
Also on lines 36–42.
There was a problem hiding this comment.
Named the two scope candidate lists so the selection is a single expression.
| GRANOLA_PERSONAL_KEY_SCOPES, | ||
| ] | ||
| if (isPersonalConnection && !isNonEmptyArray(folderIds)) { | ||
| throw new Error('A personal Granola webhook requires selected folders.'); |
There was a problem hiding this comment.
🟡 Nit · Low-level · Throw CustomException, never a generic Error``
The new validation throws a generic Error instead of a CustomException.
There was a problem hiding this comment.
The missing folder filter now raises a GranolaWebhookConfigurationError.
| receivedAt, | ||
| signingSecret, | ||
| }: { | ||
| routePayload: RoutePayload<unknown>; |
There was a problem hiding this comment.
🟡 Nit · Low-level · Narrow object parameters to the fields read
The routePayload parameter is typed as the whole RoutePayload<unknown> interface, but the function only reads rawBody and headers; it should be narrowed with Pick<>.
There was a problem hiding this comment.
Narrowed the signature verifier input to rawBody and headers.
| apiKeyFingerprint, | ||
| folderIds, | ||
| }: { | ||
| scope: GranolaPersonalSyncScope; |
There was a problem hiding this comment.
🟡 Nit · Low-level · Narrow object parameters to the fields read
The scope parameter is typed as the whole GranolaPersonalSyncScope even though the function only reads scope.connectionId, so it should be narrowed with Pick<>.
There was a problem hiding this comment.
Both IDs are required. The helper stores userWorkspaceId with the registration and uses it to recheck the connection. I destructured both fields to make that explicit.
| const apiUrl = process.env.TWENTY_API_URL; | ||
|
|
||
| if (!isNonEmptyString(apiUrl)) { | ||
| throw new Error( |
There was a problem hiding this comment.
🟡 Nit · Low-level · Throw CustomException, never a generic Error``
The added code throws a generic Error when TWENTY_API_URL is missing instead of a CustomException.
There was a problem hiding this comment.
Missing TWENTY_API_URL now raises a GranolaWebhookConfigurationError without retrying the job.
| throw error; | ||
| } | ||
|
|
||
| await deleteStaleGranolaWebhookEndpointOrThrow({ |
There was a problem hiding this comment.
🟡 Nit · Low-level · No silent failures or permissive fallbacks
When the personal sync is missing, the code silently deletes the just-created webhook and returns successfully instead of surfacing the inconsistent state with an error.
Also on lines 119–121.
There was a problem hiding this comment.
A disconnect or opt-out during setup can legitimately clear the selection. The new endpoint is rolled back and the handler now returns skipped: true.
|
|
||
| try { | ||
| if (!isDefined(client)) { | ||
| throw new Error('The Granola API key is unavailable.'); |
There was a problem hiding this comment.
🟡 Nit · Low-level · Throw CustomException, never a generic Error``
The added line throws a generic new Error(...) instead of the module's CustomException.
There was a problem hiding this comment.
Missing credentials now log the provider cleanup step and return after revoking the local registration.
| }, | ||
| }); | ||
|
|
||
| return (result.updateCallRecordings ?? []).length > 0 |
There was a problem hiding this comment.
🟡 Nit · Low-level · Use isDefined over manual checks
The emptiness check (result.updateCallRecordings ?? []).length > 0 is a manual nullish-and-length check where isNonEmptyArray would express it directly.
There was a problem hiding this comment.
Replaced the nullish fallback and length check with isNonEmptyArray.
| })), | ||
| ); | ||
|
|
||
| await enqueueGranolaPersonalReconcileOrThrow({ |
There was a problem hiding this comment.
🟡 Nit · High-level · deploy strategy
Personal folder selections saved before this deploy never get a webhook, because reconcile only runs on connect or when a selection is saved
Members who already picked folders will see them as selected in settings, but none of their notes get imported until they save again or reconnect, and nothing tells them to do either. Run a one-time reconcile for every existing personal connection, for example from the daily catch-up or on app upgrade, or point the rollout note at this gap.
There was a problem hiding this comment.
Clarified the rollout in the PR body. The Folders tab ships with scheduled reconciliation of every saved personal selection, including any choices already saved through the API.
There was a problem hiding this comment.
This implementation is being split. The first replacement is #30814 and only extracts webhook verification. Saved selections will be reconciled in the release PR that enables personal sync.
| await enqueueGranolaPersonalReconcileOrThrow({ | ||
| connectionId: request.data.connectionId, | ||
| userWorkspaceId, | ||
| }).catch((error: unknown) => { |
There was a problem hiding this comment.
🟡 Nit · Low-level · No silent failures or permissive fallbacks
The .catch swallows the reconciliation error, only logs it to console, and the handler still returns success: true, so a failed sync start is silently ignored.
Also on lines 81–84.
There was a problem hiding this comment.
The route now returns HTTP 503 if it cannot schedule setup. The saved selection remains available for retry.
| connections.map(async (connection) => { | ||
| try { | ||
| await disconnectGranolaPersonalConnection({ | ||
| connection, |
There was a problem hiding this comment.
🟡 Nit · Low-level · Consolidate duplicate concepts
The disconnect call passes both connection and connection.id, so the same identity is supplied twice and the util could take just the connection.
Also on line 54.
There was a problem hiding this comment.
Simplified cleanup to accept just the connection ID and the API key.
| `[granola] Could not list personal connections during uninstall. ${toErrorMessage(error)}`, | ||
| ); | ||
|
|
||
| return []; |
There was a problem hiding this comment.
🟡 Nit · Low-level · No silent failures or permissive fallbacks
The .catch on listGranolaPersonalConnections logs the error and returns an empty list, so uninstall proceeds as if there were no connections and leaves them uncleaned without failing.
There was a problem hiding this comment.
Keeping uninstall cleanup best effort. A failed connection lookup is logged, and uninstall still proceeds. Granola delivery cannot import once the app is removed.
| @@ -0,0 +1,6 @@ | |||
| export class GranolaWebhookConfigurationError extends Error { | |||
| constructor(message: string) { | |||
There was a problem hiding this comment.
🟡 Nit · Low-level · Exceptions take a single object parameter
The exception constructor takes a bare message: string instead of a single object parameter.
There was a problem hiding this comment.
Changed the error constructor to accept a single options object.
| }) => { | ||
| const scopeCandidates = [ | ||
| if (isPersonalConnection && !isNonEmptyArray(folderIds)) { | ||
| throw new GranolaWebhookConfigurationError( |
There was a problem hiding this comment.
🟡 Nit · Low-level · Exceptions take a single object parameter
The new GranolaWebhookConfigurationError is constructed with a bare positional string instead of a single object parameter.
There was a problem hiding this comment.
The error now takes a message options object at this call site.
| const scopeCandidates = [ | ||
| if (isPersonalConnection && !isNonEmptyArray(folderIds)) { | ||
| throw new GranolaWebhookConfigurationError( | ||
| 'A personal Granola webhook requires selected folders.', |
There was a problem hiding this comment.
🟡 Nit · Low-level · Translate user-facing strings
The thrown configuration error message is a user-facing string not wrapped in t`` or msg, so it won't be translated.
There was a problem hiding this comment.
This is an operator diagnostic from background webhook setup. The member-facing settings error is handled separately in the UI.
| const connection = await getRequestedConnectionOrThrow().catch( | ||
| (error: unknown) => { | ||
| if (error instanceof AppConnectionAuthFailedError) { | ||
| return undefined; |
There was a problem hiding this comment.
🟡 Nit · Low-level · No silent failures or permissive fallbacks
The function is named ...OrThrow yet swallows AppConnectionAuthFailedError and returns undefined for missing, mismatched, or auth-failed connections, so callers get no error signal.
Also on line 45.
There was a problem hiding this comment.
Renamed the helper to findGranolaPersonalConnection. An unavailable credential is a normal stop condition after disconnect or auth failure. Unexpected lookup errors still propagate.
| export const getGranolaPersonalWebhookKey = (connectionId: string): string => | ||
| `granola:personal-webhook:${connectionId}`; | ||
|
|
||
| export const GRANOLA_PERSONAL_REGISTRATION_PREFIX = 'personal-'; |
There was a problem hiding this comment.
🟡 Nit · Low-level · One util per file
The file bundles an unrelated registration-prefix constant (GRANOLA_PERSONAL_REGISTRATION_PREFIX) alongside the webhook key util, so it is not one util per file.
There was a problem hiding this comment.
Moved the prefix to the personal connection constants file.
| userWorkspaceId, | ||
| }); | ||
|
|
||
| if (!isDefined(connection)) { |
There was a problem hiding this comment.
🟡 Nit · Low-level · Don't guard what the types rule out
The connection comes from findGranolaPersonalConnectionOrThrow, which by its name never returns nullish, so the isDefined(connection) early return guards a case the types already rule out.
Also on lines 29–30.
There was a problem hiding this comment.
The lookup can return undefined for a removed or unusable credential. I renamed it to make that contract explicit and kept the guard.
| apiKeyFingerprint, | ||
| }); | ||
|
|
||
| if (isDefined(current)) { |
There was a problem hiding this comment.
🟡 Nit · Low-level · Return early
The added if (isDefined(current)) is nested inside the 401 if block rather than being flattened with an early return or guard.
There was a problem hiding this comment.
Flattened the 401 path with an early return when the connection has already changed.
| }); | ||
| } catch (error) { | ||
| if (error instanceof GranolaApiError && error.status === 401) { | ||
| const current = await loadGranolaPersonalSync({ |
There was a problem hiding this comment.
🟡 Nit · Low-level · Reuse or extract instead of reimplementing
The 4-line loadGranolaPersonalSync({ ...scope, apiKeyFingerprint }) re-load block is duplicated verbatim from lines 50-53 instead of being extracted into a shared helper.
Also on lines 68–70.
There was a problem hiding this comment.
Both paths already use the shared sync lookup. The write path rechecks consent before saving, and the 401 path separately checks the same key is still current before marking it for reconnect.
Superseded by smaller PRs starting with #30814. The remaining recording ownership, folder eligibility, and webhook lifecycle changes will follow from main, one PR at a time.
Context
This follows #30803 and #30806. Members who connect Granola need to opt individual folders into sharing future meeting notes as Twenty Call Recordings. The existing workspace connection can keep syncing meetings in parallel.
Changes
Build and rollout
This PR is the live delivery path. Scheduled catch-up and the Folders tab will land together in the release PR after this merges. The current app version has no member-facing folder picker. The first scheduled run will reconcile every saved personal selection, including choices made during development or through the settings API before the release, so those members do not have to save again. There is no app version bump here. The new field is additive and needs no data backfill. The current workspace webhook URL, registration keys, and scope-selection behavior are preserved.
Verification