@authing/native-js-ui-components 4.4.2 → 4.5.0-alpha.0

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/scripts/lib.js DELETED
@@ -1,200 +0,0 @@
1
- // Do this as the first thing so that any code reading it knows the right env.
2
- process.env.BABEL_ENV = 'production'
3
- process.env.NODE_ENV = 'production'
4
-
5
- // Makes the script crash on unhandled rejections instead of silently
6
- // ignoring them. In the future, promise rejections that are not handled will
7
- // terminate the Node.js process with a non-zero exit code.
8
- process.on('unhandledRejection', (err) => {
9
- throw err
10
- })
11
-
12
- // Ensure environment variables are read.
13
- require('../config/env')
14
-
15
- const path = require('path')
16
- const chalk = require('react-dev-utils/chalk')
17
- const fs = require('fs-extra')
18
- const bfj = require('bfj')
19
- const webpack = require('webpack')
20
- const configFactory = require('../config/webpack.config')
21
- const paths = require('../config/paths')
22
- const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles')
23
- const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')
24
- const printHostingInstructions = require('react-dev-utils/printHostingInstructions')
25
- const FileSizeReporter = require('react-dev-utils/FileSizeReporter')
26
- const printBuildError = require('react-dev-utils/printBuildError')
27
-
28
- const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild
29
- const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild
30
- const useYarn = fs.existsSync(paths.yarnLockFile)
31
-
32
- // These sizes are pretty large. We'll warn for bundles exceeding them.
33
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024
34
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024
35
-
36
- const isInteractive = process.stdout.isTTY
37
-
38
- // Warn and crash if required files are missing
39
- if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
40
- process.exit(1)
41
- }
42
-
43
- const argv = process.argv.slice(2)
44
- const writeStatsJson = argv.indexOf('--stats') !== -1
45
-
46
- // Generate configuration
47
- const config = configFactory('lib')
48
-
49
- // We require that you explicitly set browsers and do not fall back to
50
- // browserslist defaults.
51
- const { checkBrowsers } = require('react-dev-utils/browsersHelper')
52
- checkBrowsers(paths.appPath, isInteractive)
53
- .then(() => {
54
- // First, read the current file sizes in build directory.
55
- // This lets us display how much they changed later.
56
- return measureFileSizesBeforeBuild(paths.libBuild)
57
- })
58
- .then((previousFileSizes) => {
59
- // Remove all content but keep the directory so that
60
- // if you're in it, you don't end up in Trash
61
- fs.emptyDirSync(paths.libBuild)
62
- // Merge with the public folder
63
- // Start the webpack build
64
- return build(previousFileSizes)
65
- })
66
- .then(
67
- ({ stats, previousFileSizes, warnings }) => {
68
- if (warnings.length) {
69
- console.log(chalk.yellow('Compiled with warnings.\n'))
70
- console.log(warnings.join('\n\n'))
71
- console.log(
72
- '\nSearch for the ' +
73
- chalk.underline(chalk.yellow('keywords')) +
74
- ' to learn more about each warning.'
75
- )
76
- console.log(
77
- 'To ignore, add ' +
78
- chalk.cyan('// eslint-disable-next-line') +
79
- ' to the line before.\n'
80
- )
81
- } else {
82
- console.log(chalk.green('Compiled successfully.\n'))
83
- }
84
-
85
- console.log('File sizes after gzip:\n')
86
- printFileSizesAfterBuild(
87
- stats,
88
- previousFileSizes,
89
- paths.libBuild,
90
- WARN_AFTER_BUNDLE_GZIP_SIZE,
91
- WARN_AFTER_CHUNK_GZIP_SIZE
92
- )
93
- console.log()
94
-
95
- const appPackage = require(paths.appPackageJson)
96
- const publicUrl = paths.publicUrlOrPath
97
- const publicPath = config.output.publicPath
98
- const buildFolder = path.relative(process.cwd(), paths.libBuild)
99
- printHostingInstructions(
100
- appPackage,
101
- publicUrl,
102
- publicPath,
103
- buildFolder,
104
- useYarn
105
- )
106
- },
107
- (err) => {
108
- const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true'
109
- if (tscCompileOnError) {
110
- console.log(
111
- chalk.yellow(
112
- 'Compiled with the following type errors (you may want to check these before deploying your app):\n'
113
- )
114
- )
115
- printBuildError(err)
116
- } else {
117
- console.log(chalk.red('Failed to compile.\n'))
118
- printBuildError(err)
119
- process.exit(1)
120
- }
121
- }
122
- )
123
- .catch((err) => {
124
- if (err && err.message) {
125
- console.log(err.message)
126
- }
127
- process.exit(1)
128
- })
129
-
130
- // Create the production build and print the deployment instructions.
131
- function build(previousFileSizes) {
132
- console.log('Creating an optimized production build...')
133
-
134
- const compiler = webpack(config)
135
- return new Promise((resolve, reject) => {
136
- compiler.run((err, stats) => {
137
- let messages
138
- if (err) {
139
- if (!err.message) {
140
- return reject(err)
141
- }
142
-
143
- let errMessage = err.message
144
-
145
- // Add additional information for postcss errors
146
- if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
147
- errMessage +=
148
- '\nCompileError: Begins at CSS selector ' +
149
- err['postcssNode'].selector
150
- }
151
-
152
- messages = formatWebpackMessages({
153
- errors: [errMessage],
154
- warnings: [],
155
- })
156
- } else {
157
- messages = formatWebpackMessages(
158
- stats.toJson({ all: false, warnings: true, errors: true })
159
- )
160
- }
161
- if (messages.errors.length) {
162
- // Only keep the first error. Others are often indicative
163
- // of the same problem, but confuse the reader with noise.
164
- if (messages.errors.length > 1) {
165
- messages.errors.length = 1
166
- }
167
- return reject(new Error(messages.errors.join('\n\n')))
168
- }
169
- if (
170
- process.env.CI &&
171
- (typeof process.env.CI !== 'string' ||
172
- process.env.CI.toLowerCase() !== 'false') &&
173
- messages.warnings.length
174
- ) {
175
- console.log(
176
- chalk.yellow(
177
- '\nTreating warnings as errors because process.env.CI = true.\n' +
178
- 'Most CI servers set it automatically.\n'
179
- )
180
- )
181
- return reject(new Error(messages.warnings.join('\n\n')))
182
- }
183
-
184
- const resolveArgs = {
185
- stats,
186
- previousFileSizes,
187
- warnings: messages.warnings,
188
- }
189
-
190
- if (writeStatsJson) {
191
- return bfj
192
- .write(paths.libBuild + '/bundle-stats.json', stats.toJson())
193
- .then(() => resolve(resolveArgs))
194
- .catch((error) => reject(new Error(error)))
195
- }
196
-
197
- return resolve(resolveArgs)
198
- })
199
- })
200
- }
package/scripts/start.js DELETED
@@ -1,166 +0,0 @@
1
- 'use strict';
2
-
3
- // Do this as the first thing so that any code reading it knows the right env.
4
- process.env.BABEL_ENV = 'development';
5
- process.env.NODE_ENV = 'development';
6
-
7
- // Makes the script crash on unhandled rejections instead of silently
8
- // ignoring them. In the future, promise rejections that are not handled will
9
- // terminate the Node.js process with a non-zero exit code.
10
- process.on('unhandledRejection', err => {
11
- throw err;
12
- });
13
-
14
- // Ensure environment variables are read.
15
- require('../config/env');
16
-
17
-
18
- const fs = require('fs');
19
- const chalk = require('react-dev-utils/chalk');
20
- const webpack = require('webpack');
21
- const WebpackDevServer = require('webpack-dev-server');
22
- const clearConsole = require('react-dev-utils/clearConsole');
23
- const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
24
- const {
25
- choosePort,
26
- createCompiler,
27
- prepareProxy,
28
- prepareUrls,
29
- } = require('react-dev-utils/WebpackDevServerUtils');
30
- const openBrowser = require('react-dev-utils/openBrowser');
31
- const semver = require('semver');
32
- const paths = require('../config/paths');
33
- const configFactory = require('../config/webpack.config');
34
- const createDevServerConfig = require('../config/webpackDevServer.config');
35
- const getClientEnvironment = require('../config/env');
36
- const react = require(require.resolve('react', { paths: [paths.appPath] }));
37
-
38
- const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
39
- const useYarn = fs.existsSync(paths.yarnLockFile);
40
- const isInteractive = process.stdout.isTTY;
41
-
42
- // Warn and crash if required files are missing
43
- if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
44
- process.exit(1);
45
- }
46
-
47
- // Tools like Cloud9 rely on this.
48
- const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
49
- const HOST = process.env.HOST || '0.0.0.0';
50
-
51
- if (process.env.HOST) {
52
- console.log(
53
- chalk.cyan(
54
- `Attempting to bind to HOST environment variable: ${chalk.yellow(
55
- chalk.bold(process.env.HOST)
56
- )}`
57
- )
58
- );
59
- console.log(
60
- `If this was unintentional, check that you haven't mistakenly set it in your shell.`
61
- );
62
- console.log(
63
- `Learn more here: ${chalk.yellow('https://cra.link/advanced-config')}`
64
- );
65
- console.log();
66
- }
67
-
68
- // We require that you explicitly set browsers and do not fall back to
69
- // browserslist defaults.
70
- const { checkBrowsers } = require('react-dev-utils/browsersHelper');
71
- checkBrowsers(paths.appPath, isInteractive)
72
- .then(() => {
73
- // We attempt to use the default port but if it is busy, we offer the user to
74
- // run on a different port. `choosePort()` Promise resolves to the next free port.
75
- return choosePort(HOST, DEFAULT_PORT);
76
- })
77
- .then(port => {
78
- if (port == null) {
79
- // We have not found a port.
80
- return;
81
- }
82
-
83
- const config = configFactory('development');
84
- const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
85
- const appName = require(paths.appPackageJson).name;
86
-
87
- const useTypeScript = fs.existsSync(paths.appTsConfig);
88
- const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
89
- const urls = prepareUrls(
90
- protocol,
91
- HOST,
92
- port,
93
- paths.publicUrlOrPath.slice(0, -1)
94
- );
95
- const devSocket = {
96
- warnings: warnings =>
97
- devServer.sockWrite(devServer.sockets, 'warnings', warnings),
98
- errors: errors =>
99
- devServer.sockWrite(devServer.sockets, 'errors', errors),
100
- };
101
- // Create a webpack compiler that is configured with custom messages.
102
- const compiler = createCompiler({
103
- appName,
104
- config,
105
- devSocket,
106
- urls,
107
- useYarn,
108
- useTypeScript,
109
- tscCompileOnError,
110
- webpack,
111
- });
112
- // Load proxy config
113
- const proxySetting = require(paths.appPackageJson).proxy;
114
- const proxyConfig = prepareProxy(
115
- proxySetting,
116
- paths.appPublic,
117
- paths.publicUrlOrPath
118
- );
119
- // Serve webpack assets generated by the compiler over a web server.
120
- const serverConfig = createDevServerConfig(
121
- proxyConfig,
122
- urls.lanUrlForConfig
123
- );
124
- const devServer = new WebpackDevServer(compiler, serverConfig);
125
- // Launch WebpackDevServer.
126
- devServer.listen(port, HOST, err => {
127
- if (err) {
128
- return console.log(err);
129
- }
130
- if (isInteractive) {
131
- clearConsole();
132
- }
133
-
134
- if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
135
- console.log(
136
- chalk.yellow(
137
- `Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
138
- )
139
- );
140
- }
141
-
142
- console.log(chalk.cyan('Starting the development server...\n'));
143
- openBrowser(urls.localUrlForBrowser);
144
- });
145
-
146
- ['SIGINT', 'SIGTERM'].forEach(function (sig) {
147
- process.on(sig, function () {
148
- devServer.close();
149
- process.exit();
150
- });
151
- });
152
-
153
- if (process.env.CI !== 'true') {
154
- // Gracefully exit when stdin ends
155
- process.stdin.on('end', function () {
156
- devServer.close();
157
- process.exit();
158
- });
159
- }
160
- })
161
- .catch(err => {
162
- if (err && err.message) {
163
- console.log(err.message);
164
- }
165
- process.exit(1);
166
- });
package/scripts/test.js DELETED
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- // Do this as the first thing so that any code reading it knows the right env.
4
- process.env.BABEL_ENV = 'test';
5
- process.env.NODE_ENV = 'test';
6
- process.env.PUBLIC_URL = '';
7
-
8
- // Makes the script crash on unhandled rejections instead of silently
9
- // ignoring them. In the future, promise rejections that are not handled will
10
- // terminate the Node.js process with a non-zero exit code.
11
- process.on('unhandledRejection', err => {
12
- throw err;
13
- });
14
-
15
- // Ensure environment variables are read.
16
- require('../config/env');
17
-
18
-
19
- const jest = require('jest');
20
- const execSync = require('child_process').execSync;
21
- let argv = process.argv.slice(2);
22
-
23
- function isInGitRepository() {
24
- try {
25
- execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
26
- return true;
27
- } catch (e) {
28
- return false;
29
- }
30
- }
31
-
32
- function isInMercurialRepository() {
33
- try {
34
- execSync('hg --cwd . root', { stdio: 'ignore' });
35
- return true;
36
- } catch (e) {
37
- return false;
38
- }
39
- }
40
-
41
- // Watch unless on CI or explicitly running all tests
42
- if (
43
- !process.env.CI &&
44
- argv.indexOf('--watchAll') === -1 &&
45
- argv.indexOf('--watchAll=false') === -1
46
- ) {
47
- // https://github.com/facebook/create-react-app/issues/5210
48
- const hasSourceControl = isInGitRepository() || isInMercurialRepository();
49
- argv.push(hasSourceControl ? '--watch' : '--watchAll');
50
- }
51
-
52
-
53
- jest.run(argv);
package/src/App.css DELETED
@@ -1,38 +0,0 @@
1
- .App {
2
- text-align: center;
3
- }
4
-
5
- .App-logo {
6
- height: 40vmin;
7
- pointer-events: none;
8
- }
9
-
10
- @media (prefers-reduced-motion: no-preference) {
11
- .App-logo {
12
- animation: App-logo-spin infinite 20s linear;
13
- }
14
- }
15
-
16
- .App-header {
17
- background-color: #282c34;
18
- min-height: 100vh;
19
- display: flex;
20
- flex-direction: column;
21
- align-items: center;
22
- justify-content: center;
23
- font-size: calc(10px + 2vmin);
24
- color: white;
25
- }
26
-
27
- .App-link {
28
- color: #61dafb;
29
- }
30
-
31
- @keyframes App-logo-spin {
32
- from {
33
- transform: rotate(0deg);
34
- }
35
- to {
36
- transform: rotate(360deg);
37
- }
38
- }
package/src/App.test.tsx DELETED
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import App from './App';
4
-
5
- test('renders learn react link', () => {
6
- render(<App />);
7
- const linkElement = screen.getByText(/learn react/i);
8
- expect(linkElement).toBeInTheDocument();
9
- });
package/src/App.tsx DELETED
@@ -1,34 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import "./App.css";
3
- import { Guard, GuardEventsCamelToKebabMapping, GuardMode } from "./components";
4
-
5
- function App() {
6
- console.log(GuardEventsCamelToKebabMapping);
7
- useEffect(() => {
8
- const guard = new Guard("62cd66dc014378042b55154f", {
9
- target: ".App",
10
- mode: GuardMode.Modal,
11
- });
12
-
13
- // @ts-ignore
14
- window.guard = guard;
15
- guard.render("center", () => {
16
- console.log("mount");
17
- });
18
- guard.show();
19
-
20
- guard.on("load", (e: any) => {
21
- console.log("加载啊", e);
22
- });
23
-
24
- guard.on("close", () => {
25
- setTimeout(() => {
26
- guard.show();
27
- }, 2000);
28
- });
29
- }, []);
30
-
31
- return <div className="App"></div>;
32
- }
33
-
34
- export default App;
@@ -1,198 +0,0 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom";
3
- import { Guard as ReactAuthingGuard } from "@authing/react-ui-components";
4
- import {
5
- GuardMode,
6
- GuardEvents,
7
- AuthenticationClient,
8
- GuardEventsKebabToCamelType,
9
- GuardEventsCamelToKebabMapping,
10
- GuardLocalConfig,
11
- GuardProps,
12
- } from "@authing/react-ui-components";
13
- import "@authing/react-ui-components/lib/index.min.css";
14
- // import { GuardComponentConfig, GuardLocalConfig } from "@authing/react-ui-components/components/Guard/config";
15
-
16
- export interface NativeGuardProps {
17
- appId?: string;
18
- config?: Partial<GuardLocalConfig>;
19
- tenantId?: string;
20
- authClient?: AuthenticationClient;
21
- }
22
-
23
- export interface NativeGuardConstructor {
24
- (
25
- appId?: string | NativeGuardProps,
26
- config?: Partial<GuardLocalConfig>,
27
- tenantId?: string,
28
- authClient?: AuthenticationClient
29
- ): void;
30
-
31
- (props: NativeGuardProps): void;
32
- }
33
-
34
- export type GuardEventListeners = {
35
- [key in keyof GuardEventsKebabToCamelType]: Exclude<Required<GuardEventsKebabToCamelType>[key], undefined>[];
36
- };
37
-
38
- export class Guard {
39
- public appId?: string;
40
- public config?: Partial<GuardLocalConfig>;
41
- public tenantId?: string;
42
- public authClient?: AuthenticationClient;
43
-
44
- public visible?: boolean;
45
- constructor(props?: NativeGuardProps);
46
- constructor(appId?: string, config?: Partial<GuardLocalConfig>, tenantId?: string, authClient?: AuthenticationClient);
47
-
48
- constructor(
49
- appIdOrProps?: string | NativeGuardProps,
50
- config?: Partial<GuardLocalConfig>,
51
- tenantId?: string,
52
- authClient?: AuthenticationClient
53
- ) {
54
- if (appIdOrProps && typeof appIdOrProps !== "string") {
55
- const { appId, config: configProps, tenantId: tenantIdProps, authClient: authClientProps } = appIdOrProps;
56
- this.appId = appId;
57
- this.config = configProps;
58
- this.tenantId = tenantIdProps;
59
- this.authClient = authClientProps;
60
- } else {
61
- this.appId = appIdOrProps;
62
- this.config = config;
63
- this.tenantId = tenantId;
64
- this.authClient = authClient;
65
- }
66
-
67
- this.visible = this.config?.mode === GuardMode.Modal ? false : true;
68
-
69
- this.render();
70
- }
71
-
72
- static getGuardContainer(selector?: string | HTMLElement) {
73
- const defaultId = "authing_guard_container";
74
-
75
- if (!selector) {
76
- let container = document.querySelector(`#${defaultId}`);
77
- if (!container) {
78
- container = document.createElement("div");
79
- container.id = defaultId;
80
- document.body.appendChild(container);
81
- }
82
-
83
- return container;
84
- }
85
-
86
- if (typeof selector === "string") {
87
- return document.querySelector(selector);
88
- }
89
-
90
- return selector;
91
- }
92
-
93
- private eventListeners = Object.values(GuardEventsCamelToKebabMapping).reduce((acc, evtName) => {
94
- return Object.assign({}, acc, {
95
- [evtName as string]: [],
96
- });
97
- }, {} as GuardEventListeners);
98
-
99
- public render(): void;
100
- public render(aliginOrCb: () => void): void;
101
- public render(aliginOrCb: "none" | "center" | "left" | "right"): void;
102
- public render(aliginOrCb: "none" | "center" | "left" | "right", callback: () => void): void;
103
- public render(aliginOrCb?: any, cb?: any) {
104
- const l = arguments.length;
105
- let align: "none" | "center" | "left" | "right";
106
-
107
- let callback: (() => void) | undefined;
108
- if (l === 0) {
109
- align = "none";
110
- } else if (l === 1) {
111
- if (typeof aliginOrCb === "function") {
112
- align = "none";
113
- callback = aliginOrCb;
114
- } else {
115
- align = aliginOrCb;
116
- }
117
- } else if (l === 2) {
118
- align = aliginOrCb;
119
- callback = cb;
120
- } else {
121
- throw new Error("参数格式错误");
122
- }
123
-
124
- // 两个都有
125
-
126
- // let justifyContent = "none";
127
- // let renderCb;
128
- // if (typeof aligin === "string") {
129
- // justifyContent = aligin;
130
- // renderCb = cb;
131
- // } else {
132
- // renderCb = aligin;
133
- // }
134
-
135
- const evts: GuardEvents = Object.entries(GuardEventsCamelToKebabMapping).reduce((acc, [reactEvt, nativeEvt]) => {
136
- return Object.assign({}, acc, {
137
- [reactEvt]: (...rest: any) => {
138
- if (nativeEvt === "close") {
139
- this.hide();
140
- }
141
-
142
- // TODO 返回最后一个执行函数的值,实际应该只让监听一次
143
- return (
144
- (this.eventListeners as any)[nativeEvt as string]
145
- // @ts-ignore
146
- .map((item: any) => {
147
- return item(...rest);
148
- })
149
- .slice(-1)[0] ?? true
150
- );
151
- },
152
- });
153
- }, {} as GuardEvents);
154
-
155
- return ReactDOM.render(
156
- <div
157
- style={{
158
- display: "flex",
159
- alignItems: "center",
160
- justifyContent: align,
161
- }}
162
- >
163
- <ReactAuthingGuard
164
- {...(evts as GuardEvents)}
165
- appId={this.appId}
166
- config={this.config as GuardProps["config"]}
167
- visible={this.visible}
168
- tenantId={this.tenantId}
169
- authClient={this.authClient}
170
- />
171
- </div>,
172
- Guard.getGuardContainer(this.config?.target),
173
- callback
174
- );
175
- }
176
-
177
- on<T extends keyof GuardEventsKebabToCamelType>(evt: T, handler: Exclude<GuardEventsKebabToCamelType[T], undefined>) {
178
- (this.eventListeners as any)[evt]!.push(handler as any);
179
- }
180
-
181
- show() {
182
- this.visible = true;
183
- this.render();
184
- }
185
-
186
- hide() {
187
- this.visible = false;
188
- this.render();
189
- }
190
-
191
- unmountComponent() {
192
- const node = Guard.getGuardContainer(this.config?.target);
193
-
194
- if (node) {
195
- ReactDOM.unmountComponentAtNode(node);
196
- }
197
- }
198
- }