@datalayer/core 0.0.12 → 0.0.13
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/README.md +2 -2
- package/lib/api/DatalayerApi.d.ts +38 -26
- package/lib/api/DatalayerApi.js +35 -8
- package/lib/api/iam/authentication.d.ts +8 -7
- package/lib/api/iam/authentication.js +14 -15
- package/lib/api/iam/healthz.d.ts +3 -2
- package/lib/api/iam/healthz.js +5 -3
- package/lib/api/iam/index.d.ts +9 -4
- package/lib/api/iam/index.js +9 -4
- package/lib/api/iam/oauth2.d.ts +115 -0
- package/lib/api/iam/oauth2.js +309 -0
- package/lib/api/iam/profile.d.ts +8 -1
- package/lib/api/iam/profile.js +17 -2
- package/lib/api/iam/usage.d.ts +56 -0
- package/lib/api/iam/usage.js +39 -0
- package/lib/api/index.d.ts +6 -5
- package/lib/api/index.js +6 -5
- package/lib/api/runtimes/environments.js +3 -2
- package/lib/api/runtimes/healthz.d.ts +3 -13
- package/lib/api/runtimes/healthz.js +4 -3
- package/lib/api/runtimes/index.d.ts +3 -2
- package/lib/api/runtimes/index.js +3 -2
- package/lib/api/runtimes/runtimes.js +17 -6
- package/lib/api/runtimes/snapshots.js +3 -2
- package/lib/api/spacer/documents.d.ts +12 -0
- package/lib/api/spacer/documents.js +43 -0
- package/lib/api/spacer/healthz.d.ts +3 -13
- package/lib/api/spacer/healthz.js +4 -3
- package/lib/api/spacer/index.d.ts +4 -2
- package/lib/api/spacer/index.js +4 -2
- package/lib/api/spacer/items.d.ts +9 -1
- package/lib/api/spacer/items.js +17 -2
- package/lib/api/spacer/lexicals.js +3 -2
- package/lib/api/spacer/notebooks.js +3 -2
- package/lib/api/spacer/spaces.js +3 -2
- package/lib/api/spacer/users.js +3 -2
- package/lib/api/types/common.d.ts +64 -0
- package/lib/api/types/iam.d.ts +88 -65
- package/lib/api/types/index.d.ts +4 -2
- package/lib/api/types/index.js +4 -2
- package/lib/api/types/runtimes.d.ts +9 -39
- package/lib/api/types/spacer.d.ts +37 -65
- package/lib/api/utils/validation.d.ts +24 -1
- package/lib/api/utils/validation.js +62 -1
- package/lib/client/base.d.ts +75 -0
- package/lib/client/base.js +199 -0
- package/lib/client/constants.d.ts +22 -0
- package/lib/client/constants.js +22 -0
- package/lib/client/index.d.ts +108 -0
- package/lib/client/index.js +79 -0
- package/lib/client/mixins/IAMMixin.d.ts +54 -0
- package/lib/client/mixins/IAMMixin.js +181 -0
- package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
- package/lib/client/mixins/RuntimesMixin.js +229 -0
- package/lib/client/mixins/SpacerMixin.d.ts +111 -0
- package/lib/client/mixins/SpacerMixin.js +340 -0
- package/lib/client/models/Credits.d.ts +91 -0
- package/lib/client/models/Credits.js +130 -0
- package/lib/client/models/Environment.d.ts +73 -0
- package/lib/client/models/Environment.js +88 -0
- package/lib/client/models/HealthCheck.d.ts +72 -0
- package/lib/client/models/HealthCheck.js +107 -0
- package/lib/client/models/Item.d.ts +69 -0
- package/lib/client/models/Item.js +191 -0
- package/lib/client/models/Lexical.d.ts +83 -0
- package/lib/client/models/Lexical.js +152 -0
- package/lib/client/models/Notebook.d.ts +87 -0
- package/lib/client/models/Notebook.js +153 -0
- package/lib/client/models/Runtime.d.ts +122 -0
- package/lib/client/models/Runtime.js +204 -0
- package/lib/client/models/Snapshot.d.ts +92 -0
- package/lib/client/models/Snapshot.js +139 -0
- package/lib/client/models/Space.d.ts +135 -0
- package/lib/client/models/Space.js +234 -0
- package/lib/client/models/User.d.ts +64 -0
- package/lib/client/models/User.js +83 -0
- package/lib/client/models/index.d.ts +26 -0
- package/lib/client/models/index.js +25 -0
- package/lib/client/utils/mixins.d.ts +12 -0
- package/lib/{sdk/client → client}/utils/mixins.js +0 -28
- package/lib/client/utils/spacerUtils.d.ts +18 -0
- package/lib/client/utils/spacerUtils.js +32 -0
- package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
- package/lib/collaboration/DatalayerCollaboration.js +2 -2
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
- package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
- package/lib/components/progress/CreditsIndicator.d.ts +1 -1
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.js +1 -1
- package/lib/components/runtimes/RuntimePickerCell.js +2 -2
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
- package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
- package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
- package/lib/config/Configuration.d.ts +8 -0
- package/lib/hooks/useDatalayer.js +1 -1
- package/lib/hooks/useRuntimes.js +1 -1
- package/lib/hooks/useToast.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -2
- package/lib/sdk/index.d.ts +5 -4
- package/lib/sdk/index.js +6 -5
- package/lib/services/DatalayerServiceManager.js +1 -1
- package/lib/state/substates/CoreState.js +2 -0
- package/lib/state/substates/RuntimesState.d.ts +1 -1
- package/lib/state/substates/RuntimesState.js +1 -1
- package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
- package/lib/{sdk/stateful → stateful}/index.js +1 -1
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
- package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
- package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
- package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
- package/lib/stateful/runtimes/apis.js +5 -0
- package/package.json +12 -10
- package/lib/__tests__/hooks.test.d.ts +0 -1
- package/lib/__tests__/hooks.test.js +0 -19
- package/lib/__tests__/index.test.d.ts +0 -1
- package/lib/__tests__/index.test.js +0 -27
- package/lib/__tests__/integration.test.d.ts +0 -1
- package/lib/__tests__/integration.test.js +0 -57
- package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
- package/lib/__tests__/shared/cleanup-shared.js +0 -228
- package/lib/__tests__/shared/test-config.d.ts +0 -51
- package/lib/__tests__/shared/test-config.js +0 -110
- package/lib/__tests__/shared/test-constants.d.ts +0 -66
- package/lib/__tests__/shared/test-constants.js +0 -79
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -59
- package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
- package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
- package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
- package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
- package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.integration.test.js +0 -369
- package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.integration.test.js +0 -519
- package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
- package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
- package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
- package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
- package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
- package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
- package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
- package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
- package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
- package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
- package/lib/api/utils/__tests__/validation.test.js +0 -109
- package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
- package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
- package/lib/sdk/client/base.d.ts +0 -88
- package/lib/sdk/client/base.js +0 -112
- package/lib/sdk/client/index.d.ts +0 -192
- package/lib/sdk/client/index.js +0 -128
- package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
- package/lib/sdk/client/mixins/HealthMixin.js +0 -133
- package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
- package/lib/sdk/client/mixins/IAMMixin.js +0 -83
- package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
- package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
- package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
- package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
- package/lib/sdk/client/models/Lexical.d.ts +0 -156
- package/lib/sdk/client/models/Lexical.js +0 -275
- package/lib/sdk/client/models/Notebook.d.ts +0 -174
- package/lib/sdk/client/models/Notebook.js +0 -311
- package/lib/sdk/client/models/Runtime.d.ts +0 -221
- package/lib/sdk/client/models/Runtime.js +0 -341
- package/lib/sdk/client/models/Snapshot.d.ts +0 -156
- package/lib/sdk/client/models/Snapshot.js +0 -244
- package/lib/sdk/client/models/Space.d.ts +0 -182
- package/lib/sdk/client/models/Space.js +0 -276
- package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
- package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
- package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
- package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
- package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
- package/lib/sdk/client/models/index.d.ts +0 -30
- package/lib/sdk/client/models/index.js +0 -30
- package/lib/sdk/client/utils/mixins.d.ts +0 -42
- /package/lib/{sdk/stateful/runtimes/apis.js → api/types/common.js} +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Test constants for API unit tests
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* A valid mock JWT token for testing
|
|
10
|
-
* This token has the correct JWT structure (header.payload.signature) but is not cryptographically valid
|
|
11
|
-
*
|
|
12
|
-
* Decoded header: {"alg":"HS256","typ":"JWT"}
|
|
13
|
-
* Decoded payload: {"sub":"test-user","iss":"test-issuer","iat":1700000000,"exp":9999999999,"aud":"test-audience"}
|
|
14
|
-
*
|
|
15
|
-
* The token is constructed to:
|
|
16
|
-
* - Have three parts separated by dots
|
|
17
|
-
* - Have valid base64url encoded parts
|
|
18
|
-
* - Have proper JWT header with alg and typ
|
|
19
|
-
* - Have common JWT claims in payload
|
|
20
|
-
* - Have an expiration far in the future to avoid expiration errors
|
|
21
|
-
* - Be long enough to pass length validation (>100 chars)
|
|
22
|
-
*/
|
|
23
|
-
export const MOCK_JWT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIiLCJpc3MiOiJ0ZXN0LWlzc3VlciIsImlhdCI6MTcwMDAwMDAwMCwiZXhwIjo5OTk5OTk5OTk5LCJhdWQiOiJ0ZXN0LWF1ZGllbmNlIn0.abcdefghijklmnopqrstuvwxyz012345678901234567890';
|
|
24
|
-
/**
|
|
25
|
-
* An invalid token (not JWT format) for negative testing
|
|
26
|
-
*/
|
|
27
|
-
export const INVALID_TOKEN = 'invalid-token';
|
|
28
|
-
/**
|
|
29
|
-
* A malformed JWT token (only two parts instead of three)
|
|
30
|
-
*/
|
|
31
|
-
export const MALFORMED_JWT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ';
|
|
32
|
-
/**
|
|
33
|
-
* A JWT token with an expired timestamp
|
|
34
|
-
* Decoded payload: {"sub":"test-user","exp":1000000000}
|
|
35
|
-
*/
|
|
36
|
-
export const EXPIRED_JWT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIiLCJleHAiOjEwMDAwMDAwMDB9.abcdefghijklmnopqrstuvwxyz012345678901234567890';
|
|
37
|
-
/**
|
|
38
|
-
* Mock API responses
|
|
39
|
-
*/
|
|
40
|
-
export const MOCK_ENVIRONMENTS_RESPONSE = {
|
|
41
|
-
success: true,
|
|
42
|
-
message: 'Environments retrieved successfully',
|
|
43
|
-
environments: [
|
|
44
|
-
{
|
|
45
|
-
title: 'Python Base',
|
|
46
|
-
description: 'Basic Python environment',
|
|
47
|
-
dockerImage: 'python:3.9',
|
|
48
|
-
language: 'python',
|
|
49
|
-
burning_rate: 1,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
title: 'R Statistical',
|
|
53
|
-
description: 'R environment for statistical computing',
|
|
54
|
-
dockerImage: 'r-base:4.3',
|
|
55
|
-
language: 'r',
|
|
56
|
-
burning_rate: 2,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
};
|
|
60
|
-
export const MOCK_RUNTIME_RESPONSE = {
|
|
61
|
-
success: true,
|
|
62
|
-
message: 'Runtime retrieved successfully',
|
|
63
|
-
runtime: {
|
|
64
|
-
pod_name: 'test-runtime-pod',
|
|
65
|
-
status: 'running',
|
|
66
|
-
environment: 'python-base',
|
|
67
|
-
created_at: '2024-01-01T00:00:00Z',
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
export const MOCK_SNAPSHOT_RESPONSE = {
|
|
71
|
-
success: true,
|
|
72
|
-
message: 'Snapshot retrieved successfully',
|
|
73
|
-
snapshot: {
|
|
74
|
-
id: 'test-snapshot-123',
|
|
75
|
-
name: 'Test Snapshot',
|
|
76
|
-
created_at: '2024-01-01T00:00:00Z',
|
|
77
|
-
size: 1024000,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import { formatString, addNumbers, isDefined, delay } from '../utils';
|
|
7
|
-
describe('utils', () => {
|
|
8
|
-
describe('formatString', () => {
|
|
9
|
-
it('should trim and lowercase strings', () => {
|
|
10
|
-
expect(formatString(' HELLO WORLD ')).toBe('hello world');
|
|
11
|
-
});
|
|
12
|
-
it('should handle empty strings', () => {
|
|
13
|
-
expect(formatString('')).toBe('');
|
|
14
|
-
});
|
|
15
|
-
it('should handle already formatted strings', () => {
|
|
16
|
-
expect(formatString('hello')).toBe('hello');
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe('addNumbers', () => {
|
|
20
|
-
it('should add positive numbers', () => {
|
|
21
|
-
expect(addNumbers(2, 3)).toBe(5);
|
|
22
|
-
});
|
|
23
|
-
it('should add negative numbers', () => {
|
|
24
|
-
expect(addNumbers(-2, -3)).toBe(-5);
|
|
25
|
-
});
|
|
26
|
-
it('should add zero', () => {
|
|
27
|
-
expect(addNumbers(5, 0)).toBe(5);
|
|
28
|
-
});
|
|
29
|
-
it('should handle decimals', () => {
|
|
30
|
-
expect(addNumbers(1.5, 2.5)).toBe(4);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('isDefined', () => {
|
|
34
|
-
it('should return true for defined values', () => {
|
|
35
|
-
expect(isDefined('hello')).toBe(true);
|
|
36
|
-
expect(isDefined(0)).toBe(true);
|
|
37
|
-
expect(isDefined(false)).toBe(true);
|
|
38
|
-
expect(isDefined([])).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
it('should return false for undefined', () => {
|
|
41
|
-
expect(isDefined(undefined)).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
it('should return false for null', () => {
|
|
44
|
-
expect(isDefined(null)).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe('delay', () => {
|
|
48
|
-
it('should resolve after specified time', async () => {
|
|
49
|
-
const start = Date.now();
|
|
50
|
-
await delay(100);
|
|
51
|
-
const end = Date.now();
|
|
52
|
-
expect(end - start).toBeGreaterThanOrEqual(90); // Allow some tolerance
|
|
53
|
-
});
|
|
54
|
-
it('should return a Promise', () => {
|
|
55
|
-
const result = delay(1);
|
|
56
|
-
expect(result).toBeInstanceOf(Promise);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
6
|
-
import { authentication } from '../iam';
|
|
7
|
-
import { testConfig, debugLog, skipIfNoToken, } from '../../__tests__/shared/test-config';
|
|
8
|
-
let DATALAYER_TOKEN;
|
|
9
|
-
let SESSION_TOKEN;
|
|
10
|
-
let BASE_URL;
|
|
11
|
-
// Skip all tests if no token is available
|
|
12
|
-
const skipTests = skipIfNoToken();
|
|
13
|
-
beforeAll(async () => {
|
|
14
|
-
if (skipTests) {
|
|
15
|
-
console.log('WARNING: Skipping IAM integration tests: No Datalayer API token configured');
|
|
16
|
-
console.log(' Set DATALAYER_API_TOKEN env var or DATALAYER_TEST_TOKEN in .env.test');
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// Get token and base URL from test config
|
|
20
|
-
DATALAYER_TOKEN = testConfig.getToken();
|
|
21
|
-
BASE_URL = testConfig.getBaseUrl('IAM');
|
|
22
|
-
debugLog('Test configuration loaded');
|
|
23
|
-
debugLog('Base URL:', BASE_URL);
|
|
24
|
-
debugLog('Token available:', !!DATALAYER_TOKEN);
|
|
25
|
-
// Login to get a session token for testing
|
|
26
|
-
try {
|
|
27
|
-
const loginResponse = await authentication.login({
|
|
28
|
-
token: DATALAYER_TOKEN,
|
|
29
|
-
}, BASE_URL);
|
|
30
|
-
SESSION_TOKEN = loginResponse.token;
|
|
31
|
-
debugLog('Got session token for testing');
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
console.error('Failed to get session token:', error);
|
|
35
|
-
// Fall back to using the DATALAYER_TOKEN
|
|
36
|
-
SESSION_TOKEN = DATALAYER_TOKEN;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
describe.skipIf(skipTests)('IAM Authentication Integration Tests', () => {
|
|
40
|
-
describe('login', () => {
|
|
41
|
-
it('should successfully login with valid token (expecting 201 status)', async () => {
|
|
42
|
-
console.log('Testing login with valid token (expecting 201 Created)...');
|
|
43
|
-
// The API should return 201 Created for successful login
|
|
44
|
-
const response = await authentication.login({
|
|
45
|
-
token: DATALAYER_TOKEN,
|
|
46
|
-
}, BASE_URL);
|
|
47
|
-
console.log('Login response:', JSON.stringify(response, null, 2));
|
|
48
|
-
// Verify response structure for successful login (201 status)
|
|
49
|
-
expect(response).toBeDefined();
|
|
50
|
-
expect(response.success).toBe(true);
|
|
51
|
-
expect(response.message).toBeDefined();
|
|
52
|
-
// The message should indicate login success
|
|
53
|
-
expect(response.message.toLowerCase()).toContain('success');
|
|
54
|
-
expect(response.token).toBeDefined();
|
|
55
|
-
expect(typeof response.token).toBe('string');
|
|
56
|
-
expect(response.user).toBeDefined();
|
|
57
|
-
expect(response.user.id).toBeDefined();
|
|
58
|
-
expect(response.user.uid).toBeDefined();
|
|
59
|
-
expect(response.user.email_s).toBeDefined();
|
|
60
|
-
expect(response.user.handle_s).toBeDefined();
|
|
61
|
-
console.log('Token login successful (201 Created expected)');
|
|
62
|
-
console.log('Success:', response.success);
|
|
63
|
-
console.log('Message:', response.message);
|
|
64
|
-
console.log('User ID:', response.user.id);
|
|
65
|
-
console.log('User UID:', response.user.uid);
|
|
66
|
-
console.log('User handle:', response.user.handle_s);
|
|
67
|
-
console.log('User email:', response.user.email_s);
|
|
68
|
-
});
|
|
69
|
-
it('should successfully login with valid token using default URL', async () => {
|
|
70
|
-
console.log('Testing login with valid token using default URL...');
|
|
71
|
-
const response = await authentication.login({
|
|
72
|
-
token: DATALAYER_TOKEN,
|
|
73
|
-
});
|
|
74
|
-
console.log('Login response with default URL:', JSON.stringify(response, null, 2));
|
|
75
|
-
// Verify response structure
|
|
76
|
-
expect(response).toBeDefined();
|
|
77
|
-
expect(response.success).toBe(true);
|
|
78
|
-
expect(response.message).toBeDefined();
|
|
79
|
-
expect(response.token).toBeDefined();
|
|
80
|
-
expect(typeof response.token).toBe('string');
|
|
81
|
-
expect(response.user).toBeDefined();
|
|
82
|
-
expect(response.user.id).toBeDefined();
|
|
83
|
-
expect(response.user.uid).toBeDefined();
|
|
84
|
-
expect(response.user.email_s).toBeDefined();
|
|
85
|
-
expect(response.user.handle_s).toBeDefined();
|
|
86
|
-
console.log('Token login successful with default URL');
|
|
87
|
-
console.log('Success:', response.success);
|
|
88
|
-
console.log('Message:', response.message);
|
|
89
|
-
console.log('User ID:', response.user.id);
|
|
90
|
-
console.log('User UID:', response.user.uid);
|
|
91
|
-
console.log('User handle:', response.user.handle_s);
|
|
92
|
-
console.log('User email:', response.user.email_s);
|
|
93
|
-
});
|
|
94
|
-
it('should fail when providing invalid token (expecting 401 status)', async () => {
|
|
95
|
-
console.log('Testing login with invalid token (expecting 401 Unauthorized)...');
|
|
96
|
-
const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpbnZhbGlkIiwiaWF0IjoxNTE2MjM5MDIyfQ.invalid_signature_here';
|
|
97
|
-
try {
|
|
98
|
-
const response = await authentication.login({
|
|
99
|
-
token: invalidToken,
|
|
100
|
-
}, BASE_URL);
|
|
101
|
-
console.log('Response for invalid token:', JSON.stringify(response, null, 2));
|
|
102
|
-
// If we get a response without error, check if it indicates failure
|
|
103
|
-
if (response.success === false) {
|
|
104
|
-
console.log('Login failed as expected (success: false)');
|
|
105
|
-
expect(response.success).toBe(false);
|
|
106
|
-
expect(response.message).toBeDefined();
|
|
107
|
-
expect(response.message.toLowerCase()).toContain('fail');
|
|
108
|
-
console.log(' Error message:', response.message);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// If success is true for invalid token, that's unexpected
|
|
112
|
-
throw new Error('Expected API to reject invalid token with 401');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
// The API should throw with 401 Unauthorized for invalid credentials
|
|
117
|
-
console.log('API correctly rejected invalid token with error:', error.message);
|
|
118
|
-
expect(error).toBeDefined();
|
|
119
|
-
expect(error.message).toBeDefined();
|
|
120
|
-
// Check for expected error patterns (401 or server error)
|
|
121
|
-
const isExpectedError = error.message.includes('401') ||
|
|
122
|
-
error.message.includes('Unauthorized') ||
|
|
123
|
-
error.message.includes('Invalid') ||
|
|
124
|
-
error.message.includes('Login failed') ||
|
|
125
|
-
error.message.includes('Server Error') ||
|
|
126
|
-
error.message.includes('500');
|
|
127
|
-
expect(isExpectedError).toBe(true);
|
|
128
|
-
// Log the actual status for debugging
|
|
129
|
-
if (error.response?.status === 401) {
|
|
130
|
-
console.log('Correctly received 401 Unauthorized status');
|
|
131
|
-
}
|
|
132
|
-
else if (error.response?.status === 500) {
|
|
133
|
-
console.log('Received 500 Server Error (token might have invalid format)');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
describe('proxyAuth', () => {
|
|
139
|
-
it('should successfully validate authentication with valid token', async () => {
|
|
140
|
-
console.log('Testing /proxy-auth endpoint with valid token...');
|
|
141
|
-
try {
|
|
142
|
-
await authentication.proxyAuth(SESSION_TOKEN, BASE_URL);
|
|
143
|
-
console.log('Successfully validated authentication through proxy');
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
console.log('Proxy auth validation result:', error.message);
|
|
147
|
-
// The endpoint might not exist yet or might require specific proxy setup
|
|
148
|
-
// We'll accept either success or specific error responses
|
|
149
|
-
expect(error.message.includes('404') || // Endpoint might not exist
|
|
150
|
-
error.message.includes('401') || // Unauthorized
|
|
151
|
-
error.message.includes('403') || // Forbidden
|
|
152
|
-
error.message.includes('proxy')).toBe(true);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
it('should fail with 401 when using invalid token', async () => {
|
|
156
|
-
console.log('Testing /proxy-auth endpoint with invalid token...');
|
|
157
|
-
const invalidToken = 'invalid.token.here';
|
|
158
|
-
try {
|
|
159
|
-
await authentication.proxyAuth(invalidToken, BASE_URL);
|
|
160
|
-
// If we reach here, the endpoint accepted invalid token (shouldn't happen)
|
|
161
|
-
throw new Error('Expected proxy auth to reject invalid token');
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
console.log('Proxy auth correctly rejected invalid token:', error.message);
|
|
165
|
-
expect(error).toBeDefined();
|
|
166
|
-
// Should get 401 Unauthorized or similar error
|
|
167
|
-
expect(error.message.includes('401') ||
|
|
168
|
-
error.message.includes('Unauthorized') ||
|
|
169
|
-
error.message.includes('Invalid') ||
|
|
170
|
-
error.message.includes('404')).toBe(true);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
it('should require token parameter', async () => {
|
|
174
|
-
console.log('Testing /proxy-auth endpoint without token...');
|
|
175
|
-
try {
|
|
176
|
-
// @ts-expect-error Testing missing required parameter
|
|
177
|
-
await authentication.proxyAuth();
|
|
178
|
-
throw new Error('Expected function to throw for missing token');
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
console.log('Correctly rejected request without token:', error.message);
|
|
182
|
-
expect(error.message).toBe('Authentication token is required');
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
describe('logout', () => {
|
|
187
|
-
// NOTE: The logout endpoint appears to return 405 Method Not Allowed
|
|
188
|
-
// This might indicate the endpoint doesn't exist or uses a different HTTP method
|
|
189
|
-
// Commenting out these tests until we can verify the correct API specification
|
|
190
|
-
it.skip('should successfully logout with valid token', async () => {
|
|
191
|
-
console.log('Testing logout with valid token...');
|
|
192
|
-
// First login to get a fresh token
|
|
193
|
-
const loginResponse = await authentication.login({
|
|
194
|
-
token: DATALAYER_TOKEN,
|
|
195
|
-
});
|
|
196
|
-
expect(loginResponse.success).toBe(true);
|
|
197
|
-
const sessionToken = loginResponse.token;
|
|
198
|
-
console.log('Login successful, got session token');
|
|
199
|
-
// Now test logout with the session token
|
|
200
|
-
await expect(authentication.logout(sessionToken, BASE_URL)).resolves.toBeUndefined();
|
|
201
|
-
console.log('Logout successful');
|
|
202
|
-
});
|
|
203
|
-
it.skip('should successfully logout using default URL', async () => {
|
|
204
|
-
console.log('Testing logout with valid token using default URL...');
|
|
205
|
-
// First login to get a fresh token
|
|
206
|
-
const loginResponse = await authentication.login({
|
|
207
|
-
token: DATALAYER_TOKEN,
|
|
208
|
-
});
|
|
209
|
-
expect(loginResponse.success).toBe(true);
|
|
210
|
-
const sessionToken = loginResponse.token;
|
|
211
|
-
console.log('Login successful with default URL, got session token');
|
|
212
|
-
// Now test logout with the session token using default URL
|
|
213
|
-
await expect(authentication.logout(sessionToken)).resolves.toBeUndefined();
|
|
214
|
-
console.log('Logout successful with default URL');
|
|
215
|
-
});
|
|
216
|
-
it('should handle logout with invalid token', async () => {
|
|
217
|
-
console.log('Testing logout with invalid token...');
|
|
218
|
-
const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpbnZhbGlkIiwiaWF0IjoxNTE2MjM5MDIyfQ.invalid_signature_here';
|
|
219
|
-
try {
|
|
220
|
-
await authentication.logout(invalidToken, BASE_URL);
|
|
221
|
-
console.log('Logout completed without error (unexpected)');
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
console.log('Logout failed:', error.message);
|
|
225
|
-
expect(error).toBeDefined();
|
|
226
|
-
expect(error.message).toBeDefined();
|
|
227
|
-
// Should get a server error for invalid token
|
|
228
|
-
expect(error.message).toContain('Server Error');
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
it('should verify logout accepts token as required parameter', () => {
|
|
232
|
-
// This is a compile-time test to ensure the method signature is correct
|
|
233
|
-
// The token parameter should be required
|
|
234
|
-
const mockToken = 'test-token';
|
|
235
|
-
// This should compile without errors
|
|
236
|
-
expect(() => {
|
|
237
|
-
// Test with token only (using default URL)
|
|
238
|
-
const promise1 = authentication.logout(mockToken);
|
|
239
|
-
promise1.catch(() => { }); // Ignore the actual API call
|
|
240
|
-
// Test with both token and URL
|
|
241
|
-
const promise2 = authentication.logout(mockToken, BASE_URL);
|
|
242
|
-
promise2.catch(() => { }); // Ignore the actual API call
|
|
243
|
-
}).not.toThrow();
|
|
244
|
-
console.log('Logout method signature verified: token is required, baseUrl is optional');
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
6
|
-
import { healthz } from '../iam';
|
|
7
|
-
import { testConfig, debugLog, skipIfNoToken, } from '../../__tests__/shared/test-config';
|
|
8
|
-
let BASE_URL;
|
|
9
|
-
// Skip all tests if no token is available
|
|
10
|
-
const skipTests = skipIfNoToken();
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
if (skipTests) {
|
|
13
|
-
console.log('WARNING: Skipping IAM healthz integration tests: No Datalayer API token configured');
|
|
14
|
-
console.log(' Set DATALAYER_API_TOKEN env var or DATALAYER_TEST_TOKEN in .env.test');
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
// Get base URL from test config
|
|
18
|
-
BASE_URL = testConfig.getBaseUrl('IAM');
|
|
19
|
-
debugLog('Test configuration loaded');
|
|
20
|
-
debugLog('Base URL:', BASE_URL);
|
|
21
|
-
});
|
|
22
|
-
describe.skipIf(skipTests)('IAM Healthz Integration Tests', () => {
|
|
23
|
-
describe('ping endpoint', () => {
|
|
24
|
-
it('should successfully ping the IAM service', async () => {
|
|
25
|
-
console.log('Testing health check ping endpoint...');
|
|
26
|
-
const response = await healthz.ping(BASE_URL);
|
|
27
|
-
console.log('Ping response:', JSON.stringify(response, null, 2));
|
|
28
|
-
// Verify the response structure matches actual API response
|
|
29
|
-
expect(response).toBeDefined();
|
|
30
|
-
expect(response.success).toBe(true);
|
|
31
|
-
expect(response.message).toBeDefined();
|
|
32
|
-
expect(response.message.toLowerCase()).toContain('running');
|
|
33
|
-
expect(response.status).toBeDefined();
|
|
34
|
-
expect(response.status.status).toBe('OK');
|
|
35
|
-
expect(response.version).toBeDefined();
|
|
36
|
-
expect(typeof response.version).toBe('string');
|
|
37
|
-
console.log('Health check successful');
|
|
38
|
-
console.log('Success:', response.success);
|
|
39
|
-
console.log('Message:', response.message);
|
|
40
|
-
console.log('Status:', response.status.status);
|
|
41
|
-
console.log('Version:', response.version);
|
|
42
|
-
});
|
|
43
|
-
it('should work with default URL if not specified', async () => {
|
|
44
|
-
console.log('Testing health check with default URL...');
|
|
45
|
-
// Call without specifying URL to use default
|
|
46
|
-
const response = await healthz.ping();
|
|
47
|
-
console.log('Default URL ping response:', JSON.stringify(response, null, 2));
|
|
48
|
-
// Should still get valid response
|
|
49
|
-
expect(response).toBeDefined();
|
|
50
|
-
expect(response.success).toBe(true);
|
|
51
|
-
expect(response.status).toBeDefined();
|
|
52
|
-
expect(response.status.status).toBe('OK');
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe('error handling', () => {
|
|
56
|
-
it('should handle malformed URLs gracefully', async () => {
|
|
57
|
-
console.log('Testing error handling with malformed URL...');
|
|
58
|
-
const malformedUrl = 'not-a-valid-url';
|
|
59
|
-
// ping should throw an error
|
|
60
|
-
await expect(healthz.ping(malformedUrl)).rejects.toThrow();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|