From 7f75d6836a78e0eb6d2d224290448422d49b545e Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Fri, 11 Mar 2016 14:30:28 -0800 Subject: [PATCH 1/2] add xdomain typings --- xdomain/xdomain-tests.ts | 14 +++++++++++ xdomain/xdomain.d.ts | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 xdomain/xdomain-tests.ts create mode 100644 xdomain/xdomain.d.ts diff --git a/xdomain/xdomain-tests.ts b/xdomain/xdomain-tests.ts new file mode 100644 index 000000000..303fa15fe --- /dev/null +++ b/xdomain/xdomain-tests.ts @@ -0,0 +1,14 @@ +/// + +xdomain.masters({ + 'http://abc.example.com': '/api/*' +}); + +xdomain.slaves({ + "http://xyz.example.com": "/proxy.html" +}); + +xdomain.debug = true; +xdomain.on("log", (msg) => console.log(msg)); +xdomain.on("timeout", () => console.log("timeout")); +xdomain.cookies.master = "MASTER"; diff --git a/xdomain/xdomain.d.ts b/xdomain/xdomain.d.ts new file mode 100644 index 000000000..8b8931007 --- /dev/null +++ b/xdomain/xdomain.d.ts @@ -0,0 +1,52 @@ +// Type definitions for xdomain v0.7.5 +// Project: http://jpillora.com/xdomain/ +// Definitions by: Dan Chao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +declare interface XDomainCookies { + master: string; + slave: string; +} + +declare interface IXDomain { + /** + * Will initialize as a master + * + * Each of the slaves must be defined as: origin: proxy file + * + * The slaves object is used as a list slaves to force one proxy file per origin. + * @param slaveObj + */ + slaves (slaveObj: Object): void; + /** + * Will initialize as a slave + * + * Each of the masters must be defined as: origin: path + * + * origin and path are converted to a regular expression by escaping all non-alphanumeric chars, then converting * into .* and finally wrapping it with ^ and $. path can also be a RegExp literal. + * + * Requests that do not match both the origin and the path regular expressions will be blocked. + * @param masterObj + */ + masters(masterObj: Object): void; + origin: string; + /** + * When true, XDomain will log actions to console + */ + debug: boolean; + /** + * event may be log, warn or timeout. When listening for log and warn events, handler with contain the message as + * the first parameter. The timeout event fires when an iframe exeeds the xdomain.timeout time limit. + * @param event + * @param handler + */ + on(event: "log"|"warn"|"timeout", handler: (message?: string) => any): void; + cookies: XDomainCookies; +} + +declare var xdomain: IXDomain; + +declare module "xdomain" { + export const xdomain: IXDomain; +} From 6a1fe33b3dc37e7aea339867aab63f0351575069 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Sat, 12 Mar 2016 09:13:02 -0800 Subject: [PATCH 2/2] formatting --- xdomain/xdomain.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xdomain/xdomain.d.ts b/xdomain/xdomain.d.ts index 8b8931007..dddab6f37 100644 --- a/xdomain/xdomain.d.ts +++ b/xdomain/xdomain.d.ts @@ -29,7 +29,7 @@ declare interface IXDomain { * Requests that do not match both the origin and the path regular expressions will be blocked. * @param masterObj */ - masters(masterObj: Object): void; + masters (masterObj: Object): void; origin: string; /** * When true, XDomain will log actions to console @@ -41,7 +41,7 @@ declare interface IXDomain { * @param event * @param handler */ - on(event: "log"|"warn"|"timeout", handler: (message?: string) => any): void; + on (event: "log"|"warn"|"timeout", handler: (message?: string) => any): void; cookies: XDomainCookies; }