@atls/react-identity-links 0.0.2 → 0.0.6

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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+
2
+
3
+ ## 0.0.6 (2025-01-22)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+
9
+ * **react:** lint and typecheck errors ([a090051](https://github.com/atls/reactjs/commit/a090051d1007e171df8066e85f15fcf8fd44c4ed))
10
+ * upgrade react, types fixes ([34feb02](https://github.com/atls/reactjs/commit/34feb027a2e2d7e5741509fd1ff846755d217b97))
11
+ * upgrade yarn, typescript, set resolutions ([b235334](https://github.com/atls/reactjs/commit/b23533417af6fb323187ef281b83d8dc5e7bd9dd))
12
+
13
+ ### Features
14
+
15
+
16
+ * add emotion as deps, bump @types/react ([1ce29b3](https://github.com/atls/reactjs/commit/1ce29b384640d9be0550d9c6f4dc07083821137a))
17
+ * **common:** bump yarn ([#143](https://github.com/atls/reactjs/issues/143)) ([8239f82](https://github.com/atls/reactjs/commit/8239f82f1c85d872a99613d3693babc761703b05))
18
+ * domain based identity links ([8263449](https://github.com/atls/reactjs/commit/826344977b1a86190a47b8d8fc6eecdb432da6a8))
19
+ * **identity-links:** init, also refactor react-user ([3fe1388](https://github.com/atls/reactjs/commit/3fe138854f57f7b50ce14df6c5dd9ab6f0d90dc2))
20
+ * react bump ([#144](https://github.com/atls/reactjs/issues/144)) ([9770fa1](https://github.com/atls/reactjs/commit/9770fa10451b647ed48e226270da68228714d174))
21
+ * root domain based identity links ([61508e4](https://github.com/atls/reactjs/commit/61508e41910a041d604999c01b74469bd1ea128c))
22
+ * update kratos browser flows to client 0.8.2 ([52f9c0f](https://github.com/atls/reactjs/commit/52f9c0fa129cd7d4567ab826c754483a6ddd6817))
23
+ * upgraded ([71a06f6](https://github.com/atls/reactjs/commit/71a06f6f498c928ed33b79f93af5d398a32af487))
24
+
25
+
@@ -0,0 +1,3 @@
1
+ import type { FC } from 'react';
2
+ import type { IdentityLinkProps } from './identity-url.interfaces';
3
+ export declare const IdentityLink: FC<IdentityLinkProps>;
@@ -2,14 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IdentityLink = void 0;
4
4
  const use_identity_url_hook_1 = require("./use-identity-url.hook");
5
- const IdentityLink = ({ children, type, returnTo, subdomain, substractHost, }) => {
6
- const url = (0, use_identity_url_hook_1.useIdentityUrl)({ type, returnTo, subdomain, substractHost });
7
- if (!children || !url) {
5
+ const IdentityLink = ({ children, type, returnTo }) => {
6
+ const url = (0, use_identity_url_hook_1.useIdentityUrl)({ type, returnTo });
7
+ if (!children || !url)
8
8
  return null;
9
- }
10
- if (typeof children !== 'function') {
9
+ if (typeof children !== 'function')
11
10
  throw new Error('IdentityLink - children must be a function.');
12
- }
13
11
  return children(url);
14
12
  };
15
13
  exports.IdentityLink = IdentityLink;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,24 +1,2 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- require("@testing-library/jest-dom/extend-expect");
7
- const react_1 = require("@testing-library/react");
8
- const react_2 = __importDefault(require("react"));
9
- const identity_link_component_1 = require("./identity-link.component");
10
- describe('identity-link.component', () => {
11
- const originalLocation = window.location;
12
- const mockWindowLocation = (newLocation) => {
13
- delete window.location;
14
- window.location = newLocation;
15
- };
16
- afterEach(() => {
17
- mockWindowLocation(originalLocation);
18
- });
19
- it('without params', async () => {
20
- mockWindowLocation(new URL('https://identity.monstrs.dev'));
21
- const { getByText } = (0, react_1.render)(react_2.default.createElement(identity_link_component_1.IdentityLink, null, (url) => react_2.default.createElement("a", { href: url }, "Login")));
22
- expect(getByText('Login')).toHaveAttribute('href', 'https://accounts.monstrs.dev/auth/login?return_to=https://identity.monstrs.dev/');
23
- });
24
- });
@@ -0,0 +1,13 @@
1
+ import type { JSX } from 'react';
2
+ export type IdentityUrlType = 'login' | 'logout' | 'recovery' | 'registration' | 'settings' | 'verification';
3
+ export interface UseIdentityUrlReturnToProps {
4
+ subdomain?: string;
5
+ pathname?: string;
6
+ }
7
+ export interface UseIdentityUrlProps {
8
+ type?: IdentityUrlType;
9
+ returnTo?: UseIdentityUrlReturnToProps | false | true;
10
+ }
11
+ export interface IdentityLinkProps extends UseIdentityUrlProps {
12
+ children?: (value: string) => JSX.Element;
13
+ }
@@ -0,0 +1,3 @@
1
+ export * from './identity-link.component';
2
+ export type * from './identity-url.interfaces';
3
+ export * from './use-identity-url.hook';
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -11,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
17
  __exportStar(require("./identity-link.component"), exports);
14
- __exportStar(require("./identity-url.interfaces"), exports);
15
18
  __exportStar(require("./use-identity-url.hook"), exports);
@@ -0,0 +1,3 @@
1
+ import type { EffectCallback } from 'react';
2
+ import type { DependencyList } from 'react';
3
+ export declare const useBrowserEffect: (effect: EffectCallback, deps?: DependencyList) => void;
@@ -0,0 +1,10 @@
1
+ import type { UseIdentityUrlProps } from './identity-url.interfaces';
2
+ export declare const identityUrlTypes: {
3
+ login: string;
4
+ registration: string;
5
+ verification: string;
6
+ recovery: string;
7
+ logout: string;
8
+ settings: string;
9
+ };
10
+ export declare const useIdentityUrl: ({ type, returnTo }?: UseIdentityUrlProps) => string | null;
@@ -12,26 +12,29 @@ exports.identityUrlTypes = {
12
12
  logout: '/auth/logout',
13
13
  settings: '/profile/settings',
14
14
  };
15
- const useIdentityUrl = ({ type = 'login', returnTo } = {}) => {
15
+ const useIdentityUrl = ({ type = 'login', returnTo = false } = {}) => {
16
16
  const [url, setUrl] = (0, react_1.useState)(null);
17
17
  (0, use_browser_effect_hook_1.useBrowserEffect)(() => {
18
- const { hostname, origin, href, protocol } = window.location;
18
+ const { hostname, origin, href, protocol, pathname } = window.location;
19
19
  const path = exports.identityUrlTypes[type];
20
- const domain = hostname === 'localhost' ? 'localhost:4433' : (0, tldjs_1.getDomain)(hostname);
21
- if (returnTo === false) {
22
- setUrl(`${protocol}//accounts.${domain}${path}`);
20
+ if (hostname === 'localhost') {
21
+ setUrl(`${protocol}//localhost:3000${path}`);
23
22
  }
24
23
  else {
25
- let returnToValue = href;
26
- if (returnTo) {
27
- if (returnTo.startsWith('http')) {
28
- returnToValue = returnTo;
29
- }
30
- else if (returnTo.startsWith('/')) {
31
- returnToValue = `${origin}${returnTo}`;
32
- }
24
+ const domain = (0, tldjs_1.getDomain)(hostname);
25
+ if (returnTo === false) {
26
+ setUrl(`${protocol}//accounts.${domain}${path}`);
27
+ }
28
+ else if (returnTo === true) {
29
+ setUrl(`${protocol}//accounts.${domain}${path}?return_to=${href}`);
30
+ }
31
+ else {
32
+ const returnToOrigin = returnTo.subdomain
33
+ ? `${protocol}//${returnTo.subdomain}.${domain}`
34
+ : origin;
35
+ const returnToValue = `${returnToOrigin}${returnTo.pathname ? returnTo.pathname : pathname}`;
36
+ setUrl(`${protocol}//accounts.${domain}${path}?return_to=${returnToValue}`);
33
37
  }
34
- setUrl(`${protocol}//accounts.${domain}${path}?return_to=${returnToValue}`);
35
38
  }
36
39
  }, [type, returnTo]);
37
40
  return url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atls/react-identity-links",
3
- "version": "0.0.2",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -18,11 +18,12 @@
18
18
  "@testing-library/jest-dom": "^5.16.2",
19
19
  "@testing-library/react": "^12.1.3",
20
20
  "@testing-library/react-hooks": "^7.0.2",
21
- "@types/react": "^17.0.39",
22
- "@types/react-dom": "^17.0.11",
21
+ "@types/react": "18.3.6",
22
+ "@types/react-dom": "^18.2.7",
23
23
  "@types/testing-library__jest-dom": "^5.14.1",
24
- "react": "^17.0.2",
25
- "react-dom": "^17.0.2"
24
+ "@types/tldjs": "2.3.4",
25
+ "react": "^18.2.0",
26
+ "react-dom": "^18.2.0"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "react": "^17.0.1"