@databricks/sdk-scim 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,73 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import type {Credentials} from '@databricks/sdk-auth';
4
+ import {defaultCredentials} from '@databricks/sdk-auth/credentials';
5
+ import type {
6
+ HttpClient,
7
+ HttpRequest,
8
+ HttpResponse,
9
+ } from '@databricks/sdk-core/http';
10
+ import {newFetchHttpClient} from '@databricks/sdk-core/http';
11
+ import type {ClientOptions} from '@databricks/sdk-options/client';
12
+
13
+ /** Creates a new HTTP client with the given options. */
14
+ export function newHttpClient(options?: ClientOptions): HttpClient {
15
+ const opts = options ?? {};
16
+
17
+ // If an HTTP client is provided, use it as-is. Throw if other options are
18
+ // also set, since they would be silently ignored.
19
+ if (opts.httpClient !== undefined) {
20
+ if (opts.credentials !== undefined || opts.timeout !== undefined) {
21
+ throw new Error(
22
+ 'httpClient cannot be combined with credentials or timeout'
23
+ );
24
+ }
25
+ return opts.httpClient;
26
+ }
27
+
28
+ const credentials = opts.credentials ?? defaultCredentials();
29
+
30
+ const base = newFetchHttpClient();
31
+ let client: HttpClient = new AuthHttpClient(base, credentials);
32
+
33
+ if (opts.timeout !== undefined) {
34
+ client = new TimeoutHttpClient(client, opts.timeout);
35
+ }
36
+
37
+ return client;
38
+ }
39
+
40
+ /** Wraps an HttpClient and adds authentication headers to requests. */
41
+ class AuthHttpClient implements HttpClient {
42
+ constructor(
43
+ private readonly base: HttpClient,
44
+ private readonly credentials: Credentials
45
+ ) {}
46
+
47
+ async send(request: HttpRequest): Promise<HttpResponse> {
48
+ const authHeaders = await this.credentials.authHeaders();
49
+ // Do not modify the original request.
50
+ const headers = new Headers(request.headers);
51
+ for (const h of authHeaders) {
52
+ headers.set(h.key, h.value);
53
+ }
54
+ return this.base.send({...request, headers});
55
+ }
56
+ }
57
+
58
+ /** Wraps an HttpClient and applies a default timeout to requests. */
59
+ class TimeoutHttpClient implements HttpClient {
60
+ constructor(
61
+ private readonly base: HttpClient,
62
+ private readonly timeout: number
63
+ ) {}
64
+
65
+ async send(request: HttpRequest): Promise<HttpResponse> {
66
+ const timeoutSignal = AbortSignal.timeout(this.timeout);
67
+ const signal =
68
+ request.signal !== undefined
69
+ ? AbortSignal.any([request.signal, timeoutSignal])
70
+ : timeoutSignal;
71
+ return this.base.send({...request, signal});
72
+ }
73
+ }
@@ -0,0 +1,156 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import type {Call, Options} from '@databricks/sdk-core/api';
4
+ import {execute} from '@databricks/sdk-core/api';
5
+ import {ApiError} from '@databricks/sdk-core/apierror';
6
+ import type {
7
+ HttpClient,
8
+ HttpRequest,
9
+ HttpResponse,
10
+ } from '@databricks/sdk-core/http';
11
+ import type {Logger} from '@databricks/sdk-core/logger';
12
+ import type {CallOptions} from '@databricks/sdk-options/call';
13
+ import JSONBig from 'json-bigint';
14
+ import type {z} from 'zod';
15
+
16
+ // JSON codec that preserves int64 precision. On the way in, large integer
17
+ // literals come back as bigint instead of being rounded to JS Number. On the
18
+ // way out, bigint values are emitted as raw JSON number digits.
19
+ const jsonBigint = JSONBig({useNativeBigInt: true});
20
+
21
+ export interface HttpCallOptions {
22
+ readonly request: HttpRequest;
23
+ readonly httpClient: HttpClient;
24
+ readonly logger: Logger;
25
+ }
26
+
27
+ /**
28
+ * Translates public CallOptions to the internal Options shape accepted by
29
+ * execute(). Even though the shapes match today, this isolates the public
30
+ * API from the executor's internal type so they can diverge.
31
+ */
32
+ export async function executeCall(
33
+ call: Call,
34
+ options?: CallOptions
35
+ ): Promise<void> {
36
+ const opts: Options = {
37
+ ...(options?.retrier !== undefined && {retrier: options.retrier}),
38
+ ...(options?.rateLimiter !== undefined && {
39
+ rateLimiter: options.rateLimiter,
40
+ }),
41
+ ...(options?.timeout !== undefined && {timeout: options.timeout}),
42
+ };
43
+ return execute(options?.signal, call, opts);
44
+ }
45
+
46
+ async function readAll(
47
+ body: ReadableStream<Uint8Array> | null
48
+ ): Promise<Uint8Array> {
49
+ if (body === null) {
50
+ return new Uint8Array(0);
51
+ }
52
+ const reader = body.getReader();
53
+ const chunks: Uint8Array[] = [];
54
+ for (;;) {
55
+ const {done, value} = await reader.read();
56
+ if (done) {
57
+ break;
58
+ }
59
+ chunks.push(value);
60
+ }
61
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
62
+ const result = new Uint8Array(totalLength);
63
+ let offset = 0;
64
+ for (const chunk of chunks) {
65
+ result.set(chunk, offset);
66
+ offset += chunk.length;
67
+ }
68
+ return result;
69
+ }
70
+
71
+ export async function executeHttpCall(
72
+ opts: HttpCallOptions
73
+ ): Promise<Uint8Array> {
74
+ opts.logger.debug('HTTP request', {
75
+ method: opts.request.method,
76
+ url: opts.request.url,
77
+ });
78
+
79
+ let resp: HttpResponse;
80
+ try {
81
+ resp = await opts.httpClient.send(opts.request);
82
+ } catch (e: unknown) {
83
+ opts.logger.debug('HTTP request failed');
84
+ throw e;
85
+ }
86
+
87
+ const body = await readAll(resp.body);
88
+
89
+ opts.logger.debug('HTTP response', {
90
+ statusCode: resp.statusCode,
91
+ body: new TextDecoder().decode(body),
92
+ });
93
+
94
+ const apiErr = ApiError.fromHttpError(resp.statusCode, resp.headers, body);
95
+ if (apiErr !== undefined) {
96
+ throw apiErr;
97
+ }
98
+
99
+ return body;
100
+ }
101
+
102
+ export function buildHttpRequest(
103
+ method: string,
104
+ url: string,
105
+ headers: Headers,
106
+ signal?: AbortSignal,
107
+ body?: string | ReadableStream<Uint8Array>
108
+ ): HttpRequest {
109
+ const req: HttpRequest = {url, method, headers};
110
+ if (body !== undefined) {
111
+ req.body = body;
112
+ }
113
+ if (signal !== undefined) {
114
+ req.signal = signal;
115
+ }
116
+ return req;
117
+ }
118
+
119
+ export function parseResponse<T>(body: Uint8Array, schema: z.ZodType<T>): T {
120
+ const text = new TextDecoder().decode(body);
121
+ const parsed: unknown = jsonBigint.parse(text);
122
+ return schema.parse(parsed);
123
+ }
124
+
125
+ export function marshalRequest(data: unknown, schema: z.ZodType): string {
126
+ return jsonBigint.stringify(schema.parse(data));
127
+ }
128
+
129
+ export function flattenQueryParams(
130
+ prefix: string,
131
+ value: unknown,
132
+ params: URLSearchParams
133
+ ): void {
134
+ if (value === null || value === undefined) {
135
+ return;
136
+ }
137
+ if (Array.isArray(value)) {
138
+ // arrays of objects are not yet supported
139
+ for (const item of value) {
140
+ params.append(prefix, String(item));
141
+ }
142
+ } else if (typeof value === 'object') {
143
+ for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
144
+ flattenQueryParams(`${prefix}.${key}`, val, params);
145
+ }
146
+ } else if (
147
+ typeof value === 'string' ||
148
+ typeof value === 'number' ||
149
+ typeof value === 'boolean' ||
150
+ typeof value === 'bigint'
151
+ ) {
152
+ params.append(prefix, String(value));
153
+ } else {
154
+ throw new Error(`Unsupported query parameter type: ${typeof value}`);
155
+ }
156
+ }
package/README.md DELETED
@@ -1 +0,0 @@
1
- This is a placeholder release used to enable OIDC trusted publishing. Real code lands in a later version.
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = {};