@scryme/chat 2.91.43 → 2.91.76
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/custom-instance.d.ts +22 -2
- package/dist/custom-instance.js +109 -1
- package/dist/generated/v3-client.d.ts +2438 -1441
- package/dist/generated/v3-client.js +1795 -999
- package/dist/generated/v3-server.d.ts +315 -149
- package/dist/generated/v3-server.js +451 -202
- package/dist/sdk.d.ts +49 -49
- package/dist/sdk.js +207 -81
- package/package.json +1 -1
- package/src/__tests__/sdk-error.test.ts +229 -0
- package/src/__tests__/sdk.test.ts +41 -17
- package/src/custom-instance.ts +109 -2
- package/src/generated/v3-client.ts +4467 -2471
- package/src/generated/v3-server.ts +1156 -574
- package/src/sdk.ts +149 -70
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import { AxiosRequestConfig
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
export declare const setGlobalToken: (token: string | null) => void;
|
|
3
3
|
export declare const getGlobalToken: () => string | null;
|
|
4
|
+
/**
|
|
5
|
+
* Custom SDK Error class for meaningful, developer-friendly error messages and structured error details.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ScrymeSDKError extends Error {
|
|
8
|
+
readonly status?: number;
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
readonly data?: any;
|
|
11
|
+
readonly rawError?: any;
|
|
12
|
+
constructor(message: string, options?: {
|
|
13
|
+
status?: number;
|
|
14
|
+
code?: string;
|
|
15
|
+
data?: any;
|
|
16
|
+
rawError?: any;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export { ScrymeSDKError as ScrymeError };
|
|
20
|
+
/**
|
|
21
|
+
* Parses any error (AxiosError, Error, or unknown object) into a clean, meaningful ScrymeSDKError.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseSDKError(error: any): ScrymeSDKError;
|
|
4
24
|
export declare const AXIOS_INSTANCE: import("axios").AxiosInstance;
|
|
5
25
|
export declare const customInstance: <T>(config: AxiosRequestConfig, options?: AxiosRequestConfig) => Promise<T>;
|
|
6
|
-
export type ErrorType<Error> =
|
|
26
|
+
export type ErrorType<Error> = ScrymeSDKError;
|
|
7
27
|
export type BodyType<Body> = Body;
|
package/dist/custom-instance.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
1
16
|
var __assign = (this && this.__assign) || function () {
|
|
2
17
|
__assign = Object.assign || function(t) {
|
|
3
18
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -46,11 +61,100 @@ export var setGlobalToken = function (token) {
|
|
|
46
61
|
globalToken = token;
|
|
47
62
|
};
|
|
48
63
|
export var getGlobalToken = function () { return globalToken; };
|
|
64
|
+
/**
|
|
65
|
+
* Custom SDK Error class for meaningful, developer-friendly error messages and structured error details.
|
|
66
|
+
*/
|
|
67
|
+
var ScrymeSDKError = /** @class */ (function (_super) {
|
|
68
|
+
__extends(ScrymeSDKError, _super);
|
|
69
|
+
function ScrymeSDKError(message, options) {
|
|
70
|
+
var _newTarget = this.constructor;
|
|
71
|
+
var _this = _super.call(this, message) || this;
|
|
72
|
+
_this.name = 'ScrymeSDKError';
|
|
73
|
+
_this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
74
|
+
_this.code = options === null || options === void 0 ? void 0 : options.code;
|
|
75
|
+
_this.data = options === null || options === void 0 ? void 0 : options.data;
|
|
76
|
+
_this.rawError = options === null || options === void 0 ? void 0 : options.rawError;
|
|
77
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
return ScrymeSDKError;
|
|
81
|
+
}(Error));
|
|
82
|
+
export { ScrymeSDKError };
|
|
83
|
+
export { ScrymeSDKError as ScrymeError };
|
|
84
|
+
/**
|
|
85
|
+
* Parses any error (AxiosError, Error, or unknown object) into a clean, meaningful ScrymeSDKError.
|
|
86
|
+
*/
|
|
87
|
+
export function parseSDKError(error) {
|
|
88
|
+
if (error instanceof ScrymeSDKError) {
|
|
89
|
+
return error;
|
|
90
|
+
}
|
|
91
|
+
if (axios.isAxiosError(error)) {
|
|
92
|
+
var response = error.response;
|
|
93
|
+
var status_1 = response === null || response === void 0 ? void 0 : response.status;
|
|
94
|
+
var responseData = response === null || response === void 0 ? void 0 : response.data;
|
|
95
|
+
var code = error.code || (responseData && typeof responseData === 'object' ? responseData.code : undefined);
|
|
96
|
+
var message = void 0;
|
|
97
|
+
if (responseData) {
|
|
98
|
+
if (typeof responseData === 'string' && responseData.trim()) {
|
|
99
|
+
message = responseData;
|
|
100
|
+
}
|
|
101
|
+
else if (typeof responseData === 'object' && responseData !== null) {
|
|
102
|
+
if (Array.isArray(responseData.message)) {
|
|
103
|
+
message = responseData.message.filter(Boolean).join('; ');
|
|
104
|
+
}
|
|
105
|
+
else if (typeof responseData.message === 'string' && responseData.message.trim()) {
|
|
106
|
+
message = responseData.message;
|
|
107
|
+
}
|
|
108
|
+
else if (typeof responseData.error === 'string' && responseData.error.trim()) {
|
|
109
|
+
message = responseData.error;
|
|
110
|
+
}
|
|
111
|
+
else if (responseData.error && typeof responseData.error === 'object' && typeof responseData.error.message === 'string') {
|
|
112
|
+
message = responseData.error.message;
|
|
113
|
+
}
|
|
114
|
+
else if (typeof responseData.detail === 'string' && responseData.detail.trim()) {
|
|
115
|
+
message = responseData.detail;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!message) {
|
|
120
|
+
if (response === null || response === void 0 ? void 0 : response.statusText) {
|
|
121
|
+
message = "HTTP ".concat(status_1, ": ").concat(response.statusText);
|
|
122
|
+
}
|
|
123
|
+
else if (error.message && !error.message.startsWith('Request failed with status code')) {
|
|
124
|
+
message = error.message;
|
|
125
|
+
}
|
|
126
|
+
else if (status_1) {
|
|
127
|
+
message = "Request failed with status code ".concat(status_1);
|
|
128
|
+
}
|
|
129
|
+
else if (error.message) {
|
|
130
|
+
message = error.message;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
message = 'An unexpected error occurred during API request';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return new ScrymeSDKError(message, {
|
|
137
|
+
status: status_1,
|
|
138
|
+
code: code,
|
|
139
|
+
data: responseData,
|
|
140
|
+
rawError: error,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (error instanceof Error) {
|
|
144
|
+
return new ScrymeSDKError(error.message, {
|
|
145
|
+
rawError: error,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return new ScrymeSDKError(typeof error === 'string' ? error : 'An unexpected error occurred', {
|
|
149
|
+
rawError: error,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
49
152
|
export var AXIOS_INSTANCE = axios.create({
|
|
50
153
|
baseURL: getBaseURL(),
|
|
51
154
|
timeout: 10000,
|
|
52
155
|
withCredentials: true,
|
|
53
156
|
});
|
|
157
|
+
AXIOS_INSTANCE.interceptors.response.use(function (response) { return response; }, function (error) { return Promise.reject(parseSDKError(error)); });
|
|
54
158
|
AXIOS_INSTANCE.interceptors.request.use(function (config) {
|
|
55
159
|
if (!config.baseURL) {
|
|
56
160
|
config.baseURL = getBaseURL();
|
|
@@ -118,9 +222,13 @@ export var customInstance = function (config, options) {
|
|
|
118
222
|
var source = axios.CancelToken.source();
|
|
119
223
|
// Merge headers carefully so that options.headers does not overwrite config.headers completely
|
|
120
224
|
var mergedHeaders = __assign(__assign({}, config.headers), options === null || options === void 0 ? void 0 : options.headers);
|
|
121
|
-
var promise = AXIOS_INSTANCE(__assign(__assign(__assign({}, config), options), { headers: mergedHeaders, cancelToken: source.token }))
|
|
225
|
+
var promise = AXIOS_INSTANCE(__assign(__assign(__assign({}, config), options), { headers: mergedHeaders, cancelToken: source.token }))
|
|
226
|
+
.then(function (_a) {
|
|
122
227
|
var data = _a.data;
|
|
123
228
|
return data;
|
|
229
|
+
})
|
|
230
|
+
.catch(function (error) {
|
|
231
|
+
throw parseSDKError(error);
|
|
124
232
|
});
|
|
125
233
|
// @ts-ignore
|
|
126
234
|
promise.cancel = function () {
|