@theholocron/zendesk-client 0.0.0 → 0.2.0
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/README.md +69 -7
- package/dist/index.d.mts +117 -117
- package/dist/index.mjs +112 -255
- package/package.json +35 -36
package/README.md
CHANGED
|
@@ -1,19 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @theholocron/zendesk-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client for the Zendesk API. Covers tickets, comments, fields, status, activities, and search.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
pnpm add @theholocron/zendesk-client
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
```
|
|
14
|
-
import
|
|
13
|
+
```ts
|
|
14
|
+
import { createZendeskClient, createToken } from "@theholocron/zendesk-client";
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const zendesk = createZendeskClient({
|
|
17
|
+
baseUrl: "https://myorg.zendesk.com",
|
|
18
|
+
token: createToken("agent@example.com", "your-api-token"),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Tickets
|
|
22
|
+
const ticket = await zendesk.tickets.get(12345);
|
|
23
|
+
const all = await zendesk.tickets.list();
|
|
24
|
+
await zendesk.tickets.create({
|
|
25
|
+
subject: "Bug report",
|
|
26
|
+
comment: { body: "Details..." },
|
|
27
|
+
});
|
|
28
|
+
await zendesk.tickets.update(12345, { status: "solved" });
|
|
29
|
+
await zendesk.tickets.delete(12345);
|
|
30
|
+
|
|
31
|
+
// Comments
|
|
32
|
+
const thread = await zendesk.comments.list(12345);
|
|
33
|
+
await zendesk.comments.create(12345, "Thanks for reaching out!");
|
|
34
|
+
|
|
35
|
+
// Fields
|
|
36
|
+
const fields = await zendesk.fields.list();
|
|
37
|
+
const field = await zendesk.fields.get(7);
|
|
38
|
+
|
|
39
|
+
// Status
|
|
40
|
+
const statuses = await zendesk.status.list();
|
|
41
|
+
await zendesk.status.create({
|
|
42
|
+
agent_label: "Escalated",
|
|
43
|
+
status_category: "open",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Search
|
|
47
|
+
const results = await zendesk.search.query(
|
|
48
|
+
"type:ticket status:open assignee:me",
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Activities
|
|
52
|
+
const activities = await zendesk.activities.get();
|
|
17
53
|
```
|
|
18
54
|
|
|
19
|
-
|
|
55
|
+
## Auth
|
|
56
|
+
|
|
57
|
+
Zendesk uses HTTP Basic auth. Generate an API token in your Zendesk Admin panel under **Apps and integrations → APIs → Zendesk API**, then use `createToken` to encode your credentials:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { createToken } from "@theholocron/zendesk-client";
|
|
61
|
+
|
|
62
|
+
const token = createToken("agent@example.com", "your-api-token");
|
|
63
|
+
// → base64("agent@example.com/token:your-api-token")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Pass `token` to `createZendeskClient` along with your subdomain base URL.
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
### `createZendeskClient(opts)`
|
|
71
|
+
|
|
72
|
+
| Option | Type | Description |
|
|
73
|
+
| --------- | -------- | ------------------------------------------------------------- |
|
|
74
|
+
| `baseUrl` | `string` | Your Zendesk instance URL, e.g. `"https://myorg.zendesk.com"` |
|
|
75
|
+
| `token` | `string` | Encoded token from `createToken(email, apiToken)` |
|
|
76
|
+
|
|
77
|
+
Returns a client with `activities`, `comments`, `fields`, `search`, `status`, and `tickets` namespaces.
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
GPL-3.0 © [Newton Koumantzelis](https://github.com/iamnewton)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RestClient } from "@theholocron/http-client";
|
|
1
2
|
//#region src/types.d.ts
|
|
2
3
|
interface IAPIResponse {
|
|
3
4
|
next_page?: string | null;
|
|
@@ -98,47 +99,6 @@ interface IActivityResponse extends IAPIResponse {
|
|
|
98
99
|
users: IUser[];
|
|
99
100
|
}
|
|
100
101
|
//#endregion
|
|
101
|
-
//#region src/activities/activities.d.ts
|
|
102
|
-
interface FetchOptions$5 {
|
|
103
|
-
environment?: string;
|
|
104
|
-
headers?: Record<string, unknown>;
|
|
105
|
-
params?: Record<string, unknown>;
|
|
106
|
-
token: string;
|
|
107
|
-
}
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/group/group.types.d.ts
|
|
110
|
-
interface IGroup {
|
|
111
|
-
created_at?: string | null;
|
|
112
|
-
default?: boolean | null;
|
|
113
|
-
deleted?: boolean | null;
|
|
114
|
-
description?: string | null;
|
|
115
|
-
id?: number | null;
|
|
116
|
-
is_public?: boolean | null;
|
|
117
|
-
name?: string | null;
|
|
118
|
-
updated_at?: string | null;
|
|
119
|
-
url?: string | null;
|
|
120
|
-
}
|
|
121
|
-
//#endregion
|
|
122
|
-
//#region src/tickets/comments.types.d.ts
|
|
123
|
-
interface IComment {
|
|
124
|
-
attachments?: IAttachment[] | null;
|
|
125
|
-
audit_id?: number | null;
|
|
126
|
-
author_id?: number | null;
|
|
127
|
-
body?: string | null;
|
|
128
|
-
created_at?: string | null;
|
|
129
|
-
html_body?: string | null;
|
|
130
|
-
id?: number | null;
|
|
131
|
-
metadata?: IMetadata | null;
|
|
132
|
-
plain_body?: string | null;
|
|
133
|
-
public?: boolean | null;
|
|
134
|
-
type?: "Comment" | "VoiceComment" | null;
|
|
135
|
-
uploads?: string[] | null;
|
|
136
|
-
via?: IVia | null;
|
|
137
|
-
}
|
|
138
|
-
interface ICommentResponse {
|
|
139
|
-
comments: IComment[];
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
102
|
//#region src/tickets/fields.types.d.ts
|
|
143
103
|
interface ICustomField {
|
|
144
104
|
id: number | null;
|
|
@@ -182,9 +142,9 @@ type TTicketFieldResponse = IAPIResponse & {
|
|
|
182
142
|
};
|
|
183
143
|
//#endregion
|
|
184
144
|
//#region src/tickets/tickets.types.d.ts
|
|
185
|
-
type TTicketStatus =
|
|
186
|
-
type TTicketPriority =
|
|
187
|
-
type TTicketType =
|
|
145
|
+
type TTicketStatus = "new" | "open" | "pending" | "hold" | "solved" | "closed";
|
|
146
|
+
type TTicketPriority = "urgent" | "high" | "normal" | "low";
|
|
147
|
+
type TTicketType = "problem" | "incident" | "question" | "task";
|
|
188
148
|
interface IVia {
|
|
189
149
|
channel: string | number | null;
|
|
190
150
|
source?: {
|
|
@@ -203,7 +163,7 @@ interface IMetadata {
|
|
|
203
163
|
};
|
|
204
164
|
via: IVia;
|
|
205
165
|
}
|
|
206
|
-
interface ITicket
|
|
166
|
+
interface ITicket {
|
|
207
167
|
allow_attachments?: boolean | null;
|
|
208
168
|
allow_channelback?: boolean | null;
|
|
209
169
|
assignee_email?: string | null;
|
|
@@ -258,27 +218,51 @@ interface ITicket$1 {
|
|
|
258
218
|
voice_comment?: Record<string, unknown>;
|
|
259
219
|
}
|
|
260
220
|
type TTicketsResponse = IAPIResponse & {
|
|
261
|
-
tickets: ITicket
|
|
221
|
+
tickets: ITicket[];
|
|
262
222
|
deleted_ticket_forms?: Array<unknown>;
|
|
263
223
|
};
|
|
264
224
|
type TTicketResponse = IAPIResponse & {
|
|
265
|
-
ticket: ITicket
|
|
225
|
+
ticket: ITicket;
|
|
266
226
|
deleted_ticket_forms?: Array<unknown>;
|
|
267
227
|
};
|
|
268
228
|
//#endregion
|
|
229
|
+
//#region src/tickets/comments.types.d.ts
|
|
230
|
+
interface IComment {
|
|
231
|
+
attachments?: IAttachment[] | null;
|
|
232
|
+
audit_id?: number | null;
|
|
233
|
+
author_id?: number | null;
|
|
234
|
+
body?: string | null;
|
|
235
|
+
created_at?: string | null;
|
|
236
|
+
html_body?: string | null;
|
|
237
|
+
id?: number | null;
|
|
238
|
+
metadata?: IMetadata | null;
|
|
239
|
+
plain_body?: string | null;
|
|
240
|
+
public?: boolean | null;
|
|
241
|
+
type?: "Comment" | "VoiceComment" | null;
|
|
242
|
+
uploads?: string[] | null;
|
|
243
|
+
via?: IVia | null;
|
|
244
|
+
}
|
|
245
|
+
interface ICommentResponse {
|
|
246
|
+
comments: IComment[];
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/group/group.types.d.ts
|
|
250
|
+
interface IGroup {
|
|
251
|
+
created_at?: string | null;
|
|
252
|
+
default?: boolean | null;
|
|
253
|
+
deleted?: boolean | null;
|
|
254
|
+
description?: string | null;
|
|
255
|
+
id?: number | null;
|
|
256
|
+
is_public?: boolean | null;
|
|
257
|
+
name?: string | null;
|
|
258
|
+
updated_at?: string | null;
|
|
259
|
+
url?: string | null;
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
269
262
|
//#region src/search/search.types.d.ts
|
|
270
263
|
interface ISearchResponse extends IAPIResponse {
|
|
271
264
|
facets?: string | null;
|
|
272
|
-
results: ITicket
|
|
273
|
-
}
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/search/search.d.ts
|
|
276
|
-
interface FetchOptions$4 {
|
|
277
|
-
environment?: string;
|
|
278
|
-
headers?: Record<string, unknown>;
|
|
279
|
-
params?: Record<string, unknown>;
|
|
280
|
-
sort?: "asc" | "desc";
|
|
281
|
-
token: string;
|
|
265
|
+
results: ITicket[] | IUser[] | IGroup[];
|
|
282
266
|
}
|
|
283
267
|
//#endregion
|
|
284
268
|
//#region src/status/status.types.d.ts
|
|
@@ -311,43 +295,21 @@ interface ICustomStatusResponse extends IAPIResponse {
|
|
|
311
295
|
custom_status: ICustomStatus;
|
|
312
296
|
}
|
|
313
297
|
//#endregion
|
|
314
|
-
//#region src/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
params?: Record<string, unknown>;
|
|
321
|
-
token: string;
|
|
322
|
-
}
|
|
323
|
-
//#endregion
|
|
324
|
-
//#region src/tickets/comments.d.ts
|
|
325
|
-
interface FetchOptions$2 {
|
|
326
|
-
environment?: string;
|
|
327
|
-
headers?: Record<string, unknown>;
|
|
328
|
-
params?: Record<string, unknown>;
|
|
329
|
-
token: string;
|
|
330
|
-
}
|
|
331
|
-
//#endregion
|
|
332
|
-
//#region src/tickets/fields.d.ts
|
|
333
|
-
interface FetchOptions$1 {
|
|
334
|
-
environment?: string;
|
|
335
|
-
headers?: Record<string, unknown>;
|
|
336
|
-
id?: number | null;
|
|
337
|
-
method?: "create" | "delete" | "patch" | "post" | "put";
|
|
338
|
-
params?: Record<string, unknown>;
|
|
298
|
+
//#region src/utils.d.ts
|
|
299
|
+
declare const createToken: (user: string, password: string) => string;
|
|
300
|
+
interface ZendeskClientOptions {
|
|
301
|
+
/** Base URL of your Zendesk instance, e.g. "https://myorg.zendesk.com". */
|
|
302
|
+
baseUrl: string;
|
|
303
|
+
/** Token from createToken(email, apiToken). */
|
|
339
304
|
token: string;
|
|
305
|
+
/** Override fetch for testing. Defaults to globalThis.fetch. */
|
|
306
|
+
fetch?: typeof fetch;
|
|
340
307
|
}
|
|
341
308
|
//#endregion
|
|
342
|
-
//#region src/
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
id?: number | null;
|
|
347
|
-
method?: "create" | "delete" | "patch" | "post" | "put";
|
|
348
|
-
params?: Record<string, unknown>;
|
|
349
|
-
token: string;
|
|
350
|
-
}
|
|
309
|
+
//#region src/activities/activities.d.ts
|
|
310
|
+
declare function activities(rest: RestClient): {
|
|
311
|
+
get: (params?: Record<string, string>) => Promise<IActivityResponse>;
|
|
312
|
+
};
|
|
351
313
|
//#endregion
|
|
352
314
|
//#region src/activities/activities.mocks.d.ts
|
|
353
315
|
declare const mockActivity: IActivity;
|
|
@@ -356,17 +318,54 @@ declare const mockActivityResponse: IActivityResponse;
|
|
|
356
318
|
//#region src/group/group.mocks.d.ts
|
|
357
319
|
declare const mockGroup: IGroup;
|
|
358
320
|
//#endregion
|
|
321
|
+
//#region src/search/search.d.ts
|
|
322
|
+
declare function search(rest: RestClient): {
|
|
323
|
+
query: (q: string, params?: Record<string, string>) => Promise<ISearchResponse>;
|
|
324
|
+
};
|
|
325
|
+
//#endregion
|
|
359
326
|
//#region src/search/search.mocks.d.ts
|
|
360
327
|
declare const mockSearchResponseGroups: ISearchResponse;
|
|
361
328
|
declare const mockSearchResponseTickets: ISearchResponse;
|
|
362
329
|
declare const mockSearchResponseUsers: ISearchResponse;
|
|
363
330
|
//#endregion
|
|
331
|
+
//#region src/status/status.d.ts
|
|
332
|
+
declare function status(rest: RestClient): {
|
|
333
|
+
list: () => Promise<ICustomStatusesResponse>;
|
|
334
|
+
get: (id: number) => Promise<ICustomStatusResponse>;
|
|
335
|
+
create: (data: ICustomStatus) => Promise<ICustomStatusResponse>;
|
|
336
|
+
update: (id: number, data: Partial<ICustomStatus>) => Promise<ICustomStatusResponse>;
|
|
337
|
+
};
|
|
338
|
+
//#endregion
|
|
364
339
|
//#region src/status/status.mocks.d.ts
|
|
365
340
|
declare const mockDefaultStatus: IDefaultStatus;
|
|
366
341
|
declare const mockCustomStatus: ICustomStatus;
|
|
367
342
|
declare const mockCustomStatusesResponse: ICustomStatusesResponse;
|
|
368
343
|
declare const mockCustomStatusResponse: ICustomStatusResponse;
|
|
369
344
|
//#endregion
|
|
345
|
+
//#region src/tickets/comments.d.ts
|
|
346
|
+
declare function comments(rest: RestClient): {
|
|
347
|
+
list: (ticketId: number) => Promise<ICommentResponse>;
|
|
348
|
+
create: (ticketId: number, body: string) => Promise<void>;
|
|
349
|
+
};
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/tickets/fields.d.ts
|
|
352
|
+
declare function fields(rest: RestClient): {
|
|
353
|
+
list: () => Promise<TTicketFieldsResponse>;
|
|
354
|
+
get: (id: number) => Promise<TTicketFieldResponse>;
|
|
355
|
+
create: (data: ITicketField) => Promise<TTicketFieldResponse>;
|
|
356
|
+
update: (id: number, data: Partial<ITicketField>) => Promise<TTicketFieldResponse>;
|
|
357
|
+
delete: (id: number) => Promise<void>;
|
|
358
|
+
};
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/tickets/tickets.d.ts
|
|
361
|
+
declare function tickets(rest: RestClient): {
|
|
362
|
+
list: (params?: Record<string, string>) => Promise<TTicketsResponse>;
|
|
363
|
+
get: (id: number) => Promise<TTicketResponse>;
|
|
364
|
+
create: (data: ITicket) => Promise<TTicketResponse>;
|
|
365
|
+
update: (id: number, data: Partial<ITicket>) => Promise<TTicketResponse>;
|
|
366
|
+
delete: (id: number) => Promise<void>;
|
|
367
|
+
};
|
|
368
|
+
//#endregion
|
|
370
369
|
//#region src/tickets/comments.mocks.d.ts
|
|
371
370
|
declare const mockComment: IComment;
|
|
372
371
|
declare const mockCommentResponse: ICommentResponse;
|
|
@@ -418,44 +417,45 @@ declare const mockTicketMetric: ITicketMetric;
|
|
|
418
417
|
//#region src/tickets/tickets.mocks.d.ts
|
|
419
418
|
declare const mockVia: IVia;
|
|
420
419
|
declare const mockMetadata: IMetadata;
|
|
421
|
-
declare const mockTicket: ITicket
|
|
420
|
+
declare const mockTicket: ITicket;
|
|
422
421
|
declare const mockTicketsResponse: TTicketsResponse;
|
|
423
422
|
declare const mockTicketResponse: TTicketResponse;
|
|
424
423
|
//#endregion
|
|
425
424
|
//#region src/user/user.mocks.d.ts
|
|
426
425
|
declare const mockUser: IUser;
|
|
427
426
|
//#endregion
|
|
428
|
-
//#region src/utils.d.ts
|
|
429
|
-
declare const createToken: (user: string, password: string) => string;
|
|
430
|
-
declare function setToken(user: string, password: string): void;
|
|
431
|
-
//#endregion
|
|
432
427
|
//#region src/index.d.ts
|
|
433
|
-
declare
|
|
428
|
+
declare function createZendeskClient(opts: ZendeskClientOptions): {
|
|
434
429
|
activities: {
|
|
435
|
-
get: (
|
|
430
|
+
get: (params?: Record<string, string>) => Promise<IActivityResponse>;
|
|
431
|
+
};
|
|
432
|
+
comments: {
|
|
433
|
+
list: (ticketId: number) => Promise<ICommentResponse>;
|
|
434
|
+
create: (ticketId: number, body: string) => Promise<void>;
|
|
435
|
+
};
|
|
436
|
+
fields: {
|
|
437
|
+
list: () => Promise<TTicketFieldsResponse>;
|
|
438
|
+
get: (id: number) => Promise<TTicketFieldResponse>;
|
|
439
|
+
create: (data: ITicketField) => Promise<TTicketFieldResponse>;
|
|
440
|
+
update: (id: number, data: Partial<ITicketField>) => Promise<TTicketFieldResponse>;
|
|
441
|
+
delete: (id: number) => Promise<void>;
|
|
442
|
+
};
|
|
443
|
+
search: {
|
|
444
|
+
query: (q: string, params?: Record<string, string>) => Promise<ISearchResponse>;
|
|
436
445
|
};
|
|
437
|
-
search: (query: string, options: FetchOptions$4) => Promise<[IAPIError | null, ISearchResponse]>;
|
|
438
446
|
status: {
|
|
439
|
-
|
|
440
|
-
get: (id
|
|
441
|
-
|
|
447
|
+
list: () => Promise<ICustomStatusesResponse>;
|
|
448
|
+
get: (id: number) => Promise<ICustomStatusResponse>;
|
|
449
|
+
create: (data: ICustomStatus) => Promise<ICustomStatusResponse>;
|
|
450
|
+
update: (id: number, data: Partial<ICustomStatus>) => Promise<ICustomStatusResponse>;
|
|
442
451
|
};
|
|
443
452
|
tickets: {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
create: (field: ITicketField, options: FetchOptions$1) => Promise<ITicketField>;
|
|
450
|
-
get: (id?: number | FetchOptions$1 | undefined, options?: FetchOptions$1 | undefined) => Promise<[IAPIError | null, TTicketFieldsResponse | TTicketFieldResponse]>;
|
|
451
|
-
update: (id: number, field: ITicketField, options: FetchOptions$1) => Promise<ITicketField>;
|
|
452
|
-
delete: (id: number, options: FetchOptions$1) => any;
|
|
453
|
-
};
|
|
454
|
-
create: (ticket: ITicket$1, options: FetchOptions) => Promise<ITicket$1>;
|
|
455
|
-
get: (id?: number | FetchOptions | undefined, options?: FetchOptions | undefined) => Promise<[IAPIError | null, TTicketResponse | TTicketsResponse]>;
|
|
456
|
-
update: (id: number, ticket: ITicket$1, options: FetchOptions) => Promise<ITicket$1>;
|
|
457
|
-
delete: (id: number, options: FetchOptions) => Promise<void>;
|
|
453
|
+
list: (params?: Record<string, string>) => Promise<TTicketsResponse>;
|
|
454
|
+
get: (id: number) => Promise<TTicketResponse>;
|
|
455
|
+
create: (data: ITicket) => Promise<TTicketResponse>;
|
|
456
|
+
update: (id: number, data: Partial<ITicket>) => Promise<TTicketResponse>;
|
|
457
|
+
delete: (id: number) => Promise<void>;
|
|
458
458
|
};
|
|
459
459
|
};
|
|
460
460
|
//#endregion
|
|
461
|
-
export { type IAPIError, type IAPIResponse, type IActivity, type IActivityResponse, type IAttachment, type IComment, type ICommentResponse, type ICustomField, type ICustomStatus, type ICustomStatusResponse, type ICustomStatusesResponse, type IDefaultStatus, type IGroup, type IImage, type IMetadata, type ISearchResponse, type ITicket
|
|
461
|
+
export { type IAPIError, type IAPIResponse, type IActivity, type IActivityResponse, type IAttachment, type IComment, type ICommentResponse, type ICustomField, type ICustomStatus, type ICustomStatusResponse, type ICustomStatusesResponse, type IDefaultStatus, type IGroup, type IImage, type IMetadata, type ISearchResponse, type ITicket, type ITicketField, type ITicketMetric, type IUser, type IVia, type TTicketFieldResponse, type TTicketFieldsResponse, type TTicketPriority, type TTicketResponse, type TTicketStatus, type TTicketType, type TTicketsResponse, type ZendeskClientOptions, type activities, type comments, createToken, createZendeskClient, type fields, mockActivity, mockActivityResponse, mockAttachment, mockComment, mockCommentResponse, mockCustomField1, mockCustomField2, mockCustomFields, mockCustomStatus, mockCustomStatusResponse, mockCustomStatusesResponse, mockDefaultStatus, mockGroup, mockImage, mockMetadata, mockSearchResponseGroups, mockSearchResponseTickets, mockSearchResponseUsers, mockThumbnail, mockTicket, mockTicketField, mockTicketFieldResponse, mockTicketFieldsResponse, mockTicketMetric, mockTicketResponse, mockTicketsResponse, mockUser, mockVia, type search, type status, type tickets };
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,104 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { createRestClient } from "@theholocron/http-client";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const createToken = (user, password) => Buffer.from(`${user}/token:${password}`).toString("base64");
|
|
4
|
+
function createZendeskRestClient(opts) {
|
|
5
|
+
return createRestClient({
|
|
6
|
+
baseUrl: opts.baseUrl,
|
|
7
|
+
token: opts.token,
|
|
8
|
+
vendor: "Zendesk",
|
|
9
|
+
fetch: opts.fetch
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
4
13
|
//#region src/activities/activities.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const PATH$5 = "/api/v2/activities";
|
|
15
|
+
function activities(rest) {
|
|
16
|
+
return { get: (params) => rest.request(PATH$5, { query: params }) };
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/search/search.ts
|
|
20
|
+
const PATH$4 = "/api/v2/search";
|
|
21
|
+
function search(rest) {
|
|
22
|
+
return { query: (q, params) => rest.request(PATH$4, { query: {
|
|
23
|
+
query: q,
|
|
24
|
+
sort_order: "desc",
|
|
25
|
+
...params
|
|
26
|
+
} }) };
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/status/status.ts
|
|
30
|
+
const PATH$3 = "/api/v2/custom_statuses";
|
|
31
|
+
function status(rest) {
|
|
32
|
+
return {
|
|
33
|
+
list: () => rest.request(PATH$3),
|
|
34
|
+
get: (id) => rest.request(`${PATH$3}/${id}`),
|
|
35
|
+
create: (data) => rest.request(PATH$3, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
body: { custom_status: data }
|
|
38
|
+
}),
|
|
39
|
+
update: (id, data) => rest.request(`${PATH$3}/${id}`, {
|
|
40
|
+
method: "PUT",
|
|
41
|
+
body: { custom_status: data }
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/tickets/comments.ts
|
|
47
|
+
const PATH$2 = "/api/v2/tickets";
|
|
48
|
+
function comments(rest) {
|
|
49
|
+
return {
|
|
50
|
+
list: (ticketId) => rest.request(`${PATH$2}/${ticketId}/comments`),
|
|
51
|
+
create: (ticketId, body) => rest.request(`${PATH$2}/${ticketId}`, {
|
|
52
|
+
method: "PUT",
|
|
53
|
+
body: { ticket: { comment: { body } } }
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/tickets/fields.ts
|
|
59
|
+
const PATH$1 = "/api/v2/ticket_fields";
|
|
60
|
+
function fields(rest) {
|
|
61
|
+
return {
|
|
62
|
+
list: () => rest.request(PATH$1),
|
|
63
|
+
get: (id) => rest.request(`${PATH$1}/${id}`),
|
|
64
|
+
create: (data) => rest.request(PATH$1, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: { ticket_field: data }
|
|
67
|
+
}),
|
|
68
|
+
update: (id, data) => rest.request(`${PATH$1}/${id}`, {
|
|
69
|
+
method: "PUT",
|
|
70
|
+
body: { ticket_field: data }
|
|
71
|
+
}),
|
|
72
|
+
delete: (id) => rest.request(`${PATH$1}/${id}`, {
|
|
73
|
+
method: "DELETE",
|
|
74
|
+
expectNoContent: true
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/tickets/tickets.ts
|
|
80
|
+
const PATH = "/api/v2/tickets";
|
|
81
|
+
function tickets(rest) {
|
|
82
|
+
return {
|
|
83
|
+
list: (params) => rest.request(PATH, { query: {
|
|
84
|
+
include: "custom_statuses",
|
|
85
|
+
...params
|
|
86
|
+
} }),
|
|
87
|
+
get: (id) => rest.request(`${PATH}/${id}`),
|
|
88
|
+
create: (data) => rest.request(PATH, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
body: { ticket: data }
|
|
91
|
+
}),
|
|
92
|
+
update: (id, data) => rest.request(`${PATH}/${id}`, {
|
|
93
|
+
method: "PUT",
|
|
94
|
+
body: { ticket: data }
|
|
95
|
+
}),
|
|
96
|
+
delete: (id) => rest.request(`${PATH}/${id}`, {
|
|
97
|
+
method: "DELETE",
|
|
98
|
+
expectNoContent: true
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
}
|
|
18
102
|
//#endregion
|
|
19
103
|
//#region src/attachments/attachments.mocks.ts
|
|
20
104
|
const mockImage = {
|
|
@@ -123,9 +207,6 @@ const mockActivityResponse = {
|
|
|
123
207
|
users: [mockUser]
|
|
124
208
|
};
|
|
125
209
|
//#endregion
|
|
126
|
-
//#region src/activities/index.ts
|
|
127
|
-
var activities_default = { ...activities_default$1 };
|
|
128
|
-
//#endregion
|
|
129
210
|
//#region src/group/group.mocks.ts
|
|
130
211
|
const mockGroup = {
|
|
131
212
|
created_at: "2018-04-06T03:17:05Z",
|
|
@@ -138,25 +219,6 @@ const mockGroup = {
|
|
|
138
219
|
url: "https://example.zendesk.com/api/v2/groups/1835972.json"
|
|
139
220
|
};
|
|
140
221
|
//#endregion
|
|
141
|
-
//#region src/search/search.ts
|
|
142
|
-
const operation$4 = "/api/v2/search";
|
|
143
|
-
var search_default$1 = (query, options) => exreq({
|
|
144
|
-
operation: operation$4,
|
|
145
|
-
options: {
|
|
146
|
-
...options,
|
|
147
|
-
params: {
|
|
148
|
-
...options.params,
|
|
149
|
-
query,
|
|
150
|
-
sort_order: options?.sort || "desc"
|
|
151
|
-
},
|
|
152
|
-
headers: {
|
|
153
|
-
...options.headers,
|
|
154
|
-
Authorization: `Basic ${options.token}`
|
|
155
|
-
},
|
|
156
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
//#endregion
|
|
160
222
|
//#region src/tickets/fields.mocks.ts
|
|
161
223
|
const mockCustomField1 = {
|
|
162
224
|
id: 27642,
|
|
@@ -279,51 +341,6 @@ const mockSearchResponseUsers = {
|
|
|
279
341
|
results: [mockUser]
|
|
280
342
|
};
|
|
281
343
|
//#endregion
|
|
282
|
-
//#region src/search/index.ts
|
|
283
|
-
var search_default = search_default$1;
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/status/status.ts
|
|
286
|
-
const operation$3 = "/api/v2/custom_statuses";
|
|
287
|
-
const createStatus = (status, options) => exreq({
|
|
288
|
-
operation: operation$3,
|
|
289
|
-
id: options?.id,
|
|
290
|
-
method: options?.method || "post",
|
|
291
|
-
data: { custom_status: status },
|
|
292
|
-
options: {
|
|
293
|
-
...options,
|
|
294
|
-
headers: {
|
|
295
|
-
...options?.headers,
|
|
296
|
-
Authorization: `Basic ${options.token}`
|
|
297
|
-
},
|
|
298
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
const getStatus = (...args) => {
|
|
302
|
-
const [id, options] = parseArgs(args);
|
|
303
|
-
return exreq({
|
|
304
|
-
operation: operation$3,
|
|
305
|
-
id,
|
|
306
|
-
options: {
|
|
307
|
-
...options,
|
|
308
|
-
headers: {
|
|
309
|
-
...options.headers,
|
|
310
|
-
Authorization: `Basic ${options.token}`
|
|
311
|
-
},
|
|
312
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
};
|
|
316
|
-
const updateStatus = (id, status, options) => createStatus(status, {
|
|
317
|
-
method: "put",
|
|
318
|
-
id,
|
|
319
|
-
...options
|
|
320
|
-
});
|
|
321
|
-
var status_default$1 = {
|
|
322
|
-
create: createStatus,
|
|
323
|
-
get: getStatus,
|
|
324
|
-
update: updateStatus
|
|
325
|
-
};
|
|
326
|
-
//#endregion
|
|
327
344
|
//#region src/status/status.mocks.ts
|
|
328
345
|
const mockDefaultStatus = {
|
|
329
346
|
active: true,
|
|
@@ -358,157 +375,6 @@ const mockCustomStatusResponse = {
|
|
|
358
375
|
custom_status: mockCustomStatus
|
|
359
376
|
};
|
|
360
377
|
//#endregion
|
|
361
|
-
//#region src/status/index.ts
|
|
362
|
-
var status_default = { ...status_default$1 };
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region src/tickets/comments.ts
|
|
365
|
-
const operation$2 = "/api/v2/tickets";
|
|
366
|
-
const createComment = (id, comment, options) => exreq({
|
|
367
|
-
operation: operation$2,
|
|
368
|
-
id,
|
|
369
|
-
method: options?.method || "post",
|
|
370
|
-
data: { ticket: { comment: { body: comment } } },
|
|
371
|
-
options: {
|
|
372
|
-
...options,
|
|
373
|
-
headers: {
|
|
374
|
-
...options?.headers,
|
|
375
|
-
Authorization: `Basic ${options.token}`
|
|
376
|
-
},
|
|
377
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
const getComments = (ticket, options) => {
|
|
381
|
-
console.log({ ticket });
|
|
382
|
-
return exreq({
|
|
383
|
-
operation: `${operation$2}/${ticket}/comments`,
|
|
384
|
-
options: {
|
|
385
|
-
...options,
|
|
386
|
-
headers: {
|
|
387
|
-
...options.headers,
|
|
388
|
-
Authorization: `Basic ${options.token}`
|
|
389
|
-
},
|
|
390
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
};
|
|
394
|
-
var comments_default = {
|
|
395
|
-
create: createComment,
|
|
396
|
-
get: getComments
|
|
397
|
-
};
|
|
398
|
-
//#endregion
|
|
399
|
-
//#region src/tickets/fields.ts
|
|
400
|
-
const operation$1 = "/api/v2/ticket_fields";
|
|
401
|
-
const createField = (field, options) => exreq({
|
|
402
|
-
operation: operation$1,
|
|
403
|
-
id: options?.id,
|
|
404
|
-
method: options?.method || "post",
|
|
405
|
-
data: { ticket_field: field },
|
|
406
|
-
options: {
|
|
407
|
-
...options,
|
|
408
|
-
headers: {
|
|
409
|
-
...options?.headers,
|
|
410
|
-
Authorization: `Basic ${options.token}`
|
|
411
|
-
},
|
|
412
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
const getFields = (...args) => {
|
|
416
|
-
const [id, options] = parseArgs(args);
|
|
417
|
-
return exreq({
|
|
418
|
-
operation: operation$1,
|
|
419
|
-
id,
|
|
420
|
-
options: {
|
|
421
|
-
...options,
|
|
422
|
-
headers: {
|
|
423
|
-
...options.headers,
|
|
424
|
-
Authorization: `Basic ${options.token}`
|
|
425
|
-
},
|
|
426
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
};
|
|
430
|
-
const updateField = (id, field, options) => createField(field, {
|
|
431
|
-
method: "put",
|
|
432
|
-
id,
|
|
433
|
-
...options
|
|
434
|
-
});
|
|
435
|
-
const deleteField = (id, options) => exreq({
|
|
436
|
-
operation: operation$1,
|
|
437
|
-
id,
|
|
438
|
-
method: "delete",
|
|
439
|
-
options: {
|
|
440
|
-
...options,
|
|
441
|
-
headers: {
|
|
442
|
-
...options.headers,
|
|
443
|
-
Authorization: `Basic ${options.token}`
|
|
444
|
-
},
|
|
445
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
var fields_default = {
|
|
449
|
-
create: createField,
|
|
450
|
-
get: getFields,
|
|
451
|
-
update: updateField,
|
|
452
|
-
delete: deleteField
|
|
453
|
-
};
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region src/tickets/tickets.ts
|
|
456
|
-
const operation = "/api/v2/tickets";
|
|
457
|
-
const createTicket = (ticket, options) => exreq({
|
|
458
|
-
operation,
|
|
459
|
-
id: options?.id,
|
|
460
|
-
method: options?.method || "post",
|
|
461
|
-
data: { ticket },
|
|
462
|
-
options: {
|
|
463
|
-
...options,
|
|
464
|
-
headers: {
|
|
465
|
-
...options?.headers,
|
|
466
|
-
Authorization: `Basic ${options.token}`
|
|
467
|
-
},
|
|
468
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
const getTickets = (...args) => {
|
|
472
|
-
const [id, options] = parseArgs(args);
|
|
473
|
-
return exreq({
|
|
474
|
-
operation,
|
|
475
|
-
id,
|
|
476
|
-
options: {
|
|
477
|
-
...options,
|
|
478
|
-
params: { include: "custom_statuses" },
|
|
479
|
-
headers: {
|
|
480
|
-
...options.headers,
|
|
481
|
-
Authorization: `Basic ${options.token}`
|
|
482
|
-
},
|
|
483
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
};
|
|
487
|
-
const updateTicket = (id, ticket, options) => createTicket(ticket, {
|
|
488
|
-
method: "put",
|
|
489
|
-
id,
|
|
490
|
-
...options
|
|
491
|
-
});
|
|
492
|
-
const deleteTicket = (id, options) => exreq({
|
|
493
|
-
operation,
|
|
494
|
-
id,
|
|
495
|
-
method: "delete",
|
|
496
|
-
options: {
|
|
497
|
-
...options,
|
|
498
|
-
headers: {
|
|
499
|
-
...options.headers,
|
|
500
|
-
Authorization: `Basic ${options.token}`
|
|
501
|
-
},
|
|
502
|
-
baseURL: setBaseURL("zendesk", appConf, options?.environment)
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
var tickets_default$1 = {
|
|
506
|
-
create: createTicket,
|
|
507
|
-
get: getTickets,
|
|
508
|
-
update: updateTicket,
|
|
509
|
-
delete: deleteTicket
|
|
510
|
-
};
|
|
511
|
-
//#endregion
|
|
512
378
|
//#region src/tickets/comments.mocks.ts
|
|
513
379
|
const mockComment = {
|
|
514
380
|
attachments: [mockAttachment],
|
|
@@ -568,26 +434,17 @@ const mockTicketMetric = {
|
|
|
568
434
|
updated_at: "2011-05-05T10:38:52Z"
|
|
569
435
|
};
|
|
570
436
|
//#endregion
|
|
571
|
-
//#region src/tickets/index.ts
|
|
572
|
-
var tickets_default = {
|
|
573
|
-
...tickets_default$1,
|
|
574
|
-
comments: comments_default,
|
|
575
|
-
fields: fields_default
|
|
576
|
-
};
|
|
577
|
-
//#endregion
|
|
578
|
-
//#region src/utils.ts
|
|
579
|
-
const createToken = (user, password) => Buffer.from(`${user}/token:${password}`).toString("base64");
|
|
580
|
-
function setToken(user, password) {
|
|
581
|
-
const encoded = createToken(user, password);
|
|
582
|
-
axios.defaults.headers.common.Authorization = `Basic ${encoded}`;
|
|
583
|
-
}
|
|
584
|
-
//#endregion
|
|
585
437
|
//#region src/index.ts
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
438
|
+
function createZendeskClient(opts) {
|
|
439
|
+
const rest = createZendeskRestClient(opts);
|
|
440
|
+
return {
|
|
441
|
+
activities: activities(rest),
|
|
442
|
+
comments: comments(rest),
|
|
443
|
+
fields: fields(rest),
|
|
444
|
+
search: search(rest),
|
|
445
|
+
status: status(rest),
|
|
446
|
+
tickets: tickets(rest)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
592
449
|
//#endregion
|
|
593
|
-
export { createToken,
|
|
450
|
+
export { createToken, createZendeskClient, mockActivity, mockActivityResponse, mockAttachment, mockComment, mockCommentResponse, mockCustomField1, mockCustomField2, mockCustomFields, mockCustomStatus, mockCustomStatusResponse, mockCustomStatusesResponse, mockDefaultStatus, mockGroup, mockImage, mockMetadata, mockSearchResponseGroups, mockSearchResponseTickets, mockSearchResponseUsers, mockThumbnail, mockTicket, mockTicketField, mockTicketFieldResponse, mockTicketFieldsResponse, mockTicketMetric, mockTicketResponse, mockTicketsResponse, mockUser, mockVia };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/zendesk-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A TypeScript client for the Zendesk API",
|
|
5
5
|
"homepage": "https://github.com/theholocron/clients/tree/main/packages/zendesk-client#readme",
|
|
6
6
|
"bugs": "https://github.com/theholocron/clients/issues",
|
|
@@ -12,52 +12,51 @@
|
|
|
12
12
|
"license": "GPL-3.0",
|
|
13
13
|
"author": "Newton Koumantzelis",
|
|
14
14
|
"type": "module",
|
|
15
|
-
"main": "./
|
|
15
|
+
"main": "./dist/index.mjs",
|
|
16
16
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"test:watch": "vitest",
|
|
24
|
-
"test:coverage": "vitest run --coverage",
|
|
25
|
-
"typecheck": "tsc --noEmit"
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
}
|
|
26
22
|
},
|
|
27
23
|
"dependencies": {
|
|
28
|
-
"
|
|
24
|
+
"@theholocron/http-client": "^0.1.0"
|
|
29
25
|
},
|
|
30
26
|
"devDependencies": {
|
|
31
27
|
"@types/node": "^22.0.0",
|
|
32
|
-
"@theholocron/eslint-config": "
|
|
33
|
-
"@theholocron/tsconfig": "
|
|
34
|
-
"@theholocron/tsdown-config": "
|
|
35
|
-
"@theholocron/vitest-config": "
|
|
36
|
-
"@vitest/coverage-v8": "
|
|
37
|
-
"@vitest/eslint-plugin": "
|
|
38
|
-
"eslint": "
|
|
39
|
-
"eslint-plugin-n": "
|
|
40
|
-
"globals": "
|
|
41
|
-
"tsdown": "
|
|
42
|
-
"typescript": "
|
|
43
|
-
"vitest": "
|
|
28
|
+
"@theholocron/eslint-config": "^6.0.0",
|
|
29
|
+
"@theholocron/tsconfig": "^6.0.0",
|
|
30
|
+
"@theholocron/tsdown-config": "^6.0.0",
|
|
31
|
+
"@theholocron/vitest-config": "^6.0.0",
|
|
32
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
33
|
+
"@vitest/eslint-plugin": "^1.6.23",
|
|
34
|
+
"eslint": "^10.7.0",
|
|
35
|
+
"eslint-plugin-n": "^18.2.2",
|
|
36
|
+
"globals": "^17.7.0",
|
|
37
|
+
"tsdown": "^0.22.5",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"vitest": "^4.1.10"
|
|
44
40
|
},
|
|
45
41
|
"publishConfig": {
|
|
46
|
-
"access": "public"
|
|
47
|
-
"main": "./dist/index.mjs",
|
|
48
|
-
"types": "./dist/index.d.mts",
|
|
49
|
-
"exports": {
|
|
50
|
-
".": {
|
|
51
|
-
"types": "./dist/index.d.mts",
|
|
52
|
-
"import": "./dist/index.mjs",
|
|
53
|
-
"default": "./dist/index.mjs"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
42
|
+
"access": "public"
|
|
56
43
|
},
|
|
57
44
|
"files": [
|
|
58
45
|
"dist",
|
|
59
46
|
"README.md"
|
|
60
47
|
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=22.0.0"
|
|
50
|
+
},
|
|
61
51
|
"releases": "https://github.com/theholocron/clients/releases",
|
|
62
|
-
"wiki": "https://github.com/theholocron/clients/wiki"
|
|
63
|
-
|
|
52
|
+
"wiki": "https://github.com/theholocron/clients/wiki",
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsdown",
|
|
55
|
+
"lint": "eslint .",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest",
|
|
58
|
+
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"typecheck": "tsc --noEmit"
|
|
60
|
+
},
|
|
61
|
+
"types": "./dist/index.d.mts"
|
|
62
|
+
}
|