Skip to content

Commit

Permalink
add a CLI command to fetch a brand
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Jan 10, 2025
1 parent 2747b02 commit 2b2b818
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions connectors/src/connectors/zendesk/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import type {
ZendeskCheckIsAdminResponseType,
ZendeskCommandType,
ZendeskCountTicketsResponseType,
ZendeskFetchBrandResponseType,
ZendeskFetchTicketResponseType,
ZendeskResyncTicketsResponseType,
} from "@dust-tt/types";

import { getZendeskSubdomainAndAccessToken } from "@connectors/connectors/zendesk/lib/zendesk_access_token";
import {
fetchZendeskBrand,
fetchZendeskCurrentUser,
fetchZendeskTicket,
fetchZendeskTicketCount,
Expand All @@ -17,6 +19,7 @@ import { launchZendeskTicketReSyncWorkflow } from "@connectors/connectors/zendes
import { default as topLogger } from "@connectors/logger/logger";
import { ConnectorResource } from "@connectors/resources/connector_resource";
import {
ZendeskBrandResource,
ZendeskConfigurationResource,
ZendeskTicketResource,
} from "@connectors/resources/zendesk_resources";
Expand All @@ -29,6 +32,7 @@ export const zendesk = async ({
| ZendeskCountTicketsResponseType
| ZendeskResyncTicketsResponseType
| ZendeskFetchTicketResponseType
| ZendeskFetchBrandResponseType
> => {
const logger = topLogger.child({ majorCommand: "zendesk", command, args });

Expand Down Expand Up @@ -143,5 +147,27 @@ export const zendesk = async ({
isTicketOnDb: ticketOnDb !== null,
};
}
case "fetch-brand": {
if (!connector) {
throw new Error(`Connector ${connectorId} not found`);
}
const brandId = args.brandId ? parseInt(args.brandId, 10) : null;
if (!brandId) {
throw new Error(`Missing --brandId argument`);
}

const brand = await fetchZendeskBrand({
brandId,
...(await getZendeskSubdomainAndAccessToken(connector.connectionId)),
});
const brandOnDb = await ZendeskBrandResource.fetchByBrandId({
connectorId: connector.id,
brandId,
});
return {
brand: brand as { [key: string]: unknown } | null,
brandOnDb,
};
}
}
};
10 changes: 10 additions & 0 deletions types/src/connectors/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export const ZendeskCommandSchema = t.type({
t.literal("count-tickets"),
t.literal("resync-tickets"),
t.literal("fetch-ticket"),
t.literal("fetch-brand"),
]),
args: t.type({
connectorId: t.union([t.number, t.undefined]),
Expand Down Expand Up @@ -303,6 +304,14 @@ export const ZendeskFetchTicketResponseSchema = t.type({
export type ZendeskFetchTicketResponseType = t.TypeOf<
typeof ZendeskFetchTicketResponseSchema
>;

export const ZendeskFetchBrandResponseSchema = t.type({
brand: t.union([t.UnknownRecord, t.null]), // Zendesk type, can't be iots'd,
brandOnDb: t.union([t.UnknownRecord, t.null]),
});
export type ZendeskFetchBrandResponseType = t.TypeOf<
typeof ZendeskFetchBrandResponseSchema
>;
/**
* </Zendesk>
*/
Expand Down Expand Up @@ -465,6 +474,7 @@ export const AdminResponseSchema = t.union([
ZendeskCountTicketsResponseSchema,
ZendeskResyncTicketsResponseSchema,
ZendeskFetchTicketResponseSchema,
ZendeskFetchBrandResponseSchema,
]);

export type AdminResponseType = t.TypeOf<typeof AdminResponseSchema>;

0 comments on commit 2b2b818

Please sign in to comment.