@sixb/client 0.0.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 +21 -0
- package/README.md +193 -0
- package/dist/actions.d.ts +61 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/agent-streams.d.ts +72 -0
- package/dist/agent-streams.d.ts.map +1 -0
- package/dist/api.d.ts +54 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/browser.d.ts +41 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +174 -0
- package/dist/browser.js.map +10 -0
- package/dist/chunk-05yz32g0.js +240 -0
- package/dist/chunk-05yz32g0.js.map +10 -0
- package/dist/chunk-2d7239yx.js +1181 -0
- package/dist/chunk-2d7239yx.js.map +17 -0
- package/dist/chunk-3g6ad4jc.js +147 -0
- package/dist/chunk-3g6ad4jc.js.map +10 -0
- package/dist/chunk-aw8rcsq3.js +145 -0
- package/dist/chunk-aw8rcsq3.js.map +10 -0
- package/dist/chunk-ctsdm59b.js +1477 -0
- package/dist/chunk-ctsdm59b.js.map +19 -0
- package/dist/chunk-fxrh83wy.js +180 -0
- package/dist/chunk-fxrh83wy.js.map +12 -0
- package/dist/chunk-pey7nh0d.js +123 -0
- package/dist/chunk-pey7nh0d.js.map +10 -0
- package/dist/chunk-trpg18dp.js +3 -0
- package/dist/chunk-trpg18dp.js.map +9 -0
- package/dist/events-builder.d.ts +218 -0
- package/dist/events-builder.d.ts.map +1 -0
- package/dist/events-hooks.d.ts +50 -0
- package/dist/events-hooks.d.ts.map +1 -0
- package/dist/events-model.d.ts +12 -0
- package/dist/events-model.d.ts.map +1 -0
- package/dist/events-provider.d.ts +56 -0
- package/dist/events-provider.d.ts.map +1 -0
- package/dist/events-transport.d.ts +62 -0
- package/dist/events-transport.d.ts.map +1 -0
- package/dist/events.d.ts +5 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/file.d.ts +27 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/generated/@tanstack/react-query.gen.d.ts +17064 -0
- package/dist/generated/@tanstack/react-query.gen.d.ts.map +1 -0
- package/dist/generated/client/client.gen.d.ts +3 -0
- package/dist/generated/client/client.gen.d.ts.map +1 -0
- package/dist/generated/client/index.d.ts +9 -0
- package/dist/generated/client/index.d.ts.map +1 -0
- package/dist/generated/client/types.gen.d.ts +118 -0
- package/dist/generated/client/types.gen.d.ts.map +1 -0
- package/dist/generated/client/utils.gen.d.ts +34 -0
- package/dist/generated/client/utils.gen.d.ts.map +1 -0
- package/dist/generated/client.gen.d.ts +13 -0
- package/dist/generated/client.gen.d.ts.map +1 -0
- package/dist/generated/core/auth.gen.d.ts +19 -0
- package/dist/generated/core/auth.gen.d.ts.map +1 -0
- package/dist/generated/core/bodySerializer.gen.d.ts +26 -0
- package/dist/generated/core/bodySerializer.gen.d.ts.map +1 -0
- package/dist/generated/core/params.gen.d.ts +44 -0
- package/dist/generated/core/params.gen.d.ts.map +1 -0
- package/dist/generated/core/pathSerializer.gen.d.ts +34 -0
- package/dist/generated/core/pathSerializer.gen.d.ts.map +1 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts +19 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts.map +1 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts +72 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts.map +1 -0
- package/dist/generated/core/types.gen.d.ts +79 -0
- package/dist/generated/core/types.gen.d.ts.map +1 -0
- package/dist/generated/core/utils.gen.d.ts +20 -0
- package/dist/generated/core/utils.gen.d.ts.map +1 -0
- package/dist/generated/index.d.ts +3 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/sdk.gen.d.ts +464 -0
- package/dist/generated/sdk.gen.d.ts.map +1 -0
- package/dist/generated/types.gen.d.ts +7672 -0
- package/dist/generated/types.gen.d.ts.map +1 -0
- package/dist/hooks.d.ts +123 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +3179 -0
- package/dist/hooks.js.map +16 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +329 -0
- package/dist/index.js.map +9 -0
- package/dist/logs-builder.d.ts +59 -0
- package/dist/logs-builder.d.ts.map +1 -0
- package/dist/logs-hooks.d.ts +30 -0
- package/dist/logs-hooks.d.ts.map +1 -0
- package/dist/logs-transport.d.ts +38 -0
- package/dist/logs-transport.d.ts.map +1 -0
- package/dist/logs.d.ts +7 -0
- package/dist/logs.d.ts.map +1 -0
- package/dist/logs.js +22 -0
- package/dist/logs.js.map +9 -0
- package/dist/models.d.ts +126 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +252 -0
- package/dist/models.js.map +9 -0
- package/dist/query-hooks.d.ts +365 -0
- package/dist/query-hooks.d.ts.map +1 -0
- package/dist/query.d.ts +27 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +15 -0
- package/dist/query.js.map +9 -0
- package/dist/sha256.d.ts +15 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/telemetry-events.d.ts +25 -0
- package/dist/telemetry-events.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/useAgentRunStream.d.ts +21 -0
- package/dist/useAgentRunStream.d.ts.map +1 -0
- package/dist/ws-socket.d.ts +45 -0
- package/dist/ws-socket.d.ts.map +1 -0
- package/package.json +105 -0
- package/src/actions.ts +310 -0
- package/src/agent-streams.ts +275 -0
- package/src/api.ts +229 -0
- package/src/browser.ts +267 -0
- package/src/events-builder.ts +735 -0
- package/src/events-hooks.ts +233 -0
- package/src/events-model.ts +40 -0
- package/src/events-provider.ts +161 -0
- package/src/events-transport.ts +193 -0
- package/src/events.ts +6 -0
- package/src/file.ts +367 -0
- package/src/generated/@tanstack/react-query.gen.ts +3876 -0
- package/src/generated/client/client.gen.ts +288 -0
- package/src/generated/client/index.ts +25 -0
- package/src/generated/client/types.gen.ts +209 -0
- package/src/generated/client/utils.gen.ts +316 -0
- package/src/generated/client.gen.ts +18 -0
- package/src/generated/core/auth.gen.ts +41 -0
- package/src/generated/core/bodySerializer.gen.ts +84 -0
- package/src/generated/core/params.gen.ts +169 -0
- package/src/generated/core/pathSerializer.gen.ts +171 -0
- package/src/generated/core/queryKeySerializer.gen.ts +117 -0
- package/src/generated/core/serverSentEvents.gen.ts +243 -0
- package/src/generated/core/types.gen.ts +104 -0
- package/src/generated/core/utils.gen.ts +140 -0
- package/src/generated/index.ts +672 -0
- package/src/generated/sdk.gen.ts +1984 -0
- package/src/generated/types.gen.ts +9049 -0
- package/src/hooks.ts +404 -0
- package/src/index.ts +18 -0
- package/src/logs-builder.ts +171 -0
- package/src/logs-hooks.ts +112 -0
- package/src/logs-transport.ts +112 -0
- package/src/logs.ts +15 -0
- package/src/models.ts +420 -0
- package/src/query-hooks.ts +1021 -0
- package/src/query.ts +175 -0
- package/src/sha256.ts +159 -0
- package/src/telemetry-events.ts +71 -0
- package/src/useAgentRunStream.ts +62 -0
- package/src/ws-socket.ts +202 -0
package/src/file.ts
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import type { FileRef } from "@sixb/core"
|
|
2
|
+
import { DEFAULT_SIMPLE_FILE_UPLOAD_BYTES } from "@sixb/core/blob-storage"
|
|
3
|
+
import { isSixbApiError, type SixbClient } from "./api"
|
|
4
|
+
import {
|
|
5
|
+
abortFileUpload,
|
|
6
|
+
completeFileUpload,
|
|
7
|
+
createFileUpload,
|
|
8
|
+
signFileUploadPart,
|
|
9
|
+
uploadFileContent,
|
|
10
|
+
uploadFileRaw,
|
|
11
|
+
} from "./generated/sdk.gen"
|
|
12
|
+
import { computeStreamingBlobDigest } from "./sha256"
|
|
13
|
+
|
|
14
|
+
export type SixbFileUploadStage =
|
|
15
|
+
| "hash"
|
|
16
|
+
| "create"
|
|
17
|
+
| "server-put"
|
|
18
|
+
| "direct-put"
|
|
19
|
+
| "multipart"
|
|
20
|
+
| "complete"
|
|
21
|
+
| "abort"
|
|
22
|
+
|
|
23
|
+
export class SixbFileUploadError extends Error {
|
|
24
|
+
readonly stage: SixbFileUploadStage
|
|
25
|
+
readonly status?: number
|
|
26
|
+
readonly aborted: boolean
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
message: string,
|
|
30
|
+
options: {
|
|
31
|
+
readonly stage: SixbFileUploadStage
|
|
32
|
+
readonly status?: number
|
|
33
|
+
readonly aborted?: boolean
|
|
34
|
+
readonly cause?: unknown
|
|
35
|
+
}
|
|
36
|
+
) {
|
|
37
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause })
|
|
38
|
+
this.name = "SixbFileUploadError"
|
|
39
|
+
this.stage = options.stage
|
|
40
|
+
this.status = options.status
|
|
41
|
+
this.aborted = options.aborted ?? false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface UploadFileOptions {
|
|
46
|
+
readonly fileName?: string
|
|
47
|
+
readonly logicalPath?: string
|
|
48
|
+
readonly client?: SixbClient
|
|
49
|
+
readonly fetch?: typeof fetch
|
|
50
|
+
readonly stagedUploadThresholdBytes?: number
|
|
51
|
+
readonly signal?: AbortSignal
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface UploadFileInput extends UploadFileOptions {
|
|
55
|
+
readonly file: File | Blob
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function uploadFile(
|
|
59
|
+
file: File | Blob,
|
|
60
|
+
options: UploadFileOptions = {}
|
|
61
|
+
): Promise<FileRef> {
|
|
62
|
+
const thresholdBytes = options.stagedUploadThresholdBytes ?? DEFAULT_SIMPLE_FILE_UPLOAD_BYTES
|
|
63
|
+
if (file.size > thresholdBytes) {
|
|
64
|
+
return uploadFileStaged(file, options)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return uploadFileSimple(file, options)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function uploadFileSimple(file: File | Blob, options: UploadFileOptions): Promise<FileRef> {
|
|
71
|
+
const body = {
|
|
72
|
+
file: resolveUploadFile(file, options.fileName),
|
|
73
|
+
...(options.logicalPath === undefined ? {} : { logicalPath: options.logicalPath }),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const data = await runUploadStep("server-put", () =>
|
|
77
|
+
uploadFileRaw({ body, client: options.client, ...callOptions(options.signal) })
|
|
78
|
+
)
|
|
79
|
+
return toFileRef(data, "server-put")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function uploadFileStaged(file: File | Blob, options: UploadFileOptions): Promise<FileRef> {
|
|
83
|
+
const digest = await hashFile(file)
|
|
84
|
+
const uploadBody = {
|
|
85
|
+
...(resolveUploadFileName(file, options.fileName) === undefined
|
|
86
|
+
? {}
|
|
87
|
+
: { fileName: resolveUploadFileName(file, options.fileName) }),
|
|
88
|
+
...(file.type ? { mediaType: file.type } : {}),
|
|
89
|
+
sizeBytes: file.size,
|
|
90
|
+
digest,
|
|
91
|
+
...(options.logicalPath === undefined ? {} : { logicalPath: options.logicalPath }),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const upload = await runUploadStep("create", () =>
|
|
95
|
+
createFileUpload({ body: uploadBody, client: options.client, ...callOptions(options.signal) })
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
let parts: Array<{ partNumber: number; etag: string }> | undefined
|
|
99
|
+
let completed: Omit<FileRef, "digest"> & { readonly digest: string }
|
|
100
|
+
try {
|
|
101
|
+
if (upload.strategy === "server") {
|
|
102
|
+
await runUploadStep("server-put", () =>
|
|
103
|
+
uploadFileContent({
|
|
104
|
+
body: resolveUploadFile(file, options.fileName),
|
|
105
|
+
path: { uploadId: upload.uploadId },
|
|
106
|
+
client: options.client,
|
|
107
|
+
...callOptions(options.signal),
|
|
108
|
+
})
|
|
109
|
+
)
|
|
110
|
+
} else if (upload.strategy === "direct-put") {
|
|
111
|
+
await putDirectUpload({
|
|
112
|
+
file,
|
|
113
|
+
fetch: options.fetch ?? globalThis.fetch,
|
|
114
|
+
headers: upload.headers,
|
|
115
|
+
method: upload.method,
|
|
116
|
+
url: upload.url,
|
|
117
|
+
signal: options.signal,
|
|
118
|
+
})
|
|
119
|
+
} else {
|
|
120
|
+
parts = await uploadMultipartFile({
|
|
121
|
+
client: options.client,
|
|
122
|
+
fetch: options.fetch ?? globalThis.fetch,
|
|
123
|
+
file,
|
|
124
|
+
partSizeBytes: upload.partSizeBytes,
|
|
125
|
+
uploadId: upload.uploadId,
|
|
126
|
+
signal: options.signal,
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
completed = await runUploadStep("complete", () =>
|
|
131
|
+
completeFileUpload({
|
|
132
|
+
body: { digest, sizeBytes: file.size, ...(parts === undefined ? {} : { parts }) },
|
|
133
|
+
path: { uploadId: upload.uploadId },
|
|
134
|
+
client: options.client,
|
|
135
|
+
...callOptions(options.signal),
|
|
136
|
+
})
|
|
137
|
+
)
|
|
138
|
+
} catch (error) {
|
|
139
|
+
// Clean up the staged session even on cancellation: run detached (no signal)
|
|
140
|
+
// so an aborted upload still releases server-side state. Swallow its own
|
|
141
|
+
// failure so the original error is what surfaces.
|
|
142
|
+
await abortFileUpload({
|
|
143
|
+
path: { uploadId: upload.uploadId },
|
|
144
|
+
client: options.client,
|
|
145
|
+
responseStyle: "fields",
|
|
146
|
+
throwOnError: false,
|
|
147
|
+
}).catch(() => undefined)
|
|
148
|
+
throw error
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return toFileRef(completed, "complete")
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function putDirectUpload(input: {
|
|
155
|
+
readonly file: File | Blob
|
|
156
|
+
readonly fetch: typeof fetch
|
|
157
|
+
readonly headers: Readonly<Record<string, string>>
|
|
158
|
+
readonly method: "PUT"
|
|
159
|
+
readonly url: string
|
|
160
|
+
readonly signal?: AbortSignal
|
|
161
|
+
}): Promise<void> {
|
|
162
|
+
let response: Response
|
|
163
|
+
try {
|
|
164
|
+
response = await input.fetch(input.url, {
|
|
165
|
+
method: input.method,
|
|
166
|
+
headers: input.headers,
|
|
167
|
+
body: input.file,
|
|
168
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
169
|
+
})
|
|
170
|
+
} catch (error) {
|
|
171
|
+
throw toSixbFileUploadError(error, "direct-put")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
throw new SixbFileUploadError(
|
|
176
|
+
`[SixbClient] Direct file upload failed with HTTP ${response.status}.`,
|
|
177
|
+
{ stage: "direct-put", status: response.status }
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function uploadMultipartFile(input: {
|
|
183
|
+
readonly client?: SixbClient
|
|
184
|
+
readonly fetch: typeof fetch
|
|
185
|
+
readonly file: File | Blob
|
|
186
|
+
readonly partSizeBytes: number
|
|
187
|
+
readonly uploadId: string
|
|
188
|
+
readonly signal?: AbortSignal
|
|
189
|
+
}): Promise<Array<{ partNumber: number; etag: string }>> {
|
|
190
|
+
const parts: Array<{ partNumber: number; etag: string }> = []
|
|
191
|
+
let partNumber = 1
|
|
192
|
+
|
|
193
|
+
for (let offset = 0; offset < input.file.size; offset += input.partSizeBytes) {
|
|
194
|
+
const signedPart = await runUploadStep("multipart", () =>
|
|
195
|
+
signFileUploadPart({
|
|
196
|
+
path: { uploadId: input.uploadId, partNumber: partNumber.toString() },
|
|
197
|
+
client: input.client,
|
|
198
|
+
...callOptions(input.signal),
|
|
199
|
+
})
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
let response: Response
|
|
203
|
+
try {
|
|
204
|
+
response = await input.fetch(signedPart.url, {
|
|
205
|
+
method: signedPart.method,
|
|
206
|
+
headers: signedPart.headers,
|
|
207
|
+
body: input.file.slice(offset, Math.min(input.file.size, offset + input.partSizeBytes)),
|
|
208
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
209
|
+
})
|
|
210
|
+
} catch (error) {
|
|
211
|
+
throw toSixbFileUploadError(error, "multipart")
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!response.ok) {
|
|
215
|
+
throw new SixbFileUploadError(
|
|
216
|
+
`[SixbClient] Multipart file upload part ${partNumber} failed with HTTP ${response.status}.`,
|
|
217
|
+
{ stage: "multipart", status: response.status }
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const etag = response.headers.get("etag")
|
|
222
|
+
if (!etag) {
|
|
223
|
+
throw new SixbFileUploadError(
|
|
224
|
+
`[SixbClient] Multipart file upload part ${partNumber} did not return an ETag.`,
|
|
225
|
+
{ stage: "multipart" }
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
parts.push({ partNumber, etag })
|
|
230
|
+
partNumber += 1
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return parts
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function hashFile(file: File | Blob): Promise<FileRef["digest"]> {
|
|
237
|
+
try {
|
|
238
|
+
return await computeStreamingBlobDigest(file)
|
|
239
|
+
} catch (error) {
|
|
240
|
+
throw toSixbFileUploadError(error, "hash")
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const callOptions = (signal: AbortSignal | undefined) =>
|
|
245
|
+
({
|
|
246
|
+
responseStyle: "fields",
|
|
247
|
+
throwOnError: false,
|
|
248
|
+
...(signal === undefined ? {} : { signal }),
|
|
249
|
+
}) as const
|
|
250
|
+
|
|
251
|
+
// Runs one SDK step under the `{ data, error }` convention: HTTP failures land in
|
|
252
|
+
// `error`, transport failures (including aborts) throw — both map to a typed
|
|
253
|
+
// SixbFileUploadError tagged with the stage that failed.
|
|
254
|
+
async function runUploadStep<T>(
|
|
255
|
+
stage: SixbFileUploadStage,
|
|
256
|
+
call: () => Promise<{
|
|
257
|
+
readonly data?: T
|
|
258
|
+
readonly error?: unknown
|
|
259
|
+
readonly response?: { readonly status: number }
|
|
260
|
+
}>
|
|
261
|
+
): Promise<T> {
|
|
262
|
+
let result: {
|
|
263
|
+
readonly data?: T
|
|
264
|
+
readonly error?: unknown
|
|
265
|
+
readonly response?: { status: number }
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
result = await call()
|
|
269
|
+
} catch (error) {
|
|
270
|
+
throw toSixbFileUploadError(error, stage)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (result.error !== undefined || result.data === undefined) {
|
|
274
|
+
throw toSixbFileUploadError(result.error, stage, result.response?.status)
|
|
275
|
+
}
|
|
276
|
+
return result.data
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function toSixbFileUploadError(
|
|
280
|
+
error: unknown,
|
|
281
|
+
stage: SixbFileUploadStage,
|
|
282
|
+
status?: number
|
|
283
|
+
): SixbFileUploadError {
|
|
284
|
+
if (isAbortError(error)) {
|
|
285
|
+
return new SixbFileUploadError("[SixbClient] File upload was aborted.", {
|
|
286
|
+
stage: "abort",
|
|
287
|
+
aborted: true,
|
|
288
|
+
cause: error,
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const detail = uploadErrorDetail(error)
|
|
293
|
+
const message = detail ? `[SixbClient] ${detail}` : "[SixbClient] File upload request failed."
|
|
294
|
+
return new SixbFileUploadError(message, {
|
|
295
|
+
stage,
|
|
296
|
+
status: status ?? (isSixbApiError(error) ? error.status : undefined),
|
|
297
|
+
cause: error,
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function isAbortError(error: unknown): boolean {
|
|
302
|
+
return (
|
|
303
|
+
typeof error === "object" &&
|
|
304
|
+
error !== null &&
|
|
305
|
+
"name" in error &&
|
|
306
|
+
(error as { name?: unknown }).name === "AbortError"
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function uploadErrorDetail(error: unknown): string | undefined {
|
|
311
|
+
const body = isSixbApiError(error) ? error.body : error
|
|
312
|
+
|
|
313
|
+
if (typeof body === "string") {
|
|
314
|
+
return body.trim() || undefined
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (body && typeof body === "object" && "error" in body) {
|
|
318
|
+
const message = (body as { readonly error?: unknown }).error
|
|
319
|
+
return typeof message === "string" && message.trim() ? message : undefined
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (error instanceof Error && error.message.trim()) {
|
|
323
|
+
return error.message
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return undefined
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function resolveUploadFile(file: File | Blob, fileName: string | undefined): File | Blob {
|
|
330
|
+
if (fileName === undefined) {
|
|
331
|
+
return file
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (typeof File === "undefined") {
|
|
335
|
+
return file
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return new File([file], fileName, { type: file.type || undefined })
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function resolveUploadFileName(
|
|
342
|
+
file: File | Blob,
|
|
343
|
+
fileName: string | undefined
|
|
344
|
+
): string | undefined {
|
|
345
|
+
if (fileName !== undefined) {
|
|
346
|
+
return fileName
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return typeof File !== "undefined" && file instanceof File && file.name ? file.name : undefined
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function toFileRef(
|
|
353
|
+
value: Omit<FileRef, "digest"> & { readonly digest: string },
|
|
354
|
+
stage: SixbFileUploadStage
|
|
355
|
+
): FileRef {
|
|
356
|
+
if (!value.digest.startsWith("sha256:")) {
|
|
357
|
+
throw new SixbFileUploadError(
|
|
358
|
+
"[SixbClient] File upload response did not include a sha256 digest.",
|
|
359
|
+
{ stage }
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
...value,
|
|
365
|
+
digest: value.digest as FileRef["digest"],
|
|
366
|
+
}
|
|
367
|
+
}
|