@databricks/sdk-budgets 0.0.0-dev → 0.1.0-dev.1

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