|
| 1 | +import linearApp from "../../linear.app.mjs"; |
| 2 | + |
| 3 | +const DEFAULT_CONNECTION_LIMIT = 50; |
| 4 | + |
| 5 | +const toIsoString = (value) => value?.toISOString?.() ?? null; |
| 6 | +const toPageInfo = (pageInfo) => pageInfo && ({ |
| 7 | + endCursor: pageInfo.endCursor, |
| 8 | + hasNextPage: pageInfo.hasNextPage, |
| 9 | + hasPreviousPage: pageInfo.hasPreviousPage, |
| 10 | + startCursor: pageInfo.startCursor, |
| 11 | +}); |
| 12 | + |
| 13 | +export default { |
| 14 | + key: "linear-get-current-user", |
| 15 | + name: "Get Current User", |
| 16 | + description: "Retrieve rich context about the authenticated Linear user, including core profile fields, recent timestamps, direct team memberships, and high-level organization settings. Returns the user object, a paginated team list (with names, keys, cycle configs, etc.), associated team memberships, and organization metadata such as auth defaults and SCIM/SAML flags. Use this when your workflow or agent needs to understand who is currently authenticated, which teams they belong to, or what workspace policies might influence subsequent Linear actions. Uses OAuth authentication. See Linear's GraphQL viewer docs [here](https://developers.linear.app/docs/graphql/working-with-the-graphql-api).", |
| 17 | + version: "0.0.1", |
| 18 | + type: "action", |
| 19 | + annotations: { |
| 20 | + destructiveHint: false, |
| 21 | + openWorldHint: true, |
| 22 | + readOnlyHint: true, |
| 23 | + }, |
| 24 | + props: { |
| 25 | + linearApp, |
| 26 | + }, |
| 27 | + async run({ $ }) { |
| 28 | + const client = this.linearApp.client(); |
| 29 | + const viewer = await client.viewer; |
| 30 | + |
| 31 | + const [ |
| 32 | + organization, |
| 33 | + teamsConnection, |
| 34 | + teamMembershipsConnection, |
| 35 | + ] = await Promise.all([ |
| 36 | + viewer.organization, |
| 37 | + viewer.teams({ |
| 38 | + first: DEFAULT_CONNECTION_LIMIT, |
| 39 | + }), |
| 40 | + viewer.teamMemberships({ |
| 41 | + first: DEFAULT_CONNECTION_LIMIT, |
| 42 | + }), |
| 43 | + ]); |
| 44 | + |
| 45 | + const teams = teamsConnection?.nodes?.map((team) => ({ |
| 46 | + id: team.id, |
| 47 | + key: team.key, |
| 48 | + name: team.name, |
| 49 | + displayName: team.displayName, |
| 50 | + description: team.description, |
| 51 | + icon: team.icon, |
| 52 | + color: team.color, |
| 53 | + private: team.private, |
| 54 | + timezone: team.timezone, |
| 55 | + inviteHash: team.inviteHash, |
| 56 | + issueCount: team.issueCount, |
| 57 | + cycleDuration: team.cycleDuration, |
| 58 | + cyclesEnabled: team.cyclesEnabled, |
| 59 | + triageEnabled: team.triageEnabled, |
| 60 | + createdAt: toIsoString(team.createdAt), |
| 61 | + updatedAt: toIsoString(team.updatedAt), |
| 62 | + })) ?? []; |
| 63 | + |
| 64 | + const user = { |
| 65 | + id: viewer.id, |
| 66 | + name: viewer.name, |
| 67 | + displayName: viewer.displayName, |
| 68 | + email: viewer.email, |
| 69 | + active: viewer.active, |
| 70 | + admin: viewer.admin, |
| 71 | + guest: viewer.guest, |
| 72 | + description: viewer.description, |
| 73 | + disableReason: viewer.disableReason, |
| 74 | + timezone: viewer.timezone, |
| 75 | + statusEmoji: viewer.statusEmoji, |
| 76 | + statusLabel: viewer.statusLabel, |
| 77 | + isAssignable: viewer.isAssignable, |
| 78 | + isMentionable: viewer.isMentionable, |
| 79 | + avatarUrl: viewer.avatarUrl, |
| 80 | + url: viewer.url, |
| 81 | + calendarHash: viewer.calendarHash, |
| 82 | + inviteHash: viewer.inviteHash, |
| 83 | + initials: viewer.initials, |
| 84 | + createdIssueCount: viewer.createdIssueCount, |
| 85 | + createdAt: toIsoString(viewer.createdAt), |
| 86 | + updatedAt: toIsoString(viewer.updatedAt), |
| 87 | + archivedAt: toIsoString(viewer.archivedAt), |
| 88 | + lastSeen: toIsoString(viewer.lastSeen), |
| 89 | + statusUntilAt: toIsoString(viewer.statusUntilAt), |
| 90 | + }; |
| 91 | + |
| 92 | + const teamMemberships = teamMembershipsConnection?.nodes?.map((membership) => ({ |
| 93 | + id: membership.id, |
| 94 | + owner: membership.owner, |
| 95 | + sortOrder: membership.sortOrder, |
| 96 | + teamId: membership.teamId, |
| 97 | + userId: membership.userId, |
| 98 | + createdAt: toIsoString(membership.createdAt), |
| 99 | + updatedAt: toIsoString(membership.updatedAt), |
| 100 | + archivedAt: toIsoString(membership.archivedAt), |
| 101 | + })) ?? []; |
| 102 | + |
| 103 | + const organizationData = organization && { |
| 104 | + id: organization.id, |
| 105 | + name: organization.name, |
| 106 | + urlKey: organization.urlKey, |
| 107 | + allowedAuthServices: organization.allowedAuthServices, |
| 108 | + allowMembersToInvite: organization.allowMembersToInvite, |
| 109 | + customersEnabled: organization.customersEnabled, |
| 110 | + feedEnabled: organization.feedEnabled, |
| 111 | + gitBranchFormat: organization.gitBranchFormat, |
| 112 | + gitLinkbackMessagesEnabled: organization.gitLinkbackMessagesEnabled, |
| 113 | + gitPublicLinkbackMessagesEnabled: organization.gitPublicLinkbackMessagesEnabled, |
| 114 | + initiativeUpdateReminderFrequencyInWeeks: |
| 115 | + organization.initiativeUpdateReminderFrequencyInWeeks, |
| 116 | + initiativeUpdateRemindersDay: organization.initiativeUpdateRemindersDay, |
| 117 | + initiativeUpdateRemindersHour: organization.initiativeUpdateRemindersHour, |
| 118 | + projectUpdateReminderFrequencyInWeeks: |
| 119 | + organization.projectUpdateReminderFrequencyInWeeks, |
| 120 | + projectUpdateRemindersDay: organization.projectUpdateRemindersDay, |
| 121 | + projectUpdateRemindersHour: organization.projectUpdateRemindersHour, |
| 122 | + projectUpdatesReminderFrequency: organization.projectUpdatesReminderFrequency, |
| 123 | + restrictLabelManagementToAdmins: organization.restrictLabelManagementToAdmins, |
| 124 | + restrictTeamCreationToAdmins: organization.restrictTeamCreationToAdmins, |
| 125 | + roadmapEnabled: organization.roadmapEnabled, |
| 126 | + samlEnabled: organization.samlEnabled, |
| 127 | + scimEnabled: organization.scimEnabled, |
| 128 | + releaseChannel: organization.releaseChannel, |
| 129 | + fiscalYearStartMonth: organization.fiscalYearStartMonth, |
| 130 | + slaDayCount: organization.slaDayCount, |
| 131 | + previousUrlKeys: organization.previousUrlKeys, |
| 132 | + logoUrl: organization.logoUrl, |
| 133 | + createdIssueCount: organization.createdIssueCount, |
| 134 | + customerCount: organization.customerCount, |
| 135 | + periodUploadVolume: organization.periodUploadVolume, |
| 136 | + userCount: organization.userCount, |
| 137 | + trialEndsAt: toIsoString(organization.trialEndsAt), |
| 138 | + deletionRequestedAt: toIsoString(organization.deletionRequestedAt), |
| 139 | + archivedAt: toIsoString(organization.archivedAt), |
| 140 | + createdAt: toIsoString(organization.createdAt), |
| 141 | + updatedAt: toIsoString(organization.updatedAt), |
| 142 | + }; |
| 143 | + |
| 144 | + const summaryIdentifier = user.name || user.displayName || user.email || user.id; |
| 145 | + $.export("$summary", `Retrieved Linear user ${summaryIdentifier}`); |
| 146 | + |
| 147 | + return { |
| 148 | + user, |
| 149 | + organization: organizationData, |
| 150 | + teams: { |
| 151 | + nodes: teams, |
| 152 | + pageInfo: toPageInfo(teamsConnection?.pageInfo), |
| 153 | + }, |
| 154 | + teamMemberships: { |
| 155 | + nodes: teamMemberships, |
| 156 | + pageInfo: toPageInfo(teamMembershipsConnection?.pageInfo), |
| 157 | + }, |
| 158 | + }; |
| 159 | + }, |
| 160 | +}; |
0 commit comments