@lokalise/harmony 1.10.0 → 1.11.1
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 +62 -0
- package/dist/harmony.cjs +1 -1
- package/dist/harmony.mjs +923 -507
- package/dist/types/src/components/Sidebar/Sidebar.stories.d.ts +0 -84
- package/dist/types/src/components/Sidebar/Widgets/Avatar/Avatar.d.ts +6 -1
- package/dist/types/src/components/Sidebar/Widgets/IconLink/IconLink.d.ts +11 -1
- package/dist/types/src/components/Sidebar/Widgets/Menu/Menu.d.ts +15 -1
- package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/ProfileMenu.d.ts +20 -2
- package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/ProfileSettingsMenuItem/ProfileSettingsMenuItem.d.ts +32 -2
- package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/TeamMenuItem/TeamMenuItem.d.ts +26 -3
- package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/TeamSwitch/TeamSwitch.d.ts +20 -1
- package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/UpgradeMenuItem/UpgradeMenuItem.d.ts +19 -3
- package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/types.d.ts +7 -0
- package/dist/types/src/features/auth/backend/services/getAuthenticatedSessionDetailFromRequest.d.ts +10 -0
- package/dist/types/src/features/auth/backend/services/getAuthenticatedSessionPayloadFromRequest.test.d.ts +1 -0
- package/dist/types/src/features/auth/core/jwtTokenPayload.d.ts +7 -0
- package/dist/types/src/features/auth/core/jwtTokenPayload.test.d.ts +1 -0
- package/dist/types/src/features/auth/core/lokaliseAuthAddon.d.ts +14 -0
- package/dist/types/src/features/auth/core/middleware/jwtAuthMiddleware.d.ts +13 -0
- package/dist/types/src/features/auth/core/middleware/jwtAuthMiddleware.test.d.ts +1 -0
- package/dist/types/src/features/auth/core/middleware/publicApiHeadersMiddleware.d.ts +5 -0
- package/dist/types/src/features/auth/core/types/jwtTokenPayload.d.ts +42 -0
- package/dist/types/src/features/auth/core/types/jwtTokenPayload.fixture.d.ts +27 -0
- package/dist/types/src/features/auth/core/utils/makeAuthHeader.d.ts +2 -0
- package/dist/types/src/features/auth/core/utils/makeAuthHeader.test.d.ts +1 -0
- package/dist/types/src/features/auth/frontend/addon/lokaliseAuthBrowserAddon.d.ts +35 -0
- package/dist/types/src/features/auth/frontend/events/NewJwtIssuedEvent.d.ts +20 -0
- package/dist/types/src/features/auth/frontend/hooks/useAuthenticatedProjectContributor.d.ts +28 -0
- package/dist/types/src/features/auth/frontend/hooks/useAuthenticatedSessionPayload.d.ts +18 -0
- package/dist/types/src/features/auth/frontend/hooks/useAuthenticatedUser.d.ts +18 -0
- package/dist/types/src/features/auth/frontend/hooks/useGetPromotedClassicSessionJwtQuery.d.ts +12 -0
- package/dist/types/src/features/auth/frontend/middleware/promoteClassicSessionToJwtMiddleware.d.ts +14 -0
- package/dist/types/src/features/auth/frontend/middleware/promoteClassicSessionToJwtMiddleware.test.d.ts +1 -0
- package/dist/types/src/features/auth/frontend/utils/cookieTokenUtils.d.ts +4 -0
- package/dist/types/src/features/auth/frontend/utils/cookieTokenUtils.test.d.ts +1 -0
- package/dist/types/src/features/auth/node.d.ts +9 -0
- package/dist/types/src/features/node.d.ts +2 -0
- package/dist/types/src/features/publicApi/contributors.d.ts +111 -0
- package/dist/types/src/features/publicApi/hooks/useCreateProjectMutation.d.ts +76 -0
- package/dist/types/src/features/publicApi/hooks/useGetTeamUsersQuery.d.ts +26 -0
- package/dist/types/src/features/publicApi/hooks/useGetUserTokenQuery.d.ts +20 -0
- package/dist/types/src/features/publicApi/hooks/useListProjectsQuery.d.ts +81 -0
- package/dist/types/src/features/publicApi/hooks/useRetrieveContributorQuery.d.ts +34 -0
- package/dist/types/src/features/publicApi/hooks/useRetrieveProjectQuery.d.ts +72 -0
- package/dist/types/src/features/publicApi/node.d.ts +16 -0
- package/dist/types/src/features/publicApi/projects.d.ts +1132 -0
- package/dist/types/src/features/publicApi/teamUsers.d.ts +61 -0
- package/dist/types/src/features/publicApi/types/contributorTypes.d.ts +171 -0
- package/dist/types/src/features/publicApi/types/languageTypes.d.ts +29 -0
- package/dist/types/src/features/publicApi/types/projectTypes.d.ts +1061 -0
- package/dist/types/src/features/publicApi/types/teamRoleTypes.d.ts +3 -0
- package/dist/types/src/features/publicApi/types/teamUserTypes.d.ts +70 -0
- package/dist/types/src/features/publicApi/types/userTokenTypes.d.ts +26 -0
- package/dist/types/src/features/publicApi/userToken.d.ts +35 -0
- package/dist/types/src/node.d.ts +2 -1
- package/dist/types/src/utils/testing/createMockFactoryWithDefaults.d.ts +2 -0
- package/dist/types/src/utils/testing/createMockFactoryWithDefaults.test.d.ts +1 -0
- package/dist/types/src/utils/testing/deepOverride.d.ts +4 -0
- package/dist/types/src/utils/testing/deepOverride.test.d.ts +1 -0
- package/dist/types/src/utils/types/apiMutationOverrides.d.ts +2 -0
- package/dist/types/src/utils/types/apiQueryOverrides.d.ts +2 -0
- package/package.json +13 -2
@@ -1,89 +1,5 @@
|
|
1
1
|
import { Meta, StoryObj } from '@storybook/react';
|
2
2
|
import { Sidebar } from './Sidebar';
|
3
|
-
/**
|
4
|
-
* ## Overview
|
5
|
-
* Sidebar is a self-contained component using widgets.
|
6
|
-
*
|
7
|
-
* ## Available Widgets
|
8
|
-
*
|
9
|
-
* ### `Sidebar.Top`
|
10
|
-
* Use to wrap up a top section of the Sidebar
|
11
|
-
*
|
12
|
-
* ### `Sidebar.Bottom`
|
13
|
-
* Use to wrap up a bottom section of the Sidebar
|
14
|
-
*
|
15
|
-
* ### `Sidebar.Avatar`
|
16
|
-
* Display company main avatar / logo in the top section
|
17
|
-
* ```
|
18
|
-
* src: string;
|
19
|
-
* href?: string; ('/')
|
20
|
-
* ariaLabel?: string; ('Home')
|
21
|
-
* alt?: string; ('Lokalise')
|
22
|
-
* ```
|
23
|
-
*
|
24
|
-
* ### `Sidebar.IconLink`
|
25
|
-
* Display link with an icon. Mainly used in the top section
|
26
|
-
* ```
|
27
|
-
* to: string;
|
28
|
-
* label: string;
|
29
|
-
* icon: FC<SvgIconProps>
|
30
|
-
* ```
|
31
|
-
*
|
32
|
-
* ### `Sidebar.Menu`
|
33
|
-
* Use this widget for simple side menu. Currently utilised for `Help` section
|
34
|
-
* ```
|
35
|
-
* icon: FC<SvgIconProps>
|
36
|
-
* children: ReactNode; (representing menu list)
|
37
|
-
* ```
|
38
|
-
*
|
39
|
-
* ### `Sidebar.ProfileMenu`
|
40
|
-
* Contextual component, requires initial configuration
|
41
|
-
* ```
|
42
|
-
* teams: SidebarTeam[];
|
43
|
-
* currentTeamId: number;
|
44
|
-
* planId: number;
|
45
|
-
* isLimitedView: boolean;
|
46
|
-
* isTeamSuspended: boolean;
|
47
|
-
* canAccessTeamSettings: boolean;
|
48
|
-
* isEndOfTrialActive: boolean;
|
49
|
-
* trialDaysLeft: number;
|
50
|
-
* isProviderAlpha: boolean;
|
51
|
-
* ```
|
52
|
-
* and works with internal widgets
|
53
|
-
*
|
54
|
-
* #### `Sidebar.TeamSwitch`
|
55
|
-
* Uses available teams (other than current) and allows user to switch between them
|
56
|
-
* ```
|
57
|
-
* onSwitchTeam: (team: SidebarTeam) => void;
|
58
|
-
* ```
|
59
|
-
*
|
60
|
-
* #### `Sidebar.TeamMenuItem`
|
61
|
-
* Uses context of current team, and depending on ability to switch team or not,
|
62
|
-
* it renders as a div or clickable MenuItem. If used with TeamSwitch, it triggers `onSwitchTeams`
|
63
|
-
* callback, passing relevant team as an argument
|
64
|
-
* ```
|
65
|
-
* team?: SidebarTeam; (fallbacks to currentTeam from context if not passed)
|
66
|
-
* onClick?: (team: SidebarTeam) => void;
|
67
|
-
* hidePlanLabel?: boolean;
|
68
|
-
* ```
|
69
|
-
*
|
70
|
-
* #### `Sidebar.ProfileSettingsMenuItem`
|
71
|
-
* Menu item that comes with a small user's email and renders conditionally, only if team
|
72
|
-
* is not suspended or is not at the end of a trial
|
73
|
-
* ```
|
74
|
-
* href: string;
|
75
|
-
* userEmail: string;
|
76
|
-
* onClick?: () => void; (additional onClick for any tracking events)
|
77
|
-
* hideBottomDivider?: boolean;
|
78
|
-
* ```
|
79
|
-
*
|
80
|
-
* #### `Sidebar.UpgradeMenuItem`
|
81
|
-
* Menu item conditionally rendering only if `showUpgradeButton` is `true`. It renders correct
|
82
|
-
* upgrade note depending on the current team plan and red arrow up to indicate an update option
|
83
|
-
* ```
|
84
|
-
* upgradeOptionHref: string;
|
85
|
-
* ```
|
86
|
-
*/
|
87
3
|
declare const meta: Meta<typeof Sidebar>;
|
88
4
|
type Story = StoryObj<typeof Sidebar>;
|
89
5
|
export declare const FullSidebar: Story;
|
@@ -1,11 +1,16 @@
|
|
1
1
|
type AvatarProps = {
|
2
|
+
/** URL of the avatar/logo image */
|
2
3
|
src: string;
|
4
|
+
/** Link destination when avatar is clicked. Defaults to '/' */
|
3
5
|
href?: string;
|
6
|
+
/** Accessibility label for the avatar link. Defaults to 'Home' */
|
4
7
|
ariaLabel?: string;
|
8
|
+
/** Alt text for the avatar image. Defaults to 'Lokalise' */
|
5
9
|
alt?: string;
|
6
10
|
};
|
7
11
|
/**
|
8
|
-
* Display company main avatar / logo in the top section
|
12
|
+
* Display company main avatar / logo in the top section of the Sidebar.
|
13
|
+
* Used as the main branding element and home navigation link.
|
9
14
|
*/
|
10
15
|
export declare const Avatar: ({ src, href, ariaLabel, alt }: AvatarProps) => import("react/jsx-runtime").JSX.Element;
|
11
16
|
export {};
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { SvgIconProps } from '@lokalise/louis';
|
2
2
|
import { FC } from 'react';
|
3
3
|
type IconLinkProps = {
|
4
|
+
/** URL destination for the link */
|
4
5
|
to: string;
|
6
|
+
/** Text to display in the tooltip when hovering over the icon */
|
5
7
|
label: string;
|
8
|
+
/** Icon component from @lokalise/louis to display */
|
6
9
|
icon: FC<SvgIconProps>;
|
7
10
|
};
|
8
11
|
/**
|
9
|
-
*
|
12
|
+
* A navigation link component that displays an icon with a tooltip.
|
13
|
+
* When hovered, shows a tooltip with the label text.
|
14
|
+
* The link is highlighted when the current URL matches its destination.
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
* ```tsx
|
18
|
+
* <IconLink to="/projects" label="Projects" icon={FolderOpenIcon} />
|
19
|
+
* ```
|
10
20
|
*/
|
11
21
|
export declare const IconLink: ({ label, to, icon: Icon }: IconLinkProps) => import("react/jsx-runtime").JSX.Element;
|
12
22
|
export {};
|
@@ -1,10 +1,24 @@
|
|
1
1
|
import { SvgIconProps } from '@lokalise/louis';
|
2
2
|
import { FC, PropsWithChildren } from 'react';
|
3
3
|
type MenuProps = PropsWithChildren<{
|
4
|
+
/** Icon component from @lokalise/louis to display in the menu button */
|
4
5
|
icon: FC<SvgIconProps>;
|
5
6
|
}>;
|
6
7
|
/**
|
7
|
-
*
|
8
|
+
* A dropdown menu component that displays an icon button which reveals a menu list when clicked.
|
9
|
+
* The menu is positioned to the right of the button and includes a tooltip.
|
10
|
+
*
|
11
|
+
* Used primarily for dropdown menus in the Sidebar, such as the Help menu.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* ```tsx
|
15
|
+
* <Menu icon={HelpCenterIcon}>
|
16
|
+
* <MenuItem href="/docs">Documentation</MenuItem>
|
17
|
+
* <MenuItem href="/tutorial">Tutorials</MenuItem>
|
18
|
+
* <MenuDivider />
|
19
|
+
* <MenuItem href="/blog">Blog</MenuItem>
|
20
|
+
* </Menu>
|
21
|
+
* ```
|
8
22
|
*/
|
9
23
|
export declare const Menu: ({ children, icon: Icon }: MenuProps) => import("react/jsx-runtime").JSX.Element;
|
10
24
|
export {};
|
@@ -1,12 +1,30 @@
|
|
1
1
|
import { ProfileMenuContentProps } from './ProfileMenuContent';
|
2
2
|
import { SidebarProfileMenuConfig } from './types';
|
3
3
|
type ProfileMenuProps = {
|
4
|
+
/** Configuration object containing team and user settings */
|
4
5
|
config: SidebarProfileMenuConfig;
|
6
|
+
/** Render function for the menu content */
|
5
7
|
children: ProfileMenuContentProps['children'];
|
6
8
|
};
|
7
9
|
/**
|
8
|
-
*
|
9
|
-
*
|
10
|
+
* A contextual menu component that provides team management functionality.
|
11
|
+
* It manages team switching, profile settings, billing options, and upgrade prompts.
|
12
|
+
*
|
13
|
+
* The component uses a render prop pattern to provide context values to its children,
|
14
|
+
* allowing flexible composition of menu items based on user permissions and team status.
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
* ```tsx
|
18
|
+
* <ProfileMenu config={profileMenuConfig}>
|
19
|
+
* {({ allowTeamCreation, showBillingButton }) => (
|
20
|
+
* <>
|
21
|
+
* <TeamSwitch onSwitchTeam={handleTeamSwitch} />
|
22
|
+
* {allowTeamCreation && <MenuItem>Create new team</MenuItem>}
|
23
|
+
* {showBillingButton && <MenuItem href="/billing">Billing</MenuItem>}
|
24
|
+
* </>
|
25
|
+
* )}
|
26
|
+
* </ProfileMenu>
|
27
|
+
* ```
|
10
28
|
*/
|
11
29
|
export declare const ProfileMenu: ({ config, children }: ProfileMenuProps) => import("react/jsx-runtime").JSX.Element;
|
12
30
|
export {};
|
@@ -1,12 +1,42 @@
|
|
1
1
|
type ProfileSettingsMenuItemProps = {
|
2
|
+
/** URL to the profile settings page */
|
2
3
|
href: string;
|
4
|
+
/** User's email address to display below "Profile Settings" */
|
3
5
|
userEmail: string;
|
6
|
+
/** Optional callback function for tracking or additional actions */
|
4
7
|
onClick?: () => void;
|
8
|
+
/** Whether to hide the divider that appears below this menu item */
|
5
9
|
hideBottomDivider?: boolean;
|
6
10
|
};
|
7
11
|
/**
|
8
|
-
*
|
9
|
-
*
|
12
|
+
* A menu item component that provides access to profile settings.
|
13
|
+
*
|
14
|
+
* Features:
|
15
|
+
* - Displays "Profile Settings" with the user's email address below
|
16
|
+
* - Conditionally renders based on team status
|
17
|
+
* - Includes an optional divider below the item
|
18
|
+
* - Will not render if:
|
19
|
+
* - Team is suspended
|
20
|
+
* - Team's trial period has ended
|
21
|
+
*
|
22
|
+
* @example
|
23
|
+
* ```tsx
|
24
|
+
* <ProfileSettingsMenuItem
|
25
|
+
* href="/settings/profile"
|
26
|
+
* userEmail="user@example.com"
|
27
|
+
* onClick={() => trackSettingsClick()}
|
28
|
+
* />
|
29
|
+
*
|
30
|
+
* // Without bottom divider
|
31
|
+
* <ProfileSettingsMenuItem
|
32
|
+
* href="/settings/profile"
|
33
|
+
* userEmail="user@example.com"
|
34
|
+
* hideBottomDivider
|
35
|
+
* />
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* @note This component must be used within a ProfileMenu component
|
39
|
+
* as it requires access to the ProfileMenu context for team status information.
|
10
40
|
*/
|
11
41
|
export declare const ProfileSettingsMenuItem: ({ href, onClick, userEmail, hideBottomDivider, }: ProfileSettingsMenuItemProps) => import("react/jsx-runtime").JSX.Element | null;
|
12
42
|
export {};
|
package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/TeamMenuItem/TeamMenuItem.d.ts
CHANGED
@@ -1,13 +1,36 @@
|
|
1
1
|
import { SidebarTeam } from '../../../types';
|
2
2
|
type TeamMenuItemProps = {
|
3
|
+
/** Team to display. If not provided, uses the current team from context */
|
3
4
|
team?: SidebarTeam;
|
5
|
+
/** Callback for when the team item is clicked. If provided, renders as a clickable MenuItem */
|
4
6
|
onClick?: (team: SidebarTeam) => void;
|
7
|
+
/** Whether to hide the plan label (Free/Trial). Useful when displaying multiple teams */
|
5
8
|
hidePlanLabel?: boolean;
|
6
9
|
};
|
7
10
|
/**
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
+
* A component that displays team information in a menu item format.
|
12
|
+
* Renders team logo (or default user icon), team name, role, and plan label.
|
13
|
+
*
|
14
|
+
* The component can be used in two modes:
|
15
|
+
* 1. As a static display of the current team (when no onClick handler is provided)
|
16
|
+
* 2. As a clickable menu item for team switching (when onClick handler is provided)
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* ```tsx
|
20
|
+
* // Static current team display
|
21
|
+
* <TeamMenuItem />
|
22
|
+
*
|
23
|
+
* // Clickable team item for switching
|
24
|
+
* <TeamMenuItem
|
25
|
+
* team={someTeam}
|
26
|
+
* onClick={(team) => handleTeamSwitch(team)}
|
27
|
+
* hidePlanLabel
|
28
|
+
* />
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* @note This component must be used within a ProfileMenu component
|
32
|
+
* as it requires access to the ProfileMenu context for current team
|
33
|
+
* and plan information.
|
11
34
|
*/
|
12
35
|
export declare const TeamMenuItem: ({ team, onClick, hidePlanLabel }: TeamMenuItemProps) => import("react/jsx-runtime").JSX.Element | null;
|
13
36
|
export {};
|
@@ -1,9 +1,28 @@
|
|
1
1
|
import { SidebarTeam } from '../../../types';
|
2
2
|
type TeamSwitchProps = {
|
3
|
+
/** Callback function triggered when a user selects a different team */
|
3
4
|
onSwitchTeam: (team: SidebarTeam) => void;
|
4
5
|
};
|
5
6
|
/**
|
6
|
-
*
|
7
|
+
* A component that displays a list of available teams for switching.
|
8
|
+
* It automatically excludes the current team from the list and renders
|
9
|
+
* nothing if there are no other teams available.
|
10
|
+
*
|
11
|
+
* Uses the ProfileMenu context to access the list of other teams and
|
12
|
+
* renders each team as a TeamMenuItem with click functionality.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* ```tsx
|
16
|
+
* <TeamSwitch
|
17
|
+
* onSwitchTeam={(team) => {
|
18
|
+
* console.log(`Switching to team: ${team.name}`);
|
19
|
+
* // Handle team switch logic
|
20
|
+
* }}
|
21
|
+
* />
|
22
|
+
* ```
|
23
|
+
*
|
24
|
+
* @note This component must be used within a ProfileMenu component
|
25
|
+
* as it requires access to the ProfileMenu context.
|
7
26
|
*/
|
8
27
|
export declare const TeamSwitch: ({ onSwitchTeam }: TeamSwitchProps) => import("react/jsx-runtime").JSX.Element | null;
|
9
28
|
export {};
|
package/dist/types/src/components/Sidebar/Widgets/ProfileMenu/UpgradeMenuItem/UpgradeMenuItem.d.ts
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
type UpgradeMenuItemProps = {
|
2
|
+
/** URL to the upgrade page or pricing options */
|
2
3
|
upgradeOptionHref: string;
|
3
4
|
};
|
4
5
|
/**
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
6
|
+
* A menu item component that displays upgrade call-to-action information.
|
7
|
+
* Only renders when upgrade options should be shown (determined by context).
|
8
|
+
*
|
9
|
+
* The component displays different messages based on the team's current plan:
|
10
|
+
* - For free plans: "Your team is currently on the Free plan"
|
11
|
+
* - For trial plans: "Free trial ends in X days"
|
12
|
+
*
|
13
|
+
* Includes an upgrade icon and "See upgrade options" text, styled to draw attention
|
14
|
+
* to the upgrade opportunity.
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
* ```tsx
|
18
|
+
* <UpgradeMenuItem upgradeOptionHref="/pricing" />
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* @note This component must be used within a ProfileMenu component
|
22
|
+
* as it requires access to the ProfileMenu context for plan information
|
23
|
+
* and visibility control.
|
8
24
|
*/
|
9
25
|
export declare const UpgradeMenuItem: ({ upgradeOptionHref }: UpgradeMenuItemProps) => import("react/jsx-runtime").JSX.Element | null;
|
10
26
|
export {};
|
@@ -1,5 +1,9 @@
|
|
1
1
|
import { SidebarTeam, SidebarTeamRole } from '../../types';
|
2
2
|
export type { SidebarTeam, SidebarTeamRole } from '../../types';
|
3
|
+
/**
|
4
|
+
* Configuration object for the Sidebar's ProfileMenu component.
|
5
|
+
* Contains data from various API endpoints and JWT token.
|
6
|
+
*/
|
3
7
|
export type SidebarProfileMenuConfig = {
|
4
8
|
teams: SidebarTeam[];
|
5
9
|
isTeamSuspended: boolean;
|
@@ -12,6 +16,9 @@ export type SidebarProfileMenuConfig = {
|
|
12
16
|
userTeamRole: SidebarTeamRole;
|
13
17
|
userEmail: string;
|
14
18
|
};
|
19
|
+
/**
|
20
|
+
* Extended configuration including computed properties used within the ProfileMenu context.
|
21
|
+
*/
|
15
22
|
export type SidebarProfileMenuContextProps = SidebarProfileMenuConfig & {
|
16
23
|
currentTeam?: SidebarTeam;
|
17
24
|
otherTeams: SidebarTeam[];
|
package/dist/types/src/features/auth/backend/services/getAuthenticatedSessionDetailFromRequest.d.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import { JwtTokenPayload } from '../../core/types/jwtTokenPayload';
|
2
|
+
import { JwtToken } from '../../../publicApi/types/userTokenTypes';
|
3
|
+
type AuthenticatedSessionDetail = JwtToken & {
|
4
|
+
payload: JwtTokenPayload;
|
5
|
+
};
|
6
|
+
/**
|
7
|
+
* Returns the JWT tokens and parses the attached payload.
|
8
|
+
*/
|
9
|
+
export declare function getAuthenticatedSessionDetailFromRequest(): AuthenticatedSessionDetail | undefined;
|
10
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Wretch, WretchAddon } from 'wretch/types';
|
2
|
+
import { JwtAuthProps } from './middleware/jwtAuthMiddleware';
|
3
|
+
export interface LokaliseAuthAddon {
|
4
|
+
/**
|
5
|
+
* Add authentication and automatic token refresh to Lokalise requests.
|
6
|
+
*/
|
7
|
+
lokaliseAuth<T extends LokaliseAuthAddon>(this: T & Wretch<T>, props: JwtAuthProps): this;
|
8
|
+
}
|
9
|
+
/**
|
10
|
+
* Addon for Lokalise authentication.
|
11
|
+
* This will expose a method that can be used to authenticate requests to Lokalise.
|
12
|
+
* It will also handle refreshing the token when it expires.
|
13
|
+
*/
|
14
|
+
export declare const LokaliseAuthAddon: WretchAddon<LokaliseAuthAddon>;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { JwtToken } from '../../../publicApi/types/userTokenTypes';
|
2
|
+
import { ConfiguredMiddleware, Wretch } from 'wretch';
|
3
|
+
export type JwtAuthProps = {
|
4
|
+
/**
|
5
|
+
* This function should return the current JWT token if it exists.
|
6
|
+
*/
|
7
|
+
getCachedJwtToken: () => Promise<JwtToken | undefined>;
|
8
|
+
/**
|
9
|
+
* This function is called when a new JWT token is issued or if/when the token is refreshed.
|
10
|
+
*/
|
11
|
+
onNewJwtTokenIssued?: (jwtToken: JwtToken) => Promise<void>;
|
12
|
+
};
|
13
|
+
export declare function jwtAuthMiddleware<T>(client: Wretch<T>, props: JwtAuthProps): ConfiguredMiddleware;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
export declare const JWT_TOKEN_PAYLOAD_SCHEMA: z.ZodObject<{
|
3
|
+
userId: z.ZodNumber;
|
4
|
+
userUuid: z.ZodString;
|
5
|
+
teamId: z.ZodNumber;
|
6
|
+
userTeamRole: z.ZodUnion<[z.ZodLiteral<"owner">, z.ZodLiteral<"admin">, z.ZodLiteral<"biller">, z.ZodLiteral<"member">]>;
|
7
|
+
userEmail: z.ZodString;
|
8
|
+
userName: z.ZodString;
|
9
|
+
userCurrentTeamId: z.ZodNumber;
|
10
|
+
planId: z.ZodNumber;
|
11
|
+
planName: z.ZodString;
|
12
|
+
isProviderAlpha: z.ZodBoolean;
|
13
|
+
isFullyAuthenticated: z.ZodBoolean;
|
14
|
+
exp: z.ZodNumber;
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
16
|
+
isProviderAlpha: boolean;
|
17
|
+
isFullyAuthenticated: boolean;
|
18
|
+
planId: number;
|
19
|
+
userTeamRole: "member" | "admin" | "biller" | "owner";
|
20
|
+
userEmail: string;
|
21
|
+
teamId: number;
|
22
|
+
userId: number;
|
23
|
+
userUuid: string;
|
24
|
+
userName: string;
|
25
|
+
userCurrentTeamId: number;
|
26
|
+
planName: string;
|
27
|
+
exp: number;
|
28
|
+
}, {
|
29
|
+
isProviderAlpha: boolean;
|
30
|
+
isFullyAuthenticated: boolean;
|
31
|
+
planId: number;
|
32
|
+
userTeamRole: "member" | "admin" | "biller" | "owner";
|
33
|
+
userEmail: string;
|
34
|
+
teamId: number;
|
35
|
+
userId: number;
|
36
|
+
userUuid: string;
|
37
|
+
userName: string;
|
38
|
+
userCurrentTeamId: number;
|
39
|
+
planName: string;
|
40
|
+
exp: number;
|
41
|
+
}>;
|
42
|
+
export type JwtTokenPayload = z.infer<typeof JWT_TOKEN_PAYLOAD_SCHEMA>;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
export declare const createMockJwtTokenPayload: (overrides?: {
|
2
|
+
isProviderAlpha?: boolean | undefined;
|
3
|
+
isFullyAuthenticated?: boolean | undefined;
|
4
|
+
planId?: number | undefined;
|
5
|
+
userTeamRole?: "member" | "admin" | "biller" | "owner" | undefined;
|
6
|
+
userEmail?: string | undefined;
|
7
|
+
teamId?: number | undefined;
|
8
|
+
userId?: number | undefined;
|
9
|
+
userUuid?: string | undefined;
|
10
|
+
userName?: string | undefined;
|
11
|
+
userCurrentTeamId?: number | undefined;
|
12
|
+
planName?: string | undefined;
|
13
|
+
exp?: number | undefined;
|
14
|
+
} | undefined, removeProperties?: ("isProviderAlpha" | "isFullyAuthenticated" | "planId" | "userTeamRole" | "userEmail" | "teamId" | "userId" | "userUuid" | "userName" | "userCurrentTeamId" | "planName" | "exp")[]) => {
|
15
|
+
isProviderAlpha: boolean;
|
16
|
+
isFullyAuthenticated: boolean;
|
17
|
+
planId: number;
|
18
|
+
userTeamRole: "member" | "admin" | "biller" | "owner";
|
19
|
+
userEmail: string;
|
20
|
+
teamId: number;
|
21
|
+
userId: number;
|
22
|
+
userUuid: string;
|
23
|
+
userName: string;
|
24
|
+
userCurrentTeamId: number;
|
25
|
+
planName: string;
|
26
|
+
exp: number;
|
27
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { Wretch, WretchAddon } from 'wretch/types';
|
2
|
+
import { JwtAuthProps } from '../../core/middleware/jwtAuthMiddleware';
|
3
|
+
import { PromoteAuthProps } from '../middleware/promoteClassicSessionToJwtMiddleware';
|
4
|
+
type BrowserJwtAuthProps = Omit<JwtAuthProps, 'getCachedJwtToken'> & {
|
5
|
+
/**
|
6
|
+
* The browser implementation makes this optional, as it can be inferred from the cookie.
|
7
|
+
* You can still provide a custom implementation if you want to.
|
8
|
+
*/
|
9
|
+
getCachedJwtToken?: JwtAuthProps['getCachedJwtToken'];
|
10
|
+
};
|
11
|
+
type BrowserPromoteAuthProps = Omit<PromoteAuthProps, 'getCachedJwtToken' | 'getCsrfToken'> & {
|
12
|
+
/**
|
13
|
+
* The browser implementation makes this optional, as it can be inferred from the cookie.
|
14
|
+
* You can still provide a custom implementation if you want to.
|
15
|
+
*/
|
16
|
+
getCachedJwtToken?: PromoteAuthProps['getCachedJwtToken'];
|
17
|
+
/**
|
18
|
+
* The browser implementation makes this optional, as it can be inferred from the cookie.
|
19
|
+
* You can still provide a custom implementation if you want to.
|
20
|
+
*/
|
21
|
+
getCsrfToken?: PromoteAuthProps['getCsrfToken'];
|
22
|
+
};
|
23
|
+
export interface LokaliseAuthBrowserAddon {
|
24
|
+
lokaliseAuth<T extends LokaliseAuthBrowserAddon>(this: T & Wretch<T>, props?: BrowserJwtAuthProps): this;
|
25
|
+
promoteClassicSession<T extends LokaliseAuthBrowserAddon>(this: T & Wretch<T>, props: BrowserPromoteAuthProps): this;
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* A browser implementation of the LokaliseAuthAddon.
|
29
|
+
* This implementation provides default providers that uses cookies to retrieve the JWT token.
|
30
|
+
*
|
31
|
+
* It exposes another utility method to automatically promote a classic session to a JWT session
|
32
|
+
* when a request is made from an environment using class CSRF PHP token authentication.
|
33
|
+
*/
|
34
|
+
export declare const LokaliseAuthBrowserAddon: WretchAddon<LokaliseAuthBrowserAddon>;
|
35
|
+
export {};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { JwtTokenPayload } from '../../core/types/jwtTokenPayload';
|
2
|
+
import { JwtToken } from '../../../publicApi/types/userTokenTypes';
|
3
|
+
type NewJwtIssuedEventDetail = {
|
4
|
+
token: JwtToken;
|
5
|
+
payload: JwtTokenPayload | undefined;
|
6
|
+
};
|
7
|
+
/**
|
8
|
+
* This event is emitted when a new JWT token is issued or refreshed.
|
9
|
+
*/
|
10
|
+
export declare class NewJwtIssuedEvent extends CustomEvent<NewJwtIssuedEventDetail> {
|
11
|
+
static readonly eventName: "new-jwt-issued";
|
12
|
+
constructor(token: JwtToken);
|
13
|
+
}
|
14
|
+
export declare const isNewJwtIssuedEvent: (event: Event) => event is NewJwtIssuedEvent;
|
15
|
+
declare global {
|
16
|
+
interface WindowEventMap {
|
17
|
+
[NewJwtIssuedEvent.eventName]: NewJwtIssuedEvent;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
export {};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Wretch } from 'wretch';
|
2
|
+
/**
|
3
|
+
* Uses the payload attached to the JWT to request the contributor information
|
4
|
+
* of the provided project for the authenticated user.
|
5
|
+
* This required an active JWT token to be present in the cookie.
|
6
|
+
*
|
7
|
+
* @param wretchClient - Wretch instance configured to a public API instance.
|
8
|
+
* @param projectId - The ID of the project to retrieve the contributor information.
|
9
|
+
*/
|
10
|
+
export declare function useAuthenticatedProjectContributor<T>(wretchClient: Wretch<T>, projectId: string): import('@tanstack/react-query').UseQueryResult<{
|
11
|
+
contributors: {
|
12
|
+
email: string;
|
13
|
+
user_id: number;
|
14
|
+
fullname: string;
|
15
|
+
created_at: string;
|
16
|
+
created_at_timestamp: number;
|
17
|
+
admin_rights: string[];
|
18
|
+
languages: {
|
19
|
+
lang_id: number;
|
20
|
+
lang_iso: string;
|
21
|
+
lang_name: string;
|
22
|
+
is_writable: 0 | 1;
|
23
|
+
}[];
|
24
|
+
is_admin: boolean;
|
25
|
+
is_reviewer: boolean;
|
26
|
+
}[];
|
27
|
+
project_id: string;
|
28
|
+
}, undefined>;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* A hook that will bring the cached JWT token into the React lifecycle.
|
3
|
+
* If the token is updated or removed, the hook will update the state.
|
4
|
+
*/
|
5
|
+
export declare function useAuthenticatedSessionPayload(): {
|
6
|
+
isProviderAlpha: boolean;
|
7
|
+
isFullyAuthenticated: boolean;
|
8
|
+
planId: number;
|
9
|
+
userTeamRole: "member" | "admin" | "biller" | "owner";
|
10
|
+
userEmail: string;
|
11
|
+
teamId: number;
|
12
|
+
userId: number;
|
13
|
+
userUuid: string;
|
14
|
+
userName: string;
|
15
|
+
userCurrentTeamId: number;
|
16
|
+
planName: string;
|
17
|
+
exp: number;
|
18
|
+
} | undefined;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Wretch } from 'wretch';
|
2
|
+
/**
|
3
|
+
* Uses the payload attached to the JWT to request the team-user information for the authenticated user.
|
4
|
+
* This required an active JWT token to be present in the cookie.
|
5
|
+
*
|
6
|
+
* @param wretchClient - Wretch instance configured to a public API instance.
|
7
|
+
*/
|
8
|
+
export declare function useAuthenticatedUser<T>(wretchClient: Wretch<T>): import('@tanstack/react-query').UseQueryResult<{
|
9
|
+
team_id: number;
|
10
|
+
team_user: {
|
11
|
+
role: "member" | "admin" | "biller" | "owner";
|
12
|
+
email: string;
|
13
|
+
user_id: number;
|
14
|
+
fullname: string;
|
15
|
+
created_at: string;
|
16
|
+
created_at_timestamp: number;
|
17
|
+
};
|
18
|
+
}, undefined>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Wretch } from 'wretch';
|
2
|
+
/**
|
3
|
+
* For use in environments that are authenticated with a classic CSRF PHP session (e.g. Expert).
|
4
|
+
* This hook will send that token to the public API, upgrade to a JWT session.
|
5
|
+
*
|
6
|
+
* @param wretchClient - Wretch instance configured to a public API instance.
|
7
|
+
* @param teamId - The team ID to get the JWT for.
|
8
|
+
*/
|
9
|
+
export declare function useGetPromotedClassicSessionJwtQuery<T>(wretchClient: Wretch<T>, teamId: number): import('@tanstack/react-query').UseQueryResult<{
|
10
|
+
accessToken: string;
|
11
|
+
refreshToken: string;
|
12
|
+
}, undefined>;
|