@authing/native-js-ui-components 3.1.13-rc.8 → 3.1.15

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@authing/native-js-ui-components",
3
- "version": "3.1.13-rc.8",
3
+ "version": "3.1.15",
4
4
  "framework": "Native",
5
5
  "private": false,
6
6
  "main": "lib/index.min.js",
@@ -165,8 +165,8 @@
165
165
  "workbox-webpack-plugin": "5.1.4"
166
166
  },
167
167
  "dependencies": {
168
- "@authing/react-ui-components": "^3.1.13-rc.6",
168
+ "@authing/react-ui-components": "^3.1.15",
169
169
  "authing-js-sdk": "4.23.30-alpha.3"
170
170
  },
171
- "gitHead": "0f861e93c88d078836a93457e9eb1cbd2d74b7c0"
171
+ "gitHead": "e8c0c8a0537ae158c58225dafa0adc8e0055ed32"
172
172
  }
package/src/App.tsx CHANGED
@@ -1,8 +1,10 @@
1
1
  import React, { useEffect } from "react";
2
2
  import "./App.css";
3
- import { Guard, GuardMode } from "./components";
3
+ import { Guard, GuardEventsCamelToKebabMapping, GuardMode } from "./components";
4
4
 
5
5
  function App() {
6
+ console.log(GuardEventsCamelToKebabMapping);
7
+
6
8
  useEffect(() => {
7
9
  const guard = new Guard("6191cf610f772aa56dc70637", {
8
10
  target: ".App",
@@ -2,54 +2,20 @@ import React from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import { AuthingGuard as ReactAuthingGuard } from "@authing/react-ui-components";
4
4
  import {
5
- User,
6
5
  GuardMode,
7
6
  UserConfig,
8
- GuardScenes,
9
- LoginMethods,
10
- getAuthClient,
11
- CommonMessage,
12
- initAuthClient,
13
- RegisterMethods,
14
7
  GuardEventsHandler,
15
- AuthenticationClient,
16
8
  GuardEventsHandlerKebab,
17
9
  GuardEventsCamelToKebabMap,
18
10
  } from "@authing/react-ui-components";
19
11
  import "@authing/react-ui-components/lib/index.min.css";
20
12
 
21
- export type {
22
- User,
23
- UserConfig,
24
- CommonMessage,
25
- GuardEventsHandler,
26
- AuthenticationClient,
27
- GuardEventsHandlerKebab,
28
- };
29
-
30
- export {
31
- GuardMode,
32
- GuardScenes,
33
- LoginMethods,
34
- getAuthClient,
35
- initAuthClient,
36
- RegisterMethods,
37
- GuardEventsCamelToKebabMap,
38
- };
39
-
40
13
  export type EventListeners = {
41
- [key in keyof GuardEventsHandlerKebab]: Exclude<
42
- Required<GuardEventsHandlerKebab>[key],
43
- undefined
44
- >[];
14
+ [key in keyof GuardEventsHandlerKebab]: Exclude<Required<GuardEventsHandlerKebab>[key], undefined>[];
45
15
  };
46
16
 
47
17
  export class AuthingGuard {
48
- constructor(
49
- private appId: string,
50
- private config?: UserConfig,
51
- private tenantId?: string
52
- ) {
18
+ constructor(private appId: string, private config?: UserConfig, private tenantId?: string) {
53
19
  this.render();
54
20
  }
55
21
 
@@ -76,19 +42,14 @@ export class AuthingGuard {
76
42
 
77
43
  private visible = this.config?.mode === GuardMode.Modal ? false : true;
78
44
 
79
- private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
80
- (acc, evtName) => {
81
- return Object.assign({}, acc, {
82
- [evtName]: [],
83
- });
84
- },
85
- {} as EventListeners
86
- );
45
+ private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce((acc, evtName) => {
46
+ return Object.assign({}, acc, {
47
+ [evtName]: [],
48
+ });
49
+ }, {} as EventListeners);
87
50
 
88
51
  private render(cb?: () => void) {
89
- const evts: GuardEventsHandler = Object.entries(
90
- GuardEventsCamelToKebabMap
91
- ).reduce((acc, [reactEvt, nativeEvt]) => {
52
+ const evts: GuardEventsHandler = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [reactEvt, nativeEvt]) => {
92
53
  return Object.assign({}, acc, {
93
54
  [reactEvt]: (...rest: any) => {
94
55
  if (nativeEvt === "close") {
@@ -121,10 +82,7 @@ export class AuthingGuard {
121
82
  );
122
83
  }
123
84
 
124
- on<T extends keyof GuardEventsHandlerKebab>(
125
- evt: T,
126
- handler: Exclude<GuardEventsHandlerKebab[T], undefined>
127
- ) {
85
+ on<T extends keyof GuardEventsHandlerKebab>(evt: T, handler: Exclude<GuardEventsHandlerKebab[T], undefined>) {
128
86
  this.eventListeners[evt]!.push(handler as any);
129
87
  }
130
88
 
@@ -2,58 +2,69 @@ import React from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import { Guard as ReactAuthingGuard } from "@authing/react-ui-components";
4
4
  import {
5
- User,
6
5
  GuardMode,
7
- GuardScenes,
8
- LoginMethods,
9
- getAuthClient,
10
- CommonMessage,
11
- initAuthClient,
12
- RegisterMethods,
13
- GuardEventsHandler,
6
+ GuardEvents,
14
7
  AuthenticationClient,
15
- GuardEventsHandlerKebab,
16
- GuardEventsCamelToKebabMap,
8
+ GuardEventsKebabToCamelType,
9
+ GuardEventsCamelToKebabMapping,
17
10
  } from "@authing/react-ui-components";
18
11
  import "@authing/react-ui-components/lib/index.min.css";
19
- import {
20
- GuardComponentConfig,
21
- GuardLocalConfig,
22
- } from "@authing/react-ui-components/components/Guard/config";
23
- import { GuardEvents } from "@authing/react-ui-components/components/Guard/event";
24
-
25
- export type {
26
- User,
27
- CommonMessage,
28
- GuardEventsHandler,
29
- AuthenticationClient,
30
- GuardEventsHandlerKebab,
31
- };
12
+ import { GuardComponentConfig, GuardLocalConfig } from "@authing/react-ui-components/components/Guard/config";
32
13
 
33
- export {
34
- GuardMode,
35
- GuardScenes,
36
- LoginMethods,
37
- getAuthClient,
38
- initAuthClient,
39
- RegisterMethods,
40
- GuardEventsCamelToKebabMap,
41
- };
14
+ export interface NativeGuardProps {
15
+ appId?: string;
16
+ config?: Partial<GuardLocalConfig>;
17
+ tenantId?: string;
18
+ authClient?: AuthenticationClient;
19
+ }
20
+
21
+ export interface NativeGuardConstructor {
22
+ (
23
+ appId?: string | NativeGuardProps,
24
+ config?: Partial<GuardLocalConfig>,
25
+ tenantId?: string,
26
+ authClient?: AuthenticationClient
27
+ ): void;
28
+
29
+ (props: NativeGuardProps): void;
30
+ }
42
31
 
43
32
  export type GuardEventListeners = {
44
- [key in keyof GuardEventsHandlerKebab]: Exclude<
45
- Required<GuardEventsHandlerKebab>[key],
46
- undefined
47
- >[];
33
+ [key in keyof GuardEventsKebabToCamelType]: Exclude<Required<GuardEventsKebabToCamelType>[key], undefined>[];
48
34
  };
49
35
 
50
36
  export class Guard {
37
+ private appId?: string;
38
+ private config?: Partial<GuardLocalConfig>;
39
+ private tenantId?: string;
40
+ private authClient?: AuthenticationClient;
41
+
42
+ private visible?: boolean;
43
+
44
+ constructor(props?: NativeGuardProps);
45
+ constructor(appId?: string, config?: Partial<GuardLocalConfig>, tenantId?: string, authClient?: AuthenticationClient);
46
+
51
47
  constructor(
52
- private appId?: string,
53
- private config?: Partial<GuardLocalConfig>,
54
- private tenantId?: string,
55
- private authClient?: AuthenticationClient
48
+ appIdOrProps?: string | NativeGuardProps,
49
+ config?: Partial<GuardLocalConfig>,
50
+ tenantId?: string,
51
+ authClient?: AuthenticationClient
56
52
  ) {
53
+ if (appIdOrProps && typeof appIdOrProps !== "string") {
54
+ const { appId, config: configProps, tenantId: tenantIdProps, authClient: authClientProps } = appIdOrProps;
55
+ this.appId = appId;
56
+ this.config = configProps;
57
+ this.tenantId = tenantIdProps;
58
+ this.authClient = authClientProps;
59
+ } else {
60
+ this.appId = appIdOrProps;
61
+ this.config = config;
62
+ this.tenantId = tenantId;
63
+ this.authClient = authClient;
64
+ }
65
+
66
+ this.visible = this.config?.mode === GuardMode.Modal ? false : true;
67
+
57
68
  this.render();
58
69
  }
59
70
 
@@ -78,21 +89,14 @@ export class Guard {
78
89
  return selector;
79
90
  }
80
91
 
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
- );
92
+ private eventListeners = Object.values(GuardEventsCamelToKebabMapping).reduce((acc, evtName) => {
93
+ return Object.assign({}, acc, {
94
+ [evtName as string]: [],
95
+ });
96
+ }, {} as GuardEventListeners);
91
97
 
92
98
  private render(cb?: () => void) {
93
- const evts: GuardEventsHandler = Object.entries(
94
- GuardEventsCamelToKebabMap
95
- ).reduce((acc, [reactEvt, nativeEvt]) => {
99
+ const evts: GuardEvents = Object.entries(GuardEventsCamelToKebabMapping).reduce((acc, [reactEvt, nativeEvt]) => {
96
100
  return Object.assign({}, acc, {
97
101
  [reactEvt]: (...rest: any) => {
98
102
  if (nativeEvt === "close") {
@@ -101,7 +105,7 @@ export class Guard {
101
105
 
102
106
  // TODO 返回最后一个执行函数的值,实际应该只让监听一次
103
107
  return (
104
- this.eventListeners[nativeEvt]
108
+ (this.eventListeners as any)[nativeEvt as string]
105
109
  // @ts-ignore
106
110
  .map((item: any) => {
107
111
  return item(...rest);
@@ -110,7 +114,7 @@ export class Guard {
110
114
  );
111
115
  },
112
116
  });
113
- }, {} as GuardEventsHandler);
117
+ }, {} as GuardEvents);
114
118
 
115
119
  return ReactDOM.render(
116
120
  <ReactAuthingGuard
@@ -126,11 +130,8 @@ export class Guard {
126
130
  );
127
131
  }
128
132
 
129
- on<T extends keyof GuardEventsHandlerKebab>(
130
- evt: T,
131
- handler: Exclude<GuardEventsHandlerKebab[T], undefined>
132
- ) {
133
- this.eventListeners[evt]!.push(handler as any);
133
+ on<T extends keyof GuardEventsKebabToCamelType>(evt: T, handler: Exclude<GuardEventsKebabToCamelType[T], undefined>) {
134
+ (this.eventListeners as any)[evt]!.push(handler as any);
134
135
  }
135
136
 
136
137
  show() {
@@ -1,7 +1,49 @@
1
1
  // export * from "./Guard";
2
2
  import { Guard } from "./Guard";
3
- import { GuardConfig, GuardLocalConfig } from "@authing/react-ui-components";
4
- export * from "./AuthingGuard";
3
+ import { AuthingGuard } from "./AuthingGuard";
5
4
 
6
- export { Guard };
7
- export type { GuardConfig, GuardLocalConfig };
5
+ import {
6
+ User,
7
+ GuardMode,
8
+ UserConfig,
9
+ GuardScenes,
10
+ LoginMethods,
11
+ getAuthClient,
12
+ CommonMessage,
13
+ initAuthClient,
14
+ RegisterMethods,
15
+ GuardEventsHandler,
16
+ AuthenticationClient,
17
+ GuardEventsHandlerKebab,
18
+ GuardEventsCamelToKebabMap,
19
+ GuardEvents,
20
+ GuardEventsKebabToCamelType,
21
+ GuardEventsCamelToKebabMapping,
22
+ GuardConfig,
23
+ GuardLocalConfig,
24
+ } from "@authing/react-ui-components";
25
+
26
+ export {
27
+ Guard,
28
+ AuthingGuard,
29
+ GuardMode,
30
+ GuardScenes,
31
+ LoginMethods,
32
+ getAuthClient,
33
+ initAuthClient,
34
+ RegisterMethods,
35
+ GuardEventsCamelToKebabMap,
36
+ GuardEventsCamelToKebabMapping,
37
+ };
38
+ export type {
39
+ GuardConfig,
40
+ GuardLocalConfig,
41
+ GuardEvents,
42
+ User,
43
+ UserConfig,
44
+ CommonMessage,
45
+ GuardEventsHandler,
46
+ AuthenticationClient,
47
+ GuardEventsHandlerKebab,
48
+ GuardEventsKebabToCamelType,
49
+ };