-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Zendesk api wrapper functions (#8157)
* feat: add a function getZendeskAccessToken * feat: add an API wrapper to handle data fetching * fix: remove the await .json since it's already handled in callZendeskApi * feat: widen the OAuth scope to read to allow getting brands * feat: replace our wrapper with the lib node-zendesk
- Loading branch information
1 parent
9b98f26
commit 83daae4
Showing
7 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
101 changes: 101 additions & 0 deletions
101
connectors/src/connectors/zendesk/lib/node-zendesk-types.d.ts
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,101 @@ | ||
import "node-zendesk"; | ||
|
||
interface Brand { | ||
url: string; | ||
id: number; | ||
name: string; | ||
brand_url: string; | ||
subdomain: string; | ||
host_mapping: string | null; | ||
has_help_center: boolean; | ||
help_center_state: string; | ||
active: boolean; | ||
default: boolean; | ||
is_deleted: boolean; | ||
logo: object | null; | ||
ticket_form_ids: number[]; | ||
signature_template: string; | ||
created_at: string; | ||
updated_at: string; | ||
} | ||
|
||
interface Response { | ||
status: number; | ||
headers: object; | ||
statusText: string; | ||
} | ||
|
||
interface Category { | ||
id: number; | ||
url: string; | ||
html_url: string; | ||
position: number; | ||
created_at: string; | ||
updated_at: string; | ||
name: string; | ||
description: string; | ||
locale: string; | ||
source_locale: string; | ||
outdated: boolean; | ||
} | ||
|
||
interface Article { | ||
id: number; | ||
url: string; | ||
html_url: string; | ||
author_id: number; | ||
comments_disabled: boolean; | ||
draft: boolean; | ||
promoted: boolean; | ||
position: number; | ||
vote_sum: number; | ||
vote_count: number; | ||
section_id: number; | ||
created_at: string; | ||
updated_at: string; | ||
name: string; | ||
title: string; | ||
source_locale: string; | ||
locale: string; | ||
outdated: boolean; | ||
outdated_locales: string[]; | ||
edited_at: string; | ||
user_segment_id: number; | ||
permission_group_id: number; | ||
content_tag_ids: number[]; | ||
label_names: string[]; | ||
body: string; | ||
user_segment_ids: number[]; | ||
} | ||
|
||
declare module "node-zendesk" { | ||
interface Client { | ||
brand: { | ||
list: () => Promise<{ | ||
response: Response; | ||
result: Brand[]; | ||
}>; | ||
show: ( | ||
brandId: number | ||
) => Promise<{ response: Response; result: { brand: Brand } }>; | ||
}; | ||
helpcenter: { | ||
categories: { | ||
list: () => Promise<Category[]>; | ||
show: ( | ||
categoryId: number | ||
) => Promise<{ response: Response; result: Category }>; | ||
}; | ||
articles: { | ||
list: () => Promise<Article[]>; | ||
show: ( | ||
articleId: number | ||
) => Promise<{ response: Response; result: Article }>; | ||
listByCategory: (categoryId: number) => Promise<Article[]>; | ||
listSinceStartTime: (startTime: number) => Promise<Article[]>; | ||
}; | ||
}; | ||
} | ||
|
||
export function createClient(options: object): Client; | ||
} |
13 changes: 13 additions & 0 deletions
13
connectors/src/connectors/zendesk/lib/zendesk_access_token.ts
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,13 @@ | ||
import { getOAuthConnectionAccessTokenWithThrow } from "@connectors/lib/oauth"; | ||
import logger from "@connectors/logger/logger"; | ||
|
||
export async function getZendeskAccessToken( | ||
connectionId: string | ||
): Promise<string> { | ||
const token = await getOAuthConnectionAccessTokenWithThrow({ | ||
logger, | ||
provider: "zendesk", | ||
connectionId, | ||
}); | ||
return token.access_token; | ||
} |
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,11 @@ | ||
import { createClient } from "node-zendesk"; | ||
|
||
export function createZendeskClient({ | ||
token, | ||
subdomain = "d3v-dust", | ||
}: { | ||
token: string; | ||
subdomain?: string; | ||
}) { | ||
return createClient({ oauth: true, token, subdomain }); | ||
} |
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