@great-detail/support-sdk 0.0.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/package.json +82 -0
- package/src/Action/ListActions.ts +50 -0
- package/src/Authentication/KeyAuthentication.ts +47 -0
- package/src/Authentication/PublicAuthentication.ts +22 -0
- package/src/Authentication/TokenAuthentication.ts +38 -0
- package/src/Authentication/index.ts +12 -0
- package/src/Channel/ListChannels.ts +50 -0
- package/src/Client/index.ts +122 -0
- package/src/Contact/ListContacts.ts +50 -0
- package/src/Conversation/GetConversation.ts +50 -0
- package/src/Conversation/ListConversations.ts +49 -0
- package/src/Label/ListLabels.ts +49 -0
- package/src/Message/ListMessages.ts +52 -0
- package/src/Model/Correction/CreateCorrectionModel.ts +55 -0
- package/src/Model/ListModels.ts +49 -0
- package/src/Model/Response/CreateResponseModel.ts +64 -0
- package/src/Request/RequestFilterable.ts +12 -0
- package/src/Request/RequestStandardHeaders.ts +32 -0
- package/src/Source/ListSources.ts +49 -0
- package/src/cli/actions.ts +31 -0
- package/src/cli/channels.ts +31 -0
- package/src/cli/contacts.ts +31 -0
- package/src/cli/conversations.ts +48 -0
- package/src/cli/index.ts +46 -0
- package/src/cli/labels.ts +31 -0
- package/src/cli/messages.ts +31 -0
- package/src/cli/models.ts +31 -0
- package/src/cli/sources.ts +31 -0
- package/src/cli.ts +13 -0
- package/src/constants/index.ts +31 -0
- package/src/index.ts +15 -0
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@great-detail/support-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "JavaScript SDK for the Great Detail Support System",
|
|
6
|
+
"author": "Great Detail Ltd <info@greatdetail.com>",
|
|
7
|
+
"contributors": [
|
|
8
|
+
"Dom Webber <dom.webber@hotmail.com>",
|
|
9
|
+
"Great Detail Ltd <info@greatdetail.com>"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18"
|
|
14
|
+
},
|
|
15
|
+
"bin": "./dist/cli.js",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"default": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"./cli": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/cli/index.d.ts",
|
|
30
|
+
"default": "./dist/cli/index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/cli/index.d.cts",
|
|
34
|
+
"default": "./dist/cli/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"src"
|
|
41
|
+
],
|
|
42
|
+
"keywords": [
|
|
43
|
+
"SDK"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "npm-run-all tsup",
|
|
47
|
+
"changeset": "changeset",
|
|
48
|
+
"eslint": "eslint .",
|
|
49
|
+
"eslint:dev": "eslint . --fix",
|
|
50
|
+
"lint": "npm-run-all eslint typecheck publint prettier",
|
|
51
|
+
"lint:dev": "npm-run-all eslint:dev typecheck publint prettier:dev",
|
|
52
|
+
"prettier": "prettier --check .",
|
|
53
|
+
"prettier:dev": "prettier --write .",
|
|
54
|
+
"publint": "publint",
|
|
55
|
+
"release": "changeset publish",
|
|
56
|
+
"tsup": "tsup --entry src/index.ts --entry src/cli.ts --format cjs,esm --minify --dts",
|
|
57
|
+
"typecheck": "tsc --noEmit"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"commander": "^12.1.0",
|
|
61
|
+
"cross-fetch": "^4.0.0",
|
|
62
|
+
"ora": "^8.0.1",
|
|
63
|
+
"zod": "^3.23.8"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@changesets/cli": "^2.27.7",
|
|
67
|
+
"@great-detail/eslint-config": "^1.0.4",
|
|
68
|
+
"@great-detail/prettier-config": "^0.2.4",
|
|
69
|
+
"@types/node": "^20.14.12",
|
|
70
|
+
"eslint": "^8.57.0",
|
|
71
|
+
"npm-run-all": "^4.1.5",
|
|
72
|
+
"prettier": "^3.3.3",
|
|
73
|
+
"publint": "^0.2.9",
|
|
74
|
+
"ts-node": "^10.9.2",
|
|
75
|
+
"tsup": "^8.2.3",
|
|
76
|
+
"typescript": "^5.5.4"
|
|
77
|
+
},
|
|
78
|
+
"publishConfig": {
|
|
79
|
+
"access": "public",
|
|
80
|
+
"provenance": false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListActionsRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/actions",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListActionsResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
actions: {
|
|
35
|
+
id: string;
|
|
36
|
+
actionStatus: string;
|
|
37
|
+
object?: unknown;
|
|
38
|
+
result?: unknown;
|
|
39
|
+
startedAt?: string;
|
|
40
|
+
endedAt?: string;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class ListActionsResponse {
|
|
45
|
+
constructor(public response: Response) {}
|
|
46
|
+
|
|
47
|
+
public async result(): Promise<ListResponse> {
|
|
48
|
+
return this.response.json();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { DEFAULT_KEY_AUTHENTICATION_NAME } from "../constants/index.js";
|
|
11
|
+
import Authentication from "./index.js";
|
|
12
|
+
|
|
13
|
+
export interface Options {
|
|
14
|
+
name?: string;
|
|
15
|
+
key?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class KeyAuthentication implements Authentication {
|
|
19
|
+
public static DEFAULT_NAME = DEFAULT_KEY_AUTHENTICATION_NAME;
|
|
20
|
+
|
|
21
|
+
public name: string;
|
|
22
|
+
#key: string;
|
|
23
|
+
|
|
24
|
+
constructor({
|
|
25
|
+
name = process.env.SUPPORT_KEY_NAME ?? KeyAuthentication.DEFAULT_NAME,
|
|
26
|
+
key = process.env.SUPPORT_API_KEY,
|
|
27
|
+
}: Options = {}) {
|
|
28
|
+
if (!key) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"API Key option must be specified when using Key Authentication",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.#key = key;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async filter(request: RequestInit): Promise<RequestInit> {
|
|
39
|
+
return {
|
|
40
|
+
...request,
|
|
41
|
+
headers: {
|
|
42
|
+
...request.headers,
|
|
43
|
+
Authorization: `Basic ${btoa(this.name + ":" + this.#key)}`,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Authentication from "./index.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Public Authentication Configuration.
|
|
14
|
+
* Note: Not all APIs and endpoints will work with this authentication type.
|
|
15
|
+
*
|
|
16
|
+
* @since 1.0.l0
|
|
17
|
+
*/
|
|
18
|
+
export default class PublicAuthentication implements Authentication {
|
|
19
|
+
public async filter(request: RequestInit) {
|
|
20
|
+
return request;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Authentication from "./index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options {
|
|
13
|
+
token?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class TokenAuthentication implements Authentication {
|
|
17
|
+
#token: string;
|
|
18
|
+
|
|
19
|
+
constructor({ token = process.env.SUPPORT_ACCESS_TOKEN }: Options = {}) {
|
|
20
|
+
if (!token) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"Access Token option must be specified when using Token Authentication",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.#token = token;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async filter(request: RequestInit): Promise<RequestInit> {
|
|
30
|
+
return {
|
|
31
|
+
...request,
|
|
32
|
+
headers: {
|
|
33
|
+
...request.headers,
|
|
34
|
+
Authorization: `Bearer ${this.#token}`,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import RequestFilterable from "../Request/RequestFilterable.js";
|
|
11
|
+
|
|
12
|
+
export default interface Authentication extends RequestFilterable {}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListChannelsRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/channels",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListChannelsResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
channels: {
|
|
35
|
+
id: string;
|
|
36
|
+
name?: string;
|
|
37
|
+
channelStatus: "ActiveChannelStatus" | "PotentialChannelStatus";
|
|
38
|
+
source: "twilio-sendgrid" | "meta-whatsapp";
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt?: string;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class ListChannelsResponse {
|
|
45
|
+
constructor(public response: Response) {}
|
|
46
|
+
|
|
47
|
+
public async result(): Promise<ListResponse> {
|
|
48
|
+
return this.response.json();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import ListActionsRequest from "../Action/ListActions.js";
|
|
11
|
+
import Authentication from "../Authentication/index.js";
|
|
12
|
+
import ListChannelsRequest from "../Channel/ListChannels.js";
|
|
13
|
+
import { DEFAULT_SUPPORT_BASE_URL } from "../constants/index.js";
|
|
14
|
+
import ListContactsRequest from "../Contact/ListContacts.js";
|
|
15
|
+
import GetConversationRequest from "../Conversation/GetConversation.js";
|
|
16
|
+
import ListConversationsRequest from "../Conversation/ListConversations.js";
|
|
17
|
+
import ListLabelsRequest from "../Label/ListLabels.js";
|
|
18
|
+
import ListMessagesRequest from "../Message/ListMessages.js";
|
|
19
|
+
import CreateCorrectionModelRequest from "../Model/Correction/CreateCorrectionModel.js";
|
|
20
|
+
import ListModelsRequest from "../Model/ListModels.js";
|
|
21
|
+
import CreateResponseModelRequest from "../Model/Response/CreateResponseModel.js";
|
|
22
|
+
import RequestFilterable from "../Request/RequestFilterable.js";
|
|
23
|
+
import RequestStandardHeaders from "../Request/RequestStandardHeaders.js";
|
|
24
|
+
import ListSourcesRequest from "../Source/ListSources.js";
|
|
25
|
+
|
|
26
|
+
export interface ClientOptions {
|
|
27
|
+
requestFilterables: RequestFilterable[];
|
|
28
|
+
baseURL: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface InputClientOptions {
|
|
32
|
+
baseURL?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SendOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Alternative Fetch Provider.
|
|
38
|
+
* Used to override the default fetch provider and use polyfills or other
|
|
39
|
+
* libraries.
|
|
40
|
+
*
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default class Client {
|
|
47
|
+
public static DEFAULT_BASE_URL = DEFAULT_SUPPORT_BASE_URL;
|
|
48
|
+
|
|
49
|
+
public options: ClientOptions;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
authentication: Authentication,
|
|
53
|
+
options: InputClientOptions = {},
|
|
54
|
+
) {
|
|
55
|
+
this.options = {
|
|
56
|
+
requestFilterables: [new RequestStandardHeaders(), authentication],
|
|
57
|
+
baseURL: process.env.SUPPORT_BASE_URL ?? Client.DEFAULT_BASE_URL,
|
|
58
|
+
...options,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public action = {
|
|
63
|
+
list: new ListActionsRequest(this),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
public channel = {
|
|
67
|
+
list: new ListChannelsRequest(this),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
public contact = {
|
|
71
|
+
list: new ListContactsRequest(this),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
public conversation = {
|
|
75
|
+
get: new GetConversationRequest(this),
|
|
76
|
+
list: new ListConversationsRequest(this),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
public label = {
|
|
80
|
+
list: new ListLabelsRequest(this),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
public message = {
|
|
84
|
+
list: new ListMessagesRequest(this),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
public model = {
|
|
88
|
+
list: new ListModelsRequest(this),
|
|
89
|
+
response: {
|
|
90
|
+
create: new CreateResponseModelRequest(this),
|
|
91
|
+
},
|
|
92
|
+
correction: {
|
|
93
|
+
create: new CreateCorrectionModelRequest(this),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
public source = {
|
|
98
|
+
list: new ListSourcesRequest(this),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
protected async _filterRequest(request: RequestInit): Promise<RequestInit> {
|
|
102
|
+
for (const filterable of this.options.requestFilterables) {
|
|
103
|
+
request = await filterable.filter(request);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return request;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public async send(
|
|
110
|
+
url: string | URL,
|
|
111
|
+
request: RequestInit,
|
|
112
|
+
{ fetch: fetchAlternative = fetch }: SendOptions = {},
|
|
113
|
+
) {
|
|
114
|
+
// See: https://github.com/node-fetch/node-fetch/issues/481#issuecomment-592491825
|
|
115
|
+
return await fetchAlternative(
|
|
116
|
+
new Request(
|
|
117
|
+
new URL(url, this.options.baseURL),
|
|
118
|
+
await this._filterRequest(request),
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListContactsRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/contacts",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListContactsResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
contacts: {
|
|
35
|
+
id: string;
|
|
36
|
+
name?: string;
|
|
37
|
+
emailAddress?: string;
|
|
38
|
+
telephoneNumber?: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt?: string;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class ListContactsResponse {
|
|
45
|
+
constructor(public response: Response) {}
|
|
46
|
+
|
|
47
|
+
public async result(): Promise<ListResponse> {
|
|
48
|
+
return this.response.json();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
id: string;
|
|
14
|
+
request?: RequestInit;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class GetConversationRequest {
|
|
18
|
+
constructor(protected _client: Client) {}
|
|
19
|
+
|
|
20
|
+
public async send({ id, request = {}, ...options }: Options) {
|
|
21
|
+
return this._client
|
|
22
|
+
.send(
|
|
23
|
+
"/v1/conversations/" + encodeURIComponent(id),
|
|
24
|
+
{
|
|
25
|
+
...request,
|
|
26
|
+
method: "GET",
|
|
27
|
+
},
|
|
28
|
+
options,
|
|
29
|
+
)
|
|
30
|
+
.then((response) => new GetConversationResponse(response));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type GetResponse = {
|
|
35
|
+
conversation: {
|
|
36
|
+
id: string;
|
|
37
|
+
hasEnded: boolean;
|
|
38
|
+
accountChannel: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class GetConversationResponse {
|
|
45
|
+
constructor(public response: Response) {}
|
|
46
|
+
|
|
47
|
+
public async result(): Promise<GetResponse> {
|
|
48
|
+
return this.response.json();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListConversationsRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/conversations",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListConversationsResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
conversations: {
|
|
35
|
+
id: string;
|
|
36
|
+
hasEnded: boolean;
|
|
37
|
+
accountChannel: string;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export class ListConversationsResponse {
|
|
44
|
+
constructor(public response: Response) {}
|
|
45
|
+
|
|
46
|
+
public async result(): Promise<ListResponse> {
|
|
47
|
+
return this.response.json();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListLabelsRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/labels",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListLabelsResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
labels: {
|
|
35
|
+
id: string;
|
|
36
|
+
title: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt?: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export class ListLabelsResponse {
|
|
44
|
+
constructor(public response: Response) {}
|
|
45
|
+
|
|
46
|
+
public async result(): Promise<ListResponse> {
|
|
47
|
+
return this.response.json();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListMessagesRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/messages",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListMessagesResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
messages: {
|
|
35
|
+
id: string;
|
|
36
|
+
role: "user" | "assistant";
|
|
37
|
+
messageStatus: string;
|
|
38
|
+
externalIdentifier?: string;
|
|
39
|
+
conversation: string;
|
|
40
|
+
contact: string;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export class ListMessagesResponse {
|
|
47
|
+
constructor(public response: Response) {}
|
|
48
|
+
|
|
49
|
+
public async result(): Promise<ListResponse> {
|
|
50
|
+
return this.response.json();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import Client, { SendOptions } from "../../Client/index.js";
|
|
12
|
+
|
|
13
|
+
export interface Options extends SendOptions {
|
|
14
|
+
id: string;
|
|
15
|
+
body: z.infer<typeof CreateCorrectionModelRequest.SCHEMA>;
|
|
16
|
+
request?: RequestInit;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class CreateCorrectionModelRequest {
|
|
20
|
+
public static SCHEMA = z.object({
|
|
21
|
+
input: z.string().max(65_536),
|
|
22
|
+
original: z.string().max(65_536),
|
|
23
|
+
correction: z.string().max(65_536),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
constructor(protected _client: Client) {}
|
|
27
|
+
|
|
28
|
+
public async send({ id, body, request = {}, ...options }: Options) {
|
|
29
|
+
return this._client
|
|
30
|
+
.send(
|
|
31
|
+
"/v1/models/" + encodeURIComponent(id) + "/correction",
|
|
32
|
+
{
|
|
33
|
+
...request,
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
...request.headers,
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(CreateCorrectionModelRequest.SCHEMA.parse(body)),
|
|
40
|
+
},
|
|
41
|
+
options,
|
|
42
|
+
)
|
|
43
|
+
.then((response) => new CreateCorrectionModelResponse(response));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ListResponse = unknown;
|
|
48
|
+
|
|
49
|
+
export class CreateCorrectionModelResponse {
|
|
50
|
+
constructor(public response: Response) {}
|
|
51
|
+
|
|
52
|
+
public async result(): Promise<ListResponse> {
|
|
53
|
+
return this.response.json();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListModelsRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/models",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListModelsResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
models: {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
url: string;
|
|
38
|
+
icon: string;
|
|
39
|
+
disambiguatingDescription: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export class ListModelsResponse {
|
|
44
|
+
constructor(public response: Response) {}
|
|
45
|
+
|
|
46
|
+
public async result(): Promise<ListResponse> {
|
|
47
|
+
return this.response.json();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import Client, { SendOptions } from "../../Client/index.js";
|
|
12
|
+
|
|
13
|
+
export interface Options extends SendOptions {
|
|
14
|
+
id: string;
|
|
15
|
+
body: z.infer<typeof CreateResponseModelRequest.SCHEMA>;
|
|
16
|
+
request?: RequestInit;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class CreateResponseModelRequest {
|
|
20
|
+
public static SCHEMA = z
|
|
21
|
+
.array(
|
|
22
|
+
z.object({
|
|
23
|
+
role: z.enum(["user", "assistant"]),
|
|
24
|
+
content: z.string().max(65_536).nullable(),
|
|
25
|
+
}),
|
|
26
|
+
)
|
|
27
|
+
.min(1);
|
|
28
|
+
|
|
29
|
+
constructor(protected _client: Client) {}
|
|
30
|
+
|
|
31
|
+
public async send({ id, body, request = {}, ...options }: Options) {
|
|
32
|
+
return this._client
|
|
33
|
+
.send(
|
|
34
|
+
"/v1/models/" + encodeURIComponent(id) + "/response",
|
|
35
|
+
{
|
|
36
|
+
...request,
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: {
|
|
39
|
+
...request.headers,
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify(CreateResponseModelRequest.SCHEMA.parse(body)),
|
|
43
|
+
},
|
|
44
|
+
options,
|
|
45
|
+
)
|
|
46
|
+
.then((response) => new CreateResponseModelResponse(response));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ListResponse = {
|
|
51
|
+
message: string | null;
|
|
52
|
+
debug: {
|
|
53
|
+
duration: string;
|
|
54
|
+
sources: (string | undefined)[];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export class CreateResponseModelResponse {
|
|
59
|
+
constructor(public response: Response) {}
|
|
60
|
+
|
|
61
|
+
public async result(): Promise<ListResponse> {
|
|
62
|
+
return this.response.json();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export default interface RequestFilterable {
|
|
11
|
+
filter(request: RequestInit): Promise<RequestInit>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { STANDARD_HEADERS } from "../constants/index.js";
|
|
11
|
+
import RequestFilterable from "./RequestFilterable.js";
|
|
12
|
+
|
|
13
|
+
export default class RequestStandardHeaders implements RequestFilterable {
|
|
14
|
+
public static STANDARD_HEADERS = STANDARD_HEADERS;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
protected _standardHeaders: Record<
|
|
18
|
+
string,
|
|
19
|
+
string
|
|
20
|
+
> = RequestStandardHeaders.STANDARD_HEADERS,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
public async filter(request: RequestInit) {
|
|
24
|
+
return {
|
|
25
|
+
...request,
|
|
26
|
+
headers: {
|
|
27
|
+
...request.headers,
|
|
28
|
+
...this._standardHeaders,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Client, { SendOptions } from "../Client/index.js";
|
|
11
|
+
|
|
12
|
+
export interface Options extends SendOptions {
|
|
13
|
+
request?: RequestInit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class ListSourcesRequest {
|
|
17
|
+
constructor(protected _client: Client) {}
|
|
18
|
+
|
|
19
|
+
public async send({ request = {}, ...options }: Options = {}) {
|
|
20
|
+
return this._client
|
|
21
|
+
.send(
|
|
22
|
+
"/v1/sources",
|
|
23
|
+
{
|
|
24
|
+
...request,
|
|
25
|
+
method: "GET",
|
|
26
|
+
},
|
|
27
|
+
options,
|
|
28
|
+
)
|
|
29
|
+
.then((response) => new ListSourcesResponse(response));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListResponse = {
|
|
34
|
+
sources: {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
category: string;
|
|
38
|
+
url: string;
|
|
39
|
+
disambiguatingDescription: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export class ListSourcesResponse {
|
|
44
|
+
constructor(public response: Response) {}
|
|
45
|
+
|
|
46
|
+
public async result(): Promise<ListResponse> {
|
|
47
|
+
return this.response.json();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function actions({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("actions").description("Actions");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List actions").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.action.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding actions",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function channels({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("channels").description("Channels");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List channels").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.channel.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding channels",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function contacts({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("contacts").description("Contacts");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List contacts").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.contact.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding contacts",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function conversations({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("conversations").description("Conversations");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("get")
|
|
21
|
+
.description("Find conversation")
|
|
22
|
+
.argument("<conversation>", "Conversation ID")
|
|
23
|
+
.action(async (id) => {
|
|
24
|
+
const result = await oraPromise(
|
|
25
|
+
() => client.conversation.get.send({ id }),
|
|
26
|
+
{
|
|
27
|
+
...ora,
|
|
28
|
+
text: "Finding conversation",
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
console.log(await result.result());
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
command.addCommand(
|
|
37
|
+
new Command("list").description("List conversations").action(async () => {
|
|
38
|
+
const result = await oraPromise(() => client.conversation.list.send(), {
|
|
39
|
+
...ora,
|
|
40
|
+
text: "Finding conversations",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
console.log(await result.result());
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return command;
|
|
48
|
+
}
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import PublicAuthentication from "../Authentication/PublicAuthentication.js";
|
|
12
|
+
import Client from "../Client/index.js";
|
|
13
|
+
import actions from "./actions.js";
|
|
14
|
+
import channels from "./channels.js";
|
|
15
|
+
import contacts from "./contacts.js";
|
|
16
|
+
import conversations from "./conversations.js";
|
|
17
|
+
import labels from "./labels.js";
|
|
18
|
+
import messages from "./messages.js";
|
|
19
|
+
import models from "./models.js";
|
|
20
|
+
import sources from "./sources.js";
|
|
21
|
+
import type { Options as OraOptions } from "ora";
|
|
22
|
+
|
|
23
|
+
export interface Options {
|
|
24
|
+
client: Client;
|
|
25
|
+
ora: OraOptions;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const options: Options = {
|
|
29
|
+
ora: {
|
|
30
|
+
spinner: "simpleDotsScrolling",
|
|
31
|
+
},
|
|
32
|
+
client: new Client(new PublicAuthentication()),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const cli = new Command("gds")
|
|
36
|
+
.description("Great Detail Support System")
|
|
37
|
+
.addCommand(actions(options))
|
|
38
|
+
.addCommand(channels(options))
|
|
39
|
+
.addCommand(contacts(options))
|
|
40
|
+
.addCommand(conversations(options))
|
|
41
|
+
.addCommand(labels(options))
|
|
42
|
+
.addCommand(messages(options))
|
|
43
|
+
.addCommand(models(options))
|
|
44
|
+
.addCommand(sources(options));
|
|
45
|
+
|
|
46
|
+
export default cli;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function labels({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("labels").description("Labels");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List labels").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.label.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding labels",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function messages({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("messages").description("Messages");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List messages").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.message.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding messages",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function models({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("models").description("Models");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List models").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.model.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding models",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { oraPromise } from "ora";
|
|
12
|
+
import type { Options as CommandOptions } from "./index.js";
|
|
13
|
+
|
|
14
|
+
export interface Options extends CommandOptions {}
|
|
15
|
+
|
|
16
|
+
export default function sources({ client, ora }: Options) {
|
|
17
|
+
const command = new Command("sources").description("Sources");
|
|
18
|
+
|
|
19
|
+
command.addCommand(
|
|
20
|
+
new Command("list").description("List sources").action(async () => {
|
|
21
|
+
const result = await oraPromise(() => client.source.list.send(), {
|
|
22
|
+
...ora,
|
|
23
|
+
text: "Finding sources",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(await result.result());
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return command;
|
|
31
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Great Detail Support System.
|
|
5
|
+
*
|
|
6
|
+
* @copyright 2024 Great Detail Ltd
|
|
7
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
8
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
9
|
+
* @see https://greatdetail.com
|
|
10
|
+
*/
|
|
11
|
+
import cli from "./cli/index.js";
|
|
12
|
+
|
|
13
|
+
cli.parseAsync(process.argv);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Support System API Base URL.
|
|
12
|
+
*
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_SUPPORT_BASE_URL = "https://api.support.greatdetail.com";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Standard HTTP Request Headers.
|
|
19
|
+
*
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export const STANDARD_HEADERS = {
|
|
23
|
+
"X-Powered-By": "GDSupport/JavaScript",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Default Basic Authentication Username for Key Authentication.
|
|
28
|
+
*
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_KEY_AUTHENTICATION_NAME = "api-key";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Great Detail Support System.
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Great Detail Ltd
|
|
5
|
+
* @author Great Detail Ltd <info@greatdetail.com>
|
|
6
|
+
* @author Dom Webber <dom.webber@greatdetail.com>
|
|
7
|
+
* @see https://greatdetail.com
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { DEFAULT_SUPPORT_BASE_URL } from "./constants/index.js";
|
|
11
|
+
export { default as KeyAuthentication } from "./Authentication/KeyAuthentication.js";
|
|
12
|
+
export { default as TokenAuthentication } from "./Authentication/TokenAuthentication.js";
|
|
13
|
+
export { default as PublicAuthentication } from "./Authentication/PublicAuthentication.js";
|
|
14
|
+
export { type default as RequestFilterable } from "./Request/RequestFilterable.js";
|
|
15
|
+
export { default, default as Client } from "./Client/index.js";
|