@anonfly/sdk 0.0.0 → 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/dist/core/transport/HttpClient.d.ts +2 -0
- package/dist/core/transport/HttpClient.d.ts.map +1 -1
- package/dist/index.cjs +110 -15
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +109 -15
- package/dist/resources/AdminResource.d.ts +11 -0
- package/dist/resources/AdminResource.d.ts.map +1 -0
- package/dist/resources/AuthResource.d.ts +13 -6
- package/dist/resources/AuthResource.d.ts.map +1 -1
- package/dist/resources/MessagesResource.d.ts +4 -3
- package/dist/resources/MessagesResource.d.ts.map +1 -1
- package/dist/resources/RoomsResource.d.ts +14 -6
- package/dist/resources/RoomsResource.d.ts.map +1 -1
- package/dist/types/index.d.ts +26 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -13,6 +13,8 @@ export declare class HttpClient {
|
|
|
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,O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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,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 (e) {
|
|
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,33 @@ 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 path = `/chatrooms?sse=true${region ? `®ion=${region}` : ""}`;
|
|
312
|
+
return this.http.subscribeSSE(path, onUpdate);
|
|
313
|
+
}
|
|
314
|
+
subscribeToRoomDetails(id, onUpdate) {
|
|
315
|
+
return this.http.subscribeSSE(`/chatroom/${id}/details/sse`, onUpdate);
|
|
242
316
|
}
|
|
243
317
|
};
|
|
244
318
|
|
|
@@ -247,17 +321,34 @@ var MessagesResource = class {
|
|
|
247
321
|
constructor(http) {
|
|
248
322
|
this.http = http;
|
|
249
323
|
}
|
|
250
|
-
async list(roomId) {
|
|
251
|
-
|
|
324
|
+
async list(roomId, options) {
|
|
325
|
+
const response = await this.http.get(`/chatrooms/${roomId}/messages`, {
|
|
326
|
+
params: options
|
|
327
|
+
});
|
|
328
|
+
return response.data;
|
|
252
329
|
}
|
|
253
330
|
async send(roomId, content) {
|
|
254
|
-
|
|
331
|
+
const response = await this.http.post(`/chatrooms/${roomId}/messages`, { content });
|
|
332
|
+
return response.data;
|
|
255
333
|
}
|
|
256
|
-
|
|
257
|
-
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// src/resources/AdminResource.ts
|
|
337
|
+
var AdminResource = class {
|
|
338
|
+
constructor(http) {
|
|
339
|
+
this.http = http;
|
|
258
340
|
}
|
|
259
|
-
async
|
|
260
|
-
return this.http.
|
|
341
|
+
async listKeys() {
|
|
342
|
+
return this.http.get("/admin/keys");
|
|
343
|
+
}
|
|
344
|
+
async createKey(name) {
|
|
345
|
+
return this.http.post("/admin/keys", { name });
|
|
346
|
+
}
|
|
347
|
+
async toggleKey(id, isActive) {
|
|
348
|
+
return this.http.patch("/admin/keys/" + id, { isActive });
|
|
349
|
+
}
|
|
350
|
+
async deleteKey(id) {
|
|
351
|
+
return this.http.delete("/admin/keys/" + id);
|
|
261
352
|
}
|
|
262
353
|
};
|
|
263
354
|
|
|
@@ -292,9 +383,13 @@ var Anonfly = class {
|
|
|
292
383
|
get auth() {
|
|
293
384
|
return new AuthResource(this.http);
|
|
294
385
|
}
|
|
386
|
+
get admin() {
|
|
387
|
+
return new AdminResource(this.http);
|
|
388
|
+
}
|
|
295
389
|
};
|
|
296
390
|
// Annotate the CommonJS export names for ESM import in node:
|
|
297
391
|
0 && (module.exports = {
|
|
392
|
+
AdminResource,
|
|
298
393
|
Anonfly,
|
|
299
394
|
AnonflyError,
|
|
300
395
|
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;
|
|
@@ -25,5 +27,6 @@ export declare class Anonfly {
|
|
|
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,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;
|
|
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;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,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;AACzC,cAAc,2BAA2B,CAAC;AAE1C,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;IAED,IAAW,KAAK,kBAEf;CACJ"}
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,16 @@ var AuthResource = 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 (e) {
|
|
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,33 @@ 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 path = `/chatrooms?sse=true${region ? `®ion=${region}` : ""}`;
|
|
275
|
+
return this.http.subscribeSSE(path, onUpdate);
|
|
276
|
+
}
|
|
277
|
+
subscribeToRoomDetails(id, onUpdate) {
|
|
278
|
+
return this.http.subscribeSSE(`/chatroom/${id}/details/sse`, onUpdate);
|
|
206
279
|
}
|
|
207
280
|
};
|
|
208
281
|
|
|
@@ -211,17 +284,34 @@ var MessagesResource = class {
|
|
|
211
284
|
constructor(http) {
|
|
212
285
|
this.http = http;
|
|
213
286
|
}
|
|
214
|
-
async list(roomId) {
|
|
215
|
-
|
|
287
|
+
async list(roomId, options) {
|
|
288
|
+
const response = await this.http.get(`/chatrooms/${roomId}/messages`, {
|
|
289
|
+
params: options
|
|
290
|
+
});
|
|
291
|
+
return response.data;
|
|
216
292
|
}
|
|
217
293
|
async send(roomId, content) {
|
|
218
|
-
|
|
294
|
+
const response = await this.http.post(`/chatrooms/${roomId}/messages`, { content });
|
|
295
|
+
return response.data;
|
|
219
296
|
}
|
|
220
|
-
|
|
221
|
-
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/resources/AdminResource.ts
|
|
300
|
+
var AdminResource = class {
|
|
301
|
+
constructor(http) {
|
|
302
|
+
this.http = http;
|
|
222
303
|
}
|
|
223
|
-
async
|
|
224
|
-
return this.http.
|
|
304
|
+
async listKeys() {
|
|
305
|
+
return this.http.get("/admin/keys");
|
|
306
|
+
}
|
|
307
|
+
async createKey(name) {
|
|
308
|
+
return this.http.post("/admin/keys", { name });
|
|
309
|
+
}
|
|
310
|
+
async toggleKey(id, isActive) {
|
|
311
|
+
return this.http.patch("/admin/keys/" + id, { isActive });
|
|
312
|
+
}
|
|
313
|
+
async deleteKey(id) {
|
|
314
|
+
return this.http.delete("/admin/keys/" + id);
|
|
225
315
|
}
|
|
226
316
|
};
|
|
227
317
|
|
|
@@ -256,8 +346,12 @@ var Anonfly = class {
|
|
|
256
346
|
get auth() {
|
|
257
347
|
return new AuthResource(this.http);
|
|
258
348
|
}
|
|
349
|
+
get admin() {
|
|
350
|
+
return new AdminResource(this.http);
|
|
351
|
+
}
|
|
259
352
|
};
|
|
260
353
|
export {
|
|
354
|
+
AdminResource,
|
|
261
355
|
Anonfly,
|
|
262
356
|
AnonflyError,
|
|
263
357
|
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 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,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE9B,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"}
|
|
@@ -1,16 +1,22 @@
|
|
|
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
22
|
private http;
|
|
@@ -19,5 +25,6 @@ export declare class AuthResource {
|
|
|
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,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE9B,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"}
|
|
@@ -3,9 +3,10 @@ import { Message } from '../types/index.js';
|
|
|
3
3
|
export declare class MessagesResource {
|
|
4
4
|
private 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;IAE9B,IAAI,CAAC,MAAM,EAAE,MAAM,
|
|
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,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
4
|
private 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,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE9B,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;IAK9F,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;CAGpG"}
|
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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