@blaxel/core 0.2.49-preview.109 → 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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/client/responseInterceptor.js +53 -0
- package/dist/cjs/common/autoload.js +7 -0
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/types/client/responseInterceptor.d.ts +12 -0
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/client/responseInterceptor.js +53 -0
- package/dist/cjs-browser/common/autoload.js +7 -0
- package/dist/cjs-browser/common/settings.js +2 -2
- package/dist/cjs-browser/types/client/responseInterceptor.d.ts +12 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/client/responseInterceptor.js +49 -0
- package/dist/esm/common/autoload.js +7 -0
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/client/responseInterceptor.js +49 -0
- package/dist/esm-browser/common/autoload.js +7 -0
- package/dist/esm-browser/common/settings.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response interceptor that enhances authentication error messages (401/403)
|
|
3
|
+
* with a link to the authentication documentation.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Intercepts HTTP responses and adds authentication documentation
|
|
7
|
+
* to 401/403 error responses
|
|
8
|
+
*/
|
|
9
|
+
export const authenticationErrorInterceptor = async (response) => {
|
|
10
|
+
// Only process authentication errors (401/403)
|
|
11
|
+
if (response.status !== 401 && response.status !== 403) {
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
// Clone the response so we can modify it
|
|
15
|
+
const clonedResponse = response.clone();
|
|
16
|
+
try {
|
|
17
|
+
// Read the original response body
|
|
18
|
+
const bodyText = await clonedResponse.text();
|
|
19
|
+
// Try to parse as JSON
|
|
20
|
+
let enhancedBody;
|
|
21
|
+
try {
|
|
22
|
+
const originalError = JSON.parse(bodyText);
|
|
23
|
+
// Create enhanced error with authentication documentation
|
|
24
|
+
const authError = {
|
|
25
|
+
...originalError,
|
|
26
|
+
documentation: "For more information on authentication, visit: https://docs.blaxel.ai/sdk-reference/introduction#how-authentication-works",
|
|
27
|
+
};
|
|
28
|
+
enhancedBody = JSON.stringify(authError);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// If not JSON, just append the documentation as text
|
|
32
|
+
enhancedBody = `${bodyText}\nFor more information on authentication, visit: https://docs.blaxel.ai/sdk-reference/introduction#how-authentication-works`;
|
|
33
|
+
}
|
|
34
|
+
// Create a new response with the enhanced body
|
|
35
|
+
return new Response(enhancedBody, {
|
|
36
|
+
status: response.status,
|
|
37
|
+
statusText: response.statusText,
|
|
38
|
+
headers: response.headers,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// If anything fails, return the original response
|
|
43
|
+
console.error("Error processing authentication error response:", error);
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export const responseInterceptors = [
|
|
48
|
+
authenticationErrorInterceptor,
|
|
49
|
+
];
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { client } from "../client/client.gen.js";
|
|
2
2
|
import { interceptors } from "../client/interceptors.js";
|
|
3
|
+
import { responseInterceptors } from "../client/responseInterceptor.js";
|
|
3
4
|
import { client as clientSandbox } from "../sandbox/client/client.gen.js";
|
|
4
5
|
import { settings } from "./settings.js";
|
|
5
6
|
client.setConfig({
|
|
6
7
|
baseUrl: settings.baseUrl,
|
|
7
8
|
});
|
|
9
|
+
// Register request interceptors
|
|
8
10
|
for (const interceptor of interceptors) {
|
|
9
11
|
// @ts-expect-error - Interceptor is not typed
|
|
10
12
|
client.interceptors.request.use(interceptor);
|
|
11
13
|
// @ts-expect-error - Interceptor is not typed
|
|
12
14
|
clientSandbox.interceptors.request.use(interceptor);
|
|
13
15
|
}
|
|
16
|
+
// Register response interceptors for authentication error handling
|
|
17
|
+
for (const interceptor of responseInterceptors) {
|
|
18
|
+
client.interceptors.response.use(interceptor);
|
|
19
|
+
clientSandbox.interceptors.response.use(interceptor);
|
|
20
|
+
}
|
|
14
21
|
// Allow to set custom configuration for browser environment
|
|
15
22
|
export function initialize(config) {
|
|
16
23
|
settings.setConfig(config);
|
|
@@ -7,7 +7,7 @@ function getPackageVersion() {
|
|
|
7
7
|
if (typeof require !== "undefined") {
|
|
8
8
|
// Try to require package.json (Node.js only, gracefully fails in browser)
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
-
const packageJson = {"version":"0.2.49-preview.
|
|
10
|
+
const packageJson = {"version":"0.2.49-preview.110","commit":"8ae9567ca2664beae414afa4fd53190d8ccf4250"};
|
|
11
11
|
return packageJson.version || "unknown";
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -59,7 +59,7 @@ function getCommitHash() {
|
|
|
59
59
|
if (typeof require !== "undefined") {
|
|
60
60
|
// Try to require package.json and look for commit field (set during build)
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
62
|
-
const packageJson = {"version":"0.2.49-preview.
|
|
62
|
+
const packageJson = {"version":"0.2.49-preview.110","commit":"8ae9567ca2664beae414afa4fd53190d8ccf4250"};
|
|
63
63
|
// Check for commit in various possible locations
|
|
64
64
|
const commit = packageJson.commit || packageJson.buildInfo?.commit;
|
|
65
65
|
if (commit) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/core",
|
|
3
|
-
"version": "0.2.49-preview.
|
|
3
|
+
"version": "0.2.49-preview.110",
|
|
4
4
|
"description": "Blaxel Core SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"vite": "^5.2.0",
|
|
75
75
|
"vitest": "^1.5.0"
|
|
76
76
|
},
|
|
77
|
-
"commit": "
|
|
77
|
+
"commit": "8ae9567ca2664beae414afa4fd53190d8ccf4250",
|
|
78
78
|
"scripts": {
|
|
79
79
|
"lint": "eslint src/",
|
|
80
80
|
"dev": "tsc --watch",
|