@anonfly/sdk 0.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 +19 -0
- package/dist/core/errors/AnonflyError.d.ts +19 -0
- package/dist/core/errors/AnonflyError.d.ts.map +1 -0
- package/dist/core/transport/HttpClient.d.ts +18 -0
- package/dist/core/transport/HttpClient.d.ts.map +1 -0
- package/dist/core/transport/WebSocketClient.d.ts +18 -0
- package/dist/core/transport/WebSocketClient.d.ts.map +1 -0
- package/dist/core/transport/retryMiddleware.d.ts +8 -0
- package/dist/core/transport/retryMiddleware.d.ts.map +1 -0
- package/dist/index.cjs +309 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +272 -0
- package/dist/resources/AuthResource.d.ts +23 -0
- package/dist/resources/AuthResource.d.ts.map +1 -0
- package/dist/resources/MessagesResource.d.ts +11 -0
- package/dist/resources/MessagesResource.d.ts.map +1 -0
- package/dist/resources/RoomsResource.d.ts +14 -0
- package/dist/resources/RoomsResource.d.ts.map +1 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @anonfly/sdk
|
|
2
|
+
|
|
3
|
+
Core SDK logic for the Anonfly service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @anonfly/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Type Safety:** Comprehensive TypeScript definitions for all API resources.
|
|
14
|
+
- **Middleware Support:** Extensible HTTP client with built-in retry logic.
|
|
15
|
+
- **Real-time:** Native WebSocket support for live message updates.
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class AnonflyError extends Error {
|
|
2
|
+
message: string;
|
|
3
|
+
code: string;
|
|
4
|
+
status?: number | undefined;
|
|
5
|
+
requestId?: string | undefined;
|
|
6
|
+
constructor(message: string, code?: string, status?: number | undefined, requestId?: string | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare class AuthenticationError extends AnonflyError {
|
|
9
|
+
constructor(message: string, status?: number, requestId?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class RateLimitError extends AnonflyError {
|
|
12
|
+
retryAfter?: number | undefined;
|
|
13
|
+
constructor(message: string, status?: number, requestId?: string, retryAfter?: number | undefined);
|
|
14
|
+
}
|
|
15
|
+
export declare class ValidationError extends AnonflyError {
|
|
16
|
+
details?: any | undefined;
|
|
17
|
+
constructor(message: string, details?: any | undefined);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=AnonflyError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnonflyError.d.ts","sourceRoot":"","sources":["../../../src/core/errors/AnonflyError.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IAExB,OAAO,EAAE,MAAM;IACf,IAAI,EAAE,MAAM;IACZ,MAAM,CAAC,EAAE,MAAM;IACf,SAAS,CAAC,EAAE,MAAM;gBAHlB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAsB,EAC5B,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,SAAS,CAAC,EAAE,MAAM,YAAA;CAMhC;AAED,qBAAa,mBAAoB,SAAQ,YAAY;gBACrC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAInE;AAED,qBAAa,cAAe,SAAQ,YAAY;IAC6B,UAAU,CAAC,EAAE,MAAM;gBAAhF,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAS,UAAU,CAAC,EAAE,MAAM,YAAA;CAI/F;AAED,qBAAa,eAAgB,SAAQ,YAAY;IACT,OAAO,CAAC,EAAE,GAAG;gBAArC,OAAO,EAAE,MAAM,EAAS,OAAO,CAAC,EAAE,GAAG,YAAA;CAIpD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type NextFunction = () => Promise<Response>;
|
|
2
|
+
export type Middleware = (request: Request, next: NextFunction) => Promise<Response>;
|
|
3
|
+
export interface HttpClientConfig {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare class HttpClient {
|
|
8
|
+
private config;
|
|
9
|
+
private middlewares;
|
|
10
|
+
constructor(config: HttpClientConfig);
|
|
11
|
+
use(middleware: Middleware): void;
|
|
12
|
+
request(path: string, options?: RequestInit): Promise<any>;
|
|
13
|
+
get(path: string, options?: RequestInit): Promise<any>;
|
|
14
|
+
post(path: string, body?: any, options?: RequestInit): Promise<any>;
|
|
15
|
+
put(path: string, body?: any, options?: RequestInit): Promise<any>;
|
|
16
|
+
delete(path: string, options?: RequestInit): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../src/core/transport/HttpClient.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;AACnD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAErF,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,qBAAa,UAAU;IAGP,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,WAAW,CAAoB;gBAEnB,MAAM,EAAE,gBAAgB;IAE5C,GAAG,CAAC,UAAU,EAAE,UAAU;IAIpB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,GAAG,CAAC;IA6CpE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;IAIvC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW;IAQpD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW;IAQnD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CAG7C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export interface WsConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
reconnect?: boolean;
|
|
5
|
+
reconnectInterval?: number;
|
|
6
|
+
maxRetries?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class WebSocketClient extends EventEmitter {
|
|
9
|
+
private config;
|
|
10
|
+
private ws;
|
|
11
|
+
private retryCount;
|
|
12
|
+
constructor(config: WsConfig);
|
|
13
|
+
connect(): void;
|
|
14
|
+
private reconnect;
|
|
15
|
+
send(data: any): void;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=WebSocketClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketClient.d.ts","sourceRoot":"","sources":["../../../src/core/transport/WebSocketClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,WAAW,QAAQ;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,eAAgB,SAAQ,YAAY;IAIjC,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,UAAU,CAAK;gBAEH,MAAM,EAAE,QAAQ;IAIpC,OAAO;IA6BP,OAAO,CAAC,SAAS;IAMjB,IAAI,CAAC,IAAI,EAAE,GAAG;IAQd,UAAU;CAMb"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Middleware } from './HttpClient.js';
|
|
2
|
+
export interface RetryOptions {
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
baseDelay?: number;
|
|
5
|
+
maxDelay?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const retryMiddleware: (options?: RetryOptions) => Middleware;
|
|
8
|
+
//# sourceMappingURL=retryMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryMiddleware.d.ts","sourceRoot":"","sources":["../../../src/core/transport/retryMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,WAAW,YAAY;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,eAAe,GAAI,UAAS,YAAiB,KAAG,UA8B5D,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Anonfly: () => Anonfly,
|
|
24
|
+
AnonflyError: () => AnonflyError,
|
|
25
|
+
AuthResource: () => AuthResource,
|
|
26
|
+
AuthenticationError: () => AuthenticationError,
|
|
27
|
+
HttpClient: () => HttpClient,
|
|
28
|
+
MessagesResource: () => MessagesResource,
|
|
29
|
+
RateLimitError: () => RateLimitError,
|
|
30
|
+
RoomsResource: () => RoomsResource,
|
|
31
|
+
ValidationError: () => ValidationError,
|
|
32
|
+
WebSocketClient: () => WebSocketClient,
|
|
33
|
+
retryMiddleware: () => retryMiddleware
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/resources/AuthResource.ts
|
|
38
|
+
var AuthResource = class {
|
|
39
|
+
constructor(http) {
|
|
40
|
+
this.http = http;
|
|
41
|
+
}
|
|
42
|
+
async generateChallenge(aid) {
|
|
43
|
+
return this.http.post("/auth/challenge", { aid });
|
|
44
|
+
}
|
|
45
|
+
async verify(input) {
|
|
46
|
+
return this.http.post("/auth/verify", input);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/core/errors/AnonflyError.ts
|
|
51
|
+
var AnonflyError = class _AnonflyError extends Error {
|
|
52
|
+
constructor(message, code = "ERR_UNKNOWN", status, requestId) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.message = message;
|
|
55
|
+
this.code = code;
|
|
56
|
+
this.status = status;
|
|
57
|
+
this.requestId = requestId;
|
|
58
|
+
this.name = "AnonflyError";
|
|
59
|
+
Object.setPrototypeOf(this, _AnonflyError.prototype);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var AuthenticationError = class extends AnonflyError {
|
|
63
|
+
constructor(message, status, requestId) {
|
|
64
|
+
super(message, "ERR_AUTHENTICATION", status, requestId);
|
|
65
|
+
this.name = "AuthenticationError";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var RateLimitError = class extends AnonflyError {
|
|
69
|
+
constructor(message, status, requestId, retryAfter) {
|
|
70
|
+
super(message, "ERR_RATE_LIMIT", status, requestId);
|
|
71
|
+
this.retryAfter = retryAfter;
|
|
72
|
+
this.name = "RateLimitError";
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var ValidationError = class extends AnonflyError {
|
|
76
|
+
constructor(message, details) {
|
|
77
|
+
super(message, "ERR_VALIDATION", 400);
|
|
78
|
+
this.details = details;
|
|
79
|
+
this.name = "ValidationError";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/core/transport/HttpClient.ts
|
|
84
|
+
var HttpClient = class {
|
|
85
|
+
constructor(config) {
|
|
86
|
+
this.config = config;
|
|
87
|
+
}
|
|
88
|
+
middlewares = [];
|
|
89
|
+
use(middleware) {
|
|
90
|
+
this.middlewares.push(middleware);
|
|
91
|
+
}
|
|
92
|
+
async request(path, options = {}) {
|
|
93
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
94
|
+
const headers = {
|
|
95
|
+
...this.config.headers,
|
|
96
|
+
...options.headers,
|
|
97
|
+
"Content-Type": "application/json"
|
|
98
|
+
};
|
|
99
|
+
const initialRequest = new Request(url, { ...options, headers });
|
|
100
|
+
const executeMiddleware = async (index, currentRequest) => {
|
|
101
|
+
if (index === this.middlewares.length) {
|
|
102
|
+
const response2 = await fetch(currentRequest);
|
|
103
|
+
return response2;
|
|
104
|
+
}
|
|
105
|
+
const next = async () => {
|
|
106
|
+
return executeMiddleware(index + 1, currentRequest);
|
|
107
|
+
};
|
|
108
|
+
return this.middlewares[index](currentRequest, next);
|
|
109
|
+
};
|
|
110
|
+
const response = await executeMiddleware(0, initialRequest);
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
let errorData;
|
|
113
|
+
try {
|
|
114
|
+
errorData = await response.json();
|
|
115
|
+
} catch {
|
|
116
|
+
errorData = { message: await response.text() };
|
|
117
|
+
}
|
|
118
|
+
throw new AnonflyError(
|
|
119
|
+
errorData.message || response.statusText,
|
|
120
|
+
errorData.code,
|
|
121
|
+
response.status,
|
|
122
|
+
response.headers.get("x-request-id") || void 0
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (response.status === 204) return null;
|
|
126
|
+
return response.json();
|
|
127
|
+
}
|
|
128
|
+
get(path, options) {
|
|
129
|
+
return this.request(path, { ...options, method: "GET" });
|
|
130
|
+
}
|
|
131
|
+
post(path, body, options) {
|
|
132
|
+
return this.request(path, {
|
|
133
|
+
...options,
|
|
134
|
+
method: "POST",
|
|
135
|
+
body: JSON.stringify(body)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
put(path, body, options) {
|
|
139
|
+
return this.request(path, {
|
|
140
|
+
...options,
|
|
141
|
+
method: "PUT",
|
|
142
|
+
body: JSON.stringify(body)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
delete(path, options) {
|
|
146
|
+
return this.request(path, { ...options, method: "DELETE" });
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/core/transport/WebSocketClient.ts
|
|
151
|
+
var import_events = require("events");
|
|
152
|
+
var import_ws = require("ws");
|
|
153
|
+
var WebSocketClient = class extends import_events.EventEmitter {
|
|
154
|
+
constructor(config) {
|
|
155
|
+
super();
|
|
156
|
+
this.config = config;
|
|
157
|
+
}
|
|
158
|
+
ws = null;
|
|
159
|
+
retryCount = 0;
|
|
160
|
+
connect() {
|
|
161
|
+
this.ws = new import_ws.WebSocket(this.config.url);
|
|
162
|
+
this.ws.on("open", () => {
|
|
163
|
+
this.retryCount = 0;
|
|
164
|
+
this.emit("connected");
|
|
165
|
+
});
|
|
166
|
+
this.ws.on("message", (data) => {
|
|
167
|
+
try {
|
|
168
|
+
const message = JSON.parse(data.toString());
|
|
169
|
+
this.emit("message", message);
|
|
170
|
+
} catch {
|
|
171
|
+
this.emit("message", data.toString());
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
this.ws.on("close", () => {
|
|
175
|
+
this.emit("disconnected");
|
|
176
|
+
if (this.config.reconnect && this.retryCount < (this.config.maxRetries || 10)) {
|
|
177
|
+
this.reconnect();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
this.ws.on("error", (error) => {
|
|
181
|
+
this.emit("error", error);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
reconnect() {
|
|
185
|
+
this.retryCount++;
|
|
186
|
+
const delay = (this.config.reconnectInterval || 1e3) * this.retryCount;
|
|
187
|
+
setTimeout(() => this.connect(), delay);
|
|
188
|
+
}
|
|
189
|
+
send(data) {
|
|
190
|
+
if (this.ws && this.ws.readyState === 1) {
|
|
191
|
+
this.ws.send(typeof data === "string" ? data : JSON.stringify(data));
|
|
192
|
+
} else {
|
|
193
|
+
throw new Error("WebSocket is not connected");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
disconnect() {
|
|
197
|
+
if (this.ws) {
|
|
198
|
+
this.ws.close();
|
|
199
|
+
this.ws = null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/core/transport/retryMiddleware.ts
|
|
205
|
+
var retryMiddleware = (options = {}) => {
|
|
206
|
+
const { maxRetries = 3, baseDelay = 1e3, maxDelay = 1e4 } = options;
|
|
207
|
+
return async (request, next) => {
|
|
208
|
+
let lastError;
|
|
209
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
210
|
+
try {
|
|
211
|
+
return await next();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
lastError = error;
|
|
214
|
+
if (attempt === maxRetries || error.status && error.status < 500 && error.status !== 429) {
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
const delay = Math.min(maxDelay, baseDelay * Math.pow(2, attempt));
|
|
218
|
+
const jitter = Math.random() * 100;
|
|
219
|
+
await new Promise((resolve) => setTimeout(resolve, delay + jitter));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
throw lastError;
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/resources/RoomsResource.ts
|
|
227
|
+
var RoomsResource = class {
|
|
228
|
+
constructor(http) {
|
|
229
|
+
this.http = http;
|
|
230
|
+
}
|
|
231
|
+
async list() {
|
|
232
|
+
return this.http.get("/rooms");
|
|
233
|
+
}
|
|
234
|
+
async create(data) {
|
|
235
|
+
return this.http.post("/rooms", data);
|
|
236
|
+
}
|
|
237
|
+
async get(id) {
|
|
238
|
+
return this.http.get(`/rooms/${id}`);
|
|
239
|
+
}
|
|
240
|
+
async join(id) {
|
|
241
|
+
return this.http.post(`/rooms/${id}/join`);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/resources/MessagesResource.ts
|
|
246
|
+
var MessagesResource = class {
|
|
247
|
+
constructor(http) {
|
|
248
|
+
this.http = http;
|
|
249
|
+
}
|
|
250
|
+
async list(roomId) {
|
|
251
|
+
return this.http.get(`/rooms/${roomId}/messages`);
|
|
252
|
+
}
|
|
253
|
+
async send(roomId, content) {
|
|
254
|
+
return this.http.post(`/rooms/${roomId}/messages`, { content });
|
|
255
|
+
}
|
|
256
|
+
async edit(messageId, content) {
|
|
257
|
+
return this.http.put(`/messages/${messageId}`, { content });
|
|
258
|
+
}
|
|
259
|
+
async delete(messageId) {
|
|
260
|
+
return this.http.delete(`/messages/${messageId}`);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/index.ts
|
|
265
|
+
var Anonfly = class {
|
|
266
|
+
constructor(config) {
|
|
267
|
+
this.config = config;
|
|
268
|
+
this.http = new HttpClient({
|
|
269
|
+
baseUrl: this.config.baseUrl,
|
|
270
|
+
headers: {
|
|
271
|
+
"X-API-Key": this.config.apiKey
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
if (this.config.retries !== 0) {
|
|
275
|
+
this.http.use(retryMiddleware({ maxRetries: this.config.retries }));
|
|
276
|
+
}
|
|
277
|
+
if (this.config.wsUrl) {
|
|
278
|
+
this.ws = new WebSocketClient({
|
|
279
|
+
url: this.config.wsUrl,
|
|
280
|
+
reconnect: true
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
http;
|
|
285
|
+
ws;
|
|
286
|
+
get rooms() {
|
|
287
|
+
return new RoomsResource(this.http);
|
|
288
|
+
}
|
|
289
|
+
get messages() {
|
|
290
|
+
return new MessagesResource(this.http);
|
|
291
|
+
}
|
|
292
|
+
get auth() {
|
|
293
|
+
return new AuthResource(this.http);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
297
|
+
0 && (module.exports = {
|
|
298
|
+
Anonfly,
|
|
299
|
+
AnonflyError,
|
|
300
|
+
AuthResource,
|
|
301
|
+
AuthenticationError,
|
|
302
|
+
HttpClient,
|
|
303
|
+
MessagesResource,
|
|
304
|
+
RateLimitError,
|
|
305
|
+
RoomsResource,
|
|
306
|
+
ValidationError,
|
|
307
|
+
WebSocketClient,
|
|
308
|
+
retryMiddleware
|
|
309
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AuthResource } from './resources/AuthResource';
|
|
2
|
+
import { HttpClient } from './core/transport/HttpClient';
|
|
3
|
+
import { WebSocketClient } from './core/transport/WebSocketClient';
|
|
4
|
+
import { RoomsResource } from './resources/RoomsResource';
|
|
5
|
+
import { MessagesResource } from './resources/MessagesResource';
|
|
6
|
+
export * from './types/index';
|
|
7
|
+
export * from './core/errors/AnonflyError';
|
|
8
|
+
export * from './core/transport/HttpClient';
|
|
9
|
+
export * from './core/transport/WebSocketClient';
|
|
10
|
+
export * from './core/transport/retryMiddleware';
|
|
11
|
+
export * from './resources/RoomsResource';
|
|
12
|
+
export * from './resources/MessagesResource';
|
|
13
|
+
export * from './resources/AuthResource';
|
|
14
|
+
export interface AnonflyConfig {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
wsUrl?: string;
|
|
18
|
+
retries?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class Anonfly {
|
|
21
|
+
private config;
|
|
22
|
+
http: HttpClient;
|
|
23
|
+
ws?: WebSocketClient;
|
|
24
|
+
constructor(config: AnonflyConfig);
|
|
25
|
+
get rooms(): RoomsResource;
|
|
26
|
+
get messages(): MessagesResource;
|
|
27
|
+
get auth(): AuthResource;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AAEzC,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,OAAO;IAIJ,OAAO,CAAC,MAAM;IAHnB,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,CAAC,EAAE,eAAe,CAAC;gBAER,MAAM,EAAE,aAAa;IAoBzC,IAAW,KAAK,kBAEf;IAED,IAAW,QAAQ,qBAElB;IAED,IAAW,IAAI,iBAEd;CACJ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// src/resources/AuthResource.ts
|
|
2
|
+
var AuthResource = class {
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
async generateChallenge(aid) {
|
|
7
|
+
return this.http.post("/auth/challenge", { aid });
|
|
8
|
+
}
|
|
9
|
+
async verify(input) {
|
|
10
|
+
return this.http.post("/auth/verify", input);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/core/errors/AnonflyError.ts
|
|
15
|
+
var AnonflyError = class _AnonflyError extends Error {
|
|
16
|
+
constructor(message, code = "ERR_UNKNOWN", status, requestId) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.message = message;
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.requestId = requestId;
|
|
22
|
+
this.name = "AnonflyError";
|
|
23
|
+
Object.setPrototypeOf(this, _AnonflyError.prototype);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var AuthenticationError = class extends AnonflyError {
|
|
27
|
+
constructor(message, status, requestId) {
|
|
28
|
+
super(message, "ERR_AUTHENTICATION", status, requestId);
|
|
29
|
+
this.name = "AuthenticationError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var RateLimitError = class extends AnonflyError {
|
|
33
|
+
constructor(message, status, requestId, retryAfter) {
|
|
34
|
+
super(message, "ERR_RATE_LIMIT", status, requestId);
|
|
35
|
+
this.retryAfter = retryAfter;
|
|
36
|
+
this.name = "RateLimitError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var ValidationError = class extends AnonflyError {
|
|
40
|
+
constructor(message, details) {
|
|
41
|
+
super(message, "ERR_VALIDATION", 400);
|
|
42
|
+
this.details = details;
|
|
43
|
+
this.name = "ValidationError";
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/core/transport/HttpClient.ts
|
|
48
|
+
var HttpClient = class {
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.config = config;
|
|
51
|
+
}
|
|
52
|
+
middlewares = [];
|
|
53
|
+
use(middleware) {
|
|
54
|
+
this.middlewares.push(middleware);
|
|
55
|
+
}
|
|
56
|
+
async request(path, options = {}) {
|
|
57
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
58
|
+
const headers = {
|
|
59
|
+
...this.config.headers,
|
|
60
|
+
...options.headers,
|
|
61
|
+
"Content-Type": "application/json"
|
|
62
|
+
};
|
|
63
|
+
const initialRequest = new Request(url, { ...options, headers });
|
|
64
|
+
const executeMiddleware = async (index, currentRequest) => {
|
|
65
|
+
if (index === this.middlewares.length) {
|
|
66
|
+
const response2 = await fetch(currentRequest);
|
|
67
|
+
return response2;
|
|
68
|
+
}
|
|
69
|
+
const next = async () => {
|
|
70
|
+
return executeMiddleware(index + 1, currentRequest);
|
|
71
|
+
};
|
|
72
|
+
return this.middlewares[index](currentRequest, next);
|
|
73
|
+
};
|
|
74
|
+
const response = await executeMiddleware(0, initialRequest);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
let errorData;
|
|
77
|
+
try {
|
|
78
|
+
errorData = await response.json();
|
|
79
|
+
} catch {
|
|
80
|
+
errorData = { message: await response.text() };
|
|
81
|
+
}
|
|
82
|
+
throw new AnonflyError(
|
|
83
|
+
errorData.message || response.statusText,
|
|
84
|
+
errorData.code,
|
|
85
|
+
response.status,
|
|
86
|
+
response.headers.get("x-request-id") || void 0
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (response.status === 204) return null;
|
|
90
|
+
return response.json();
|
|
91
|
+
}
|
|
92
|
+
get(path, options) {
|
|
93
|
+
return this.request(path, { ...options, method: "GET" });
|
|
94
|
+
}
|
|
95
|
+
post(path, body, options) {
|
|
96
|
+
return this.request(path, {
|
|
97
|
+
...options,
|
|
98
|
+
method: "POST",
|
|
99
|
+
body: JSON.stringify(body)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
put(path, body, options) {
|
|
103
|
+
return this.request(path, {
|
|
104
|
+
...options,
|
|
105
|
+
method: "PUT",
|
|
106
|
+
body: JSON.stringify(body)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
delete(path, options) {
|
|
110
|
+
return this.request(path, { ...options, method: "DELETE" });
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/core/transport/WebSocketClient.ts
|
|
115
|
+
import { EventEmitter } from "events";
|
|
116
|
+
import { WebSocket } from "ws";
|
|
117
|
+
var WebSocketClient = class extends EventEmitter {
|
|
118
|
+
constructor(config) {
|
|
119
|
+
super();
|
|
120
|
+
this.config = config;
|
|
121
|
+
}
|
|
122
|
+
ws = null;
|
|
123
|
+
retryCount = 0;
|
|
124
|
+
connect() {
|
|
125
|
+
this.ws = new WebSocket(this.config.url);
|
|
126
|
+
this.ws.on("open", () => {
|
|
127
|
+
this.retryCount = 0;
|
|
128
|
+
this.emit("connected");
|
|
129
|
+
});
|
|
130
|
+
this.ws.on("message", (data) => {
|
|
131
|
+
try {
|
|
132
|
+
const message = JSON.parse(data.toString());
|
|
133
|
+
this.emit("message", message);
|
|
134
|
+
} catch {
|
|
135
|
+
this.emit("message", data.toString());
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.ws.on("close", () => {
|
|
139
|
+
this.emit("disconnected");
|
|
140
|
+
if (this.config.reconnect && this.retryCount < (this.config.maxRetries || 10)) {
|
|
141
|
+
this.reconnect();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
this.ws.on("error", (error) => {
|
|
145
|
+
this.emit("error", error);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
reconnect() {
|
|
149
|
+
this.retryCount++;
|
|
150
|
+
const delay = (this.config.reconnectInterval || 1e3) * this.retryCount;
|
|
151
|
+
setTimeout(() => this.connect(), delay);
|
|
152
|
+
}
|
|
153
|
+
send(data) {
|
|
154
|
+
if (this.ws && this.ws.readyState === 1) {
|
|
155
|
+
this.ws.send(typeof data === "string" ? data : JSON.stringify(data));
|
|
156
|
+
} else {
|
|
157
|
+
throw new Error("WebSocket is not connected");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
disconnect() {
|
|
161
|
+
if (this.ws) {
|
|
162
|
+
this.ws.close();
|
|
163
|
+
this.ws = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/core/transport/retryMiddleware.ts
|
|
169
|
+
var retryMiddleware = (options = {}) => {
|
|
170
|
+
const { maxRetries = 3, baseDelay = 1e3, maxDelay = 1e4 } = options;
|
|
171
|
+
return async (request, next) => {
|
|
172
|
+
let lastError;
|
|
173
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
174
|
+
try {
|
|
175
|
+
return await next();
|
|
176
|
+
} catch (error) {
|
|
177
|
+
lastError = error;
|
|
178
|
+
if (attempt === maxRetries || error.status && error.status < 500 && error.status !== 429) {
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
const delay = Math.min(maxDelay, baseDelay * Math.pow(2, attempt));
|
|
182
|
+
const jitter = Math.random() * 100;
|
|
183
|
+
await new Promise((resolve) => setTimeout(resolve, delay + jitter));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
throw lastError;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/resources/RoomsResource.ts
|
|
191
|
+
var RoomsResource = class {
|
|
192
|
+
constructor(http) {
|
|
193
|
+
this.http = http;
|
|
194
|
+
}
|
|
195
|
+
async list() {
|
|
196
|
+
return this.http.get("/rooms");
|
|
197
|
+
}
|
|
198
|
+
async create(data) {
|
|
199
|
+
return this.http.post("/rooms", data);
|
|
200
|
+
}
|
|
201
|
+
async get(id) {
|
|
202
|
+
return this.http.get(`/rooms/${id}`);
|
|
203
|
+
}
|
|
204
|
+
async join(id) {
|
|
205
|
+
return this.http.post(`/rooms/${id}/join`);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/resources/MessagesResource.ts
|
|
210
|
+
var MessagesResource = class {
|
|
211
|
+
constructor(http) {
|
|
212
|
+
this.http = http;
|
|
213
|
+
}
|
|
214
|
+
async list(roomId) {
|
|
215
|
+
return this.http.get(`/rooms/${roomId}/messages`);
|
|
216
|
+
}
|
|
217
|
+
async send(roomId, content) {
|
|
218
|
+
return this.http.post(`/rooms/${roomId}/messages`, { content });
|
|
219
|
+
}
|
|
220
|
+
async edit(messageId, content) {
|
|
221
|
+
return this.http.put(`/messages/${messageId}`, { content });
|
|
222
|
+
}
|
|
223
|
+
async delete(messageId) {
|
|
224
|
+
return this.http.delete(`/messages/${messageId}`);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/index.ts
|
|
229
|
+
var Anonfly = class {
|
|
230
|
+
constructor(config) {
|
|
231
|
+
this.config = config;
|
|
232
|
+
this.http = new HttpClient({
|
|
233
|
+
baseUrl: this.config.baseUrl,
|
|
234
|
+
headers: {
|
|
235
|
+
"X-API-Key": this.config.apiKey
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
if (this.config.retries !== 0) {
|
|
239
|
+
this.http.use(retryMiddleware({ maxRetries: this.config.retries }));
|
|
240
|
+
}
|
|
241
|
+
if (this.config.wsUrl) {
|
|
242
|
+
this.ws = new WebSocketClient({
|
|
243
|
+
url: this.config.wsUrl,
|
|
244
|
+
reconnect: true
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
http;
|
|
249
|
+
ws;
|
|
250
|
+
get rooms() {
|
|
251
|
+
return new RoomsResource(this.http);
|
|
252
|
+
}
|
|
253
|
+
get messages() {
|
|
254
|
+
return new MessagesResource(this.http);
|
|
255
|
+
}
|
|
256
|
+
get auth() {
|
|
257
|
+
return new AuthResource(this.http);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
export {
|
|
261
|
+
Anonfly,
|
|
262
|
+
AnonflyError,
|
|
263
|
+
AuthResource,
|
|
264
|
+
AuthenticationError,
|
|
265
|
+
HttpClient,
|
|
266
|
+
MessagesResource,
|
|
267
|
+
RateLimitError,
|
|
268
|
+
RoomsResource,
|
|
269
|
+
ValidationError,
|
|
270
|
+
WebSocketClient,
|
|
271
|
+
retryMiddleware
|
|
272
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
|
+
export interface VerifyIdentityInput {
|
|
3
|
+
aid: string;
|
|
4
|
+
signature: string;
|
|
5
|
+
username: string;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
exchangePublicKey: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AuthSession {
|
|
10
|
+
token: string;
|
|
11
|
+
aid: string;
|
|
12
|
+
username: string;
|
|
13
|
+
identityId: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class AuthResource {
|
|
16
|
+
private http;
|
|
17
|
+
constructor(http: HttpClient);
|
|
18
|
+
generateChallenge(aid: string): Promise<{
|
|
19
|
+
nonce: string;
|
|
20
|
+
}>;
|
|
21
|
+
verify(input: VerifyIdentityInput): Promise<AuthSession>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=AuthResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthResource.d.ts","sourceRoot":"","sources":["../../src/resources/AuthResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,MAAM,WAAW,mBAAmB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,YAAY;IACT,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE9B,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAI1D,MAAM,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC;CAGjE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
|
+
import { Message } from '../types/index.js';
|
|
3
|
+
export declare class MessagesResource {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
list(roomId: string): Promise<Message[]>;
|
|
7
|
+
send(roomId: string, content: string): Promise<Message>;
|
|
8
|
+
edit(messageId: string, content: string): Promise<Message>;
|
|
9
|
+
delete(messageId: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=MessagesResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessagesResource.d.ts","sourceRoot":"","sources":["../../src/resources/MessagesResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,qBAAa,gBAAgB;IACb,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE9B,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAIxC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
|
+
import { Room } from '../types/index.js';
|
|
3
|
+
export declare class RoomsResource {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
list(): Promise<Room[]>;
|
|
7
|
+
create(data: {
|
|
8
|
+
name: string;
|
|
9
|
+
isPublic?: boolean;
|
|
10
|
+
}): Promise<Room>;
|
|
11
|
+
get(id: string): Promise<Room>;
|
|
12
|
+
join(id: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=RoomsResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoomsResource.d.ts","sourceRoot":"","sources":["../../src/resources/RoomsResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,qBAAa,aAAa;IACV,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE9B,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAIvB,MAAM,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9B,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Room {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
isPublic: boolean;
|
|
5
|
+
createdAt: string;
|
|
6
|
+
updatedAt: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Message {
|
|
9
|
+
id: string;
|
|
10
|
+
roomId: string;
|
|
11
|
+
content: string;
|
|
12
|
+
senderId: string;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
}
|
|
15
|
+
export interface Participant {
|
|
16
|
+
id: string;
|
|
17
|
+
identityId: string;
|
|
18
|
+
roomId: string;
|
|
19
|
+
joinedAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Identity {
|
|
22
|
+
id: string;
|
|
23
|
+
publicKey: string;
|
|
24
|
+
nonce: string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACjB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@anonfly/sdk",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Core SDK logic for Anonfly service",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build:tsup": "tsup src/index.ts --format cjs,esm --clean",
|
|
22
|
+
"build:types": "tsc -p tsconfig.dts.json",
|
|
23
|
+
"build": "pnpm run build:tsup && pnpm run build:types",
|
|
24
|
+
"dev": "tsup src/index.ts --format cjs,esm --watch --dts",
|
|
25
|
+
"test": "vitest run"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"cross-fetch": "^4.0.0",
|
|
29
|
+
"events": "^3.3.0",
|
|
30
|
+
"ws": "^8.16.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"vitest": "^1.2.0",
|
|
35
|
+
"@types/ws": "^8.5.10"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|