@anonfly/sdk 0.0.0 → 1.0.1
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/core/transport/HttpClient.d.ts +4 -2
- package/dist/core/transport/HttpClient.d.ts.map +1 -1
- package/dist/index.cjs +111 -15
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -15
- package/dist/resources/AdminResource.d.ts +11 -0
- package/dist/resources/AdminResource.d.ts.map +1 -0
- package/dist/resources/AdminResource.test.d.ts +2 -0
- package/dist/resources/AdminResource.test.d.ts.map +1 -0
- package/dist/resources/AuthResource.d.ts +14 -7
- package/dist/resources/AuthResource.d.ts.map +1 -1
- package/dist/resources/MessagesResource.d.ts +5 -4
- package/dist/resources/MessagesResource.d.ts.map +1 -1
- package/dist/resources/RoomsResource.d.ts +15 -7
- package/dist/resources/RoomsResource.d.ts.map +1 -1
- package/dist/resources/RoomsResource.test.d.ts +2 -0
- package/dist/resources/RoomsResource.test.d.ts.map +1 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -5,14 +5,16 @@ export interface HttpClientConfig {
|
|
|
5
5
|
headers?: Record<string, string>;
|
|
6
6
|
}
|
|
7
7
|
export declare class HttpClient {
|
|
8
|
-
private config;
|
|
9
|
-
private middlewares;
|
|
8
|
+
private readonly config;
|
|
9
|
+
private readonly middlewares;
|
|
10
10
|
constructor(config: HttpClientConfig);
|
|
11
11
|
use(middleware: Middleware): void;
|
|
12
12
|
request(path: string, options?: RequestInit): Promise<any>;
|
|
13
13
|
get(path: string, options?: RequestInit): Promise<any>;
|
|
14
14
|
post(path: string, body?: any, options?: RequestInit): Promise<any>;
|
|
15
15
|
put(path: string, body?: any, options?: RequestInit): Promise<any>;
|
|
16
|
+
patch(path: string, body?: any, options?: RequestInit): Promise<any>;
|
|
16
17
|
delete(path: string, options?: RequestInit): Promise<any>;
|
|
18
|
+
subscribeSSE<T>(path: string, onMessage: (data: T) => void, onError?: (error: any) => void): Promise<() => void>;
|
|
17
19
|
}
|
|
18
20
|
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -1 +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;
|
|
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,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;gBAEnB,MAAM,EAAE,gBAAgB;IAErD,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,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW;IAQrD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;IAIpC,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;CAqDzH"}
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
AdminResource: () => AdminResource,
|
|
23
24
|
Anonfly: () => Anonfly,
|
|
24
25
|
AnonflyError: () => AnonflyError,
|
|
25
26
|
AuthResource: () => AuthResource,
|
|
@@ -40,10 +41,16 @@ var AuthResource = class {
|
|
|
40
41
|
this.http = http;
|
|
41
42
|
}
|
|
42
43
|
async generateChallenge(aid) {
|
|
43
|
-
|
|
44
|
+
const response = await this.http.post("/auth/challenge", { aid });
|
|
45
|
+
return response.data;
|
|
44
46
|
}
|
|
45
47
|
async verify(input) {
|
|
46
|
-
|
|
48
|
+
const response = await this.http.post("/auth/verify", input);
|
|
49
|
+
return response.data;
|
|
50
|
+
}
|
|
51
|
+
async getPremiumStatus() {
|
|
52
|
+
const response = await this.http.get("/auth/premium-status");
|
|
53
|
+
return response.data;
|
|
47
54
|
}
|
|
48
55
|
};
|
|
49
56
|
|
|
@@ -142,9 +149,60 @@ var HttpClient = class {
|
|
|
142
149
|
body: JSON.stringify(body)
|
|
143
150
|
});
|
|
144
151
|
}
|
|
152
|
+
patch(path, body, options) {
|
|
153
|
+
return this.request(path, {
|
|
154
|
+
...options,
|
|
155
|
+
method: "PATCH",
|
|
156
|
+
body: JSON.stringify(body)
|
|
157
|
+
});
|
|
158
|
+
}
|
|
145
159
|
delete(path, options) {
|
|
146
160
|
return this.request(path, { ...options, method: "DELETE" });
|
|
147
161
|
}
|
|
162
|
+
async subscribeSSE(path, onMessage, onError) {
|
|
163
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
164
|
+
const headers = {
|
|
165
|
+
...this.config.headers,
|
|
166
|
+
"Accept": "text/event-stream"
|
|
167
|
+
};
|
|
168
|
+
const controller = new AbortController();
|
|
169
|
+
const response = await fetch(url, {
|
|
170
|
+
headers,
|
|
171
|
+
signal: controller.signal
|
|
172
|
+
});
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
throw new AnonflyError("Failed to connect to SSE", void 0, response.status);
|
|
175
|
+
}
|
|
176
|
+
const reader = response.body?.getReader();
|
|
177
|
+
const decoder = new TextDecoder();
|
|
178
|
+
if (!reader) {
|
|
179
|
+
throw new AnonflyError("Response body is not readable");
|
|
180
|
+
}
|
|
181
|
+
(async () => {
|
|
182
|
+
let buffer = "";
|
|
183
|
+
try {
|
|
184
|
+
while (true) {
|
|
185
|
+
const { done, value } = await reader.read();
|
|
186
|
+
if (done) break;
|
|
187
|
+
buffer += decoder.decode(value, { stream: true });
|
|
188
|
+
const lines = buffer.split("\n");
|
|
189
|
+
buffer = lines.pop() || "";
|
|
190
|
+
for (const line of lines) {
|
|
191
|
+
if (line.startsWith("data: ")) {
|
|
192
|
+
const data = line.slice(6);
|
|
193
|
+
try {
|
|
194
|
+
onMessage(JSON.parse(data));
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (onError) onError(error);
|
|
202
|
+
}
|
|
203
|
+
})();
|
|
204
|
+
return () => controller.abort();
|
|
205
|
+
}
|
|
148
206
|
};
|
|
149
207
|
|
|
150
208
|
// src/core/transport/WebSocketClient.ts
|
|
@@ -228,17 +286,34 @@ var RoomsResource = class {
|
|
|
228
286
|
constructor(http) {
|
|
229
287
|
this.http = http;
|
|
230
288
|
}
|
|
231
|
-
async list() {
|
|
232
|
-
|
|
289
|
+
async list(region) {
|
|
290
|
+
const response = await this.http.get("/chatrooms", {
|
|
291
|
+
params: region ? { region } : void 0
|
|
292
|
+
});
|
|
293
|
+
return response.data;
|
|
233
294
|
}
|
|
234
295
|
async create(data) {
|
|
235
|
-
|
|
296
|
+
const response = await this.http.post("/chatrooms", data);
|
|
297
|
+
return response.data;
|
|
236
298
|
}
|
|
237
299
|
async get(id) {
|
|
238
|
-
|
|
300
|
+
const response = await this.http.get(`/chatroom/${id}/details`);
|
|
301
|
+
return response.data;
|
|
239
302
|
}
|
|
240
|
-
async join(id) {
|
|
241
|
-
return this.http.post(`/
|
|
303
|
+
async join(id, password) {
|
|
304
|
+
return this.http.post(`/chatrooms/${id}/join`, { password });
|
|
305
|
+
}
|
|
306
|
+
async checkAccess(id) {
|
|
307
|
+
const response = await this.http.post(`/chatroom/${id}/check-access`);
|
|
308
|
+
return response.data;
|
|
309
|
+
}
|
|
310
|
+
subscribeToPublicList(onUpdate, region) {
|
|
311
|
+
const regionParam = region ? `®ion=${region}` : "";
|
|
312
|
+
const path = `/chatrooms?sse=true${regionParam}`;
|
|
313
|
+
return this.http.subscribeSSE(path, onUpdate);
|
|
314
|
+
}
|
|
315
|
+
subscribeToRoomDetails(id, onUpdate) {
|
|
316
|
+
return this.http.subscribeSSE(`/chatroom/${id}/details/sse`, onUpdate);
|
|
242
317
|
}
|
|
243
318
|
};
|
|
244
319
|
|
|
@@ -247,17 +322,34 @@ var MessagesResource = class {
|
|
|
247
322
|
constructor(http) {
|
|
248
323
|
this.http = http;
|
|
249
324
|
}
|
|
250
|
-
async list(roomId) {
|
|
251
|
-
|
|
325
|
+
async list(roomId, options) {
|
|
326
|
+
const response = await this.http.get(`/chatrooms/${roomId}/messages`, {
|
|
327
|
+
params: options
|
|
328
|
+
});
|
|
329
|
+
return response.data;
|
|
252
330
|
}
|
|
253
331
|
async send(roomId, content) {
|
|
254
|
-
|
|
332
|
+
const response = await this.http.post(`/chatrooms/${roomId}/messages`, { content });
|
|
333
|
+
return response.data;
|
|
255
334
|
}
|
|
256
|
-
|
|
257
|
-
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// src/resources/AdminResource.ts
|
|
338
|
+
var AdminResource = class {
|
|
339
|
+
constructor(http) {
|
|
340
|
+
this.http = http;
|
|
258
341
|
}
|
|
259
|
-
async
|
|
260
|
-
return this.http.
|
|
342
|
+
async listKeys() {
|
|
343
|
+
return this.http.get("/admin/keys");
|
|
344
|
+
}
|
|
345
|
+
async createKey(name) {
|
|
346
|
+
return this.http.post("/admin/keys", { name });
|
|
347
|
+
}
|
|
348
|
+
async toggleKey(id, isActive) {
|
|
349
|
+
return this.http.patch("/admin/keys/" + id, { isActive });
|
|
350
|
+
}
|
|
351
|
+
async deleteKey(id) {
|
|
352
|
+
return this.http.delete("/admin/keys/" + id);
|
|
261
353
|
}
|
|
262
354
|
};
|
|
263
355
|
|
|
@@ -292,9 +384,13 @@ var Anonfly = class {
|
|
|
292
384
|
get auth() {
|
|
293
385
|
return new AuthResource(this.http);
|
|
294
386
|
}
|
|
387
|
+
get admin() {
|
|
388
|
+
return new AdminResource(this.http);
|
|
389
|
+
}
|
|
295
390
|
};
|
|
296
391
|
// Annotate the CommonJS export names for ESM import in node:
|
|
297
392
|
0 && (module.exports = {
|
|
393
|
+
AdminResource,
|
|
298
394
|
Anonfly,
|
|
299
395
|
AnonflyError,
|
|
300
396
|
AuthResource,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { HttpClient } from './core/transport/HttpClient';
|
|
|
3
3
|
import { WebSocketClient } from './core/transport/WebSocketClient';
|
|
4
4
|
import { RoomsResource } from './resources/RoomsResource';
|
|
5
5
|
import { MessagesResource } from './resources/MessagesResource';
|
|
6
|
+
import { AdminResource } from './resources/AdminResource';
|
|
6
7
|
export * from './types/index';
|
|
7
8
|
export * from './core/errors/AnonflyError';
|
|
8
9
|
export * from './core/transport/HttpClient';
|
|
@@ -11,6 +12,7 @@ export * from './core/transport/retryMiddleware';
|
|
|
11
12
|
export * from './resources/RoomsResource';
|
|
12
13
|
export * from './resources/MessagesResource';
|
|
13
14
|
export * from './resources/AuthResource';
|
|
15
|
+
export * from './resources/AdminResource';
|
|
14
16
|
export interface AnonflyConfig {
|
|
15
17
|
apiKey: string;
|
|
16
18
|
baseUrl: string;
|
|
@@ -18,12 +20,13 @@ export interface AnonflyConfig {
|
|
|
18
20
|
retries?: number;
|
|
19
21
|
}
|
|
20
22
|
export declare class Anonfly {
|
|
21
|
-
private config;
|
|
23
|
+
private readonly config;
|
|
22
24
|
http: HttpClient;
|
|
23
25
|
ws?: WebSocketClient;
|
|
24
26
|
constructor(config: AnonflyConfig);
|
|
25
27
|
get rooms(): RoomsResource;
|
|
26
28
|
get messages(): MessagesResource;
|
|
27
29
|
get auth(): AuthResource;
|
|
30
|
+
get admin(): AdminResource;
|
|
28
31
|
}
|
|
29
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,EAA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thResource = class {
|
|
|
4
4
|
this.http = http;
|
|
5
5
|
}
|
|
6
6
|
async generateChallenge(aid) {
|
|
7
|
-
|
|
7
|
+
const response = await this.http.post("/auth/challenge", { aid });
|
|
8
|
+
return response.data;
|
|
8
9
|
}
|
|
9
10
|
async verify(input) {
|
|
10
|
-
|
|
11
|
+
const response = await this.http.post("/auth/verify", input);
|
|
12
|
+
return response.data;
|
|
13
|
+
}
|
|
14
|
+
async getPremiumStatus() {
|
|
15
|
+
const response = await this.http.get("/auth/premium-status");
|
|
16
|
+
return response.data;
|
|
11
17
|
}
|
|
12
18
|
};
|
|
13
19
|
|
|
@@ -106,9 +112,60 @@ var HttpClient = class {
|
|
|
106
112
|
body: JSON.stringify(body)
|
|
107
113
|
});
|
|
108
114
|
}
|
|
115
|
+
patch(path, body, options) {
|
|
116
|
+
return this.request(path, {
|
|
117
|
+
...options,
|
|
118
|
+
method: "PATCH",
|
|
119
|
+
body: JSON.stringify(body)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
109
122
|
delete(path, options) {
|
|
110
123
|
return this.request(path, { ...options, method: "DELETE" });
|
|
111
124
|
}
|
|
125
|
+
async subscribeSSE(path, onMessage, onError) {
|
|
126
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
127
|
+
const headers = {
|
|
128
|
+
...this.config.headers,
|
|
129
|
+
"Accept": "text/event-stream"
|
|
130
|
+
};
|
|
131
|
+
const controller = new AbortController();
|
|
132
|
+
const response = await fetch(url, {
|
|
133
|
+
headers,
|
|
134
|
+
signal: controller.signal
|
|
135
|
+
});
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
throw new AnonflyError("Failed to connect to SSE", void 0, response.status);
|
|
138
|
+
}
|
|
139
|
+
const reader = response.body?.getReader();
|
|
140
|
+
const decoder = new TextDecoder();
|
|
141
|
+
if (!reader) {
|
|
142
|
+
throw new AnonflyError("Response body is not readable");
|
|
143
|
+
}
|
|
144
|
+
(async () => {
|
|
145
|
+
let buffer = "";
|
|
146
|
+
try {
|
|
147
|
+
while (true) {
|
|
148
|
+
const { done, value } = await reader.read();
|
|
149
|
+
if (done) break;
|
|
150
|
+
buffer += decoder.decode(value, { stream: true });
|
|
151
|
+
const lines = buffer.split("\n");
|
|
152
|
+
buffer = lines.pop() || "";
|
|
153
|
+
for (const line of lines) {
|
|
154
|
+
if (line.startsWith("data: ")) {
|
|
155
|
+
const data = line.slice(6);
|
|
156
|
+
try {
|
|
157
|
+
onMessage(JSON.parse(data));
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (onError) onError(error);
|
|
165
|
+
}
|
|
166
|
+
})();
|
|
167
|
+
return () => controller.abort();
|
|
168
|
+
}
|
|
112
169
|
};
|
|
113
170
|
|
|
114
171
|
// src/core/transport/WebSocketClient.ts
|
|
@@ -192,17 +249,34 @@ var RoomsResource = class {
|
|
|
192
249
|
constructor(http) {
|
|
193
250
|
this.http = http;
|
|
194
251
|
}
|
|
195
|
-
async list() {
|
|
196
|
-
|
|
252
|
+
async list(region) {
|
|
253
|
+
const response = await this.http.get("/chatrooms", {
|
|
254
|
+
params: region ? { region } : void 0
|
|
255
|
+
});
|
|
256
|
+
return response.data;
|
|
197
257
|
}
|
|
198
258
|
async create(data) {
|
|
199
|
-
|
|
259
|
+
const response = await this.http.post("/chatrooms", data);
|
|
260
|
+
return response.data;
|
|
200
261
|
}
|
|
201
262
|
async get(id) {
|
|
202
|
-
|
|
263
|
+
const response = await this.http.get(`/chatroom/${id}/details`);
|
|
264
|
+
return response.data;
|
|
203
265
|
}
|
|
204
|
-
async join(id) {
|
|
205
|
-
return this.http.post(`/
|
|
266
|
+
async join(id, password) {
|
|
267
|
+
return this.http.post(`/chatrooms/${id}/join`, { password });
|
|
268
|
+
}
|
|
269
|
+
async checkAccess(id) {
|
|
270
|
+
const response = await this.http.post(`/chatroom/${id}/check-access`);
|
|
271
|
+
return response.data;
|
|
272
|
+
}
|
|
273
|
+
subscribeToPublicList(onUpdate, region) {
|
|
274
|
+
const regionParam = region ? `®ion=${region}` : "";
|
|
275
|
+
const path = `/chatrooms?sse=true${regionParam}`;
|
|
276
|
+
return this.http.subscribeSSE(path, onUpdate);
|
|
277
|
+
}
|
|
278
|
+
subscribeToRoomDetails(id, onUpdate) {
|
|
279
|
+
return this.http.subscribeSSE(`/chatroom/${id}/details/sse`, onUpdate);
|
|
206
280
|
}
|
|
207
281
|
};
|
|
208
282
|
|
|
@@ -211,17 +285,34 @@ var MessagesResource = class {
|
|
|
211
285
|
constructor(http) {
|
|
212
286
|
this.http = http;
|
|
213
287
|
}
|
|
214
|
-
async list(roomId) {
|
|
215
|
-
|
|
288
|
+
async list(roomId, options) {
|
|
289
|
+
const response = await this.http.get(`/chatrooms/${roomId}/messages`, {
|
|
290
|
+
params: options
|
|
291
|
+
});
|
|
292
|
+
return response.data;
|
|
216
293
|
}
|
|
217
294
|
async send(roomId, content) {
|
|
218
|
-
|
|
295
|
+
const response = await this.http.post(`/chatrooms/${roomId}/messages`, { content });
|
|
296
|
+
return response.data;
|
|
219
297
|
}
|
|
220
|
-
|
|
221
|
-
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/resources/AdminResource.ts
|
|
301
|
+
var AdminResource = class {
|
|
302
|
+
constructor(http) {
|
|
303
|
+
this.http = http;
|
|
222
304
|
}
|
|
223
|
-
async
|
|
224
|
-
return this.http.
|
|
305
|
+
async listKeys() {
|
|
306
|
+
return this.http.get("/admin/keys");
|
|
307
|
+
}
|
|
308
|
+
async createKey(name) {
|
|
309
|
+
return this.http.post("/admin/keys", { name });
|
|
310
|
+
}
|
|
311
|
+
async toggleKey(id, isActive) {
|
|
312
|
+
return this.http.patch("/admin/keys/" + id, { isActive });
|
|
313
|
+
}
|
|
314
|
+
async deleteKey(id) {
|
|
315
|
+
return this.http.delete("/admin/keys/" + id);
|
|
225
316
|
}
|
|
226
317
|
};
|
|
227
318
|
|
|
@@ -256,8 +347,12 @@ var Anonfly = class {
|
|
|
256
347
|
get auth() {
|
|
257
348
|
return new AuthResource(this.http);
|
|
258
349
|
}
|
|
350
|
+
get admin() {
|
|
351
|
+
return new AdminResource(this.http);
|
|
352
|
+
}
|
|
259
353
|
};
|
|
260
354
|
export {
|
|
355
|
+
AdminResource,
|
|
261
356
|
Anonfly,
|
|
262
357
|
AnonflyError,
|
|
263
358
|
AuthResource,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
|
+
import { ApiKey } from '../types/index.js';
|
|
3
|
+
export declare class AdminResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
listKeys(): Promise<ApiKey[]>;
|
|
7
|
+
createKey(name: string): Promise<ApiKey>;
|
|
8
|
+
toggleKey(id: string, isActive: boolean): Promise<ApiKey>;
|
|
9
|
+
deleteKey(id: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=AdminResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdminResource.d.ts","sourceRoot":"","sources":["../../src/resources/AdminResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,aAAa;IACV,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI7B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdminResource.test.d.ts","sourceRoot":"","sources":["../../src/resources/AdminResource.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
|
+
import { PremiumStatus } from '../types/index.js';
|
|
2
3
|
export interface VerifyIdentityInput {
|
|
3
|
-
|
|
4
|
+
challenge: string;
|
|
4
5
|
signature: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
identity: {
|
|
7
|
+
aid: string;
|
|
8
|
+
username: string;
|
|
9
|
+
publicKey: string;
|
|
10
|
+
exchangePublicKey: string;
|
|
11
|
+
};
|
|
8
12
|
}
|
|
9
13
|
export interface AuthSession {
|
|
10
14
|
token: string;
|
|
11
|
-
aid: string;
|
|
12
|
-
username: string;
|
|
13
15
|
identityId: string;
|
|
16
|
+
identityAid: string;
|
|
17
|
+
username: string;
|
|
18
|
+
isPremium: boolean;
|
|
19
|
+
allowedFeatures: string[];
|
|
14
20
|
}
|
|
15
21
|
export declare class AuthResource {
|
|
16
|
-
private http;
|
|
22
|
+
private readonly http;
|
|
17
23
|
constructor(http: HttpClient);
|
|
18
24
|
generateChallenge(aid: string): Promise<{
|
|
19
25
|
nonce: string;
|
|
20
26
|
}>;
|
|
21
27
|
verify(input: VerifyIdentityInput): Promise<AuthSession>;
|
|
28
|
+
getPremiumStatus(): Promise<PremiumStatus>;
|
|
22
29
|
}
|
|
23
30
|
//# sourceMappingURL=AuthResource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthResource.d.ts","sourceRoot":"","sources":["../../src/resources/AuthResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthResource.d.ts","sourceRoot":"","sources":["../../src/resources/AuthResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;KAC7B,CAAC;CACL;AAED,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,qBAAa,YAAY;IACT,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAK1D,MAAM,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC;IAKxD,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;CAInD"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
2
|
import { Message } from '../types/index.js';
|
|
3
3
|
export declare class MessagesResource {
|
|
4
|
-
private http;
|
|
4
|
+
private readonly http;
|
|
5
5
|
constructor(http: HttpClient);
|
|
6
|
-
list(roomId: string
|
|
6
|
+
list(roomId: string, options?: {
|
|
7
|
+
limit?: number;
|
|
8
|
+
before?: string;
|
|
9
|
+
}): Promise<Message[]>;
|
|
7
10
|
send(roomId: string, content: string): Promise<Message>;
|
|
8
|
-
edit(messageId: string, content: string): Promise<Message>;
|
|
9
|
-
delete(messageId: string): Promise<void>;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=MessagesResource.d.ts.map
|
|
@@ -1 +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;
|
|
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,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAOvF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAIhE"}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { HttpClient } from '../core/transport/HttpClient.js';
|
|
2
|
-
import { Room } from '../types/index.js';
|
|
2
|
+
import { Room, RoomDetails } from '../types/index.js';
|
|
3
3
|
export declare class RoomsResource {
|
|
4
|
-
private http;
|
|
4
|
+
private readonly http;
|
|
5
5
|
constructor(http: HttpClient);
|
|
6
|
-
list(): Promise<Room[]>;
|
|
6
|
+
list(region?: string): Promise<Room[]>;
|
|
7
7
|
create(data: {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
roomname: string;
|
|
9
|
+
isPrivate?: boolean;
|
|
10
|
+
description?: string;
|
|
11
|
+
password?: string;
|
|
10
12
|
}): Promise<Room>;
|
|
11
|
-
get(id: string): Promise<
|
|
12
|
-
join(id: string): Promise<void>;
|
|
13
|
+
get(id: string): Promise<RoomDetails>;
|
|
14
|
+
join(id: string, password?: string): Promise<void>;
|
|
15
|
+
checkAccess(id: string): Promise<{
|
|
16
|
+
accessGranted: boolean;
|
|
17
|
+
roomId: string;
|
|
18
|
+
}>;
|
|
19
|
+
subscribeToPublicList(onUpdate: (rooms: Room[]) => void, region?: string): Promise<() => void>;
|
|
20
|
+
subscribeToRoomDetails(id: string, onUpdate: (details: RoomDetails) => void): Promise<() => void>;
|
|
13
21
|
}
|
|
14
22
|
//# sourceMappingURL=RoomsResource.d.ts.map
|
|
@@ -1 +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;
|
|
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,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEtD,qBAAa,aAAa;IACV,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAOtC,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/G,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAKrC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAKlF,qBAAqB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;IAM9F,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;CAGpG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoomsResource.test.d.ts","sourceRoot":"","sources":["../../src/resources/RoomsResource.test.ts"],"names":[],"mappings":""}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,4 +23,30 @@ export interface Identity {
|
|
|
23
23
|
publicKey: string;
|
|
24
24
|
nonce: string;
|
|
25
25
|
}
|
|
26
|
+
export interface ApiKey {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
keyHash: string;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
isActive: boolean;
|
|
33
|
+
rawKey?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface PremiumStatus {
|
|
36
|
+
isPremium: boolean;
|
|
37
|
+
allowedFeatures: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface RoomDetails extends Room {
|
|
40
|
+
participants: {
|
|
41
|
+
userId: string;
|
|
42
|
+
username: string;
|
|
43
|
+
userAid: string;
|
|
44
|
+
joinedAt: string;
|
|
45
|
+
}[];
|
|
46
|
+
hostAid: string;
|
|
47
|
+
}
|
|
48
|
+
export interface SSEEvent<T = any> {
|
|
49
|
+
type: string;
|
|
50
|
+
data: T;
|
|
51
|
+
}
|
|
26
52
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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"}
|
|
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;IA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