@databricks/sdk-notificationdestinations 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,248 @@
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
+ CreateNotificationDestinationRequest,
21
+ DeleteNotificationDestinationRequest,
22
+ Empty,
23
+ GetNotificationDestinationRequest,
24
+ ListNotificationDestinationsRequest,
25
+ ListNotificationDestinationsResponse,
26
+ ListNotificationDestinationsResult,
27
+ NotificationDestination,
28
+ UpdateNotificationDestinationRequest,
29
+ } from './model';
30
+ import {
31
+ marshalCreateNotificationDestinationRequestSchema,
32
+ marshalUpdateNotificationDestinationRequestSchema,
33
+ unmarshalEmptySchema,
34
+ unmarshalListNotificationDestinationsResponseSchema,
35
+ unmarshalNotificationDestinationSchema,
36
+ } from './model';
37
+
38
+ // Package identity segment for this client to be used in the User-Agent header.
39
+ const PACKAGE_SEGMENT = {
40
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
41
+ value: pkgJson.version,
42
+ };
43
+
44
+ export class NotificationDestinationsClient {
45
+ private readonly host: string;
46
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
47
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
48
+ // request.
49
+ private readonly workspaceId: string | undefined;
50
+ private readonly httpClient: HttpClient;
51
+ private readonly logger: Logger;
52
+ // User-Agent header value. Composed once at construction from
53
+ // createDefault() merged with this package's identity and the active
54
+ // credential's name.
55
+ private readonly userAgent: string;
56
+
57
+ constructor(options: ClientOptions) {
58
+ if (options.host === undefined) {
59
+ throw new Error('Host is required.');
60
+ }
61
+ this.host = options.host.replace(/\/$/, '');
62
+ this.workspaceId = options.workspaceId;
63
+ this.logger = options.logger ?? new NoOpLogger();
64
+ const info = createDefault()
65
+ .with(PACKAGE_SEGMENT)
66
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
67
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
68
+ this.userAgent = info.toString();
69
+ this.httpClient = newHttpClient(options);
70
+ }
71
+
72
+ /** Creates a notification destination. Requires workspace admin permissions. */
73
+ async createNotificationDestination(
74
+ req: CreateNotificationDestinationRequest,
75
+ options?: CallOptions
76
+ ): Promise<NotificationDestination> {
77
+ const url = `${this.host}/api/2.0/notification-destinations`;
78
+ const body = marshalRequest(
79
+ req,
80
+ marshalCreateNotificationDestinationRequestSchema
81
+ );
82
+ let resp: NotificationDestination | undefined;
83
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
84
+ const headers = new Headers({'Content-Type': 'application/json'});
85
+ if (this.workspaceId !== undefined) {
86
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
87
+ }
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(respBody, unmarshalNotificationDestinationSchema);
96
+ };
97
+ await executeCall(call, options);
98
+ if (resp === undefined) {
99
+ throw new Error('operation completed without a result.');
100
+ }
101
+ return resp;
102
+ }
103
+
104
+ /** Deletes a notification destination. Requires workspace admin permissions. */
105
+ async deleteNotificationDestination(
106
+ req: DeleteNotificationDestinationRequest,
107
+ options?: CallOptions
108
+ ): Promise<Empty> {
109
+ const url = `${this.host}/api/2.0/notification-destinations/${req.id ?? ''}`;
110
+ let resp: Empty | undefined;
111
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
112
+ const headers = new Headers();
113
+ if (this.workspaceId !== undefined) {
114
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
115
+ }
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(respBody, unmarshalEmptySchema);
124
+ };
125
+ await executeCall(call, options);
126
+ if (resp === undefined) {
127
+ throw new Error('operation completed without a result.');
128
+ }
129
+ return resp;
130
+ }
131
+
132
+ /** Gets a notification destination. */
133
+ async getNotificationDestination(
134
+ req: GetNotificationDestinationRequest,
135
+ options?: CallOptions
136
+ ): Promise<NotificationDestination> {
137
+ const url = `${this.host}/api/2.0/notification-destinations/${req.id ?? ''}`;
138
+ let resp: NotificationDestination | undefined;
139
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
140
+ const headers = new Headers();
141
+ if (this.workspaceId !== undefined) {
142
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
143
+ }
144
+ headers.set('User-Agent', this.userAgent);
145
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
146
+ const respBody = await executeHttpCall({
147
+ request: httpReq,
148
+ httpClient: this.httpClient,
149
+ logger: this.logger,
150
+ });
151
+ resp = parseResponse(respBody, unmarshalNotificationDestinationSchema);
152
+ };
153
+ await executeCall(call, options);
154
+ if (resp === undefined) {
155
+ throw new Error('operation completed without a result.');
156
+ }
157
+ return resp;
158
+ }
159
+
160
+ /** Lists notification destinations. */
161
+ async listNotificationDestinations(
162
+ req: ListNotificationDestinationsRequest,
163
+ options?: CallOptions
164
+ ): Promise<ListNotificationDestinationsResponse> {
165
+ const url = `${this.host}/api/2.0/notification-destinations`;
166
+ const params = new URLSearchParams();
167
+ if (req.pageToken !== undefined) {
168
+ params.append('page_token', req.pageToken);
169
+ }
170
+ if (req.pageSize !== undefined) {
171
+ params.append('page_size', String(req.pageSize));
172
+ }
173
+ const query = params.toString();
174
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
175
+ let resp: ListNotificationDestinationsResponse | undefined;
176
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
177
+ const headers = new Headers();
178
+ if (this.workspaceId !== undefined) {
179
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
180
+ }
181
+ headers.set('User-Agent', this.userAgent);
182
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
183
+ const respBody = await executeHttpCall({
184
+ request: httpReq,
185
+ httpClient: this.httpClient,
186
+ logger: this.logger,
187
+ });
188
+ resp = parseResponse(
189
+ respBody,
190
+ unmarshalListNotificationDestinationsResponseSchema
191
+ );
192
+ };
193
+ await executeCall(call, options);
194
+ if (resp === undefined) {
195
+ throw new Error('operation completed without a result.');
196
+ }
197
+ return resp;
198
+ }
199
+
200
+ async *listNotificationDestinationsIter(
201
+ req: ListNotificationDestinationsRequest,
202
+ options?: CallOptions
203
+ ): AsyncGenerator<ListNotificationDestinationsResult> {
204
+ const pageReq: ListNotificationDestinationsRequest = {...req};
205
+ for (;;) {
206
+ const resp = await this.listNotificationDestinations(pageReq, options);
207
+ for (const item of resp.results ?? []) {
208
+ yield item;
209
+ }
210
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
211
+ return;
212
+ }
213
+ pageReq.pageToken = resp.nextPageToken;
214
+ }
215
+ }
216
+
217
+ /** Updates a notification destination. Requires workspace admin permissions. At least one field is required in the request body. */
218
+ async updateNotificationDestination(
219
+ req: UpdateNotificationDestinationRequest,
220
+ options?: CallOptions
221
+ ): Promise<NotificationDestination> {
222
+ const url = `${this.host}/api/2.0/notification-destinations/${req.id ?? ''}`;
223
+ const body = marshalRequest(
224
+ req,
225
+ marshalUpdateNotificationDestinationRequestSchema
226
+ );
227
+ let resp: NotificationDestination | undefined;
228
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
229
+ const headers = new Headers({'Content-Type': 'application/json'});
230
+ if (this.workspaceId !== undefined) {
231
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
232
+ }
233
+ headers.set('User-Agent', this.userAgent);
234
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
235
+ const respBody = await executeHttpCall({
236
+ request: httpReq,
237
+ httpClient: this.httpClient,
238
+ logger: this.logger,
239
+ });
240
+ resp = parseResponse(respBody, unmarshalNotificationDestinationSchema);
241
+ };
242
+ await executeCall(call, options);
243
+ if (resp === undefined) {
244
+ throw new Error('operation completed without a result.');
245
+ }
246
+ return resp;
247
+ }
248
+ }
@@ -0,0 +1,23 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ export {NotificationDestinationsClient} from './client';
4
+
5
+ export {DestinationType} from './model';
6
+
7
+ export type {
8
+ Config,
9
+ CreateNotificationDestinationRequest,
10
+ DeleteNotificationDestinationRequest,
11
+ EmailConfig,
12
+ Empty,
13
+ GenericWebhookConfig,
14
+ GetNotificationDestinationRequest,
15
+ ListNotificationDestinationsRequest,
16
+ ListNotificationDestinationsResponse,
17
+ ListNotificationDestinationsResult,
18
+ MicrosoftTeamsConfig,
19
+ NotificationDestination,
20
+ PagerdutyConfig,
21
+ SlackConfig,
22
+ UpdateNotificationDestinationRequest,
23
+ } from './model';