feat: add delete_file & session

Adds delete_file & session functions.
Adds examples to README.md & example app.
Fixes Android bindings.
Adds event listener functionality for future methods & features.
Bumps version to 0.9.0.
This commit is contained in:
coreyphillips
2024-10-07 09:47:52 -04:00
parent ca95ddaf8a
commit df9c8f7104
20 changed files with 1639 additions and 424 deletions

View File

@@ -1,4 +1,4 @@
import { NativeModules, Platform } from 'react-native';
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import { ok, err, type Result } from '@synonymdev/result';
const LINKING_ERROR =
@@ -18,6 +18,30 @@ const Pubky = NativeModules.Pubky
}
);
const eventEmitter = new NativeEventEmitter(Pubky);
export async function setEventListener(
callback: (eventData: string) => void
): Promise<Result<void>> {
try {
await Pubky.setEventListener();
eventEmitter.addListener('PubkyEvent', callback);
return ok(undefined);
} catch (e) {
return err(JSON.stringify(e));
}
}
export async function removeEventListener(): Promise<Result<void>> {
try {
//await Pubky.removeEventListener();
eventEmitter.removeAllListeners('PubkyEvent');
return ok(undefined);
} catch (e) {
return err(JSON.stringify(e));
}
}
export async function auth(
url: string,
secretKey: string
@@ -225,6 +249,35 @@ export async function list(url: string): Promise<Result<string[]>> {
}
}
export async function deleteFile(url: string): Promise<Result<string[]>> {
try {
const res = await Pubky.deleteFile(url);
if (res[0] === 'error') {
return err(res[1]);
}
return ok(res[1]);
} catch (e) {
return err(JSON.stringify(e));
}
}
interface SessionInfo {
pubky: string;
capabilities: string[];
}
export async function session(pubky: string): Promise<Result<SessionInfo>> {
try {
const res = await Pubky.session(pubky);
if (res[0] === 'error') {
return err(res[1]);
}
return ok(JSON.parse(res[1]));
} catch (e) {
return err(JSON.stringify(e));
}
}
interface IPublicKeyInfo {
public_key: string;
uri: string;