@superoffice/webapi 11.7.727 → 11.9.1204
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +15 -15
- package/README.md +184 -184
- package/__tests__/Appointment63-notz.json +1925 -1925
- package/__tests__/Appointment63-utctz.json +1925 -1925
- package/__tests__/Appointment63.json +1925 -1925
- package/__tests__/AppointmentTzTest.ts +115 -115
- package/__tests__/AxiosNockTest.ts +28 -28
- package/__tests__/ContactDefault.json +699 -699
- package/__tests__/ContactEntity.json +272 -272
- package/__tests__/ContactRestTest.ts +144 -144
- package/__tests__/ContactTest.ts +395 -395
- package/__tests__/ConvertersTest.ts +97 -97
- package/__tests__/DocumentTest.ts +101 -101
- package/__tests__/Person210-notz.json +1932 -1932
- package/__tests__/Person210-utctz.json +1932 -1932
- package/__tests__/Person210.json +1932 -1932
- package/__tests__/PersonImageData.nock +22 -22
- package/__tests__/PersonTest.ts +41 -41
- package/__tests__/PersonTzTest.ts +113 -113
- package/__tests__/RecurrenceInfo.json +55 -55
- package/__tests__/ResponseCallbackTest.ts +23 -23
- package/__tests__/TableRights.json +441 -441
- package/__tests__/WebapiTest.ts +264 -264
- package/__tests__/Webhook.json +16 -16
- package/__tests__/WebhookTest.ts +209 -209
- package/dist/cjs/AIAgent.d.ts +62 -0
- package/dist/cjs/AIAgent.d.ts.map +1 -1
- package/dist/cjs/AIAgent.js +149 -0
- package/dist/cjs/AIAgent.js.map +1 -1
- package/dist/cjs/Carriers.d.ts +640 -14
- package/dist/cjs/Carriers.d.ts.map +1 -1
- package/dist/cjs/Converters.d.ts +24 -0
- package/dist/cjs/Converters.d.ts.map +1 -1
- package/dist/cjs/Converters.js +388 -17
- package/dist/cjs/Converters.js.map +1 -1
- package/dist/cjs/DiagnosticsAgent.d.ts +38 -0
- package/dist/cjs/DiagnosticsAgent.d.ts.map +1 -1
- package/dist/cjs/DiagnosticsAgent.js +91 -0
- package/dist/cjs/DiagnosticsAgent.js.map +1 -1
- package/dist/cjs/Enums.d.ts +77 -1
- package/dist/cjs/Enums.d.ts.map +1 -1
- package/dist/cjs/Enums.js +83 -4
- package/dist/cjs/Enums.js.map +1 -1
- package/dist/cjs/ListAgent.d.ts +71 -6
- package/dist/cjs/ListAgent.d.ts.map +1 -1
- package/dist/cjs/ListAgent.js +157 -0
- package/dist/cjs/ListAgent.js.map +1 -1
- package/dist/cjs/MarketingAgent.d.ts +68 -0
- package/dist/cjs/MarketingAgent.d.ts.map +1 -1
- package/dist/cjs/MarketingAgent.js +157 -0
- package/dist/cjs/MarketingAgent.js.map +1 -1
- package/dist/cjs/TicketAgent.d.ts +23 -0
- package/dist/cjs/TicketAgent.d.ts.map +1 -1
- package/dist/cjs/TicketAgent.js +65 -0
- package/dist/cjs/TicketAgent.js.map +1 -1
- package/dist/esm/AIAgent.d.ts +62 -0
- package/dist/esm/AIAgent.d.ts.map +1 -1
- package/dist/esm/AIAgent.js +150 -1
- package/dist/esm/AIAgent.js.map +1 -1
- package/dist/esm/Carriers.d.ts +640 -14
- package/dist/esm/Carriers.d.ts.map +1 -1
- package/dist/esm/Converters.d.ts +24 -0
- package/dist/esm/Converters.d.ts.map +1 -1
- package/dist/esm/Converters.js +346 -0
- package/dist/esm/Converters.js.map +1 -1
- package/dist/esm/DiagnosticsAgent.d.ts +38 -0
- package/dist/esm/DiagnosticsAgent.d.ts.map +1 -1
- package/dist/esm/DiagnosticsAgent.js +91 -0
- package/dist/esm/DiagnosticsAgent.js.map +1 -1
- package/dist/esm/Enums.d.ts +77 -1
- package/dist/esm/Enums.d.ts.map +1 -1
- package/dist/esm/Enums.js +79 -0
- package/dist/esm/Enums.js.map +1 -1
- package/dist/esm/ListAgent.d.ts +71 -6
- package/dist/esm/ListAgent.d.ts.map +1 -1
- package/dist/esm/ListAgent.js +157 -0
- package/dist/esm/ListAgent.js.map +1 -1
- package/dist/esm/MarketingAgent.d.ts +68 -0
- package/dist/esm/MarketingAgent.d.ts.map +1 -1
- package/dist/esm/MarketingAgent.js +157 -0
- package/dist/esm/MarketingAgent.js.map +1 -1
- package/dist/esm/TicketAgent.d.ts +23 -0
- package/dist/esm/TicketAgent.d.ts.map +1 -1
- package/dist/esm/TicketAgent.js +65 -0
- package/dist/esm/TicketAgent.js.map +1 -1
- package/examples-js/hello.js +12 -12
- package/examples-ts/hello.ts +8 -8
- package/package.json +93 -93
- package/scripts/postbuild.js +22 -22
- package/scripts/setVersion.js +44 -44
- package/src/AIAgent.ts +2239 -1992
- package/src/AppointmentAgent.ts +6263 -6263
- package/src/AppointmentRestApi.ts +225 -225
- package/src/ArchiveAgent.ts +1950 -1950
- package/src/AssociateAgent.ts +422 -422
- package/src/AxiosCacheHandler.ts +74 -74
- package/src/BLOBAgent.ts +2100 -2100
- package/src/Base64.ts +285 -285
- package/src/BatchAgent.ts +910 -910
- package/src/BulkUpdateAgent.ts +504 -504
- package/src/CRMScriptAgent.ts +1390 -1390
- package/src/Carriers.ts +53121 -52274
- package/src/ChatAgent.ts +1422 -1422
- package/src/ConfigurationAgent.ts +2228 -2228
- package/src/ContactAgent.ts +1756 -1756
- package/src/ContactRestApi.ts +237 -237
- package/src/Converters.ts +23496 -23090
- package/src/CustomerServiceAgent.ts +1799 -1799
- package/src/DashAgent.ts +1674 -1674
- package/src/DatabaseAgent.ts +120 -120
- package/src/DatabaseTableAgent.ts +534 -534
- package/src/Day_js.ts +41 -41
- package/src/DiagnosticsAgent.ts +1384 -1240
- package/src/DocumentAgent.ts +5079 -5079
- package/src/DocumentMigrationAgent.ts +524 -524
- package/src/DocumentRestApi.ts +259 -259
- package/src/EMailAgent.ts +5328 -5328
- package/src/Enums.ts +6998 -6916
- package/src/ErpSyncAgent.ts +2658 -2658
- package/src/FavouriteAgent.ts +720 -720
- package/src/FindAgent.ts +2330 -2330
- package/src/ForeignSystemAgent.ts +1710 -1710
- package/src/FreeTextAgent.ts +372 -372
- package/src/ImportAgent.ts +304 -304
- package/src/LicenseAgent.ts +1230 -1230
- package/src/ListAgent.ts +11451 -11237
- package/src/MDOAgent.ts +748 -748
- package/src/MarketingAgent.ts +1146 -890
- package/src/MessagingAgent.ts +384 -384
- package/src/NavigatorAgent.ts +140 -140
- package/src/NumberAllocationAgent.ts +296 -296
- package/src/PersonAgent.ts +3287 -3287
- package/src/PersonRestApi.ts +241 -241
- package/src/PhoneListAgent.ts +458 -458
- package/src/PocketAgent.ts +780 -780
- package/src/PreferenceAgent.ts +1900 -1900
- package/src/PreviewsAgent.ts +116 -116
- package/src/ProjectAgent.ts +2391 -2391
- package/src/ProjectRestApi.ts +239 -239
- package/src/QuoteAgent.ts +5159 -5159
- package/src/RelationAgent.ts +220 -220
- package/src/ReportAgent.ts +154 -154
- package/src/ResourceAgent.ts +358 -358
- package/src/SaintAgent.ts +601 -601
- package/src/SaleAgent.ts +2034 -2034
- package/src/SaleRestApi.ts +233 -233
- package/src/SelectionAgent.ts +3195 -3195
- package/src/SentryAgent.ts +462 -462
- package/src/SoApiConstants.ts +8 -8
- package/src/TargetsAgent.ts +1104 -1104
- package/src/TicketAgent.ts +3708 -3638
- package/src/TimeZoneAgent.ts +528 -528
- package/src/TooltipsAgent.ts +116 -116
- package/src/UserAgent.ts +4856 -4856
- package/src/UserDefinedFieldInfoAgent.ts +1764 -1764
- package/src/ViewStateAgent.ts +858 -858
- package/src/WebApi.ts +872 -872
- package/src/WebApiBase.ts +565 -565
- package/src/WebhookAgent.ts +388 -388
- package/src/WorkflowAgent.ts +1338 -1338
- package/tsconfig.esm.json +8 -8
- package/tsconfig.jest.json +8 -8
- package/tsconfig.json +34 -34
package/__tests__/WebapiTest.ts
CHANGED
|
@@ -1,264 +1,264 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
import axios, { AxiosRequestConfig } from "axios";
|
|
3
|
-
import nock from "nock";
|
|
4
|
-
import { WebhookAgent } from "../src/WebhookAgent";
|
|
5
|
-
import { WebApiOptions, ResourceParsing } from "../src/WebApiBase";
|
|
6
|
-
import { WebhookState } from "../src/Enums";
|
|
7
|
-
import { WebApi, Webhook } from "../src/WebApi";
|
|
8
|
-
import { HEADER_NAME_ACCEPT_LANGUAGE, HEADER_NAME_LANGUAGE } from "../src/SoApiConstants";
|
|
9
|
-
|
|
10
|
-
const host: string = "http://localhost/";
|
|
11
|
-
const defaultHook = {
|
|
12
|
-
WebhookId: 0,
|
|
13
|
-
Name: null,
|
|
14
|
-
Events: ["contact.created", "contact.deleted"],
|
|
15
|
-
TargetUrl: null,
|
|
16
|
-
Secret: null,
|
|
17
|
-
State: "Active",
|
|
18
|
-
Type: "webhook",
|
|
19
|
-
Headers: null,
|
|
20
|
-
Properties: null,
|
|
21
|
-
Registered: "0001-01-01T00:00:00",
|
|
22
|
-
RegisteredAssociate: null,
|
|
23
|
-
Updated: "0001-01-01T00:00:00",
|
|
24
|
-
UpdatedAssociate: null
|
|
25
|
-
};
|
|
26
|
-
const aHook = {
|
|
27
|
-
WebhookId: 3,
|
|
28
|
-
Name: "My hook",
|
|
29
|
-
Events: ["contact.created"],
|
|
30
|
-
TargetUrl: "https://www.example.com",
|
|
31
|
-
Secret: "",
|
|
32
|
-
State: "Active",
|
|
33
|
-
Type: "webhook",
|
|
34
|
-
Headers: {},
|
|
35
|
-
Properties: {},
|
|
36
|
-
Registered: "0001-01-01T00:00:00",
|
|
37
|
-
RegisteredAssociate: null,
|
|
38
|
-
Updated: "0001-01-01T00:00:00",
|
|
39
|
-
UpdatedAssociate: null
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
axios.defaults.baseURL = host;
|
|
43
|
-
|
|
44
|
-
describe("WebAPI tests", () => {
|
|
45
|
-
it("Can configure agents via webapi", done => {
|
|
46
|
-
const scope = nock(host)
|
|
47
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
48
|
-
.reply(200, defaultHook);
|
|
49
|
-
|
|
50
|
-
WebApi.configure(host);
|
|
51
|
-
const agent = new WebhookAgent();
|
|
52
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
53
|
-
assert.equal(response.webhookId, 0);
|
|
54
|
-
assert.equal(response.name, null);
|
|
55
|
-
assert.equal(response.state, WebhookState.Active);
|
|
56
|
-
assert.equal(response.type, "webhook");
|
|
57
|
-
done();
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("Can configure agents via webapi", done => {
|
|
62
|
-
const scope = nock(host)
|
|
63
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
64
|
-
.reply(200, defaultHook);
|
|
65
|
-
|
|
66
|
-
const config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
67
|
-
WebApi.configure(host, config);
|
|
68
|
-
const agent = new WebhookAgent();
|
|
69
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
70
|
-
assert.equal(response.webhookId, 0);
|
|
71
|
-
assert.equal(response.name, null);
|
|
72
|
-
assert.equal(response.state, WebhookState.Active);
|
|
73
|
-
assert.equal(response.type, "webhook");
|
|
74
|
-
done();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("Can configure multiple agents using global defaults", done => {
|
|
79
|
-
let scope = nock(host)
|
|
80
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
81
|
-
.reply(200, defaultHook);
|
|
82
|
-
|
|
83
|
-
WebApi.configure(host);
|
|
84
|
-
let agent1 = new WebhookAgent();
|
|
85
|
-
let agent2 = new WebhookAgent();
|
|
86
|
-
agent2.createDefaultWebhookAsync().then(response => {
|
|
87
|
-
assert.equal(response.webhookId, 0);
|
|
88
|
-
assert.equal(response.name, null);
|
|
89
|
-
assert.equal(response.state, WebhookState.Active);
|
|
90
|
-
assert.equal(response.type, "webhook");
|
|
91
|
-
done();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("Cannot create an agent with no global defaults", done => {
|
|
96
|
-
WebApi.configure(""); // Reset global config
|
|
97
|
-
assert.throws(() => {
|
|
98
|
-
let agent2 = new WebhookAgent();
|
|
99
|
-
});
|
|
100
|
-
done();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("Can configure using an options object", done => {
|
|
104
|
-
let scope = nock(host)
|
|
105
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
106
|
-
.reply(200, defaultHook);
|
|
107
|
-
|
|
108
|
-
let opts: WebApiOptions = { baseUrl: host };
|
|
109
|
-
WebApi.configure(opts);
|
|
110
|
-
let agent = new WebhookAgent();
|
|
111
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
112
|
-
assert.equal(response.webhookId, 0);
|
|
113
|
-
assert.equal(response.name, null);
|
|
114
|
-
assert.equal(response.state, WebhookState.Active);
|
|
115
|
-
assert.equal(response.type, "webhook");
|
|
116
|
-
|
|
117
|
-
done();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("Can configure using a webAPi instance", done => {
|
|
122
|
-
let scope = nock(host)
|
|
123
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
124
|
-
.reply(200, defaultHook);
|
|
125
|
-
|
|
126
|
-
let api = new WebApi(host);
|
|
127
|
-
let agent = api.getWebhookAgent();
|
|
128
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
129
|
-
assert.equal(response.webhookId, 0);
|
|
130
|
-
assert.equal(response.name, null);
|
|
131
|
-
assert.equal(response.state, WebhookState.Active);
|
|
132
|
-
assert.equal(response.type, "webhook");
|
|
133
|
-
|
|
134
|
-
done();
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("Can configure hook using an axios config object", async () => {
|
|
139
|
-
let scope = nock(host, { badheaders: [HEADER_NAME_LANGUAGE] })
|
|
140
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
141
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
142
|
-
.reply(200, defaultHook);
|
|
143
|
-
|
|
144
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
145
|
-
WebApi.configure(host, config);
|
|
146
|
-
let agent = new WebhookAgent();
|
|
147
|
-
let response = await agent.createDefaultWebhookAsync();
|
|
148
|
-
assert.equal(response.webhookId, 0);
|
|
149
|
-
assert.equal(response.name, null);
|
|
150
|
-
assert.equal(response.state, WebhookState.Active);
|
|
151
|
-
assert.equal(response.type, "webhook");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("can configure without parsing languages", done => {
|
|
155
|
-
let scope = nock(host)
|
|
156
|
-
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
157
|
-
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
158
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
159
|
-
.reply(200, defaultHook);
|
|
160
|
-
|
|
161
|
-
let opts: WebApiOptions = { baseUrl: host, cultureCode: "sv", languageCode: "sv" };
|
|
162
|
-
let api = new WebApi(opts);
|
|
163
|
-
api.authenticateWithPassword("ADM0", "");
|
|
164
|
-
let agent = new WebhookAgent();
|
|
165
|
-
agent.createDefaultWebhookAsync({ languageCode: "" }).then(response => {
|
|
166
|
-
assert.equal(response.webhookId, 0);
|
|
167
|
-
assert.equal(response.name, null);
|
|
168
|
-
assert.equal(response.state, WebhookState.Active);
|
|
169
|
-
assert.equal(response.type, "webhook");
|
|
170
|
-
done();
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("can create a default hook without parsing languages and a password", done => {
|
|
175
|
-
let scope = nock(host)
|
|
176
|
-
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
177
|
-
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
178
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
179
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
180
|
-
.reply(200, defaultHook);
|
|
181
|
-
|
|
182
|
-
let api = new WebApi(host);
|
|
183
|
-
api.authenticateWithPassword("ADM0", "");
|
|
184
|
-
let agent = new WebhookAgent(undefined, ResourceParsing.DoNotParse);
|
|
185
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
186
|
-
assert.equal(response.webhookId, 0);
|
|
187
|
-
assert.equal(response.name, null);
|
|
188
|
-
assert.equal(response.state, WebhookState.Active);
|
|
189
|
-
assert.equal(response.type, "webhook");
|
|
190
|
-
done();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("create a new webhook will reject a non-https target URL", done => {
|
|
195
|
-
let webhook: Webhook = {
|
|
196
|
-
name: "My hook",
|
|
197
|
-
events: ["contact.created"],
|
|
198
|
-
type: "webhook",
|
|
199
|
-
targetUrl: "https://www.example.com"
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
let scope = nock(host)
|
|
203
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
204
|
-
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
205
|
-
.reply(400, {
|
|
206
|
-
Error: true,
|
|
207
|
-
ErrorType: "ArgumentException",
|
|
208
|
-
Message: "Webhook TargetUrl must be secure: 'HTTPS:' not found in http://www.example.com",
|
|
209
|
-
ErrorSource: "SuperOffice.Services.Implementation"
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
213
|
-
WebApi.configure(host, config);
|
|
214
|
-
let agent = new WebhookAgent();
|
|
215
|
-
agent.saveWebhookAsync(webhook).catch(error => {
|
|
216
|
-
assert.equal(error.response.status, 400);
|
|
217
|
-
assert.equal(error.response.data.ErrorType, "ArgumentException");
|
|
218
|
-
done();
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it("create a new webhook will accept a https target URL", done => {
|
|
223
|
-
let webhook: Webhook = {
|
|
224
|
-
name: "My hook",
|
|
225
|
-
events: ["contact.created"],
|
|
226
|
-
type: "webhook",
|
|
227
|
-
targetUrl: "https://www.example.com"
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
let scope = nock(host)
|
|
231
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
232
|
-
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
233
|
-
.reply(200, aHook);
|
|
234
|
-
|
|
235
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
236
|
-
WebApi.configure(host, config);
|
|
237
|
-
let agent = new WebhookAgent();
|
|
238
|
-
agent.saveWebhookAsync(webhook).then(hook => {
|
|
239
|
-
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
240
|
-
assert.equal(hook.type, "webhook");
|
|
241
|
-
assert.equal(hook.state, WebhookState.Active);
|
|
242
|
-
assert.notEqual(hook.webhookId, 0);
|
|
243
|
-
done();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("create a new webhook will accept a https target URL", done => {
|
|
248
|
-
let scope = nock(host)
|
|
249
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
250
|
-
.post("/api/v1/Agents/Webhook/GetWebhook?webhookId=1")
|
|
251
|
-
.reply(200, aHook);
|
|
252
|
-
|
|
253
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
254
|
-
WebApi.configure(host, config);
|
|
255
|
-
let agent = new WebhookAgent();
|
|
256
|
-
agent.getWebhookAsync(1).then(hook => {
|
|
257
|
-
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
258
|
-
assert.equal(hook.type, "webhook");
|
|
259
|
-
assert.equal(hook.state, WebhookState.Active);
|
|
260
|
-
assert.notEqual(hook.webhookId, 0);
|
|
261
|
-
done();
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
});
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import axios, { AxiosRequestConfig } from "axios";
|
|
3
|
+
import nock from "nock";
|
|
4
|
+
import { WebhookAgent } from "../src/WebhookAgent";
|
|
5
|
+
import { WebApiOptions, ResourceParsing } from "../src/WebApiBase";
|
|
6
|
+
import { WebhookState } from "../src/Enums";
|
|
7
|
+
import { WebApi, Webhook } from "../src/WebApi";
|
|
8
|
+
import { HEADER_NAME_ACCEPT_LANGUAGE, HEADER_NAME_LANGUAGE } from "../src/SoApiConstants";
|
|
9
|
+
|
|
10
|
+
const host: string = "http://localhost/";
|
|
11
|
+
const defaultHook = {
|
|
12
|
+
WebhookId: 0,
|
|
13
|
+
Name: null,
|
|
14
|
+
Events: ["contact.created", "contact.deleted"],
|
|
15
|
+
TargetUrl: null,
|
|
16
|
+
Secret: null,
|
|
17
|
+
State: "Active",
|
|
18
|
+
Type: "webhook",
|
|
19
|
+
Headers: null,
|
|
20
|
+
Properties: null,
|
|
21
|
+
Registered: "0001-01-01T00:00:00",
|
|
22
|
+
RegisteredAssociate: null,
|
|
23
|
+
Updated: "0001-01-01T00:00:00",
|
|
24
|
+
UpdatedAssociate: null
|
|
25
|
+
};
|
|
26
|
+
const aHook = {
|
|
27
|
+
WebhookId: 3,
|
|
28
|
+
Name: "My hook",
|
|
29
|
+
Events: ["contact.created"],
|
|
30
|
+
TargetUrl: "https://www.example.com",
|
|
31
|
+
Secret: "",
|
|
32
|
+
State: "Active",
|
|
33
|
+
Type: "webhook",
|
|
34
|
+
Headers: {},
|
|
35
|
+
Properties: {},
|
|
36
|
+
Registered: "0001-01-01T00:00:00",
|
|
37
|
+
RegisteredAssociate: null,
|
|
38
|
+
Updated: "0001-01-01T00:00:00",
|
|
39
|
+
UpdatedAssociate: null
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
axios.defaults.baseURL = host;
|
|
43
|
+
|
|
44
|
+
describe("WebAPI tests", () => {
|
|
45
|
+
it("Can configure agents via webapi", done => {
|
|
46
|
+
const scope = nock(host)
|
|
47
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
48
|
+
.reply(200, defaultHook);
|
|
49
|
+
|
|
50
|
+
WebApi.configure(host);
|
|
51
|
+
const agent = new WebhookAgent();
|
|
52
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
53
|
+
assert.equal(response.webhookId, 0);
|
|
54
|
+
assert.equal(response.name, null);
|
|
55
|
+
assert.equal(response.state, WebhookState.Active);
|
|
56
|
+
assert.equal(response.type, "webhook");
|
|
57
|
+
done();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("Can configure agents via webapi", done => {
|
|
62
|
+
const scope = nock(host)
|
|
63
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
64
|
+
.reply(200, defaultHook);
|
|
65
|
+
|
|
66
|
+
const config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
67
|
+
WebApi.configure(host, config);
|
|
68
|
+
const agent = new WebhookAgent();
|
|
69
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
70
|
+
assert.equal(response.webhookId, 0);
|
|
71
|
+
assert.equal(response.name, null);
|
|
72
|
+
assert.equal(response.state, WebhookState.Active);
|
|
73
|
+
assert.equal(response.type, "webhook");
|
|
74
|
+
done();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("Can configure multiple agents using global defaults", done => {
|
|
79
|
+
let scope = nock(host)
|
|
80
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
81
|
+
.reply(200, defaultHook);
|
|
82
|
+
|
|
83
|
+
WebApi.configure(host);
|
|
84
|
+
let agent1 = new WebhookAgent();
|
|
85
|
+
let agent2 = new WebhookAgent();
|
|
86
|
+
agent2.createDefaultWebhookAsync().then(response => {
|
|
87
|
+
assert.equal(response.webhookId, 0);
|
|
88
|
+
assert.equal(response.name, null);
|
|
89
|
+
assert.equal(response.state, WebhookState.Active);
|
|
90
|
+
assert.equal(response.type, "webhook");
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("Cannot create an agent with no global defaults", done => {
|
|
96
|
+
WebApi.configure(""); // Reset global config
|
|
97
|
+
assert.throws(() => {
|
|
98
|
+
let agent2 = new WebhookAgent();
|
|
99
|
+
});
|
|
100
|
+
done();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("Can configure using an options object", done => {
|
|
104
|
+
let scope = nock(host)
|
|
105
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
106
|
+
.reply(200, defaultHook);
|
|
107
|
+
|
|
108
|
+
let opts: WebApiOptions = { baseUrl: host };
|
|
109
|
+
WebApi.configure(opts);
|
|
110
|
+
let agent = new WebhookAgent();
|
|
111
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
112
|
+
assert.equal(response.webhookId, 0);
|
|
113
|
+
assert.equal(response.name, null);
|
|
114
|
+
assert.equal(response.state, WebhookState.Active);
|
|
115
|
+
assert.equal(response.type, "webhook");
|
|
116
|
+
|
|
117
|
+
done();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("Can configure using a webAPi instance", done => {
|
|
122
|
+
let scope = nock(host)
|
|
123
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
124
|
+
.reply(200, defaultHook);
|
|
125
|
+
|
|
126
|
+
let api = new WebApi(host);
|
|
127
|
+
let agent = api.getWebhookAgent();
|
|
128
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
129
|
+
assert.equal(response.webhookId, 0);
|
|
130
|
+
assert.equal(response.name, null);
|
|
131
|
+
assert.equal(response.state, WebhookState.Active);
|
|
132
|
+
assert.equal(response.type, "webhook");
|
|
133
|
+
|
|
134
|
+
done();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("Can configure hook using an axios config object", async () => {
|
|
139
|
+
let scope = nock(host, { badheaders: [HEADER_NAME_LANGUAGE] })
|
|
140
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
141
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
142
|
+
.reply(200, defaultHook);
|
|
143
|
+
|
|
144
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
145
|
+
WebApi.configure(host, config);
|
|
146
|
+
let agent = new WebhookAgent();
|
|
147
|
+
let response = await agent.createDefaultWebhookAsync();
|
|
148
|
+
assert.equal(response.webhookId, 0);
|
|
149
|
+
assert.equal(response.name, null);
|
|
150
|
+
assert.equal(response.state, WebhookState.Active);
|
|
151
|
+
assert.equal(response.type, "webhook");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("can configure without parsing languages", done => {
|
|
155
|
+
let scope = nock(host)
|
|
156
|
+
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
157
|
+
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
158
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
159
|
+
.reply(200, defaultHook);
|
|
160
|
+
|
|
161
|
+
let opts: WebApiOptions = { baseUrl: host, cultureCode: "sv", languageCode: "sv" };
|
|
162
|
+
let api = new WebApi(opts);
|
|
163
|
+
api.authenticateWithPassword("ADM0", "");
|
|
164
|
+
let agent = new WebhookAgent();
|
|
165
|
+
agent.createDefaultWebhookAsync({ languageCode: "" }).then(response => {
|
|
166
|
+
assert.equal(response.webhookId, 0);
|
|
167
|
+
assert.equal(response.name, null);
|
|
168
|
+
assert.equal(response.state, WebhookState.Active);
|
|
169
|
+
assert.equal(response.type, "webhook");
|
|
170
|
+
done();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("can create a default hook without parsing languages and a password", done => {
|
|
175
|
+
let scope = nock(host)
|
|
176
|
+
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
177
|
+
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
178
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
179
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
180
|
+
.reply(200, defaultHook);
|
|
181
|
+
|
|
182
|
+
let api = new WebApi(host);
|
|
183
|
+
api.authenticateWithPassword("ADM0", "");
|
|
184
|
+
let agent = new WebhookAgent(undefined, ResourceParsing.DoNotParse);
|
|
185
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
186
|
+
assert.equal(response.webhookId, 0);
|
|
187
|
+
assert.equal(response.name, null);
|
|
188
|
+
assert.equal(response.state, WebhookState.Active);
|
|
189
|
+
assert.equal(response.type, "webhook");
|
|
190
|
+
done();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("create a new webhook will reject a non-https target URL", done => {
|
|
195
|
+
let webhook: Webhook = {
|
|
196
|
+
name: "My hook",
|
|
197
|
+
events: ["contact.created"],
|
|
198
|
+
type: "webhook",
|
|
199
|
+
targetUrl: "https://www.example.com"
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
let scope = nock(host)
|
|
203
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
204
|
+
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
205
|
+
.reply(400, {
|
|
206
|
+
Error: true,
|
|
207
|
+
ErrorType: "ArgumentException",
|
|
208
|
+
Message: "Webhook TargetUrl must be secure: 'HTTPS:' not found in http://www.example.com",
|
|
209
|
+
ErrorSource: "SuperOffice.Services.Implementation"
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
213
|
+
WebApi.configure(host, config);
|
|
214
|
+
let agent = new WebhookAgent();
|
|
215
|
+
agent.saveWebhookAsync(webhook).catch(error => {
|
|
216
|
+
assert.equal(error.response.status, 400);
|
|
217
|
+
assert.equal(error.response.data.ErrorType, "ArgumentException");
|
|
218
|
+
done();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("create a new webhook will accept a https target URL", done => {
|
|
223
|
+
let webhook: Webhook = {
|
|
224
|
+
name: "My hook",
|
|
225
|
+
events: ["contact.created"],
|
|
226
|
+
type: "webhook",
|
|
227
|
+
targetUrl: "https://www.example.com"
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
let scope = nock(host)
|
|
231
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
232
|
+
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
233
|
+
.reply(200, aHook);
|
|
234
|
+
|
|
235
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
236
|
+
WebApi.configure(host, config);
|
|
237
|
+
let agent = new WebhookAgent();
|
|
238
|
+
agent.saveWebhookAsync(webhook).then(hook => {
|
|
239
|
+
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
240
|
+
assert.equal(hook.type, "webhook");
|
|
241
|
+
assert.equal(hook.state, WebhookState.Active);
|
|
242
|
+
assert.notEqual(hook.webhookId, 0);
|
|
243
|
+
done();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("create a new webhook will accept a https target URL", done => {
|
|
248
|
+
let scope = nock(host)
|
|
249
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
250
|
+
.post("/api/v1/Agents/Webhook/GetWebhook?webhookId=1")
|
|
251
|
+
.reply(200, aHook);
|
|
252
|
+
|
|
253
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
254
|
+
WebApi.configure(host, config);
|
|
255
|
+
let agent = new WebhookAgent();
|
|
256
|
+
agent.getWebhookAsync(1).then(hook => {
|
|
257
|
+
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
258
|
+
assert.equal(hook.type, "webhook");
|
|
259
|
+
assert.equal(hook.state, WebhookState.Active);
|
|
260
|
+
assert.notEqual(hook.webhookId, 0);
|
|
261
|
+
done();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
package/__tests__/Webhook.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"WebhookId": 3,
|
|
3
|
-
"Name": "My hook",
|
|
4
|
-
"Events": [
|
|
5
|
-
"contact.created"
|
|
6
|
-
],
|
|
7
|
-
"TargetUrl": "https://www.example.com",
|
|
8
|
-
"Secret": "",
|
|
9
|
-
"State": "Active",
|
|
10
|
-
"Type": "webhook",
|
|
11
|
-
"Headers": {},
|
|
12
|
-
"Properties": {},
|
|
13
|
-
"Registered": "0001-01-01T00:00:00",
|
|
14
|
-
"RegisteredAssociate": null,
|
|
15
|
-
"Updated": "0001-01-01T00:00:00",
|
|
16
|
-
"UpdatedAssociate": null
|
|
1
|
+
{
|
|
2
|
+
"WebhookId": 3,
|
|
3
|
+
"Name": "My hook",
|
|
4
|
+
"Events": [
|
|
5
|
+
"contact.created"
|
|
6
|
+
],
|
|
7
|
+
"TargetUrl": "https://www.example.com",
|
|
8
|
+
"Secret": "",
|
|
9
|
+
"State": "Active",
|
|
10
|
+
"Type": "webhook",
|
|
11
|
+
"Headers": {},
|
|
12
|
+
"Properties": {},
|
|
13
|
+
"Registered": "0001-01-01T00:00:00",
|
|
14
|
+
"RegisteredAssociate": null,
|
|
15
|
+
"Updated": "0001-01-01T00:00:00",
|
|
16
|
+
"UpdatedAssociate": null
|
|
17
17
|
}
|