@databricks/sdk-settings 0.0.0-dev → 0.1.0-dev.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.
@@ -0,0 +1,444 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
5
+ import type {Logger} from '@databricks/sdk-core/logger';
6
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
7
+ import type {CallOptions} from '@databricks/sdk-options/call';
8
+ import type {ClientOptions} from '@databricks/sdk-options/client';
9
+ import type {HttpClient} from '@databricks/sdk-core/http';
10
+ import {newHttpClient} from './transport';
11
+ import {
12
+ buildHttpRequest,
13
+ executeCall,
14
+ executeHttpCall,
15
+ marshalRequest,
16
+ parseResponse,
17
+ } from './utils';
18
+ import pkgJson from '../../package.json' with {type: 'json'};
19
+ import type {
20
+ GetPublicAccountSettingRequest,
21
+ GetPublicAccountUserPreferenceRequest,
22
+ GetPublicWorkspaceSettingRequest,
23
+ ListAccountSettingsMetadataRequest,
24
+ ListAccountSettingsMetadataResponse,
25
+ ListAccountUserPreferencesMetadataRequest,
26
+ ListAccountUserPreferencesMetadataResponse,
27
+ ListWorkspaceSettingsMetadataRequest,
28
+ ListWorkspaceSettingsMetadataResponse,
29
+ PatchPublicAccountSettingRequest,
30
+ PatchPublicAccountUserPreferenceRequest,
31
+ PatchPublicWorkspaceSettingRequest,
32
+ Setting,
33
+ SettingsMetadata,
34
+ UserPreference,
35
+ } from './model';
36
+ import {
37
+ marshalSettingSchema,
38
+ marshalUserPreferenceSchema,
39
+ unmarshalListAccountSettingsMetadataResponseSchema,
40
+ unmarshalListAccountUserPreferencesMetadataResponseSchema,
41
+ unmarshalListWorkspaceSettingsMetadataResponseSchema,
42
+ unmarshalSettingSchema,
43
+ unmarshalUserPreferenceSchema,
44
+ } from './model';
45
+
46
+ // Package identity segment for this client to be used in the User-Agent header.
47
+ const PACKAGE_SEGMENT = {
48
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
49
+ value: pkgJson.version,
50
+ };
51
+
52
+ export class SettingsClient {
53
+ private readonly host: string;
54
+ // Fallback for endpoints whose path contains {account_id}. If the request
55
+ // already carries an accountId, that value wins.
56
+ private readonly accountId: string | undefined;
57
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
58
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
59
+ // request.
60
+ private readonly workspaceId: string | undefined;
61
+ private readonly httpClient: HttpClient;
62
+ private readonly logger: Logger;
63
+ // User-Agent header value. Composed once at construction from
64
+ // createDefault() merged with this package's identity and the active
65
+ // credential's name.
66
+ private readonly userAgent: string;
67
+
68
+ constructor(options: ClientOptions) {
69
+ if (options.host === undefined) {
70
+ throw new Error('Host is required.');
71
+ }
72
+ this.host = options.host.replace(/\/$/, '');
73
+ this.accountId = options.accountId;
74
+ this.workspaceId = options.workspaceId;
75
+ this.logger = options.logger ?? new NoOpLogger();
76
+ const info = createDefault()
77
+ .with(PACKAGE_SEGMENT)
78
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
79
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
80
+ this.userAgent = info.toString();
81
+ this.httpClient = newHttpClient(options);
82
+ }
83
+
84
+ /** Get a setting value at account level. See :method:settingsv2/listaccountsettingsmetadata for list of setting available via public APIs at account level. */
85
+ async getPublicAccountSetting(
86
+ req: GetPublicAccountSettingRequest,
87
+ options?: CallOptions
88
+ ): Promise<Setting> {
89
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/settings/${req.name ?? ''}`;
90
+ let resp: Setting | undefined;
91
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
92
+ const headers = new Headers();
93
+ headers.set('User-Agent', this.userAgent);
94
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
95
+ const respBody = await executeHttpCall({
96
+ request: httpReq,
97
+ httpClient: this.httpClient,
98
+ logger: this.logger,
99
+ });
100
+ resp = parseResponse(respBody, unmarshalSettingSchema);
101
+ };
102
+ await executeCall(call, options);
103
+ if (resp === undefined) {
104
+ throw new Error('operation completed without a result.');
105
+ }
106
+ return resp;
107
+ }
108
+
109
+ /**
110
+ * Get a user preference for a specific user.
111
+ * User preferences are personal settings that allow individual customization without affecting other users.
112
+ * See :method:settingsv2/listaccountuserpreferencesmetadata for list of user preferences available via public APIs.
113
+ */
114
+ async getPublicAccountUserPreference(
115
+ req: GetPublicAccountUserPreferenceRequest,
116
+ options?: CallOptions
117
+ ): Promise<UserPreference> {
118
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/users/${req.userId ?? ''}/settings/${req.name ?? ''}`;
119
+ let resp: UserPreference | undefined;
120
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
121
+ const headers = new Headers();
122
+ headers.set('User-Agent', this.userAgent);
123
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
124
+ const respBody = await executeHttpCall({
125
+ request: httpReq,
126
+ httpClient: this.httpClient,
127
+ logger: this.logger,
128
+ });
129
+ resp = parseResponse(respBody, unmarshalUserPreferenceSchema);
130
+ };
131
+ await executeCall(call, options);
132
+ if (resp === undefined) {
133
+ throw new Error('operation completed without a result.');
134
+ }
135
+ return resp;
136
+ }
137
+
138
+ /** Get a setting value at workspace level. See :method:settingsv2/listworkspacesettingsmetadata for list of setting available via public APIs. */
139
+ async getPublicWorkspaceSetting(
140
+ req: GetPublicWorkspaceSettingRequest,
141
+ options?: CallOptions
142
+ ): Promise<Setting> {
143
+ const url = `${this.host}/api/2.1/settings/${req.name ?? ''}`;
144
+ let resp: Setting | undefined;
145
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
146
+ const headers = new Headers();
147
+ if (this.workspaceId !== undefined) {
148
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
149
+ }
150
+ headers.set('User-Agent', this.userAgent);
151
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
152
+ const respBody = await executeHttpCall({
153
+ request: httpReq,
154
+ httpClient: this.httpClient,
155
+ logger: this.logger,
156
+ });
157
+ resp = parseResponse(respBody, unmarshalSettingSchema);
158
+ };
159
+ await executeCall(call, options);
160
+ if (resp === undefined) {
161
+ throw new Error('operation completed without a result.');
162
+ }
163
+ return resp;
164
+ }
165
+
166
+ /**
167
+ * List valid setting keys and metadata. These settings are available to be referenced via
168
+ * GET :method:settingsv2/getpublicaccountsetting and
169
+ * PATCH :method:settingsv2/patchpublicaccountsetting APIs
170
+ */
171
+ async listAccountSettingsMetadata(
172
+ req: ListAccountSettingsMetadataRequest,
173
+ options?: CallOptions
174
+ ): Promise<ListAccountSettingsMetadataResponse> {
175
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/settings-metadata`;
176
+ const params = new URLSearchParams();
177
+ if (req.pageSize !== undefined) {
178
+ params.append('page_size', String(req.pageSize));
179
+ }
180
+ if (req.pageToken !== undefined) {
181
+ params.append('page_token', req.pageToken);
182
+ }
183
+ const query = params.toString();
184
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
185
+ let resp: ListAccountSettingsMetadataResponse | undefined;
186
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
187
+ const headers = new Headers();
188
+ headers.set('User-Agent', this.userAgent);
189
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
190
+ const respBody = await executeHttpCall({
191
+ request: httpReq,
192
+ httpClient: this.httpClient,
193
+ logger: this.logger,
194
+ });
195
+ resp = parseResponse(
196
+ respBody,
197
+ unmarshalListAccountSettingsMetadataResponseSchema
198
+ );
199
+ };
200
+ await executeCall(call, options);
201
+ if (resp === undefined) {
202
+ throw new Error('operation completed without a result.');
203
+ }
204
+ return resp;
205
+ }
206
+
207
+ async *listAccountSettingsMetadataIter(
208
+ req: ListAccountSettingsMetadataRequest,
209
+ options?: CallOptions
210
+ ): AsyncGenerator<SettingsMetadata> {
211
+ const pageReq: ListAccountSettingsMetadataRequest = {...req};
212
+ for (;;) {
213
+ const resp = await this.listAccountSettingsMetadata(pageReq, options);
214
+ for (const item of resp.settingsMetadata ?? []) {
215
+ yield item;
216
+ }
217
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
218
+ return;
219
+ }
220
+ pageReq.pageToken = resp.nextPageToken;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * List valid user preferences and their metadata for a specific user.
226
+ * User preferences are personal settings that allow individual customization without affecting other users.
227
+ * These settings are available to be referenced via
228
+ * GET :method:settingsv2/getpublicaccountuserpreference and
229
+ * PATCH :method:settingsv2/patchpublicaccountuserpreference APIs
230
+ */
231
+ async listAccountUserPreferencesMetadata(
232
+ req: ListAccountUserPreferencesMetadataRequest,
233
+ options?: CallOptions
234
+ ): Promise<ListAccountUserPreferencesMetadataResponse> {
235
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/users/${req.userId ?? ''}/settings-metadata`;
236
+ const params = new URLSearchParams();
237
+ if (req.pageSize !== undefined) {
238
+ params.append('page_size', String(req.pageSize));
239
+ }
240
+ if (req.pageToken !== undefined) {
241
+ params.append('page_token', req.pageToken);
242
+ }
243
+ const query = params.toString();
244
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
245
+ let resp: ListAccountUserPreferencesMetadataResponse | undefined;
246
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
247
+ const headers = new Headers();
248
+ headers.set('User-Agent', this.userAgent);
249
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
250
+ const respBody = await executeHttpCall({
251
+ request: httpReq,
252
+ httpClient: this.httpClient,
253
+ logger: this.logger,
254
+ });
255
+ resp = parseResponse(
256
+ respBody,
257
+ unmarshalListAccountUserPreferencesMetadataResponseSchema
258
+ );
259
+ };
260
+ await executeCall(call, options);
261
+ if (resp === undefined) {
262
+ throw new Error('operation completed without a result.');
263
+ }
264
+ return resp;
265
+ }
266
+
267
+ async *listAccountUserPreferencesMetadataIter(
268
+ req: ListAccountUserPreferencesMetadataRequest,
269
+ options?: CallOptions
270
+ ): AsyncGenerator<SettingsMetadata> {
271
+ const pageReq: ListAccountUserPreferencesMetadataRequest = {...req};
272
+ for (;;) {
273
+ const resp = await this.listAccountUserPreferencesMetadata(
274
+ pageReq,
275
+ options
276
+ );
277
+ for (const item of resp.settingsMetadata ?? []) {
278
+ yield item;
279
+ }
280
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
281
+ return;
282
+ }
283
+ pageReq.pageToken = resp.nextPageToken;
284
+ }
285
+ }
286
+
287
+ /**
288
+ * List valid setting keys and metadata. These settings are available to be referenced via
289
+ * GET :method:settingsv2/getpublicworkspacesetting and
290
+ * PATCH :method:settingsv2/patchpublicworkspacesetting APIs
291
+ */
292
+ async listWorkspaceSettingsMetadata(
293
+ req: ListWorkspaceSettingsMetadataRequest,
294
+ options?: CallOptions
295
+ ): Promise<ListWorkspaceSettingsMetadataResponse> {
296
+ const url = `${this.host}/api/2.1/settings-metadata`;
297
+ const params = new URLSearchParams();
298
+ if (req.pageSize !== undefined) {
299
+ params.append('page_size', String(req.pageSize));
300
+ }
301
+ if (req.pageToken !== undefined) {
302
+ params.append('page_token', req.pageToken);
303
+ }
304
+ const query = params.toString();
305
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
306
+ let resp: ListWorkspaceSettingsMetadataResponse | undefined;
307
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
308
+ const headers = new Headers();
309
+ if (this.workspaceId !== undefined) {
310
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
311
+ }
312
+ headers.set('User-Agent', this.userAgent);
313
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
314
+ const respBody = await executeHttpCall({
315
+ request: httpReq,
316
+ httpClient: this.httpClient,
317
+ logger: this.logger,
318
+ });
319
+ resp = parseResponse(
320
+ respBody,
321
+ unmarshalListWorkspaceSettingsMetadataResponseSchema
322
+ );
323
+ };
324
+ await executeCall(call, options);
325
+ if (resp === undefined) {
326
+ throw new Error('operation completed without a result.');
327
+ }
328
+ return resp;
329
+ }
330
+
331
+ async *listWorkspaceSettingsMetadataIter(
332
+ req: ListWorkspaceSettingsMetadataRequest,
333
+ options?: CallOptions
334
+ ): AsyncGenerator<SettingsMetadata> {
335
+ const pageReq: ListWorkspaceSettingsMetadataRequest = {...req};
336
+ for (;;) {
337
+ const resp = await this.listWorkspaceSettingsMetadata(pageReq, options);
338
+ for (const item of resp.settingsMetadata ?? []) {
339
+ yield item;
340
+ }
341
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
342
+ return;
343
+ }
344
+ pageReq.pageToken = resp.nextPageToken;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Patch a setting value at account level. See :method:settingsv2/listaccountsettingsmetadata for list of setting available via public APIs at account level.
350
+ * To determine the correct field to include in a patch request, refer to the type field of the setting returned in the :method:settingsv2/listaccountsettingsmetadata response.
351
+ *
352
+ * Note: Page refresh is required for changes to take effect in UI.
353
+ */
354
+ async patchPublicAccountSetting(
355
+ req: PatchPublicAccountSettingRequest,
356
+ options?: CallOptions
357
+ ): Promise<Setting> {
358
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/settings/${req.name ?? ''}`;
359
+ const body = marshalRequest(req.setting, marshalSettingSchema);
360
+ let resp: Setting | undefined;
361
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
362
+ const headers = new Headers({'Content-Type': 'application/json'});
363
+ headers.set('User-Agent', this.userAgent);
364
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
365
+ const respBody = await executeHttpCall({
366
+ request: httpReq,
367
+ httpClient: this.httpClient,
368
+ logger: this.logger,
369
+ });
370
+ resp = parseResponse(respBody, unmarshalSettingSchema);
371
+ };
372
+ await executeCall(call, options);
373
+ if (resp === undefined) {
374
+ throw new Error('operation completed without a result.');
375
+ }
376
+ return resp;
377
+ }
378
+
379
+ /**
380
+ * Update a user preference for a specific user.
381
+ * User preferences are personal settings that allow individual customization without affecting other users.
382
+ * See :method:settingsv2/listaccountuserpreferencesmetadata for list of user preferences available via public APIs.
383
+ *
384
+ * Note: Page refresh is required for changes to take effect in UI.
385
+ */
386
+ async patchPublicAccountUserPreference(
387
+ req: PatchPublicAccountUserPreferenceRequest,
388
+ options?: CallOptions
389
+ ): Promise<UserPreference> {
390
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/users/${req.userId ?? ''}/settings/${req.name ?? ''}`;
391
+ const body = marshalRequest(req.setting, marshalUserPreferenceSchema);
392
+ let resp: UserPreference | undefined;
393
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
394
+ const headers = new Headers({'Content-Type': 'application/json'});
395
+ headers.set('User-Agent', this.userAgent);
396
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
397
+ const respBody = await executeHttpCall({
398
+ request: httpReq,
399
+ httpClient: this.httpClient,
400
+ logger: this.logger,
401
+ });
402
+ resp = parseResponse(respBody, unmarshalUserPreferenceSchema);
403
+ };
404
+ await executeCall(call, options);
405
+ if (resp === undefined) {
406
+ throw new Error('operation completed without a result.');
407
+ }
408
+ return resp;
409
+ }
410
+
411
+ /**
412
+ * Patch a setting value at workspace level. See :method:settingsv2/listworkspacesettingsmetadata for list of setting available via public APIs at workspace level.
413
+ * To determine the correct field to include in a patch request, refer to the type field of the setting returned in the :method:settingsv2/listworkspacesettingsmetadata response.
414
+ *
415
+ * Note: Page refresh is required for changes to take effect in UI.
416
+ */
417
+ async patchPublicWorkspaceSetting(
418
+ req: PatchPublicWorkspaceSettingRequest,
419
+ options?: CallOptions
420
+ ): Promise<Setting> {
421
+ const url = `${this.host}/api/2.1/settings/${req.name ?? ''}`;
422
+ const body = marshalRequest(req.setting, marshalSettingSchema);
423
+ let resp: Setting | undefined;
424
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
425
+ const headers = new Headers({'Content-Type': 'application/json'});
426
+ if (this.workspaceId !== undefined) {
427
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
428
+ }
429
+ headers.set('User-Agent', this.userAgent);
430
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
431
+ const respBody = await executeHttpCall({
432
+ request: httpReq,
433
+ httpClient: this.httpClient,
434
+ logger: this.logger,
435
+ });
436
+ resp = parseResponse(respBody, unmarshalSettingSchema);
437
+ };
438
+ await executeCall(call, options);
439
+ if (resp === undefined) {
440
+ throw new Error('operation completed without a result.');
441
+ }
442
+ return resp;
443
+ }
444
+ }
@@ -0,0 +1,44 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ export {SettingsClient} from './client';
4
+
5
+ export {
6
+ PreviewPhase,
7
+ AibiDashboardEmbeddingAccessPolicy_AccessPolicyType,
8
+ ClusterAutoRestartMessage_MaintenanceWindow_DayOfWeek,
9
+ ClusterAutoRestartMessage_MaintenanceWindow_WeekDayFrequency,
10
+ PersonalComputeMessage_PersonalComputeMessageEnum,
11
+ RestrictWorkspaceAdminsMessage_Status,
12
+ } from './model';
13
+
14
+ export type {
15
+ AibiDashboardEmbeddingAccessPolicy,
16
+ AibiDashboardEmbeddingApprovedDomains,
17
+ AllowedAppsUserApiScopesMessage,
18
+ BooleanMessage,
19
+ ClusterAutoRestartMessage,
20
+ ClusterAutoRestartMessage_EnablementDetails,
21
+ ClusterAutoRestartMessage_MaintenanceWindow,
22
+ ClusterAutoRestartMessage_MaintenanceWindow_WeekDayBasedSchedule,
23
+ ClusterAutoRestartMessage_MaintenanceWindow_WindowStartTime,
24
+ GetPublicAccountSettingRequest,
25
+ GetPublicAccountUserPreferenceRequest,
26
+ GetPublicWorkspaceSettingRequest,
27
+ IntegerMessage,
28
+ ListAccountSettingsMetadataRequest,
29
+ ListAccountSettingsMetadataResponse,
30
+ ListAccountUserPreferencesMetadataRequest,
31
+ ListAccountUserPreferencesMetadataResponse,
32
+ ListWorkspaceSettingsMetadataRequest,
33
+ ListWorkspaceSettingsMetadataResponse,
34
+ OperationalEmailCustomRecipientMessage,
35
+ PatchPublicAccountSettingRequest,
36
+ PatchPublicAccountUserPreferenceRequest,
37
+ PatchPublicWorkspaceSettingRequest,
38
+ PersonalComputeMessage,
39
+ RestrictWorkspaceAdminsMessage,
40
+ Setting,
41
+ SettingsMetadata,
42
+ StringMessage,
43
+ UserPreference,
44
+ } from './model';