@eka-care/medassist-core 1.0.0
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/README.md +32 -0
- package/dist/Synapse.d.ts +131 -0
- package/dist/Synapse.d.ts.map +1 -0
- package/dist/Synapse.js +479 -0
- package/dist/connection/ConnectionFactory.d.ts +17 -0
- package/dist/connection/ConnectionFactory.d.ts.map +1 -0
- package/dist/connection/ConnectionFactory.js +28 -0
- package/dist/connection/Websocket.d.ts +61 -0
- package/dist/connection/Websocket.d.ts.map +1 -0
- package/dist/connection/Websocket.js +184 -0
- package/dist/constants/index.d.ts +17 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +28 -0
- package/dist/constants/types.d.ts +2 -0
- package/dist/constants/types.d.ts.map +1 -0
- package/dist/constants/types.js +2 -0
- package/dist/events/Events.d.ts +47 -0
- package/dist/events/Events.d.ts.map +1 -0
- package/dist/events/Events.js +46 -0
- package/dist/events/Incoming.d.ts +2 -0
- package/dist/events/Incoming.d.ts.map +1 -0
- package/dist/events/Incoming.js +2 -0
- package/dist/events/Outgoing.d.ts +2 -0
- package/dist/events/Outgoing.d.ts.map +1 -0
- package/dist/events/Outgoing.js +2 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +38 -0
- package/dist/events/types.d.ts +86 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +6 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/internal/Api/BaseResource.d.ts +35 -0
- package/dist/internal/Api/BaseResource.d.ts.map +1 -0
- package/dist/internal/Api/BaseResource.js +54 -0
- package/dist/internal/Api/HttpClient.d.ts +25 -0
- package/dist/internal/Api/HttpClient.d.ts.map +1 -0
- package/dist/internal/Api/HttpClient.js +131 -0
- package/dist/internal/Api/types.d.ts +7 -0
- package/dist/internal/Api/types.d.ts.map +1 -0
- package/dist/internal/Api/types.js +2 -0
- package/dist/internal/Error/Error.d.ts +97 -0
- package/dist/internal/Error/Error.d.ts.map +1 -0
- package/dist/internal/Error/Error.js +243 -0
- package/dist/internal/Error/types.d.ts +17 -0
- package/dist/internal/Error/types.d.ts.map +1 -0
- package/dist/internal/Error/types.js +12 -0
- package/dist/internal/connection/BaseConnection.d.ts +100 -0
- package/dist/internal/connection/BaseConnection.d.ts.map +1 -0
- package/dist/internal/connection/BaseConnection.js +138 -0
- package/dist/internal/connection/types.d.ts +43 -0
- package/dist/internal/connection/types.d.ts.map +1 -0
- package/dist/internal/connection/types.js +20 -0
- package/dist/internal/events/EventEmitter.d.ts +7 -0
- package/dist/internal/events/EventEmitter.d.ts.map +1 -0
- package/dist/internal/events/EventEmitter.js +27 -0
- package/dist/internal/store/index.d.ts +10 -0
- package/dist/internal/store/index.d.ts.map +1 -0
- package/dist/internal/store/index.js +9 -0
- package/dist/media/audio/Audio.d.ts +37 -0
- package/dist/media/audio/Audio.d.ts.map +1 -0
- package/dist/media/audio/Audio.js +310 -0
- package/dist/media/audio/types.d.ts +25 -0
- package/dist/media/audio/types.d.ts.map +1 -0
- package/dist/media/audio/types.js +10 -0
- package/dist/media/file/File.d.ts +54 -0
- package/dist/media/file/File.d.ts.map +1 -0
- package/dist/media/file/File.js +159 -0
- package/dist/messages/MessageManager.d.ts +79 -0
- package/dist/messages/MessageManager.d.ts.map +1 -0
- package/dist/messages/MessageManager.js +420 -0
- package/dist/messages/types.d.ts +74 -0
- package/dist/messages/types.d.ts.map +1 -0
- package/dist/messages/types.js +34 -0
- package/dist/resources/config/Config.d.ts +5 -0
- package/dist/resources/config/Config.d.ts.map +1 -0
- package/dist/resources/config/Config.js +5 -0
- package/dist/resources/index.d.ts +34 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +108 -0
- package/dist/resources/session/Session.d.ts +21 -0
- package/dist/resources/session/Session.d.ts.map +1 -0
- package/dist/resources/session/Session.js +39 -0
- package/dist/resources/session/types.d.ts +17 -0
- package/dist/resources/session/types.d.ts.map +1 -0
- package/dist/resources/session/types.js +8 -0
- package/dist/resources/types.d.ts +22 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +5 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +24 -0
- package/dist/utils/Error.d.ts +45 -0
- package/dist/utils/Error.d.ts.map +1 -0
- package/dist/utils/Error.js +114 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Synapse SDK - Main exports
|
|
4
|
+
* Medical Chatbot TypeScript SDK
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.SYNAPSE_MESSAGE_TYPES = exports.ErrorUtils = exports.ErrorType = exports.InternalServerError = exports.RateLimitError = exports.MethodNotAllowedError = exports.NotFoundError = exports.PermissionDeniedError = exports.UnauthorizedError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIUserAbortError = exports.APIError = exports.SynapseError = exports.HttpClient = exports.SYNAPSE_REALTIME_EVENTS = exports.MessageManager = exports.Session = exports.ResourceManager = exports.ConnectionType = exports.ConnectionFactory = exports.WebSocketConnection = exports.BaseConnection = exports.SynapseSDK = void 0;
|
|
22
|
+
// High-level API (Primary interface for most users)
|
|
23
|
+
var Synapse_1 = require("./Synapse");
|
|
24
|
+
Object.defineProperty(exports, "SynapseSDK", { enumerable: true, get: function () { return Synapse_1.SynapseSDK; } });
|
|
25
|
+
// Connection layer (for advanced usage)
|
|
26
|
+
var BaseConnection_1 = require("./internal/connection/BaseConnection");
|
|
27
|
+
Object.defineProperty(exports, "BaseConnection", { enumerable: true, get: function () { return BaseConnection_1.BaseConnection; } });
|
|
28
|
+
var Websocket_1 = require("./connection/Websocket");
|
|
29
|
+
Object.defineProperty(exports, "WebSocketConnection", { enumerable: true, get: function () { return Websocket_1.WebSocketConnection; } });
|
|
30
|
+
var ConnectionFactory_1 = require("./connection/ConnectionFactory");
|
|
31
|
+
Object.defineProperty(exports, "ConnectionFactory", { enumerable: true, get: function () { return ConnectionFactory_1.ConnectionFactory; } });
|
|
32
|
+
Object.defineProperty(exports, "ConnectionType", { enumerable: true, get: function () { return ConnectionFactory_1.ConnectionType; } });
|
|
33
|
+
__exportStar(require("./internal/connection/types"), exports);
|
|
34
|
+
// Resources layer (for advanced usage)
|
|
35
|
+
var resources_1 = require("./resources");
|
|
36
|
+
Object.defineProperty(exports, "ResourceManager", { enumerable: true, get: function () { return resources_1.ResourceManager; } });
|
|
37
|
+
__exportStar(require("./resources/types"), exports);
|
|
38
|
+
var Session_1 = require("./resources/session/Session");
|
|
39
|
+
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return Session_1.Session; } });
|
|
40
|
+
__exportStar(require("./resources/session/types"), exports);
|
|
41
|
+
// Message layer (for advanced usage)
|
|
42
|
+
var MessageManager_1 = require("./messages/MessageManager");
|
|
43
|
+
Object.defineProperty(exports, "MessageManager", { enumerable: true, get: function () { return MessageManager_1.MessageManager; } });
|
|
44
|
+
var types_1 = require("./messages/types");
|
|
45
|
+
Object.defineProperty(exports, "SYNAPSE_REALTIME_EVENTS", { enumerable: true, get: function () { return types_1.SYNAPSE_REALTIME_EVENTS; } });
|
|
46
|
+
// Core HTTP client (for advanced usage)
|
|
47
|
+
var HttpClient_1 = require("./internal/Api/HttpClient");
|
|
48
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_1.HttpClient; } });
|
|
49
|
+
// Error handling
|
|
50
|
+
var Error_1 = require("./internal/Error/Error");
|
|
51
|
+
Object.defineProperty(exports, "SynapseError", { enumerable: true, get: function () { return Error_1.SynapseError; } });
|
|
52
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return Error_1.APIError; } });
|
|
53
|
+
Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return Error_1.APIUserAbortError; } });
|
|
54
|
+
Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return Error_1.APIConnectionTimeoutError; } });
|
|
55
|
+
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return Error_1.BadRequestError; } });
|
|
56
|
+
Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return Error_1.UnauthorizedError; } });
|
|
57
|
+
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return Error_1.PermissionDeniedError; } });
|
|
58
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return Error_1.NotFoundError; } });
|
|
59
|
+
Object.defineProperty(exports, "MethodNotAllowedError", { enumerable: true, get: function () { return Error_1.MethodNotAllowedError; } });
|
|
60
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return Error_1.RateLimitError; } });
|
|
61
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return Error_1.InternalServerError; } });
|
|
62
|
+
var types_2 = require("./internal/Error/types");
|
|
63
|
+
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return types_2.ErrorType; } });
|
|
64
|
+
// Utilities
|
|
65
|
+
var Error_2 = require("./utils/Error");
|
|
66
|
+
Object.defineProperty(exports, "ErrorUtils", { enumerable: true, get: function () { return Error_2.ErrorUtils; } });
|
|
67
|
+
__exportStar(require("./media/audio/types"), exports);
|
|
68
|
+
var types_3 = require("./messages/types");
|
|
69
|
+
Object.defineProperty(exports, "SYNAPSE_MESSAGE_TYPES", { enumerable: true, get: function () { return types_3.SYNAPSE_MESSAGE_TYPES; } });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all resources
|
|
3
|
+
*/
|
|
4
|
+
import { HttpClient } from "./HttpClient";
|
|
5
|
+
import { type RequestOptions } from "./types";
|
|
6
|
+
export declare abstract class BaseResource {
|
|
7
|
+
protected client: HttpClient;
|
|
8
|
+
constructor(httpClient: HttpClient);
|
|
9
|
+
/**
|
|
10
|
+
* Helper method for making GET requests
|
|
11
|
+
*/
|
|
12
|
+
protected get<T>(path: string, params?: Record<string, string>, options?: RequestOptions): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Helper method for making POST requests
|
|
15
|
+
*/
|
|
16
|
+
protected post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Helper method for making PUT requests
|
|
19
|
+
*/
|
|
20
|
+
protected put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Helper method for making DELETE requests
|
|
23
|
+
*/
|
|
24
|
+
protected delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Helper method for making PATCH requests
|
|
27
|
+
*/
|
|
28
|
+
protected patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Build a path with parameters
|
|
31
|
+
* Example: buildPath('/sessions/:id', { id: '123' }) => '/sessions/123'
|
|
32
|
+
*/
|
|
33
|
+
protected buildPath(template: string, params: Record<string, string>): string;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=BaseResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseResource.d.ts","sourceRoot":"","sources":["../../../src/internal/Api/BaseResource.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,8BAAsB,YAAY;IAChC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;gBAEjB,UAAU,EAAE,UAAU;IAIlC;;OAEG;cACa,GAAG,CAAC,CAAC,EACnB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIb;;OAEG;cACa,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAI3F;;OAEG;cACa,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAI1F;;OAEG;cACa,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAI7E;;OAEG;cACa,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F;;;OAGG;IACH,SAAS,CAAC,SAAS,CACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM;CAOV"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all resources
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BaseResource = void 0;
|
|
7
|
+
class BaseResource {
|
|
8
|
+
client;
|
|
9
|
+
constructor(httpClient) {
|
|
10
|
+
this.client = httpClient;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Helper method for making GET requests
|
|
14
|
+
*/
|
|
15
|
+
async get(path, params, options) {
|
|
16
|
+
return this.client.get(path, params, options);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Helper method for making POST requests
|
|
20
|
+
*/
|
|
21
|
+
async post(path, body, options) {
|
|
22
|
+
return this.client.post(path, body, options);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Helper method for making PUT requests
|
|
26
|
+
*/
|
|
27
|
+
async put(path, body, options) {
|
|
28
|
+
return this.client.put(path, body, options);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Helper method for making DELETE requests
|
|
32
|
+
*/
|
|
33
|
+
async delete(path, options) {
|
|
34
|
+
return this.client.delete(path, options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Helper method for making PATCH requests
|
|
38
|
+
*/
|
|
39
|
+
async patch(path, body, options) {
|
|
40
|
+
return this.client.patch(path, body, options);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build a path with parameters
|
|
44
|
+
* Example: buildPath('/sessions/:id', { id: '123' }) => '/sessions/123'
|
|
45
|
+
*/
|
|
46
|
+
buildPath(template, params) {
|
|
47
|
+
let path = template;
|
|
48
|
+
for (const [key, value] of Object.entries(params)) {
|
|
49
|
+
path = path.replace(`:${key}`, encodeURIComponent(value));
|
|
50
|
+
}
|
|
51
|
+
return path;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.BaseResource = BaseResource;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RequestOptions } from "./types";
|
|
2
|
+
export interface HttpClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
authorization?: string;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export declare class HttpClient {
|
|
11
|
+
private baseUrl;
|
|
12
|
+
private headers;
|
|
13
|
+
private timeout;
|
|
14
|
+
private maxRetries;
|
|
15
|
+
constructor(config: HttpClientConfig);
|
|
16
|
+
private request;
|
|
17
|
+
get<T>(path: string, params?: Record<string, string>, options?: RequestOptions): Promise<T>;
|
|
18
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
19
|
+
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
20
|
+
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
21
|
+
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
22
|
+
private buildUrl;
|
|
23
|
+
private handleError;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../src/internal/Api/HttpClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AACD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,gBAAgB;YAatB,OAAO;IAmGf,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIP,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIP,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIP,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAI7D,KAAK,CAAC,CAAC,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIb,OAAO,CAAC,QAAQ;YAUF,WAAW;CAqB1B"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const Error_1 = require("../Error/Error");
|
|
5
|
+
class HttpClient {
|
|
6
|
+
baseUrl;
|
|
7
|
+
headers;
|
|
8
|
+
timeout;
|
|
9
|
+
maxRetries;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, ""); // Remove trailing slash
|
|
12
|
+
this.timeout = config.timeout || 30000;
|
|
13
|
+
this.maxRetries = config.maxRetries || 3;
|
|
14
|
+
this.headers = {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
...config.headers, // Include custom headers
|
|
17
|
+
};
|
|
18
|
+
if (config.authorization) {
|
|
19
|
+
this.headers["Authorization"] = config.authorization;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async request(method, path, options) {
|
|
23
|
+
const maxRetries = options?.retries ?? this.maxRetries;
|
|
24
|
+
let lastError;
|
|
25
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
26
|
+
try {
|
|
27
|
+
const url = this.buildUrl(path, options?.params);
|
|
28
|
+
const response = await fetch(url, {
|
|
29
|
+
method,
|
|
30
|
+
headers: {
|
|
31
|
+
...this.headers,
|
|
32
|
+
...options?.headers,
|
|
33
|
+
},
|
|
34
|
+
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
35
|
+
signal: AbortSignal.timeout(this.timeout),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
await this.handleError(response);
|
|
39
|
+
}
|
|
40
|
+
return response.json();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
lastError = error;
|
|
44
|
+
// Don't retry on the last attempt
|
|
45
|
+
if (attempt === maxRetries) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
// Only retry on network errors and timeouts
|
|
49
|
+
const shouldRetry = (error instanceof TypeError && error.message === "Failed to fetch") ||
|
|
50
|
+
(error instanceof DOMException && error.name === "AbortError") ||
|
|
51
|
+
error instanceof SyntaxError;
|
|
52
|
+
if (!shouldRetry) {
|
|
53
|
+
// Don't retry for API errors (4xx, 5xx), parsing errors, etc.
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
// Exponential backoff: wait 2^attempt * 100ms
|
|
57
|
+
const delay = Math.pow(2, attempt) * 100;
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// If we get here, all retries failed
|
|
62
|
+
if (!lastError) {
|
|
63
|
+
throw new Error_1.APIError("Unknown error occurred", 500, {
|
|
64
|
+
type: "UNKNOWN_ERROR",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (lastError instanceof TypeError &&
|
|
68
|
+
lastError.message === "Failed to fetch") {
|
|
69
|
+
// Network error - no internet, DNS failure, etc.
|
|
70
|
+
throw new Error_1.APIError("Network error: Unable to connect to the server. Please check your internet connection.", 0, { type: "NETWORK_ERROR", originalError: lastError.message });
|
|
71
|
+
}
|
|
72
|
+
if (lastError instanceof DOMException && lastError.name === "AbortError") {
|
|
73
|
+
// Timeout error
|
|
74
|
+
throw new Error_1.APIConnectionTimeoutError({
|
|
75
|
+
message: `Request timed out after ${this.timeout}ms`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (lastError instanceof SyntaxError) {
|
|
79
|
+
// JSON parsing error
|
|
80
|
+
throw new Error_1.APIError("Invalid response format from server", 502, {
|
|
81
|
+
type: "PARSE_ERROR",
|
|
82
|
+
originalError: lastError.message,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// If it's already an APIError, re-throw it
|
|
86
|
+
if (lastError instanceof Error_1.APIError) {
|
|
87
|
+
throw lastError;
|
|
88
|
+
}
|
|
89
|
+
// Any other unexpected error
|
|
90
|
+
throw new Error_1.APIError(`Request failed: ${lastError.message || "Unknown error"}`, 500, { type: "UNKNOWN_ERROR", originalError: lastError });
|
|
91
|
+
}
|
|
92
|
+
async get(path, params, options) {
|
|
93
|
+
return this.request("GET", path, { params, ...options });
|
|
94
|
+
}
|
|
95
|
+
async post(path, body, options) {
|
|
96
|
+
return this.request("POST", path, { body, ...options });
|
|
97
|
+
}
|
|
98
|
+
async put(path, body, options) {
|
|
99
|
+
return this.request("PUT", path, { body, ...options });
|
|
100
|
+
}
|
|
101
|
+
async delete(path, options) {
|
|
102
|
+
return this.request("DELETE", path, { ...options });
|
|
103
|
+
}
|
|
104
|
+
async patch(path, body, options) {
|
|
105
|
+
return this.request("PATCH", path, { body, ...options });
|
|
106
|
+
}
|
|
107
|
+
buildUrl(path, params) {
|
|
108
|
+
let url = `${this.baseUrl}${path}`;
|
|
109
|
+
if (params) {
|
|
110
|
+
const queryString = new URLSearchParams(params).toString();
|
|
111
|
+
url += `?${queryString}`;
|
|
112
|
+
}
|
|
113
|
+
return url;
|
|
114
|
+
}
|
|
115
|
+
async handleError(response) {
|
|
116
|
+
let errorMessage;
|
|
117
|
+
let errorData;
|
|
118
|
+
try {
|
|
119
|
+
errorData = await response.json();
|
|
120
|
+
errorMessage =
|
|
121
|
+
errorData.message ||
|
|
122
|
+
errorData?.msg ||
|
|
123
|
+
response.statusText;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
errorMessage = response.statusText;
|
|
127
|
+
}
|
|
128
|
+
throw Error_1.APIError.generate(response.status, errorData, errorMessage, response.headers);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/internal/Api/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export declare const SynapseErrorCode: {
|
|
2
|
+
readonly API: "API_ERROR";
|
|
3
|
+
readonly CONNECTION: "CONNECTION_ERROR";
|
|
4
|
+
readonly RECORDING: "RECORDING_ERROR";
|
|
5
|
+
readonly FILE: "FILE_ERROR";
|
|
6
|
+
readonly SESSION: "SESSION_ERROR";
|
|
7
|
+
readonly MESSAGE: "MESSAGE_ERROR";
|
|
8
|
+
readonly STORE: "STORE_ERROR";
|
|
9
|
+
readonly CONFIGURATION: "CONFIGURATION_ERROR";
|
|
10
|
+
readonly VALIDATION: "VALIDATION_ERROR";
|
|
11
|
+
readonly AUTH: "AUTH_ERROR";
|
|
12
|
+
readonly UNKNOWN: "UNKNOWN_ERROR";
|
|
13
|
+
};
|
|
14
|
+
export type SynapseErrorCode = (typeof SynapseErrorCode)[keyof typeof SynapseErrorCode];
|
|
15
|
+
export interface SynapseErrorOptions {
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
context?: Record<string, unknown>;
|
|
18
|
+
hint?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SynapseError extends Error {
|
|
21
|
+
readonly code: SynapseErrorCode;
|
|
22
|
+
readonly timestamp: Date;
|
|
23
|
+
readonly cause?: unknown;
|
|
24
|
+
readonly context?: Record<string, unknown>;
|
|
25
|
+
readonly hint?: string;
|
|
26
|
+
constructor(message: string, code?: SynapseErrorCode, options?: SynapseErrorOptions);
|
|
27
|
+
}
|
|
28
|
+
export declare class APIError<TStatus extends number | undefined = number | undefined, THeader extends Headers | undefined = Headers | undefined, TError extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> extends SynapseError {
|
|
29
|
+
/** HTTP status code */
|
|
30
|
+
readonly status?: TStatus;
|
|
31
|
+
/** JSON body of the error response or custom error object */
|
|
32
|
+
readonly error?: TError;
|
|
33
|
+
/** HTTP response headers */
|
|
34
|
+
readonly headers?: THeader;
|
|
35
|
+
constructor(message: string, status?: TStatus, error?: TError, headers?: THeader);
|
|
36
|
+
private static makeMessage;
|
|
37
|
+
static generate(status: number | undefined, errorResponse: Record<string, unknown> | undefined, message?: string, headers?: Headers): APIError<number, Headers, Record<string, unknown>>;
|
|
38
|
+
}
|
|
39
|
+
export declare class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
|
40
|
+
constructor({ message }?: {
|
|
41
|
+
message?: string;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export declare class APIConnectionTimeoutError extends APIError<undefined, undefined, undefined> {
|
|
45
|
+
constructor({ message }?: {
|
|
46
|
+
message?: string;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export declare class BadRequestError extends APIError<400, Headers, Record<string, unknown>> {
|
|
50
|
+
constructor(message: string, status: 400, error?: Record<string, unknown>, headers?: Headers);
|
|
51
|
+
}
|
|
52
|
+
export declare class UnauthorizedError extends APIError<401, Headers, Record<string, unknown>> {
|
|
53
|
+
constructor(message: string, status: 401, error?: Record<string, unknown>, headers?: Headers);
|
|
54
|
+
}
|
|
55
|
+
export declare class PermissionDeniedError extends APIError<403, Headers, Record<string, unknown>> {
|
|
56
|
+
constructor(message: string, status: 403, error?: Record<string, unknown>, headers?: Headers);
|
|
57
|
+
}
|
|
58
|
+
export declare class NotFoundError extends APIError<404, Headers, Record<string, unknown>> {
|
|
59
|
+
constructor(message: string, status: 404, error?: Record<string, unknown>, headers?: Headers);
|
|
60
|
+
}
|
|
61
|
+
export declare class MethodNotAllowedError extends APIError<405, Headers, Record<string, unknown>> {
|
|
62
|
+
constructor(message: string, status: 405, error?: Record<string, unknown>, headers?: Headers);
|
|
63
|
+
}
|
|
64
|
+
export declare class RateLimitError extends APIError<429, Headers, Record<string, unknown>> {
|
|
65
|
+
constructor(message: string, status: 429, error?: Record<string, unknown>, headers?: Headers);
|
|
66
|
+
}
|
|
67
|
+
export declare class InternalServerError extends APIError<number, Headers, Record<string, unknown>> {
|
|
68
|
+
constructor(message: string, status: number, error?: Record<string, unknown>, headers?: Headers);
|
|
69
|
+
}
|
|
70
|
+
export declare class ConnectionError extends SynapseError {
|
|
71
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
72
|
+
}
|
|
73
|
+
export declare class RecordingError extends SynapseError {
|
|
74
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
75
|
+
}
|
|
76
|
+
export declare class FileError extends SynapseError {
|
|
77
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
78
|
+
}
|
|
79
|
+
export declare class SessionError extends SynapseError {
|
|
80
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
81
|
+
}
|
|
82
|
+
export declare class MessageError extends SynapseError {
|
|
83
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
84
|
+
}
|
|
85
|
+
export declare class StoreError extends SynapseError {
|
|
86
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
87
|
+
}
|
|
88
|
+
export declare class ConfigurationError extends SynapseError {
|
|
89
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
90
|
+
}
|
|
91
|
+
export declare class ValidationError extends SynapseError {
|
|
92
|
+
constructor(message: string, options?: SynapseErrorOptions);
|
|
93
|
+
}
|
|
94
|
+
type SynapseErrorCtor<T extends SynapseError> = new (message: string, options?: SynapseErrorOptions) => T;
|
|
95
|
+
export declare function normalizeError<T extends SynapseError>(error: unknown, ctor: SynapseErrorCtor<T>, fallbackMessage: string, options?: SynapseErrorOptions): T;
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=Error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../src/internal/Error/Error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAC1B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,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