@kosha-ai/integration-zendesk 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/integration-zendesk.d.ts +5 -0
- package/dist/lib/integration-zendesk.d.ts.map +1 -0
- package/dist/lib/integration-zendesk.js +170 -0
- package/docs/images/zendesk-add-oauth-client.png +0 -0
- package/docs/images/zendesk-api-terms.png +0 -0
- package/docs/images/zendesk-client-details.png +0 -0
- package/docs/images/zendesk-client-kind.png +0 -0
- package/docs/images/zendesk-get-started.png +0 -0
- package/docs/images/zendesk-redirect-scopes.png +0 -0
- package/docs/images/zendesk-subdomain.png +0 -0
- package/docs/setup.md +161 -0
- package/migrations/001_init/migration.sql +60 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codemancers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kosha-ai/integration-zendesk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Zendesk provider for [Kosha](https://github.com/codemancers/kosha). Adds OAuth2
|
|
4
|
+
connect, automatic token refresh, an authenticated request proxy, and account
|
|
5
|
+
identity for the Zendesk REST API.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @kosha-ai/integration-zendesk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from '@kosha-ai/server';
|
|
17
|
+
import zendesk from '@kosha-ai/integration-zendesk';
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
// ...database, auth, encryption
|
|
21
|
+
integrations: [zendesk()],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Zendesk is per-tenant, so each organization supplies its own account
|
|
26
|
+
**subdomain** when it creates a configuration in the admin. It is the label
|
|
27
|
+
only: `acme` for `https://acme.zendesk.com`.
|
|
28
|
+
|
|
29
|
+
Every URL is derived from it, and the subdomain is recorded on the connection so
|
|
30
|
+
the proxy routes later calls to `https://{subdomain}.zendesk.com/api/v2`.
|
|
31
|
+
|
|
32
|
+
> **Connecting is not wired up yet.** A strategy is handed only the OAuth client
|
|
33
|
+
> context (`clientId`, `clientSecret`, `redirectUri`, `scopes`), so a package
|
|
34
|
+
> cannot read its own configuration column. Zendesk is the first provider that
|
|
35
|
+
> needs to, and the mechanism is being decided separately. Until it lands, the
|
|
36
|
+
> authorize, token and identity steps fail with a clear error rather than
|
|
37
|
+
> guessing at a host.
|
|
38
|
+
|
|
39
|
+
## Scopes
|
|
40
|
+
|
|
41
|
+
Zendesk scopes are either broad (`read`, `write`, `impersonate`) or
|
|
42
|
+
resource-qualified (`tickets:read`, `users:read`, …).
|
|
43
|
+
|
|
44
|
+
**The package decides what to request, and an operator does not choose.** It
|
|
45
|
+
asks for `users:read` and `tickets:read`. The first is required: connecting
|
|
46
|
+
calls `GET /users/me.json` to identify the account, so without it no connection
|
|
47
|
+
can be made at all. Whoever connects approves that set on Zendesk's consent
|
|
48
|
+
screen, and whatever they actually granted is what Kosha stores against the
|
|
49
|
+
connection.
|
|
50
|
+
|
|
51
|
+
The full catalogue is still declared, for display and validation. Your Zendesk
|
|
52
|
+
OAuth client has to permit the requested scopes, or Zendesk refuses the
|
|
53
|
+
authorization.
|
|
54
|
+
|
|
55
|
+
See [docs/setup.md](./docs/setup.md) for the OAuth client walkthrough, the
|
|
56
|
+
operation → scope reference, and the subdomain rules.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { zendesk, zendesk as default } from './lib/integration-zendesk.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration-zendesk.d.ts","sourceRoot":"","sources":["../../src/lib/integration-zendesk.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAOlE,eAAO,MAAM,OAAO,GAAI,WAAW,MAAM,WACL,CAAC;AAqGrC,wBAAgB,OAAO,IAAI,gBAAgB,CA4E1C;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { defineIntegration, oauth2, packageDirs, } from '@kosha-ai/integration-sdk';
|
|
2
|
+
const { docsPath, migrationsPath } = packageDirs(import.meta.url);
|
|
3
|
+
/** A bare DNS label: `acme`, never `acme.zendesk.com`, a URL, or a path. */
|
|
4
|
+
const SUBDOMAIN_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
5
|
+
export const hostFor = (subdomain) => `https://${subdomain}.zendesk.com`;
|
|
6
|
+
/**
|
|
7
|
+
* Zendesk's full OAuth scope catalogue: the broad tiers plus every
|
|
8
|
+
* resource-qualified scope. Display and validation only. Hand-maintained, so
|
|
9
|
+
* keep in sync with
|
|
10
|
+
* https://developer.zendesk.com/api-reference/ticketing/oauth/grant_type_tokens/#scope
|
|
11
|
+
*/
|
|
12
|
+
const SCOPES_AVAILABLE = [
|
|
13
|
+
'read',
|
|
14
|
+
'write',
|
|
15
|
+
'impersonate',
|
|
16
|
+
'account_settings:read',
|
|
17
|
+
'account_settings:write',
|
|
18
|
+
'ai_agents:chat',
|
|
19
|
+
'any_channel:write',
|
|
20
|
+
'apps:read',
|
|
21
|
+
'apps:write',
|
|
22
|
+
'auditlogs:read',
|
|
23
|
+
'automations:read',
|
|
24
|
+
'automations:write',
|
|
25
|
+
'brands:read',
|
|
26
|
+
'brands:write',
|
|
27
|
+
'custom_objects:read',
|
|
28
|
+
'custom_objects:write',
|
|
29
|
+
'deletion_schedules:read',
|
|
30
|
+
'deletion_schedules:write',
|
|
31
|
+
'dynamic_content:read',
|
|
32
|
+
'dynamic_content:write',
|
|
33
|
+
'groups:read',
|
|
34
|
+
'groups:write',
|
|
35
|
+
'hc:read',
|
|
36
|
+
'hc:write',
|
|
37
|
+
'macros:read',
|
|
38
|
+
'macros:write',
|
|
39
|
+
'organizations:read',
|
|
40
|
+
'organizations:write',
|
|
41
|
+
'requests:read',
|
|
42
|
+
'requests:write',
|
|
43
|
+
'satisfaction_ratings:read',
|
|
44
|
+
'satisfaction_ratings:write',
|
|
45
|
+
'security:read',
|
|
46
|
+
'side_conversations:read',
|
|
47
|
+
'side_conversations:write',
|
|
48
|
+
'sla_policies:read',
|
|
49
|
+
'sla_policies:write',
|
|
50
|
+
'targets:read',
|
|
51
|
+
'targets:write',
|
|
52
|
+
'themes:read',
|
|
53
|
+
'themes:write',
|
|
54
|
+
'ticket_attachments:read',
|
|
55
|
+
'ticket_attachments:write',
|
|
56
|
+
'ticket_views:read',
|
|
57
|
+
'ticket_views:write',
|
|
58
|
+
'tickets:read',
|
|
59
|
+
'tickets:write',
|
|
60
|
+
'triggers:read',
|
|
61
|
+
'triggers:write',
|
|
62
|
+
'users:read',
|
|
63
|
+
'users:write',
|
|
64
|
+
'web_widget:write',
|
|
65
|
+
'webhooks:read',
|
|
66
|
+
'webhooks:write',
|
|
67
|
+
'zis:read',
|
|
68
|
+
'zis:write',
|
|
69
|
+
];
|
|
70
|
+
/**
|
|
71
|
+
* What the authorize URL actually asks for. An operator does not choose, so
|
|
72
|
+
* this is the whole of the consent screen and it has to carry its own weight:
|
|
73
|
+
*
|
|
74
|
+
* - `users:read` is not optional. Connecting calls `GET /users/me.json` to
|
|
75
|
+
* identify the account, so without it every connect fails and nobody can fix
|
|
76
|
+
* it by ticking a box.
|
|
77
|
+
* - `tickets:read` is what a support integration is for.
|
|
78
|
+
*
|
|
79
|
+
* Read-only on purpose. Asking for 56 scopes because the catalogue lists 56
|
|
80
|
+
* would put an alarming consent screen in front of every user for access
|
|
81
|
+
* nothing uses.
|
|
82
|
+
*/
|
|
83
|
+
const SCOPES_REQUESTED = ['users:read', 'tickets:read'];
|
|
84
|
+
/**
|
|
85
|
+
* Zendesk needs its configuration's `subdomain` column before it can address
|
|
86
|
+
* anything, and a strategy is currently handed only `clientId`,
|
|
87
|
+
* `clientSecret`, `redirectUri` and `scopes` (`clientContextFor` in
|
|
88
|
+
* `connect.service.ts`). A package therefore has no way to read its own
|
|
89
|
+
* configuration column yet.
|
|
90
|
+
*
|
|
91
|
+
* Zendesk is the first provider to need this, and the mechanism is being
|
|
92
|
+
* decided separately rather than guessed at here. Until it lands, connecting
|
|
93
|
+
* fails loudly instead of inventing a host.
|
|
94
|
+
*/
|
|
95
|
+
function subdomainNotReadable() {
|
|
96
|
+
throw new Error('Zendesk cannot read the subdomain from its configuration yet. ' +
|
|
97
|
+
'A strategy receives only the OAuth client context, so the per-tenant ' +
|
|
98
|
+
'host is unavailable until that is extended.');
|
|
99
|
+
}
|
|
100
|
+
export function zendesk() {
|
|
101
|
+
// The declared endpoints are templates: the catalogue shows the shape, and
|
|
102
|
+
// each call will rebuild them from the configuration's subdomain once a
|
|
103
|
+
// package can read it.
|
|
104
|
+
const auth = oauth2({
|
|
105
|
+
authorizationUrl: 'https://{subdomain}.zendesk.com/oauth/authorizations/new',
|
|
106
|
+
tokenUrl: 'https://{subdomain}.zendesk.com/oauth/tokens',
|
|
107
|
+
// Zendesk's token endpoint takes JSON, not a form body, and a
|
|
108
|
+
// space-separated `scope` string. Refresh hits the same endpoint with the
|
|
109
|
+
// standard parameters, so oauth2()'s default refresh already fits.
|
|
110
|
+
//
|
|
111
|
+
// There is no `revokeUrl`: Zendesk revokes by token *id* through
|
|
112
|
+
// `DELETE /api/v2/oauth/tokens/{id}`, an admin call rather than the usual
|
|
113
|
+
// "post the token back" endpoint. See docs/setup.md.
|
|
114
|
+
tokenRequest: 'json',
|
|
115
|
+
scopeSeparator: ' ',
|
|
116
|
+
scopesAvailable: SCOPES_AVAILABLE,
|
|
117
|
+
scopesRequested: SCOPES_REQUESTED,
|
|
118
|
+
});
|
|
119
|
+
auth.buildAuthorizationUrl = () => subdomainNotReadable();
|
|
120
|
+
auth.exchangeCode = () => subdomainNotReadable();
|
|
121
|
+
auth.refresh = () => subdomainNotReadable();
|
|
122
|
+
return defineIntegration({
|
|
123
|
+
key: 'zendesk',
|
|
124
|
+
name: 'Zendesk',
|
|
125
|
+
docsUrl: 'https://developer.zendesk.com/api-reference/',
|
|
126
|
+
docsPath,
|
|
127
|
+
migrationsPath,
|
|
128
|
+
auth,
|
|
129
|
+
// The subdomain is known before anyone authorizes, so it is configuration
|
|
130
|
+
// rather than connection metadata. Declaring it here is what makes the
|
|
131
|
+
// admin ask for it and what lets core accept it as a `fields` key; the
|
|
132
|
+
// matching column lives in this package's own migration. Until #88 lands
|
|
133
|
+
// nothing reads or writes it, so it stays NULL and the auth steps below
|
|
134
|
+
// still throw.
|
|
135
|
+
configFields: [
|
|
136
|
+
{
|
|
137
|
+
key: 'subdomain',
|
|
138
|
+
label: 'Subdomain',
|
|
139
|
+
type: 'string',
|
|
140
|
+
required: true,
|
|
141
|
+
help: 'The part before .zendesk.com, e.g. acme',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
api: {
|
|
145
|
+
// No static base: every account is a different host. The subdomain is
|
|
146
|
+
// recorded on the connection when the account is linked, so the proxy
|
|
147
|
+
// resolves from there. Rooted at /api/v2 so the proxy's path-escape
|
|
148
|
+
// guard also keeps callers away from /oauth/*.
|
|
149
|
+
resolveBaseUrl: ({ metadata }) => {
|
|
150
|
+
const subdomain = metadata?.['subdomain'];
|
|
151
|
+
return typeof subdomain === 'string' &&
|
|
152
|
+
SUBDOMAIN_PATTERN.test(subdomain)
|
|
153
|
+
? `${hostFor(subdomain)}/api/v2`
|
|
154
|
+
: undefined;
|
|
155
|
+
},
|
|
156
|
+
authHeaders: ({ accessToken }) => ({
|
|
157
|
+
Authorization: `Bearer ${accessToken}`,
|
|
158
|
+
Accept: 'application/json',
|
|
159
|
+
}),
|
|
160
|
+
// Per-account hosts, so the rule is a suffix rather than one name.
|
|
161
|
+
egress: [{ hosts: ['*.zendesk.com'] }],
|
|
162
|
+
},
|
|
163
|
+
identity: {
|
|
164
|
+
// Also blocked: `GET /users/me.json` lives on the tenant host, so this
|
|
165
|
+
// needs the same configuration column the auth steps do.
|
|
166
|
+
fetchAccount: () => subdomainNotReadable(),
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
export default zendesk;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/docs/setup.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Zendesk Setup
|
|
2
|
+
|
|
3
|
+
To connect to Zendesk you need a Zendesk **OAuth client**. It lets Kosha
|
|
4
|
+
complete the OAuth handshake and act on behalf of your users.
|
|
5
|
+
|
|
6
|
+
Zendesk is per-tenant: every URL lives under your account's own subdomain, so
|
|
7
|
+
each configuration carries that subdomain (see "Subdomain rules" below).
|
|
8
|
+
|
|
9
|
+
## 1. Enable API access
|
|
10
|
+
|
|
11
|
+
Open **Admin Center → Apps and integrations → APIs → OAuth clients**. The first
|
|
12
|
+
time, Zendesk asks you to accept the Developer Terms — tick the box.
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
Then click **Get started**.
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
## 2. Add an OAuth client
|
|
21
|
+
|
|
22
|
+
Click **Add OAuth client**.
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
Fill in the details your users see on the consent screen — **Name**,
|
|
27
|
+
**Description**, and **Company**.
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
Scroll on to **Identifier** and **Client kind**.
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
- The **Identifier** _is_ your **client ID**. Zendesk pre-fills it from the
|
|
36
|
+
name; it is not a separately generated value. Keep a note of it.
|
|
37
|
+
- **Client kind** must be **Confidential**.
|
|
38
|
+
|
|
39
|
+
> **The client must be Confidential.** As Zendesk's own help text on that screen
|
|
40
|
+
> says, public clients "must use PKCE". A public client therefore requires a
|
|
41
|
+
> `code_challenge` on the authorize request; this provider authenticates with a
|
|
42
|
+
> client secret and does not send one, so a public client fails at the very
|
|
43
|
+
> first step with:
|
|
44
|
+
>
|
|
45
|
+
> ```
|
|
46
|
+
> invalid_request — The request is missing a required parameter, includes an
|
|
47
|
+
> unsupported parameter or parameter value, or is otherwise malformed.
|
|
48
|
+
> ```
|
|
49
|
+
>
|
|
50
|
+
> If you see that, check the client kind before anything else.
|
|
51
|
+
|
|
52
|
+
## 3. Redirect URL, scopes, and the secret
|
|
53
|
+
|
|
54
|
+

|
|
55
|
+
|
|
56
|
+
**Redirect URLs** — your Kosha callback, one per line:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
https://your-kosha-host/api/connect/callback/zendesk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For local development use `http://localhost:3333/api/connect/callback/zendesk`.
|
|
63
|
+
Zendesk allows plain HTTP only for `localhost` / `127.0.0.1`.
|
|
64
|
+
|
|
65
|
+
> **It must match exactly** — same scheme, host, port and path, with no trailing
|
|
66
|
+
> slash. A mismatch produces the same `invalid_request` error, because Zendesk
|
|
67
|
+
> will not redirect to an unregistered URL.
|
|
68
|
+
|
|
69
|
+
**Scopes** — restrict what tokens for this client may request, or leave it empty
|
|
70
|
+
to allow any scope. Whatever you set has to permit what the package asks for;
|
|
71
|
+
see the next section.
|
|
72
|
+
|
|
73
|
+
**Secret** — shown in full **exactly once**, right after you save. Afterwards
|
|
74
|
+
only the first few characters are visible (you can regenerate it on the Edit
|
|
75
|
+
page). Copy it now.
|
|
76
|
+
|
|
77
|
+
Click **Save**, then paste the **Identifier** (client ID) and **secret** into
|
|
78
|
+
the Kosha configuration form for Zendesk. Kosha stores the secret encrypted
|
|
79
|
+
(AES-256-GCM); it is never returned to a client.
|
|
80
|
+
|
|
81
|
+
A new client shows **Status: Inactive** with **0 tokens** until the first
|
|
82
|
+
connection is made — that is expected, not a problem to fix.
|
|
83
|
+
|
|
84
|
+
## 4. Scopes
|
|
85
|
+
|
|
86
|
+
**The package decides what to request, and an operator does not choose.** Kosha
|
|
87
|
+
asks Zendesk for:
|
|
88
|
+
|
|
89
|
+
- **`users:read`** — required. Connecting calls `GET /users/me.json` to identify
|
|
90
|
+
the account, so without it nobody can connect and no setting can fix it.
|
|
91
|
+
- **`tickets:read`** — what a support integration is for.
|
|
92
|
+
|
|
93
|
+
Whoever connects approves that set on Zendesk's own consent screen, and whatever
|
|
94
|
+
they actually granted is what Kosha stores against the connection.
|
|
95
|
+
|
|
96
|
+
So the only scope decision on your side is the **client's** list in step 3.
|
|
97
|
+
Leave it empty to allow any scope, or make sure it permits both of the above,
|
|
98
|
+
otherwise Zendesk refuses the authorization.
|
|
99
|
+
|
|
100
|
+
The catalogue below is reference, not a menu anyone picks from.
|
|
101
|
+
|
|
102
|
+
## Operation → scope reference
|
|
103
|
+
|
|
104
|
+
Representative support operations, the endpoint each uses, and the scope it
|
|
105
|
+
needs. Paths are relative to the proxy, which is rooted at `/api/v2`:
|
|
106
|
+
|
|
107
|
+
- **`read`** (broad) — every GET endpoint, including all of the below
|
|
108
|
+
- **`tickets:read`** — search tickets (`GET /search.json?query=type:ticket ...`)
|
|
109
|
+
- **`tickets:read`** — read one ticket (`GET /tickets/{id}.json`) and its
|
|
110
|
+
thread (`GET /tickets/{id}/comments.json`)
|
|
111
|
+
- **`tickets:write`** — create / update a ticket (`POST` / `PUT /tickets.json`)
|
|
112
|
+
- **`users:read`** — read users (`GET /users/{id}.json`) and the connected
|
|
113
|
+
account (`GET /users/me.json`)
|
|
114
|
+
- **`organizations:read`** — read organizations (`GET /organizations.json`)
|
|
115
|
+
- **`ticket_views:read`** — list views (`GET /views.json`)
|
|
116
|
+
|
|
117
|
+
A read-only integration wants `tickets:read` + `users:read` (or simply `read`).
|
|
118
|
+
|
|
119
|
+
## Subdomain rules
|
|
120
|
+
|
|
121
|
+
The subdomain is a field on the configuration, alongside the client ID and
|
|
122
|
+
secret. Enter the label only:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
acme (for https://acme.zendesk.com)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
You can read it off the Zendesk admin header, or the browser address bar, on
|
|
129
|
+
any Admin Center page:
|
|
130
|
+
|
|
131
|
+

|
|
132
|
+
|
|
133
|
+
- It must be a **bare DNS label**. Not `acme.zendesk.com`, not a URL, and
|
|
134
|
+
nothing containing `/`, `@`, a space, or a scheme.
|
|
135
|
+
- Kosha validates it on every use and refuses anything else. The value is
|
|
136
|
+
interpolated into the host Kosha calls, so an unchecked subdomain would let a
|
|
137
|
+
configuration redirect Kosha's server-side requests (SSRF).
|
|
138
|
+
- It is recorded on the connection when the account is linked, and the proxy
|
|
139
|
+
routes to `https://{subdomain}.zendesk.com/api/v2` from there. Rooting at
|
|
140
|
+
`/api/v2` means a caller cannot reach `/oauth/*` or anything else outside the
|
|
141
|
+
REST API.
|
|
142
|
+
- Each configuration carries its own subdomain, so one Kosha deployment can
|
|
143
|
+
serve several Zendesk accounts.
|
|
144
|
+
|
|
145
|
+
## Token lifetime and revocation
|
|
146
|
+
|
|
147
|
+
- The **Expire tokens** setting on the client (see the screenshot above) gives
|
|
148
|
+
every issued token a default expiry. OAuth clients created **on or after 30
|
|
149
|
+
April 2026** have it applied automatically: access tokens last 30 minutes and
|
|
150
|
+
come with a 30-day refresh token. Kosha refreshes them on the next proxied
|
|
151
|
+
request, so this is invisible to callers. Note Zendesk says it "cannot be
|
|
152
|
+
turned off once turned on".
|
|
153
|
+
- **Zendesk rotates refresh tokens.** A refresh returns both a new access token
|
|
154
|
+
and a new refresh token, and the old refresh token stops working. Kosha stores
|
|
155
|
+
whichever refresh token comes back, so this is handled — but it does mean a
|
|
156
|
+
refresh response that never lands leaves the connection needing a reconnect.
|
|
157
|
+
- Zendesk has **no standard OAuth revoke endpoint**: tokens are revoked by id
|
|
158
|
+
through `DELETE /api/v2/oauth/tokens/{id}`, an admin call. The provider
|
|
159
|
+
therefore declares no `revokeUrl`. Revoking a connection in Kosha deletes the
|
|
160
|
+
stored credential; to invalidate the token at Zendesk as well, delete it from
|
|
161
|
+
**Admin Center → APIs → OAuth tokens**.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
CREATE TABLE "zendesk_configuration" (
|
|
2
|
+
"id" TEXT NOT NULL,
|
|
3
|
+
"environmentId" TEXT NOT NULL,
|
|
4
|
+
"name" TEXT NOT NULL,
|
|
5
|
+
"slug" TEXT NOT NULL,
|
|
6
|
+
-- Encrypted, so TEXT rather than JSONB.
|
|
7
|
+
"credentials" TEXT,
|
|
8
|
+
-- Provider specific. Zendesk is per tenant: authorize, token and the API
|
|
9
|
+
-- all live under "{subdomain}.zendesk.com", and the authorize URL is needed
|
|
10
|
+
-- before anyone has logged in, so unlike Jira's cloudId there is nothing to
|
|
11
|
+
-- discover from a token. It is configuration, known when the OAuth client
|
|
12
|
+
-- is created, which is why it is a column here rather than connection
|
|
13
|
+
-- metadata.
|
|
14
|
+
--
|
|
15
|
+
-- Nullable until #88 lets a package read its own configuration columns:
|
|
16
|
+
-- the store's INSERT names only the columns every provider has, so NOT
|
|
17
|
+
-- NULL here would fail a create with a driver error. Once #88 lands this
|
|
18
|
+
-- is declared with configFields, which enforces required on create.
|
|
19
|
+
"subdomain" TEXT,
|
|
20
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
21
|
+
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
22
|
+
|
|
23
|
+
CONSTRAINT "zendesk_configuration_pkey" PRIMARY KEY ("id")
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
CREATE TABLE "zendesk_connection" (
|
|
27
|
+
"accountId" TEXT NOT NULL,
|
|
28
|
+
-- Copied from `account` so the unique index below can use it.
|
|
29
|
+
"userId" TEXT NOT NULL,
|
|
30
|
+
"environmentId" TEXT NOT NULL,
|
|
31
|
+
"configurationId" TEXT NOT NULL,
|
|
32
|
+
"metadata" JSONB,
|
|
33
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
34
|
+
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
35
|
+
|
|
36
|
+
CONSTRAINT "zendesk_connection_pkey" PRIMARY KEY ("accountId")
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
CREATE UNIQUE INDEX "zendesk_configuration_environmentId_slug_key" ON "zendesk_configuration"("environmentId", "slug");
|
|
40
|
+
|
|
41
|
+
CREATE INDEX "zendesk_configuration_environmentId_idx" ON "zendesk_configuration"("environmentId");
|
|
42
|
+
|
|
43
|
+
CREATE UNIQUE INDEX "zendesk_connection_environmentId_configurationId_userId_key" ON "zendesk_connection"("environmentId", "configurationId", "userId");
|
|
44
|
+
|
|
45
|
+
CREATE INDEX "zendesk_connection_environmentId_idx" ON "zendesk_connection"("environmentId");
|
|
46
|
+
|
|
47
|
+
CREATE INDEX "zendesk_connection_configurationId_idx" ON "zendesk_connection"("configurationId");
|
|
48
|
+
|
|
49
|
+
CREATE INDEX "zendesk_connection_userId_idx" ON "zendesk_connection"("userId");
|
|
50
|
+
|
|
51
|
+
ALTER TABLE "zendesk_configuration" ADD CONSTRAINT "zendesk_configuration_environmentId_fkey" FOREIGN KEY ("environmentId") REFERENCES "environment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
52
|
+
|
|
53
|
+
ALTER TABLE "zendesk_connection" ADD CONSTRAINT "zendesk_connection_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
54
|
+
|
|
55
|
+
ALTER TABLE "zendesk_connection" ADD CONSTRAINT "zendesk_connection_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
56
|
+
|
|
57
|
+
ALTER TABLE "zendesk_connection" ADD CONSTRAINT "zendesk_connection_environmentId_fkey" FOREIGN KEY ("environmentId") REFERENCES "environment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
58
|
+
|
|
59
|
+
-- RESTRICT: a configuration that still has connections cannot be deleted.
|
|
60
|
+
ALTER TABLE "zendesk_connection" ADD CONSTRAINT "zendesk_connection_configurationId_fkey" FOREIGN KEY ("configurationId") REFERENCES "zendesk_configuration"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosha-ai/integration-zendesk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Zendesk integration for Kosha",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"kosha",
|
|
7
|
+
"zendesk",
|
|
8
|
+
"oauth",
|
|
9
|
+
"integrations"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/codemancers/kosha#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/codemancers/kosha/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/codemancers/kosha.git",
|
|
19
|
+
"directory": "packages/integrations/zendesk"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
".": {
|
|
31
|
+
"@org/source": "./src/index.ts",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"docs",
|
|
40
|
+
"migrations",
|
|
41
|
+
"!**/*.tsbuildinfo"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"tslib": "^2.3.0"
|
|
45
|
+
},
|
|
46
|
+
"kosha": {
|
|
47
|
+
"kind": "integration",
|
|
48
|
+
"key": "zendesk"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@kosha-ai/integration-sdk": "0.4.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@kosha-ai/integration-sdk": "0.4.1"
|
|
55
|
+
}
|
|
6
56
|
}
|