@blaxel/core 0.2.52-dev.9 → 0.2.52-preview.127

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.
Files changed (57) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/common/autoload.js +0 -3
  3. package/dist/cjs/common/settings.js +47 -13
  4. package/dist/cjs/common/webhook.js +101 -0
  5. package/dist/cjs/index.js +1 -0
  6. package/dist/cjs/sandbox/client/sdk.gen.js +1 -124
  7. package/dist/cjs/sandbox/filesystem/filesystem.js +1 -81
  8. package/dist/cjs/types/client/types.gen.d.ts +12 -0
  9. package/dist/cjs/types/common/settings.d.ts +1 -2
  10. package/dist/cjs/types/common/webhook.d.ts +89 -0
  11. package/dist/cjs/types/index.d.ts +1 -0
  12. package/dist/cjs/types/sandbox/client/sdk.gen.d.ts +1 -36
  13. package/dist/cjs/types/sandbox/client/types.gen.d.ts +0 -315
  14. package/dist/cjs/types/sandbox/filesystem/filesystem.d.ts +2 -5
  15. package/dist/cjs/types/sandbox/filesystem/types.d.ts +0 -20
  16. package/dist/cjs-browser/.tsbuildinfo +1 -1
  17. package/dist/cjs-browser/common/autoload.js +0 -3
  18. package/dist/cjs-browser/common/settings.js +47 -13
  19. package/dist/cjs-browser/common/webhook.js +101 -0
  20. package/dist/cjs-browser/index.js +1 -0
  21. package/dist/cjs-browser/sandbox/client/sdk.gen.js +1 -124
  22. package/dist/cjs-browser/sandbox/filesystem/filesystem.js +1 -81
  23. package/dist/cjs-browser/types/client/types.gen.d.ts +12 -0
  24. package/dist/cjs-browser/types/common/settings.d.ts +1 -2
  25. package/dist/cjs-browser/types/common/webhook.d.ts +89 -0
  26. package/dist/cjs-browser/types/index.d.ts +1 -0
  27. package/dist/cjs-browser/types/sandbox/client/sdk.gen.d.ts +1 -36
  28. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +0 -315
  29. package/dist/cjs-browser/types/sandbox/filesystem/filesystem.d.ts +2 -5
  30. package/dist/cjs-browser/types/sandbox/filesystem/types.d.ts +0 -20
  31. package/dist/esm/.tsbuildinfo +1 -1
  32. package/dist/esm/common/autoload.js +0 -3
  33. package/dist/esm/common/settings.js +47 -13
  34. package/dist/esm/common/webhook.js +97 -0
  35. package/dist/esm/index.js +1 -0
  36. package/dist/esm/sandbox/client/sdk.gen.js +0 -116
  37. package/dist/esm/sandbox/filesystem/filesystem.js +2 -82
  38. package/dist/esm-browser/.tsbuildinfo +1 -1
  39. package/dist/esm-browser/common/autoload.js +0 -3
  40. package/dist/esm-browser/common/settings.js +47 -13
  41. package/dist/esm-browser/common/webhook.js +97 -0
  42. package/dist/esm-browser/index.js +1 -0
  43. package/dist/esm-browser/sandbox/client/sdk.gen.js +0 -116
  44. package/dist/esm-browser/sandbox/filesystem/filesystem.js +2 -82
  45. package/package.json +5 -4
  46. package/dist/cjs/common/sentry.js +0 -219
  47. package/dist/cjs/common/version.js +0 -6
  48. package/dist/cjs/types/common/sentry.d.ts +0 -17
  49. package/dist/cjs/types/common/version.d.ts +0 -2
  50. package/dist/cjs-browser/common/sentry.js +0 -219
  51. package/dist/cjs-browser/common/version.js +0 -6
  52. package/dist/cjs-browser/types/common/sentry.d.ts +0 -17
  53. package/dist/cjs-browser/types/common/version.d.ts +0 -2
  54. package/dist/esm/common/sentry.js +0 -181
  55. package/dist/esm/common/version.js +0 -3
  56. package/dist/esm-browser/common/sentry.js +0 -181
  57. package/dist/esm-browser/common/version.js +0 -3
@@ -6,7 +6,6 @@ const client_gen_js_1 = require("../client/client.gen.js");
6
6
  const interceptors_js_1 = require("../client/interceptors.js");
7
7
  const responseInterceptor_js_1 = require("../client/responseInterceptor.js");
8
8
  const client_gen_js_2 = require("../sandbox/client/client.gen.js");
9
- const sentry_js_1 = require("./sentry.js");
10
9
  const settings_js_1 = require("./settings.js");
11
10
  client_gen_js_1.client.setConfig({
12
11
  baseUrl: settings_js_1.settings.baseUrl,
@@ -23,8 +22,6 @@ for (const interceptor of responseInterceptor_js_1.responseInterceptors) {
23
22
  client_gen_js_1.client.interceptors.response.use(interceptor);
24
23
  client_gen_js_2.client.interceptors.response.use(interceptor);
25
24
  }
26
- // Initialize Sentry for SDK error tracking immediately when module loads
27
- (0, sentry_js_1.initSentry)();
28
25
  // Allow to set custom configuration for browser environment
29
26
  function initialize(config) {
30
27
  settings_js_1.settings.setConfig(config);
@@ -3,10 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.settings = void 0;
4
4
  const index_js_1 = require("../authentication/index.js");
5
5
  const env_js_1 = require("../common/env.js");
6
- // Build info - these placeholders are replaced at build time by build:replace-imports
7
- const BUILD_VERSION = "0.2.52-dev.9";
8
- const BUILD_COMMIT = "106270f8890bd85e35e0f6b3f9701c0c6ad9b3cf";
9
- const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
6
+ // Function to get package version
7
+ function getPackageVersion() {
8
+ try {
9
+ // Check if require is available (CommonJS environment)
10
+ if (typeof require !== "undefined") {
11
+ // Try to require package.json (Node.js only, gracefully fails in browser)
12
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
13
+ const packageJson = {"version":"0.2.52-preview.127","commit":"4acd7b5efa6c9e04c5131f55e7a87029c4889b1d"};
14
+ return packageJson.version || "unknown";
15
+ }
16
+ else {
17
+ // ESM environment - return unknown
18
+ return "unknown";
19
+ }
20
+ }
21
+ catch {
22
+ // Fallback for browser environments or if require fails
23
+ return "unknown";
24
+ }
25
+ }
10
26
  // Function to get OS and architecture
11
27
  function getOsArch() {
12
28
  try {
@@ -39,9 +55,30 @@ function getOsArch() {
39
55
  }
40
56
  return "browser/unknown";
41
57
  }
58
+ // Function to get commit hash
59
+ function getCommitHash() {
60
+ try {
61
+ // Check if require is available (CommonJS environment)
62
+ if (typeof require !== "undefined") {
63
+ // Try to require package.json and look for commit field (set during build)
64
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
65
+ const packageJson = {"version":"0.2.52-preview.127","commit":"4acd7b5efa6c9e04c5131f55e7a87029c4889b1d"};
66
+ // Check for commit in various possible locations
67
+ const commit = packageJson.commit || packageJson.buildInfo?.commit;
68
+ if (commit) {
69
+ return commit.length > 7 ? commit.substring(0, 7) : commit;
70
+ }
71
+ }
72
+ }
73
+ catch {
74
+ // Fallback for browser environments or if require fails
75
+ }
76
+ return "unknown";
77
+ }
42
78
  class Settings {
43
79
  credentials;
44
80
  config;
81
+ _version = null;
45
82
  constructor() {
46
83
  this.credentials = (0, index_js_1.authentication)();
47
84
  this.config = {
@@ -96,21 +133,18 @@ class Settings {
96
133
  return this.credentials.token;
97
134
  }
98
135
  get version() {
99
- return BUILD_VERSION || "unknown";
100
- }
101
- get commit() {
102
- const commit = BUILD_COMMIT || "unknown";
103
- return commit.length > 7 ? commit.substring(0, 7) : commit;
104
- }
105
- get sentryDsn() {
106
- return BUILD_SENTRY_DSN || "";
136
+ if (this._version === null) {
137
+ this._version = getPackageVersion();
138
+ }
139
+ return this._version;
107
140
  }
108
141
  get headers() {
109
142
  const osArch = getOsArch();
143
+ const commitHash = getCommitHash();
110
144
  return {
111
145
  "x-blaxel-authorization": this.authorization,
112
146
  "x-blaxel-workspace": this.workspace || "",
113
- "User-Agent": `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${this.commit}`,
147
+ "User-Agent": `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${commitHash}`,
114
148
  };
115
149
  }
116
150
  get name() {
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyWebhookSignature = verifyWebhookSignature;
4
+ exports.verifyWebhookFromRequest = verifyWebhookFromRequest;
5
+ const crypto_1 = require("crypto");
6
+ /**
7
+ * Verify the HMAC-SHA256 signature of a webhook callback from async-sidecar
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { verifyWebhookSignature } from '@blaxel/core';
12
+ *
13
+ * // In your Express endpoint
14
+ * app.post('/webhook', express.text({ type: 'application/json' }), (req, res) => {
15
+ * const isValid = verifyWebhookSignature({
16
+ * body: req.body,
17
+ * signature: req.headers['x-blaxel-signature'] as string,
18
+ * secret: process.env.CALLBACK_SECRET!
19
+ * });
20
+ *
21
+ * if (!isValid) {
22
+ * return res.status(401).json({ error: 'Invalid signature' });
23
+ * }
24
+ *
25
+ * const data = JSON.parse(req.body);
26
+ * // Process callback...
27
+ * });
28
+ * ```
29
+ *
30
+ * @param options - Verification options
31
+ * @returns true if the signature is valid, false otherwise
32
+ */
33
+ function verifyWebhookSignature(options) {
34
+ const { body, signature, secret, timestamp, maxAge = 300 } = options;
35
+ if (!body || !signature || !secret) {
36
+ return false;
37
+ }
38
+ try {
39
+ // Verify timestamp if provided (prevents replay attacks)
40
+ if (timestamp) {
41
+ const requestTime = parseInt(timestamp, 10);
42
+ const currentTime = Math.floor(Date.now() / 1000);
43
+ const age = Math.abs(currentTime - requestTime);
44
+ if (isNaN(requestTime) || age > maxAge) {
45
+ return false;
46
+ }
47
+ }
48
+ // Extract hex signature from "sha256=<hex>" format
49
+ const expectedSignature = signature.replace('sha256=', '');
50
+ // Compute HMAC-SHA256 signature
51
+ const hmac = (0, crypto_1.createHmac)('sha256', secret);
52
+ hmac.update(body);
53
+ const computedSignature = hmac.digest('hex');
54
+ // Timing-safe comparison to prevent timing attacks
55
+ return (0, crypto_1.timingSafeEqual)(Buffer.from(expectedSignature, 'hex'), Buffer.from(computedSignature, 'hex'));
56
+ }
57
+ catch {
58
+ // Invalid signature format or other error
59
+ return false;
60
+ }
61
+ }
62
+ /**
63
+ * Helper to verify webhook from Express request object
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import { verifyWebhookFromRequest } from '@blaxel/core';
68
+ * import express from 'express';
69
+ *
70
+ * app.use(express.text({ type: 'application/json' }));
71
+ *
72
+ * app.post('/webhook', (req, res) => {
73
+ * if (!verifyWebhookFromRequest(req, process.env.CALLBACK_SECRET!)) {
74
+ * return res.status(401).json({ error: 'Invalid signature' });
75
+ * }
76
+ *
77
+ * const data = JSON.parse(req.body);
78
+ * console.log('Received callback:', data);
79
+ * res.json({ received: true });
80
+ * });
81
+ * ```
82
+ *
83
+ * @param request - Express request object (must use express.text() middleware)
84
+ * @param secret - The callback secret
85
+ * @param maxAge - Optional maximum age in seconds (default: 300)
86
+ * @returns true if the signature is valid, false otherwise
87
+ */
88
+ function verifyWebhookFromRequest(request, secret, maxAge) {
89
+ const signature = request.headers['x-blaxel-signature'];
90
+ const timestamp = request.headers['x-blaxel-timestamp'];
91
+ if (typeof signature !== 'string') {
92
+ return false;
93
+ }
94
+ return verifyWebhookSignature({
95
+ body: request.body,
96
+ signature,
97
+ secret,
98
+ timestamp: typeof timestamp === 'string' ? timestamp : undefined,
99
+ maxAge
100
+ });
101
+ }
@@ -24,6 +24,7 @@ __exportStar(require("./common/errors.js"), exports);
24
24
  __exportStar(require("./common/internal.js"), exports);
25
25
  __exportStar(require("./common/logger.js"), exports);
26
26
  __exportStar(require("./common/settings.js"), exports);
27
+ __exportStar(require("./common/webhook.js"), exports);
27
28
  __exportStar(require("./jobs/index.js"), exports);
28
29
  __exportStar(require("./mcp/index.js"), exports);
29
30
  __exportStar(require("./models/index.js"), exports);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // This file is auto-generated by @hey-api/openapi-ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getWs = exports.getWatchFilesystemByPath = exports.getProcessByIdentifierLogsStream = exports.getProcessByIdentifierLogs = exports.deleteProcessByIdentifierKill = exports.getProcessByIdentifier = exports.deleteProcessByIdentifier = exports.postProcess = exports.getProcess = exports.getNetworkProcessByPidPorts = exports.postNetworkProcessByPidMonitor = exports.deleteNetworkProcessByPidMonitor = exports.putFilesystemTreeByPath = exports.getFilesystemTreeByPath = exports.deleteFilesystemTreeByPath = exports.putFilesystemByPath = exports.getFilesystemByPath = exports.deleteFilesystemByPath = exports.getFilesystemSearchByPath = exports.postFilesystemMultipartInitiateByPath = exports.getFilesystemMultipartByUploadIdParts = exports.putFilesystemMultipartByUploadIdPart = exports.postFilesystemMultipartByUploadIdComplete = exports.deleteFilesystemMultipartByUploadIdAbort = exports.getFilesystemMultipart = exports.getFilesystemFindByPath = exports.getFilesystemContentSearchByPath = exports.getCodegenRerankingByPath = exports.putCodegenFastapplyByPath = exports.put = exports.post = exports.patch = exports.options = exports.get = exports.delete_ = void 0;
4
+ exports.getWatchFilesystemByPath = exports.getProcessByIdentifierLogsStream = exports.getProcessByIdentifierLogs = exports.deleteProcessByIdentifierKill = exports.getProcessByIdentifier = exports.deleteProcessByIdentifier = exports.postProcess = exports.getProcess = exports.getNetworkProcessByPidPorts = exports.postNetworkProcessByPidMonitor = exports.deleteNetworkProcessByPidMonitor = exports.putFilesystemByPath = exports.getFilesystemByPath = exports.deleteFilesystemByPath = exports.postFilesystemMultipartInitiateByPath = exports.getFilesystemMultipartByUploadIdParts = exports.putFilesystemMultipartByUploadIdPart = exports.postFilesystemMultipartByUploadIdComplete = exports.deleteFilesystemMultipartByUploadIdAbort = exports.getFilesystemMultipart = exports.getCodegenRerankingByPath = exports.putCodegenFastapplyByPath = exports.put = exports.post = exports.patch = exports.options = exports.get = exports.delete_ = void 0;
5
5
  const client_fetch_1 = require("@hey-api/client-fetch");
6
6
  const client_gen_1 = require("./client.gen");
7
7
  /**
@@ -175,40 +175,6 @@ const getCodegenRerankingByPath = (options) => {
175
175
  });
176
176
  };
177
177
  exports.getCodegenRerankingByPath = getCodegenRerankingByPath;
178
- /**
179
- * Search for text content in files
180
- * Searches for text content inside files using ripgrep. Returns matching lines with context.
181
- */
182
- const getFilesystemContentSearchByPath = (options) => {
183
- return (options.client ?? client_gen_1.client).get({
184
- security: [
185
- {
186
- scheme: 'bearer',
187
- type: 'http'
188
- }
189
- ],
190
- url: '/filesystem-content-search/{path}',
191
- ...options
192
- });
193
- };
194
- exports.getFilesystemContentSearchByPath = getFilesystemContentSearchByPath;
195
- /**
196
- * Find files and directories
197
- * Finds files and directories using the find command.
198
- */
199
- const getFilesystemFindByPath = (options) => {
200
- return (options.client ?? client_gen_1.client).get({
201
- security: [
202
- {
203
- scheme: 'bearer',
204
- type: 'http'
205
- }
206
- ],
207
- url: '/filesystem-find/{path}',
208
- ...options
209
- });
210
- };
211
- exports.getFilesystemFindByPath = getFilesystemFindByPath;
212
178
  /**
213
179
  * List multipart uploads
214
180
  * List all active multipart uploads
@@ -324,23 +290,6 @@ const postFilesystemMultipartInitiateByPath = (options) => {
324
290
  });
325
291
  };
326
292
  exports.postFilesystemMultipartInitiateByPath = postFilesystemMultipartInitiateByPath;
327
- /**
328
- * Fuzzy search for files and directories
329
- * Performs fuzzy search on filesystem paths using fuzzy matching algorithm. Optimized alternative to find and grep commands.
330
- */
331
- const getFilesystemSearchByPath = (options) => {
332
- return (options.client ?? client_gen_1.client).get({
333
- security: [
334
- {
335
- scheme: 'bearer',
336
- type: 'http'
337
- }
338
- ],
339
- url: '/filesystem-search/{path}',
340
- ...options
341
- });
342
- };
343
- exports.getFilesystemSearchByPath = getFilesystemSearchByPath;
344
293
  /**
345
294
  * Delete file or directory
346
295
  * Delete a file or directory
@@ -396,61 +345,6 @@ const putFilesystemByPath = (options) => {
396
345
  });
397
346
  };
398
347
  exports.putFilesystemByPath = putFilesystemByPath;
399
- /**
400
- * Delete directory tree
401
- * Delete a directory tree recursively
402
- */
403
- const deleteFilesystemTreeByPath = (options) => {
404
- return (options.client ?? client_gen_1.client).delete({
405
- security: [
406
- {
407
- scheme: 'bearer',
408
- type: 'http'
409
- }
410
- ],
411
- url: '/filesystem/tree/{path}',
412
- ...options
413
- });
414
- };
415
- exports.deleteFilesystemTreeByPath = deleteFilesystemTreeByPath;
416
- /**
417
- * Get directory tree
418
- * Get a recursive directory tree structure starting from the specified path
419
- */
420
- const getFilesystemTreeByPath = (options) => {
421
- return (options.client ?? client_gen_1.client).get({
422
- security: [
423
- {
424
- scheme: 'bearer',
425
- type: 'http'
426
- }
427
- ],
428
- url: '/filesystem/tree/{path}',
429
- ...options
430
- });
431
- };
432
- exports.getFilesystemTreeByPath = getFilesystemTreeByPath;
433
- /**
434
- * Create or update directory tree
435
- * Create or update multiple files within a directory tree structure
436
- */
437
- const putFilesystemTreeByPath = (options) => {
438
- return (options.client ?? client_gen_1.client).put({
439
- security: [
440
- {
441
- scheme: 'bearer',
442
- type: 'http'
443
- }
444
- ],
445
- url: '/filesystem/tree/{path}',
446
- ...options,
447
- headers: {
448
- 'Content-Type': 'application/json',
449
- ...options?.headers
450
- }
451
- });
452
- };
453
- exports.putFilesystemTreeByPath = putFilesystemTreeByPath;
454
348
  /**
455
349
  * Stop monitoring ports for a process
456
350
  * Stop monitoring for new ports opened by a process
@@ -646,20 +540,3 @@ const getWatchFilesystemByPath = (options) => {
646
540
  });
647
541
  };
648
542
  exports.getWatchFilesystemByPath = getWatchFilesystemByPath;
649
- /**
650
- * WebSocket endpoint
651
- * WebSocket endpoint for all sandbox operations
652
- */
653
- const getWs = (options) => {
654
- return (options?.client ?? client_gen_1.client).get({
655
- security: [
656
- {
657
- scheme: 'bearer',
658
- type: 'http'
659
- }
660
- ],
661
- url: '/ws',
662
- ...options
663
- });
664
- };
665
- exports.getWs = getWs;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SandboxFileSystem = void 0;
4
- const node_js_1 = require("../../common/node.js");
5
4
  const settings_js_1 = require("../../common/settings.js");
5
+ const node_js_1 = require("../../common/node.js");
6
6
  const action_js_1 = require("../action.js");
7
7
  const index_js_1 = require("../client/index.js");
8
8
  // Multipart upload constants
@@ -199,86 +199,6 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
199
199
  }
200
200
  return data;
201
201
  }
202
- async search(query, path = "/", options) {
203
- const formattedPath = this.formatPath(path);
204
- const queryParams = {};
205
- if (options?.maxResults !== undefined) {
206
- queryParams.maxResults = options.maxResults;
207
- }
208
- if (options?.patterns && options.patterns.length > 0) {
209
- queryParams.patterns = options.patterns.join(',');
210
- }
211
- if (options?.excludeDirs && options.excludeDirs.length > 0) {
212
- queryParams.excludeDirs = options.excludeDirs.join(',');
213
- }
214
- if (options?.excludeHidden !== undefined) {
215
- queryParams.excludeHidden = options.excludeHidden;
216
- }
217
- const result = await (0, index_js_1.getFilesystemSearchByPath)({
218
- path: { path: formattedPath },
219
- query: queryParams,
220
- baseUrl: this.url,
221
- client: this.client,
222
- });
223
- this.handleResponseError(result.response, result.data, result.error);
224
- return result.data;
225
- }
226
- async find(path, options) {
227
- const formattedPath = this.formatPath(path);
228
- const queryParams = {};
229
- if (options?.type) {
230
- queryParams.type = options.type;
231
- }
232
- if (options?.patterns && options.patterns.length > 0) {
233
- queryParams.patterns = options.patterns.join(',');
234
- }
235
- if (options?.maxResults !== undefined) {
236
- queryParams.maxResults = options.maxResults;
237
- }
238
- if (options?.excludeDirs && options.excludeDirs.length > 0) {
239
- queryParams.excludeDirs = options.excludeDirs.join(',');
240
- }
241
- if (options?.excludeHidden !== undefined) {
242
- queryParams.excludeHidden = options.excludeHidden;
243
- }
244
- const result = await (0, index_js_1.getFilesystemFindByPath)({
245
- path: { path: formattedPath },
246
- query: queryParams,
247
- baseUrl: this.url,
248
- client: this.client,
249
- });
250
- this.handleResponseError(result.response, result.data, result.error);
251
- return result.data;
252
- }
253
- async grep(query, path = "/", options) {
254
- const formattedPath = this.formatPath(path);
255
- const queryParams = {
256
- query,
257
- };
258
- if (options?.caseSensitive !== undefined) {
259
- queryParams.caseSensitive = options.caseSensitive;
260
- }
261
- if (options?.contextLines !== undefined) {
262
- queryParams.contextLines = options.contextLines;
263
- }
264
- if (options?.maxResults !== undefined) {
265
- queryParams.maxResults = options.maxResults;
266
- }
267
- if (options?.filePattern) {
268
- queryParams.filePattern = options.filePattern;
269
- }
270
- if (options?.excludeDirs && options.excludeDirs.length > 0) {
271
- queryParams.excludeDirs = options.excludeDirs.join(',');
272
- }
273
- const result = await (0, index_js_1.getFilesystemContentSearchByPath)({
274
- path: { path: formattedPath },
275
- query: queryParams,
276
- baseUrl: this.url,
277
- client: this.client,
278
- });
279
- this.handleResponseError(result.response, result.data, result.error);
280
- return result.data;
281
- }
282
202
  async cp(source, destination, { maxWait = 180000 } = {}) {
283
203
  let process = await this.process.exec({
284
204
  command: `cp -r ${source} ${destination}`,
@@ -2779,6 +2779,14 @@ export type TriggerConfiguration = {
2779
2779
  * The authentication type of the trigger
2780
2780
  */
2781
2781
  authenticationType?: string;
2782
+ /**
2783
+ * The callback secret for async triggers (auto-generated, encrypted)
2784
+ */
2785
+ callbackSecret?: string;
2786
+ /**
2787
+ * The callback URL for async triggers (optional)
2788
+ */
2789
+ callbackUrl?: string;
2782
2790
  /**
2783
2791
  * The path of the trigger
2784
2792
  */
@@ -2795,6 +2803,10 @@ export type TriggerConfiguration = {
2795
2803
  * The tasks configuration of the cronjob
2796
2804
  */
2797
2805
  tasks?: Array<TriggerConfigurationTask>;
2806
+ /**
2807
+ * The timeout in seconds for async triggers (max 900s, MK3 only)
2808
+ */
2809
+ timeout?: number;
2798
2810
  };
2799
2811
  /**
2800
2812
  * The tasks configuration of the cronjob
@@ -7,6 +7,7 @@ export type Config = {
7
7
  declare class Settings {
8
8
  credentials: Credentials;
9
9
  config: Config;
10
+ private _version;
10
11
  constructor();
11
12
  setConfig(config: Config): void;
12
13
  get env(): string;
@@ -16,8 +17,6 @@ declare class Settings {
16
17
  get authorization(): string;
17
18
  get token(): string;
18
19
  get version(): string;
19
- get commit(): string;
20
- get sentryDsn(): string;
21
20
  get headers(): Record<string, string>;
22
21
  get name(): string;
23
22
  get type(): string;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Webhook signature verification for async-sidecar callbacks
3
+ */
4
+ export interface WebhookVerificationOptions {
5
+ /**
6
+ * The raw request body as a string
7
+ */
8
+ body: string;
9
+ /**
10
+ * The X-Blaxel-Signature header value (format: "sha256=<hex_digest>")
11
+ */
12
+ signature: string;
13
+ /**
14
+ * The secret key used to sign the webhook (same as CALLBACK_SECRET in async-sidecar)
15
+ */
16
+ secret: string;
17
+ /**
18
+ * Optional: The X-Blaxel-Timestamp header value for replay attack prevention
19
+ */
20
+ timestamp?: string;
21
+ /**
22
+ * Optional: Maximum age of the webhook in seconds (default: 300 = 5 minutes)
23
+ */
24
+ maxAge?: number;
25
+ }
26
+ export interface AsyncSidecarCallback {
27
+ status_code: number;
28
+ response_body: string;
29
+ response_length: number;
30
+ timestamp: number;
31
+ }
32
+ /**
33
+ * Verify the HMAC-SHA256 signature of a webhook callback from async-sidecar
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { verifyWebhookSignature } from '@blaxel/core';
38
+ *
39
+ * // In your Express endpoint
40
+ * app.post('/webhook', express.text({ type: 'application/json' }), (req, res) => {
41
+ * const isValid = verifyWebhookSignature({
42
+ * body: req.body,
43
+ * signature: req.headers['x-blaxel-signature'] as string,
44
+ * secret: process.env.CALLBACK_SECRET!
45
+ * });
46
+ *
47
+ * if (!isValid) {
48
+ * return res.status(401).json({ error: 'Invalid signature' });
49
+ * }
50
+ *
51
+ * const data = JSON.parse(req.body);
52
+ * // Process callback...
53
+ * });
54
+ * ```
55
+ *
56
+ * @param options - Verification options
57
+ * @returns true if the signature is valid, false otherwise
58
+ */
59
+ export declare function verifyWebhookSignature(options: WebhookVerificationOptions): boolean;
60
+ /**
61
+ * Helper to verify webhook from Express request object
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * import { verifyWebhookFromRequest } from '@blaxel/core';
66
+ * import express from 'express';
67
+ *
68
+ * app.use(express.text({ type: 'application/json' }));
69
+ *
70
+ * app.post('/webhook', (req, res) => {
71
+ * if (!verifyWebhookFromRequest(req, process.env.CALLBACK_SECRET!)) {
72
+ * return res.status(401).json({ error: 'Invalid signature' });
73
+ * }
74
+ *
75
+ * const data = JSON.parse(req.body);
76
+ * console.log('Received callback:', data);
77
+ * res.json({ received: true });
78
+ * });
79
+ * ```
80
+ *
81
+ * @param request - Express request object (must use express.text() middleware)
82
+ * @param secret - The callback secret
83
+ * @param maxAge - Optional maximum age in seconds (default: 300)
84
+ * @returns true if the signature is valid, false otherwise
85
+ */
86
+ export declare function verifyWebhookFromRequest(request: {
87
+ body: string;
88
+ headers: Record<string, string | string[] | undefined>;
89
+ }, secret: string, maxAge?: number): boolean;
@@ -8,6 +8,7 @@ export * from "./common/errors.js";
8
8
  export * from "./common/internal.js";
9
9
  export * from "./common/logger.js";
10
10
  export * from "./common/settings.js";
11
+ export * from "./common/webhook.js";
11
12
  export * from "./jobs/index.js";
12
13
  export * from "./mcp/index.js";
13
14
  export * from "./models/index.js";