@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.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.d.cts +12 -8
- package/dist/esm/index.d.ts +12 -8
- package/dist/esm/index.js +1 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
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}))}})};
|
package/dist/cjs/index.d.cts
CHANGED
@@ -1,28 +1,32 @@
|
|
1
1
|
interface IStartCallbackWindowOptions {
|
2
2
|
/**
|
3
|
-
*
|
3
|
+
* Time to close window in milliseconds
|
4
|
+
* @default Infinity
|
4
5
|
*/
|
5
|
-
|
6
|
+
timeout: number;
|
6
7
|
/**
|
7
|
-
* Time to
|
8
|
+
* Time to checking current url in milliseconds
|
9
|
+
* @default 100
|
8
10
|
*/
|
9
|
-
|
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
|
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
|
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
|
-
|
30
|
+
declare const startCallbackWindow: IStartCallbackWindow;
|
31
|
+
|
32
|
+
export { type IStartCallbackWindow, type IStartCallbackWindowOptions, type IStartCallbackWindowResult, startCallbackWindow };
|
package/dist/esm/index.d.ts
CHANGED
@@ -1,28 +1,32 @@
|
|
1
1
|
interface IStartCallbackWindowOptions {
|
2
2
|
/**
|
3
|
-
*
|
3
|
+
* Time to close window in milliseconds
|
4
|
+
* @default Infinity
|
4
5
|
*/
|
5
|
-
|
6
|
+
timeout: number;
|
6
7
|
/**
|
7
|
-
* Time to
|
8
|
+
* Time to checking current url in milliseconds
|
9
|
+
* @default 100
|
8
10
|
*/
|
9
|
-
|
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
|
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
|
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
|
-
|
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