@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,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.
|
|
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.
|
|
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) {
|
|
@@ -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 {};
|