@scalekit-sdk/node 2.1.6 → 2.1.8
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/buf.gen.yaml +1 -0
- package/lib/auth.d.ts +41 -9
- package/lib/auth.js +44 -12
- package/lib/auth.js.map +1 -1
- package/lib/connection.d.ts +195 -21
- package/lib/connection.js +197 -23
- package/lib/connection.js.map +1 -1
- package/lib/core.d.ts +2 -2
- package/lib/core.js +13 -12
- package/lib/core.js.map +1 -1
- package/lib/directory.d.ts +293 -40
- package/lib/directory.js +308 -44
- package/lib/directory.js.map +1 -1
- package/lib/domain.d.ts +166 -18
- package/lib/domain.js +178 -29
- package/lib/domain.js.map +1 -1
- package/lib/organization.d.ts +407 -40
- package/lib/organization.js +433 -49
- package/lib/organization.js.map +1 -1
- package/lib/permission.d.ts +179 -35
- package/lib/permission.js +190 -38
- package/lib/permission.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.d.ts +3 -3
- package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js +2 -2
- package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.d.ts +16 -16
- package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js +21 -21
- package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.d.ts +82 -0
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js +90 -0
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.d.ts +647 -0
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js +993 -0
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.d.ts +142 -0
- package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js +165 -1
- package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.d.ts +1 -10
- package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js +0 -9
- package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +28 -63
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +9 -90
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.d.ts +6 -6
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js +5 -5
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +19 -30
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +22 -31
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +2 -2
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +1 -1
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
- package/lib/role.d.ts +252 -56
- package/lib/role.js +262 -62
- package/lib/role.js.map +1 -1
- package/lib/scalekit.d.ts +323 -54
- package/lib/scalekit.js +354 -76
- package/lib/scalekit.js.map +1 -1
- package/lib/session.d.ts +235 -22
- package/lib/session.js +237 -24
- package/lib/session.js.map +1 -1
- package/lib/types/organization.d.ts +3 -0
- package/lib/user.d.ts +571 -53
- package/lib/user.js +598 -89
- package/lib/user.js.map +1 -1
- package/lib/webauthn.d.ts +33 -0
- package/lib/webauthn.js +80 -0
- package/lib/webauthn.js.map +1 -0
- package/package.json +2 -2
- package/src/auth.ts +53 -19
- package/src/connection.ts +237 -62
- package/src/core.ts +39 -33
- package/src/directory.ts +356 -98
- package/src/domain.ts +215 -68
- package/src/organization.ts +506 -105
- package/src/permission.ts +234 -88
- package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +3 -3
- package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +24 -24
- package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +89 -0
- package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +1263 -0
- package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +217 -0
- package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +1 -10
- package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +42 -129
- package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +6 -6
- package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +28 -43
- package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +3 -3
- package/src/role.ts +336 -136
- package/src/scalekit.ts +478 -149
- package/src/session.ts +266 -63
- package/src/types/organization.ts +4 -0
- package/src/user.ts +675 -168
- package/src/webauthn.ts +98 -0
- package/tests/organization.test.ts +16 -0
package/src/session.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { PartialMessage } from
|
|
2
|
-
import { PromiseClient } from
|
|
3
|
-
import GrpcConnect from
|
|
4
|
-
import CoreClient from
|
|
5
|
-
import { SessionService } from
|
|
6
|
-
import {
|
|
1
|
+
import { PartialMessage } from "@bufbuild/protobuf";
|
|
2
|
+
import { PromiseClient } from "@connectrpc/connect";
|
|
3
|
+
import GrpcConnect from "./connect";
|
|
4
|
+
import CoreClient from "./core";
|
|
5
|
+
import { SessionService } from "./pkg/grpc/scalekit/v1/sessions/sessions_connect";
|
|
6
|
+
import {
|
|
7
7
|
SessionDetailsRequest,
|
|
8
8
|
SessionDetails,
|
|
9
9
|
UserSessionDetailsRequest,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
RevokeSessionRequest,
|
|
13
13
|
RevokeSessionResponse,
|
|
14
14
|
RevokeAllUserSessionsRequest,
|
|
15
|
-
RevokeAllUserSessionsResponse
|
|
16
|
-
} from
|
|
17
|
-
import { Timestamp } from
|
|
15
|
+
RevokeAllUserSessionsResponse,
|
|
16
|
+
} from "./pkg/grpc/scalekit/v1/sessions/sessions_pb";
|
|
17
|
+
import { Timestamp } from "@bufbuild/protobuf";
|
|
18
18
|
|
|
19
19
|
export default class SessionClient {
|
|
20
20
|
private client: PromiseClient<typeof SessionService>;
|
|
@@ -27,45 +27,126 @@ export default class SessionClient {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* Retrieves comprehensive metadata and status for a specific user session.
|
|
31
|
+
*
|
|
32
|
+
* Fetches complete session information including authentication status, device details,
|
|
33
|
+
* IP address, geolocation, and expiration timelines.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} sessionId - The session identifier to retrieve (format: "ses_...")
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<SessionDetails>} Session details containing:
|
|
38
|
+
* - sessionId: Unique session identifier
|
|
39
|
+
* - userId: User who owns this session
|
|
40
|
+
* - organizationId: Organization context for the session
|
|
41
|
+
* - status: Current session status ('active', 'expired', 'revoked', 'logout')
|
|
42
|
+
* - deviceInfo: Browser and operating system information
|
|
43
|
+
* - ipAddress: IP address from which session was created
|
|
44
|
+
* - geoLocation: Geographic location data (city, region, country)
|
|
45
|
+
* - createTime: When the session was created
|
|
46
|
+
* - lastActivityTime: Most recent session activity
|
|
47
|
+
* - idleExpirationTime: When session expires due to inactivity
|
|
48
|
+
* - absoluteExpirationTime: Maximum session lifetime
|
|
49
|
+
* - expirationTime: Actual expiration time (if session has ended)
|
|
50
|
+
*
|
|
51
|
+
* @throws {Error} If the session is not found
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Get session details
|
|
55
|
+
* const session = await scalekitClient.session.getSession('ses_123456');
|
|
56
|
+
*
|
|
57
|
+
* console.log('Status:', session.status);
|
|
58
|
+
* console.log('User:', session.userId);
|
|
59
|
+
* console.log('Device:', session.deviceInfo);
|
|
60
|
+
* console.log('Location:', session.geoLocation);
|
|
61
|
+
* console.log('Last active:', session.lastActivityTime);
|
|
62
|
+
*
|
|
63
|
+
*
|
|
64
|
+
* @see {@link https://docs.scalekit.com/apis/#tag/sessions | Get Session API}
|
|
65
|
+
* @see {@link getUserSessions} - List all sessions for a user
|
|
66
|
+
* @see {@link revokeSession} - Revoke this session
|
|
33
67
|
*/
|
|
34
68
|
async getSession(sessionId: string): Promise<SessionDetails> {
|
|
35
|
-
return this.coreClient.connectExec(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
sessionId
|
|
39
|
-
}
|
|
40
|
-
);
|
|
69
|
+
return this.coreClient.connectExec(this.client.getSession, {
|
|
70
|
+
sessionId,
|
|
71
|
+
});
|
|
41
72
|
}
|
|
42
73
|
|
|
43
74
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
53
|
-
* @
|
|
75
|
+
* Retrieves a paginated list of all sessions for a specific user across all devices and browsers.
|
|
76
|
+
*
|
|
77
|
+
* Lists all user sessions with support for filtering by status and time range. Essential for
|
|
78
|
+
* displaying active sessions in account management, auditing user activity, verifying authentication
|
|
79
|
+
* across devices, or identifying suspicious sessions. Use filtering to find active sessions,
|
|
80
|
+
* sessions from specific time periods, or sessions with particular statuses.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} userId - The user identifier (format: "usr_...")
|
|
83
|
+
* @param {object} [options] - Optional pagination and filtering parameters
|
|
84
|
+
* @param {number} [options.pageSize] - Number of sessions to return per page
|
|
85
|
+
* @param {string} [options.pageToken] - Token for retrieving the next page from previous response
|
|
86
|
+
* @param {object} [options.filter] - Filter criteria for sessions
|
|
87
|
+
* @param {string[]} [options.filter.status] - Filter by status values: 'active', 'expired', 'revoked', 'logout'
|
|
88
|
+
* (multiple values use OR logic)
|
|
89
|
+
* @param {Date} [options.filter.startTime] - Include sessions created on or after this time
|
|
90
|
+
* @param {Date} [options.filter.endTime] - Include sessions created before this time
|
|
91
|
+
* (must be after startTime)
|
|
92
|
+
*
|
|
93
|
+
* @returns {Promise<UserSessionDetails>} Response containing:
|
|
94
|
+
* - sessions: Array of session objects with device info, location, and status
|
|
95
|
+
* - nextPageToken: Token for fetching the next page
|
|
96
|
+
* - totalSize: Total number of sessions matching the filter
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // List all active sessions for a user
|
|
100
|
+
* const response = await scalekitClient.session.getUserSessions('usr_123456', {
|
|
101
|
+
* filter: { status: ['active'] },
|
|
102
|
+
* pageSize: 20
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* console.log(`User has ${response.totalSize} active sessions`);
|
|
106
|
+
* response.sessions.forEach(session => {
|
|
107
|
+
* console.log(`- ${session.deviceInfo} from ${session.geoLocation?.city}`);
|
|
108
|
+
* console.log(` Last active: ${session.lastActivityTime}`);
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* // Get all sessions (active and inactive)
|
|
113
|
+
* const response = await scalekitClient.session.getUserSessions('usr_123456');
|
|
114
|
+
* console.log(`Total sessions: ${response.totalSize}`);
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Find sessions from the last 7 days
|
|
118
|
+
* const sevenDaysAgo = new Date();
|
|
119
|
+
* sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
|
|
120
|
+
*
|
|
121
|
+
* const response = await scalekitClient.session.getUserSessions('usr_123456', {
|
|
122
|
+
* filter: {
|
|
123
|
+
* startTime: sevenDaysAgo,
|
|
124
|
+
* status: ['active', 'logout']
|
|
125
|
+
* }
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* console.log(`Sessions in last 7 days: ${response.sessions.length}`);
|
|
129
|
+
*
|
|
130
|
+
*
|
|
131
|
+
* @see {@link https://docs.scalekit.com/apis/#tag/sessions | List User Sessions API}
|
|
132
|
+
* @see {@link getSession} - Get details of a specific session
|
|
133
|
+
* @see {@link revokeSession} - Revoke a specific session
|
|
134
|
+
* @see {@link revokeAllUserSessions} - Revoke all sessions for user
|
|
54
135
|
*/
|
|
55
136
|
async getUserSessions(
|
|
56
137
|
userId: string,
|
|
57
138
|
options?: {
|
|
58
|
-
pageSize?: number
|
|
59
|
-
pageToken?: string
|
|
139
|
+
pageSize?: number;
|
|
140
|
+
pageToken?: string;
|
|
60
141
|
filter?: {
|
|
61
|
-
status?: string[]
|
|
62
|
-
startTime?: Date
|
|
63
|
-
endTime?: Date
|
|
64
|
-
}
|
|
142
|
+
status?: string[];
|
|
143
|
+
startTime?: Date;
|
|
144
|
+
endTime?: Date;
|
|
145
|
+
};
|
|
65
146
|
}
|
|
66
147
|
): Promise<UserSessionDetails> {
|
|
67
148
|
const request: PartialMessage<UserSessionDetailsRequest> = {
|
|
68
|
-
userId
|
|
149
|
+
userId,
|
|
69
150
|
};
|
|
70
151
|
|
|
71
152
|
if (options?.pageSize !== undefined) {
|
|
@@ -78,57 +159,179 @@ export default class SessionClient {
|
|
|
78
159
|
|
|
79
160
|
if (options?.filter) {
|
|
80
161
|
const filter = new UserSessionFilter();
|
|
81
|
-
|
|
162
|
+
|
|
82
163
|
if (options.filter.status) {
|
|
83
164
|
filter.status = options.filter.status;
|
|
84
165
|
}
|
|
85
|
-
|
|
166
|
+
|
|
86
167
|
if (options.filter.startTime) {
|
|
87
168
|
filter.startTime = Timestamp.fromDate(options.filter.startTime);
|
|
88
169
|
}
|
|
89
|
-
|
|
170
|
+
|
|
90
171
|
if (options.filter.endTime) {
|
|
91
172
|
filter.endTime = Timestamp.fromDate(options.filter.endTime);
|
|
92
173
|
}
|
|
93
|
-
|
|
174
|
+
|
|
94
175
|
request.filter = filter;
|
|
95
176
|
}
|
|
96
177
|
|
|
97
|
-
return this.coreClient.connectExec(
|
|
98
|
-
this.client.getUserSessions,
|
|
99
|
-
request
|
|
100
|
-
);
|
|
178
|
+
return this.coreClient.connectExec(this.client.getUserSessions, request);
|
|
101
179
|
}
|
|
102
180
|
|
|
103
181
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
182
|
+
* Immediately invalidates a specific user session by setting its status to 'revoked'.
|
|
183
|
+
*
|
|
184
|
+
* Terminates a single session, forcing the user to re-authenticate on that specific device.
|
|
185
|
+
* Use this for session-level logout, terminating suspicious sessions, forcing re-authentication
|
|
186
|
+
* on specific devices, or implementing "logout from this device" functionality. The revocation
|
|
187
|
+
* is instantaneous and irreversible - once revoked, the session cannot be used for any future
|
|
188
|
+
* API requests or application access.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} sessionId - The session identifier to revoke (format: "ses_...")
|
|
191
|
+
*
|
|
192
|
+
* @returns {Promise<RevokeSessionResponse>} Response containing:
|
|
193
|
+
* - sessionId: The ID of the revoked session
|
|
194
|
+
* - userId: User who owned the session
|
|
195
|
+
* - revokedAt: Timestamp when the session was revoked
|
|
196
|
+
* - status: Updated session status ('revoked')
|
|
197
|
+
*
|
|
198
|
+
* @throws {Error} If the session is not found
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* // Revoke a specific session
|
|
202
|
+
* const response = await scalekitClient.session.revokeSession('ses_123456');
|
|
203
|
+
* console.log('Session revoked at:', response.revokedAt);
|
|
204
|
+
* console.log('Status:', response.status); // 'revoked'
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* // Logout from specific device
|
|
208
|
+
* app.post('/api/sessions/:sessionId/logout', async (req, res) => {
|
|
209
|
+
* const { sessionId } = req.params;
|
|
210
|
+
*
|
|
211
|
+
* try {
|
|
212
|
+
* await scalekitClient.session.revokeSession(sessionId);
|
|
213
|
+
* res.json({ message: 'Session terminated successfully' });
|
|
214
|
+
* } catch (error) {
|
|
215
|
+
* res.status(500).json({ error: 'Failed to revoke session' });
|
|
216
|
+
* }
|
|
217
|
+
* });
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* // Revoke suspicious session
|
|
221
|
+
* const session = await scalekitClient.session.getSession(sessionId);
|
|
222
|
+
*
|
|
223
|
+
* if (session.geoLocation?.country !== expectedCountry) {
|
|
224
|
+
* console.log('Suspicious session detected');
|
|
225
|
+
* console.log(`Location: ${session.geoLocation?.city}, ${session.geoLocation?.country}`);
|
|
226
|
+
* console.log(`IP: ${session.ipAddress}`);
|
|
227
|
+
*
|
|
228
|
+
* await scalekitClient.session.revokeSession(sessionId);
|
|
229
|
+
* console.log('Session revoked for security');
|
|
230
|
+
*
|
|
231
|
+
* // Send security alert to user
|
|
232
|
+
* await sendSecurityAlert(session.userId, {
|
|
233
|
+
* message: 'Unusual login location detected and session terminated',
|
|
234
|
+
* location: session.geoLocation
|
|
235
|
+
* });
|
|
236
|
+
* }
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* // Revoke all non-current sessions for a user
|
|
240
|
+
* const response = await scalekitClient.session.getUserSessions(userId, {
|
|
241
|
+
* filter: { status: ['active'] }
|
|
242
|
+
* });
|
|
243
|
+
*
|
|
244
|
+
* for (const session of response.sessions) {
|
|
245
|
+
* if (session.sessionId !== currentSessionId) {
|
|
246
|
+
* await scalekitClient.session.revokeSession(session.sessionId);
|
|
247
|
+
* console.log(`Revoked session from: ${session.deviceInfo}`);
|
|
248
|
+
* }
|
|
249
|
+
* }
|
|
250
|
+
*
|
|
251
|
+
* @see {@link https://docs.scalekit.com/apis/#tag/sessions | Revoke Session API}
|
|
252
|
+
* @see {@link revokeAllUserSessions} - Revoke all sessions for a user
|
|
253
|
+
* @see {@link getUserSessions} - List user sessions to find suspicious ones
|
|
254
|
+
* @see {@link getSession} - Get session details before revoking
|
|
107
255
|
*/
|
|
108
256
|
async revokeSession(sessionId: string): Promise<RevokeSessionResponse> {
|
|
109
|
-
return this.coreClient.connectExec(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
sessionId
|
|
113
|
-
}
|
|
114
|
-
);
|
|
257
|
+
return this.coreClient.connectExec(this.client.revokeSession, {
|
|
258
|
+
sessionId,
|
|
259
|
+
});
|
|
115
260
|
}
|
|
116
261
|
|
|
117
262
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
263
|
+
* Immediately invalidates all active sessions for a user across all devices and browsers.
|
|
264
|
+
*
|
|
265
|
+
* Terminates all active sessions simultaneously, forcing the user to re-authenticate everywhere.
|
|
266
|
+
* Use this to implement global logout, force re-authentication after security incidents (password
|
|
267
|
+
* compromise, suspicious activity), terminate all sessions following password reset, or revoke
|
|
268
|
+
* access after account changes. Only active sessions are revoked; already expired, logout, or
|
|
269
|
+
* previously revoked sessions remain unchanged. This operation is atomic, instantaneous, and
|
|
270
|
+
* cannot be undone.
|
|
271
|
+
*
|
|
272
|
+
* @param {string} userId - The user identifier whose sessions should be revoked (format: "usr_...")
|
|
273
|
+
*
|
|
274
|
+
* @returns {Promise<RevokeAllUserSessionsResponse>} Response containing:
|
|
275
|
+
* - revokedSessions: Array of all revoked session objects with details
|
|
276
|
+
* - totalCount: Number of sessions that were revoked
|
|
277
|
+
* - revokedAt: Timestamp when revocation occurred
|
|
278
|
+
*
|
|
279
|
+
* @throws {Error} When userId is missing or invalid
|
|
280
|
+
* @throws {Error} If the user is not found
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* // Revoke all user sessions (global logout)
|
|
284
|
+
* const response = await scalekitClient.session.revokeAllUserSessions('usr_123456');
|
|
285
|
+
*
|
|
286
|
+
* console.log(`Revoked ${response.totalCount} sessions`);
|
|
287
|
+
* console.log('User must re-authenticate on all devices');
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* // Force logout after password reset
|
|
291
|
+
* app.post('/api/users/:userId/reset-password', async (req, res) => {
|
|
292
|
+
* const { userId } = req.params;
|
|
293
|
+
* const { newPassword } = req.body;
|
|
294
|
+
*
|
|
295
|
+
* try {
|
|
296
|
+
* // Update password
|
|
297
|
+
* await updateUserPassword(userId, newPassword);
|
|
298
|
+
*
|
|
299
|
+
* // Revoke all existing sessions
|
|
300
|
+
* const response = await scalekitClient.session.revokeAllUserSessions(userId);
|
|
301
|
+
*
|
|
302
|
+
* res.json({
|
|
303
|
+
* message: 'Password updated successfully',
|
|
304
|
+
* sessionsRevoked: response.totalCount,
|
|
305
|
+
* note: 'Please log in again with your new password'
|
|
306
|
+
* });
|
|
307
|
+
* } catch (error) {
|
|
308
|
+
* res.status(500).json({ error: 'Failed to reset password' });
|
|
309
|
+
* }
|
|
310
|
+
* });
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* // Force re-authentication after role change
|
|
314
|
+
* async function updateUserRole(userId, newRole) {
|
|
315
|
+
* await updateRole(userId, newRole);
|
|
316
|
+
*
|
|
317
|
+
* // Force re-authentication to apply new permissions
|
|
318
|
+
* await scalekitClient.session.revokeAllUserSessions(userId);
|
|
319
|
+
* console.log('User will re-authenticate with new role permissions');
|
|
320
|
+
* }
|
|
321
|
+
*
|
|
322
|
+
* @see {@link https://docs.scalekit.com/apis/#tag/sessions | Revoke All Sessions API}
|
|
323
|
+
* @see {@link revokeSession} - Revoke a specific session
|
|
324
|
+
* @see {@link getUserSessions} - View user's active sessions before revoking
|
|
121
325
|
*/
|
|
122
|
-
async revokeAllUserSessions(
|
|
326
|
+
async revokeAllUserSessions(
|
|
327
|
+
userId: string
|
|
328
|
+
): Promise<RevokeAllUserSessionsResponse> {
|
|
123
329
|
if (!userId) {
|
|
124
|
-
throw new Error(
|
|
330
|
+
throw new Error("userId is required");
|
|
125
331
|
}
|
|
126
332
|
|
|
127
|
-
return this.coreClient.connectExec(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
userId
|
|
131
|
-
}
|
|
132
|
-
);
|
|
333
|
+
return this.coreClient.connectExec(this.client.revokeAllUserSessions, {
|
|
334
|
+
userId,
|
|
335
|
+
});
|
|
133
336
|
}
|
|
134
337
|
}
|