@databricks/sdk-budgets 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,260 @@
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
+ BudgetConfiguration,
21
+ CreateBudgetConfigurationRequest,
22
+ CreateBudgetConfigurationRequest_Response,
23
+ DeleteBudgetConfigurationRequest,
24
+ DeleteBudgetConfigurationRequest_Response,
25
+ GetBudgetConfigurationRequest,
26
+ GetBudgetConfigurationRequest_Response,
27
+ ListBudgetConfigurationsRequest,
28
+ ListBudgetConfigurationsRequest_Response,
29
+ UpdateBudgetConfigurationRequest,
30
+ UpdateBudgetConfigurationRequest_Response,
31
+ } from './model';
32
+ import {
33
+ marshalCreateBudgetConfigurationRequestSchema,
34
+ marshalUpdateBudgetConfigurationRequestSchema,
35
+ unmarshalCreateBudgetConfigurationRequest_ResponseSchema,
36
+ unmarshalDeleteBudgetConfigurationRequest_ResponseSchema,
37
+ unmarshalGetBudgetConfigurationRequest_ResponseSchema,
38
+ unmarshalListBudgetConfigurationsRequest_ResponseSchema,
39
+ unmarshalUpdateBudgetConfigurationRequest_ResponseSchema,
40
+ } from './model';
41
+
42
+ // Package identity segment for this client to be used in the User-Agent header.
43
+ const PACKAGE_SEGMENT = {
44
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
45
+ value: pkgJson.version,
46
+ };
47
+
48
+ export class BudgetsClient {
49
+ private readonly host: string;
50
+ // Fallback for endpoints whose path contains {account_id}. If the request
51
+ // already carries an accountId, that value wins.
52
+ private readonly accountId: string | undefined;
53
+ private readonly httpClient: HttpClient;
54
+ private readonly logger: Logger;
55
+ // User-Agent header value. Composed once at construction from
56
+ // createDefault() merged with this package's identity and the active
57
+ // credential's name.
58
+ private readonly userAgent: string;
59
+
60
+ constructor(options: ClientOptions) {
61
+ if (options.host === undefined) {
62
+ throw new Error('Host is required.');
63
+ }
64
+ this.host = options.host.replace(/\/$/, '');
65
+ this.accountId = options.accountId;
66
+ this.logger = options.logger ?? new NoOpLogger();
67
+ const info = createDefault()
68
+ .with(PACKAGE_SEGMENT)
69
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
70
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
71
+ this.userAgent = info.toString();
72
+ this.httpClient = newHttpClient(options);
73
+ }
74
+
75
+ /** Create a new budget configuration for an account. For full details, see https://docs.databricks.com/en/admin/account-settings/budgets.html. */
76
+ async createBudgetConfiguration(
77
+ req: CreateBudgetConfigurationRequest,
78
+ options?: CallOptions
79
+ ): Promise<CreateBudgetConfigurationRequest_Response> {
80
+ const url = `${this.host}/api/2.1/accounts/${req.budget?.accountId ?? this.accountId ?? ''}/budgets`;
81
+ const body = marshalRequest(
82
+ req,
83
+ marshalCreateBudgetConfigurationRequestSchema
84
+ );
85
+ let resp: CreateBudgetConfigurationRequest_Response | undefined;
86
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
87
+ const headers = new Headers({'Content-Type': 'application/json'});
88
+ headers.set('User-Agent', this.userAgent);
89
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
90
+ const respBody = await executeHttpCall({
91
+ request: httpReq,
92
+ httpClient: this.httpClient,
93
+ logger: this.logger,
94
+ });
95
+ resp = parseResponse(
96
+ respBody,
97
+ unmarshalCreateBudgetConfigurationRequest_ResponseSchema
98
+ );
99
+ };
100
+ await executeCall(call, options);
101
+ if (resp === undefined) {
102
+ throw new Error('operation completed without a result.');
103
+ }
104
+ return resp;
105
+ }
106
+
107
+ /** Deletes a budget configuration for an account. Both account and budget configuration are specified by ID. This cannot be undone. */
108
+ async deleteBudgetConfiguration(
109
+ req: DeleteBudgetConfigurationRequest,
110
+ options?: CallOptions
111
+ ): Promise<DeleteBudgetConfigurationRequest_Response> {
112
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/budgets/${req.budgetId ?? ''}`;
113
+ let resp: DeleteBudgetConfigurationRequest_Response | undefined;
114
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
115
+ const headers = new Headers();
116
+ headers.set('User-Agent', this.userAgent);
117
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
118
+ const respBody = await executeHttpCall({
119
+ request: httpReq,
120
+ httpClient: this.httpClient,
121
+ logger: this.logger,
122
+ });
123
+ resp = parseResponse(
124
+ respBody,
125
+ unmarshalDeleteBudgetConfigurationRequest_ResponseSchema
126
+ );
127
+ };
128
+ await executeCall(call, options);
129
+ if (resp === undefined) {
130
+ throw new Error('operation completed without a result.');
131
+ }
132
+ return resp;
133
+ }
134
+
135
+ /** Gets a budget configuration for an account. Both account and budget configuration are specified by ID. */
136
+ async getBudgetConfiguration(
137
+ req: GetBudgetConfigurationRequest,
138
+ options?: CallOptions
139
+ ): Promise<GetBudgetConfigurationRequest_Response> {
140
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/budgets/${req.budgetId ?? ''}`;
141
+ const params = new URLSearchParams();
142
+ if (req.includeSpendStatus !== undefined) {
143
+ params.append('include_spend_status', String(req.includeSpendStatus));
144
+ }
145
+ const query = params.toString();
146
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
147
+ let resp: GetBudgetConfigurationRequest_Response | undefined;
148
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
149
+ const headers = new Headers();
150
+ headers.set('User-Agent', this.userAgent);
151
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
152
+ const respBody = await executeHttpCall({
153
+ request: httpReq,
154
+ httpClient: this.httpClient,
155
+ logger: this.logger,
156
+ });
157
+ resp = parseResponse(
158
+ respBody,
159
+ unmarshalGetBudgetConfigurationRequest_ResponseSchema
160
+ );
161
+ };
162
+ await executeCall(call, options);
163
+ if (resp === undefined) {
164
+ throw new Error('operation completed without a result.');
165
+ }
166
+ return resp;
167
+ }
168
+
169
+ /** Gets all budgets associated with this account. */
170
+ async listBudgetConfigurations(
171
+ req: ListBudgetConfigurationsRequest,
172
+ options?: CallOptions
173
+ ): Promise<ListBudgetConfigurationsRequest_Response> {
174
+ const url = `${this.host}/api/2.1/accounts/${req.accountId ?? this.accountId ?? ''}/budgets`;
175
+ const params = new URLSearchParams();
176
+ if (req.pageToken !== undefined) {
177
+ params.append('page_token', req.pageToken);
178
+ }
179
+ if (req.includeSpendStatus !== undefined) {
180
+ params.append('include_spend_status', String(req.includeSpendStatus));
181
+ }
182
+ if (req.includeWorkspaceBudgets !== undefined) {
183
+ params.append(
184
+ 'include_workspace_budgets',
185
+ String(req.includeWorkspaceBudgets)
186
+ );
187
+ }
188
+ const query = params.toString();
189
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
190
+ let resp: ListBudgetConfigurationsRequest_Response | undefined;
191
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
192
+ const headers = new Headers();
193
+ headers.set('User-Agent', this.userAgent);
194
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
195
+ const respBody = await executeHttpCall({
196
+ request: httpReq,
197
+ httpClient: this.httpClient,
198
+ logger: this.logger,
199
+ });
200
+ resp = parseResponse(
201
+ respBody,
202
+ unmarshalListBudgetConfigurationsRequest_ResponseSchema
203
+ );
204
+ };
205
+ await executeCall(call, options);
206
+ if (resp === undefined) {
207
+ throw new Error('operation completed without a result.');
208
+ }
209
+ return resp;
210
+ }
211
+
212
+ async *listBudgetConfigurationsIter(
213
+ req: ListBudgetConfigurationsRequest,
214
+ options?: CallOptions
215
+ ): AsyncGenerator<BudgetConfiguration> {
216
+ const pageReq: ListBudgetConfigurationsRequest = {...req};
217
+ for (;;) {
218
+ const resp = await this.listBudgetConfigurations(pageReq, options);
219
+ for (const item of resp.budgets ?? []) {
220
+ yield item;
221
+ }
222
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
223
+ return;
224
+ }
225
+ pageReq.pageToken = resp.nextPageToken;
226
+ }
227
+ }
228
+
229
+ /** Updates a budget configuration for an account. Both account and budget configuration are specified by ID. */
230
+ async updateBudgetConfiguration(
231
+ req: UpdateBudgetConfigurationRequest,
232
+ options?: CallOptions
233
+ ): Promise<UpdateBudgetConfigurationRequest_Response> {
234
+ const url = `${this.host}/api/2.1/accounts/${req.budget?.accountId ?? this.accountId ?? ''}/budgets/${req.budgetId ?? ''}`;
235
+ const body = marshalRequest(
236
+ req,
237
+ marshalUpdateBudgetConfigurationRequestSchema
238
+ );
239
+ let resp: UpdateBudgetConfigurationRequest_Response | undefined;
240
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
241
+ const headers = new Headers({'Content-Type': 'application/json'});
242
+ headers.set('User-Agent', this.userAgent);
243
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
244
+ const respBody = await executeHttpCall({
245
+ request: httpReq,
246
+ httpClient: this.httpClient,
247
+ logger: this.logger,
248
+ });
249
+ resp = parseResponse(
250
+ respBody,
251
+ unmarshalUpdateBudgetConfigurationRequest_ResponseSchema
252
+ );
253
+ };
254
+ await executeCall(call, options);
255
+ if (resp === undefined) {
256
+ throw new Error('operation completed without a result.');
257
+ }
258
+ return resp;
259
+ }
260
+ }
@@ -0,0 +1,33 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ export {BudgetsClient} from './client';
4
+
5
+ export {
6
+ ActionConfigurationType,
7
+ AlertConfigurationQuantityType,
8
+ AlertConfigurationTimePeriod,
9
+ AlertConfigurationTriggerType,
10
+ BudgetConfigurationFilter_Operator,
11
+ } from './model';
12
+
13
+ export type {
14
+ ActionConfiguration,
15
+ AlertConfiguration,
16
+ BudgetConfiguration,
17
+ BudgetConfigurationFilter,
18
+ BudgetConfigurationFilter_Clause,
19
+ BudgetConfigurationFilter_TagClause,
20
+ BudgetConfigurationFilter_WorkspaceIdClause,
21
+ CreateBudgetConfigurationBudget,
22
+ CreateBudgetConfigurationRequest,
23
+ CreateBudgetConfigurationRequest_Response,
24
+ DeleteBudgetConfigurationRequest,
25
+ DeleteBudgetConfigurationRequest_Response,
26
+ GetBudgetConfigurationRequest,
27
+ GetBudgetConfigurationRequest_Response,
28
+ ListBudgetConfigurationsRequest,
29
+ ListBudgetConfigurationsRequest_Response,
30
+ UpdateBudgetConfigurationBudget,
31
+ UpdateBudgetConfigurationRequest,
32
+ UpdateBudgetConfigurationRequest_Response,
33
+ } from './model';