@thangved/callback-window 1.1.0 → 1.1.1

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/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Callback window
2
+
3
+ > A simple handler for external website window callback
4
+
5
+ ## Install
6
+
7
+ Install this package via npm
8
+
9
+ ```sh
10
+ npm i @thangved/callback-window
11
+ ```
12
+
13
+ Or via yarn
14
+
15
+ ```sh
16
+ yarn add @thangved/callback-window
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { startCallbackWindow } from '@thangved/callback-window';
23
+
24
+ const handleCallback = async () => {
25
+ try {
26
+ const { redirectedUrl } = await startCallbackWindow(
27
+ 'https://redirect.thangved.com/?redirect_uri=https://profile.thangved.com',
28
+ );
29
+
30
+ console.log(redirectedUrl); // https://profile.thangved.com
31
+ } catch (error) {
32
+ console.log(error);
33
+ }
34
+ };
35
+ ```
36
+
37
+ ## Options
38
+
39
+ | Option | Type | Default | Description |
40
+ | --------------------- | ----------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | `timeout` | `number` | `Infinity` | Time to close window in milliseconds |
42
+ | `interval` | `number` | `100` | Time to check current URL in milliseconds |
43
+ | `shouldClose` | `(currentUrl: string) => boolean \| Promise<boolean>` | – | 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 |
44
+ | `onBrowserNotAllowed` | `(url: string) => void` | – | What to do when the browser does not allow opening new windows; by default changes the current window address to the destination address |
@@ -24,7 +24,7 @@ interface IStartCallbackWindowResult {
24
24
  redirectedUrl: string;
25
25
  }
26
26
  interface IStartCallbackWindow {
27
- (url: string, options: Partial<IStartCallbackWindowOptions>): Promise<IStartCallbackWindowResult>;
27
+ (url: string, options?: Partial<IStartCallbackWindowOptions>): Promise<IStartCallbackWindowResult>;
28
28
  }
29
29
 
30
30
  declare const startCallbackWindow: IStartCallbackWindow;
@@ -24,7 +24,7 @@ interface IStartCallbackWindowResult {
24
24
  redirectedUrl: string;
25
25
  }
26
26
  interface IStartCallbackWindow {
27
- (url: string, options: Partial<IStartCallbackWindowOptions>): Promise<IStartCallbackWindowResult>;
27
+ (url: string, options?: Partial<IStartCallbackWindowOptions>): Promise<IStartCallbackWindowResult>;
28
28
  }
29
29
 
30
30
  declare const startCallbackWindow: IStartCallbackWindow;
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "files": [
29
29
  "dist"
30
30
  ],
31
- "homepage": "https://github.com/thangved/callback-window#readme",
31
+ "homepage": "https://github.com/thangved/callback-window/packages/callback-window#readme",
32
32
  "keywords": [
33
33
  "js"
34
34
  ],
@@ -52,5 +52,5 @@
52
52
  "sideEffects": false,
53
53
  "type": "module",
54
54
  "types": "./dist/esm/index.d.ts",
55
- "version": "1.1.0"
55
+ "version": "1.1.1"
56
56
  }