@blaxel/core 0.2.49-preview.108 → 0.2.49-preview.110

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,53 @@
1
+ "use strict";
2
+ /**
3
+ * Response interceptor that enhances authentication error messages (401/403)
4
+ * with a link to the authentication documentation.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.responseInterceptors = exports.authenticationErrorInterceptor = void 0;
8
+ /**
9
+ * Intercepts HTTP responses and adds authentication documentation
10
+ * to 401/403 error responses
11
+ */
12
+ const authenticationErrorInterceptor = async (response) => {
13
+ // Only process authentication errors (401/403)
14
+ if (response.status !== 401 && response.status !== 403) {
15
+ return response;
16
+ }
17
+ // Clone the response so we can modify it
18
+ const clonedResponse = response.clone();
19
+ try {
20
+ // Read the original response body
21
+ const bodyText = await clonedResponse.text();
22
+ // Try to parse as JSON
23
+ let enhancedBody;
24
+ try {
25
+ const originalError = JSON.parse(bodyText);
26
+ // Create enhanced error with authentication documentation
27
+ const authError = {
28
+ ...originalError,
29
+ documentation: "For more information on authentication, visit: https://docs.blaxel.ai/sdk-reference/introduction#how-authentication-works",
30
+ };
31
+ enhancedBody = JSON.stringify(authError);
32
+ }
33
+ catch {
34
+ // If not JSON, just append the documentation as text
35
+ enhancedBody = `${bodyText}\nFor more information on authentication, visit: https://docs.blaxel.ai/sdk-reference/introduction#how-authentication-works`;
36
+ }
37
+ // Create a new response with the enhanced body
38
+ return new Response(enhancedBody, {
39
+ status: response.status,
40
+ statusText: response.statusText,
41
+ headers: response.headers,
42
+ });
43
+ }
44
+ catch (error) {
45
+ // If anything fails, return the original response
46
+ console.error("Error processing authentication error response:", error);
47
+ return response;
48
+ }
49
+ };
50
+ exports.authenticationErrorInterceptor = authenticationErrorInterceptor;
51
+ exports.responseInterceptors = [
52
+ exports.authenticationErrorInterceptor,
53
+ ];
@@ -4,17 +4,24 @@ exports.initialize = initialize;
4
4
  exports.authenticate = authenticate;
5
5
  const client_gen_js_1 = require("../client/client.gen.js");
6
6
  const interceptors_js_1 = require("../client/interceptors.js");
7
+ const responseInterceptor_js_1 = require("../client/responseInterceptor.js");
7
8
  const client_gen_js_2 = require("../sandbox/client/client.gen.js");
8
9
  const settings_js_1 = require("./settings.js");
9
10
  client_gen_js_1.client.setConfig({
10
11
  baseUrl: settings_js_1.settings.baseUrl,
11
12
  });
13
+ // Register request interceptors
12
14
  for (const interceptor of interceptors_js_1.interceptors) {
13
15
  // @ts-expect-error - Interceptor is not typed
14
16
  client_gen_js_1.client.interceptors.request.use(interceptor);
15
17
  // @ts-expect-error - Interceptor is not typed
16
18
  client_gen_js_2.client.interceptors.request.use(interceptor);
17
19
  }
20
+ // Register response interceptors for authentication error handling
21
+ for (const interceptor of responseInterceptor_js_1.responseInterceptors) {
22
+ client_gen_js_1.client.interceptors.response.use(interceptor);
23
+ client_gen_js_2.client.interceptors.response.use(interceptor);
24
+ }
18
25
  // Allow to set custom configuration for browser environment
19
26
  function initialize(config) {
20
27
  settings_js_1.settings.setConfig(config);
@@ -10,7 +10,7 @@ function getPackageVersion() {
10
10
  if (typeof require !== "undefined") {
11
11
  // Try to require package.json (Node.js only, gracefully fails in browser)
12
12
  // eslint-disable-next-line @typescript-eslint/no-require-imports
13
- const packageJson = {"version":"0.2.49-preview.108","commit":"b8f2a000c36ca89ff78dbf1199a8e528929f4439"};
13
+ const packageJson = {"version":"0.2.49-preview.110","commit":"8ae9567ca2664beae414afa4fd53190d8ccf4250"};
14
14
  return packageJson.version || "unknown";
15
15
  }
16
16
  else {
@@ -62,7 +62,7 @@ function getCommitHash() {
62
62
  if (typeof require !== "undefined") {
63
63
  // Try to require package.json and look for commit field (set during build)
64
64
  // eslint-disable-next-line @typescript-eslint/no-require-imports
65
- const packageJson = {"version":"0.2.49-preview.108","commit":"b8f2a000c36ca89ff78dbf1199a8e528929f4439"};
65
+ const packageJson = {"version":"0.2.49-preview.110","commit":"8ae9567ca2664beae414afa4fd53190d8ccf4250"};
66
66
  // Check for commit in various possible locations
67
67
  const commit = packageJson.commit || packageJson.buildInfo?.commit;
68
68
  if (commit) {
@@ -8,7 +8,7 @@ const index_js_1 = require("../client/index.js");
8
8
  // Multipart upload constants
9
9
  const MULTIPART_THRESHOLD = 5 * 1024 * 1024; // 5MB
10
10
  const CHUNK_SIZE = 5 * 1024 * 1024; // 5MB per part
11
- const MAX_PARALLEL_UPLOADS = 3; // Number of parallel part uploads
11
+ const MAX_PARALLEL_UPLOADS = 20; // Number of parallel part uploads
12
12
  class SandboxFileSystem extends action_js_1.SandboxAction {
13
13
  process;
14
14
  constructor(sandbox, process) {
@@ -304,7 +304,6 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
304
304
  // Multipart upload helper methods
305
305
  async initiateMultipartUpload(path, permissions = "0644") {
306
306
  path = this.formatPath(path);
307
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
308
307
  const { data } = await (0, index_js_1.postFilesystemMultipartInitiateByPath)({
309
308
  path: { path },
310
309
  body: { permissions },
@@ -315,7 +314,6 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
315
314
  return data;
316
315
  }
317
316
  async uploadPart(uploadId, partNumber, fileBlob) {
318
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
319
317
  const { data } = await (0, index_js_1.putFilesystemMultipartByUploadIdPart)({
320
318
  path: { uploadId },
321
319
  query: { partNumber },
@@ -327,7 +325,6 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
327
325
  return data;
328
326
  }
329
327
  async completeMultipartUpload(uploadId, parts) {
330
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
331
328
  const { data } = await (0, index_js_1.postFilesystemMultipartByUploadIdComplete)({
332
329
  path: { uploadId },
333
330
  body: { parts },
@@ -338,19 +335,17 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
338
335
  return data;
339
336
  }
340
337
  async abortMultipartUpload(uploadId) {
341
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
342
- await (0, index_js_1.deleteFilesystemMultipartByUploadIdAbort)({
338
+ const { data } = await (0, index_js_1.deleteFilesystemMultipartByUploadIdAbort)({
343
339
  path: { uploadId },
344
340
  baseUrl: this.url,
345
341
  client: this.client,
346
342
  throwOnError: true,
347
343
  });
344
+ return data;
348
345
  }
349
346
  async uploadWithMultipart(path, blob, permissions = "0644") {
350
347
  // Initiate multipart upload
351
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
352
348
  const initResponse = await this.initiateMultipartUpload(path, permissions);
353
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
354
349
  const uploadId = initResponse.uploadId;
355
350
  if (!uploadId) {
356
351
  throw new Error("Failed to get upload ID from initiate response");
@@ -367,26 +362,20 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
367
362
  const start = (partNumber - 1) * CHUNK_SIZE;
368
363
  const end = Math.min(start + CHUNK_SIZE, size);
369
364
  const chunk = blob.slice(start, end);
370
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
371
365
  batch.push(this.uploadPart(uploadId, partNumber, chunk));
372
366
  }
373
367
  // Wait for batch to complete
374
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
375
368
  const batchResults = await Promise.all(batch);
376
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
377
- parts.push(...batchResults.map((r) => ({ partNumber: r.partNumber, etag: r.etag })));
369
+ parts.push(...batchResults);
378
370
  }
379
371
  // Sort parts by partNumber to ensure correct order
380
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
381
372
  parts.sort((a, b) => (a.partNumber ?? 0) - (b.partNumber ?? 0));
382
373
  // Complete the upload
383
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
384
374
  return await this.completeMultipartUpload(uploadId, parts);
385
375
  }
386
376
  catch (error) {
387
377
  // Abort the upload on failure
388
378
  try {
389
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
390
379
  await this.abortMultipartUpload(uploadId);
391
380
  }
392
381
  catch (abortError) {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Response interceptor that enhances authentication error messages (401/403)
3
+ * with a link to the authentication documentation.
4
+ */
5
+ type ResponseInterceptor = (response: Response) => Promise<Response>;
6
+ /**
7
+ * Intercepts HTTP responses and adds authentication documentation
8
+ * to 401/403 error responses
9
+ */
10
+ export declare const authenticationErrorInterceptor: ResponseInterceptor;
11
+ export declare const responseInterceptors: ResponseInterceptor[];
12
+ export {};