From 6439a6c63fb603c9137e5f7f7b65168db7d98cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Thu, 31 Jan 2019 17:52:17 +0900 Subject: [PATCH] Create type definition for 'webfinger.js' (#4054) --- src/@types/webfinger.js.d.ts | 65 ++++++++++++++++++++++++++++++++++++ src/remote/webfinger.ts | 4 +-- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/@types/webfinger.js.d.ts diff --git a/src/@types/webfinger.js.d.ts b/src/@types/webfinger.js.d.ts new file mode 100644 index 0000000000..9783a14cba --- /dev/null +++ b/src/@types/webfinger.js.d.ts @@ -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; + } +} diff --git a/src/remote/webfinger.ts b/src/remote/webfinger.ts index cba09379a1..1229dbaf98 100644 --- a/src/remote/webfinger.ts +++ b/src/remote/webfinger.ts @@ -1,4 +1,4 @@ -const WebFinger = require('webfinger.js'); +import { WebFinger } from 'webfinger.js'; const webFinger = new WebFinger({ }); @@ -13,7 +13,7 @@ type IWebFinger = { }; export default async function resolve(query: any): Promise { - 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) { return rej(error); }