@databricks/sdk-tokens 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.
- package/LICENSE +203 -0
- package/dist/v1/client.d.ts +32 -0
- package/dist/v1/client.d.ts.map +1 -0
- package/dist/v1/client.js +152 -0
- package/dist/v1/client.js.map +1 -0
- package/dist/v1/index.d.ts +5 -0
- package/dist/v1/index.d.ts.map +1 -0
- package/dist/v1/index.js +5 -0
- package/dist/v1/index.js.map +1 -0
- package/dist/v1/model.d.ts +94 -0
- package/dist/v1/model.d.ts.map +1 -0
- package/dist/v1/model.js +138 -0
- package/dist/v1/model.js.map +1 -0
- package/dist/v1/transport.d.ts +5 -0
- package/dist/v1/transport.d.ts.map +1 -0
- package/dist/v1/transport.js +57 -0
- package/dist/v1/transport.js.map +1 -0
- package/dist/v1/utils.d.ts +22 -0
- package/dist/v1/utils.d.ts.map +1 -0
- package/dist/v1/utils.js +113 -0
- package/dist/v1/utils.js.map +1 -0
- package/package.json +38 -4
- package/src/v1/client.ts +206 -0
- package/src/v1/index.ts +19 -0
- package/src/v1/model.ts +236 -0
- package/src/v1/transport.ts +73 -0
- package/src/v1/utils.ts +156 -0
- package/README.md +0 -1
- package/index.js +0 -1
package/src/v1/model.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
import {FieldMask} from '@databricks/sdk-core/wkt';
|
|
4
|
+
import type {FieldMaskSchema} from '@databricks/sdk-core/wkt';
|
|
5
|
+
import {z} from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* State of inferred scope collection (autoscope) for an external PAT.
|
|
9
|
+
* Mirrored in databricks.identity.AutoscopeState in common/principal-context/api/proto/tokendetails.proto.
|
|
10
|
+
* Token store and token management proto can depend on this.
|
|
11
|
+
* Principal context proto should NOT depend on this proto definitions because too many services depend on the principal context proto.
|
|
12
|
+
*/
|
|
13
|
+
export enum AutoscopeState {
|
|
14
|
+
AUTOSCOPE_STATE_UNSPECIFIED = 'AUTOSCOPE_STATE_UNSPECIFIED',
|
|
15
|
+
AUTOSCOPE_STATE_DISABLED = 'AUTOSCOPE_STATE_DISABLED',
|
|
16
|
+
AUTOSCOPE_STATE_RUNNING = 'AUTOSCOPE_STATE_RUNNING',
|
|
17
|
+
AUTOSCOPE_STATE_COMPLETED = 'AUTOSCOPE_STATE_COMPLETED',
|
|
18
|
+
AUTOSCOPE_STATE_BACKFILLED = 'AUTOSCOPE_STATE_BACKFILLED',
|
|
19
|
+
AUTOSCOPE_STATE_USER_SELECTED = 'AUTOSCOPE_STATE_USER_SELECTED',
|
|
20
|
+
AUTOSCOPE_STATE_API_NOT_COVERED = 'AUTOSCOPE_STATE_API_NOT_COVERED',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CreateTokenRequest {
|
|
24
|
+
/**
|
|
25
|
+
* The lifetime of the token, in seconds.
|
|
26
|
+
*
|
|
27
|
+
* If the lifetime is not specified, this token remains valid for 2 years.
|
|
28
|
+
*/
|
|
29
|
+
lifetimeSeconds?: bigint | undefined;
|
|
30
|
+
/** Optional description to attach to the token. */
|
|
31
|
+
comment?: string | undefined;
|
|
32
|
+
/** Optional scopes of the token. */
|
|
33
|
+
scopes?: string[] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to enable autoscoping for this token. When true, the token will
|
|
36
|
+
* automatically collect inferred API path scopes as it is used.
|
|
37
|
+
*/
|
|
38
|
+
autoscopeEnabled?: boolean | undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
42
|
+
export interface CreateTokenRequest_Response {
|
|
43
|
+
/** The value of the new token. */
|
|
44
|
+
tokenValue?: string | undefined;
|
|
45
|
+
/** The information for the new token. */
|
|
46
|
+
tokenInfo?: PublicTokenInfo | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
50
|
+
export interface ListTokensRequest {}
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
53
|
+
export interface ListTokensRequest_Response {
|
|
54
|
+
/** The information for each token. */
|
|
55
|
+
tokenInfos?: PublicTokenInfo[] | undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PublicTokenInfo {
|
|
59
|
+
/** The ID of this token. */
|
|
60
|
+
tokenId?: string | undefined;
|
|
61
|
+
/** Server time (in epoch milliseconds) when the token was created. */
|
|
62
|
+
creationTime?: bigint | undefined;
|
|
63
|
+
/** Server time (in epoch milliseconds) when the token will expire, or -1 if not applicable. */
|
|
64
|
+
expiryTime?: bigint | undefined;
|
|
65
|
+
/** Comment the token was created with, if applicable. */
|
|
66
|
+
comment?: string | undefined;
|
|
67
|
+
/** Scope of the token was created with, if applicable. */
|
|
68
|
+
scopes?: string[] | undefined;
|
|
69
|
+
/** Output only. The autoscope state of this token. */
|
|
70
|
+
autoscopeState?: AutoscopeState | undefined;
|
|
71
|
+
/** Output only. Inferred API path scopes collected for this token when autoscope is enabled. */
|
|
72
|
+
inferredScopes?: string[] | undefined;
|
|
73
|
+
/** Output only. Scopes inferred from offline backfill processing. */
|
|
74
|
+
backfillScopes?: string[] | undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface RevokeTokenRequest {
|
|
78
|
+
/** The ID of the token to be revoked. */
|
|
79
|
+
tokenId?: string | undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type -- Proto-style nested message name.
|
|
83
|
+
export interface RevokeTokenRequest_Response {}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* For the list of supported token scopes, see
|
|
87
|
+
* https://docs.databricks.com/api/workspace/api/scopes.
|
|
88
|
+
*/
|
|
89
|
+
export interface UpdateTokenRequest {
|
|
90
|
+
/** The SHA-256 hash of the token to be updated. */
|
|
91
|
+
tokenId?: string | undefined;
|
|
92
|
+
token?: PublicTokenInfo | undefined;
|
|
93
|
+
/** A list of field name under token, For example, {"update_mask": "comment,scopes"} */
|
|
94
|
+
updateMask?: FieldMask<PublicTokenInfo> | undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
98
|
+
export interface UpdateTokenResponse {}
|
|
99
|
+
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
101
|
+
export const unmarshalCreateTokenRequest_ResponseSchema: z.ZodType<CreateTokenRequest_Response> =
|
|
102
|
+
z
|
|
103
|
+
.object({
|
|
104
|
+
token_value: z.string().optional(),
|
|
105
|
+
token_info: z.lazy(() => unmarshalPublicTokenInfoSchema).optional(),
|
|
106
|
+
})
|
|
107
|
+
.transform(d => ({
|
|
108
|
+
tokenValue: d.token_value,
|
|
109
|
+
tokenInfo: d.token_info,
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
113
|
+
export const unmarshalListTokensRequest_ResponseSchema: z.ZodType<ListTokensRequest_Response> =
|
|
114
|
+
z
|
|
115
|
+
.object({
|
|
116
|
+
token_infos: z
|
|
117
|
+
.array(z.lazy(() => unmarshalPublicTokenInfoSchema))
|
|
118
|
+
.optional(),
|
|
119
|
+
})
|
|
120
|
+
.transform(d => ({
|
|
121
|
+
tokenInfos: d.token_infos,
|
|
122
|
+
}));
|
|
123
|
+
|
|
124
|
+
export const unmarshalPublicTokenInfoSchema: z.ZodType<PublicTokenInfo> = z
|
|
125
|
+
.object({
|
|
126
|
+
token_id: z.string().optional(),
|
|
127
|
+
creation_time: z
|
|
128
|
+
.union([z.number(), z.bigint()])
|
|
129
|
+
.transform(v => BigInt(v))
|
|
130
|
+
.optional(),
|
|
131
|
+
expiry_time: z
|
|
132
|
+
.union([z.number(), z.bigint()])
|
|
133
|
+
.transform(v => BigInt(v))
|
|
134
|
+
.optional(),
|
|
135
|
+
comment: z.string().optional(),
|
|
136
|
+
scopes: z.array(z.string()).optional(),
|
|
137
|
+
autoscope_state: z.enum(AutoscopeState).optional(),
|
|
138
|
+
inferred_scopes: z.array(z.string()).optional(),
|
|
139
|
+
backfill_scopes: z.array(z.string()).optional(),
|
|
140
|
+
})
|
|
141
|
+
.transform(d => ({
|
|
142
|
+
tokenId: d.token_id,
|
|
143
|
+
creationTime: d.creation_time,
|
|
144
|
+
expiryTime: d.expiry_time,
|
|
145
|
+
comment: d.comment,
|
|
146
|
+
scopes: d.scopes,
|
|
147
|
+
autoscopeState: d.autoscope_state,
|
|
148
|
+
inferredScopes: d.inferred_scopes,
|
|
149
|
+
backfillScopes: d.backfill_scopes,
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
153
|
+
export const unmarshalRevokeTokenRequest_ResponseSchema: z.ZodType<RevokeTokenRequest_Response> =
|
|
154
|
+
z.object({});
|
|
155
|
+
|
|
156
|
+
export const unmarshalUpdateTokenResponseSchema: z.ZodType<UpdateTokenResponse> =
|
|
157
|
+
z.object({});
|
|
158
|
+
|
|
159
|
+
export const marshalCreateTokenRequestSchema: z.ZodType = z
|
|
160
|
+
.object({
|
|
161
|
+
lifetimeSeconds: z.bigint().optional(),
|
|
162
|
+
comment: z.string().optional(),
|
|
163
|
+
scopes: z.array(z.string()).optional(),
|
|
164
|
+
autoscopeEnabled: z.boolean().optional(),
|
|
165
|
+
})
|
|
166
|
+
.transform(d => ({
|
|
167
|
+
lifetime_seconds: d.lifetimeSeconds,
|
|
168
|
+
comment: d.comment,
|
|
169
|
+
scopes: d.scopes,
|
|
170
|
+
autoscope_enabled: d.autoscopeEnabled,
|
|
171
|
+
}));
|
|
172
|
+
|
|
173
|
+
export const marshalPublicTokenInfoSchema: z.ZodType = z
|
|
174
|
+
.object({
|
|
175
|
+
tokenId: z.string().optional(),
|
|
176
|
+
creationTime: z.bigint().optional(),
|
|
177
|
+
expiryTime: z.bigint().optional(),
|
|
178
|
+
comment: z.string().optional(),
|
|
179
|
+
scopes: z.array(z.string()).optional(),
|
|
180
|
+
autoscopeState: z.enum(AutoscopeState).optional(),
|
|
181
|
+
inferredScopes: z.array(z.string()).optional(),
|
|
182
|
+
backfillScopes: z.array(z.string()).optional(),
|
|
183
|
+
})
|
|
184
|
+
.transform(d => ({
|
|
185
|
+
token_id: d.tokenId,
|
|
186
|
+
creation_time: d.creationTime,
|
|
187
|
+
expiry_time: d.expiryTime,
|
|
188
|
+
comment: d.comment,
|
|
189
|
+
scopes: d.scopes,
|
|
190
|
+
autoscope_state: d.autoscopeState,
|
|
191
|
+
inferred_scopes: d.inferredScopes,
|
|
192
|
+
backfill_scopes: d.backfillScopes,
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
export const marshalRevokeTokenRequestSchema: z.ZodType = z
|
|
196
|
+
.object({
|
|
197
|
+
tokenId: z.string().optional(),
|
|
198
|
+
})
|
|
199
|
+
.transform(d => ({
|
|
200
|
+
token_id: d.tokenId,
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
export const marshalUpdateTokenRequestSchema: z.ZodType = z
|
|
204
|
+
.object({
|
|
205
|
+
tokenId: z.string().optional(),
|
|
206
|
+
token: z.lazy(() => marshalPublicTokenInfoSchema).optional(),
|
|
207
|
+
updateMask: z
|
|
208
|
+
.any()
|
|
209
|
+
.transform((m: FieldMask) => m.toString())
|
|
210
|
+
.optional(),
|
|
211
|
+
})
|
|
212
|
+
.transform(d => ({
|
|
213
|
+
token_id: d.tokenId,
|
|
214
|
+
token: d.token,
|
|
215
|
+
update_mask: d.updateMask,
|
|
216
|
+
}));
|
|
217
|
+
|
|
218
|
+
const publicTokenInfoFieldMaskSchema: FieldMaskSchema = {
|
|
219
|
+
autoscopeState: {wire: 'autoscope_state'},
|
|
220
|
+
backfillScopes: {wire: 'backfill_scopes'},
|
|
221
|
+
comment: {wire: 'comment'},
|
|
222
|
+
creationTime: {wire: 'creation_time'},
|
|
223
|
+
expiryTime: {wire: 'expiry_time'},
|
|
224
|
+
inferredScopes: {wire: 'inferred_scopes'},
|
|
225
|
+
scopes: {wire: 'scopes'},
|
|
226
|
+
tokenId: {wire: 'token_id'},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export function publicTokenInfoFieldMask(
|
|
230
|
+
...paths: string[]
|
|
231
|
+
): FieldMask<PublicTokenInfo> {
|
|
232
|
+
return FieldMask.build<PublicTokenInfo>(
|
|
233
|
+
paths,
|
|
234
|
+
publicTokenInfoFieldMaskSchema
|
|
235
|
+
);
|
|
236
|
+
}
|
|
@@ -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
|
+
}
|
package/src/v1/utils.ts
ADDED
|
@@ -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 = {};
|