@sonoransoftware/sonoran.js 1.0.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/.eslintrc.js +11 -0
- package/.prettierrc.js +7 -0
- package/docs/CAD-Methods-and-Usage.md +59 -0
- package/docs/CMS-Methods-and-Usage.md +212 -0
- package/docs/REST-Methods-and-Usage.md +47 -0
- package/package.json +42 -0
- package/readme.md +54 -0
- package/src/builders/cad/DispatchCall.ts +159 -0
- package/src/builders/cad/index.ts +1 -0
- package/src/builders/index.ts +3 -0
- package/src/constants.ts +174 -0
- package/src/errors/LibraryErrors.ts +43 -0
- package/src/errors/Messages.ts +7 -0
- package/src/errors/index.ts +2 -0
- package/src/index.ts +12 -0
- package/src/instance/Instance.ts +118 -0
- package/src/instance/instance.types.ts +17 -0
- package/src/libs/rest/src/index.ts +6 -0
- package/src/libs/rest/src/lib/REST.ts +201 -0
- package/src/libs/rest/src/lib/RequestManager.ts +256 -0
- package/src/libs/rest/src/lib/errors/APIError.ts +15 -0
- package/src/libs/rest/src/lib/errors/HTTPError.ts +22 -0
- package/src/libs/rest/src/lib/errors/RateLimitError.ts +21 -0
- package/src/libs/rest/src/lib/errors/index.ts +4 -0
- package/src/libs/rest/src/lib/handlers/IHandler.ts +13 -0
- package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +157 -0
- package/src/libs/rest/src/lib/utils/constants.ts +919 -0
- package/src/libs/rest/src/lib/utils/utils.ts +18 -0
- package/src/managers/BaseManager.ts +15 -0
- package/src/managers/CADActiveUnitsManager.ts +50 -0
- package/src/managers/CADManager.ts +58 -0
- package/src/managers/CADServerManager.ts +27 -0
- package/src/managers/CMSManager.ts +133 -0
- package/src/managers/CMSServerManager.ts +27 -0
- package/src/managers/CacheManager.ts +38 -0
- package/src/managers/DataManager.ts +64 -0
- package/src/structures/Base.ts +28 -0
- package/src/structures/CADActiveUnit.ts +85 -0
- package/src/structures/CADServer.ts +37 -0
- package/src/structures/CMSServer.ts +26 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +75 -0
- package/tsconfig.json +71 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
parser: '@typescript-eslint/parser',
|
|
3
|
+
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
|
|
4
|
+
parserOptions: {
|
|
5
|
+
sourceType: 'module',
|
|
6
|
+
},
|
|
7
|
+
rules: {
|
|
8
|
+
'prettier/prettier': 'error',
|
|
9
|
+
},
|
|
10
|
+
plugins: ['@typescript-eslint', 'prettier'],
|
|
11
|
+
}
|
package/.prettierrc.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Sonoran CAD Specific Methods & Usage
|
|
2
|
+
The following methods can be accessed from the `cad` property of an instance.
|
|
3
|
+
|
|
4
|
+
## Basic General Usage
|
|
5
|
+
```js
|
|
6
|
+
const Sonoran = require('sonoran.js');
|
|
7
|
+
const instance = Sonoran.instance({
|
|
8
|
+
communityId: 'mycommunity',
|
|
9
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
10
|
+
product: Sonoran.productEnums.CAD
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const whitelist = await instance.cad.getAccount('459798465498798432');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## getAccount(params)
|
|
18
|
+
| Parameter | Optional | Type | Note |
|
|
19
|
+
|----------|:-------------:|------:|-----:|
|
|
20
|
+
| params.username | Yes | String | Must have at least apiId or accId |
|
|
21
|
+
| params.apiId | Yes | String | Must have at least apiId or accId |
|
|
22
|
+
|
|
23
|
+
Returns *accountResult*;
|
|
24
|
+
| Property | Optional | Type | Note |
|
|
25
|
+
|----------|:-------------:|------:|-----:|
|
|
26
|
+
| accountResult.success | No | Boolean | Wether the whitelist verification was successful |
|
|
27
|
+
| accountResult.account | Yes | Object | Object of the account data |
|
|
28
|
+
| accountResult.reason | Yes | String | Fail reason if success is falsy |
|
|
29
|
+
|
|
30
|
+
### Example Code
|
|
31
|
+
```js
|
|
32
|
+
const Sonoran = require('sonoran.js');
|
|
33
|
+
const instance = Sonoran.instance({
|
|
34
|
+
communityId: 'mycommunity',
|
|
35
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
36
|
+
product: Sonoran.productEnums.CMS,
|
|
37
|
+
serverId: 2
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// This will verify the whitelist of the given API ID or account ID for server id 2 as specified above
|
|
41
|
+
const verification = await instance.cad.getAccount('459798465498798432');
|
|
42
|
+
// This will verify the whitelist of the given API ID for server id 1 since I specified that
|
|
43
|
+
const verification = await instance.cad.getAccount({
|
|
44
|
+
apiId: '459798465498798432',
|
|
45
|
+
serverId: 1
|
|
46
|
+
});
|
|
47
|
+
// OR
|
|
48
|
+
// This will verify the whitelist of the given account ID for server id 1 since I specified that
|
|
49
|
+
const verification = await instance.cad.getAccount({
|
|
50
|
+
accId: 'd5663516-ee35-11e9-9714-5600023b2434',
|
|
51
|
+
serverId: 1
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (verification.success) {
|
|
55
|
+
console.log('Success!', verification.reason);
|
|
56
|
+
} else {
|
|
57
|
+
console.log('Unsuccessful', verfication.reason); // Log the reason it was unsuccessful.
|
|
58
|
+
}
|
|
59
|
+
```
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Sonoran CMS Specific Methods & Usage
|
|
2
|
+
The following methods can be accessed from the `cms` property of an instance.
|
|
3
|
+
|
|
4
|
+
## Basic General Usage
|
|
5
|
+
```js
|
|
6
|
+
const Sonoran = require('sonoran.js');
|
|
7
|
+
const instance = Sonoran.instance({
|
|
8
|
+
communityId: 'mycommunity',
|
|
9
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
10
|
+
product: Sonoran.productEnums.CMS
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const whitelist = await instance.cms.verifyWhitelist('459798465498798432');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## verifyWhitelist(whitelistOptions)
|
|
18
|
+
| Parameter | Optional | Type | Note |
|
|
19
|
+
|----------|:-------------:|------:|-----:|
|
|
20
|
+
| whitelistOptions | Yes | String | May just be a string if you'd like to not specify any additional options such as serverId to which will default to the 1 as default or whatever was instanciated with the instance. |
|
|
21
|
+
| whitelistOptions.apiId | Yes | String | Must have at least apiId or accId |
|
|
22
|
+
| whitelistOptions.accId | Yes | String | Must have at least apiId or accId |
|
|
23
|
+
| whitelistOptions.serverId | Yes | Number | Checks whitelist of specific server Id instead of default or set server ID at instance initialization.. |
|
|
24
|
+
|
|
25
|
+
Returns *whitelistResult*;
|
|
26
|
+
| Property | Optional | Type | Note |
|
|
27
|
+
|----------|:-------------:|------:|-----:|
|
|
28
|
+
| whitelistResult.success | No | Boolean | Wether the whitelist verification was successful |
|
|
29
|
+
| whitelistResult.reason | Yes | String | Username if success is truthy, fail reason if success is falsy |
|
|
30
|
+
|
|
31
|
+
### Example Code
|
|
32
|
+
```js
|
|
33
|
+
const Sonoran = require('sonoran.js');
|
|
34
|
+
const instance = Sonoran.instance({
|
|
35
|
+
communityId: 'mycommunity',
|
|
36
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
37
|
+
product: Sonoran.productEnums.CMS,
|
|
38
|
+
serverId: 2
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// This will verify the whitelist of the given API ID or account ID for server id 2 as specified above
|
|
42
|
+
const verification = await instance.cms.verifyWhitelist('459798465498798432');
|
|
43
|
+
// This will verify the whitelist of the given API ID for server id 1 since I specified that
|
|
44
|
+
const verification = await instance.cms.verifyWhitelist({
|
|
45
|
+
apiId: '459798465498798432',
|
|
46
|
+
serverId: 1
|
|
47
|
+
});
|
|
48
|
+
// OR
|
|
49
|
+
// This will verify the whitelist of the given account ID for server id 1 since I specified that
|
|
50
|
+
const verification = await instance.cms.verifyWhitelist({
|
|
51
|
+
accId: 'd5663516-ee35-11e9-9714-5600023b2434',
|
|
52
|
+
serverId: 1
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (verification.success) {
|
|
56
|
+
console.log('Success!', verification.reason);
|
|
57
|
+
} else {
|
|
58
|
+
console.log('Unsuccessful', verfication.reason); // Log the reason it was unsuccessful.
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## getComAccount(params)
|
|
63
|
+
| Parameter | Optional | Type | Note |
|
|
64
|
+
|----------|:-------------:|------:|-----:|
|
|
65
|
+
| params.accId | Yes | String | Must have at least apiId, username or accId |
|
|
66
|
+
| params.username | Yes | String | Must have at least apiId, username or accId |
|
|
67
|
+
| params.apiId | Yes | String | Must have at least apiId, username or accId |
|
|
68
|
+
|
|
69
|
+
Returns *accountResult*;
|
|
70
|
+
| Property | Optional | Type | Note |
|
|
71
|
+
|----------|:-------------:|------:|-----:|
|
|
72
|
+
| accountResult.success | No | Boolean | Wether the whitelist verification was successful |
|
|
73
|
+
| accountResult.account | Yes | Object | Object of the account data |
|
|
74
|
+
| accountResult.reason | Yes | String | Fail reason if success is falsy |
|
|
75
|
+
|
|
76
|
+
### Example Account Data Object
|
|
77
|
+
```js
|
|
78
|
+
{
|
|
79
|
+
accId: '67ceebae-ee63-43c1-a6a6-5234b2210abf',
|
|
80
|
+
active: true,
|
|
81
|
+
username: 'Dawson G.',
|
|
82
|
+
comName: 'Dawson G.',
|
|
83
|
+
primaryIdentifier: '1A-1',
|
|
84
|
+
secondaryIdentifiers: [],
|
|
85
|
+
primaryRank: 'fc2c3825-df41-4485-ad9a-6c2ac900b4f4', // Rank UUID
|
|
86
|
+
secondaryRanks: [
|
|
87
|
+
'331d4ece-b582-4c9c-885b-7060341cf482' // Rank UUID
|
|
88
|
+
],
|
|
89
|
+
primaryDepartment: '00116ef0-9d22-491e-964c-1eb1b6ffd167', // Department UUID
|
|
90
|
+
secondaryDepartments: [
|
|
91
|
+
'7dbedb0e-4df2-4405-b241-cb5dee253ab8' // Department UUID
|
|
92
|
+
],
|
|
93
|
+
joinDate: '2022-02-22 20:28:40.000 -0800',
|
|
94
|
+
totalRankPower: 100,
|
|
95
|
+
comOwner: true,
|
|
96
|
+
isBanned: false,
|
|
97
|
+
lastLogin: '2022-02-22 22:43:46.000 -0800',
|
|
98
|
+
activeApiIds: [
|
|
99
|
+
'235947056630333440'
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Example Code
|
|
106
|
+
```js
|
|
107
|
+
const Sonoran = require('sonoran.js');
|
|
108
|
+
const instance = Sonoran.instance({
|
|
109
|
+
communityId: 'mycommunity',
|
|
110
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
111
|
+
product: Sonoran.productEnums.CMS
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// This will get the community account with the given API ID if there's one found
|
|
115
|
+
const comAccount = await instance.cms.getComAccount({
|
|
116
|
+
apiId: '235947056630333440'
|
|
117
|
+
});
|
|
118
|
+
// OR
|
|
119
|
+
// This will get the community account with the given username if there's one found
|
|
120
|
+
const comAccount = await instance.cms.getComAccount({
|
|
121
|
+
username: 'Dawson G.'
|
|
122
|
+
});
|
|
123
|
+
// OR
|
|
124
|
+
// This will get the community account with the given account ID if there's one found
|
|
125
|
+
const comAccount = await instance.cms.getComAccount({
|
|
126
|
+
accId: '67ceebae-ee63-43c1-a6a6-5234b2210abf'
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (comAccount.success) {
|
|
130
|
+
console.log('Success! Account data:', comAccount.data);
|
|
131
|
+
} else {
|
|
132
|
+
console.log('Unsuccessful', comAccount.reason);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## clockInOut(data)
|
|
137
|
+
| Parameter | Optional | Type | Note |
|
|
138
|
+
|----------|:-------------:|------:|-----:|
|
|
139
|
+
| data.apiId | Yes | String | Must have at least apiId or accId |
|
|
140
|
+
| data.accId | Yes | String | Must have at least apiId or accId |
|
|
141
|
+
| data.forceClockIn | Yes | Boolean | Will start a new clock in and overrite any current clock in |
|
|
142
|
+
|
|
143
|
+
Returns *clockResult*;
|
|
144
|
+
| Property | Optional | Type | Note |
|
|
145
|
+
|----------|:-------------:|------:|-----:|
|
|
146
|
+
| clockResult.success | No | Boolean | Wether the whitelist verification was successful |
|
|
147
|
+
| clockResult.clockedIn | Yes | Boolean | Wether the account was clocked in or out if success is truthy |
|
|
148
|
+
| clockResult.reason | Yes | String | Fail reason if success is falsy |
|
|
149
|
+
|
|
150
|
+
### Example Code
|
|
151
|
+
```js
|
|
152
|
+
const Sonoran = require('sonoran.js');
|
|
153
|
+
const instance = Sonoran.instance({
|
|
154
|
+
communityId: 'mycommunity',
|
|
155
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
156
|
+
product: Sonoran.productEnums.CMS
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// This will override any current clock in and will start a new one on the community account found by the specified API ID if found
|
|
160
|
+
const clockResult = await instance.cms.clockInOut({
|
|
161
|
+
apiId: '235947056630333440',
|
|
162
|
+
forceClockIn: true
|
|
163
|
+
});
|
|
164
|
+
// OR
|
|
165
|
+
// This will either clock in or out the community account found by the specified API ID if found.
|
|
166
|
+
// Will determine to clock in or out depending on what is pending.
|
|
167
|
+
const clockResult = await instance.cms.clockInOut({
|
|
168
|
+
apiId: '235947056630333440'
|
|
169
|
+
});
|
|
170
|
+
// OR
|
|
171
|
+
// This will either clock in or out the community account found by the specified accId if found.
|
|
172
|
+
// Will determine to clock in or out depending on what is pending.
|
|
173
|
+
const clockResult = await instance.cms.clockInOut({
|
|
174
|
+
accId: '67ceebae-ee63-43c1-a6a6-5234b2210abf'
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (clockResult.success) {
|
|
178
|
+
console.log(`Success! Clocked in? ${clockResult.clockedIn ? 'Yes!' : 'No!'}`);
|
|
179
|
+
} else {
|
|
180
|
+
console.log('Unsuccessful', comAccount.reason);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## checkComApiId(apiId)
|
|
185
|
+
| Parameter | Optional | Type |
|
|
186
|
+
|----------|:-------------:|------:|
|
|
187
|
+
| apiId | Yes | String |
|
|
188
|
+
|
|
189
|
+
Returns *checkResult*;
|
|
190
|
+
| Property | Optional | Type | Note |
|
|
191
|
+
|----------|:-------------:|------:|-----:|
|
|
192
|
+
| checkResult.success | No | Boolean | Wether the whitelist verification was successful |
|
|
193
|
+
| checkResult.username | Yes | String | Username for the account found with the API ID given |
|
|
194
|
+
| checkResult.reason | Yes | String | Fail reason if success is falsy |
|
|
195
|
+
|
|
196
|
+
### Example Code
|
|
197
|
+
```js
|
|
198
|
+
const Sonoran = require('sonoran.js');
|
|
199
|
+
const instance = Sonoran.instance({
|
|
200
|
+
communityId: 'mycommunity',
|
|
201
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
202
|
+
product: Sonoran.productEnums.CMS
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const checkResult = await instance.cms.checkComApiId('235947056630333440');
|
|
206
|
+
|
|
207
|
+
if (checkResult.success) {
|
|
208
|
+
console.log(`Success! Account found: ${checkResult.username}`);
|
|
209
|
+
} else {
|
|
210
|
+
console.log('Unsuccessful', checkResult.reason);
|
|
211
|
+
}
|
|
212
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# REST Methods & Usage
|
|
2
|
+
The following methods can be accessed from the `rest` property of an CAD Manager & CMS Manager.
|
|
3
|
+
|
|
4
|
+
## Basic General Usage
|
|
5
|
+
```js
|
|
6
|
+
const Sonoran = require('sonoran.js');
|
|
7
|
+
const instance = Sonoran.instance({
|
|
8
|
+
communityId: 'mycommunity',
|
|
9
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
10
|
+
product: Sonoran.productEnums.CMS
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const subVersion = await instance.cms.rest.request('GET_SUB_VERSION');
|
|
15
|
+
console.log(`Community version is: ${subVersion}`);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.log(err);
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## request(type, [...args])
|
|
22
|
+
| Parameter | Optional | Type | Note |
|
|
23
|
+
|----------|:-------------:|------:|-----:|
|
|
24
|
+
| type | No | String | Must be a valid Sonoran API type (AllAPITypesType) |
|
|
25
|
+
| ...args | Yes | Any | Arguments based on the type given to construct a proper API request |
|
|
26
|
+
|
|
27
|
+
returns *requestResult*;
|
|
28
|
+
| Parameter | Optional | Type | Note |
|
|
29
|
+
|----------|:-------------:|------:|-----:|
|
|
30
|
+
| requestResult | No | Any | Response body from given API request |
|
|
31
|
+
|
|
32
|
+
### Example Code
|
|
33
|
+
```js
|
|
34
|
+
const Sonoran = require('sonoran.js');
|
|
35
|
+
const instance = Sonoran.instance({
|
|
36
|
+
communityId: 'mycommunity',
|
|
37
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
38
|
+
product: Sonoran.productEnums.CMS
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const responseData = await instance.cms.rest.request('VERIFY_WHITELIST', '235947056630333440', undefined, instance.defaultServerId);
|
|
43
|
+
console.log(responseData);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(err);
|
|
46
|
+
}
|
|
47
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sonoransoftware/sonoran.js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Sonoran.js is a library that allows you to interact with the Sonoran CAD and Sonoran CMS API. Based off of and utilizes several Discord.js library techniques for ease of use.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"start": "ts-node src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/Sonoran-Software/Sonoran.js.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^17.0.21",
|
|
19
|
+
"@types/node-fetch": "^2.6.1",
|
|
20
|
+
"eslint": "^8.10.0",
|
|
21
|
+
"eslint-config-prettier": "^8.5.0",
|
|
22
|
+
"eslint-plugin-import": "^2.25.4",
|
|
23
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
24
|
+
"prettier": "^2.5.1",
|
|
25
|
+
"ts-loader": "^9.2.7",
|
|
26
|
+
"ts-node": "^10.7.0",
|
|
27
|
+
"tslint": "^6.1.3",
|
|
28
|
+
"typescript": "^4.6.2"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=16.9.0"
|
|
32
|
+
},
|
|
33
|
+
"nodemonConfig": {
|
|
34
|
+
"ext": "*.ts, *.json"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@discordjs/collection": "^0.5.0",
|
|
38
|
+
"@sapphire/async-queue": "^1.3.0",
|
|
39
|
+
"@sapphire/snowflake": "^3.2.0",
|
|
40
|
+
"node-fetch": "^2.6.5"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Sonoran.js
|
|
2
|
+
Sonoran.js is a library that allows you to interact with the [Sonoran CAD](https://sonorancad.com/) and [Sonoran CMS](https://sonorancms.com/) API. Based off of and utilizes several Discord.js library techniques for ease of use.
|
|
3
|
+
|
|
4
|
+
## Example Instance Setup
|
|
5
|
+
|
|
6
|
+
Utilizing both Sonoran CMS & Sonoran CAD
|
|
7
|
+
```js
|
|
8
|
+
const Sonoran = require('sonoran.js');
|
|
9
|
+
const instance = Sonoran.instance({
|
|
10
|
+
cadCommunityId: 'mycommunity',
|
|
11
|
+
cadApiKey: 'DF58F1E-FD8A-44C5-BA',
|
|
12
|
+
cmsCommunityId: 'mycommunity',
|
|
13
|
+
cmsApiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf'
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Utilizing just Sonoran CMS or Sonoran CAD
|
|
18
|
+
```js
|
|
19
|
+
const Sonoran = require('sonoran.js');
|
|
20
|
+
const instance = Sonoran.instance({
|
|
21
|
+
communityId: 'mycommunity',
|
|
22
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
23
|
+
product: Sonoran.productEnums.CMS
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example Method Usage
|
|
28
|
+
```js
|
|
29
|
+
const Sonoran = require('sonoran.js');
|
|
30
|
+
const instance = Sonoran.instance({
|
|
31
|
+
communityId: 'mycommunity',
|
|
32
|
+
apiKey: 'e6ba9d68-ca7a-4e59-a9e2-93e275b4e0bf',
|
|
33
|
+
product: Sonoran.productEnums.CMS,
|
|
34
|
+
serverId: 2 // Optional - The default server id for both CAD & CMS is 1
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// This will verify the whitelist of the given API ID or account ID for server id 2 as specified above
|
|
38
|
+
instance.cms.verifyWhitelist('459798465498798432');
|
|
39
|
+
// OR
|
|
40
|
+
// This will verify the whitelist of the given API ID for server id 1 since I specified that
|
|
41
|
+
instance.cms.verifyWhitelist({
|
|
42
|
+
apiId: '459798465498798432',
|
|
43
|
+
serverId: 1
|
|
44
|
+
});
|
|
45
|
+
// OR
|
|
46
|
+
// This will verify the whitelist of the given account ID for server id 1 since I specified that
|
|
47
|
+
instance.cms.verifyWhitelist({
|
|
48
|
+
accId: 'd5663516-ee35-11e9-9714-5600023b2434',
|
|
49
|
+
serverId: 1
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Further Documentation
|
|
54
|
+
More documentation for Sonoran CAD specific methods and usage can be found [here](/docs/CAD-Methods-and-Usage.md), Sonoran CMS specific methods and usage can be found [here](/docs/CMS-Methods-and-Usage.md), and usage information for the REST class [here](/docs/REST-Methods-and-Usage.md).
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { CADNewDispatchBuilderOptions } from '../../constants';
|
|
2
|
+
import { CADDispatchOriginEnums, CADDispatchStatusEnums } from '../../libs/rest/src';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a constructed dispatch call for API requests
|
|
6
|
+
*/
|
|
7
|
+
export class DispatchCallBuilder {
|
|
8
|
+
public readonly data: CADNewDispatchBuilderOptions;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Dispatch Call Builder used for API calls with Sonoran CAD to create a new dispatch call.
|
|
12
|
+
* @param data Data Options (CADNewDispatchBuilderOptions) used to build the new dispatch call
|
|
13
|
+
*/
|
|
14
|
+
public constructor(data: CADNewDispatchBuilderOptions = {}) {
|
|
15
|
+
this.data = { ...data };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sets the origin for this dispatch call
|
|
20
|
+
* @param origin Origin enum used for this dispatch call for information purposes
|
|
21
|
+
*/
|
|
22
|
+
public setOrigin(origin: CADDispatchOriginEnums): this {
|
|
23
|
+
this.data.origin = origin;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sets the status for this dispatch call
|
|
29
|
+
* @param status Status enum used for the dispatch call for information purposes
|
|
30
|
+
*/
|
|
31
|
+
public setStatus(status: CADDispatchStatusEnums): this {
|
|
32
|
+
this.data.status = status;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Sets the priority level for this dispatch call
|
|
38
|
+
* @param priority Priority level used for the dispatch call for information purposes
|
|
39
|
+
*/
|
|
40
|
+
public setPriority(priority: 1 | 2 | 3): this {
|
|
41
|
+
this.data.priority = priority;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets the block for this dispatch call
|
|
47
|
+
* @param block Block used for the dispatch call for information purposes
|
|
48
|
+
*/
|
|
49
|
+
public setBlock(block: string): this {
|
|
50
|
+
this.data.block = block;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Sets the address for this dispatch call
|
|
56
|
+
* @param address Address used for the dispatch call for information purposes
|
|
57
|
+
*/
|
|
58
|
+
public setAddress(address: string): this {
|
|
59
|
+
this.data.address = address;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Sets the postal for this dispatch call
|
|
65
|
+
* @param postal Postal used for the dispatch call for information purposes
|
|
66
|
+
*/
|
|
67
|
+
public setPostal(postal: string): this {
|
|
68
|
+
this.data.postal = postal;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Sets the title for this dispatch call
|
|
74
|
+
* @param title Title used for the dispatch call for information purposes
|
|
75
|
+
*/
|
|
76
|
+
public setTitle(title: string): this {
|
|
77
|
+
this.data.title = title;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Sets the code for this dispatch call
|
|
83
|
+
* @param code Code used for the dispatch call for information purposes
|
|
84
|
+
*/
|
|
85
|
+
public setCode(code: string): this {
|
|
86
|
+
this.data.code = code;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Sets the primary tracking preference for this dispatch call
|
|
92
|
+
* @param primaryUnit Primary unit identifier
|
|
93
|
+
*/
|
|
94
|
+
public setPrimary(primaryUnit: number): this {
|
|
95
|
+
this.data.primary = primaryUnit;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Sets the track primary preference for this dispatch call
|
|
101
|
+
* @param preference Preference for tracking primary
|
|
102
|
+
*/
|
|
103
|
+
public setTrackPrimaryPreference(preference: boolean): this {
|
|
104
|
+
this.data.trackPrimary = preference;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sets the description for this dispatch call
|
|
110
|
+
* @param description Description for a dispatch call
|
|
111
|
+
*/
|
|
112
|
+
public setDescription(description: string): this {
|
|
113
|
+
this.data.description = description;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Sets metadata for this dispatch call that can be used later on
|
|
119
|
+
* @param metaData Dictionary of metadata to store with a dispatch call, can be used later on
|
|
120
|
+
*/
|
|
121
|
+
public setMetadata(metaData: Record<string, string>): this {
|
|
122
|
+
this.data.metaData = metaData;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sets specified units for this dispatch call
|
|
128
|
+
* @param units Units to be removed from a call
|
|
129
|
+
*/
|
|
130
|
+
public setUnits(units: string[]): this {
|
|
131
|
+
this.data.units = units;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Adds specified units from this dispatch call
|
|
137
|
+
* @param units Units to be removed from a call
|
|
138
|
+
*/
|
|
139
|
+
public addUnits(...units: string[]): this {
|
|
140
|
+
this.data.units?.push(...units);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Removes specified units from this dispatch call
|
|
146
|
+
* @param units Units to be removed from a call
|
|
147
|
+
*/
|
|
148
|
+
public removeUnits(...units: string[]): this {
|
|
149
|
+
this.data.units?.filter((unit) => !units.includes(unit));
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Transforms the dispatch call to a plain object
|
|
155
|
+
*/
|
|
156
|
+
public toJSON(): CADNewDispatchBuilderOptions{
|
|
157
|
+
return { ...this.data };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DispatchCall';
|