@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/LICENSE.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023, SuperOffice AS
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, SuperOffice AS
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
# SuperOffice WebAPI TypeScript client
|
|
2
|
-
|
|
3
|
-
Provides a strongly-typed API to the SuperOffice Agents (web services).
|
|
4
|
-
|
|
5
|
-
You can either set up a `WebApi` connection object, and use it as a factory to get agents:
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { WebApi } from "@superoffice/webapi";
|
|
9
|
-
|
|
10
|
-
let webapi = new WebApi("http://example.com/SuperOffice");
|
|
11
|
-
let agent = webapi.getWebhookAgent();
|
|
12
|
-
let hook = await agent.createDefaultWebhookAsync();
|
|
13
|
-
hook.Name = "My hook";
|
|
14
|
-
hook.Events = ["contact.created"];
|
|
15
|
-
hook.TargetUrl = "https://www.requestbin.com";
|
|
16
|
-
let hook = await agent.saveWebhookAsync(hook);
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
or you can configure the WebApi using a static method, and let the agents re-use the global configuration:
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import { WebApi, WebhookAgent } from "@superoffice/webapi";
|
|
23
|
-
|
|
24
|
-
WebApi.configure("http://example.com/SuperOffice");
|
|
25
|
-
WebApi.authenticateWithPassword("username", "password");
|
|
26
|
-
let agent = new WebhookAgent();
|
|
27
|
-
let hook = await agent.createDefaultWebhookAsync();
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
or you can configure the agents directly
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
import { WebhookAgent } from "@superoffice/webapi";
|
|
34
|
-
|
|
35
|
-
let config: AxiosRequestConfig = { auth: { username: "username", password: "password" } };
|
|
36
|
-
let agent = new WebhookAgent("http://example.com/SuperOffice", config);
|
|
37
|
-
let hook = await agent.createDefaultWebhookAsync();
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Request parameters are also typed, so you can define objects like this:
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
import { WebApi, Webhook, WebhookAgent } from "@superoffice/webapi";
|
|
44
|
-
|
|
45
|
-
let webhook: Webhook = {
|
|
46
|
-
name: "My hook",
|
|
47
|
-
events: ["contact.created"],
|
|
48
|
-
type: "webhook",
|
|
49
|
-
targetUrl: "https://www.requestbin.com"
|
|
50
|
-
};
|
|
51
|
-
WebApi.configure("http://example.com/SuperOffice");
|
|
52
|
-
let agent = new WebhookAgent();
|
|
53
|
-
let hook = await agent.saveWebhookAsync(webhook);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
The hook object is typed, and its properties are all marked as optional, so that you don't
|
|
57
|
-
have to fill in everything.
|
|
58
|
-
|
|
59
|
-
The agent methods return promises, so these are all `then`able/`await`able.
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
let agent = new WebhookAgent();
|
|
63
|
-
agent.saveWebhookAsync(webhook).then(webhook => console.log(webhook.WebhookId));
|
|
64
|
-
const temp = await agent.saveWebhookAsync(webhook);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Agents API
|
|
68
|
-
|
|
69
|
-
Each agent corresponds to a service, with methods on the agent exposing service endpoints.
|
|
70
|
-
Agents POST arguments to the service, and return the result wihtout implementing HTTP semantics.
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
import { WebApi, Webhook, WebhookAgent } from "@superoffice/webapi";
|
|
74
|
-
|
|
75
|
-
WebApi.configure("http://example.com/SuperOffice");
|
|
76
|
-
let agent = new WebhookAgent();
|
|
77
|
-
let hook = await agent.getWebhookAsync(123);
|
|
78
|
-
// hook == null
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Typical methods on the Agents API:
|
|
82
|
-
* `createDefaultXxxEntityAsync`
|
|
83
|
-
* `getXxxAsync`
|
|
84
|
-
* `getXxxEntityAsync`
|
|
85
|
-
* `saveXxxEntityAsync`
|
|
86
|
-
* `deleteXxxEntityAsync`
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## REST API
|
|
90
|
-
|
|
91
|
-
The RestApi endpoints DO implement HTTP semantics, so trying to get a non-existent item will return a HTTP 404 rather than NULL.
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
import { WebApi, Webhook, WebhookRestApi } from "@superoffice/webapi";
|
|
95
|
-
|
|
96
|
-
WebApi.configure("http://example.com/SuperOffice");
|
|
97
|
-
let restApi = new WebhookRestApi();
|
|
98
|
-
let hook = await restApi.getByIdAsync(123);
|
|
99
|
-
// throws exception on 404 unless
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
The REST API also supports conditional-get or conditional-put.
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
import { WebApi, Webhook, WebhookRestApi } from "@superoffice/webapi";
|
|
106
|
-
|
|
107
|
-
WebApi.configure("http://example.com/SuperOffice");
|
|
108
|
-
let restApi = new WebhookRestApi();
|
|
109
|
-
let hook = await restApi.getByIdAsync(123), { ifModifiedSince: new Date() };
|
|
110
|
-
// returns null when not modified
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Typical methods on the REST API:
|
|
114
|
-
* `getDefaultAsync`
|
|
115
|
-
* `getByIdAsync`
|
|
116
|
-
* `putByIdAsync`
|
|
117
|
-
* `postAsync`
|
|
118
|
-
* `patchByIdAsync`
|
|
119
|
-
* `deleteByIdAsync`
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
## Language parsing
|
|
123
|
-
|
|
124
|
-
This request will add SO-Language and SO-Culture headers to the HTTP request,
|
|
125
|
-
so that the WebAPI will return strings that match the requested language (by using the resource
|
|
126
|
-
strings and multi-language string parsing.
|
|
127
|
-
|
|
128
|
-
```ts
|
|
129
|
-
import { WebApi, WebhookAgent } from "@superoffice/webapi";
|
|
130
|
-
WebApi.configure("http://example.com/SuperOffice", "en-us");
|
|
131
|
-
|
|
132
|
-
let agent = new WebhookAgent();
|
|
133
|
-
let hook = await agent.CreateDefaultWebhook();
|
|
134
|
-
|
|
135
|
-
// HTTP request:
|
|
136
|
-
// POST http://example.com/SuperOffice/api/v1/Webhook/CreateDefaultWebhook
|
|
137
|
-
// SO-Language: en-us
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
You can disable string substitution for an agent instance by passing in an enum value:
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
WebApi.configure("http://example.com/SuperOffice", "en");
|
|
144
|
-
|
|
145
|
-
let agent = new WebhookAgent(ResourceParsing.DoNotParse);
|
|
146
|
-
let hook = await agent.CreateDefaultWebhook();
|
|
147
|
-
|
|
148
|
-
// HTTP request:
|
|
149
|
-
// POST http://example.com/SuperOffice/api/v1/Webhook/CreateDefaultWebhook
|
|
150
|
-
// SO-Language: -
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Request Cancellation
|
|
154
|
-
|
|
155
|
-
You can cancel a request by providing an AbortController.
|
|
156
|
-
|
|
157
|
-
```ts
|
|
158
|
-
let agent = new WebhookAgent();
|
|
159
|
-
let aborter = agent.MakeAbortController();
|
|
160
|
-
let options: WebApiRequestOptions = { abortController: aborter };
|
|
161
|
-
agent
|
|
162
|
-
.CreateDefaultWebhook(options)
|
|
163
|
-
.then(response => console.log(response))
|
|
164
|
-
.catch(err => {
|
|
165
|
-
if (options.requestStatus === WebApiStatus.Cancelled) {
|
|
166
|
-
console.error("Request was cancelled");
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Abort the request
|
|
171
|
-
aborter.abort();
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Misc Types
|
|
175
|
-
|
|
176
|
-
- `DateTime` is converted to JS/TS `date` using Dayjs
|
|
177
|
-
- `TimeSpan` is converted to a `Dayjs.Duration` using Dayjs
|
|
178
|
-
- Blobs are converted to `ArrayBuffer`s.
|
|
179
|
-
|
|
180
|
-
# License
|
|
181
|
-
|
|
182
|
-
ISC
|
|
183
|
-
|
|
184
|
-
Copyright (c) 2023, SuperOffice AS
|
|
1
|
+
# SuperOffice WebAPI TypeScript client
|
|
2
|
+
|
|
3
|
+
Provides a strongly-typed API to the SuperOffice Agents (web services).
|
|
4
|
+
|
|
5
|
+
You can either set up a `WebApi` connection object, and use it as a factory to get agents:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { WebApi } from "@superoffice/webapi";
|
|
9
|
+
|
|
10
|
+
let webapi = new WebApi("http://example.com/SuperOffice");
|
|
11
|
+
let agent = webapi.getWebhookAgent();
|
|
12
|
+
let hook = await agent.createDefaultWebhookAsync();
|
|
13
|
+
hook.Name = "My hook";
|
|
14
|
+
hook.Events = ["contact.created"];
|
|
15
|
+
hook.TargetUrl = "https://www.requestbin.com";
|
|
16
|
+
let hook = await agent.saveWebhookAsync(hook);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
or you can configure the WebApi using a static method, and let the agents re-use the global configuration:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { WebApi, WebhookAgent } from "@superoffice/webapi";
|
|
23
|
+
|
|
24
|
+
WebApi.configure("http://example.com/SuperOffice");
|
|
25
|
+
WebApi.authenticateWithPassword("username", "password");
|
|
26
|
+
let agent = new WebhookAgent();
|
|
27
|
+
let hook = await agent.createDefaultWebhookAsync();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or you can configure the agents directly
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { WebhookAgent } from "@superoffice/webapi";
|
|
34
|
+
|
|
35
|
+
let config: AxiosRequestConfig = { auth: { username: "username", password: "password" } };
|
|
36
|
+
let agent = new WebhookAgent("http://example.com/SuperOffice", config);
|
|
37
|
+
let hook = await agent.createDefaultWebhookAsync();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Request parameters are also typed, so you can define objects like this:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { WebApi, Webhook, WebhookAgent } from "@superoffice/webapi";
|
|
44
|
+
|
|
45
|
+
let webhook: Webhook = {
|
|
46
|
+
name: "My hook",
|
|
47
|
+
events: ["contact.created"],
|
|
48
|
+
type: "webhook",
|
|
49
|
+
targetUrl: "https://www.requestbin.com"
|
|
50
|
+
};
|
|
51
|
+
WebApi.configure("http://example.com/SuperOffice");
|
|
52
|
+
let agent = new WebhookAgent();
|
|
53
|
+
let hook = await agent.saveWebhookAsync(webhook);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The hook object is typed, and its properties are all marked as optional, so that you don't
|
|
57
|
+
have to fill in everything.
|
|
58
|
+
|
|
59
|
+
The agent methods return promises, so these are all `then`able/`await`able.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
let agent = new WebhookAgent();
|
|
63
|
+
agent.saveWebhookAsync(webhook).then(webhook => console.log(webhook.WebhookId));
|
|
64
|
+
const temp = await agent.saveWebhookAsync(webhook);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Agents API
|
|
68
|
+
|
|
69
|
+
Each agent corresponds to a service, with methods on the agent exposing service endpoints.
|
|
70
|
+
Agents POST arguments to the service, and return the result wihtout implementing HTTP semantics.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { WebApi, Webhook, WebhookAgent } from "@superoffice/webapi";
|
|
74
|
+
|
|
75
|
+
WebApi.configure("http://example.com/SuperOffice");
|
|
76
|
+
let agent = new WebhookAgent();
|
|
77
|
+
let hook = await agent.getWebhookAsync(123);
|
|
78
|
+
// hook == null
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Typical methods on the Agents API:
|
|
82
|
+
* `createDefaultXxxEntityAsync`
|
|
83
|
+
* `getXxxAsync`
|
|
84
|
+
* `getXxxEntityAsync`
|
|
85
|
+
* `saveXxxEntityAsync`
|
|
86
|
+
* `deleteXxxEntityAsync`
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## REST API
|
|
90
|
+
|
|
91
|
+
The RestApi endpoints DO implement HTTP semantics, so trying to get a non-existent item will return a HTTP 404 rather than NULL.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { WebApi, Webhook, WebhookRestApi } from "@superoffice/webapi";
|
|
95
|
+
|
|
96
|
+
WebApi.configure("http://example.com/SuperOffice");
|
|
97
|
+
let restApi = new WebhookRestApi();
|
|
98
|
+
let hook = await restApi.getByIdAsync(123);
|
|
99
|
+
// throws exception on 404 unless
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The REST API also supports conditional-get or conditional-put.
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import { WebApi, Webhook, WebhookRestApi } from "@superoffice/webapi";
|
|
106
|
+
|
|
107
|
+
WebApi.configure("http://example.com/SuperOffice");
|
|
108
|
+
let restApi = new WebhookRestApi();
|
|
109
|
+
let hook = await restApi.getByIdAsync(123), { ifModifiedSince: new Date() };
|
|
110
|
+
// returns null when not modified
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Typical methods on the REST API:
|
|
114
|
+
* `getDefaultAsync`
|
|
115
|
+
* `getByIdAsync`
|
|
116
|
+
* `putByIdAsync`
|
|
117
|
+
* `postAsync`
|
|
118
|
+
* `patchByIdAsync`
|
|
119
|
+
* `deleteByIdAsync`
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## Language parsing
|
|
123
|
+
|
|
124
|
+
This request will add SO-Language and SO-Culture headers to the HTTP request,
|
|
125
|
+
so that the WebAPI will return strings that match the requested language (by using the resource
|
|
126
|
+
strings and multi-language string parsing.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { WebApi, WebhookAgent } from "@superoffice/webapi";
|
|
130
|
+
WebApi.configure("http://example.com/SuperOffice", "en-us");
|
|
131
|
+
|
|
132
|
+
let agent = new WebhookAgent();
|
|
133
|
+
let hook = await agent.CreateDefaultWebhook();
|
|
134
|
+
|
|
135
|
+
// HTTP request:
|
|
136
|
+
// POST http://example.com/SuperOffice/api/v1/Webhook/CreateDefaultWebhook
|
|
137
|
+
// SO-Language: en-us
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
You can disable string substitution for an agent instance by passing in an enum value:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
WebApi.configure("http://example.com/SuperOffice", "en");
|
|
144
|
+
|
|
145
|
+
let agent = new WebhookAgent(ResourceParsing.DoNotParse);
|
|
146
|
+
let hook = await agent.CreateDefaultWebhook();
|
|
147
|
+
|
|
148
|
+
// HTTP request:
|
|
149
|
+
// POST http://example.com/SuperOffice/api/v1/Webhook/CreateDefaultWebhook
|
|
150
|
+
// SO-Language: -
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Request Cancellation
|
|
154
|
+
|
|
155
|
+
You can cancel a request by providing an AbortController.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
let agent = new WebhookAgent();
|
|
159
|
+
let aborter = agent.MakeAbortController();
|
|
160
|
+
let options: WebApiRequestOptions = { abortController: aborter };
|
|
161
|
+
agent
|
|
162
|
+
.CreateDefaultWebhook(options)
|
|
163
|
+
.then(response => console.log(response))
|
|
164
|
+
.catch(err => {
|
|
165
|
+
if (options.requestStatus === WebApiStatus.Cancelled) {
|
|
166
|
+
console.error("Request was cancelled");
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Abort the request
|
|
171
|
+
aborter.abort();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Misc Types
|
|
175
|
+
|
|
176
|
+
- `DateTime` is converted to JS/TS `date` using Dayjs
|
|
177
|
+
- `TimeSpan` is converted to a `Dayjs.Duration` using Dayjs
|
|
178
|
+
- Blobs are converted to `ArrayBuffer`s.
|
|
179
|
+
|
|
180
|
+
# License
|
|
181
|
+
|
|
182
|
+
ISC
|
|
183
|
+
|
|
184
|
+
Copyright (c) 2023, SuperOffice AS
|