@unboundcx/sdk 4.13.146-security.3 → 4.13.146-security.4
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/README.md +6 -0
- package/package.json +1 -1
- package/services/login.js +75 -1
package/README.md
CHANGED
|
@@ -159,6 +159,12 @@ await api.login.login('username', 'password');
|
|
|
159
159
|
await api.login.logout();
|
|
160
160
|
await api.login.validate();
|
|
161
161
|
await api.login.changePassword('current', 'new');
|
|
162
|
+
|
|
163
|
+
// User sessions (refresh-token families) -- list/revoke your own, or an
|
|
164
|
+
// account admin acting on another user in the same account
|
|
165
|
+
await api.login.listSessions({ includeClosed: true });
|
|
166
|
+
await api.login.revokeSession(sessionId);
|
|
167
|
+
await api.login.revokeAllSessions({ keepCurrent: true });
|
|
162
168
|
```
|
|
163
169
|
|
|
164
170
|
#### Objects (`api.objects`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.146-security.
|
|
3
|
+
"version": "4.13.146-security.4",
|
|
4
4
|
"description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/services/login.js
CHANGED
|
@@ -146,7 +146,7 @@ export class LoginService {
|
|
|
146
146
|
body: { email },
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
const result = await internalRequest(this.sdk,
|
|
149
|
+
const result = await internalRequest(this.sdk,
|
|
150
150
|
'/login/forgotPassword',
|
|
151
151
|
'POST',
|
|
152
152
|
options,
|
|
@@ -154,4 +154,78 @@ export class LoginService {
|
|
|
154
154
|
);
|
|
155
155
|
return result;
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* User sessions (one row per refresh-token family). userId defaults to
|
|
160
|
+
* the caller; passing someone else's userId requires the caller to hold
|
|
161
|
+
* admin:user:manage AND that user to be in the caller's own account --
|
|
162
|
+
* the API 403s otherwise.
|
|
163
|
+
* @param {object} [params]
|
|
164
|
+
* @param {string} [params.userId] -- defaults to the caller
|
|
165
|
+
* @param {boolean} [params.includeClosed] -- also return closed
|
|
166
|
+
* (revoked/expired) sessions from the last 30 days
|
|
167
|
+
* @returns {Promise<{ sessions: Array<object> }>}
|
|
168
|
+
*/
|
|
169
|
+
async listSessions({ userId, includeClosed } = {}) {
|
|
170
|
+
const query = {};
|
|
171
|
+
if (userId) query.userId = userId;
|
|
172
|
+
if (includeClosed) query.includeClosed = true;
|
|
173
|
+
|
|
174
|
+
const options = { query };
|
|
175
|
+
const result = await internalRequest(this.sdk,
|
|
176
|
+
'/login/sessions',
|
|
177
|
+
'GET',
|
|
178
|
+
options,
|
|
179
|
+
);
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Revoke a single session (refresh-token family) by id.
|
|
185
|
+
* @param {string} sessionId
|
|
186
|
+
* @param {object} [params]
|
|
187
|
+
* @param {string} [params.userId] -- defaults to the caller; same
|
|
188
|
+
* self-or-admin-same-account rule as listSessions
|
|
189
|
+
* @returns {Promise<{ revoked: boolean, id: string, current: boolean }>}
|
|
190
|
+
*/
|
|
191
|
+
async revokeSession(sessionId, { userId } = {}) {
|
|
192
|
+
this.sdk.validateParams(
|
|
193
|
+
{ sessionId },
|
|
194
|
+
{
|
|
195
|
+
sessionId: { type: 'string', required: true },
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const options = {};
|
|
200
|
+
if (userId) options.body = { userId };
|
|
201
|
+
|
|
202
|
+
const result = await internalRequest(this.sdk,
|
|
203
|
+
`/login/sessions/${sessionId}`,
|
|
204
|
+
'DELETE',
|
|
205
|
+
options,
|
|
206
|
+
);
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Revoke every live session for a user.
|
|
212
|
+
* @param {object} [params]
|
|
213
|
+
* @param {string} [params.userId] -- defaults to the caller
|
|
214
|
+
* @param {boolean} [params.keepCurrent] -- when acting on your own
|
|
215
|
+
* sessions, leave the session you're calling from untouched
|
|
216
|
+
* @returns {Promise<{ revoked: number }>}
|
|
217
|
+
*/
|
|
218
|
+
async revokeAllSessions({ userId, keepCurrent } = {}) {
|
|
219
|
+
const body = {};
|
|
220
|
+
if (userId) body.userId = userId;
|
|
221
|
+
if (keepCurrent) body.keepCurrent = true;
|
|
222
|
+
|
|
223
|
+
const options = { body };
|
|
224
|
+
const result = await internalRequest(this.sdk,
|
|
225
|
+
'/login/sessions/revoke-all',
|
|
226
|
+
'POST',
|
|
227
|
+
options,
|
|
228
|
+
);
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
157
231
|
}
|