@scalekit-sdk/node 2.2.0-beta.1 → 2.2.1

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.
Files changed (226) hide show
  1. package/README.md +5 -5
  2. package/{reference.md → REFERENCE.md} +530 -748
  3. package/lib/auth.d.ts +9 -6
  4. package/lib/auth.js +4 -20
  5. package/lib/auth.js.map +1 -1
  6. package/lib/connect.d.ts +3 -3
  7. package/lib/connect.js +1 -2
  8. package/lib/connect.js.map +1 -1
  9. package/lib/connection.d.ts +2 -2
  10. package/lib/connection.js +4 -4
  11. package/lib/connection.js.map +1 -1
  12. package/lib/core.js +2 -2
  13. package/lib/core.js.map +1 -1
  14. package/lib/directory.d.ts +2 -2
  15. package/lib/directory.js +7 -7
  16. package/lib/directory.js.map +1 -1
  17. package/lib/domain.d.ts +6 -5
  18. package/lib/domain.js +4 -5
  19. package/lib/domain.js.map +1 -1
  20. package/lib/errors/base-exception.d.ts +1 -1
  21. package/lib/errors/base-exception.js +1 -1
  22. package/lib/errors/base-exception.js.map +1 -1
  23. package/lib/organization.d.ts +10 -9
  24. package/lib/organization.js +11 -9
  25. package/lib/organization.js.map +1 -1
  26. package/lib/passwordless.d.ts +2 -2
  27. package/lib/passwordless.js +8 -7
  28. package/lib/passwordless.js.map +1 -1
  29. package/lib/permission.d.ts +6 -5
  30. package/lib/permission.js +10 -11
  31. package/lib/permission.js.map +1 -1
  32. package/lib/pkg/grpc/buf/validate/validate_pb.d.ts +7 -0
  33. package/lib/pkg/grpc/buf/validate/validate_pb.js +25 -0
  34. package/lib/pkg/grpc/buf/validate/validate_pb.js.map +1 -0
  35. package/lib/pkg/grpc/google/api/annotations_pb.d.ts +7 -0
  36. package/lib/pkg/grpc/google/api/annotations_pb.js +25 -0
  37. package/lib/pkg/grpc/google/api/annotations_pb.js.map +1 -0
  38. package/lib/pkg/grpc/google/api/field_behavior_pb.d.ts +7 -0
  39. package/lib/pkg/grpc/google/api/field_behavior_pb.js +25 -0
  40. package/lib/pkg/grpc/google/api/field_behavior_pb.js.map +1 -0
  41. package/lib/pkg/grpc/google/api/visibility_pb.d.ts +7 -0
  42. package/lib/pkg/grpc/google/api/visibility_pb.js +25 -0
  43. package/lib/pkg/grpc/google/api/visibility_pb.js.map +1 -0
  44. package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.d.ts +7 -0
  45. package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.js +25 -0
  46. package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.js.map +1 -0
  47. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.d.ts +48 -42
  48. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js +27 -263
  49. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js.map +1 -1
  50. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.d.ts +371 -325
  51. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js +132 -835
  52. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js.map +1 -1
  53. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.d.ts +113 -87
  54. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.js +45 -201
  55. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.js.map +1 -1
  56. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.d.ts +262 -265
  57. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js +92 -938
  58. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js.map +1 -1
  59. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.d.ts +162 -157
  60. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js +42 -313
  61. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js.map +1 -1
  62. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +1488 -1459
  63. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +353 -2362
  64. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
  65. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.d.ts +520 -483
  66. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js +224 -1555
  67. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js.map +1 -1
  68. package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.d.ts +219 -191
  69. package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.js +96 -553
  70. package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.js.map +1 -1
  71. package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.d.ts +76 -102
  72. package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js +37 -393
  73. package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js.map +1 -1
  74. package/lib/pkg/grpc/scalekit/v1/options/options_pb.d.ts +36 -26
  75. package/lib/pkg/grpc/scalekit/v1/options/options_pb.js +20 -69
  76. package/lib/pkg/grpc/scalekit/v1/options/options_pb.js.map +1 -1
  77. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +447 -400
  78. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +163 -1238
  79. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
  80. package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.d.ts +622 -556
  81. package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.js +201 -1718
  82. package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.js.map +1 -1
  83. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.d.ts +135 -132
  84. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.js +55 -518
  85. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.js.map +1 -1
  86. package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +445 -413
  87. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +142 -1490
  88. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
  89. package/lib/role.d.ts +8 -7
  90. package/lib/role.js +14 -14
  91. package/lib/role.js.map +1 -1
  92. package/lib/scalekit.d.ts +0 -4
  93. package/lib/scalekit.js +0 -4
  94. package/lib/scalekit.js.map +1 -1
  95. package/lib/session.js +15 -24
  96. package/lib/session.js.map +1 -1
  97. package/lib/user.d.ts +6 -5
  98. package/lib/user.js +17 -20
  99. package/lib/user.js.map +1 -1
  100. package/lib/webauthn.js +6 -5
  101. package/lib/webauthn.js.map +1 -1
  102. package/package.json +12 -10
  103. package/.github/dependabot.yml +0 -10
  104. package/.nvmrc +0 -1
  105. package/buf.gen.yaml +0 -24
  106. package/jest.config.js +0 -15
  107. package/lib/connected-accounts.d.ts +0 -119
  108. package/lib/connected-accounts.js +0 -241
  109. package/lib/connected-accounts.js.map +0 -1
  110. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.d.ts +0 -19
  111. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.js +0 -27
  112. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.js.map +0 -1
  113. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.d.ts +0 -118
  114. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js +0 -126
  115. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js.map +0 -1
  116. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.d.ts +0 -37
  117. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.js +0 -45
  118. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.js.map +0 -1
  119. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.d.ts +0 -82
  120. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js +0 -90
  121. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js.map +0 -1
  122. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.d.ts +0 -87
  123. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.js +0 -95
  124. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.js.map +0 -1
  125. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.d.ts +0 -718
  126. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js +0 -893
  127. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js.map +0 -1
  128. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.d.ts +0 -172
  129. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js +0 -180
  130. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js.map +0 -1
  131. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.d.ts +0 -154
  132. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js +0 -162
  133. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js.map +0 -1
  134. package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.d.ts +0 -73
  135. package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.js +0 -81
  136. package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.js.map +0 -1
  137. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.d.ts +0 -171
  138. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js +0 -179
  139. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js.map +0 -1
  140. package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.d.ts +0 -250
  141. package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.js +0 -258
  142. package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.js.map +0 -1
  143. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.d.ts +0 -46
  144. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.js +0 -54
  145. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.js.map +0 -1
  146. package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.d.ts +0 -75
  147. package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.js +0 -83
  148. package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.js.map +0 -1
  149. package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.d.ts +0 -431
  150. package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js +0 -627
  151. package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js.map +0 -1
  152. package/lib/pkg/grpc/scalekit/v1/users/users_connect.d.ts +0 -173
  153. package/lib/pkg/grpc/scalekit/v1/users/users_connect.js +0 -181
  154. package/lib/pkg/grpc/scalekit/v1/users/users_connect.js.map +0 -1
  155. package/lib/tools.d.ts +0 -75
  156. package/lib/tools.js +0 -127
  157. package/lib/tools.js.map +0 -1
  158. package/src/auth.ts +0 -99
  159. package/src/connect.ts +0 -33
  160. package/src/connected-accounts.ts +0 -358
  161. package/src/connection.ts +0 -267
  162. package/src/constants/user.ts +0 -22
  163. package/src/core.ts +0 -139
  164. package/src/directory.ts +0 -431
  165. package/src/domain.ts +0 -272
  166. package/src/errors/base-exception.ts +0 -262
  167. package/src/errors/index.ts +0 -3
  168. package/src/errors/specific-exceptions.ts +0 -88
  169. package/src/index.ts +0 -10
  170. package/src/organization.ts +0 -568
  171. package/src/passwordless.ts +0 -138
  172. package/src/permission.ts +0 -310
  173. package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.ts +0 -26
  174. package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -342
  175. package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +0 -125
  176. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -1213
  177. package/src/pkg/grpc/scalekit/v1/auth/passwordless_connect.ts +0 -44
  178. package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -336
  179. package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +0 -89
  180. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -1263
  181. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -573
  182. package/src/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.ts +0 -94
  183. package/src/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.ts +0 -1294
  184. package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +0 -179
  185. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -3846
  186. package/src/pkg/grpc/scalekit/v1/directories/directories_connect.ts +0 -161
  187. package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -2119
  188. package/src/pkg/grpc/scalekit/v1/domains/domains_connect.ts +0 -80
  189. package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -855
  190. package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -524
  191. package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -230
  192. package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +0 -178
  193. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1766
  194. package/src/pkg/grpc/scalekit/v1/roles/roles_connect.ts +0 -257
  195. package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -2395
  196. package/src/pkg/grpc/scalekit/v1/sessions/sessions_connect.ts +0 -53
  197. package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -749
  198. package/src/pkg/grpc/scalekit/v1/tools/tools_connect.ts +0 -82
  199. package/src/pkg/grpc/scalekit/v1/tools/tools_pb.ts +0 -847
  200. package/src/pkg/grpc/scalekit/v1/users/users_connect.ts +0 -180
  201. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -2151
  202. package/src/role.ts +0 -461
  203. package/src/scalekit.ts +0 -809
  204. package/src/session.ts +0 -337
  205. package/src/tools.ts +0 -166
  206. package/src/types/auth.ts +0 -73
  207. package/src/types/organization.ts +0 -12
  208. package/src/types/scalekit.ts +0 -50
  209. package/src/types/user.ts +0 -21
  210. package/src/user.ts +0 -825
  211. package/src/webauthn.ts +0 -98
  212. package/tests/README.md +0 -25
  213. package/tests/connected-accounts.test.ts +0 -472
  214. package/tests/connection.test.ts +0 -42
  215. package/tests/directory.test.ts +0 -46
  216. package/tests/domain.test.ts +0 -293
  217. package/tests/organization.test.ts +0 -81
  218. package/tests/passwordless.test.ts +0 -108
  219. package/tests/permission.test.ts +0 -399
  220. package/tests/role.test.ts +0 -323
  221. package/tests/scalekit.test.ts +0 -104
  222. package/tests/setup.ts +0 -34
  223. package/tests/tools.test.ts +0 -239
  224. package/tests/users.test.ts +0 -168
  225. package/tests/utils/test-data.ts +0 -481
  226. package/tsconfig.json +0 -19
package/src/session.ts DELETED
@@ -1,337 +0,0 @@
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
- SessionDetailsRequest,
8
- SessionDetails,
9
- UserSessionDetailsRequest,
10
- UserSessionDetails,
11
- UserSessionFilter,
12
- RevokeSessionRequest,
13
- RevokeSessionResponse,
14
- RevokeAllUserSessionsRequest,
15
- RevokeAllUserSessionsResponse,
16
- } from "./pkg/grpc/scalekit/v1/sessions/sessions_pb";
17
- import { Timestamp } from "@bufbuild/protobuf";
18
-
19
- export default class SessionClient {
20
- private client: PromiseClient<typeof SessionService>;
21
-
22
- constructor(
23
- private readonly grpcConnect: GrpcConnect,
24
- private readonly coreClient: CoreClient
25
- ) {
26
- this.client = this.grpcConnect.createClient(SessionService);
27
- }
28
-
29
- /**
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
67
- */
68
- async getSession(sessionId: string): Promise<SessionDetails> {
69
- return this.coreClient.connectExec(this.client.getSession, {
70
- sessionId,
71
- });
72
- }
73
-
74
- /**
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
135
- */
136
- async getUserSessions(
137
- userId: string,
138
- options?: {
139
- pageSize?: number;
140
- pageToken?: string;
141
- filter?: {
142
- status?: string[];
143
- startTime?: Date;
144
- endTime?: Date;
145
- };
146
- }
147
- ): Promise<UserSessionDetails> {
148
- const request: PartialMessage<UserSessionDetailsRequest> = {
149
- userId,
150
- };
151
-
152
- if (options?.pageSize !== undefined) {
153
- request.pageSize = options.pageSize;
154
- }
155
-
156
- if (options?.pageToken) {
157
- request.pageToken = options.pageToken;
158
- }
159
-
160
- if (options?.filter) {
161
- const filter = new UserSessionFilter();
162
-
163
- if (options.filter.status) {
164
- filter.status = options.filter.status;
165
- }
166
-
167
- if (options.filter.startTime) {
168
- filter.startTime = Timestamp.fromDate(options.filter.startTime);
169
- }
170
-
171
- if (options.filter.endTime) {
172
- filter.endTime = Timestamp.fromDate(options.filter.endTime);
173
- }
174
-
175
- request.filter = filter;
176
- }
177
-
178
- return this.coreClient.connectExec(this.client.getUserSessions, request);
179
- }
180
-
181
- /**
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
255
- */
256
- async revokeSession(sessionId: string): Promise<RevokeSessionResponse> {
257
- return this.coreClient.connectExec(this.client.revokeSession, {
258
- sessionId,
259
- });
260
- }
261
-
262
- /**
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
325
- */
326
- async revokeAllUserSessions(
327
- userId: string
328
- ): Promise<RevokeAllUserSessionsResponse> {
329
- if (!userId) {
330
- throw new Error("userId is required");
331
- }
332
-
333
- return this.coreClient.connectExec(this.client.revokeAllUserSessions, {
334
- userId,
335
- });
336
- }
337
- }
package/src/tools.ts DELETED
@@ -1,166 +0,0 @@
1
- import { PartialMessage } from "@bufbuild/protobuf";
2
- import { PromiseClient } from "@connectrpc/connect";
3
- import GrpcConnect from "./connect";
4
- import CoreClient from "./core";
5
- import { ToolService } from "./pkg/grpc/scalekit/v1/tools/tools_connect";
6
- import {
7
- ExecuteToolRequest,
8
- ExecuteToolResponse,
9
- Filter,
10
- ListScopedToolsRequest,
11
- ListScopedToolsResponse,
12
- ListToolsRequest,
13
- ListToolsResponse,
14
- ScopedToolFilter,
15
- } from "./pkg/grpc/scalekit/v1/tools/tools_pb";
16
-
17
- /**
18
- * Client for listing and executing tools.
19
- *
20
- * This client provides convenient helpers around the `ToolService` for:
21
- * - listing all tools available in your workspace
22
- * - listing tools scoped to a specific connected account identifier
23
- * - executing tools using connected account credentials
24
- *
25
- * It mirrors the capabilities of the Python SDK `ToolsClient` while following
26
- * the idioms and patterns used across the Node SDK.
27
- */
28
- export default class ToolsClient {
29
- private client: PromiseClient<typeof ToolService>;
30
-
31
- constructor(
32
- private readonly grpcConnect: GrpcConnect,
33
- private readonly coreClient: CoreClient
34
- ) {
35
- this.client = this.grpcConnect.createClient(ToolService);
36
- }
37
-
38
- /**
39
- * Lists tools available in your workspace with optional filtering and pagination.
40
- *
41
- * @param options Optional filter and pagination parameters
42
- * @param options.filter Filter configuration matching the `Filter` proto message.
43
- * Use this to filter by provider, identifier, or tool names.
44
- * @param options.pageSize Maximum number of tools to return per page.
45
- * @param options.pageToken Token from a previous `listTools` response for pagination.
46
- */
47
- async listTools(options?: {
48
- filter?: PartialMessage<Filter>;
49
- pageSize?: number;
50
- pageToken?: string;
51
- }): Promise<ListToolsResponse> {
52
- const request: PartialMessage<ListToolsRequest> = {};
53
-
54
- if (options?.filter) {
55
- request.filter = options.filter as Filter;
56
- }
57
- if (options?.pageSize !== undefined) {
58
- request.pageSize = options.pageSize;
59
- }
60
- if (options?.pageToken) {
61
- request.pageToken = options.pageToken;
62
- }
63
-
64
- return this.coreClient.connectExec(this.client.listTools, request);
65
- }
66
-
67
- /**
68
- * Lists tools that are scoped to a specific connected account identifier.
69
- *
70
- * @param identifier Connected account identifier to scope the tools list (for example,
71
- * a workspace identifier or email).
72
- * @param options Optional filter and pagination parameters
73
- * @param options.filter Filter configuration for scoped tools (providers, tool names, connection names).
74
- * @param options.pageSize Maximum number of tools to return per page.
75
- * @param options.pageToken Token from a previous `listScopedTools` response for pagination.
76
- */
77
- async listScopedTools(
78
- identifier: string,
79
- options?: {
80
- filter?: PartialMessage<ScopedToolFilter>;
81
- pageSize?: number;
82
- pageToken?: string;
83
- }
84
- ): Promise<ListScopedToolsResponse> {
85
- const request: PartialMessage<ListScopedToolsRequest> = {
86
- identifier,
87
- };
88
-
89
- if (options?.filter) {
90
- request.filter = options.filter as ScopedToolFilter;
91
- }
92
- if (options?.pageSize !== undefined) {
93
- request.pageSize = options.pageSize;
94
- }
95
- if (options?.pageToken) {
96
- request.pageToken = options.pageToken;
97
- }
98
-
99
- return this.coreClient.connectExec(this.client.listScopedTools, request);
100
- }
101
-
102
- /**
103
- * Executes a tool using credentials from a connected account.
104
- *
105
- * You can either:
106
- * - reference the connected account directly via `connectedAccountId`, or
107
- * - identify it using a combination of `identifier`, `connector`, `organizationId`, and `userId`.
108
- *
109
- * @param params Execution configuration
110
- * @param params.toolName Name of the tool to execute.
111
- * @param params.identifier Optional connected account identifier (for example, email or workspace ID).
112
- * @param params.params JSON parameters required by the tool. These will be sent as a structured payload.
113
- * @param params.connectedAccountId Optional direct ID of the connected account (`ca_...`).
114
- * @param params.connector Optional connector/provider name when using identifier-based lookup.
115
- * @param params.organizationId Optional organization ID to scope the connected account lookup.
116
- * @param params.userId Optional user ID to scope the connected account lookup.
117
- */
118
- async executeTool(params: {
119
- toolName: string;
120
- identifier?: string;
121
- params?: Record<string, unknown>;
122
- connectedAccountId?: string;
123
- connector?: string;
124
- organizationId?: string;
125
- userId?: string;
126
- }): Promise<ExecuteToolResponse> {
127
- const {
128
- toolName,
129
- identifier,
130
- params: toolParams,
131
- connectedAccountId,
132
- connector,
133
- organizationId,
134
- userId,
135
- } = params;
136
-
137
- const request: PartialMessage<ExecuteToolRequest> = {
138
- toolName,
139
- };
140
-
141
- if (identifier) {
142
- request.identifier = identifier;
143
- }
144
-
145
- if (toolParams) {
146
- // `google.protobuf.Struct` messages in bufbuild accept plain JSON objects.
147
- request.params = toolParams as any;
148
- }
149
-
150
- if (connectedAccountId) {
151
- request.connectedAccountId = connectedAccountId;
152
- }
153
- if (connector) {
154
- request.connector = connector;
155
- }
156
- if (organizationId) {
157
- request.organizationId = organizationId;
158
- }
159
- if (userId) {
160
- request.userId = userId;
161
- }
162
-
163
- return this.coreClient.connectExec(this.client.executeTool, request);
164
- }
165
- }
166
-
package/src/types/auth.ts DELETED
@@ -1,73 +0,0 @@
1
- export type User = {
2
- id: string;
3
- username: string | undefined;
4
- name: string;
5
- givenName: string;
6
- familyName: string | undefined;
7
- email: string;
8
- emailVerified: boolean;
9
- phoneNumber: string | undefined;
10
- phoneNumberVerified: boolean | undefined;
11
- profile: string | undefined;
12
- picture: string | undefined;
13
- gender: string | undefined;
14
- birthDate: string | undefined;
15
- zoneInfo: string | undefined;
16
- locale: string | undefined;
17
- updatedAt: string | undefined;
18
- identities: Identity[];
19
- metadata: string | undefined;
20
- }
21
-
22
- export type Identity = {
23
- connectionId: string;
24
- organizationId: string;
25
- connectionType: string;
26
- providerName: string;
27
- social: boolean;
28
- providerRawAttributes: string;
29
- }
30
-
31
- export type IdTokenClaimIdentity = {
32
- connection_id: string;
33
- organization_id: string;
34
- connection_type: string;
35
- provider_name: string;
36
- social: boolean;
37
- provider_raw_attributes: string;
38
- }
39
-
40
- export type IdTokenClaim = {
41
- sub: string;
42
- name: string;
43
- preferred_username: string | undefined;
44
- given_name: string;
45
- family_name: string | undefined;
46
- email: string;
47
- email_verified: boolean;
48
- phone_number: string | undefined;
49
- phone_number_verified: boolean | undefined;
50
- profile: string | undefined;
51
- picture: string | undefined;
52
- gender: string | undefined;
53
- birthdate: string | undefined;
54
- zoneinfo: string | undefined;
55
- locale: string | undefined;
56
- updated_at: string | undefined;
57
- identities: IdTokenClaimIdentity[];
58
- metadata: string | undefined;
59
- }
60
-
61
- export type TokenResponse = {
62
- access_token: string;
63
- id_token: string;
64
- expires_in: number;
65
- refresh_token: string;
66
- }
67
-
68
- export type IdpInitiatedLoginClaims ={
69
- connection_id: string;
70
- organization_id: string;
71
- login_hint: string;
72
- relay_state?: string;
73
- }
@@ -1,12 +0,0 @@
1
- export type OrganizationSettings = {
2
- features: Feature[];
3
- }
4
-
5
- export type Feature = {
6
- name: string;
7
- enabled: boolean;
8
- }
9
-
10
- export type OrganizationUserManagementSettingsInput = {
11
- maxAllowedUsers?: number | null;
12
- }
@@ -1,50 +0,0 @@
1
- import { User } from './auth';
2
-
3
- export enum GrantType {
4
- AuthorizationCode = 'authorization_code',
5
- RefreshToken = 'refresh_token',
6
- ClientCredentials = 'client_credentials',
7
- }
8
-
9
- export type AuthorizationUrlOptions = {
10
- connectionId?: string;
11
- organizationId?: string;
12
- scopes?: string[];
13
- state?: string;
14
- nonce?: string;
15
- domainHint?: string;
16
- loginHint?: string;
17
- codeChallenge?: string;
18
- codeChallengeMethod?: string;
19
- provider?: string;
20
- prompt?: string;
21
- }
22
-
23
- export type AuthenticationOptions = {
24
- codeVerifier?: string;
25
- }
26
-
27
- export type TokenValidationOptions = {
28
- issuer?: string;
29
- audience?: string[];
30
- requiredScopes?: string[];
31
- }
32
-
33
- export type AuthenticationResponse = {
34
- user: User;
35
- idToken: string;
36
- accessToken: string;
37
- expiresIn: number;
38
- refreshToken: string;
39
- }
40
-
41
- export type RefreshTokenResponse = {
42
- accessToken: string;
43
- refreshToken: string;
44
- }
45
-
46
- export interface LogoutUrlOptions {
47
- idTokenHint?: string;
48
- postLogoutRedirectUri?: string;
49
- state?: string;
50
- }
package/src/types/user.ts DELETED
@@ -1,21 +0,0 @@
1
- export interface CreateUserRequest {
2
- email: string;
3
- externalId?: string;
4
- phoneNumber?: string;
5
- userProfile?: {
6
- firstName?: string;
7
- lastName?: string;
8
- };
9
- metadata?: Record<string, string>;
10
- sendInvitationEmail?: boolean;
11
- }
12
-
13
- export interface UpdateUserRequest {
14
- email?: string;
15
- externalId?: string;
16
- userProfile?: {
17
- firstName?: string;
18
- lastName?: string;
19
- };
20
- metadata?: Record<string, string>;
21
- }