Create type definition for 'webfinger.js' (#4054)

This commit is contained in:
Acid Chicken (硫酸鶏) 2019-01-31 17:52:17 +09:00 committed by GitHub
parent 76fe1c21c3
commit 6439a6c63f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 2 deletions

65
src/@types/webfinger.js.d.ts vendored Normal file
View File

@ -0,0 +1,65 @@
declare module 'webfinger.js' {
interface IWebFingerConstructorConfig {
tls_only?: boolean;
webfist_fallback?: boolean;
uri_fallback?: boolean;
request_timeout?: number;
}
type JRDProperties = { [type: string]: string };
interface IJRDLink {
rel: string;
type?: string;
href?: string;
template?: string;
titles?: { [lang: string]: string };
properties?: JRDProperties;
}
interface IJRD {
subject?: string;
expires?: Date;
aliases?: string[];
properties?: JRDProperties;
links?: IJRDLink[];
}
interface IIDXLinks {
'avatar': IJRDLink[];
'remotestorage': IJRDLink[];
'blog': IJRDLink[];
'vcard': IJRDLink[];
'updates': IJRDLink[];
'share': IJRDLink[];
'profile': IJRDLink[];
'webfist': IJRDLink[];
'camlistore': IJRDLink[];
[type: string]: IJRDLink[];
}
interface IIDXProperties {
'name': string;
[type: string]: string;
}
interface IIDX {
links: IIDXLinks;
properties: IIDXProperties;
}
interface ILookupCallbackResult {
object: IJRD;
json: string;
idx: IIDX;
}
type LookupCallback = (err: Error | string, result?: ILookupCallbackResult) => void;
export class WebFinger {
constructor(config?: IWebFingerConstructorConfig);
public lookup(address: string, cb: LookupCallback): NodeJS.Timeout;
public lookupLink(address: string, rel: string, cb: IJRDLink): void;
}
}

View File

@ -1,4 +1,4 @@
const WebFinger = require('webfinger.js'); import { WebFinger } from 'webfinger.js';
const webFinger = new WebFinger({ }); const webFinger = new WebFinger({ });
@ -13,7 +13,7 @@ type IWebFinger = {
}; };
export default async function resolve(query: any): Promise<IWebFinger> { export default async function resolve(query: any): Promise<IWebFinger> {
return await new Promise((res, rej) => webFinger.lookup(query, (error: Error, result: any) => { return await new Promise((res, rej) => webFinger.lookup(query, (error: Error | string, result: any) => {
if (error) { if (error) {
return rej(error); return rej(error);
} }