@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/connect.ts DELETED
@@ -1,33 +0,0 @@
1
- import { ServiceType } from '@bufbuild/protobuf';
2
- import { PromiseClient, Transport, createPromiseClient } from '@connectrpc/connect';
3
- import { createGrpcTransport } from '@connectrpc/connect-node';
4
- import CoreClient, { headers } from './core';
5
-
6
- export default class GrpcConnect {
7
- private transport: Transport;
8
- constructor(
9
- private readonly coreClient: CoreClient
10
- ) {
11
- this.transport = createGrpcTransport({
12
- baseUrl: this.coreClient.envUrl,
13
- httpVersion: "2",
14
- interceptors: [
15
- (next) => {
16
- return (req) => {
17
- req.header.set(headers['user-agent'], this.coreClient.userAgent)
18
- req.header.set(headers['x-sdk-version'], this.coreClient.sdkVersion)
19
- req.header.set(headers['x-api-version'], this.coreClient.apiVersion)
20
- if (this.coreClient.accessToken) {
21
- req.header.set(headers.authorization, `Bearer ${this.coreClient.accessToken}`)
22
- }
23
- return next(req)
24
- }
25
- }
26
- ],
27
- });
28
- }
29
-
30
- createClient<T extends ServiceType>(service: T): PromiseClient<T> {
31
- return createPromiseClient(service, this.transport);
32
- }
33
- }
@@ -1,358 +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 { ScalekitNotFoundException } from "./errors";
6
- import { ConnectedAccountService } from "./pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect";
7
- import {
8
- AuthorizationDetails,
9
- CreateConnectedAccount,
10
- CreateConnectedAccountRequest,
11
- CreateConnectedAccountResponse,
12
- DeleteConnectedAccountRequest,
13
- DeleteConnectedAccountResponse,
14
- GetConnectedAccountByIdentifierRequest,
15
- GetConnectedAccountByIdentifierResponse,
16
- GetMagicLinkForConnectedAccountRequest,
17
- GetMagicLinkForConnectedAccountResponse,
18
- ListConnectedAccountsRequest,
19
- ListConnectedAccountsResponse,
20
- OauthToken,
21
- UpdateConnectedAccount,
22
- UpdateConnectedAccountRequest,
23
- UpdateConnectedAccountResponse,
24
- } from "./pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb";
25
-
26
- /**
27
- * Client for managing connected accounts for third-party integrations.
28
- *
29
- * This mirrors the Python SDK `ConnectedAccountsClient` and exposes a typed,
30
- * ergonomic API around the `ConnectedAccountService` to:
31
- * - list connected accounts
32
- * - create/update/delete connected accounts
33
- * - generate magic links for authorization
34
- * - fetch full authentication details for a connected account
35
- */
36
- export default class ConnectedAccountsClient {
37
- private client: PromiseClient<typeof ConnectedAccountService>;
38
-
39
- constructor(
40
- private readonly grpcConnect: GrpcConnect,
41
- private readonly coreClient: CoreClient
42
- ) {
43
- this.client = this.grpcConnect.createClient(ConnectedAccountService);
44
- }
45
-
46
- /**
47
- * Lists connected accounts with optional filters and pagination.
48
- *
49
- * @param options Optional filtering and pagination parameters
50
- */
51
- async listConnectedAccounts(options?: {
52
- organizationId?: string;
53
- userId?: string;
54
- connector?: string;
55
- identifier?: string;
56
- provider?: string;
57
- pageSize?: number;
58
- pageToken?: string;
59
- query?: string;
60
- }): Promise<ListConnectedAccountsResponse> {
61
- const request: PartialMessage<ListConnectedAccountsRequest> = {};
62
-
63
- if (options?.organizationId) {
64
- request.organizationId = options.organizationId;
65
- }
66
- if (options?.userId) {
67
- request.userId = options.userId;
68
- }
69
- if (options?.connector) {
70
- request.connector = options.connector;
71
- }
72
- if (options?.identifier) {
73
- request.identifier = options.identifier;
74
- }
75
- if (options?.provider) {
76
- request.provider = options.provider;
77
- }
78
- if (options?.pageSize !== undefined) {
79
- request.pageSize = options.pageSize;
80
- }
81
- if (options?.pageToken) {
82
- request.pageToken = options.pageToken;
83
- }
84
- if (options?.query) {
85
- request.query = options.query;
86
- }
87
-
88
- return this.coreClient.connectExec(
89
- this.client.listConnectedAccounts,
90
- request
91
- );
92
- }
93
-
94
- /**
95
- * Creates a new connected account.
96
- *
97
- * @param params Connected account creation parameters
98
- */
99
- async createConnectedAccount(params: {
100
- connector: string;
101
- identifier: string;
102
- connectedAccount: CreateConnectedAccount;
103
- organizationId?: string;
104
- userId?: string;
105
- }): Promise<CreateConnectedAccountResponse> {
106
- const {
107
- connector,
108
- identifier,
109
- connectedAccount,
110
- organizationId,
111
- userId,
112
- } = params;
113
-
114
- const request: PartialMessage<CreateConnectedAccountRequest> = {
115
- connector,
116
- identifier,
117
- connectedAccount,
118
- };
119
-
120
- if (organizationId) {
121
- request.organizationId = organizationId;
122
- }
123
- if (userId) {
124
- request.userId = userId;
125
- }
126
-
127
- return this.coreClient.connectExec(
128
- this.client.createConnectedAccount,
129
- request
130
- );
131
- }
132
-
133
- /**
134
- * Gets an existing connected account by connector and identifier, or creates one if none exists.
135
- * Mirrors the Python SDK `get_or_create_connected_account`. When creating, the backend may require
136
- * valid authorization details; if omitted, a minimal payload is sent and the server may return
137
- * a validation error.
138
- *
139
- * @param params Get-or-create parameters
140
- * @param params.connector Connector identifier (required)
141
- * @param params.identifier Connected account identifier (required)
142
- * @param params.authorizationDetails Optional auth details for the create path (OAuth token or static auth)
143
- * @param params.organizationId Optional organization ID
144
- * @param params.userId Optional user ID
145
- * @param params.apiConfig Optional API config for the create path
146
- */
147
- async getOrCreateConnectedAccount(params: {
148
- connector: string;
149
- identifier: string;
150
- authorizationDetails?: PartialMessage<AuthorizationDetails>;
151
- organizationId?: string;
152
- userId?: string;
153
- apiConfig?: Record<string, unknown>;
154
- }): Promise<CreateConnectedAccountResponse> {
155
- const {
156
- connector,
157
- identifier,
158
- authorizationDetails,
159
- organizationId,
160
- userId,
161
- apiConfig,
162
- } = params;
163
-
164
- if (!connector?.trim()) {
165
- throw new Error("connector is required");
166
- }
167
- if (!identifier?.trim()) {
168
- throw new Error("identifier is required");
169
- }
170
-
171
- try {
172
- const getResponse = await this.getConnectedAccountByIdentifier({
173
- connector,
174
- identifier,
175
- organizationId,
176
- userId,
177
- });
178
- return new CreateConnectedAccountResponse({
179
- connectedAccount: getResponse.connectedAccount,
180
- });
181
- } catch (err) {
182
- if (!(err instanceof ScalekitNotFoundException)) {
183
- throw err;
184
- }
185
- }
186
-
187
- const connectedAccountPayload = new CreateConnectedAccount({
188
- authorizationDetails: authorizationDetails
189
- ? (authorizationDetails as AuthorizationDetails)
190
- : new AuthorizationDetails({
191
- details: { case: "oauthToken", value: new OauthToken({}) },
192
- }),
193
- ...(apiConfig != null && { apiConfig: apiConfig as unknown as CreateConnectedAccount["apiConfig"] }),
194
- });
195
-
196
- return this.createConnectedAccount({
197
- connector,
198
- identifier,
199
- connectedAccount: connectedAccountPayload,
200
- organizationId,
201
- userId,
202
- });
203
- }
204
-
205
- /**
206
- * Updates an existing connected account.
207
- *
208
- * You can target the account either by `connectedAccountId` or by the combination
209
- * of `organizationId`/`userId`, `connector`, and `identifier`.
210
- */
211
- async updateConnectedAccount(params: {
212
- connector: string;
213
- identifier: string;
214
- connectedAccount: UpdateConnectedAccount;
215
- organizationId?: string;
216
- userId?: string;
217
- connectedAccountId?: string;
218
- }): Promise<UpdateConnectedAccountResponse> {
219
- const {
220
- connector,
221
- identifier,
222
- connectedAccount,
223
- organizationId,
224
- userId,
225
- connectedAccountId,
226
- } = params;
227
-
228
- const request: PartialMessage<UpdateConnectedAccountRequest> = {
229
- connector,
230
- identifier,
231
- connectedAccount,
232
- };
233
-
234
- if (organizationId) {
235
- request.organizationId = organizationId;
236
- }
237
- if (userId) {
238
- request.userId = userId;
239
- }
240
- if (connectedAccountId) {
241
- request.id = connectedAccountId;
242
- }
243
-
244
- return this.coreClient.connectExec(
245
- this.client.updateConnectedAccount,
246
- request
247
- );
248
- }
249
-
250
- /**
251
- * Deletes a connected account and revokes its credentials.
252
- *
253
- * You can target the account either by `connectedAccountId` or by the combination
254
- * of `organizationId`/`userId`, `connector`, and `identifier`.
255
- */
256
- async deleteConnectedAccount(params: {
257
- connector: string;
258
- identifier: string;
259
- organizationId?: string;
260
- userId?: string;
261
- connectedAccountId?: string;
262
- }): Promise<DeleteConnectedAccountResponse> {
263
- const { connector, identifier, organizationId, userId, connectedAccountId } =
264
- params;
265
-
266
- const request: PartialMessage<DeleteConnectedAccountRequest> = {
267
- connector,
268
- identifier,
269
- };
270
-
271
- if (organizationId) {
272
- request.organizationId = organizationId;
273
- }
274
- if (userId) {
275
- request.userId = userId;
276
- }
277
- if (connectedAccountId) {
278
- request.id = connectedAccountId;
279
- }
280
-
281
- return this.coreClient.connectExec(
282
- this.client.deleteConnectedAccount,
283
- request
284
- );
285
- }
286
-
287
- /**
288
- * Generates a time-limited magic link for connecting or re-authorizing a third-party account.
289
- */
290
- async getMagicLinkForConnectedAccount(params: {
291
- connector: string;
292
- identifier: string;
293
- organizationId?: string;
294
- userId?: string;
295
- connectedAccountId?: string;
296
- }): Promise<GetMagicLinkForConnectedAccountResponse> {
297
- const { connector, identifier, organizationId, userId, connectedAccountId } =
298
- params;
299
-
300
- const request: PartialMessage<GetMagicLinkForConnectedAccountRequest> = {
301
- connector,
302
- identifier,
303
- };
304
-
305
- if (organizationId) {
306
- request.organizationId = organizationId;
307
- }
308
- if (userId) {
309
- request.userId = userId;
310
- }
311
- if (connectedAccountId) {
312
- request.id = connectedAccountId;
313
- }
314
-
315
- return this.coreClient.connectExec(
316
- this.client.getMagicLinkForConnectedAccount,
317
- request
318
- );
319
- }
320
-
321
- /**
322
- * Retrieves complete authentication details for a connected account.
323
- *
324
- * This method returns sensitive credential information, so ensure you protect access
325
- * to this in your application.
326
- */
327
- async getConnectedAccountByIdentifier(params: {
328
- connector: string;
329
- identifier: string;
330
- organizationId?: string;
331
- userId?: string;
332
- connectedAccountId?: string;
333
- }): Promise<GetConnectedAccountByIdentifierResponse> {
334
- const { connector, identifier, organizationId, userId, connectedAccountId } =
335
- params;
336
-
337
- const request: PartialMessage<GetConnectedAccountByIdentifierRequest> = {
338
- connector,
339
- identifier,
340
- };
341
-
342
- if (organizationId) {
343
- request.organizationId = organizationId;
344
- }
345
- if (userId) {
346
- request.userId = userId;
347
- }
348
- if (connectedAccountId) {
349
- request.id = connectedAccountId;
350
- }
351
-
352
- return this.coreClient.connectExec(
353
- this.client.getConnectedAccountAuth,
354
- request
355
- );
356
- }
357
- }
358
-
package/src/connection.ts DELETED
@@ -1,267 +0,0 @@
1
- import { PromiseClient } from "@connectrpc/connect";
2
- import GrpcConnect from "./connect";
3
- import CoreClient from "./core";
4
- import { ConnectionService } from "./pkg/grpc/scalekit/v1/connections/connections_connect";
5
- import {
6
- GetConnectionResponse,
7
- ToggleConnectionResponse,
8
- ListConnectionsResponse,
9
- } from "./pkg/grpc/scalekit/v1/connections/connections_pb";
10
-
11
- /**
12
- * Client for managing enterprise SSO connections for organizations.
13
- *
14
- * Connections represent the SSO integration between an organization and their identity provider (IdP).
15
- * Each organization can have an enterprise connection supporting different protocols (SAML, OIDC) and
16
- * providers (Okta, Azure AD, Google Workspace, etc.). Use this client to retrieve connection details,
17
- * list connections, and enable/disable them.
18
- *
19
- * @example
20
- * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
21
- * const connectionClient = scalekitClient.connection;
22
- *
23
- * @see {@link https://docs.scalekit.com/apis/#tag/connections | Connection API Documentation}
24
- */
25
- export default class ConnectionClient {
26
- private client: PromiseClient<typeof ConnectionService>;
27
- constructor(
28
- private readonly grpcConncet: GrpcConnect,
29
- private readonly coreClient: CoreClient
30
- ) {
31
- this.client = this.grpcConncet.createClient(ConnectionService);
32
- }
33
-
34
- /**
35
- * Retrieves complete configuration and status details for a specific SSO connection.
36
- *
37
- * Use this method to fetch comprehensive information about an organization's SSO connection,
38
- * including provider settings, protocol details (SAML/OIDC), enabled status, and configuration
39
- * metadata. This is useful for verifying connection setup, auditing configurations, checking
40
- * connection health before authentication flows, or displaying connection details to administrators.
41
- *
42
- * @param {string} organizationId - The organization ID that owns the connection (format: "org_...")
43
- * @param {string} id - The connection identifier to retrieve (format: "conn_...")
44
- *
45
- * @returns {Promise<GetConnectionResponse>} Response containing:
46
- * - connection: Complete connection object with:
47
- * - id: Unique connection identifier
48
- * - organizationId: Parent organization ID
49
- * - provider: Identity provider name (e.g., "okta", "azure_ad", "google")
50
- * - type: Protocol type ("saml", "oidc")
51
- * - enabled: Whether the connection is active
52
- * - status: Configuration status
53
- * - domains: Associated email domains for this connection
54
- * - metadata: Provider-specific configuration details
55
- * - createTime: When the connection was created
56
- * - updateTime: When the connection was last modified
57
- *
58
- * @throws {Error} If the organization or connection is not found
59
- *
60
- * @example
61
- * // Get connection details
62
- * const response = await scalekitClient.connection.getConnection(
63
- * 'org_123456',
64
- * 'conn_abc123'
65
- * );
66
- *
67
- * const conn = response.connection;
68
- * console.log('Provider:', conn.provider);
69
- * console.log('Type:', conn.type);
70
- * console.log('Status:', conn.enabled ? 'Enabled' : 'Disabled');
71
- * console.log('Domains:', conn.domains);
72
- *
73
- * @example
74
- * // Verify connection is ready for authentication
75
- * const response = await scalekitClient.connection.getConnection(orgId, connId);
76
- *
77
- * if (response.connection.enabled && response.connection.status === 'active') {
78
- * console.log('Connection is ready for SSO authentication');
79
- * } else {
80
- * console.log('Connection not ready:', response.connection.status);
81
- * }
82
- *
83
- *
84
- * @see {@link https://docs.scalekit.com/apis/#tag/connections | Get Connection API}
85
- * @see {@link listConnections} - List all connections for an organization
86
- * @see {@link enableConnection} - Enable this connection
87
- * @see {@link disableConnection} - Disable this connection
88
- */
89
- async getConnection(
90
- organizationId: string,
91
- id: string
92
- ): Promise<GetConnectionResponse> {
93
- return this.coreClient.connectExec(this.client.getConnection, {
94
- id,
95
- organizationId,
96
- });
97
- }
98
-
99
- /**
100
- * Lists all SSO connections associated with a specific email domain.
101
- *
102
- * Use this method to discover which organizations have SSO configured for a particular
103
- * domain. This is useful for implementing domain-based SSO routing where users are
104
- * automatically directed to their organization's SSO based on their email domain.
105
- *
106
- * @param {string} domain - The email domain to search for (e.g., "acme.com")
107
- *
108
- * @returns {Promise<ListConnectionsResponse>} Response containing:
109
- * - connections: Array of connection objects for the domain
110
- *
111
- * @example
112
- * // Find SSO connections for a domain
113
- * const response = await scalekitClient.connection.listConnectionsByDomain('acme.com');
114
- *
115
- * if (response.connections.length > 0) {
116
- * console.log('SSO available for domain acme.com');
117
- * const connection = response.connections[0];
118
- * console.log('Organization:', connection.organizationId);
119
- * console.log('Provider:', connection.provider);
120
- * }
121
- *
122
- * @example
123
- * // Implement domain-based SSO routing
124
- * app.post('/auth/login', async (req, res) => {
125
- * const email = req.body.email;
126
- * const domain = email.split('@')[1];
127
- *
128
- * const response = await scalekitClient.connection.listConnectionsByDomain(domain);
129
- *
130
- * if (response.connections.length > 0) {
131
- * // Redirect to SSO
132
- * const authUrl = scalekitClient.getAuthorizationUrl(redirectUri, {
133
- * connectionId: response.connections[0].id,
134
- * loginHint: email
135
- * });
136
- * return res.redirect(authUrl);
137
- * } else {
138
- * // Use password-based login
139
- * return res.render('password-login');
140
- * }
141
- * });
142
- *
143
- * @see {@link https://docs.scalekit.com/apis/#tag/connections | List Connections API}
144
- * @see {@link listConnections} - List all connections for an organization
145
- */
146
- async listConnectionsByDomain(
147
- domain: string
148
- ): Promise<ListConnectionsResponse> {
149
- return this.coreClient.connectExec(this.client.listConnections, {
150
- domain,
151
- });
152
- }
153
-
154
- /**
155
- * Lists all SSO connections configured for an organization.
156
- *
157
- * Retrieves all enterprise SSO connections (SAML, OIDC) that have been configured for
158
- * the specified organization. Each connection includes details about the provider,
159
- * status, and configuration.
160
- *
161
- * @param {string} organizationId - The organization ID
162
- *
163
- * @returns {Promise<ListConnectionsResponse>} Response containing:
164
- * - connections: Array of connection objects with provider details and status
165
- *
166
- * @example
167
- * // List all SSO connections for an organization
168
- * const response = await scalekitClient.connection.listConnections('org_123456');
169
- *
170
- * console.log(`Found ${response.connections.length} connections`);
171
- * response.connections.forEach(conn => {
172
- * console.log(`- ${conn.provider} (${conn.type}): ${conn.enabled ? 'Enabled' : 'Disabled'}`);
173
- * });
174
- *
175
- * @example
176
- * // Check if organization has any enabled connections
177
- * const response = await scalekitClient.connection.listConnections('org_123456');
178
- * const hasEnabledSSO = response.connections.some(conn => conn.enabled);
179
- *
180
- * if (!hasEnabledSSO) {
181
- * console.log('No SSO connections enabled for this organization');
182
- * }
183
- *
184
- * @see {@link https://docs.scalekit.com/apis/#tag/connections | List Connections API}
185
- * @see {@link getConnection} - Get details of a specific connection
186
- * @see {@link enableConnection} - Enable a connection
187
- * @see {@link disableConnection} - Disable a connection
188
- */
189
- async listConnections(
190
- organizationId: string
191
- ): Promise<ListConnectionsResponse> {
192
- return this.coreClient.connectExec(this.client.listConnections, {
193
- organizationId,
194
- });
195
- }
196
-
197
- /**
198
- * Enables an SSO connection for an organization.
199
- *
200
- * Activates a previously disabled or newly configured SSO connection, allowing users
201
- * from the organization to authenticate using this identity provider. Once enabled,
202
- * users can immediately start using SSO to log in.
203
- *
204
- * @param {string} organizationId - The organization ID
205
- * @param {string} id - The connection ID to enable
206
- *
207
- * @returns {Promise<ToggleConnectionResponse>} Response with updated connection status
208
- *
209
- * @example
210
- * // Enable an SSO connection
211
- * const response = await scalekitClient.connection.enableConnection(
212
- * 'org_123456',
213
- * 'conn_abc123'
214
- * );
215
- *
216
- * console.log('Connection enabled:', response.connection.enabled); // true
217
- *
218
- *
219
- * @see {@link https://docs.scalekit.com/apis/#tag/connections | Enable Connection API}
220
- * @see {@link disableConnection} - Disable a connection
221
- * @see {@link listConnections} - List all connections
222
- */
223
- async enableConnection(
224
- organizationId: string,
225
- id: string
226
- ): Promise<ToggleConnectionResponse> {
227
- return this.coreClient.connectExec(this.client.enableConnection, {
228
- id,
229
- organizationId,
230
- });
231
- }
232
-
233
- /**
234
- * Disables an SSO connection for an organization.
235
- *
236
- * Deactivates an SSO connection, preventing users from authenticating via this identity
237
- * provider. This is useful for temporarily suspending SSO access, during maintenance,
238
- * or when migrating to a different provider. Existing user sessions remain valid.
239
- *
240
- * @param {string} organizationId - The organization ID
241
- * @param {string} id - The connection ID to disable
242
- *
243
- * @returns {Promise<ToggleConnectionResponse>} Response with updated connection status
244
- *
245
- * @example
246
- * // Disable an SSO connection
247
- * const response = await scalekitClient.connection.disableConnection(
248
- * 'org_123456',
249
- * 'conn_abc123'
250
- * );
251
- *
252
- * console.log('Connection disabled:', !response.connection.enabled); // true
253
- *
254
- * @see {@link https://docs.scalekit.com/apis/#tag/connections | Disable Connection API}
255
- * @see {@link enableConnection} - Enable a connection
256
- * @see {@link listConnections} - List all connections
257
- */
258
- async disableConnection(
259
- organizationId: string,
260
- id: string
261
- ): Promise<ToggleConnectionResponse> {
262
- return this.coreClient.connectExec(this.client.disableConnection, {
263
- id,
264
- organizationId,
265
- });
266
- }
267
- }
@@ -1,22 +0,0 @@
1
- import type { IdTokenClaim, User } from '../types/auth';
2
-
3
- export const IdTokenClaimToUserMap: { [k in keyof IdTokenClaim]: keyof User } = {
4
- "sub": "id",
5
- "name": "name",
6
- "preferred_username": "username",
7
- "given_name": "givenName",
8
- "family_name": "familyName",
9
- "email": "email",
10
- "email_verified": "emailVerified",
11
- "phone_number": "phoneNumber",
12
- "phone_number_verified": "phoneNumberVerified",
13
- "profile": 'profile',
14
- "picture": "picture",
15
- "gender": "gender",
16
- "birthdate": "birthDate",
17
- "zoneinfo": "zoneInfo",
18
- "locale": "locale",
19
- "updated_at": "updatedAt",
20
- "identities": "identities",
21
- "metadata": "metadata"
22
- }