Skip to content

improvement(confluence): expand scopes, persist canonical mode toggle#4461

Merged
waleedlatif1 merged 5 commits intostagingfrom
waleedlatif1/confluence-kb-mode-persist
May 6, 2026
Merged

improvement(confluence): expand scopes, persist canonical mode toggle#4461
waleedlatif1 merged 5 commits intostagingfrom
waleedlatif1/confluence-kb-mode-persist

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Expand Confluence connector requiredScopes to cover granular v2 + CQL search endpoints (read:page:confluence, read:blogpost:confluence, read:space:confluence, read:label:confluence, search:confluence)
  • Persist canonical-pair mode (basic/advanced toggle) in source_config._canonicalModes so selector vs manual-input choice survives reloads in the edit modal
  • Reuse shared normalizeConfluenceDomainHost helper across connector and tool utils (no duplication)
  • Label fetch now falls back from pagesblogposts so blogpost labels surface; lower concurrency to 5

Type of Change

  • Improvement

Testing

Tested manually — verified scope subset against OAUTH_PROVIDERS.confluence, confirmed all prod credentials already have these scopes (no re-auth banner), verified mode persistence survives modal close/reopen.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 6, 2026 2:59am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 6, 2026

PR Summary

Medium Risk
Moderate risk due to changes in selector pagination behavior (new cursor protocol, infinite-query auto-draining) and Confluence OAuth scope expansion, which can affect data fetching and auth expectations.

Overview
Improves Confluence integration by expanding the connector’s OAuth requiredScopes to cover additional v2/CQL endpoints and normalizing Confluence domains via a shared normalizeConfluenceDomainHost helper.

Adds cursor-based pagination to the Confluence space selector API (including a transparent handoff from current to archived spaces) and updates the selector framework to optionally stream paged results via fetchPage/useInfiniteQuery, preventing “missing option” states while more pages are still loading.

Persists canonical selector-vs-manual mode toggles in connector sourceConfig._canonicalModes so the basic/advanced choice survives modal reopen and is included/removed appropriately on create/update.

Reviewed by Cursor Bugbot for commit a677ae8. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 6, 2026

Greptile Summary

This PR expands the Confluence connector's OAuth scopes to cover granular v2 and CQL endpoints, adds cursor-based pagination for the spaces selector (including archived spaces), persists the canonical-pair mode toggle in source_config._canonicalModes, and consolidates domain normalization into a shared normalizeConfluenceDomainHost helper.

  • Pagination: selector-spaces/route.ts now returns a nextCursor using a status:inner compound format that transparently flips from currentarchived spaces; use-selector-query.ts gains a useInfiniteQuery-backed path with a useEffect auto-drain so the combobox populates progressively.
  • Canonical mode persistence: _canonicalModes is written into sourceConfig on save (both add and edit modals) and restored on modal open via useConnectorConfigFields; the didCanonicalModesChange helper correctly defaults absent keys to 'basic' on both sides.
  • Domain normalization: normalizeConfluenceDomainHost (previously normalizeDomain, private) is now exported and reused in the connector, which also fixes a latent bug where a https://-prefixed domain would produce a double-protocol sourceUrl.

Confidence Score: 5/5

Safe to merge — all changes are additive, well-guarded, and confined to the Confluence connector and its selector infrastructure.

The pagination logic is correct: the compound cursor correctly transitions from current → archived spaces and terminates cleanly, the auto-drain effect is properly guarded against re-entrancy, and the !hasMore guard in the combobox prevents false missing-option states during draining. The canonical mode persistence is correctly scoped to _canonicalModes, excluded from user-editable keys, and the didCanonicalModesChange comparison correctly defaults absent keys to basic on both sides. The domain normalization refactoring fixes a latent double-protocol URL bug and is safe because getConfluenceCloudId already lowercases internally.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/hooks/selectors/use-selector-query.ts Adds useInfiniteQuery path for paginated selectors with a useEffect auto-drain; correctly gates isLoading/hasMore/isFetchingMore; returns stable SelectorOptionsResult for both paginated and flat paths.
apps/sim/hooks/selectors/providers/confluence/selectors.ts Adds fetchPage for cursor-based space listing; fetchList now loops all pages but is dead code in the paginated path; fetchById only hits the first page of current spaces (intentional, documented).
apps/sim/app/api/tools/confluence/selector-spaces/route.ts Adds compound cursor (status:inner) logic to paginate both current and archived spaces; parseCursor is safe; correctly emits archived: sentinel after exhausting current pages.
apps/sim/connectors/confluence/confluence.ts Expands requiredScopes; applies normalizeConfluenceDomainHost to listDocuments/getDocument (fixes double-protocol sourceUrl bug); fetchLabelsForPages now falls back pages→blogposts with reduced concurrency.
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/edit-connector-modal/edit-connector-modal.tsx Adds readPersistedCanonicalModes/didCanonicalModesChange helpers; correctly uses useMemo for persistedCanonicalModes; handleSave properly merges or removes _canonicalModes from sourceConfig.
apps/sim/lib/api/contracts/selectors/confluence.ts Extends confluenceSpacesSelectorBodySchema with optional cursor; adds optional status to space schema and nextCursor to response schema; correctly uses optionalString.

Sequence Diagram

sequenceDiagram
    participant C as SelectorCombobox
    participant Q as useSelectorOptions
    participant IQ as useInfiniteQuery
    participant API as /api/tools/confluence/selector-spaces

    C->>Q: useSelectorOptions('confluence.spaces')
    Q->>IQ: enabled (supportsPagination=true)
    IQ->>API: POST {cursor: undefined}
    API-->>IQ: {spaces: [...], nextCursor: "current:abc"}
    IQ-->>Q: page 1 items
    Q-->>C: data=page1, hasMore=true

    Note over Q: useEffect: hasNextPage && !isFetchingNextPage
    Q->>IQ: fetchNextPage()
    IQ->>API: POST {cursor: "current:abc"}
    API-->>IQ: {spaces: [...], nextCursor: "archived:"}
    IQ-->>Q: page 2 items
    Q-->>C: data=page1+page2, hasMore=true

    Q->>IQ: fetchNextPage()
    IQ->>API: POST {cursor: "archived:"}
    API-->>IQ: {spaces: [...archived...], nextCursor: undefined}
    IQ-->>Q: archived items
    Q-->>C: data=all pages, hasMore=false
Loading

Reviews (3): Last reviewed commit: "improvement(confluence): stream paginate..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2b1e223. Configure here.

Confluence v2 spaces endpoint caps at limit=250 per page. The selector
endpoint was making one request and silently dropping every space past
the first page, which is why some spaces only worked when entered as a
manual spaceKey. Now follows _links.next cursor up to 20 pages (5000
spaces).
Confluence v2 /spaces defaults to status=current and the status param
is a single-value enum, so archived spaces never surface. They synced
fine when entered manually as a spaceKey because the connector looks
up spaces via ?keys=<key> which ignores status. Now fetches current
and archived in parallel and tags archived ones in the dropdown label.
Bake pagination support into the selector abstraction via an opt-in
fetchPage definition so dropdowns populate progressively instead of
blocking on a full page-walk. Confluence spaces now stream current
then archived in a single cursor sequence.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a677ae8. Configure here.

@waleedlatif1 waleedlatif1 merged commit 3a79289 into staging May 6, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/confluence-kb-mode-persist branch May 6, 2026 03:11
waleedlatif1 added a commit that referenced this pull request May 7, 2026
…#4461)

* improvement(confluence): expand scopes, persist canonical mode toggle

* improvement(confluence): memoize persisted canonical modes parse

* fix(confluence): paginate space selector dropdown

Confluence v2 spaces endpoint caps at limit=250 per page. The selector
endpoint was making one request and silently dropping every space past
the first page, which is why some spaces only worked when entered as a
manual spaceKey. Now follows _links.next cursor up to 20 pages (5000
spaces).

* fix(confluence): include archived spaces in selector dropdown

Confluence v2 /spaces defaults to status=current and the status param
is a single-value enum, so archived spaces never surface. They synced
fine when entered manually as a spaceKey because the connector looks
up spaces via ?keys=<key> which ignores status. Now fetches current
and archived in parallel and tags archived ones in the dropdown label.

* improvement(confluence): stream paginated space selector results

Bake pagination support into the selector abstraction via an opt-in
fetchPage definition so dropdowns populate progressively instead of
blocking on a full page-walk. Confluence spaces now stream current
then archived in a single cursor sequence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant