@scalekit-sdk/node 2.2.0 → 2.2.2

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 (62) hide show
  1. package/{reference.md → REFERENCE.md} +530 -77
  2. package/lib/core.js +1 -1
  3. package/package.json +9 -3
  4. package/.github/dependabot.yml +0 -10
  5. package/.nvmrc +0 -1
  6. package/buf.gen.yaml +0 -20
  7. package/jest.config.js +0 -15
  8. package/src/auth.ts +0 -99
  9. package/src/connect.ts +0 -32
  10. package/src/connection.ts +0 -267
  11. package/src/constants/user.ts +0 -22
  12. package/src/core.ts +0 -139
  13. package/src/directory.ts +0 -431
  14. package/src/domain.ts +0 -273
  15. package/src/errors/base-exception.ts +0 -263
  16. package/src/errors/index.ts +0 -3
  17. package/src/errors/specific-exceptions.ts +0 -88
  18. package/src/index.ts +0 -10
  19. package/src/organization.ts +0 -571
  20. package/src/passwordless.ts +0 -139
  21. package/src/permission.ts +0 -310
  22. package/src/pkg/grpc/buf/validate/validate_pb.ts +0 -28
  23. package/src/pkg/grpc/google/api/annotations_pb.ts +0 -28
  24. package/src/pkg/grpc/google/api/field_behavior_pb.ts +0 -28
  25. package/src/pkg/grpc/google/api/visibility_pb.ts +0 -28
  26. package/src/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.ts +0 -28
  27. package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -257
  28. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -836
  29. package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -264
  30. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -794
  31. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -452
  32. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -2645
  33. package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -1393
  34. package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -599
  35. package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -311
  36. package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -200
  37. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1141
  38. package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -1491
  39. package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -497
  40. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -1404
  41. package/src/role.ts +0 -463
  42. package/src/scalekit.ts +0 -800
  43. package/src/session.ts +0 -323
  44. package/src/types/auth.ts +0 -73
  45. package/src/types/organization.ts +0 -12
  46. package/src/types/scalekit.ts +0 -50
  47. package/src/types/user.ts +0 -21
  48. package/src/user.ts +0 -829
  49. package/src/webauthn.ts +0 -99
  50. package/tests/README.md +0 -25
  51. package/tests/connection.test.ts +0 -42
  52. package/tests/directory.test.ts +0 -46
  53. package/tests/domain.test.ts +0 -293
  54. package/tests/organization.test.ts +0 -81
  55. package/tests/passwordless.test.ts +0 -108
  56. package/tests/permission.test.ts +0 -399
  57. package/tests/role.test.ts +0 -323
  58. package/tests/scalekit.test.ts +0 -104
  59. package/tests/setup.ts +0 -34
  60. package/tests/users.test.ts +0 -168
  61. package/tests/utils/test-data.ts +0 -490
  62. package/tsconfig.json +0 -19
package/src/domain.ts DELETED
@@ -1,273 +0,0 @@
1
- import type { MessageShape } from "@bufbuild/protobuf";
2
- import { EmptySchema } from "@bufbuild/protobuf/wkt";
3
- import type { Client } from "@connectrpc/connect";
4
- import GrpcConnect from "./connect";
5
- import CoreClient from "./core";
6
- import {
7
- DomainService,
8
- CreateDomainResponse,
9
- GetDomainResponse,
10
- ListDomainResponse,
11
- DomainType,
12
- } from "./pkg/grpc/scalekit/v1/domains/domains_pb";
13
-
14
- /**
15
- * Client for managing domains for organizations.
16
- *
17
- * Domains enable automatic organization identification during SSO flows based on user email addresses.
18
- * You can configure domains as ORGANIZATION_DOMAIN (for SSO routing) or ALLOWED_EMAIL_DOMAIN
19
- * (for restricting which email domains can automatically join an organization).
20
- *
21
- * @example
22
- * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
23
- * const domainClient = scalekitClient.domain;
24
- *
25
- * @see {@link https://docs.scalekit.com/apis/#tag/domains | Domain API Documentation}
26
- */
27
- export default class DomainClient {
28
- private client: Client<typeof DomainService>;
29
- constructor(
30
- private readonly grpcConnect: GrpcConnect,
31
- private readonly coreClient: CoreClient
32
- ) {
33
- this.client = this.grpcConnect.createClient(DomainService);
34
- }
35
-
36
- /**
37
- * Adds a new domain configuration to an organization for SSO routing or user suggestions.
38
- *
39
- * Domains serve two purposes based on their type:
40
- * - **ORGANIZATION_DOMAIN**: Used to identify the SSO connection for the organization. When users
41
- * authenticate with email addresses from this domain, they're automatically routed to the
42
- * organization's SSO provider.
43
- * - **ALLOWED_EMAIL_DOMAIN**: Enables users to join the organization with automatic suggestions
44
- * in the organization switcher during signup/login.
45
- *
46
- * Note: Public disposable domains (gmail.com, outlook.com, etc.) are automatically blocked for security.
47
- *
48
- * @param {string} organizationId - The organization ID (format: "org_...")
49
- * @param {string} name - The domain name (e.g., "acme.com", "example.org")
50
- * @param {object} [options] - Optional domain configuration
51
- * @param {DomainType | string} [options.domainType] - Domain type: 'ALLOWED_EMAIL_DOMAIN' or 'ORGANIZATION_DOMAIN'
52
- *
53
- * @returns {Promise<CreateDomainResponse>} The created domain with ID and verification status
54
- *
55
- * @throws {Error} If domain type is invalid
56
- * @throws {Error} If domain is a blocked public domain (gmail.com, etc.)
57
- *
58
- * @example
59
- * // Add SSO routing domain
60
- * const response = await scalekitClient.domain.createDomain(
61
- * 'org_123456',
62
- * 'acme.com',
63
- * { domainType: 'ORGANIZATION_DOMAIN' }
64
- * );
65
- * console.log('Domain created:', response.domain.id);
66
- * console.log('Verification required:', response.domain.verificationStatus);
67
- *
68
- * @example
69
- * // Add allowed email domain for user suggestions
70
- * await scalekitClient.domain.createDomain(
71
- * 'org_123456',
72
- * 'acme.io',
73
- * { domainType: 'ALLOWED_EMAIL_DOMAIN' }
74
- * );
75
- *
76
- * @example
77
- * // Create domain with default type
78
- * await scalekitClient.domain.createDomain('org_123456', 'company.com');
79
- *
80
- * @example
81
- * // Configure multiple domains for an organization
82
- * const domains = ['acme.com', 'acme.io', 'acme.net'];
83
- * for (const domain of domains) {
84
- * await scalekitClient.domain.createDomain('org_123456', domain, {
85
- * domainType: 'ORGANIZATION_DOMAIN'
86
- * });
87
- * }
88
- *
89
- * @see {@link https://docs.scalekit.com/apis/#tag/domains | Create Domain API}
90
- * @see {@link listDomains} - List all domains for an organization
91
- * @see {@link deleteDomain} - Remove a domain
92
- */
93
- async createDomain(
94
- organizationId: string,
95
- name: string,
96
- options?: { domainType?: DomainType | string }
97
- ): Promise<CreateDomainResponse> {
98
- let domainTypeValue: DomainType | undefined;
99
- if (options?.domainType) {
100
- if (typeof options.domainType === "string") {
101
- domainTypeValue =
102
- DomainType[options.domainType as keyof typeof DomainType];
103
- if (domainTypeValue === undefined) {
104
- throw new Error("Invalid domain type");
105
- }
106
- } else {
107
- domainTypeValue = options.domainType;
108
- }
109
- }
110
-
111
- return this.coreClient.connectExec(this.client.createDomain, {
112
- identities: {
113
- case: "organizationId",
114
- value: organizationId,
115
- },
116
- domain: {
117
- domain: name,
118
- ...(!!domainTypeValue && { domainType: domainTypeValue }),
119
- },
120
- });
121
- }
122
-
123
- /**
124
- * Retrieves detailed information about a specific domain configuration.
125
- *
126
- * Returns complete domain details including the domain name, type (ORGANIZATION_DOMAIN or
127
- * ALLOWED_EMAIL_DOMAIN), verification status, and when it was created/updated. Use this to
128
- * check domain configuration status or verification requirements.
129
- *
130
- * @param {string} organizationId - The organization ID (format: "org_...")
131
- * @param {string} domainId - The domain ID (format: "domain_...")
132
- *
133
- * @returns {Promise<GetDomainResponse>} Complete domain configuration and status
134
- *
135
- * @example
136
- * // Check domain verification status
137
- * const response = await scalekitClient.domain.getDomain(
138
- * 'org_123456',
139
- * 'domain_abc123'
140
- * );
141
- * console.log('Domain:', response.domain.domain);
142
- * console.log('Type:', response.domain.domainType);
143
- * console.log('Verified:', response.domain.verificationStatus);
144
- *
145
- * @example
146
- * // Verify domain configuration after creation
147
- * const created = await scalekitClient.domain.createDomain(
148
- * 'org_123456',
149
- * 'acme.com',
150
- * { domainType: 'ORGANIZATION_DOMAIN' }
151
- * );
152
- *
153
- * // Later, check if domain has been verified
154
- * const domain = await scalekitClient.domain.getDomain(
155
- * 'org_123456',
156
- * created.domain.id
157
- * );
158
- * if (domain.domain.verificationStatus === 'VERIFIED') {
159
- * console.log('Domain is ready for SSO routing');
160
- * }
161
- *
162
- * @see {@link https://docs.scalekit.com/apis/#tag/domains | Get Domain API}
163
- * @see {@link createDomain} - Add a new domain
164
- * @see {@link listDomains} - List all domains for an organization
165
- */
166
- async getDomain(
167
- organizationId: string,
168
- domainId: string
169
- ): Promise<GetDomainResponse> {
170
- return this.coreClient.connectExec(this.client.getDomain, {
171
- id: domainId,
172
- identities: {
173
- case: "organizationId",
174
- value: organizationId,
175
- },
176
- });
177
- }
178
-
179
- private resolveDomainType(
180
- domainType?: DomainType | string
181
- ): DomainType | undefined {
182
- if (domainType == null) return;
183
- if (typeof domainType !== 'string') return domainType;
184
- const resolved = DomainType[domainType as keyof typeof DomainType];
185
- if (resolved === undefined) {
186
- throw new Error(
187
- `Invalid domain type: ${domainType}. Expected ALLOWED_EMAIL_DOMAIN or ORGANIZATION_DOMAIN`
188
- );
189
- }
190
- return resolved;
191
- }
192
-
193
- /**
194
- * Retrieves all domain configurations for an organization.
195
- *
196
- * Returns a complete list of domains configured for the organization, including both
197
- * ORGANIZATION_DOMAIN (for SSO routing) and ALLOWED_EMAIL_DOMAIN (for user suggestions).
198
- * Each domain includes its verification status, type, and configuration details.
199
- *
200
- * Use this to audit domain configuration, check which domains are verified, or display
201
- * domain settings in an admin dashboard.
202
- *
203
- * @param {string} organizationId - The organization ID (format: "org_...")
204
- *
205
- * @param options Optional parameters for filtering domains
206
- * @param {DomainType | string} options.domainType Filter domains by type (ALLOWED_EMAIL_DOMAIN or ORGANIZATION_DOMAIN)
207
- * @returns {Promise<ListDomainResponse>} List of all domains with their configurations
208
- *
209
- * @example
210
- * // List all domains for an organization
211
- * const response = await scalekitClient.domain.listDomains('org_123456');
212
- * console.log(`Found ${response.domains.length} domains`);
213
- * response.domains.forEach(domain => {
214
- * console.log(`- ${domain.domain} (${domain.domainType}): ${domain.verificationStatus}`);
215
- * });
216
- *
217
- * @example
218
- * // Check which domains are verified for SSO
219
- * const response = await scalekitClient.domain.listDomains('org_123456');
220
- * const verifiedSSODomains = response.domains.filter(
221
- * d => d.domainType === 'ORGANIZATION_DOMAIN' && d.verificationStatus === 'VERIFIED'
222
- * );
223
- * console.log('Verified SSO domains:', verifiedSSODomains.map(d => d.domain));
224
- * @see {@link https://docs.scalekit.com/apis/#tag/domains | List Domains API}
225
- * @see {@link createDomain} - Add a new domain
226
- * @see {@link getDomain} - Get details for a specific domain
227
- * @see {@link deleteDomain} - Remove a domain
228
- */
229
- async listDomains(organizationId: string, options?: { domainType?: DomainType | string }): Promise<ListDomainResponse> {
230
- const domainTypeValue = this.resolveDomainType(options?.domainType);
231
-
232
- return this.coreClient.connectExec(
233
- this.client.listDomains,
234
- {
235
- identities: {
236
- case: 'organizationId',
237
- value: organizationId
238
- },
239
- ...(!!domainTypeValue && { domainType: domainTypeValue })
240
- },
241
- );
242
- }
243
-
244
- /**
245
- * Deletes a domain from an organization.
246
- *
247
- * Removes the domain configuration from the organization. Users with email addresses from
248
- * this domain will no longer be automatically routed to this organization's SSO connection.
249
- *
250
- * @param {string} organizationId - The organization ID
251
- * @param {string} domainId - The domain ID to delete
252
- *
253
- * @returns {Promise<MessageShape<EmptySchema>>} Empty response on successful deletion
254
- *
255
- * @example
256
- * // Remove a domain from an organization
257
- * await scalekitClient.domain.deleteDomain('org_123456', 'domain_abc123');
258
- * console.log('Domain deleted successfully');
259
- *
260
- * @see {@link https://docs.scalekit.com/apis/#tag/domains | Delete Domain API}
261
- * @see {@link createDomain} - Add a new domain
262
- * @see {@link listDomains} - List all domains for an organization
263
- */
264
- async deleteDomain(organizationId: string, domainId: string): Promise<MessageShape<typeof EmptySchema>> {
265
- return this.coreClient.connectExec(this.client.deleteDomain, {
266
- id: domainId,
267
- identities: {
268
- case: "organizationId",
269
- value: organizationId,
270
- },
271
- });
272
- }
273
- }
@@ -1,263 +0,0 @@
1
- import { ConnectError, Code } from '@connectrpc/connect';
2
- import { AxiosResponse } from 'axios';
3
- import type { ErrorInfo } from '../pkg/grpc/scalekit/v1/errdetails/errdetails_pb';
4
- import { ErrorInfoSchema } from '../pkg/grpc/scalekit/v1/errdetails/errdetails_pb';
5
-
6
- // gRPC to HTTP status mapping
7
- const GRPC_TO_HTTP: Record<number, number> = {
8
- [Code.InvalidArgument]: 400,
9
- [Code.FailedPrecondition]: 400,
10
- [Code.OutOfRange]: 400,
11
- [Code.Unauthenticated]: 401,
12
- [Code.PermissionDenied]: 403,
13
- [Code.NotFound]: 404,
14
- [Code.AlreadyExists]: 409,
15
- [Code.Aborted]: 409,
16
- [Code.ResourceExhausted]: 429,
17
- [Code.Canceled]: 499,
18
- [Code.DataLoss]: 500,
19
- [Code.Unknown]: 500,
20
- [Code.Internal]: 500,
21
- [Code.Unimplemented]: 501,
22
- [Code.Unavailable]: 503,
23
- [Code.DeadlineExceeded]: 504,
24
- };
25
-
26
- // HTTP to gRPC status mapping
27
- const HTTP_TO_GRPC: Record<number, number> = {
28
- 200: Code.Unknown, // No direct mapping for 200
29
- 400: Code.InvalidArgument,
30
- 401: Code.Unauthenticated,
31
- 403: Code.PermissionDenied,
32
- 404: Code.NotFound,
33
- 409: Code.AlreadyExists,
34
- 429: Code.ResourceExhausted,
35
- 500: Code.Internal,
36
- 501: Code.Unimplemented,
37
- 503: Code.Unavailable,
38
- 504: Code.DeadlineExceeded,
39
- };
40
-
41
- // HTTP status constants
42
- const HTTP_STATUS = {
43
- 'OK': 200,
44
- 'BAD_REQUEST': 400,
45
- 'UNAUTHORIZED': 401,
46
- 'FORBIDDEN': 403,
47
- 'NOT_FOUND': 404,
48
- 'CONFLICT': 409,
49
- 'TOO_MANY_REQUESTS': 429,
50
- 'INTERNAL_SERVER_ERROR': 500,
51
- 'NOT_IMPLEMENTED': 501,
52
- 'SERVICE_UNAVAILABLE': 503,
53
- 'GATEWAY_TIMEOUT': 504,
54
- };
55
-
56
- // Base exception class
57
- export class ScalekitException extends Error {
58
- constructor(error: any) {
59
- super(error?.message || error?.toString() || 'Unknown error');
60
- this.name = 'ScalekitException';
61
- }
62
- }
63
-
64
- // Webhook verification error
65
- export class WebhookVerificationError extends ScalekitException {
66
- constructor(error: any) {
67
- super(error);
68
- this.name = 'WebhookVerificationError';
69
- }
70
- }
71
-
72
- // Token validation failure exception
73
- export class ScalekitValidateTokenFailureException extends ScalekitException {
74
- constructor(error: any) {
75
- super(error);
76
- this.name = 'ScalekitValidateTokenFailureException';
77
- }
78
- }
79
-
80
- // Base server exception
81
- export class ScalekitServerException extends ScalekitException {
82
- private _grpcStatus: Code;
83
- private _httpStatus: number;
84
- private _message: string | null;
85
- private _errDetails: any;
86
- private _errorCode: string | null;
87
- private _unpackedDetails: ErrorInfo[];
88
-
89
- constructor(error: AxiosResponse | ConnectError) {
90
- super(error);
91
-
92
- this._unpackedDetails = [];
93
-
94
- if (this.isAxiosResponse(error)) {
95
- // Handle HTTP Response errors
96
- if (error.statusText && typeof error.statusText === 'string') {
97
- this._httpStatus = HTTP_STATUS[error.statusText.toUpperCase() as keyof typeof HTTP_STATUS] || HTTP_STATUS.INTERNAL_SERVER_ERROR;
98
- } else {
99
- this._httpStatus = HTTP_STATUS.INTERNAL_SERVER_ERROR;
100
- }
101
- this._grpcStatus = HTTP_TO_GRPC[error.status] || Code.Unknown;
102
- this._errorCode = error.statusText;
103
- this._errDetails = error.data;
104
- this._message = null;
105
- } else {
106
- // Handle gRPC ConnectError
107
- this._grpcStatus = error.code;
108
- this._httpStatus = GRPC_TO_HTTP[error.code] || 500;
109
- this._message = error.message;
110
- this._errDetails = error.findDetails(ErrorInfoSchema);
111
- this._errorCode = null;
112
-
113
- // Unpack error details
114
- for (const detail of this._errDetails) {
115
- this._unpackedDetails.push(detail);
116
- if (!this._errorCode) {
117
- this._errorCode = detail.errorCode;
118
- }
119
- }
120
- }
121
-
122
- this.name = 'ScalekitServerException';
123
- }
124
-
125
- private isAxiosResponse(error: any): error is AxiosResponse {
126
- return error && typeof error.status === 'number' && typeof error.statusText === 'string';
127
- }
128
-
129
- // String representation
130
- toString(): string {
131
- const border = '='.repeat(40);
132
-
133
- if (this._unpackedDetails.length > 0) {
134
- let detailsStr = JSON.stringify(this._unpackedDetails, null, 2);
135
-
136
- // Format the JSON string for better readability
137
-
138
- if (detailsStr.startsWith("[") && detailsStr.includes("\n")) {
139
- detailsStr = "[\n" + detailsStr.substring(1);
140
- }
141
-
142
- return `\n${border}\n` +
143
- `Error Code: ${this._errorCode}\n` +
144
- `GRPC: (${this.getGrpcStatusName()}: ${this._grpcStatus})\n` +
145
- `HTTP: (${this.getHttpStatusName()}: ${this._httpStatus})\n` +
146
- `Error Details:\n` +
147
- `${this._message}: ${detailsStr}\n${border}\n`;
148
- } else {
149
- return `\n${border}\n` +
150
- `Error Code: ${this._errorCode}\n` +
151
- `GRPC: (${this.getGrpcStatusName()}: ${this._grpcStatus})\n` +
152
- `HTTP: (${this.getHttpStatusName()}: ${this._httpStatus})\n` +
153
- `Error Details: ${this._errDetails}\n${border}\n`;
154
- }
155
- }
156
-
157
- // Helper method to get gRPC status name
158
- private getGrpcStatusName(): string {
159
- switch (this._grpcStatus) {
160
- case Code.InvalidArgument: return 'INVALID_ARGUMENT';
161
- case Code.FailedPrecondition: return 'FAILED_PRECONDITION';
162
- case Code.OutOfRange: return 'OUT_OF_RANGE';
163
- case Code.Unauthenticated: return 'UNAUTHENTICATED';
164
- case Code.PermissionDenied: return 'PERMISSION_DENIED';
165
- case Code.NotFound: return 'NOT_FOUND';
166
- case Code.AlreadyExists: return 'ALREADY_EXISTS';
167
- case Code.Aborted: return 'ABORTED';
168
- case Code.ResourceExhausted: return 'RESOURCE_EXHAUSTED';
169
- case Code.Canceled: return 'CANCELED';
170
- case Code.DataLoss: return 'DATA_LOSS';
171
- case Code.Unknown: return 'UNKNOWN';
172
- case Code.Internal: return 'INTERNAL';
173
- case Code.Unimplemented: return 'UNIMPLEMENTED';
174
- case Code.Unavailable: return 'UNAVAILABLE';
175
- case Code.DeadlineExceeded: return 'DEADLINE_EXCEEDED';
176
- default: return 'UNKNOWN';
177
- }
178
- }
179
-
180
- // Helper method to get HTTP status name
181
- private getHttpStatusName(): string {
182
- switch (this._httpStatus) {
183
- case 200: return 'OK';
184
- case 400: return 'BAD_REQUEST';
185
- case 401: return 'UNAUTHORIZED';
186
- case 403: return 'FORBIDDEN';
187
- case 404: return 'NOT_FOUND';
188
- case 409: return 'CONFLICT';
189
- case 429: return 'TOO_MANY_REQUESTS';
190
- case 500: return 'INTERNAL_SERVER_ERROR';
191
- case 501: return 'NOT_IMPLEMENTED';
192
- case 503: return 'SERVICE_UNAVAILABLE';
193
- case 504: return 'GATEWAY_TIMEOUT';
194
- default: return 'INTERNAL_SERVER_ERROR';
195
- }
196
- }
197
-
198
- // Getters
199
- get grpcStatus(): Code {
200
- return this._grpcStatus;
201
- }
202
-
203
- get httpStatus(): number {
204
- return this._httpStatus;
205
- }
206
-
207
- get errorCode(): string | null {
208
- return this._errorCode;
209
- }
210
-
211
- get message(): string {
212
- return this._message || super.message;
213
- }
214
-
215
- get errDetails(): any {
216
- return this._errDetails;
217
- }
218
-
219
- get unpackedDetails(): ErrorInfo[] {
220
- return this._unpackedDetails;
221
- }
222
-
223
- static promote(error: AxiosResponse | ConnectError): ScalekitServerException {
224
- // Use dynamic import to avoid circular dependency
225
- // eslint-disable-next-line @typescript-eslint/no-var-requires
226
- const specific = require('./specific-exceptions');
227
- const grpcStatus = error instanceof ConnectError
228
- ? error.code
229
- : HTTP_TO_GRPC[error.status] || Code.Unknown;
230
-
231
- switch (grpcStatus) {
232
- case Code.InvalidArgument:
233
- case Code.FailedPrecondition:
234
- case Code.OutOfRange:
235
- return new specific.ScalekitBadRequestException(error);
236
- case Code.Unauthenticated:
237
- return new specific.ScalekitUnauthorizedException(error);
238
- case Code.PermissionDenied:
239
- return new specific.ScalekitForbiddenException(error);
240
- case Code.NotFound:
241
- return new specific.ScalekitNotFoundException(error);
242
- case Code.AlreadyExists:
243
- case Code.Aborted:
244
- return new specific.ScalekitConflictException(error);
245
- case Code.ResourceExhausted:
246
- return new specific.ScalekitTooManyRequestsException(error);
247
- case Code.Canceled:
248
- return new specific.ScalekitCancelledException(error);
249
- case Code.DataLoss:
250
- case Code.Unknown:
251
- case Code.Internal:
252
- return new specific.ScalekitInternalServerException(error);
253
- case Code.Unimplemented:
254
- return new specific.ScalekitNotImplementedException(error);
255
- case Code.Unavailable:
256
- return new specific.ScalekitServiceUnavailableException(error);
257
- case Code.DeadlineExceeded:
258
- return new specific.ScalekitGatewayTimeoutException(error);
259
- default:
260
- return new specific.ScalekitUnknownException(error);
261
- }
262
- }
263
- }
@@ -1,3 +0,0 @@
1
- // Export base exceptions
2
- export * from './base-exception';
3
- export * from './specific-exceptions';
@@ -1,88 +0,0 @@
1
- import { ConnectError } from '@connectrpc/connect';
2
- import { AxiosResponse } from 'axios';
3
- import { ScalekitServerException } from './base-exception';
4
-
5
- // Specific exception classes
6
- export class ScalekitBadRequestException extends ScalekitServerException {
7
- constructor(error: AxiosResponse | ConnectError) {
8
- super(error);
9
- this.name = 'ScalekitBadRequestException';
10
- }
11
- }
12
-
13
- export class ScalekitUnauthorizedException extends ScalekitServerException {
14
- constructor(error: AxiosResponse | ConnectError) {
15
- super(error);
16
- this.name = 'ScalekitUnauthorizedException';
17
- }
18
- }
19
-
20
- export class ScalekitForbiddenException extends ScalekitServerException {
21
- constructor(error: AxiosResponse | ConnectError) {
22
- super(error);
23
- this.name = 'ScalekitForbiddenException';
24
- }
25
- }
26
-
27
- export class ScalekitNotFoundException extends ScalekitServerException {
28
- constructor(error: AxiosResponse | ConnectError) {
29
- super(error);
30
- this.name = 'ScalekitNotFoundException';
31
- }
32
- }
33
-
34
- export class ScalekitConflictException extends ScalekitServerException {
35
- constructor(error: AxiosResponse | ConnectError) {
36
- super(error);
37
- this.name = 'ScalekitConflictException';
38
- }
39
- }
40
-
41
- export class ScalekitTooManyRequestsException extends ScalekitServerException {
42
- constructor(error: AxiosResponse | ConnectError) {
43
- super(error);
44
- this.name = 'ScalekitTooManyRequestsException';
45
- }
46
- }
47
-
48
- export class ScalekitInternalServerException extends ScalekitServerException {
49
- constructor(error: AxiosResponse | ConnectError) {
50
- super(error);
51
- this.name = 'ScalekitInternalServerException';
52
- }
53
- }
54
-
55
- export class ScalekitNotImplementedException extends ScalekitServerException {
56
- constructor(error: AxiosResponse | ConnectError) {
57
- super(error);
58
- this.name = 'ScalekitNotImplementedException';
59
- }
60
- }
61
-
62
- export class ScalekitServiceUnavailableException extends ScalekitServerException {
63
- constructor(error: AxiosResponse | ConnectError) {
64
- super(error);
65
- this.name = 'ScalekitServiceUnavailableException';
66
- }
67
- }
68
-
69
- export class ScalekitGatewayTimeoutException extends ScalekitServerException {
70
- constructor(error: AxiosResponse | ConnectError) {
71
- super(error);
72
- this.name = 'ScalekitGatewayTimeoutException';
73
- }
74
- }
75
-
76
- export class ScalekitCancelledException extends ScalekitServerException {
77
- constructor(error: AxiosResponse | ConnectError) {
78
- super(error);
79
- this.name = 'ScalekitCancelledException';
80
- }
81
- }
82
-
83
- export class ScalekitUnknownException extends ScalekitServerException {
84
- constructor(error: AxiosResponse | ConnectError) {
85
- super(error);
86
- this.name = 'ScalekitUnknownException';
87
- }
88
- }
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import ScalekitClient from "./scalekit";
2
-
3
- export { ScalekitClient };
4
- export { ScalekitClient as Scalekit };
5
- export default ScalekitClient;
6
-
7
- export * from "./types/scalekit";
8
- export * from "./types/auth";
9
-
10
- export * from "./errors";