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