@descope/react-sdk 0.0.51

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,29 @@
1
+ # @descope/react-sdk
2
+ This library lets you consume your login pages created by Descope console-app in your application
3
+ Under the hood, it uses [web-js-sdk](https://github.com/descope/web-js-sdk)
4
+
5
+ ## Usage
6
+ ### Install the package
7
+ ```bash
8
+ npm install @descope/react-sdk
9
+ ```
10
+
11
+ ### Render it in your application
12
+ ```js
13
+ import Descope from '@descope/react-sdk'
14
+
15
+ const App = () => {
16
+
17
+ return (
18
+ <Descope
19
+ projectId="myProjectId"
20
+ flowId="myFlowId"
21
+ onSuccess={(e) => console.log('Logged in!')}
22
+ onError={(e) => console.log('Could not logged in!')}
23
+ >
24
+ )
25
+ }
26
+ ```
27
+
28
+ TODO:
29
+ - decide about the callbacks event data & structure
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import '@descope/web-component';
3
+ import { DescopeCustomElement } from './types';
4
+ interface PropsType {
5
+ projectId: string;
6
+ flowId: string;
7
+ baseUrl?: string;
8
+ onSuccess?: DescopeCustomElement['onsuccess'];
9
+ onError?: DescopeCustomElement['onerror'];
10
+ }
11
+ declare const Descope: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<HTMLElement>>;
12
+ export default Descope;
@@ -0,0 +1,28 @@
1
+ import React, { useRef, useImperativeHandle, useEffect } from 'react';
2
+ import '@descope/web-component';
3
+
4
+ const Descope = React.forwardRef(({ projectId, flowId, baseUrl, onSuccess, onError }, ref) => {
5
+ const innerRef = useRef();
6
+ useImperativeHandle(ref, () => innerRef.current);
7
+ useEffect(() => {
8
+ const ele = innerRef.current;
9
+ if (onError)
10
+ ele?.addEventListener('error', onError);
11
+ if (onSuccess)
12
+ ele?.addEventListener('success', onSuccess);
13
+ return () => {
14
+ if (onError)
15
+ ele?.removeEventListener('error', onError);
16
+ if (onSuccess)
17
+ ele?.removeEventListener('success', onSuccess);
18
+ };
19
+ }, [innerRef, onError, onSuccess]);
20
+ return React.createElement("descope-wc", { "project-id": projectId, "flow-id": flowId, "base-url": baseUrl, ref: innerRef });
21
+ });
22
+ Descope.defaultProps = {
23
+ onError: undefined,
24
+ onSuccess: undefined,
25
+ baseUrl: undefined
26
+ };
27
+
28
+ export { Descope as default };
@@ -0,0 +1,17 @@
1
+ import React, { DOMAttributes } from 'react';
2
+ import DescopeWc from '@descope/web-component';
3
+ declare global {
4
+ namespace JSX {
5
+ interface IntrinsicElements {
6
+ ['descope-wc']: DescopeCustomElement;
7
+ }
8
+ }
9
+ }
10
+ export declare type CustomEvents<K extends string> = {
11
+ [key in K]: (event: CustomEvent) => void;
12
+ };
13
+ export declare type CustomElement<T, K extends string = ''> = Partial<T & DOMAttributes<T> & {
14
+ children: React.ReactChild;
15
+ ref: React.Ref<HTMLElement>;
16
+ } & CustomEvents<`on${K}`>>;
17
+ export declare type DescopeCustomElement = CustomElement<DescopeWc, 'success' | 'error'>;
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@descope/react-sdk",
3
+ "version": "0.0.51",
4
+ "main": "dist/Descope.js",
5
+ "types": "dist/Descope.d.ts",
6
+ "description": "Descope React SDK",
7
+ "license": "ISC",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/descope/react-sdk.git"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "@descope/web-component": "^0.0.25"
17
+ },
18
+ "devDependencies": {
19
+ "@babel/core": "7.18.9",
20
+ "@babel/preset-env": "7.18.9",
21
+ "@babel/preset-react": "7.18.6",
22
+ "@babel/preset-typescript": "7.18.6",
23
+ "@open-wc/rollup-plugin-html": "^1.2.5",
24
+ "@rollup/plugin-commonjs": "^21.0.1",
25
+ "@rollup/plugin-node-resolve": "^13.1.1",
26
+ "@rollup/plugin-replace": "^3.0.0",
27
+ "@rollup/plugin-typescript": "^8.3.0",
28
+ "@testing-library/jest-dom": "5.16.5",
29
+ "@testing-library/react": "13.3.0",
30
+ "@testing-library/user-event": "14.4.3",
31
+ "@types/jest": "^27.0.2",
32
+ "@types/react": "18.0.17",
33
+ "@types/react-dom": "18.0.5",
34
+ "babel-jest": "27.5.1",
35
+ "eslint": "8.20.0",
36
+ "eslint-config-airbnb": "19.0.4",
37
+ "eslint-config-airbnb-typescript": "17.0.0",
38
+ "eslint-config-prettier": "8.5.0",
39
+ "eslint-config-standard": "17.0.0",
40
+ "eslint-import-resolver-typescript": "2.7.1",
41
+ "eslint-plugin-import": "2.26.0",
42
+ "eslint-plugin-jest": "26.7.0",
43
+ "eslint-plugin-jest-dom": "4.0.2",
44
+ "eslint-plugin-jest-formatting": "3.1.0",
45
+ "eslint-plugin-jsx-a11y": "6.6.1",
46
+ "eslint-plugin-n": "15.2.4",
47
+ "eslint-plugin-no-only-tests": "2.6.0",
48
+ "eslint-plugin-prefer-arrow": "1.2.3",
49
+ "eslint-plugin-prettier": "4.2.1",
50
+ "eslint-plugin-promise": "6.0.0",
51
+ "eslint-plugin-react": "7.30.1",
52
+ "eslint-plugin-react-hooks": "4.6.0",
53
+ "eslint-plugin-testing-library": "5.6.0",
54
+ "jest": "^27.3.1",
55
+ "react": "18.2.0",
56
+ "react-dom": "18.2.0",
57
+ "rollup": "^2.62.0",
58
+ "rollup-plugin-browsersync": "^1.3.3",
59
+ "rollup-plugin-delete": "^2.0.0",
60
+ "rollup-plugin-livereload": "^2.0.5",
61
+ "rollup-plugin-serve": "^1.1.0",
62
+ "ts-jest": "^27.0.7",
63
+ "ts-node": "10.9.1",
64
+ "typescript": "^4.5.3"
65
+ },
66
+ "peerDependencies": {
67
+ "@types/react": ">=16",
68
+ "react": ">=16"
69
+ },
70
+ "scripts": {
71
+ "start": "rollup -c rollup.config.app.js -w",
72
+ "build": "rollup -c",
73
+ "test": "jest",
74
+ "lint": "eslint ./src",
75
+ "prepublishOnly": "npm run build"
76
+ }
77
+ }