@great-detail/support-sdk 0.1.6 → 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-GQPMRQEH.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-fAkhYzqW.d.cts → index-Dj17QRj0.d.cts} +135 -112
- package/dist/{index-fAkhYzqW.d.ts → index-Dj17QRj0.d.ts} +135 -112
- 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 +13 -11
- 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-Q4LJP3V4.js +0 -1
- package/src/__tests__/Authentication/KeyAuthentication.test.ts +0 -79
- package/src/__tests__/Authentication/TokenAuthentication.test.ts +0 -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
|
-
});
|