[TW-4729] refactor(dashboard,email): reduce code duplication in auth and pagination#41
Merged
qasim-nylas merged 1 commit intomainfrom Mar 27, 2026
Conversation
…and pagination Extract shared helpers to eliminate duplicated logic across dashboard auth and email list/search commands. Dashboard auth: - Extract loadDashboardTokens() into session_store.go (was duplicated in AuthService and AppService) - Fix multi-org bug: only auto-store org when exactly one exists - SyncSessionOrg now surfaces errors; CLI wraps with warning - New persistActiveOrg() and syncSessionOrgWithWarning() shared helpers - Exported SyncSessionOrg() changed to best-effort (no error return) Email pagination: - Extract shared fetchMessages() with messagesClient interface - Remove ~60 lines of duplicated pagination boilerplate from list.go Release workflow: - Add snapshot validation build before tagging on workflow_dispatch - Restrict real release/DMG steps to tag push events only
AaronDDM
approved these changes
Mar 27, 2026
AaronDDM
reviewed
Mar 27, 2026
AaronDDM
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loadDashboardTokens()helper, fix multi-org auto-selection bug (only auto-store when exactly 1 org), surfaceSyncSessionOrgerrors as warnings, addpersistActiveOrg()andsyncSessionOrgWithWarning()shared helpers for login/SSO flowsfetchMessages()withmessagesClientinterface, removing ~60 lines of duplicated pagination boilerplate fromlist.go(was repeated 3x across list table output, list structured output, and search)workflow_dispatch; restrict real GoReleaser release, DMG creation, and upload to tag push events onlyDetails
Dashboard auth improvements
session_store.go— newloadDashboardTokens()AuthService.loadTokens()andAppService.loadTokens()storeTokens:len(orgs) > 0→== 1SyncSessionOrgreturns errorsreturn nil); callers now get warnings viasyncSessionOrgWithWarning()persistActiveOrg()helperlogin.goandsso.goexports.go:SyncSessionOrg()returns voidsyncSessionOrgWithWarning()internally for consistencyEmail pagination consolidation
list.go(×2) andsearch.gofetchMessages()function shared by all three call sitessearchMessagesClientinterface (search-only)messagesClientinterface (package-shared)fetchMessages(maxItems):<0= single page,0= unlimited,>0= cappedRelease workflow hardening
workflow_dispatchnow runs a--snapshotvalidation build before creating the git taggoreleaser release, DMG creation, and DMG upload restricted togithub.event_name == 'push'(tag push)Files changed (13)
.github/workflows/release.ymlinternal/app/dashboard/session_store.goloadDashboardTokens()internal/app/dashboard/auth_service.go== 1org logic; return errors fromSyncSessionOrginternal/app/dashboard/app_service.goloadDashboardTokens()internal/app/dashboard/auth_service_test.goSyncSessionOrg; addfailingSecretStore; addstoreTokenstestsinternal/cli/dashboard/helpers.gopersistActiveOrg(),syncSessionOrgWithWarning(); fixprintAuthSuccessorg logicinternal/cli/dashboard/login.gointernal/cli/dashboard/sso.gointernal/cli/dashboard/exports.goSyncSessionOrg()returns void, delegates tosyncSessionOrgWithWarning()internal/cli/dashboard/dashboard_test.gointernal/cli/email/search.gofetchMessages()withmessagesClientinterfaceinternal/cli/email/list.gofetchMessages()callsinternal/cli/email/search_test.goTest plan
make ci-fullpasses (unit + integration + lint + vet + security + vuln)nylas email list --limit 5— single-page fetch worksnylas email list --limit 250— pagination works (fetched 250 across multiple pages)nylas email search "*" --limit 3— search worksnylas email list --limit 5 --json— structured output worksnylas dashboard status— dashboard auth worksJIRA: TW-4729