@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.
- package/{reference.md → REFERENCE.md} +530 -77
- package/lib/core.js +1 -1
- package/package.json +9 -3
- package/.github/dependabot.yml +0 -10
- package/.nvmrc +0 -1
- package/buf.gen.yaml +0 -20
- package/jest.config.js +0 -15
- package/src/auth.ts +0 -99
- package/src/connect.ts +0 -32
- package/src/connection.ts +0 -267
- package/src/constants/user.ts +0 -22
- package/src/core.ts +0 -139
- package/src/directory.ts +0 -431
- package/src/domain.ts +0 -273
- package/src/errors/base-exception.ts +0 -263
- package/src/errors/index.ts +0 -3
- package/src/errors/specific-exceptions.ts +0 -88
- package/src/index.ts +0 -10
- package/src/organization.ts +0 -571
- package/src/passwordless.ts +0 -139
- package/src/permission.ts +0 -310
- package/src/pkg/grpc/buf/validate/validate_pb.ts +0 -28
- package/src/pkg/grpc/google/api/annotations_pb.ts +0 -28
- package/src/pkg/grpc/google/api/field_behavior_pb.ts +0 -28
- package/src/pkg/grpc/google/api/visibility_pb.ts +0 -28
- package/src/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.ts +0 -28
- package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -257
- package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -836
- package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -264
- package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -794
- package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -452
- package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -2645
- package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -1393
- package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -599
- package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -311
- package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -200
- package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1141
- package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -1491
- package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -497
- package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -1404
- package/src/role.ts +0 -463
- package/src/scalekit.ts +0 -800
- package/src/session.ts +0 -323
- package/src/types/auth.ts +0 -73
- package/src/types/organization.ts +0 -12
- package/src/types/scalekit.ts +0 -50
- package/src/types/user.ts +0 -21
- package/src/user.ts +0 -829
- package/src/webauthn.ts +0 -99
- package/tests/README.md +0 -25
- package/tests/connection.test.ts +0 -42
- package/tests/directory.test.ts +0 -46
- package/tests/domain.test.ts +0 -293
- package/tests/organization.test.ts +0 -81
- package/tests/passwordless.test.ts +0 -108
- package/tests/permission.test.ts +0 -399
- package/tests/role.test.ts +0 -323
- package/tests/scalekit.test.ts +0 -104
- package/tests/setup.ts +0 -34
- package/tests/users.test.ts +0 -168
- package/tests/utils/test-data.ts +0 -490
- package/tsconfig.json +0 -19
package/src/webauthn.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { create } from '@bufbuild/protobuf';
|
|
2
|
-
import type { Client } from '@connectrpc/connect';
|
|
3
|
-
import GrpcConnect from './connect';
|
|
4
|
-
import CoreClient from './core';
|
|
5
|
-
import { WebAuthnService } from './pkg/grpc/scalekit/v1/auth/webauthn_pb';
|
|
6
|
-
import {
|
|
7
|
-
ListCredentialsRequestSchema,
|
|
8
|
-
UpdateCredentialRequestSchema,
|
|
9
|
-
DeleteCredentialRequestSchema,
|
|
10
|
-
ListCredentialsResponse,
|
|
11
|
-
UpdateCredentialResponse,
|
|
12
|
-
DeleteCredentialResponse
|
|
13
|
-
} from './pkg/grpc/scalekit/v1/auth/webauthn_pb';
|
|
14
|
-
|
|
15
|
-
export default class WebAuthnClient {
|
|
16
|
-
private client: Client<typeof WebAuthnService>;
|
|
17
|
-
|
|
18
|
-
constructor(
|
|
19
|
-
private readonly grpcConnect: GrpcConnect,
|
|
20
|
-
private readonly coreClient: CoreClient
|
|
21
|
-
) {
|
|
22
|
-
this.client = this.grpcConnect.createClient(WebAuthnService);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* List all WebAuthn credentials for a user
|
|
27
|
-
* @param {string} userId The user ID to list credentials for
|
|
28
|
-
* @returns {Promise<ListCredentialsResponse>} The response containing:
|
|
29
|
-
* - credentials: Array of WebAuthn credentials
|
|
30
|
-
* - allAcceptedCredentialsOptions: Options for all accepted credentials
|
|
31
|
-
*/
|
|
32
|
-
async listCredentials(userId: string): Promise<ListCredentialsResponse> {
|
|
33
|
-
if (!userId || typeof userId !== 'string') {
|
|
34
|
-
throw new Error('userId must be a non-empty string');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const request = create(ListCredentialsRequestSchema, {
|
|
38
|
-
userId
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return this.coreClient.connectExec(
|
|
42
|
-
this.client.listCredentials,
|
|
43
|
-
request
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Update a WebAuthn credential's display name
|
|
49
|
-
* @param {string} credentialId The credential ID to update
|
|
50
|
-
* @param {string} displayName The new display name for the credential
|
|
51
|
-
* @returns {Promise<UpdateCredentialResponse>} The response containing:
|
|
52
|
-
* - credential: The updated WebAuthn credential
|
|
53
|
-
*/
|
|
54
|
-
async updateCredential(
|
|
55
|
-
credentialId: string,
|
|
56
|
-
displayName: string
|
|
57
|
-
): Promise<UpdateCredentialResponse> {
|
|
58
|
-
if (!credentialId || typeof credentialId !== 'string') {
|
|
59
|
-
throw new Error('credentialId must be a non-empty string');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!displayName || typeof displayName !== 'string') {
|
|
63
|
-
throw new Error('displayName must be a non-empty string');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const request = create(UpdateCredentialRequestSchema, {
|
|
67
|
-
credentialId,
|
|
68
|
-
displayName
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return this.coreClient.connectExec(
|
|
72
|
-
this.client.updateCredential,
|
|
73
|
-
request
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Delete a WebAuthn credential
|
|
79
|
-
* @param {string} credentialId The credential ID to delete
|
|
80
|
-
* @returns {Promise<DeleteCredentialResponse>} The response containing:
|
|
81
|
-
* - success: Boolean indicating if the deletion was successful
|
|
82
|
-
* - unknownCredentialOptions: Options if the credential was not found
|
|
83
|
-
*/
|
|
84
|
-
async deleteCredential(credentialId: string): Promise<DeleteCredentialResponse> {
|
|
85
|
-
if (!credentialId || typeof credentialId !== 'string') {
|
|
86
|
-
throw new Error('credentialId must be a non-empty string');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const request = create(DeleteCredentialRequestSchema, {
|
|
90
|
-
credentialId
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return this.coreClient.connectExec(
|
|
94
|
-
this.client.deleteCredential,
|
|
95
|
-
request
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
package/tests/README.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Scalekit Node SDK Tests
|
|
2
|
-
|
|
3
|
-
This directory contains the test suite for the Scalekit Node SDK.
|
|
4
|
-
|
|
5
|
-
## Setup
|
|
6
|
-
|
|
7
|
-
1. Create a `.env` file in the root directory with the following environment variables:
|
|
8
|
-
|
|
9
|
-
```env
|
|
10
|
-
# Required for client initialization
|
|
11
|
-
SCALEKIT_ENVIRONMENT_URL= "Your Scalekit environment URL."
|
|
12
|
-
SCALEKIT_CLIENT_ID= " Your Scalekit environment client id "
|
|
13
|
-
SCALEKIT_CLIENT_SECRET= " Your Scalekit environment client secret "
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
2. Install dependencies:
|
|
17
|
-
```bash
|
|
18
|
-
npm install
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Running Tests
|
|
22
|
-
|
|
23
|
-
- Run all tests: `npm test`
|
|
24
|
-
- Run tests in watch mode: `npm run test:watch`
|
|
25
|
-
|
package/tests/connection.test.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
3
|
-
import { TestOrganizationManager } from './utils/test-data';
|
|
4
|
-
|
|
5
|
-
describe('Connections', () => {
|
|
6
|
-
let client: ScalekitClient;
|
|
7
|
-
let testOrg: string;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
// Use global client
|
|
11
|
-
client = global.client;
|
|
12
|
-
|
|
13
|
-
// Create test organization for each test
|
|
14
|
-
testOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
// Clean up test organization
|
|
19
|
-
await TestOrganizationManager.cleanupTestOrganization(client, testOrg);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('listConnections', () => {
|
|
23
|
-
it('should list connections by organization', async () => {
|
|
24
|
-
const connections = await client.connection.listConnections(testOrg);
|
|
25
|
-
|
|
26
|
-
expect(connections).toBeDefined();
|
|
27
|
-
expect(connections.connections).toBeDefined();
|
|
28
|
-
expect(Array.isArray(connections.connections)).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('listConnectionsByDomain', () => {
|
|
33
|
-
it('should list connections by domain', async () => {
|
|
34
|
-
const domain = 'example.com';
|
|
35
|
-
const connections = await client.connection.listConnectionsByDomain(domain);
|
|
36
|
-
|
|
37
|
-
expect(connections).toBeDefined();
|
|
38
|
-
expect(connections.connections).toBeDefined();
|
|
39
|
-
expect(Array.isArray(connections.connections)).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
package/tests/directory.test.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
3
|
-
import { TestOrganizationManager } from './utils/test-data';
|
|
4
|
-
|
|
5
|
-
describe('Directories', () => {
|
|
6
|
-
let client: ScalekitClient;
|
|
7
|
-
let testOrg: string;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
// Use global client
|
|
11
|
-
client = global.client;
|
|
12
|
-
|
|
13
|
-
// Create test organization for each test
|
|
14
|
-
testOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
// Clean up test organization
|
|
19
|
-
await TestOrganizationManager.cleanupTestOrganization(client, testOrg);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('listDirectories', () => {
|
|
23
|
-
it('should list directories', async () => {
|
|
24
|
-
const directories = await client.directory.listDirectories(testOrg);
|
|
25
|
-
|
|
26
|
-
expect(directories).toBeDefined();
|
|
27
|
-
expect(directories.directories).toBeDefined();
|
|
28
|
-
expect(Array.isArray(directories.directories)).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('getPrimaryDirectoryByOrganizationId', () => {
|
|
33
|
-
it('should get primary directory by organization id', async () => {
|
|
34
|
-
try {
|
|
35
|
-
const primaryDirectory = await client.directory.getPrimaryDirectoryByOrganizationId(testOrg);
|
|
36
|
-
|
|
37
|
-
expect(primaryDirectory).toBeDefined();
|
|
38
|
-
expect(primaryDirectory.id).toBeDefined();
|
|
39
|
-
expect(primaryDirectory.organizationId).toBe(testOrg);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
// Expected when no directories exist
|
|
42
|
-
expect(error).toBeDefined();
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
});
|
package/tests/domain.test.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { DomainType } from '../src/pkg/grpc/scalekit/v1/domains/domains_pb';
|
|
3
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
4
|
-
import { TestDataGenerator, TestOrganizationManager, TestDomainManager } from './utils/test-data';
|
|
5
|
-
|
|
6
|
-
describe('Domains', () => {
|
|
7
|
-
let client: ScalekitClient;
|
|
8
|
-
let testOrg: string;
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
// Use global client
|
|
12
|
-
client = global.client;
|
|
13
|
-
|
|
14
|
-
// Create test organization for each test
|
|
15
|
-
testOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(async () => {
|
|
19
|
-
// Clean up test organization
|
|
20
|
-
await TestOrganizationManager.cleanupTestOrganization(client, testOrg);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('createDomain', () => {
|
|
24
|
-
it('should create domain without domainType (backward compatibility)', async () => {
|
|
25
|
-
const domainName = TestDataGenerator.generateUniqueDomainName('backward-compat');
|
|
26
|
-
|
|
27
|
-
const response = await client.domain.createDomain(testOrg, domainName);
|
|
28
|
-
|
|
29
|
-
expect(response).toBeDefined();
|
|
30
|
-
expect(response.domain).toBeDefined();
|
|
31
|
-
expect(response.domain?.domain).toBe(domainName);
|
|
32
|
-
expect(response.domain?.id).toBeDefined();
|
|
33
|
-
expect(response.domain?.organizationId).toBe(testOrg);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should create domain with ALLOWED_EMAIL_DOMAIN type', async () => {
|
|
37
|
-
const domainName = TestDataGenerator.generateUniqueDomainName('allowed-email');
|
|
38
|
-
|
|
39
|
-
const response = await client.domain.createDomain(testOrg, domainName, {
|
|
40
|
-
domainType: DomainType.ALLOWED_EMAIL_DOMAIN
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(response).toBeDefined();
|
|
44
|
-
expect(response.domain).toBeDefined();
|
|
45
|
-
expect(response.domain?.domain).toBe(domainName);
|
|
46
|
-
expect(response.domain?.domainType).toBe(DomainType.ALLOWED_EMAIL_DOMAIN);
|
|
47
|
-
expect(response.domain?.id).toBeDefined();
|
|
48
|
-
expect(response.domain?.organizationId).toBe(testOrg);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should create domain with ORGANIZATION_DOMAIN type', async () => {
|
|
52
|
-
const domainName = TestDataGenerator.generateUniqueDomainName('org-domain');
|
|
53
|
-
|
|
54
|
-
const response = await client.domain.createDomain(testOrg, domainName, {
|
|
55
|
-
domainType: DomainType.ORGANIZATION_DOMAIN
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
expect(response).toBeDefined();
|
|
59
|
-
expect(response.domain).toBeDefined();
|
|
60
|
-
expect(response.domain?.domain).toBe(domainName);
|
|
61
|
-
expect(response.domain?.domainType).toBe(DomainType.ORGANIZATION_DOMAIN);
|
|
62
|
-
expect(response.domain?.id).toBeDefined();
|
|
63
|
-
expect(response.domain?.organizationId).toBe(testOrg);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should create multiple domains of different types', async () => {
|
|
67
|
-
const allowedDomainName = TestDataGenerator.generateUniqueDomainName('allowed');
|
|
68
|
-
const orgDomainName = TestDataGenerator.generateUniqueDomainName('org');
|
|
69
|
-
|
|
70
|
-
// Create allowed email domain
|
|
71
|
-
const allowedResponse = await client.domain.createDomain(testOrg, allowedDomainName, {
|
|
72
|
-
domainType: DomainType.ALLOWED_EMAIL_DOMAIN
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Create organization domain
|
|
76
|
-
const orgResponse = await client.domain.createDomain(testOrg, orgDomainName, {
|
|
77
|
-
domainType: DomainType.ORGANIZATION_DOMAIN
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
expect(allowedResponse.domain?.domainType).toBe(DomainType.ALLOWED_EMAIL_DOMAIN);
|
|
81
|
-
expect(orgResponse.domain?.domainType).toBe(DomainType.ORGANIZATION_DOMAIN);
|
|
82
|
-
expect(allowedResponse.domain?.domain).toBe(allowedDomainName);
|
|
83
|
-
expect(orgResponse.domain?.domain).toBe(orgDomainName);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should create domain using TestDomainManager utility', async () => {
|
|
87
|
-
const { domainId, domainName, domainType, response } = await TestDomainManager.createTestDomain(
|
|
88
|
-
client,
|
|
89
|
-
testOrg,
|
|
90
|
-
'allowed'
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
expect(domainId).toBeDefined();
|
|
94
|
-
expect(domainName).toBeDefined();
|
|
95
|
-
expect(domainType).toBe(DomainType.ALLOWED_EMAIL_DOMAIN);
|
|
96
|
-
expect(response.domain?.domain).toBe(domainName);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('listDomains', () => {
|
|
101
|
-
it('should list domains for organization', async () => {
|
|
102
|
-
// Create a test domain first
|
|
103
|
-
const { domainName } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
104
|
-
|
|
105
|
-
const response = await client.domain.listDomains(testOrg);
|
|
106
|
-
|
|
107
|
-
expect(response).toBeDefined();
|
|
108
|
-
expect(response.domains).toBeDefined();
|
|
109
|
-
expect(Array.isArray(response.domains)).toBe(true);
|
|
110
|
-
expect(response.domains.length).toBeGreaterThan(0);
|
|
111
|
-
|
|
112
|
-
// Verify basic domain attributes
|
|
113
|
-
const firstDomain = response.domains[0];
|
|
114
|
-
expect(firstDomain.id).toBeDefined();
|
|
115
|
-
expect(firstDomain.domain).toBeDefined();
|
|
116
|
-
expect(firstDomain.organizationId).toBe(testOrg);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should return empty list when no domains exist', async () => {
|
|
120
|
-
// Use a fresh organization without any domains
|
|
121
|
-
const freshOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
const response = await client.domain.listDomains(freshOrg);
|
|
125
|
-
|
|
126
|
-
expect(response).toBeDefined();
|
|
127
|
-
expect(response.domains).toBeDefined();
|
|
128
|
-
expect(Array.isArray(response.domains)).toBe(true);
|
|
129
|
-
expect(response.domains.length).toBe(0);
|
|
130
|
-
} finally {
|
|
131
|
-
await TestOrganizationManager.cleanupTestOrganization(client, freshOrg);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should list domains with different types', async () => {
|
|
136
|
-
// Create domains of different types
|
|
137
|
-
const { domainName: allowedDomainName } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
138
|
-
const { domainName: orgDomainName } = await TestDomainManager.createTestDomain(client, testOrg, 'organization');
|
|
139
|
-
|
|
140
|
-
const response = await client.domain.listDomains(testOrg);
|
|
141
|
-
|
|
142
|
-
expect(response.domains.length).toBeGreaterThanOrEqual(2);
|
|
143
|
-
|
|
144
|
-
const domainNames = response.domains.map(d => d.domain);
|
|
145
|
-
const domainTypes = response.domains.map(d => d.domainType);
|
|
146
|
-
|
|
147
|
-
expect(domainNames).toContain(allowedDomainName);
|
|
148
|
-
expect(domainNames).toContain(orgDomainName);
|
|
149
|
-
expect(domainTypes).toContain(DomainType.ALLOWED_EMAIL_DOMAIN);
|
|
150
|
-
expect(domainTypes).toContain(DomainType.ORGANIZATION_DOMAIN);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should list domains filtered by ALLOWED_EMAIL_DOMAIN type', async () => {
|
|
154
|
-
// Create domains of different types
|
|
155
|
-
const { domainName: allowedDomainName } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
156
|
-
const { domainName: orgDomainName } = await TestDomainManager.createTestDomain(client, testOrg, 'organization');
|
|
157
|
-
|
|
158
|
-
// Filter by ALLOWED_EMAIL_DOMAIN type
|
|
159
|
-
const response = await client.domain.listDomains(testOrg, {
|
|
160
|
-
domainType: DomainType.ALLOWED_EMAIL_DOMAIN
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
expect(response).toBeDefined();
|
|
164
|
-
expect(response.domains).toBeDefined();
|
|
165
|
-
expect(Array.isArray(response.domains)).toBe(true);
|
|
166
|
-
|
|
167
|
-
// Verify all returned domains are of type ALLOWED_EMAIL_DOMAIN
|
|
168
|
-
response.domains.forEach(domain => {
|
|
169
|
-
expect(domain.domainType).toBe(DomainType.ALLOWED_EMAIL_DOMAIN);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// Verify the allowed domain is in the filtered list
|
|
173
|
-
const domainNames = response.domains.map(d => d.domain);
|
|
174
|
-
expect(domainNames).toContain(allowedDomainName);
|
|
175
|
-
|
|
176
|
-
// Verify the organization domain is NOT in the filtered list
|
|
177
|
-
expect(domainNames).not.toContain(orgDomainName);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('should list domains filtered by ORGANIZATION_DOMAIN type', async () => {
|
|
181
|
-
// Create domains of different types
|
|
182
|
-
const { domainName: allowedDomainName } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
183
|
-
const { domainName: orgDomainName } = await TestDomainManager.createTestDomain(client, testOrg, 'organization');
|
|
184
|
-
|
|
185
|
-
// Filter by ORGANIZATION_DOMAIN type
|
|
186
|
-
const response = await client.domain.listDomains(testOrg, {
|
|
187
|
-
domainType: DomainType.ORGANIZATION_DOMAIN
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
expect(response).toBeDefined();
|
|
191
|
-
expect(response.domains).toBeDefined();
|
|
192
|
-
expect(Array.isArray(response.domains)).toBe(true);
|
|
193
|
-
|
|
194
|
-
// Verify all returned domains are of type ORGANIZATION_DOMAIN
|
|
195
|
-
response.domains.forEach(domain => {
|
|
196
|
-
expect(domain.domainType).toBe(DomainType.ORGANIZATION_DOMAIN);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// Verify the organization domain is in the filtered list
|
|
200
|
-
const domainNames = response.domains.map(d => d.domain);
|
|
201
|
-
expect(domainNames).toContain(orgDomainName);
|
|
202
|
-
|
|
203
|
-
// Verify the allowed domain is NOT in the filtered list
|
|
204
|
-
expect(domainNames).not.toContain(allowedDomainName);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
describe('getDomain', () => {
|
|
209
|
-
it('should get domain by ID successfully', async () => {
|
|
210
|
-
// Create a test domain first
|
|
211
|
-
const { domainId, domainName } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
212
|
-
|
|
213
|
-
const response = await client.domain.getDomain(testOrg, domainId);
|
|
214
|
-
|
|
215
|
-
expect(response).toBeDefined();
|
|
216
|
-
expect(response.domain).toBeDefined();
|
|
217
|
-
expect(response.domain?.id).toBe(domainId);
|
|
218
|
-
expect(response.domain?.domain).toBe(domainName);
|
|
219
|
-
expect(response.domain?.organizationId).toBe(testOrg);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should throw error for non-existent domain', async () => {
|
|
223
|
-
const nonExistentDomainId = 'non-existent-domain-id';
|
|
224
|
-
|
|
225
|
-
await expect(
|
|
226
|
-
client.domain.getDomain(testOrg, nonExistentDomainId)
|
|
227
|
-
).rejects.toThrow();
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('should throw error for invalid organization ID', async () => {
|
|
231
|
-
// Create a test domain first
|
|
232
|
-
const { domainId } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
233
|
-
const invalidOrgId = 'invalid-org-id';
|
|
234
|
-
|
|
235
|
-
await expect(
|
|
236
|
-
client.domain.getDomain(invalidOrgId, domainId)
|
|
237
|
-
).rejects.toThrow();
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe('deleteDomain', () => {
|
|
242
|
-
it('should delete domain successfully', async () => {
|
|
243
|
-
// Create a test domain for deletion
|
|
244
|
-
const { domainId, domainName } = await TestDomainManager.createTestDomain(client, testOrg, 'allowed');
|
|
245
|
-
|
|
246
|
-
// Verify domain exists before deletion
|
|
247
|
-
const getResponse = await client.domain.getDomain(testOrg, domainId);
|
|
248
|
-
expect(getResponse.domain?.id).toBe(domainId);
|
|
249
|
-
|
|
250
|
-
// Delete the domain
|
|
251
|
-
const deleteResponse = await client.domain.deleteDomain(testOrg, domainId);
|
|
252
|
-
expect(deleteResponse).toBeDefined();
|
|
253
|
-
|
|
254
|
-
// Verify domain is deleted by trying to get it
|
|
255
|
-
await expect(
|
|
256
|
-
client.domain.getDomain(testOrg, domainId)
|
|
257
|
-
).rejects.toThrow();
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('should throw error when deleting non-existent domain', async () => {
|
|
261
|
-
const nonExistentDomainId = 'non-existent-domain-id';
|
|
262
|
-
|
|
263
|
-
await expect(
|
|
264
|
-
client.domain.deleteDomain(testOrg, nonExistentDomainId)
|
|
265
|
-
).rejects.toThrow();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe('error handling', () => {
|
|
272
|
-
it('should handle invalid organization ID', async () => {
|
|
273
|
-
const invalidOrgId = 'invalid-org-id';
|
|
274
|
-
const domainName = TestDataGenerator.generateUniqueDomainName('error-test');
|
|
275
|
-
|
|
276
|
-
await expect(
|
|
277
|
-
client.domain.createDomain(invalidOrgId, domainName)
|
|
278
|
-
).rejects.toThrow();
|
|
279
|
-
|
|
280
|
-
await expect(
|
|
281
|
-
client.domain.listDomains(invalidOrgId)
|
|
282
|
-
).rejects.toThrow();
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('should handle invalid domain name format', async () => {
|
|
286
|
-
const invalidDomainName = 'invalid-domain-name';
|
|
287
|
-
|
|
288
|
-
await expect(
|
|
289
|
-
client.domain.createDomain(testOrg, invalidDomainName)
|
|
290
|
-
).rejects.toThrow();
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
3
|
-
import { TestDataGenerator, TestOrganizationManager } from './utils/test-data';
|
|
4
|
-
|
|
5
|
-
describe('Organizations', () => {
|
|
6
|
-
let client: ScalekitClient;
|
|
7
|
-
let testOrg: string;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
// Use global client
|
|
11
|
-
client = global.client;
|
|
12
|
-
|
|
13
|
-
// Create test organization for each test
|
|
14
|
-
testOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
// Clean up test organization
|
|
19
|
-
await TestOrganizationManager.cleanupTestOrganization(client, testOrg);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('listOrganization', () => {
|
|
23
|
-
it('should list organizations', async () => {
|
|
24
|
-
const organizations = await client.organization.listOrganization(TestDataGenerator.generatePaginationParams());
|
|
25
|
-
|
|
26
|
-
expect(organizations).toBeDefined();
|
|
27
|
-
expect(organizations.organizations).toBeDefined();
|
|
28
|
-
expect(Array.isArray(organizations.organizations)).toBe(true);
|
|
29
|
-
expect(organizations.organizations.length).toBeGreaterThan(0);
|
|
30
|
-
|
|
31
|
-
// Verify basic organization attributes
|
|
32
|
-
const firstOrg = organizations.organizations[0];
|
|
33
|
-
expect(firstOrg.id).toBeDefined();
|
|
34
|
-
expect(firstOrg.displayName).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should handle pagination', async () => {
|
|
38
|
-
const firstPage = await client.organization.listOrganization(TestDataGenerator.generatePaginationParams(5));
|
|
39
|
-
|
|
40
|
-
expect(firstPage).toBeDefined();
|
|
41
|
-
expect(firstPage.organizations.length).toBeLessThanOrEqual(5);
|
|
42
|
-
|
|
43
|
-
if (firstPage.nextPageToken) {
|
|
44
|
-
const secondPage = await client.organization.listOrganization({
|
|
45
|
-
pageSize: 5,
|
|
46
|
-
pageToken: firstPage.nextPageToken
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
expect(secondPage).toBeDefined();
|
|
50
|
-
expect(secondPage.organizations).toBeDefined();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('getOrganization', () => {
|
|
56
|
-
it('should get organization by ID', async () => {
|
|
57
|
-
const organization = await client.organization.getOrganization(testOrg);
|
|
58
|
-
|
|
59
|
-
expect(organization).toBeDefined();
|
|
60
|
-
expect(organization.organization).toBeDefined();
|
|
61
|
-
expect(organization.organization?.id).toBe(testOrg);
|
|
62
|
-
expect(organization.organization?.displayName).toBeDefined();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('upsertUserManagementSettings', () => {
|
|
67
|
-
it('should upsert max allowed users', async () => {
|
|
68
|
-
const maxUsers = 50;
|
|
69
|
-
let settings;
|
|
70
|
-
try {
|
|
71
|
-
settings = await client.organization.upsertUserManagementSettings(testOrg, { maxAllowedUsers: maxUsers });
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.warn('Skipping upsertUserManagementSettings test due to error:', error);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
expect(settings).toBeDefined();
|
|
78
|
-
expect(settings?.maxAllowedUsers).toBe(maxUsers);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { TemplateType } from '../src/pkg/grpc/scalekit/v1/auth/passwordless_pb';
|
|
3
|
-
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
4
|
-
import { TestDataGenerator } from './utils/test-data';
|
|
5
|
-
|
|
6
|
-
describe('Passwordless', () => {
|
|
7
|
-
let client: ScalekitClient;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
// Use global client
|
|
11
|
-
client = global.client;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('sendPasswordlessEmail', () => {
|
|
15
|
-
it('should send passwordless email with basic parameters', async () => {
|
|
16
|
-
const email = TestDataGenerator.generateUniqueEmail();
|
|
17
|
-
|
|
18
|
-
const response = await client.passwordless.sendPasswordlessEmail(email, TestDataGenerator.generatePasswordlessEmailData());
|
|
19
|
-
|
|
20
|
-
expect(response).toBeDefined();
|
|
21
|
-
expect(response.authRequestId).toBeDefined();
|
|
22
|
-
expect(response.expiresAt).toBeDefined();
|
|
23
|
-
expect(response.expiresIn).toBe(3600);
|
|
24
|
-
expect(response.passwordlessType).toBeDefined();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should send passwordless email with template variables', async () => {
|
|
28
|
-
const email = TestDataGenerator.generateUniqueEmail();
|
|
29
|
-
|
|
30
|
-
const response = await client.passwordless.sendPasswordlessEmail(email, TestDataGenerator.generatePasswordlessEmailWithTemplateData());
|
|
31
|
-
|
|
32
|
-
expect(response).toBeDefined();
|
|
33
|
-
expect(response.authRequestId).toBeDefined();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should throw error for invalid email', async () => {
|
|
37
|
-
await expect(
|
|
38
|
-
client.passwordless.sendPasswordlessEmail('', {
|
|
39
|
-
template: TemplateType.SIGNIN
|
|
40
|
-
})
|
|
41
|
-
).rejects.toThrow('Email must be a valid string');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should throw error for invalid template type', async () => {
|
|
45
|
-
const email = TestDataGenerator.generateUniqueEmail();
|
|
46
|
-
|
|
47
|
-
await expect(
|
|
48
|
-
client.passwordless.sendPasswordlessEmail(email, {
|
|
49
|
-
template: 'INVALID_TEMPLATE' as any
|
|
50
|
-
})
|
|
51
|
-
).rejects.toThrow('Invalid template type');
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('verifyPasswordlessEmail', () => {
|
|
56
|
-
it('should throw error when neither code nor linkToken is provided', async () => {
|
|
57
|
-
await expect(
|
|
58
|
-
client.passwordless.verifyPasswordlessEmail({})
|
|
59
|
-
).rejects.toThrow('Either code or linkToken must be provided');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should verify with code', async () => {
|
|
63
|
-
// Mock code for testing - expected to fail
|
|
64
|
-
const credential = TestDataGenerator.generateCredentialData('code');
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const response = await client.passwordless.verifyPasswordlessEmail(credential);
|
|
68
|
-
expect(response).toBeDefined();
|
|
69
|
-
} catch (error) {
|
|
70
|
-
// Expected failure with mock code
|
|
71
|
-
expect(error).toBeDefined();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should verify with linkToken', async () => {
|
|
76
|
-
// Mock linkToken for testing - expected to fail
|
|
77
|
-
const credential = TestDataGenerator.generateCredentialData('linkToken');
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const response = await client.passwordless.verifyPasswordlessEmail(credential);
|
|
81
|
-
expect(response).toBeDefined();
|
|
82
|
-
} catch (error) {
|
|
83
|
-
// Expected failure with mock linkToken
|
|
84
|
-
expect(error).toBeDefined();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('resendPasswordlessEmail', () => {
|
|
90
|
-
it('should resend passwordless email', async () => {
|
|
91
|
-
// Send initial passwordless email
|
|
92
|
-
const email = TestDataGenerator.generateUniqueEmail();
|
|
93
|
-
|
|
94
|
-
const sendResponse = await client.passwordless.sendPasswordlessEmail(email, TestDataGenerator.generatePasswordlessEmailData());
|
|
95
|
-
|
|
96
|
-
// Resend the email
|
|
97
|
-
const resendResponse = await client.passwordless.resendPasswordlessEmail(
|
|
98
|
-
sendResponse.authRequestId
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
expect(resendResponse).toBeDefined();
|
|
102
|
-
expect(resendResponse.authRequestId).toBeDefined();
|
|
103
|
-
expect(resendResponse.expiresAt).toBeDefined();
|
|
104
|
-
expect(resendResponse.expiresIn).toBeDefined();
|
|
105
|
-
expect(resendResponse.passwordlessType).toBeDefined();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|