-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[connectors] Add a CLI for Zendesk with a
check-is-admin
(#8881)
* feat: add a CLI for Zendesk with a command check-is-admin * feat: add Zendesk CLI to admin/cli
- Loading branch information
1 parent
595b27a
commit 693bbba
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { ZendeskCommandType } from "@dust-tt/types"; | ||
import type { ZendeskCheckIsAdminResponseType } from "@dust-tt/types/src"; | ||
|
||
import { getZendeskSubdomainAndAccessToken } from "@connectors/connectors/zendesk/lib/zendesk_access_token"; | ||
import { fetchZendeskCurrentUser } from "@connectors/connectors/zendesk/lib/zendesk_api"; | ||
import { default as topLogger } from "@connectors/logger/logger"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
|
||
export const zendesk = async ({ | ||
command, | ||
args, | ||
}: ZendeskCommandType): Promise<ZendeskCheckIsAdminResponseType> => { | ||
const logger = topLogger.child({ majorCommand: "zendesk", command, args }); | ||
|
||
const connectorId = args.connectorId ? args.connectorId.toString() : null; | ||
const connector = connectorId | ||
? await ConnectorResource.fetchById(connectorId) | ||
: null; | ||
if (connector && connector.type !== "zendesk") { | ||
throw new Error(`Connector ${args.connectorId} is not of type zendesk`); | ||
} | ||
|
||
switch (command) { | ||
case "check-is-admin": { | ||
if (!connector) { | ||
throw new Error(`Connector ${connectorId} not found`); | ||
} | ||
const user = await fetchZendeskCurrentUser( | ||
await getZendeskSubdomainAndAccessToken(connector.connectionId) | ||
); | ||
logger.info({ user }, "User returned by /users/me"); | ||
return { | ||
userActive: user.active, | ||
userRole: user.role, | ||
userIsAdmin: user.role === "admin" && user.active, | ||
}; | ||
} | ||
} | ||
}; |
This file contains 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
This file contains 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
This file contains 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