@thangved/callback-window 1.0.1-1 → 1.0.1-2

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.
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var b=(r,o,p,f)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of x(o))!a.call(r,e)&&e!==p&&m(r,e,{get:()=>o[e],enumerable:!(f=t(o,e))||f.enumerable});return r};var c=r=>b(m({},"__esModule",{value:!0}),r);var d={};module.exports=c(d);
1
+ "use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var C=(o,t)=>{for(var e in t)a(o,e,{get:t[e],enumerable:!0})},b=(o,t,e,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of f(t))!m.call(o,r)&&r!==e&&a(o,r,{get:()=>t[r],enumerable:!(l=u(t,r))||l.enumerable});return o};var h=o=>b(a({},"__esModule",{value:!0}),o);var I={};C(I,{startCallbackWindow:()=>k});module.exports=h(I);var S={onBrowserNotAllowed(o){window.location.href=o},shouldClose(o){return window.location.origin===new URL(o).origin},timeout:1/0,interval:100},k=(o,t)=>{let{onBrowserNotAllowed:e,shouldClose:l,timeout:r,interval:w}={...S,...t};return new Promise(async(s,c)=>{try{let i=window.open(o),d=Date.now();if(!i)return e(o);for(;;)try{let n=i.window.location.href;if(await Promise.resolve(l(n)))return s({redirectedUrl:n})}catch{}finally{if(r!==1/0){let n=Date.now();if(d+r>=n)throw new Error("Timeout")}if(i.closed)throw new Error("Window closed by user");await new Promise(n=>setTimeout(n,w))}}catch(i){c(new Error("Start callback window failed",{cause:i}))}})};
@@ -1,28 +1,32 @@
1
1
  interface IStartCallbackWindowOptions {
2
2
  /**
3
- * Url to open
3
+ * Time to close window in milliseconds
4
+ * @default Infinity
4
5
  */
5
- url: string;
6
+ timeout: number;
6
7
  /**
7
- * Time to close window in milliseconds
8
+ * Time to checking current url in milliseconds
9
+ * @default 100
8
10
  */
9
- timeout?: number;
11
+ interval: number;
10
12
  /**
11
13
  * The window checker should be closed. By default, the window will close when the origin of the window equals the origin of the parent window.
12
14
  * @param currentUrl - current url of the opened window
13
15
  */
14
- shouldClose?: (currentUrl: string) => boolean | Promise<boolean>;
16
+ shouldClose: (currentUrl: string) => boolean | Promise<boolean>;
15
17
  /**
16
18
  * What to do when browser does not allow opening new windows, by default will change the current window address to the destination address
17
19
  * @param url
18
20
  */
19
- onBrowserNotAllowed?: (url: string) => {};
21
+ onBrowserNotAllowed: (url: string) => void;
20
22
  }
21
23
  interface IStartCallbackWindowResult {
22
24
  redirectedUrl: string;
23
25
  }
24
26
  interface IStartCallbackWindow {
25
- (options: IStartCallbackWindowOptions): Promise<IStartCallbackWindowResult>;
27
+ (url: string, options: Partial<IStartCallbackWindowOptions>): Promise<IStartCallbackWindowResult>;
26
28
  }
27
29
 
28
- export type { IStartCallbackWindow, IStartCallbackWindowOptions, IStartCallbackWindowResult };
30
+ declare const startCallbackWindow: IStartCallbackWindow;
31
+
32
+ export { type IStartCallbackWindow, type IStartCallbackWindowOptions, type IStartCallbackWindowResult, startCallbackWindow };
@@ -1,28 +1,32 @@
1
1
  interface IStartCallbackWindowOptions {
2
2
  /**
3
- * Url to open
3
+ * Time to close window in milliseconds
4
+ * @default Infinity
4
5
  */
5
- url: string;
6
+ timeout: number;
6
7
  /**
7
- * Time to close window in milliseconds
8
+ * Time to checking current url in milliseconds
9
+ * @default 100
8
10
  */
9
- timeout?: number;
11
+ interval: number;
10
12
  /**
11
13
  * The window checker should be closed. By default, the window will close when the origin of the window equals the origin of the parent window.
12
14
  * @param currentUrl - current url of the opened window
13
15
  */
14
- shouldClose?: (currentUrl: string) => boolean | Promise<boolean>;
16
+ shouldClose: (currentUrl: string) => boolean | Promise<boolean>;
15
17
  /**
16
18
  * What to do when browser does not allow opening new windows, by default will change the current window address to the destination address
17
19
  * @param url
18
20
  */
19
- onBrowserNotAllowed?: (url: string) => {};
21
+ onBrowserNotAllowed: (url: string) => void;
20
22
  }
21
23
  interface IStartCallbackWindowResult {
22
24
  redirectedUrl: string;
23
25
  }
24
26
  interface IStartCallbackWindow {
25
- (options: IStartCallbackWindowOptions): Promise<IStartCallbackWindowResult>;
27
+ (url: string, options: Partial<IStartCallbackWindowOptions>): Promise<IStartCallbackWindowResult>;
26
28
  }
27
29
 
28
- export type { IStartCallbackWindow, IStartCallbackWindowOptions, IStartCallbackWindowResult };
30
+ declare const startCallbackWindow: IStartCallbackWindow;
31
+
32
+ export { type IStartCallbackWindow, type IStartCallbackWindowOptions, type IStartCallbackWindowResult, startCallbackWindow };
package/dist/esm/index.js CHANGED
@@ -0,0 +1 @@
1
+ var d={onBrowserNotAllowed(t){window.location.href=t},shouldClose(t){return window.location.origin===new URL(t).origin},timeout:1/0,interval:100},f=(t,e)=>{let{onBrowserNotAllowed:i,shouldClose:l,timeout:n,interval:a}={...d,...e};return new Promise(async(w,s)=>{try{let r=window.open(t),c=Date.now();if(!r)return i(t);for(;;)try{let o=r.window.location.href;if(await Promise.resolve(l(o)))return w({redirectedUrl:o})}catch{}finally{if(n!==1/0){let o=Date.now();if(c+n>=o)throw new Error("Timeout")}if(r.closed)throw new Error("Window closed by user");await new Promise(o=>setTimeout(o,a))}}catch(r){s(new Error("Start callback window failed",{cause:r}))}})};export{f as startCallbackWindow};
package/package.json CHANGED
@@ -52,5 +52,5 @@
52
52
  "sideEffects": false,
53
53
  "type": "module",
54
54
  "types": "./dist/esm/index.d.ts",
55
- "version": "1.0.1-1"
55
+ "version": "1.0.1-2"
56
56
  }