@sonoransoftware/sonoran.js 1.0.26 → 1.0.27

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.
@@ -113,7 +113,12 @@ class SequentialHandler {
113
113
  return parsedRes;
114
114
  }
115
115
  else if (res.status === 400 || res.status === 401 || res.status === 404) {
116
- throw new errors_1.APIError(parsedRes, data.type, data.fullUrl, res.status, data);
116
+ if (typeof parsedRes === 'object' && !(parsedRes === null || parsedRes === void 0 ? void 0 : parsedRes.authorized)) {
117
+ return parsedRes;
118
+ }
119
+ else {
120
+ throw new errors_1.APIError(parsedRes, data.type, data.fullUrl, res.status, data);
121
+ }
117
122
  }
118
123
  else if (res.status === 429) {
119
124
  const timeout = setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonoransoftware/sonoran.js",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
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
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -50,5 +50,131 @@ instance.cms.verifyWhitelist({
50
50
  });
51
51
  ```
52
52
 
53
+ ## CAD Functions
54
+ ### getAccount
55
+ Returns the user's account object.
56
+ #### Argument `params`
57
+ ##### Type: `object` `{apiId?, username?}`
58
+ ```js
59
+ const params = {
60
+ apiId: '',
61
+ username: 'SomeUser',
62
+ };
63
+ // Get user account object
64
+ const account = await instance.cad.getAccount(params);
65
+ ```
66
+
67
+ ## CMS Functions
68
+ ### verifyWhitelist(obj)
69
+ Verifies that a user is whitelisted in the specified server.
70
+ #### Arugment `params`
71
+ ##### Type `object` `{accId?: string, apiId?: string, username?: string, discord?: string, uniqueId?: number, serverId?: number}`
72
+ ##### Type `string` (Account UUID or API ID as a string)
73
+ *Note: If passing a `string` for data (Account UUID or API ID) the `serverId` will default to `1`*
74
+ ```js
75
+ const params = {
76
+ accId: '',
77
+ apiId: '',
78
+ username: '',
79
+ discord: '',
80
+ uniqueId: 1234,
81
+ serverId: 1
82
+ };
83
+ // Check if user with Unique ID 1234 is whitelisted on Server ID 1
84
+ const isWhitelisted = await instance.cms.verifyWhitelist(params);
85
+ ```
86
+
87
+ ### getFullWhitelist()
88
+ Returns a full list of whitelisted users in the specified server.
89
+ #### Arugment `serverId`
90
+ ##### Type `number` `1`
91
+ ```js
92
+ // Get the full whitelist for server ID 1
93
+ const fullWhitelist = await instance.cms.getFullWhitelist(1);
94
+ ```
95
+
96
+ ### getComAccount(obj)
97
+ Returns the user's account object
98
+ #### Arugment `params`
99
+ ##### Type `object` `{accId?: string, apiId?: string, username?: string, discord?: string, uniqueId?: string}`
100
+ ```js
101
+ const params = {
102
+ accId: '',
103
+ apiId: '',
104
+ username: '',
105
+ discord: '',
106
+ uniqueId: '1234',
107
+ };
108
+ // Get a user's account as an object
109
+ const getAccount = await instance.cms.getComAccount(params);
110
+ ```
111
+
112
+ ### getAccountRanks(obj)
113
+ Returns a user account's ranks
114
+ #### Arugment `params`
115
+ ##### Type `object` `{accId?: string, apiId?: string, username?: string, discord?: string, uniqueId?: string}`
116
+ ```js
117
+ const params = {
118
+ accId: '',
119
+ apiId: '',
120
+ username: '',
121
+ discord: '',
122
+ uniqueId: '1234',
123
+ };
124
+ // Get a user's ranks
125
+ const getRanks = await instance.cms.getAccountRanks(params);
126
+ ```
127
+
128
+ ### clockInOut(obj)
129
+ Clock a user in or out in the CMS system
130
+ #### Arugment `obj`
131
+ ##### Type `object` `{accId?: string, apiId?: string, forceClockIn?: boolean, discord?: string, uniqueId?: string}`
132
+ ```js
133
+ const params = {
134
+ accId: '',
135
+ apiId: '',
136
+ forceClockIn: true,
137
+ discord: '',
138
+ uniqueId: '1234',
139
+ };
140
+ // Clocks a user in or out
141
+ const clock = await instance.cms.clockInOut(params);
142
+ ```
143
+
144
+ ### checkComApiId(apiId)
145
+ Checks if a given API ID is attatched to any account within the community, and if true, returns the username of the associated account.
146
+ #### Arugment `apiId`
147
+ ##### Type `string` `1234`
148
+ ```js
149
+ // Checks if API ID is attatched to a user, returns username if true
150
+ const apiIdUsername = await instance.cms.checkComApiId('1234');
151
+ ```
152
+
153
+ ### getDepartments()
154
+ Gets all department information for a CMS community
155
+ ```js
156
+ // Gets department information for community
157
+ const getDepts = await instance.cms.getDepartments();
158
+ ```
159
+
160
+ ### setAccountRanks(obj, apiId, accId, username, discord, uniqueId)
161
+ Gets all department information for a CMS community
162
+ #### Arugment `params`
163
+ ##### Type `object` `{set?: string[]; add?: string[]; remove?: string[]}`
164
+ #### Arguments `apiId`, `accId`, `username`, `discord`, `uniqueId`
165
+ ##### Type `string` or `undefined`
166
+ *Note: Only one identifier is required (Discord, accID, etc.) pass in undefined for variables you are not searching by*
167
+ ```js
168
+ const params = {
169
+ set: ['9ad00ded-93d1-422e-8470-d2515f02652c'],
170
+ add: undefined,
171
+ remove: undefined
172
+ };
173
+ // Wipe users existing ranks, and set ones provided
174
+ // Add and Remove are undefined as we don't want to call them here
175
+ // Sets account ranks by the discord ID parameter
176
+ const setRanks = await instance.cms.setAccountRanks(params, undefined, undefined, undefined, '12345678', undefined);
177
+ ```
178
+
53
179
  ## 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).
180
+ 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).
@@ -134,7 +134,11 @@ export class SequentialHandler implements IHandler {
134
134
  if (res.ok) {
135
135
  return parsedRes;
136
136
  } else if (res.status === 400 || res.status === 401 || res.status === 404) {
137
- throw new APIError(parsedRes as string, data.type, data.fullUrl, res.status, data);
137
+ if (typeof parsedRes === 'object' && !(parsedRes as any)?.authorized) {
138
+ return parsedRes;
139
+ } else {
140
+ throw new APIError(parsedRes as string, data.type, data.fullUrl, res.status, data);
141
+ }
138
142
  } else if (res.status === 429) {
139
143
  const timeout = setTimeout(() => {
140
144
  this.manager.removeRateLimit(data.requestTypeId);
@@ -155,7 +159,7 @@ export class SequentialHandler implements IHandler {
155
159
  if (res.headers.get('Content-Type')?.startsWith('application/json')) {
156
160
  return res.json();
157
161
  }
158
-
162
+
159
163
  return res.text();
160
164
  }
161
165
  }