@authing/native-js-ui-components 3.1.13 → 3.1.21

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",
3
+ "version": "3.1.21",
4
4
  "framework": "Native",
5
5
  "private": false,
6
6
  "main": "lib/index.min.js",
@@ -91,7 +91,6 @@
91
91
  ]
92
92
  },
93
93
  "devDependencies": {
94
- "@authing/react-ui-components": "^3.1.13",
95
94
  "@babel/core": "7.12.3",
96
95
  "@pmmmwh/react-refresh-webpack-plugin": "0.4.2",
97
96
  "@svgr/webpack": "5.4.0",
@@ -165,5 +164,9 @@
165
164
  "webpack-manifest-plugin": "2.2.0",
166
165
  "workbox-webpack-plugin": "5.1.4"
167
166
  },
168
- "gitHead": "5c1cc892173eb0e95dee392edd648c6c57397999"
167
+ "dependencies": {
168
+ "@authing/react-ui-components": "^3.1.21",
169
+ "authing-js-sdk": "4.23.30-alpha.3"
170
+ },
171
+ "gitHead": "493b1ecd80bab9a0c0b9f5225d80ae7b1bc74f73"
169
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,56 +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
- AuthenticationClientOptions,
19
10
  } from "@authing/react-ui-components";
20
11
  import "@authing/react-ui-components/lib/index.min.css";
21
12
 
22
- export type {
23
- User,
24
- UserConfig,
25
- CommonMessage,
26
- GuardEventsHandler,
27
- AuthenticationClient,
28
- GuardEventsHandlerKebab,
29
- AuthenticationClientOptions,
30
- };
31
-
32
- export {
33
- GuardMode,
34
- GuardScenes,
35
- LoginMethods,
36
- getAuthClient,
37
- initAuthClient,
38
- RegisterMethods,
39
- GuardEventsCamelToKebabMap,
40
- };
41
-
42
13
  export type EventListeners = {
43
- [key in keyof GuardEventsHandlerKebab]: Exclude<
44
- Required<GuardEventsHandlerKebab>[key],
45
- undefined
46
- >[];
14
+ [key in keyof GuardEventsHandlerKebab]: Exclude<Required<GuardEventsHandlerKebab>[key], undefined>[];
47
15
  };
48
16
 
49
17
  export class AuthingGuard {
50
- constructor(
51
- private appId: string,
52
- private config?: UserConfig,
53
- private tenantId?: string
54
- ) {
18
+ constructor(private appId: string, private config?: UserConfig, private tenantId?: string) {
55
19
  this.render();
56
20
  }
57
21
 
@@ -78,19 +42,14 @@ export class AuthingGuard {
78
42
 
79
43
  private visible = this.config?.mode === GuardMode.Modal ? false : true;
80
44
 
81
- private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
82
- (acc, evtName) => {
83
- return Object.assign({}, acc, {
84
- [evtName]: [],
85
- });
86
- },
87
- {} as EventListeners
88
- );
45
+ private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce((acc, evtName) => {
46
+ return Object.assign({}, acc, {
47
+ [evtName]: [],
48
+ });
49
+ }, {} as EventListeners);
89
50
 
90
51
  private render(cb?: () => void) {
91
- const evts: GuardEventsHandler = Object.entries(
92
- GuardEventsCamelToKebabMap
93
- ).reduce((acc, [reactEvt, nativeEvt]) => {
52
+ const evts: GuardEventsHandler = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [reactEvt, nativeEvt]) => {
94
53
  return Object.assign({}, acc, {
95
54
  [reactEvt]: (...rest: any) => {
96
55
  if (nativeEvt === "close") {
@@ -123,10 +82,7 @@ export class AuthingGuard {
123
82
  );
124
83
  }
125
84
 
126
- on<T extends keyof GuardEventsHandlerKebab>(
127
- evt: T,
128
- handler: Exclude<GuardEventsHandlerKebab[T], undefined>
129
- ) {
85
+ on<T extends keyof GuardEventsHandlerKebab>(evt: T, handler: Exclude<GuardEventsHandlerKebab[T], undefined>) {
130
86
  this.eventListeners[evt]!.push(handler as any);
131
87
  }
132
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,
17
- AuthenticationClientOptions,
8
+ GuardEventsKebabToCamelType,
9
+ GuardEventsCamelToKebabMapping,
18
10
  } from "@authing/react-ui-components";
19
11
  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
- };
12
+ import { GuardComponentConfig, GuardLocalConfig } from "@authing/react-ui-components/components/Guard/config";
34
13
 
35
- export {
36
- GuardMode,
37
- GuardScenes,
38
- LoginMethods,
39
- getAuthClient,
40
- initAuthClient,
41
- RegisterMethods,
42
- GuardEventsCamelToKebabMap,
43
- };
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
+ }
44
31
 
45
32
  export type GuardEventListeners = {
46
- [key in keyof GuardEventsHandlerKebab]: Exclude<
47
- Required<GuardEventsHandlerKebab>[key],
48
- undefined
49
- >[];
33
+ [key in keyof GuardEventsKebabToCamelType]: Exclude<Required<GuardEventsKebabToCamelType>[key], undefined>[];
50
34
  };
51
35
 
52
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
+
53
47
  constructor(
54
- private appId: string,
55
- private config?: Partial<GuardLocalConfig>
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
@@ -118,17 +122,16 @@ export class Guard {
118
122
  appId={this.appId}
119
123
  config={this.config as GuardComponentConfig}
120
124
  visible={this.visible}
125
+ tenantId={this.tenantId}
126
+ authClient={this.authClient}
121
127
  />,
122
128
  Guard.getGuardContainer(this.config?.target),
123
129
  cb
124
130
  );
125
131
  }
126
132
 
127
- on<T extends keyof GuardEventsHandlerKebab>(
128
- evt: T,
129
- handler: Exclude<GuardEventsHandlerKebab[T], undefined>
130
- ) {
131
- 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);
132
135
  }
133
136
 
134
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
+ };