@sandeshnaroj/api-engine 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.
@@ -0,0 +1,3 @@
1
+ import { Endpoint } from '../schemas/manifest';
2
+ import { RequestOptions } from '../core/types';
3
+ export declare const createRestAdapter: (baseUrl: string) => <T>(endpoint: Endpoint, options?: RequestOptions) => Promise<T>;
@@ -0,0 +1,29 @@
1
+ import { Endpoint } from '../schemas/manifest';
2
+ export declare class SocketManager {
3
+ private endpoint;
4
+ private url;
5
+ private socket;
6
+ private subscribers;
7
+ private retryCount;
8
+ private reconnectTimer;
9
+ private heartbeatTimer;
10
+ constructor(endpoint: {
11
+ path: string;
12
+ autoReconnect?: boolean;
13
+ maxRetries?: number;
14
+ pingInterval?: number;
15
+ }, url: string);
16
+ connect(): void;
17
+ private reconnect;
18
+ private startHeartbeat;
19
+ private stopHeartbeat;
20
+ subscribe(callback: (data: any) => void): () => void;
21
+ send(data: any): void;
22
+ close(): void;
23
+ }
24
+ export interface SocketConnection {
25
+ send: (data: any) => void;
26
+ subscribe: (callback: (data: any) => void) => () => void;
27
+ close: () => void;
28
+ }
29
+ export declare const createSocketAdapter: (baseUrl: string) => (endpoint: Endpoint) => SocketManager;
@@ -0,0 +1,11 @@
1
+ import { Endpoint } from '../schemas/manifest';
2
+ export interface WatchOptions {
3
+ headers?: Record<string, string>;
4
+ body?: any;
5
+ params?: Record<string, any>;
6
+ }
7
+ export interface SSEConnection {
8
+ subscribe: (callback: (data: any) => void) => () => void;
9
+ close: () => void;
10
+ }
11
+ export declare const createSSEAdapter: (baseUrl: string) => (endpoint: Endpoint, options?: WatchOptions) => SSEConnection;
@@ -0,0 +1,53 @@
1
+ import * as v from 'valibot';
2
+ export declare const EndpointSchema: v.VariantSchema<"protocol", [v.ObjectSchema<{
3
+ readonly protocol: v.LiteralSchema<"REST", undefined>;
4
+ readonly path: v.StringSchema<undefined>;
5
+ readonly method: v.PicklistSchema<["GET", "POST", "PUT", "DELETE"], undefined>;
6
+ readonly headers: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, {}>;
7
+ readonly options: v.OptionalSchema<v.ObjectSchema<{
8
+ readonly cache: v.OptionalSchema<v.PicklistSchema<["default", "no-store", "reload", "force-cache"], undefined>, undefined>;
9
+ readonly credentials: v.OptionalSchema<v.PicklistSchema<["include", "same-origin", "omit"], undefined>, undefined>;
10
+ }, undefined>, {}>;
11
+ readonly timeout: v.OptionalSchema<v.NumberSchema<undefined>, 5000>;
12
+ }, undefined>, v.ObjectSchema<{
13
+ readonly protocol: v.LiteralSchema<"WS", undefined>;
14
+ readonly path: v.StringSchema<undefined>;
15
+ readonly autoReconnect: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
16
+ readonly maxRetries: v.OptionalSchema<v.NumberSchema<undefined>, 5>;
17
+ readonly pingInterval: v.OptionalSchema<v.NumberSchema<undefined>, 30000>;
18
+ }, undefined>, v.ObjectSchema<{
19
+ readonly protocol: v.LiteralSchema<"SSE", undefined>;
20
+ readonly path: v.StringSchema<undefined>;
21
+ readonly method: v.OptionalSchema<v.PicklistSchema<["GET", "POST"], undefined>, "GET">;
22
+ readonly headers: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, {}>;
23
+ readonly eventType: v.OptionalSchema<v.StringSchema<undefined>, "message">;
24
+ }, undefined>], undefined>;
25
+ export declare const ManifestSchema: v.ObjectSchema<{
26
+ readonly version: v.StringSchema<undefined>;
27
+ readonly baseUrl: v.StringSchema<undefined>;
28
+ readonly endpoints: v.RecordSchema<v.StringSchema<undefined>, v.VariantSchema<"protocol", [v.ObjectSchema<{
29
+ readonly protocol: v.LiteralSchema<"REST", undefined>;
30
+ readonly path: v.StringSchema<undefined>;
31
+ readonly method: v.PicklistSchema<["GET", "POST", "PUT", "DELETE"], undefined>;
32
+ readonly headers: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, {}>;
33
+ readonly options: v.OptionalSchema<v.ObjectSchema<{
34
+ readonly cache: v.OptionalSchema<v.PicklistSchema<["default", "no-store", "reload", "force-cache"], undefined>, undefined>;
35
+ readonly credentials: v.OptionalSchema<v.PicklistSchema<["include", "same-origin", "omit"], undefined>, undefined>;
36
+ }, undefined>, {}>;
37
+ readonly timeout: v.OptionalSchema<v.NumberSchema<undefined>, 5000>;
38
+ }, undefined>, v.ObjectSchema<{
39
+ readonly protocol: v.LiteralSchema<"WS", undefined>;
40
+ readonly path: v.StringSchema<undefined>;
41
+ readonly autoReconnect: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
42
+ readonly maxRetries: v.OptionalSchema<v.NumberSchema<undefined>, 5>;
43
+ readonly pingInterval: v.OptionalSchema<v.NumberSchema<undefined>, 30000>;
44
+ }, undefined>, v.ObjectSchema<{
45
+ readonly protocol: v.LiteralSchema<"SSE", undefined>;
46
+ readonly path: v.StringSchema<undefined>;
47
+ readonly method: v.OptionalSchema<v.PicklistSchema<["GET", "POST"], undefined>, "GET">;
48
+ readonly headers: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, {}>;
49
+ readonly eventType: v.OptionalSchema<v.StringSchema<undefined>, "message">;
50
+ }, undefined>], undefined>, undefined>;
51
+ }, undefined>;
52
+ export type Manifest = v.InferOutput<typeof ManifestSchema>;
53
+ export type Endpoint = v.InferOutput<typeof EndpointSchema>;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@sandeshnaroj/api-engine",
3
+ "version": "1.0.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "A lightweight, protocol-agnostic API client designed to unify REST, Server-Sent Events (SSE), and WebSockets (WS)",
8
+ "main": "dist/index.cjs",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "homepage": "https://github.com/sandeshnaroju/api-engine#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/sandeshnaroju/api-engine/issues"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "test": "echo \"Error: no test specified\" && exit 1",
27
+ "dev": "vite",
28
+ "build": "vite build && tsc",
29
+ "prepublishOnly": "npm run build"
30
+ },
31
+ "keywords": [
32
+ "api",
33
+ "client",
34
+ "typescript",
35
+ "sse",
36
+ "websocket",
37
+ "rest",
38
+ "fetch",
39
+ "eventsource",
40
+ "axios"
41
+ ],
42
+ "sideEffects": false,
43
+ "author": "Naroju Sandesh",
44
+ "license": "Apache-2.0",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/sandeshnaroju/api-engine.git"
48
+ },
49
+ "dependencies": {
50
+ "@microsoft/fetch-event-source": "^2.0.1",
51
+ "axios": "^1.16.0",
52
+ "js-yaml": "^4.1.1",
53
+ "valibot": "^1.3.1"
54
+ },
55
+ "devDependencies": {
56
+ "@rollup/plugin-yaml": "^4.1.2",
57
+ "tsx": "^4.21.0",
58
+ "typescript": "^6.0.3",
59
+ "vite": "^8.0.10"
60
+ },
61
+ "engines": {
62
+ "node": ">=20.19.0"
63
+ },
64
+ "engineStrict": false
65
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ ### **APIEngine**
2
+
3
+ A lightweight, protocol-agnostic API client designed to unify REST, Server-Sent Events (SSE), and WebSockets (WS). It transforms your API manifest into a strongly-typed, easy-to-use communication layer for modern web applications.