@great-detail/support-sdk 0.1.5 → 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/dist/chunk-IXJNWCJL.js +1 -0
- package/dist/{chunk-PTKKI5PQ.js → chunk-SRYAEALQ.js} +1 -1
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.d.cts +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/{index-Dm8jdpkD.d.cts → index-Dj17QRj0.d.cts} +141 -111
- package/dist/{index-Dm8jdpkD.d.ts → index-Dj17QRj0.d.ts} +141 -111
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +63 -6
- package/dist/index.d.ts +63 -6
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/src/Action/ListActions.ts +8 -12
- package/src/Authentication/KeyAuthentication.ts +10 -11
- package/src/Authentication/PublicAuthentication.ts +8 -2
- package/src/Authentication/TokenAuthentication.ts +9 -7
- package/src/Channel/ListChannels.ts +8 -12
- package/src/Client/index.ts +6 -5
- package/src/Contact/ContactVCF/GetContactVCF.ts +24 -5
- package/src/Contact/CreateContact.ts +12 -16
- package/src/Contact/GetContact.ts +8 -12
- package/src/Contact/ListContacts.ts +8 -12
- package/src/Contact/ListLabelContacts.ts +8 -12
- package/src/Contact/UpdateContact.ts +12 -16
- package/src/Conversation/GetConversation.ts +8 -12
- package/src/Conversation/ListConversations.ts +8 -12
- package/src/Conversation/ListLabelConversations.ts +8 -12
- package/src/Conversation/UpdateConversation.ts +12 -16
- package/src/Error/AuthError.ts +12 -0
- package/src/Error/AuthenticationError.ts +16 -0
- package/src/Error/AuthorizationError.ts +16 -0
- package/src/Error/LogicError.ts +20 -0
- package/src/Error/NetworkError.ts +12 -0
- package/src/Error/SupportError.ts +10 -0
- package/src/Error/ValidationError.ts +16 -0
- package/src/Error/index.ts +11 -0
- package/src/Label/CreateLabel.ts +12 -16
- package/src/Label/DeleteLabel.ts +8 -12
- package/src/Label/GetLabel.ts +8 -12
- package/src/Label/ListLabels.ts +8 -12
- package/src/Label/UpdateLabel.ts +12 -16
- package/src/Message/ListConversationMessages.ts +8 -12
- package/src/Message/ListMessages.ts +8 -12
- package/src/Model/Correction/CreateCorrectionModel.ts +12 -16
- package/src/Model/GetModel.ts +8 -12
- package/src/Model/ListModels.ts +8 -12
- package/src/Model/Response/CreateResponseModel.ts +12 -16
- package/src/Request/RequestFilterable.ts +5 -1
- package/src/Request/RequestStandardHeaders.ts +6 -6
- package/src/Source/GetSource.ts +8 -12
- package/src/Source/ListSources.ts +8 -12
- package/src/Transport/FetchTransport.ts +112 -0
- package/src/Transport/index.ts +2 -44
- package/src/__tests__/Client/Client.test.ts +38 -0
- package/src/constants/environment.ts +36 -0
- package/src/constants/index.ts +0 -21
- package/src/index.ts +4 -4
- package/dist/chunk-2LKRKCHH.js +0 -1
- package/src/__tests__/Authentication/KeyAuthentication.test.ts +0 -79
- package/src/__tests__/Authentication/TokenAuthentication.test.ts +0 -79
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { z } from "zod";
|
|
11
|
-
import
|
|
11
|
+
import FetchTransport from "../../Transport/FetchTransport.js";
|
|
12
12
|
|
|
13
|
-
export interface Options
|
|
13
|
+
export interface Options {
|
|
14
14
|
id: string;
|
|
15
15
|
body: z.infer<typeof CreateResponseModel.SCHEMA>;
|
|
16
16
|
request?: RequestInit;
|
|
@@ -26,23 +26,19 @@ export default class CreateResponseModel {
|
|
|
26
26
|
)
|
|
27
27
|
.min(1);
|
|
28
28
|
|
|
29
|
-
constructor(protected _transport:
|
|
29
|
+
constructor(protected _transport: FetchTransport) {}
|
|
30
30
|
|
|
31
|
-
public async send({ id, body, request = {}
|
|
31
|
+
public async send({ id, body, request = {} }: Options) {
|
|
32
32
|
return this._transport
|
|
33
|
-
.send(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...request.headers,
|
|
40
|
-
"Content-Type": "application/json",
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify(CreateResponseModel.SCHEMA.parse(body)),
|
|
33
|
+
.send("v1/models/" + encodeURIComponent(id) + "/response", {
|
|
34
|
+
...request,
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
...request.headers,
|
|
38
|
+
"Content-Type": "application/json",
|
|
43
39
|
},
|
|
44
|
-
|
|
45
|
-
)
|
|
40
|
+
body: JSON.stringify(CreateResponseModel.SCHEMA.parse(body)),
|
|
41
|
+
})
|
|
46
42
|
.then((response) => new CreateResponseModelResponse(response));
|
|
47
43
|
}
|
|
48
44
|
}
|
|
@@ -8,5 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export default interface RequestFilterable {
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
filter(...options: unknown[]): Promise<{ headers: Record<string, string> }>;
|
|
15
|
+
getHeaders(): Record<string, string>;
|
|
12
16
|
}
|
|
@@ -20,13 +20,13 @@ export default class RequestStandardHeaders implements RequestFilterable {
|
|
|
20
20
|
> = RequestStandardHeaders.STANDARD_HEADERS,
|
|
21
21
|
) {}
|
|
22
22
|
|
|
23
|
-
public async filter(
|
|
23
|
+
public async filter() {
|
|
24
24
|
return {
|
|
25
|
-
|
|
26
|
-
headers: {
|
|
27
|
-
...request.headers,
|
|
28
|
-
...this._standardHeaders,
|
|
29
|
-
},
|
|
25
|
+
headers: this.getHeaders(),
|
|
30
26
|
};
|
|
31
27
|
}
|
|
28
|
+
|
|
29
|
+
public getHeaders() {
|
|
30
|
+
return this._standardHeaders;
|
|
31
|
+
}
|
|
32
32
|
}
|
package/src/Source/GetSource.ts
CHANGED
|
@@ -7,26 +7,22 @@
|
|
|
7
7
|
* @see https://greatdetail.com
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import FetchTransport from "../Transport/FetchTransport.js";
|
|
11
11
|
|
|
12
|
-
export interface Options
|
|
12
|
+
export interface Options {
|
|
13
13
|
id: string;
|
|
14
14
|
request?: RequestInit;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export default class GetSource {
|
|
18
|
-
constructor(protected _transport:
|
|
18
|
+
constructor(protected _transport: FetchTransport) {}
|
|
19
19
|
|
|
20
|
-
public async send({ id, request = {}
|
|
20
|
+
public async send({ id, request = {} }: Options) {
|
|
21
21
|
return this._transport
|
|
22
|
-
.send(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
method: "GET",
|
|
27
|
-
},
|
|
28
|
-
options,
|
|
29
|
-
)
|
|
22
|
+
.send("v1/sources/" + encodeURIComponent(id), {
|
|
23
|
+
...request,
|
|
24
|
+
method: "GET",
|
|
25
|
+
})
|
|
30
26
|
.then((response) => new GetSourceResponse(response));
|
|
31
27
|
}
|
|
32
28
|
}
|
|
@@ -7,25 +7,21 @@
|
|
|
7
7
|
* @see https://greatdetail.com
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import FetchTransport from "../Transport/FetchTransport.js";
|
|
11
11
|
|
|
12
|
-
export interface Options
|
|
12
|
+
export interface Options {
|
|
13
13
|
request?: RequestInit;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export default class ListSources {
|
|
17
|
-
constructor(protected _transport:
|
|
17
|
+
constructor(protected _transport: FetchTransport) {}
|
|
18
18
|
|
|
19
|
-
public async send({ request = {}
|
|
19
|
+
public async send({ request = {} }: Options = {}) {
|
|
20
20
|
return this._transport
|
|
21
|
-
.send(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
method: "GET",
|
|
26
|
-
},
|
|
27
|
-
options,
|
|
28
|
-
)
|
|
21
|
+
.send("v1/sources", {
|
|
22
|
+
...request,
|
|
23
|
+
method: "GET",
|
|
24
|
+
})
|
|
29
25
|
.then((response) => new ListSourcesResponse(response));
|
|
30
26
|
}
|
|
31
27
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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 isNetworkError from "is-network-error";
|
|
11
|
+
import AuthenticationError from "../Error/AuthenticationError.js";
|
|
12
|
+
import AuthorizationError from "../Error/AuthorizationError.js";
|
|
13
|
+
import LogicError from "../Error/LogicError.js";
|
|
14
|
+
import NetworkError from "../Error/NetworkError.js";
|
|
15
|
+
import ValidationError from "../Error/ValidationError.js";
|
|
16
|
+
import Transport, { Options as TransportOptions } from "./index.js";
|
|
17
|
+
|
|
18
|
+
export interface InputOptions extends TransportOptions {
|
|
19
|
+
baseURL: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Alternative Fetch Provider.
|
|
23
|
+
* Used to override the default fetch provider and use polyfills or other
|
|
24
|
+
* libraries.
|
|
25
|
+
*
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
fetch?: typeof fetch;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Options extends TransportOptions {
|
|
32
|
+
baseURL: string;
|
|
33
|
+
fetch: typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class FetchTransport implements Transport {
|
|
37
|
+
public options: Options;
|
|
38
|
+
|
|
39
|
+
constructor({
|
|
40
|
+
baseURL,
|
|
41
|
+
fetch: fetchAlternative = fetch,
|
|
42
|
+
...options
|
|
43
|
+
}: InputOptions) {
|
|
44
|
+
this.options = {
|
|
45
|
+
...options,
|
|
46
|
+
fetch: fetchAlternative,
|
|
47
|
+
baseURL,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public getURL(url: string): string {
|
|
52
|
+
return new URL(url, this.options.baseURL).toString();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public getRequest(url: string, request: RequestInit): Request {
|
|
56
|
+
// Merge headers
|
|
57
|
+
request.headers = new Headers(request.headers);
|
|
58
|
+
for (const filterable of this.options.requestFilterables) {
|
|
59
|
+
const filterableHeaders = filterable.getHeaders();
|
|
60
|
+
for (const [headerName, headerValue] of Object.entries(
|
|
61
|
+
filterableHeaders,
|
|
62
|
+
)) {
|
|
63
|
+
request.headers.set(headerName, headerValue);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return new Request(this.getURL(url), request);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async send(url: string, request: RequestInit) {
|
|
71
|
+
// See: https://github.com/node-fetch/node-fetch/issues/481#issuecomment-592491825
|
|
72
|
+
return await this.options
|
|
73
|
+
.fetch(this.getRequest(url, request))
|
|
74
|
+
.then((response) => {
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const code = response.status;
|
|
77
|
+
console.error(JSON.stringify(response));
|
|
78
|
+
|
|
79
|
+
switch (code) {
|
|
80
|
+
case 400: {
|
|
81
|
+
throw ValidationError.badRequest();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
case 401: {
|
|
85
|
+
throw AuthenticationError.unauthenticated();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
case 403: {
|
|
89
|
+
throw AuthorizationError.forbidden();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case 404: {
|
|
93
|
+
throw LogicError.notFound(url);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
case 405: {
|
|
97
|
+
throw LogicError.forbiddenMethod(url, request.method ?? "GET");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return response;
|
|
103
|
+
})
|
|
104
|
+
.catch((error) => {
|
|
105
|
+
if (isNetworkError(error)) {
|
|
106
|
+
throw new NetworkError("A network error occurred", { cause: error });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
throw error;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
package/src/Transport/index.ts
CHANGED
|
@@ -11,50 +11,8 @@ import RequestFilterable from "../Request/RequestFilterable.js";
|
|
|
11
11
|
|
|
12
12
|
export interface Options {
|
|
13
13
|
requestFilterables: RequestFilterable[];
|
|
14
|
-
baseURL: string;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
* Alternative Fetch Provider.
|
|
20
|
-
* Used to override the default fetch provider and use polyfills or other
|
|
21
|
-
* libraries.
|
|
22
|
-
*
|
|
23
|
-
* @since 1.0.0
|
|
24
|
-
*/
|
|
25
|
-
fetch?: typeof fetch;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default class Transport {
|
|
29
|
-
public options: Options;
|
|
30
|
-
|
|
31
|
-
constructor({ baseURL, ...options }: Options) {
|
|
32
|
-
this.options = {
|
|
33
|
-
...options,
|
|
34
|
-
baseURL,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected async _filterRequest(request: RequestInit): Promise<RequestInit> {
|
|
39
|
-
for (const filterable of this.options.requestFilterables) {
|
|
40
|
-
request = await filterable.filter(request);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return request;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public getURL(url: string | URL): URL {
|
|
47
|
-
return new URL(url, this.options.baseURL);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async send(
|
|
51
|
-
url: string | URL,
|
|
52
|
-
request: RequestInit,
|
|
53
|
-
{ fetch: fetchAlternative = fetch }: SendOptions = {},
|
|
54
|
-
) {
|
|
55
|
-
// See: https://github.com/node-fetch/node-fetch/issues/481#issuecomment-592491825
|
|
56
|
-
return await fetchAlternative(
|
|
57
|
-
new Request(this.getURL(url), await this._filterRequest(request)),
|
|
58
|
-
);
|
|
59
|
-
}
|
|
16
|
+
export default interface Transport {
|
|
17
|
+
getURL(url: string): string;
|
|
60
18
|
}
|
|
@@ -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 { describe, expect, test } from "@jest/globals";
|
|
11
|
+
import Client from "../../Client/index.js";
|
|
12
|
+
import { DEFAULT_SUPPORT_BASE_URL } from "../../constants/index.js";
|
|
13
|
+
|
|
14
|
+
describe("Client", () => {
|
|
15
|
+
describe("Determining Base URL", () => {
|
|
16
|
+
test("When a base URL is set via environment variables, it should be used as the default base URL", () => {
|
|
17
|
+
// Arrange
|
|
18
|
+
process.env.SUPPORT_BASE_URL = "https://example.com";
|
|
19
|
+
|
|
20
|
+
// Act
|
|
21
|
+
const baseURL = Client.getBaseURL();
|
|
22
|
+
|
|
23
|
+
// Assert
|
|
24
|
+
expect(baseURL).toBe(process.env.SUPPORT_BASE_URL);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("When a base URL is not set via environment, the default should be assumed", () => {
|
|
28
|
+
// Arrange
|
|
29
|
+
process.env = { SUPPORT_BASE_URL: undefined };
|
|
30
|
+
|
|
31
|
+
// Act
|
|
32
|
+
const baseURL = Client.getBaseURL();
|
|
33
|
+
|
|
34
|
+
// Assert
|
|
35
|
+
expect(baseURL).toBe(DEFAULT_SUPPORT_BASE_URL);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
* The Token-Authentication Environment Variable Name.
|
|
12
|
+
*
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export const TOKEN_ENV_VAR = "SUPPORT_ACCESS_TOKEN";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The API-Key Authentication Environment Variable Name.
|
|
19
|
+
*
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export const KEY_ENV_VAR = "SUPPORT_API_KEY";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The API-Key Authentication Username Environment Variable Name.
|
|
26
|
+
*
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
*/
|
|
29
|
+
export const USER_ENV_VAR = "SUPPORT_KEY_NAME";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The Base URL Environment Variable Name.
|
|
33
|
+
*
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export const BASE_URL_ENV_VAR = "SUPPORT_BASE_URL";
|
package/src/constants/index.ts
CHANGED
|
@@ -29,24 +29,3 @@ export const STANDARD_HEADERS = {
|
|
|
29
29
|
* @since 1.0.0
|
|
30
30
|
*/
|
|
31
31
|
export const DEFAULT_KEY_AUTHENTICATION_NAME = "api-key";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The Token-Authentication Environment Variable Name.
|
|
35
|
-
*
|
|
36
|
-
* @since 1.0.0
|
|
37
|
-
*/
|
|
38
|
-
export const TOKEN_ENV_VAR = "SUPPORT_ACCESS_TOKEN";
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The API-Key Authentication Environment Variable Name.
|
|
42
|
-
*
|
|
43
|
-
* @since 1.0.0
|
|
44
|
-
*/
|
|
45
|
-
export const KEY_ENV_VAR = "SUPPORT_API_KEY";
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The API-Key Authentication Username Environment Variable Name.
|
|
49
|
-
*
|
|
50
|
-
* @since 1.0.0
|
|
51
|
-
*/
|
|
52
|
-
export const USER_ENV_VAR = "SUPPORT_KEY_NAME";
|
package/src/index.ts
CHANGED
|
@@ -12,12 +12,12 @@ export { DEFAULT_SUPPORT_BASE_URL } from "./constants/index.js";
|
|
|
12
12
|
// Client
|
|
13
13
|
export { default, default as Client, type Options } from "./Client/index.js";
|
|
14
14
|
|
|
15
|
+
// Errors
|
|
16
|
+
export * as Error from "./Error/index.js";
|
|
17
|
+
|
|
15
18
|
// Transport & Filtering
|
|
16
19
|
export { type default as RequestFilterable } from "./Request/RequestFilterable.js";
|
|
17
|
-
export {
|
|
18
|
-
type Options as TransportOptions,
|
|
19
|
-
type SendOptions as TransportSendOptions,
|
|
20
|
-
} from "./Transport/index.js";
|
|
20
|
+
export { type Options as TransportOptions } from "./Transport/index.js";
|
|
21
21
|
|
|
22
22
|
// Authentication
|
|
23
23
|
export { default as KeyAuthentication } from "./Authentication/KeyAuthentication.js";
|
package/dist/chunk-2LKRKCHH.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var ut="https://api.support.greatdetail.com",lt={"X-Powered-By":"GDSupport/JavaScript"},gt="api-key",ht="SUPPORT_ACCESS_TOKEN",bt="SUPPORT_API_KEY",yt="SUPPORT_KEY_NAME";var i=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/actions",{...t,method:"GET"},s).then(n=>new M(n))}},M=class{constructor(t){this.response=t}async result(){return this.response.json()}};var p=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/channels",{...t,method:"GET"},s).then(n=>new D(n))}},D=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as a}from"zod";var c=class e{constructor(t){this._transport=t}static SCHEMA=a.object({name:a.string(),account:a.string(),emailAddress:a.string().email().optional(),telephoneNumber:a.string().optional()});async send({body:t,request:s={},...n}){return this._transport.send("v1/contacts",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(t))},n).then(r=>new G(r))}},G=class{constructor(t){this.response=t}async result(){return this.response.json()}};var d=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...s,method:"GET"},n).then(r=>new z(r))}},z=class{constructor(t){this.response=t}async result(){return this.response.json()}};var u=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/contacts",{...t,method:"GET"},s).then(n=>new F(n))}},F=class{constructor(t){this.response=t}async result(){return this.response.json()}};var l=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/contacts",{...s,method:"GET"},n).then(r=>new B(r))}},B=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as L}from"zod";var m=class e{constructor(t){this._transport=t}static SCHEMA=L.object({name:L.string().optional(),emailAddress:L.string().email().optional(),telephoneNumber:L.string().optional()});async send({id:t,body:s,request:n={},...r}){return this._transport.send("v1/contacts/"+encodeURIComponent(t),{...n,method:"PATCH",headers:{...n.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(s))},r).then(o=>new J(o))}},J=class{constructor(t){this.response=t}async result(){return this.response.json()}};var g=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...s,method:"GET"},n).then(r=>new K(r))}},K=class{constructor(t){this.response=t}async result(){return this.response.json()}};var h=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/conversations",{...t,method:"GET"},s).then(n=>new V(n))}},V=class{constructor(t){this.response=t}async result(){return this.response.json()}};var b=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/labels/"+encodeURIComponent(t)+"/conversations",{...s,method:"GET"},n).then(r=>new Y(r))}},Y=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as mt}from"zod";var y=class e{constructor(t){this._transport=t}static SCHEMA=mt.object({hasEnded:mt.boolean()});async send({id:t,body:s,request:n={},...r}){return this._transport.send("v1/conversations/"+encodeURIComponent(t),{...n,method:"POST",headers:{...n.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(s))},r).then(o=>new k(o))}},k=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as j}from"zod";var f=class e{constructor(t){this._transport=t}static SCHEMA=j.object({title:j.string(),description:j.string().optional(),account:j.string()});async send({body:t,request:s={},...n}){return this._transport.send("v1/labels",{...s,method:"POST",headers:{...s.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(t))},n).then(r=>new W(r))}},W=class{constructor(t){this.response=t}async result(){return this.response.json()}};var R=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...s,method:"DELETE"},n).then(r=>new X(r))}},X=class{constructor(t){this.response=t}async result(){return this.response.json()}};var x=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...s,method:"GET"},n).then(r=>new Q(r))}},Q=class{constructor(t){this.response=t}async result(){return this.response.json()}};var S=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/labels",{...t,method:"GET"},s).then(n=>new Z(n))}},Z=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as $}from"zod";var O=class e{constructor(t){this._transport=t}static SCHEMA=$.object({title:$.string().optional(),description:$.string().optional()});async send({id:t,body:s,request:n={},...r}){return this._transport.send("v1/labels/"+encodeURIComponent(t),{...n,method:"PATCH",headers:{...n.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(s))},r).then(o=>new tt(o))}},tt=class{constructor(t){this.response=t}async result(){return this.response.json()}};var A=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/conversations/"+encodeURIComponent(t)+"/messages",{...s,method:"GET"},n).then(r=>new et(r))}},et=class{constructor(t){this.response=t}async result(){return this.response.json()}};var _=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/messages",{...t,method:"GET"},s).then(n=>new st(n))}},st=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as H}from"zod";var T=class e{constructor(t){this._transport=t}static SCHEMA=H.object({input:H.string().max(65536),original:H.string().max(65536),correction:H.string().max(65536)});async send({id:t,body:s,request:n={},...r}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/correction",{...n,method:"POST",headers:{...n.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(s))},r).then(o=>new nt(o))}},nt=class{constructor(t){this.response=t}async result(){return this.response.json()}};var C=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/models/"+encodeURIComponent(t),{...s,method:"GET"},n).then(r=>new rt(r))}},rt=class{constructor(t){this.response=t}async result(){return this.response.json()}};var P=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/models",{...t,method:"GET"},s).then(n=>new ot(n))}},ot=class{constructor(t){this.response=t}async result(){return this.response.json()}};import{z as N}from"zod";var E=class e{constructor(t){this._transport=t}static SCHEMA=N.array(N.object({role:N.enum(["user","assistant"]),content:N.string().max(65536).nullable()})).min(1);async send({id:t,body:s,request:n={},...r}){return this._transport.send("v1/models/"+encodeURIComponent(t)+"/response",{...n,method:"POST",headers:{...n.headers,"Content-Type":"application/json"},body:JSON.stringify(e.SCHEMA.parse(s))},r).then(o=>new it(o))}},it=class{constructor(t){this.response=t}async result(){return this.response.json()}};var v=class{constructor(t){this._transport=t}async send({id:t,request:s={},...n}){return this._transport.send("v1/sources/"+encodeURIComponent(t),{...s,method:"GET"},n).then(r=>new pt(r))}},pt=class{constructor(t){this.response=t}async result(){return this.response.json()}};var w=class{constructor(t){this._transport=t}async send({request:t={},...s}={}){return this._transport.send("v1/sources",{...t,method:"GET"},s).then(n=>new at(n))}},at=class{constructor(t){this.response=t}async result(){return this.response.json()}};var U=class{options;constructor({baseURL:t,...s}){this.options={...s,baseURL:t}}async _filterRequest(t){for(let s of this.options.requestFilterables)t=await s.filter(t);return t}getURL(t){return new URL(t,this.options.baseURL)}async send(t,s,{fetch:n=fetch}={}){return await n(new Request(this.getURL(t),await this._filterRequest(s)))}};var q=class{constructor(t){this._transport=t}async send({id:t}){return this._transport.getURL("v1/contacts/"+encodeURIComponent(t)+"/vcf")}};var I=class e{constructor(t=e.STANDARD_HEADERS){this._standardHeaders=t}static STANDARD_HEADERS=lt;async filter(t){return{...t,headers:{...t.headers,...this._standardHeaders}}}};var ct=class e{static DEFAULT_BASE_URL=ut;_transport;constructor(t,{baseURL:s,...n}={}){this._transport=new U({requestFilterables:[new I,t],...n,baseURL:s?.toString()??e.getBaseURL()})}static getBaseURL(){return process.env.SUPPORT_BASE_URL??this.DEFAULT_BASE_URL}get action(){return{list:new i(this._transport)}}get channel(){return{list:new p(this._transport)}}get contact(){return{get:new d(this._transport),list:new u(this._transport),update:new m(this._transport),create:new c(this._transport),vcf:{getURL:new q(this._transport)}}}get conversation(){return{get:new g(this._transport),list:new h(this._transport),update:new y(this._transport),message:{list:new A(this._transport)}}}get label(){return{create:new f(this._transport),get:new x(this._transport),list:new S(this._transport),update:new O(this._transport),delete:new R(this._transport),contact:{list:new l(this._transport)},conversation:{list:new b(this._transport)}}}get message(){return{list:new _(this._transport)}}get model(){return{get:new C(this._transport),list:new P(this._transport),response:{create:new E(this._transport)},correction:{create:new T(this._transport)}}}get source(){return{get:new v(this._transport),list:new w(this._transport)}}};var dt=class{async filter(t){return t}};export{ut as a,gt as b,ht as c,bt as d,yt as e,ct as f,dt as g};
|
|
@@ -1,79 +0,0 @@
|
|
|
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 { describe, expect, test } from "@jest/globals";
|
|
11
|
-
import KeyAuthentication from "../../Authentication/KeyAuthentication.js";
|
|
12
|
-
|
|
13
|
-
describe("KeyAuthentication", () => {
|
|
14
|
-
describe("Authentication application via filtering", () => {
|
|
15
|
-
test("When an api key is sourced from environment variables, it should be added in request headers", async () => {
|
|
16
|
-
// Arrange
|
|
17
|
-
const key = "example-api-key";
|
|
18
|
-
process.env.SUPPORT_API_KEY = key;
|
|
19
|
-
const auth = new KeyAuthentication();
|
|
20
|
-
const init = {
|
|
21
|
-
headers: {
|
|
22
|
-
// Ensure that existing, non-colliding, headers remain
|
|
23
|
-
"X-Trace-ID": "example",
|
|
24
|
-
|
|
25
|
-
// Ensure that existing, colliding, headers are overwritten
|
|
26
|
-
Authorization: "Basic ZXhhbXBsZTpleGFtcGxl", // example:example
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Act
|
|
31
|
-
const request = await auth.filter(init);
|
|
32
|
-
|
|
33
|
-
// Assert
|
|
34
|
-
expect(request).toHaveProperty("headers");
|
|
35
|
-
expect(request.headers).toHaveProperty(
|
|
36
|
-
"Authorization",
|
|
37
|
-
"Basic YXBpLWtleTpleGFtcGxlLWFwaS1rZXk=",
|
|
38
|
-
);
|
|
39
|
-
expect(request.headers).toHaveProperty("X-Trace-ID", "example");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("When an api key is sourced directly, it should be added in request headers", async () => {
|
|
43
|
-
// Arrange
|
|
44
|
-
const key = "example-api-key";
|
|
45
|
-
const auth = new KeyAuthentication({ key });
|
|
46
|
-
const init = {
|
|
47
|
-
headers: {
|
|
48
|
-
// Ensure that existing, non-colliding, headers remain
|
|
49
|
-
"X-Trace-ID": "example",
|
|
50
|
-
|
|
51
|
-
// Ensure that existing, colliding, headers are overwritten
|
|
52
|
-
Authorization: "Basic ZXhhbXBsZTpleGFtcGxl", // example:example
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Act
|
|
57
|
-
const request = await auth.filter(init);
|
|
58
|
-
|
|
59
|
-
// Assert
|
|
60
|
-
expect(request).toHaveProperty("headers");
|
|
61
|
-
expect(request.headers).toHaveProperty(
|
|
62
|
-
"Authorization",
|
|
63
|
-
"Basic YXBpLWtleTpleGFtcGxlLWFwaS1rZXk=",
|
|
64
|
-
);
|
|
65
|
-
expect(request.headers).toHaveProperty("X-Trace-ID", "example");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("When no api key can be found, the constructor should throw", async () => {
|
|
69
|
-
// Arrange
|
|
70
|
-
process.env = {};
|
|
71
|
-
|
|
72
|
-
// Act
|
|
73
|
-
const auth = () => new KeyAuthentication(); // eslint-disable-line unicorn/consistent-function-scoping
|
|
74
|
-
|
|
75
|
-
// Assert
|
|
76
|
-
expect(auth).toThrow();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
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 { describe, expect, test } from "@jest/globals";
|
|
11
|
-
import TokenAuthentication from "../../Authentication/TokenAuthentication.js";
|
|
12
|
-
|
|
13
|
-
describe("TokenAuthentication", () => {
|
|
14
|
-
describe("Authentication application via filtering", () => {
|
|
15
|
-
test("When a token is sourced from environment variables, it should be added in request headers", async () => {
|
|
16
|
-
// Arrange
|
|
17
|
-
const token = "example-access-token";
|
|
18
|
-
process.env.SUPPORT_ACCESS_TOKEN = token;
|
|
19
|
-
const auth = new TokenAuthentication();
|
|
20
|
-
const init = {
|
|
21
|
-
headers: {
|
|
22
|
-
// Ensure that existing, non-colliding, headers remain
|
|
23
|
-
"X-Trace-ID": "example",
|
|
24
|
-
|
|
25
|
-
// Ensure that existing, colliding, headers are overwritten
|
|
26
|
-
Authorization: "Basic ZXhhbXBsZTpleGFtcGxl", // example:example
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Act
|
|
31
|
-
const request = await auth.filter(init);
|
|
32
|
-
|
|
33
|
-
// Assert
|
|
34
|
-
expect(request).toHaveProperty("headers");
|
|
35
|
-
expect(request.headers).toHaveProperty(
|
|
36
|
-
"Authorization",
|
|
37
|
-
"Bearer " + token,
|
|
38
|
-
);
|
|
39
|
-
expect(request.headers).toHaveProperty("X-Trace-ID", "example");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("When a token is sourced directly, it should be added in request headers", async () => {
|
|
43
|
-
// Arrange
|
|
44
|
-
const token = "example-access-token";
|
|
45
|
-
const auth = new TokenAuthentication({ token });
|
|
46
|
-
const init = {
|
|
47
|
-
headers: {
|
|
48
|
-
// Ensure that existing, non-colliding, headers remain
|
|
49
|
-
"X-Trace-ID": "example",
|
|
50
|
-
|
|
51
|
-
// Ensure that existing, colliding, headers are overwritten
|
|
52
|
-
Authorization: "Basic ZXhhbXBsZTpleGFtcGxl", // example:example
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Act
|
|
57
|
-
const request = await auth.filter(init);
|
|
58
|
-
|
|
59
|
-
// Assert
|
|
60
|
-
expect(request).toHaveProperty("headers");
|
|
61
|
-
expect(request.headers).toHaveProperty(
|
|
62
|
-
"Authorization",
|
|
63
|
-
"Bearer " + token,
|
|
64
|
-
);
|
|
65
|
-
expect(request.headers).toHaveProperty("X-Trace-ID", "example");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("When no token can be found, the constructor should throw", async () => {
|
|
69
|
-
// Arrange
|
|
70
|
-
process.env = {};
|
|
71
|
-
|
|
72
|
-
// Act
|
|
73
|
-
const auth = () => new TokenAuthentication(); // eslint-disable-line unicorn/consistent-function-scoping
|
|
74
|
-
|
|
75
|
-
// Assert
|
|
76
|
-
expect(auth).toThrow();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|