@sovaria/sdk 0.0.0-stage → 0.5.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,146 @@
1
+ import type { Bucket, ColumnDefinition, DocumentGetResponse, DocumentPutResponse, DocumentScanResult, FunctionDeployResponse, FunctionInvokeResponse, NodeResponse, RealtimeCallback, RealtimeSubscription, SovariaClientOptions, StorageObject, TimelineJumpResponse, TimelineLogResponse, TokenResponse, UserProfile } from "./types.js";
2
+ /**
3
+ * Async TypeScript client for the Sovaria API Gateway.
4
+ *
5
+ * @deprecated Use {@link SovariaSDK} from `./index`. This legacy client is retained
6
+ * for in-repo tests only and is not a public package export.
7
+ *
8
+ * All requests flow through the gateway; engines are never called directly.
9
+ * Token refresh is automatic and transparent.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const sov = new SovariaClient("https://api.sovaria.in");
14
+ * await sov.auth.login("user@example.com", "password"); // deprecated; posts to /console/login
15
+ * sov.setContext("org-123", "proj-456");
16
+ *
17
+ * const rows = await sov.data.sql.query("SELECT * FROM users LIMIT 10");
18
+ * await sov.auth.logout();
19
+ * ```
20
+ */
21
+ export declare class SovariaClient {
22
+ private readonly baseUrl;
23
+ private accessToken;
24
+ private refreshToken;
25
+ private expiresAt;
26
+ private orgId;
27
+ private projectId;
28
+ private envId;
29
+ private refreshPromise;
30
+ private onTokenRefresh?;
31
+ readonly auth: AuthModule;
32
+ readonly org: OrgModule;
33
+ readonly data: DataModule;
34
+ readonly storage: StorageModule;
35
+ readonly functions: FunctionsModule;
36
+ readonly realtime: RealtimeModule;
37
+ readonly chrono: ChronoModule;
38
+ constructor(baseUrl: string, options?: SovariaClientOptions);
39
+ /**
40
+ * Bind org/project context for multi-tenant headers.
41
+ * These are injected as `X-Sovaria-Org-ID` and `X-Sovaria-Project-ID`
42
+ * on every subsequent request.
43
+ */
44
+ setContext(orgId: string, projectId: string, envId?: string): void;
45
+ clearContext(): void;
46
+ /** @internal */
47
+ _setTokens(tokens: TokenResponse): void;
48
+ /** @internal */
49
+ _clearTokens(): void;
50
+ /** @internal */
51
+ get _refreshToken(): string | null;
52
+ /** @internal */
53
+ get _isAuthenticated(): boolean;
54
+ /**
55
+ * Execute an HTTP request with automatic auth injection, token refresh, and
56
+ * exponential back-off with jitter on transient failures.
57
+ *
58
+ * @internal
59
+ */
60
+ _request<T = unknown>(method: string, path: string, options?: {
61
+ body?: unknown;
62
+ params?: Record<string, string>;
63
+ requiresAuth?: boolean;
64
+ headers?: Record<string, string>;
65
+ }): Promise<T>;
66
+ private ensureTokenFresh;
67
+ private doRefresh;
68
+ /**
69
+ * Build a WebSocket URL from the base URL, converting http(s) to ws(s).
70
+ * @internal
71
+ */
72
+ _wsUrl(path: string): string;
73
+ /** @internal */
74
+ _issueRealtimeWsTicket(channel: string): Promise<string>;
75
+ /** @internal */
76
+ get _accessToken(): string | null;
77
+ }
78
+ declare class AuthModule {
79
+ private readonly client;
80
+ constructor(client: SovariaClient);
81
+ login(email: string, password: string): Promise<TokenResponse>;
82
+ register(email: string, password: string, name: string): Promise<TokenResponse>;
83
+ logout(): Promise<void>;
84
+ me(): Promise<UserProfile>;
85
+ }
86
+ declare class OrgModule {
87
+ private readonly client;
88
+ constructor(client: SovariaClient);
89
+ list(): Promise<NodeResponse[]>;
90
+ get(id: string): Promise<NodeResponse>;
91
+ create(type: string, name: string, metadata?: Record<string, unknown>): Promise<NodeResponse>;
92
+ children(id: string): Promise<NodeResponse[]>;
93
+ }
94
+ declare class SqlSubmodule {
95
+ private readonly client;
96
+ constructor(client: SovariaClient);
97
+ createTable(tableName: string, columns: ColumnDefinition[]): Promise<Record<string, unknown>>;
98
+ query(sql: string, params?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
99
+ dropTable(name: string): Promise<Record<string, unknown>>;
100
+ }
101
+ declare class DocSubmodule {
102
+ private readonly client;
103
+ constructor(client: SovariaClient);
104
+ put(collection: string, key: string, data: Record<string, unknown>): Promise<DocumentPutResponse>;
105
+ get(collection: string, key: string): Promise<DocumentGetResponse>;
106
+ scan(collection: string, filter?: Record<string, unknown>): Promise<DocumentScanResult>;
107
+ }
108
+ declare class DataModule {
109
+ readonly sql: SqlSubmodule;
110
+ readonly doc: DocSubmodule;
111
+ constructor(client: SovariaClient);
112
+ }
113
+ declare class StorageModule {
114
+ private readonly client;
115
+ constructor(client: SovariaClient);
116
+ listBuckets(): Promise<Bucket[]>;
117
+ createBucket(name: string, isPublic?: boolean): Promise<Bucket>;
118
+ listObjects(bucket: string): Promise<StorageObject[]>;
119
+ uploadObject(bucket: string, path: string, body: string | Blob | ArrayBuffer | ReadableStream, contentType?: string): Promise<StorageObject>;
120
+ deleteObject(bucket: string, path: string): Promise<void>;
121
+ }
122
+ declare class FunctionsModule {
123
+ private readonly client;
124
+ constructor(client: SovariaClient);
125
+ deploy(name: string, code: string, runtime: string, entrypoint?: string): Promise<FunctionDeployResponse>;
126
+ invoke(name: string, payload?: unknown): Promise<FunctionInvokeResponse>;
127
+ }
128
+ declare class RealtimeModule {
129
+ private readonly client;
130
+ constructor(client: SovariaClient);
131
+ /**
132
+ * Subscribe to a realtime channel via WebSocket.
133
+ *
134
+ * Uses a short-lived ticket so JWTs are never placed in WebSocket URLs.
135
+ *
136
+ * Returns a subscription handle with an `unsubscribe()` method.
137
+ */
138
+ subscribe(channel: string, callback: RealtimeCallback): RealtimeSubscription;
139
+ }
140
+ declare class ChronoModule {
141
+ private readonly client;
142
+ constructor(client: SovariaClient);
143
+ log(timelineName: string): Promise<TimelineLogResponse>;
144
+ jump(timelineName: string, targetHex: string): Promise<TimelineJumpResponse>;
145
+ }
146
+ export {};