@authing/native-js-ui-components 3.1.1 → 3.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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@authing/native-js-ui-components",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
+ "framework": "Native",
4
5
  "private": false,
5
6
  "main": "lib/index.min.js",
6
7
  "typings": "lib/index.d.ts",
7
8
  "dependencies": {
8
- "@authing/react-ui-components": "^3.1.1",
9
+ "@authing/react-ui-components": "^3.1.2",
9
10
  "react": "16.14.0",
10
11
  "react-dom": "16.14.0"
11
12
  },
@@ -165,6 +166,5 @@
165
166
  "webpack-dev-server": "3.11.0",
166
167
  "webpack-manifest-plugin": "2.2.0",
167
168
  "workbox-webpack-plugin": "5.1.4"
168
- },
169
- "gitHead": "2fd4f4170d33b498f325dd026a727bd021f0cf32"
169
+ }
170
170
  }
package/src/App.tsx CHANGED
@@ -1,18 +1,13 @@
1
1
  import React, { useEffect } from "react";
2
2
  import "./App.css";
3
- import { AuthingGuard, GuardMode } from "./components";
3
+ import { Guard, GuardMode } from "./components";
4
4
 
5
5
  function App() {
6
6
  useEffect(() => {
7
- const guard = new AuthingGuard(
8
- "6191cf610f772aa56dc70637",
9
- {
10
- target: ".App",
11
- appHost: "https://core.dev2.authing-inc.co/",
12
- mode: GuardMode.Modal,
13
- },
14
- "6194a41abf23c1d5268b362a"
15
- );
7
+ const guard = new Guard("6191cf610f772aa56dc70637", {
8
+ target: ".App",
9
+ mode: GuardMode.Modal,
10
+ });
16
11
 
17
12
  // @ts-ignore
18
13
  window.guard = guard;
@@ -40,11 +40,18 @@ export {
40
40
  };
41
41
 
42
42
  export type EventListeners = {
43
- [key in keyof GuardEventsHandlerKebab]: Exclude<Required<GuardEventsHandlerKebab>[key], undefined>[];
43
+ [key in keyof GuardEventsHandlerKebab]: Exclude<
44
+ Required<GuardEventsHandlerKebab>[key],
45
+ undefined
46
+ >[];
44
47
  };
45
48
 
46
49
  export class AuthingGuard {
47
- constructor(private appId: string, private config?: UserConfig, private tenantId?: string) {
50
+ constructor(
51
+ private appId: string,
52
+ private config?: UserConfig,
53
+ private tenantId?: string
54
+ ) {
48
55
  this.render();
49
56
  }
50
57
 
@@ -71,14 +78,19 @@ export class AuthingGuard {
71
78
 
72
79
  private visible = this.config?.mode === GuardMode.Modal ? false : true;
73
80
 
74
- private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce((acc, evtName) => {
75
- return Object.assign({}, acc, {
76
- [evtName]: [],
77
- });
78
- }, {} as EventListeners);
81
+ private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
82
+ (acc, evtName) => {
83
+ return Object.assign({}, acc, {
84
+ [evtName]: [],
85
+ });
86
+ },
87
+ {} as EventListeners
88
+ );
79
89
 
80
90
  private render(cb?: () => void) {
81
- const evts: GuardEventsHandler = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [reactEvt, nativeEvt]) => {
91
+ const evts: GuardEventsHandler = Object.entries(
92
+ GuardEventsCamelToKebabMap
93
+ ).reduce((acc, [reactEvt, nativeEvt]) => {
82
94
  return Object.assign({}, acc, {
83
95
  [reactEvt]: (...rest: any) => {
84
96
  if (nativeEvt === "close") {
@@ -111,7 +123,10 @@ export class AuthingGuard {
111
123
  );
112
124
  }
113
125
 
114
- on<T extends keyof GuardEventsHandlerKebab>(evt: T, handler: Exclude<GuardEventsHandlerKebab[T], undefined>) {
126
+ on<T extends keyof GuardEventsHandlerKebab>(
127
+ evt: T,
128
+ handler: Exclude<GuardEventsHandlerKebab[T], undefined>
129
+ ) {
115
130
  this.eventListeners[evt]!.push(handler as any);
116
131
  }
117
132
 
@@ -0,0 +1,143 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom";
3
+ import { Guard as ReactAuthingGuard } from "@authing/react-ui-components";
4
+ import {
5
+ User,
6
+ GuardMode,
7
+ GuardScenes,
8
+ LoginMethods,
9
+ getAuthClient,
10
+ CommonMessage,
11
+ initAuthClient,
12
+ RegisterMethods,
13
+ GuardEventsHandler,
14
+ AuthenticationClient,
15
+ GuardEventsHandlerKebab,
16
+ GuardEventsCamelToKebabMap,
17
+ AuthenticationClientOptions,
18
+ } from "@authing/react-ui-components";
19
+ import "@authing/react-ui-components/lib/index.min.css";
20
+ import {
21
+ GuardComponentConfig,
22
+ GuardLocalConfig,
23
+ } from "@authing/react-ui-components/components/Guard/config";
24
+ import { GuardEvents } from "@authing/react-ui-components/components/Guard/event";
25
+
26
+ export type {
27
+ User,
28
+ CommonMessage,
29
+ GuardEventsHandler,
30
+ AuthenticationClient,
31
+ GuardEventsHandlerKebab,
32
+ AuthenticationClientOptions,
33
+ };
34
+
35
+ export {
36
+ GuardMode,
37
+ GuardScenes,
38
+ LoginMethods,
39
+ getAuthClient,
40
+ initAuthClient,
41
+ RegisterMethods,
42
+ GuardEventsCamelToKebabMap,
43
+ };
44
+
45
+ export type GuardEventListeners = {
46
+ [key in keyof GuardEventsHandlerKebab]: Exclude<
47
+ Required<GuardEventsHandlerKebab>[key],
48
+ undefined
49
+ >[];
50
+ };
51
+
52
+ export class Guard {
53
+ constructor(
54
+ private appId: string,
55
+ private config?: Partial<GuardLocalConfig>
56
+ ) {
57
+ this.render();
58
+ }
59
+
60
+ static getGuardContainer(selector?: string | HTMLElement) {
61
+ const defaultId = "authing_guard_container";
62
+
63
+ if (!selector) {
64
+ let container = document.querySelector(`#${defaultId}`);
65
+ if (!container) {
66
+ container = document.createElement("div");
67
+ container.id = defaultId;
68
+ document.body.appendChild(container);
69
+ }
70
+
71
+ return container;
72
+ }
73
+
74
+ if (typeof selector === "string") {
75
+ return document.querySelector(selector);
76
+ }
77
+
78
+ return selector;
79
+ }
80
+
81
+ private visible = this.config?.mode === GuardMode.Modal ? false : true;
82
+
83
+ private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
84
+ (acc, evtName) => {
85
+ return Object.assign({}, acc, {
86
+ [evtName]: [],
87
+ });
88
+ },
89
+ {} as GuardEventListeners
90
+ );
91
+
92
+ private render(cb?: () => void) {
93
+ const evts: GuardEventsHandler = Object.entries(
94
+ GuardEventsCamelToKebabMap
95
+ ).reduce((acc, [reactEvt, nativeEvt]) => {
96
+ return Object.assign({}, acc, {
97
+ [reactEvt]: (...rest: any) => {
98
+ if (nativeEvt === "close") {
99
+ this.hide();
100
+ }
101
+
102
+ // TODO 返回最后一个执行函数的值,实际应该只让监听一次
103
+ return (
104
+ this.eventListeners[nativeEvt]
105
+ // @ts-ignore
106
+ .map((item: any) => {
107
+ return item(...rest);
108
+ })
109
+ .slice(-1)[0] ?? true
110
+ );
111
+ },
112
+ });
113
+ }, {} as GuardEventsHandler);
114
+
115
+ return ReactDOM.render(
116
+ <ReactAuthingGuard
117
+ {...(evts as GuardEvents)}
118
+ appId={this.appId}
119
+ config={this.config as GuardComponentConfig}
120
+ visible={this.visible}
121
+ />,
122
+ Guard.getGuardContainer(this.config?.target),
123
+ cb
124
+ );
125
+ }
126
+
127
+ on<T extends keyof GuardEventsHandlerKebab>(
128
+ evt: T,
129
+ handler: Exclude<GuardEventsHandlerKebab[T], undefined>
130
+ ) {
131
+ this.eventListeners[evt]!.push(handler as any);
132
+ }
133
+
134
+ show() {
135
+ this.visible = true;
136
+ this.render();
137
+ }
138
+
139
+ hide() {
140
+ this.visible = false;
141
+ this.render();
142
+ }
143
+ }
@@ -1 +1,7 @@
1
- export * from './AuthingGuard'
1
+ // export * from "./Guard";
2
+ import { Guard } from "./Guard";
3
+ import { GuardConfig, GuardLocalConfig } from "@authing/react-ui-components";
4
+ export * from "./AuthingGuard";
5
+
6
+ export { Guard };
7
+ export type { GuardConfig, GuardLocalConfig };
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Authing
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.