@datalayer/core 0.0.20 → 0.0.23
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/lib/api/iam/datasources.d.ts +86 -0
- package/lib/api/iam/datasources.js +185 -0
- package/lib/api/iam/index.d.ts +2 -0
- package/lib/api/iam/index.js +2 -0
- package/lib/api/iam/secrets.d.ts +85 -0
- package/lib/api/iam/secrets.js +196 -0
- package/lib/client/auth/storage.js +17 -62
- package/lib/client/base.d.ts +3 -0
- package/lib/client/base.js +2 -2
- package/lib/client/index.d.ts +82 -3
- package/lib/client/index.js +5 -1
- package/lib/client/mixins/IAMMixin.d.ts +62 -0
- package/lib/client/mixins/IAMMixin.js +116 -0
- package/lib/collaboration/DatalayerCollaboration.d.ts +1 -2
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +1 -1
- package/lib/collaboration/DatalayerCollaborationProvider.js +1 -1
- package/lib/hooks/useBackdrop.d.ts +2 -3
- package/lib/hooks/useBackdropJupyterLab.d.ts +2 -2
- package/lib/hooks/useCache.d.ts +3 -3
- package/lib/hooks/useScreenshot.d.ts +2 -3
- package/lib/hooks/useWindowSize.d.ts +1 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -1
- package/lib/models/Datasource.d.ts +170 -0
- package/lib/models/Datasource.js +140 -0
- package/lib/models/Runtime.d.ts +1 -1
- package/lib/models/RuntimeSnapshotDTO.d.ts +1 -1
- package/lib/models/RuntimeSnapshotDTO.js +1 -1
- package/lib/models/Secret.d.ts +159 -0
- package/lib/models/Secret.js +135 -0
- package/lib/models/SpaceDTO.d.ts +0 -11
- package/lib/state/substates/IAMState.d.ts +1 -1
- package/lib/state/substates/LayoutState.d.ts +2 -2
- package/lib/state/substates/NbformatState.d.ts +1 -1
- package/lib/utils/File.d.ts +1 -1
- package/lib/utils/File.js +1 -1
- package/lib/utils/Notebook.d.ts +5 -3
- package/lib/utils/Notebook.js +5 -3
- package/package.json +9 -8
- package/patches/.gitkeep +1 -0
- package/scripts/apply-patches.sh +44 -0
- package/scripts/create-patches.sh +40 -0
- package/scripts/fix-esm-imports.cjs +124 -0
- package/scripts/sync-jupyter.sh +121 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CreateDatasourceRequest, CreateDatasourceResponse, GetDatasourceResponse, ListDatasourcesResponse, UpdateDatasourceRequest, UpdateDatasourceResponse } from '../../models/Datasource';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new datasource.
|
|
4
|
+
* Creates a new datasource configuration for the authenticated user.
|
|
5
|
+
*
|
|
6
|
+
* @param token - Authentication token
|
|
7
|
+
* @param data - Datasource creation data
|
|
8
|
+
* @param baseUrl - Base URL for IAM service
|
|
9
|
+
* @returns Created datasource data
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const response = await createDatasource(token, {
|
|
14
|
+
* type: 'Amazon Athena',
|
|
15
|
+
* name: 'my-athena-datasource',
|
|
16
|
+
* description: 'Production Athena datasource',
|
|
17
|
+
* database: 'my_database',
|
|
18
|
+
* output_bucket: 's3://my-bucket/output/'
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const createDatasource: (token: string, data: CreateDatasourceRequest, baseUrl?: string) => Promise<CreateDatasourceResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* List all datasources for authenticated user.
|
|
25
|
+
* Retrieves all datasource configurations accessible to the user.
|
|
26
|
+
*
|
|
27
|
+
* @param token - Authentication token
|
|
28
|
+
* @param baseUrl - Base URL for IAM service
|
|
29
|
+
* @returns List of datasources
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const response = await listDatasources(token);
|
|
34
|
+
* console.log(response.datasources);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const listDatasources: (token: string, baseUrl?: string) => Promise<ListDatasourcesResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Get a specific datasource by ID.
|
|
40
|
+
* Retrieves detailed information about a specific datasource.
|
|
41
|
+
*
|
|
42
|
+
* @param token - Authentication token
|
|
43
|
+
* @param datasourceId - Datasource unique identifier
|
|
44
|
+
* @param baseUrl - Base URL for IAM service
|
|
45
|
+
* @returns Datasource data
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const response = await getDatasource(token, 'datasource-id-123');
|
|
50
|
+
* console.log(response.datasource);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const getDatasource: (token: string, datasourceId: string, baseUrl?: string) => Promise<GetDatasourceResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* Update a specific datasource.
|
|
56
|
+
* Updates the configuration of an existing datasource.
|
|
57
|
+
*
|
|
58
|
+
* @param token - Authentication token
|
|
59
|
+
* @param datasourceId - Datasource unique identifier
|
|
60
|
+
* @param data - Update data
|
|
61
|
+
* @param baseUrl - Base URL for IAM service
|
|
62
|
+
* @returns Updated datasource data
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const response = await updateDatasource(token, 'datasource-id-123', {
|
|
67
|
+
* description: 'Updated description',
|
|
68
|
+
* database: 'new_database'
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const updateDatasource: (token: string, datasourceId: string, data: UpdateDatasourceRequest, baseUrl?: string) => Promise<UpdateDatasourceResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Delete a specific datasource.
|
|
75
|
+
* Removes a datasource configuration.
|
|
76
|
+
*
|
|
77
|
+
* @param token - Authentication token
|
|
78
|
+
* @param datasourceId - Datasource unique identifier
|
|
79
|
+
* @param baseUrl - Base URL for IAM service
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* await deleteDatasource(token, 'datasource-id-123');
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare const deleteDatasource: (token: string, datasourceId: string, baseUrl?: string) => Promise<void>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Datasources API functions.
|
|
7
|
+
* @module api/iam/datasources
|
|
8
|
+
*/
|
|
9
|
+
import { requestDatalayerAPI } from '../DatalayerApi';
|
|
10
|
+
import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
|
|
11
|
+
import { validateToken, validateRequiredString } from '../utils/validation';
|
|
12
|
+
/**
|
|
13
|
+
* Create a new datasource.
|
|
14
|
+
* Creates a new datasource configuration for the authenticated user.
|
|
15
|
+
*
|
|
16
|
+
* @param token - Authentication token
|
|
17
|
+
* @param data - Datasource creation data
|
|
18
|
+
* @param baseUrl - Base URL for IAM service
|
|
19
|
+
* @returns Created datasource data
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const response = await createDatasource(token, {
|
|
24
|
+
* type: 'Amazon Athena',
|
|
25
|
+
* name: 'my-athena-datasource',
|
|
26
|
+
* description: 'Production Athena datasource',
|
|
27
|
+
* database: 'my_database',
|
|
28
|
+
* output_bucket: 's3://my-bucket/output/'
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const createDatasource = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
33
|
+
validateToken(token);
|
|
34
|
+
validateRequiredString(data.name, 'Datasource name');
|
|
35
|
+
validateRequiredString(data.type, 'Datasource type');
|
|
36
|
+
// Map datasource type to API variant format
|
|
37
|
+
const variantMap = {
|
|
38
|
+
'Amazon Athena': 'athena',
|
|
39
|
+
'Google BigQuery': 'bigquery',
|
|
40
|
+
'Microsoft Sentinel': 'sentinel',
|
|
41
|
+
Splunk: 'splunk',
|
|
42
|
+
};
|
|
43
|
+
const requestBody = {
|
|
44
|
+
name: data.name,
|
|
45
|
+
variant: variantMap[data.type] || data.type.toLowerCase(),
|
|
46
|
+
description: data.description || '',
|
|
47
|
+
database: data.database || '',
|
|
48
|
+
outputBucket: data.output_bucket || '',
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
return await requestDatalayerAPI({
|
|
52
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/datasources`,
|
|
53
|
+
method: 'POST',
|
|
54
|
+
body: requestBody,
|
|
55
|
+
token,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error.response?.status === 409) {
|
|
60
|
+
throw new Error(`Datasource with name '${data.name}' already exists. Please use a different name.`);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* List all datasources for authenticated user.
|
|
67
|
+
* Retrieves all datasource configurations accessible to the user.
|
|
68
|
+
*
|
|
69
|
+
* @param token - Authentication token
|
|
70
|
+
* @param baseUrl - Base URL for IAM service
|
|
71
|
+
* @returns List of datasources
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const response = await listDatasources(token);
|
|
76
|
+
* console.log(response.datasources);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export const listDatasources = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
80
|
+
validateToken(token);
|
|
81
|
+
return await requestDatalayerAPI({
|
|
82
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/datasources`,
|
|
83
|
+
method: 'GET',
|
|
84
|
+
token,
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Get a specific datasource by ID.
|
|
89
|
+
* Retrieves detailed information about a specific datasource.
|
|
90
|
+
*
|
|
91
|
+
* @param token - Authentication token
|
|
92
|
+
* @param datasourceId - Datasource unique identifier
|
|
93
|
+
* @param baseUrl - Base URL for IAM service
|
|
94
|
+
* @returns Datasource data
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const response = await getDatasource(token, 'datasource-id-123');
|
|
99
|
+
* console.log(response.datasource);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export const getDatasource = async (token, datasourceId, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
103
|
+
validateToken(token);
|
|
104
|
+
validateRequiredString(datasourceId, 'Datasource ID');
|
|
105
|
+
try {
|
|
106
|
+
return await requestDatalayerAPI({
|
|
107
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/datasources/${datasourceId}`,
|
|
108
|
+
method: 'GET',
|
|
109
|
+
token,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error.response?.status === 404) {
|
|
114
|
+
throw new Error(`Datasource '${datasourceId}' not found.`);
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Update a specific datasource.
|
|
121
|
+
* Updates the configuration of an existing datasource.
|
|
122
|
+
*
|
|
123
|
+
* @param token - Authentication token
|
|
124
|
+
* @param datasourceId - Datasource unique identifier
|
|
125
|
+
* @param data - Update data
|
|
126
|
+
* @param baseUrl - Base URL for IAM service
|
|
127
|
+
* @returns Updated datasource data
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const response = await updateDatasource(token, 'datasource-id-123', {
|
|
132
|
+
* description: 'Updated description',
|
|
133
|
+
* database: 'new_database'
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export const updateDatasource = async (token, datasourceId, data, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
138
|
+
validateToken(token);
|
|
139
|
+
validateRequiredString(datasourceId, 'Datasource ID');
|
|
140
|
+
const requestBody = { ...data };
|
|
141
|
+
try {
|
|
142
|
+
return await requestDatalayerAPI({
|
|
143
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/datasources/${datasourceId}`,
|
|
144
|
+
method: 'PUT',
|
|
145
|
+
body: requestBody,
|
|
146
|
+
token,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error.response?.status === 404) {
|
|
151
|
+
throw new Error(`Datasource '${datasourceId}' not found.`);
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Delete a specific datasource.
|
|
158
|
+
* Removes a datasource configuration.
|
|
159
|
+
*
|
|
160
|
+
* @param token - Authentication token
|
|
161
|
+
* @param datasourceId - Datasource unique identifier
|
|
162
|
+
* @param baseUrl - Base URL for IAM service
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* await deleteDatasource(token, 'datasource-id-123');
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export const deleteDatasource = async (token, datasourceId, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
170
|
+
validateToken(token);
|
|
171
|
+
validateRequiredString(datasourceId, 'Datasource ID');
|
|
172
|
+
try {
|
|
173
|
+
await requestDatalayerAPI({
|
|
174
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/datasources/${datasourceId}`,
|
|
175
|
+
method: 'DELETE',
|
|
176
|
+
token,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error.response?.status === 404) {
|
|
181
|
+
throw new Error(`Datasource '${datasourceId}' not found.`);
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
};
|
package/lib/api/iam/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export * as oauth2 from './oauth2';
|
|
|
10
10
|
export * as profile from './profile';
|
|
11
11
|
export * as healthz from './healthz';
|
|
12
12
|
export * as usage from './usage';
|
|
13
|
+
export * as secrets from './secrets';
|
|
14
|
+
export * as datasources from './datasources';
|
|
13
15
|
export { login, logout, checkAuth } from './authentication';
|
|
14
16
|
export { getOAuth2AuthzUrl, getOAuth2AuthzUrlForLink, handleGitHubOAuth2Callback, handleLinkedInOAuth2Callback, handleOktaOAuth2Callback, type OAuth2Provider, type OAuth2AuthzUrlResponse, type OAuth2CallbackParams, type OAuth2CallbackResponse, } from './oauth2';
|
|
15
17
|
export { me, whoami } from './profile';
|
package/lib/api/iam/index.js
CHANGED
|
@@ -14,6 +14,8 @@ export * as oauth2 from './oauth2';
|
|
|
14
14
|
export * as profile from './profile';
|
|
15
15
|
export * as healthz from './healthz';
|
|
16
16
|
export * as usage from './usage';
|
|
17
|
+
export * as secrets from './secrets';
|
|
18
|
+
export * as datasources from './datasources';
|
|
17
19
|
// For backward compatibility, export the old API structure
|
|
18
20
|
export { login, logout, checkAuth } from './authentication';
|
|
19
21
|
export { getOAuth2AuthzUrl, getOAuth2AuthzUrlForLink, handleGitHubOAuth2Callback, handleLinkedInOAuth2Callback, handleOktaOAuth2Callback, } from './oauth2';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { CreateSecretRequest, CreateSecretResponse, GetSecretResponse, ListSecretsResponse, UpdateSecretRequest, UpdateSecretResponse } from '../../models/Secret';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new secret.
|
|
4
|
+
* Creates a new encrypted secret for the authenticated user.
|
|
5
|
+
*
|
|
6
|
+
* @param token - Authentication token
|
|
7
|
+
* @param data - Secret creation data
|
|
8
|
+
* @param baseUrl - Base URL for IAM service
|
|
9
|
+
* @returns Created secret data
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const response = await createSecret(token, {
|
|
14
|
+
* variant: 'password',
|
|
15
|
+
* name: 'db_password',
|
|
16
|
+
* description: 'Production database password',
|
|
17
|
+
* value: 'my-secure-password'
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const createSecret: (token: string, data: CreateSecretRequest, baseUrl?: string) => Promise<CreateSecretResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* List all secrets for authenticated user.
|
|
24
|
+
* Retrieves all secret configurations accessible to the user.
|
|
25
|
+
*
|
|
26
|
+
* @param token - Authentication token
|
|
27
|
+
* @param baseUrl - Base URL for IAM service
|
|
28
|
+
* @returns List of secrets
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const response = await listSecrets(token);
|
|
33
|
+
* console.log(response.secrets);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const listSecrets: (token: string, baseUrl?: string) => Promise<ListSecretsResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a specific secret by ID.
|
|
39
|
+
* Retrieves detailed information about a specific secret.
|
|
40
|
+
*
|
|
41
|
+
* @param token - Authentication token
|
|
42
|
+
* @param secretId - Secret unique identifier
|
|
43
|
+
* @param baseUrl - Base URL for IAM service
|
|
44
|
+
* @returns Secret data
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const response = await getSecret(token, 'secret-id-123');
|
|
49
|
+
* console.log(response.secret);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const getSecret: (token: string, secretId: string, baseUrl?: string) => Promise<GetSecretResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Update a specific secret.
|
|
55
|
+
* Updates the configuration of an existing secret.
|
|
56
|
+
*
|
|
57
|
+
* @param token - Authentication token
|
|
58
|
+
* @param secretId - Secret unique identifier
|
|
59
|
+
* @param data - Update data
|
|
60
|
+
* @param baseUrl - Base URL for IAM service
|
|
61
|
+
* @returns Updated secret data
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const response = await updateSecret(token, 'secret-id-123', {
|
|
66
|
+
* description: 'Updated description',
|
|
67
|
+
* value: 'new-password'
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare const updateSecret: (token: string, secretId: string, data: UpdateSecretRequest, baseUrl?: string) => Promise<UpdateSecretResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Delete a specific secret.
|
|
74
|
+
* Removes a secret configuration and its encrypted data.
|
|
75
|
+
*
|
|
76
|
+
* @param token - Authentication token
|
|
77
|
+
* @param secretId - Secret unique identifier
|
|
78
|
+
* @param baseUrl - Base URL for IAM service
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* await deleteSecret(token, 'secret-id-123');
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare const deleteSecret: (token: string, secretId: string, baseUrl?: string) => Promise<void>;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Secrets API functions.
|
|
7
|
+
* @module api/secrets/secrets
|
|
8
|
+
*/
|
|
9
|
+
import { requestDatalayerAPI } from '../DatalayerApi';
|
|
10
|
+
import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
|
|
11
|
+
import { validateToken, validateRequiredString } from '../utils/validation';
|
|
12
|
+
/**
|
|
13
|
+
* Helper function to Base64 encode a value (cross-platform).
|
|
14
|
+
* @param value - Plain text value to encode
|
|
15
|
+
* @returns Base64 encoded string
|
|
16
|
+
*/
|
|
17
|
+
function encodeValue(value) {
|
|
18
|
+
if (typeof Buffer !== 'undefined') {
|
|
19
|
+
// Node.js environment
|
|
20
|
+
return Buffer.from(value).toString('base64');
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Browser environment
|
|
24
|
+
return btoa(value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a new secret.
|
|
29
|
+
* Creates a new encrypted secret for the authenticated user.
|
|
30
|
+
*
|
|
31
|
+
* @param token - Authentication token
|
|
32
|
+
* @param data - Secret creation data
|
|
33
|
+
* @param baseUrl - Base URL for IAM service
|
|
34
|
+
* @returns Created secret data
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const response = await createSecret(token, {
|
|
39
|
+
* variant: 'password',
|
|
40
|
+
* name: 'db_password',
|
|
41
|
+
* description: 'Production database password',
|
|
42
|
+
* value: 'my-secure-password'
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export const createSecret = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
47
|
+
validateToken(token);
|
|
48
|
+
validateRequiredString(data.name, 'Secret name');
|
|
49
|
+
validateRequiredString(data.value, 'Secret value');
|
|
50
|
+
// Base64 encode the value before sending to API
|
|
51
|
+
const requestBody = {
|
|
52
|
+
variant: data.variant || 'generic',
|
|
53
|
+
name: data.name,
|
|
54
|
+
description: data.description || '',
|
|
55
|
+
value: encodeValue(data.value),
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
return await requestDatalayerAPI({
|
|
59
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/secrets`,
|
|
60
|
+
method: 'POST',
|
|
61
|
+
body: requestBody,
|
|
62
|
+
token,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error.response?.status === 409) {
|
|
67
|
+
throw new Error(`Secret with name '${data.name}' already exists. Please use a different name.`);
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* List all secrets for authenticated user.
|
|
74
|
+
* Retrieves all secret configurations accessible to the user.
|
|
75
|
+
*
|
|
76
|
+
* @param token - Authentication token
|
|
77
|
+
* @param baseUrl - Base URL for IAM service
|
|
78
|
+
* @returns List of secrets
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const response = await listSecrets(token);
|
|
83
|
+
* console.log(response.secrets);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export const listSecrets = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
87
|
+
validateToken(token);
|
|
88
|
+
return await requestDatalayerAPI({
|
|
89
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/secrets`,
|
|
90
|
+
method: 'GET',
|
|
91
|
+
token,
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Get a specific secret by ID.
|
|
96
|
+
* Retrieves detailed information about a specific secret.
|
|
97
|
+
*
|
|
98
|
+
* @param token - Authentication token
|
|
99
|
+
* @param secretId - Secret unique identifier
|
|
100
|
+
* @param baseUrl - Base URL for IAM service
|
|
101
|
+
* @returns Secret data
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const response = await getSecret(token, 'secret-id-123');
|
|
106
|
+
* console.log(response.secret);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const getSecret = async (token, secretId, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
110
|
+
validateToken(token);
|
|
111
|
+
validateRequiredString(secretId, 'Secret ID');
|
|
112
|
+
try {
|
|
113
|
+
return await requestDatalayerAPI({
|
|
114
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/secrets/${secretId}`,
|
|
115
|
+
method: 'GET',
|
|
116
|
+
token,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error.response?.status === 404) {
|
|
121
|
+
throw new Error(`Secret '${secretId}' not found.`);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Update a specific secret.
|
|
128
|
+
* Updates the configuration of an existing secret.
|
|
129
|
+
*
|
|
130
|
+
* @param token - Authentication token
|
|
131
|
+
* @param secretId - Secret unique identifier
|
|
132
|
+
* @param data - Update data
|
|
133
|
+
* @param baseUrl - Base URL for IAM service
|
|
134
|
+
* @returns Updated secret data
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const response = await updateSecret(token, 'secret-id-123', {
|
|
139
|
+
* description: 'Updated description',
|
|
140
|
+
* value: 'new-password'
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export const updateSecret = async (token, secretId, data, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
145
|
+
validateToken(token);
|
|
146
|
+
validateRequiredString(secretId, 'Secret ID');
|
|
147
|
+
// Base64 encode value if provided
|
|
148
|
+
const requestBody = { ...data };
|
|
149
|
+
if (data.value) {
|
|
150
|
+
requestBody.value = encodeValue(data.value);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
return await requestDatalayerAPI({
|
|
154
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/secrets/${secretId}`,
|
|
155
|
+
method: 'PUT',
|
|
156
|
+
body: requestBody,
|
|
157
|
+
token,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error.response?.status === 404) {
|
|
162
|
+
throw new Error(`Secret '${secretId}' not found.`);
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Delete a specific secret.
|
|
169
|
+
* Removes a secret configuration and its encrypted data.
|
|
170
|
+
*
|
|
171
|
+
* @param token - Authentication token
|
|
172
|
+
* @param secretId - Secret unique identifier
|
|
173
|
+
* @param baseUrl - Base URL for IAM service
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* await deleteSecret(token, 'secret-id-123');
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export const deleteSecret = async (token, secretId, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
|
|
181
|
+
validateToken(token);
|
|
182
|
+
validateRequiredString(secretId, 'Secret ID');
|
|
183
|
+
try {
|
|
184
|
+
await requestDatalayerAPI({
|
|
185
|
+
url: `${baseUrl}${API_BASE_PATHS.IAM}/secrets/${secretId}`,
|
|
186
|
+
method: 'DELETE',
|
|
187
|
+
token,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error.response?.status === 404) {
|
|
192
|
+
throw new Error(`Secret '${secretId}' not found.`);
|
|
193
|
+
}
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
};
|