@joelbarron/react-web-dev-kit 0.1.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/README.md +236 -0
- package/dist/auth/client.d.ts +44 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +354 -0
- package/dist/auth/constants/countryCallingCodes.d.ts +9 -0
- package/dist/auth/constants/countryCallingCodes.d.ts.map +1 -0
- package/dist/auth/constants/countryCallingCodes.js +209 -0
- package/dist/auth/constants/gender.d.ts +9 -0
- package/dist/auth/constants/gender.d.ts.map +1 -0
- package/dist/auth/constants/gender.js +12 -0
- package/dist/auth/constants/index.d.ts +3 -0
- package/dist/auth/constants/index.d.ts.map +1 -0
- package/dist/auth/constants/index.js +2 -0
- package/dist/auth/forms/account/AuthAccountConfirmationForm.d.ts +18 -0
- package/dist/auth/forms/account/AuthAccountConfirmationForm.d.ts.map +1 -0
- package/dist/auth/forms/account/AuthAccountConfirmationForm.js +166 -0
- package/dist/auth/forms/account/index.d.ts +2 -0
- package/dist/auth/forms/account/index.d.ts.map +1 -0
- package/dist/auth/forms/account/index.js +1 -0
- package/dist/auth/forms/errorParser.d.ts +7 -0
- package/dist/auth/forms/errorParser.d.ts.map +1 -0
- package/dist/auth/forms/errorParser.js +65 -0
- package/dist/auth/forms/index.d.ts +6 -0
- package/dist/auth/forms/index.d.ts.map +1 -0
- package/dist/auth/forms/index.js +5 -0
- package/dist/auth/forms/password/AuthForgotPasswordForm.d.ts +12 -0
- package/dist/auth/forms/password/AuthForgotPasswordForm.d.ts.map +1 -0
- package/dist/auth/forms/password/AuthForgotPasswordForm.js +71 -0
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.d.ts +15 -0
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.d.ts.map +1 -0
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.js +88 -0
- package/dist/auth/forms/password/AuthResetPasswordForm.d.ts +12 -0
- package/dist/auth/forms/password/AuthResetPasswordForm.d.ts.map +1 -0
- package/dist/auth/forms/password/AuthResetPasswordForm.js +18 -0
- package/dist/auth/forms/password/index.d.ts +4 -0
- package/dist/auth/forms/password/index.d.ts.map +1 -0
- package/dist/auth/forms/password/index.js +3 -0
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.d.ts +24 -0
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.d.ts.map +1 -0
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.js +226 -0
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.d.ts +21 -0
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.d.ts.map +1 -0
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.js +120 -0
- package/dist/auth/forms/sign-in/index.d.ts +3 -0
- package/dist/auth/forms/sign-in/index.d.ts.map +1 -0
- package/dist/auth/forms/sign-in/index.js +2 -0
- package/dist/auth/forms/sign-up/AuthSignUpForm.d.ts +36 -0
- package/dist/auth/forms/sign-up/AuthSignUpForm.d.ts.map +1 -0
- package/dist/auth/forms/sign-up/AuthSignUpForm.js +164 -0
- package/dist/auth/forms/sign-up/index.d.ts +2 -0
- package/dist/auth/forms/sign-up/index.d.ts.map +1 -0
- package/dist/auth/forms/sign-up/index.js +1 -0
- package/dist/auth/fuse/createFuseAuthViews.d.ts +24 -0
- package/dist/auth/fuse/createFuseAuthViews.d.ts.map +1 -0
- package/dist/auth/fuse/createFuseAuthViews.js +360 -0
- package/dist/auth/fuse/fuseAdapter.d.ts +40 -0
- package/dist/auth/fuse/fuseAdapter.d.ts.map +1 -0
- package/dist/auth/fuse/fuseAdapter.js +265 -0
- package/dist/auth/fuse/fuseIntegration.d.ts +59 -0
- package/dist/auth/fuse/fuseIntegration.d.ts.map +1 -0
- package/dist/auth/fuse/fuseIntegration.js +85 -0
- package/dist/auth/fuse/index.d.ts +4 -0
- package/dist/auth/fuse/index.d.ts.map +1 -0
- package/dist/auth/fuse/index.js +3 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/provider.d.ts +35 -0
- package/dist/auth/provider.d.ts.map +1 -0
- package/dist/auth/provider.js +133 -0
- package/dist/auth/query.d.ts +23 -0
- package/dist/auth/query.d.ts.map +1 -0
- package/dist/auth/query.js +103 -0
- package/dist/auth/routes.d.ts +37 -0
- package/dist/auth/routes.d.ts.map +1 -0
- package/dist/auth/routes.js +73 -0
- package/dist/auth/social/providerAuth.d.ts +76 -0
- package/dist/auth/social/providerAuth.d.ts.map +1 -0
- package/dist/auth/social/providerAuth.js +130 -0
- package/dist/auth/storage.d.ts +3 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +20 -0
- package/dist/auth/types.d.ts +208 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/auth/ui/AuthPagesMessageSection.d.ts +3 -0
- package/dist/auth/ui/AuthPagesMessageSection.d.ts.map +1 -0
- package/dist/auth/ui/AuthPagesMessageSection.js +39 -0
- package/dist/auth/ui/AuthPrimaryButton.d.ts +9 -0
- package/dist/auth/ui/AuthPrimaryButton.d.ts.map +1 -0
- package/dist/auth/ui/AuthPrimaryButton.js +19 -0
- package/dist/auth/ui/AuthRoleSelectionDialog.d.ts +14 -0
- package/dist/auth/ui/AuthRoleSelectionDialog.d.ts.map +1 -0
- package/dist/auth/ui/AuthRoleSelectionDialog.js +39 -0
- package/dist/auth/ui/AuthRoutePageWrapper.d.ts +12 -0
- package/dist/auth/ui/AuthRoutePageWrapper.d.ts.map +1 -0
- package/dist/auth/ui/AuthRoutePageWrapper.js +59 -0
- package/dist/auth/ui/AuthSecondaryButton.d.ts +7 -0
- package/dist/auth/ui/AuthSecondaryButton.d.ts.map +1 -0
- package/dist/auth/ui/AuthSecondaryButton.js +18 -0
- package/dist/auth/ui/AuthSocialProviderButton.d.ts +11 -0
- package/dist/auth/ui/AuthSocialProviderButton.d.ts.map +1 -0
- package/dist/auth/ui/AuthSocialProviderButton.js +30 -0
- package/dist/auth/ui/SignInPageTitle.d.ts +6 -0
- package/dist/auth/ui/SignInPageTitle.d.ts.map +1 -0
- package/dist/auth/ui/SignInPageTitle.js +7 -0
- package/dist/auth/ui/SignOutPageTitle.d.ts +6 -0
- package/dist/auth/ui/SignOutPageTitle.d.ts.map +1 -0
- package/dist/auth/ui/SignOutPageTitle.js +7 -0
- package/dist/auth/ui/SignUpPageTitle.d.ts +6 -0
- package/dist/auth/ui/SignUpPageTitle.d.ts.map +1 -0
- package/dist/auth/ui/SignUpPageTitle.js +7 -0
- package/dist/auth/ui/index.d.ts +11 -0
- package/dist/auth/ui/index.d.ts.map +1 -0
- package/dist/auth/ui/index.js +10 -0
- package/dist/auth/ui/types.d.ts +15 -0
- package/dist/auth/ui/types.d.ts.map +1 -0
- package/dist/auth/ui/types.js +1 -0
- package/dist/config/createConfig.d.ts +13 -0
- package/dist/config/createConfig.d.ts.map +1 -0
- package/dist/config/createConfig.js +104 -0
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +38 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/merge.d.ts +2 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +18 -0
- package/dist/config/types.d.ts +46 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +1 -0
- package/dist/forms/JBCheckboxField.d.ts +12 -0
- package/dist/forms/JBCheckboxField.d.ts.map +1 -0
- package/dist/forms/JBCheckboxField.js +36 -0
- package/dist/forms/JBDatePickerField.d.ts +12 -0
- package/dist/forms/JBDatePickerField.d.ts.map +1 -0
- package/dist/forms/JBDatePickerField.js +14 -0
- package/dist/forms/JBRadioGroupField.d.ts +10 -0
- package/dist/forms/JBRadioGroupField.d.ts.map +1 -0
- package/dist/forms/JBRadioGroupField.js +8 -0
- package/dist/forms/JBSelectField.d.ts +9 -0
- package/dist/forms/JBSelectField.d.ts.map +1 -0
- package/dist/forms/JBSelectField.js +8 -0
- package/dist/forms/JBSwitchField.d.ts +11 -0
- package/dist/forms/JBSwitchField.d.ts.map +1 -0
- package/dist/forms/JBSwitchField.js +10 -0
- package/dist/forms/JBTextField.d.ts +6 -0
- package/dist/forms/JBTextField.d.ts.map +1 -0
- package/dist/forms/JBTextField.js +8 -0
- package/dist/forms/JBTimePickerField.d.ts +12 -0
- package/dist/forms/JBTimePickerField.d.ts.map +1 -0
- package/dist/forms/JBTimePickerField.js +14 -0
- package/dist/forms/index.d.ts +11 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/index.js +10 -0
- package/dist/forms/rules.d.ts +16 -0
- package/dist/forms/rules.d.ts.map +1 -0
- package/dist/forms/rules.js +21 -0
- package/dist/forms/types.d.ts +12 -0
- package/dist/forms/types.d.ts.map +1 -0
- package/dist/forms/types.js +1 -0
- package/dist/forms/utils.d.ts +5 -0
- package/dist/forms/utils.d.ts.map +1 -0
- package/dist/forms/utils.js +7 -0
- package/dist/grid/JBGrid.d.ts +3 -0
- package/dist/grid/JBGrid.d.ts.map +1 -0
- package/dist/grid/JBGrid.js +89 -0
- package/dist/grid/JBGridHeader.d.ts +3 -0
- package/dist/grid/JBGridHeader.d.ts.map +1 -0
- package/dist/grid/JBGridHeader.js +22 -0
- package/dist/grid/JBGridProviders.d.ts +10 -0
- package/dist/grid/JBGridProviders.d.ts.map +1 -0
- package/dist/grid/JBGridProviders.js +31 -0
- package/dist/grid/index.d.ts +5 -0
- package/dist/grid/index.d.ts.map +1 -0
- package/dist/grid/index.js +4 -0
- package/dist/grid/types.d.ts +81 -0
- package/dist/grid/types.d.ts.map +1 -0
- package/dist/grid/types.js +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useJBDebouncedValue.d.ts +2 -0
- package/dist/hooks/useJBDebouncedValue.d.ts.map +1 -0
- package/dist/hooks/useJBDebouncedValue.js +11 -0
- package/dist/hooks/useJBRedirect.d.ts +10 -0
- package/dist/hooks/useJBRedirect.d.ts.map +1 -0
- package/dist/hooks/useJBRedirect.js +11 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/query/createQueryClient.d.ts +8 -0
- package/dist/query/createQueryClient.d.ts.map +1 -0
- package/dist/query/createQueryClient.js +25 -0
- package/dist/query/http.d.ts +3 -0
- package/dist/query/http.d.ts.map +1 -0
- package/dist/query/http.js +12 -0
- package/dist/query/index.d.ts +3 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +2 -0
- package/dist/utils/format.d.ts +4 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +28 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/query.d.ts +2 -0
- package/dist/utils/query.d.ts.map +1 -0
- package/dist/utils/query.js +4 -0
- package/dist/utils/regex.d.ts +7 -0
- package/dist/utils/regex.d.ts.map +1 -0
- package/dist/utils/regex.js +6 -0
- package/package.json +85 -0
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# @joelbarron/react-web-dev-kit
|
|
2
|
+
|
|
3
|
+
Core reusable para apps web React.
|
|
4
|
+
|
|
5
|
+
Incluye:
|
|
6
|
+
- `auth` (`createAuthClient` para `jb-drf-auth`)
|
|
7
|
+
- `config` (`createJBWebConfig`, overrides por stage/env)
|
|
8
|
+
- `forms` (`JBTextField`, `JBSelectField`, `JBCheckboxField`, `JBSwitchField`, `JBRadioGroupField`, `JBDatePickerField`, `JBTimePickerField`)
|
|
9
|
+
- `grid` (`JBGrid`, `JBGridHeader`, providers)
|
|
10
|
+
- `hooks` y `utils`
|
|
11
|
+
|
|
12
|
+
## Documentacion por secciones
|
|
13
|
+
|
|
14
|
+
- [Indice docs](./docs/README.md)
|
|
15
|
+
- [Auth](./docs/auth.md)
|
|
16
|
+
- [Config](./docs/config.md)
|
|
17
|
+
- [Forms](./docs/forms.md)
|
|
18
|
+
- [Grid](./docs/grid.md)
|
|
19
|
+
- [Query](./docs/query.md)
|
|
20
|
+
- [Hooks](./docs/hooks.md)
|
|
21
|
+
- [Utils](./docs/utils.md)
|
|
22
|
+
|
|
23
|
+
## Instalacion
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm i @joelbarron/react-web-dev-kit
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Auth
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createAuthClient } from '@joelbarron/react-web-dev-kit';
|
|
33
|
+
|
|
34
|
+
export const authClient = createAuthClient({
|
|
35
|
+
apiBaseUrl: import.meta.env.VITE_API_URL,
|
|
36
|
+
onUnauthorized: () => {
|
|
37
|
+
// ejemplo: limpiar estado y redirigir
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await authClient.loginBasic({
|
|
42
|
+
login: 'demo@mail.com',
|
|
43
|
+
password: 'secret',
|
|
44
|
+
client: 'web'
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const me = await authClient.getMe();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Auth Provider + Hook
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { JBAuthProvider, useJBAuth, createAuthClient } from '@joelbarron/react-web-dev-kit/auth';
|
|
54
|
+
|
|
55
|
+
const authClient = createAuthClient({
|
|
56
|
+
apiBaseUrl: import.meta.env.VITE_API_URL
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function Root() {
|
|
60
|
+
return (
|
|
61
|
+
<JBAuthProvider authClient={authClient}>
|
|
62
|
+
<App />
|
|
63
|
+
</JBAuthProvider>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Auth Routes Factory
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { createAuthRoutes } from '@joelbarron/react-web-dev-kit/auth';
|
|
72
|
+
|
|
73
|
+
const authRoutes = createAuthRoutes({
|
|
74
|
+
pages: {
|
|
75
|
+
signIn: SignInPage,
|
|
76
|
+
signUp: SignUpPage,
|
|
77
|
+
forgotPassword: ForgotPasswordPage,
|
|
78
|
+
resetPassword: ResetPasswordPage,
|
|
79
|
+
signOut: SignOutPage
|
|
80
|
+
},
|
|
81
|
+
pageComponent: ({ children }) => <AuthLayout>{children}</AuthLayout>,
|
|
82
|
+
routeMeta: {
|
|
83
|
+
signIn: { auth: ['guest'] },
|
|
84
|
+
signUp: { auth: ['guest'] }
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Auth Query Hooks (TanStack Query)
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { createAuthClient, createAuthQueryHooks } from '@joelbarron/react-web-dev-kit/auth';
|
|
93
|
+
|
|
94
|
+
const authClient = createAuthClient({
|
|
95
|
+
apiBaseUrl: import.meta.env.VITE_API_URL
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const authQueryHooks = createAuthQueryHooks(authClient);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Query Client
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { createReactWebQueryClient } from '@joelbarron/react-web-dev-kit/query';
|
|
105
|
+
|
|
106
|
+
const queryClient = createReactWebQueryClient({
|
|
107
|
+
onUnauthorized: () => {
|
|
108
|
+
window.location.href = '/sign-in';
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Auth Forms Base
|
|
114
|
+
|
|
115
|
+
Tambien incluye formularios base para auth:
|
|
116
|
+
- `AuthPasswordSignInForm`
|
|
117
|
+
- `AuthForgotPasswordForm`
|
|
118
|
+
- `AuthResetPasswordForm`
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import { AuthPasswordSignInForm } from '@joelbarron/react-web-dev-kit/auth';
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Config Global (overrideable)
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { createJBWebConfigFromEnv, getApiBaseUrl } from '@joelbarron/react-web-dev-kit/config';
|
|
128
|
+
|
|
129
|
+
const appConfig = createJBWebConfigFromEnv(
|
|
130
|
+
{
|
|
131
|
+
stage: 'qa',
|
|
132
|
+
api: {
|
|
133
|
+
version: 'v1',
|
|
134
|
+
host: {
|
|
135
|
+
production: 'https://api.example.com',
|
|
136
|
+
qa: 'https://api-qa.example.com',
|
|
137
|
+
development: 'http://127.0.0.1:8000',
|
|
138
|
+
local: 'http://localhost:8000'
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
import.meta.env as Record<string, string | undefined>
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const apiBaseUrl = getApiBaseUrl(appConfig);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Forms (React Hook Form + MUI)
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
152
|
+
import { JBDatePickerField, JBSelectField, JBTextField } from '@joelbarron/react-web-dev-kit';
|
|
153
|
+
|
|
154
|
+
type FormValues = {
|
|
155
|
+
name: string;
|
|
156
|
+
status: string;
|
|
157
|
+
birthday: Date | null;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const options = [
|
|
161
|
+
{ label: 'Active', value: 'ACTIVE' },
|
|
162
|
+
{ label: 'Inactive', value: 'INACTIVE' }
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
function ExampleForm() {
|
|
166
|
+
const { control } = useForm<FormValues>({
|
|
167
|
+
defaultValues: { name: '', status: '', birthday: null }
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<JBTextField
|
|
173
|
+
control={control}
|
|
174
|
+
name="name"
|
|
175
|
+
label="Name"
|
|
176
|
+
fullWidth
|
|
177
|
+
/>
|
|
178
|
+
<JBSelectField
|
|
179
|
+
control={control}
|
|
180
|
+
name="status"
|
|
181
|
+
label="Status"
|
|
182
|
+
options={options}
|
|
183
|
+
fullWidth
|
|
184
|
+
/>
|
|
185
|
+
<JBDatePickerField
|
|
186
|
+
control={control}
|
|
187
|
+
name="birthday"
|
|
188
|
+
label="Birthday"
|
|
189
|
+
/>
|
|
190
|
+
</>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Grid
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
import { JBGrid, JBGridHeader, JBGridConfig } from '@joelbarron/react-web-dev-kit';
|
|
199
|
+
import { useState } from 'react';
|
|
200
|
+
|
|
201
|
+
const gridConfig: JBGridConfig = {
|
|
202
|
+
columns: [
|
|
203
|
+
{ name: 'id', title: 'ID' },
|
|
204
|
+
{ name: 'name', title: 'Name' }
|
|
205
|
+
],
|
|
206
|
+
columnsWidths: [
|
|
207
|
+
{ columnName: 'id', width: 120 },
|
|
208
|
+
{ columnName: 'name', width: 320 }
|
|
209
|
+
],
|
|
210
|
+
defaults: {
|
|
211
|
+
pageSize: 10,
|
|
212
|
+
allowSelection: true
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
function ExampleGrid({ service }: { service: { list: Function } }) {
|
|
217
|
+
const [searchText, setSearchText] = useState('');
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<>
|
|
221
|
+
<JBGridHeader
|
|
222
|
+
title="Users"
|
|
223
|
+
searchText={searchText}
|
|
224
|
+
onSearchTextChange={setSearchText}
|
|
225
|
+
/>
|
|
226
|
+
<JBGrid
|
|
227
|
+
gridConfig={gridConfig}
|
|
228
|
+
service={service as any}
|
|
229
|
+
searchText={searchText}
|
|
230
|
+
onSearchTextChange={setSearchText}
|
|
231
|
+
onRowSelected={(row) => console.log(row)}
|
|
232
|
+
/>
|
|
233
|
+
</>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { JBAppConfig } from '../config';
|
|
3
|
+
import { AccountUpdatePayload, AccountConfirmationPayload, AccountConfirmationResendPayload, ApiDetailResponse, CreateAdminUserPayload, CreateProfilePayload, CreateAuthenticatedAxiosOptions, DeleteAccountPayload, JbDrfAuthConfig, JbDrfAuthEndpoints, JbDrfWebAuthResponse, LinkSocialPayload, LoginBasicPayload, LoginSocialPayload, PasswordChangePayload, PasswordResetConfirmPayload, PasswordResetRequestPayload, ProfilePicturePayload, ProfilesResponse, RegisterPayload, RefreshPayload, RequestOtpPayload, SwitchProfilePayload, TokenPair, TokenStorage, UnlinkSocialPayload, UpdateProfilePayload, VerifyOtpPayload } from './types';
|
|
4
|
+
export declare const createAuthEndpoints: (basePath?: string) => JbDrfAuthEndpoints;
|
|
5
|
+
export declare const defaultAuthEndpoints: JbDrfAuthEndpoints;
|
|
6
|
+
export type AuthClient = {
|
|
7
|
+
endpoints: JbDrfAuthEndpoints;
|
|
8
|
+
tokenStorage: TokenStorage;
|
|
9
|
+
getAccessToken: () => string | null;
|
|
10
|
+
setAccessToken: (token: string) => void;
|
|
11
|
+
clearSession: () => void;
|
|
12
|
+
createPublicAxios: () => AxiosInstance;
|
|
13
|
+
createAuthenticatedAxios: (options?: CreateAuthenticatedAxiosOptions) => AxiosInstance;
|
|
14
|
+
createAuthenticatedAxiosWithRefresh: (options?: CreateAuthenticatedAxiosOptions) => AxiosInstance;
|
|
15
|
+
loginBasic: (payload: LoginBasicPayload) => Promise<JbDrfWebAuthResponse>;
|
|
16
|
+
loginSocial: (payload: LoginSocialPayload) => Promise<JbDrfWebAuthResponse>;
|
|
17
|
+
linkSocial: (payload: LinkSocialPayload) => Promise<Record<string, unknown>>;
|
|
18
|
+
unlinkSocial: (payload: UnlinkSocialPayload) => Promise<Record<string, unknown>>;
|
|
19
|
+
requestOtp: (payload: RequestOtpPayload) => Promise<Record<string, unknown>>;
|
|
20
|
+
verifyOtp: (payload: VerifyOtpPayload) => Promise<JbDrfWebAuthResponse>;
|
|
21
|
+
register: (payload: RegisterPayload) => Promise<ApiDetailResponse>;
|
|
22
|
+
confirmAccountEmail: (payload: AccountConfirmationPayload) => Promise<ApiDetailResponse>;
|
|
23
|
+
resendAccountConfirmation: (payload: AccountConfirmationResendPayload) => Promise<ApiDetailResponse>;
|
|
24
|
+
getMe: () => Promise<JbDrfWebAuthResponse>;
|
|
25
|
+
updateProfilePicture: (payload: ProfilePicturePayload) => Promise<Record<string, unknown>>;
|
|
26
|
+
updateAccount: (payload: AccountUpdatePayload, method?: 'PATCH' | 'PUT') => Promise<Record<string, unknown>>;
|
|
27
|
+
deleteAccount: (payload: DeleteAccountPayload) => Promise<unknown>;
|
|
28
|
+
getProfiles: () => Promise<ProfilesResponse>;
|
|
29
|
+
getProfileById: (profileId: number | string) => Promise<Record<string, unknown>>;
|
|
30
|
+
createProfile: (payload: CreateProfilePayload) => Promise<Record<string, unknown>>;
|
|
31
|
+
updateProfile: (profileId: number | string, payload: UpdateProfilePayload) => Promise<Record<string, unknown>>;
|
|
32
|
+
deleteProfile: (profileId: number | string) => Promise<Record<string, unknown>>;
|
|
33
|
+
requestPasswordReset: (payload: PasswordResetRequestPayload) => Promise<Record<string, unknown>>;
|
|
34
|
+
confirmPasswordReset: (payload: PasswordResetConfirmPayload) => Promise<Record<string, unknown>>;
|
|
35
|
+
changePassword: (payload: PasswordChangePayload) => Promise<Record<string, unknown>>;
|
|
36
|
+
refreshToken: (payload?: RefreshPayload) => Promise<TokenPair>;
|
|
37
|
+
switchProfile: (payload: SwitchProfilePayload) => Promise<JbDrfWebAuthResponse>;
|
|
38
|
+
createSuperuser: (payload: CreateAdminUserPayload, bootstrapToken?: string) => Promise<Record<string, unknown>>;
|
|
39
|
+
createStaffUser: (payload: CreateAdminUserPayload, bootstrapToken?: string) => Promise<Record<string, unknown>>;
|
|
40
|
+
logout: () => void;
|
|
41
|
+
};
|
|
42
|
+
export declare const createAuthClient: (config: JbDrfAuthConfig) => AuthClient;
|
|
43
|
+
export declare const createAuthClientFromJBWebConfig: (appConfig: JBAppConfig, overrides?: Omit<JbDrfAuthConfig, "apiBaseUrl" | "apiBasePath">) => AuthClient;
|
|
44
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getApiBaseUrl, getAuthBasePath } from '../config';
|
|
3
|
+
import { createLocalStorageTokenStorage } from './storage';
|
|
4
|
+
const normalizeAuthBasePath = (basePath) => {
|
|
5
|
+
const normalized = (basePath ?? '/authentication').trim();
|
|
6
|
+
if (!normalized) {
|
|
7
|
+
return '/authentication';
|
|
8
|
+
}
|
|
9
|
+
const withLeadingSlash = normalized.startsWith('/') ? normalized : `/${normalized}`;
|
|
10
|
+
return withLeadingSlash.replace(/\/+$/, '');
|
|
11
|
+
};
|
|
12
|
+
export const createAuthEndpoints = (basePath) => {
|
|
13
|
+
const root = normalizeAuthBasePath(basePath);
|
|
14
|
+
return {
|
|
15
|
+
loginBasic: `${root}/login/basic/`,
|
|
16
|
+
loginSocial: `${root}/login/social/`,
|
|
17
|
+
loginSocialLink: `${root}/login/social/link/`,
|
|
18
|
+
loginSocialUnlink: `${root}/login/social/unlink/`,
|
|
19
|
+
loginOtpVerify: `${root}/otp/verify/`,
|
|
20
|
+
otpRequest: `${root}/otp/request/`,
|
|
21
|
+
register: `${root}/register/`,
|
|
22
|
+
accountConfirmation: `${root}/registration/account-confirmation-email/`,
|
|
23
|
+
accountConfirmationResend: `${root}/registration/account-confirmation-email/resend/`,
|
|
24
|
+
me: `${root}/me/?client=web`,
|
|
25
|
+
profilePicture: `${root}/profile/picture/`,
|
|
26
|
+
refresh: `${root}/token/refresh/`,
|
|
27
|
+
switchProfile: `${root}/profile/switch/`,
|
|
28
|
+
profiles: `${root}/profiles/`,
|
|
29
|
+
accountUpdate: `${root}/account/update/`,
|
|
30
|
+
accountDelete: `${root}/account/delete/`,
|
|
31
|
+
passwordResetRequest: `${root}/password-reset/request/`,
|
|
32
|
+
passwordResetConfirm: `${root}/password-reset/confirm/`,
|
|
33
|
+
passwordResetChange: `${root}/password-reset/change/`,
|
|
34
|
+
adminCreateSuperuser: `${root}/admin/create-superuser/`,
|
|
35
|
+
adminCreateStaff: `${root}/admin/create-staff/`
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export const defaultAuthEndpoints = createAuthEndpoints('/authentication');
|
|
39
|
+
const getRefreshTokenFromResponse = (response) => ({
|
|
40
|
+
accessToken: response.data.accessToken ?? response.data.access ?? '',
|
|
41
|
+
refreshToken: response.data.refreshToken ?? response.data.refresh ?? ''
|
|
42
|
+
});
|
|
43
|
+
const normalizeBaseUrl = (apiBaseUrl) => apiBaseUrl.replace(/\/+$/, '');
|
|
44
|
+
const normalizeDetailResponse = (data) => ({
|
|
45
|
+
...data,
|
|
46
|
+
emailSent: data.emailSent ?? data.email_sent
|
|
47
|
+
});
|
|
48
|
+
const withClientPayload = (payload, defaultClient) => {
|
|
49
|
+
const client = payload.client ?? defaultClient;
|
|
50
|
+
if (client === 'web') {
|
|
51
|
+
const { device: _device, ...rest } = payload;
|
|
52
|
+
return { ...rest, client };
|
|
53
|
+
}
|
|
54
|
+
return { ...payload, client };
|
|
55
|
+
};
|
|
56
|
+
export const createAuthClient = (config) => {
|
|
57
|
+
const endpoints = {
|
|
58
|
+
...createAuthEndpoints(config.apiBasePath),
|
|
59
|
+
...(config.endpoints ?? {})
|
|
60
|
+
};
|
|
61
|
+
const tokenStorageKey = config.tokenStorageKey ?? 'jwt_access_token';
|
|
62
|
+
const refreshTokenStorageKey = config.refreshTokenStorageKey ?? 'jwt_refresh_token';
|
|
63
|
+
const tokenStorage = config.tokenStorage ?? createLocalStorageTokenStorage(tokenStorageKey);
|
|
64
|
+
const baseUrl = normalizeBaseUrl(config.apiBaseUrl);
|
|
65
|
+
const defaultClient = config.defaultClient ?? 'web';
|
|
66
|
+
const withBaseUrl = (path) => `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
|
|
67
|
+
const getAccessToken = () => tokenStorage.getAccessToken();
|
|
68
|
+
const setAccessToken = (token) => tokenStorage.setAccessToken(token);
|
|
69
|
+
const clearSession = () => tokenStorage.removeAccessToken();
|
|
70
|
+
let refreshPromise = null;
|
|
71
|
+
const saveRefreshToken = (token) => {
|
|
72
|
+
if (!token) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
window.localStorage.setItem(refreshTokenStorageKey, token);
|
|
79
|
+
};
|
|
80
|
+
const getStoredRefreshToken = () => {
|
|
81
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return window.localStorage.getItem(refreshTokenStorageKey);
|
|
85
|
+
};
|
|
86
|
+
const clearStoredRefreshToken = () => {
|
|
87
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
window.localStorage.removeItem(refreshTokenStorageKey);
|
|
91
|
+
};
|
|
92
|
+
const createPublicAxios = () => axios.create({
|
|
93
|
+
baseURL: baseUrl
|
|
94
|
+
});
|
|
95
|
+
const createAuthenticatedAxios = (options) => {
|
|
96
|
+
const instance = axios.create({
|
|
97
|
+
baseURL: baseUrl,
|
|
98
|
+
...(options?.requestConfig ?? {})
|
|
99
|
+
});
|
|
100
|
+
instance.interceptors.request.use((requestConfig) => {
|
|
101
|
+
const token = getAccessToken();
|
|
102
|
+
if (token) {
|
|
103
|
+
requestConfig.headers = requestConfig.headers ?? {};
|
|
104
|
+
requestConfig.headers.Authorization = `Bearer ${token}`;
|
|
105
|
+
}
|
|
106
|
+
return requestConfig;
|
|
107
|
+
});
|
|
108
|
+
instance.interceptors.response.use((response) => response, (error) => {
|
|
109
|
+
if (axios.isAxiosError(error) &&
|
|
110
|
+
error.response?.status === 401 &&
|
|
111
|
+
typeof config.onUnauthorized === 'function') {
|
|
112
|
+
config.onUnauthorized();
|
|
113
|
+
}
|
|
114
|
+
return Promise.reject(error);
|
|
115
|
+
});
|
|
116
|
+
return instance;
|
|
117
|
+
};
|
|
118
|
+
const createAuthenticatedAxiosWithRefresh = (options) => {
|
|
119
|
+
const instance = createAuthenticatedAxios(options);
|
|
120
|
+
instance.interceptors.response.use((response) => response, async (error) => {
|
|
121
|
+
if (!axios.isAxiosError(error)) {
|
|
122
|
+
return Promise.reject(error);
|
|
123
|
+
}
|
|
124
|
+
const originalRequest = error.config;
|
|
125
|
+
if (error.response?.status !== 401 || !originalRequest || originalRequest._retry) {
|
|
126
|
+
return Promise.reject(error);
|
|
127
|
+
}
|
|
128
|
+
originalRequest._retry = true;
|
|
129
|
+
try {
|
|
130
|
+
if (!refreshPromise) {
|
|
131
|
+
refreshPromise = (async () => {
|
|
132
|
+
const refreshTokenFromStorage = getStoredRefreshToken();
|
|
133
|
+
if (!refreshTokenFromStorage) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const nextTokens = await refreshToken({ refreshToken: refreshTokenFromStorage });
|
|
137
|
+
saveRefreshToken(nextTokens.refreshToken);
|
|
138
|
+
return nextTokens.accessToken || null;
|
|
139
|
+
})().finally(() => {
|
|
140
|
+
refreshPromise = null;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const nextAccessToken = await refreshPromise;
|
|
144
|
+
if (!nextAccessToken) {
|
|
145
|
+
return Promise.reject(error);
|
|
146
|
+
}
|
|
147
|
+
setAccessToken(nextAccessToken);
|
|
148
|
+
originalRequest.headers = originalRequest.headers ?? {};
|
|
149
|
+
originalRequest.headers.Authorization = `Bearer ${nextAccessToken}`;
|
|
150
|
+
return instance(originalRequest);
|
|
151
|
+
}
|
|
152
|
+
catch (refreshError) {
|
|
153
|
+
if (typeof config.onUnauthorized === 'function') {
|
|
154
|
+
config.onUnauthorized();
|
|
155
|
+
}
|
|
156
|
+
return Promise.reject(refreshError);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return instance;
|
|
160
|
+
};
|
|
161
|
+
const loginBasic = async (payload) => {
|
|
162
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.loginBasic), {
|
|
163
|
+
...withClientPayload(payload, defaultClient)
|
|
164
|
+
});
|
|
165
|
+
const accessToken = response.data.tokens?.accessToken;
|
|
166
|
+
const refreshTokenValue = response.data.tokens?.refreshToken;
|
|
167
|
+
if (accessToken) {
|
|
168
|
+
setAccessToken(accessToken);
|
|
169
|
+
}
|
|
170
|
+
saveRefreshToken(refreshTokenValue);
|
|
171
|
+
return response.data;
|
|
172
|
+
};
|
|
173
|
+
const loginSocial = async (payload) => {
|
|
174
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.loginSocial), withClientPayload(payload, defaultClient));
|
|
175
|
+
const accessToken = response.data.tokens?.accessToken;
|
|
176
|
+
const refreshTokenValue = response.data.tokens?.refreshToken;
|
|
177
|
+
if (accessToken) {
|
|
178
|
+
setAccessToken(accessToken);
|
|
179
|
+
}
|
|
180
|
+
saveRefreshToken(refreshTokenValue);
|
|
181
|
+
return response.data;
|
|
182
|
+
};
|
|
183
|
+
const linkSocial = async (payload) => {
|
|
184
|
+
const response = await createAuthenticatedAxiosWithRefresh().post(withBaseUrl(endpoints.loginSocialLink), payload);
|
|
185
|
+
return response.data;
|
|
186
|
+
};
|
|
187
|
+
const unlinkSocial = async (payload) => {
|
|
188
|
+
const response = await createAuthenticatedAxiosWithRefresh().post(withBaseUrl(endpoints.loginSocialUnlink), payload);
|
|
189
|
+
return response.data;
|
|
190
|
+
};
|
|
191
|
+
const requestOtp = async (payload) => {
|
|
192
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.otpRequest), payload);
|
|
193
|
+
return response.data;
|
|
194
|
+
};
|
|
195
|
+
const verifyOtp = async (payload) => {
|
|
196
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.loginOtpVerify), withClientPayload(payload, defaultClient));
|
|
197
|
+
const accessToken = response.data.tokens?.accessToken;
|
|
198
|
+
const refreshTokenValue = response.data.tokens?.refreshToken;
|
|
199
|
+
if (accessToken) {
|
|
200
|
+
setAccessToken(accessToken);
|
|
201
|
+
}
|
|
202
|
+
saveRefreshToken(refreshTokenValue);
|
|
203
|
+
return response.data;
|
|
204
|
+
};
|
|
205
|
+
const register = async (payload) => {
|
|
206
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.register), payload);
|
|
207
|
+
return normalizeDetailResponse(response.data);
|
|
208
|
+
};
|
|
209
|
+
const confirmAccountEmail = async (payload) => {
|
|
210
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.accountConfirmation), payload);
|
|
211
|
+
return normalizeDetailResponse(response.data);
|
|
212
|
+
};
|
|
213
|
+
const resendAccountConfirmation = async (payload) => {
|
|
214
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.accountConfirmationResend), payload);
|
|
215
|
+
return normalizeDetailResponse(response.data);
|
|
216
|
+
};
|
|
217
|
+
const getMe = async () => {
|
|
218
|
+
const response = await createAuthenticatedAxiosWithRefresh().get(withBaseUrl(endpoints.me));
|
|
219
|
+
return response.data;
|
|
220
|
+
};
|
|
221
|
+
const updateProfilePicture = async (payload) => {
|
|
222
|
+
const response = await createAuthenticatedAxiosWithRefresh().patch(withBaseUrl(endpoints.profilePicture), payload);
|
|
223
|
+
return response.data;
|
|
224
|
+
};
|
|
225
|
+
const updateAccount = async (payload, method = 'PATCH') => {
|
|
226
|
+
const instance = createAuthenticatedAxiosWithRefresh();
|
|
227
|
+
const response = method === 'PUT'
|
|
228
|
+
? await instance.put(withBaseUrl(endpoints.accountUpdate), payload)
|
|
229
|
+
: await instance.patch(withBaseUrl(endpoints.accountUpdate), payload);
|
|
230
|
+
return response.data;
|
|
231
|
+
};
|
|
232
|
+
const deleteAccount = async (payload) => {
|
|
233
|
+
const response = await createAuthenticatedAxiosWithRefresh().delete(withBaseUrl(endpoints.accountDelete), {
|
|
234
|
+
data: payload
|
|
235
|
+
});
|
|
236
|
+
return response.data;
|
|
237
|
+
};
|
|
238
|
+
const getProfiles = async () => {
|
|
239
|
+
const response = await createAuthenticatedAxiosWithRefresh().get(withBaseUrl(endpoints.profiles));
|
|
240
|
+
return response.data;
|
|
241
|
+
};
|
|
242
|
+
const getProfileById = async (profileId) => {
|
|
243
|
+
const response = await createAuthenticatedAxiosWithRefresh().get(withBaseUrl(`${endpoints.profiles}${profileId}/`));
|
|
244
|
+
return response.data;
|
|
245
|
+
};
|
|
246
|
+
const createProfile = async (payload) => {
|
|
247
|
+
const response = await createAuthenticatedAxiosWithRefresh().post(withBaseUrl(endpoints.profiles), payload);
|
|
248
|
+
return response.data;
|
|
249
|
+
};
|
|
250
|
+
const updateProfile = async (profileId, payload) => {
|
|
251
|
+
const response = await createAuthenticatedAxiosWithRefresh().patch(withBaseUrl(`${endpoints.profiles}${profileId}/`), payload);
|
|
252
|
+
return response.data;
|
|
253
|
+
};
|
|
254
|
+
const deleteProfile = async (profileId) => {
|
|
255
|
+
const response = await createAuthenticatedAxiosWithRefresh().delete(withBaseUrl(`${endpoints.profiles}${profileId}/`));
|
|
256
|
+
return response.data;
|
|
257
|
+
};
|
|
258
|
+
const requestPasswordReset = async (payload) => {
|
|
259
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.passwordResetRequest), payload);
|
|
260
|
+
return normalizeDetailResponse(response.data);
|
|
261
|
+
};
|
|
262
|
+
const confirmPasswordReset = async (payload) => {
|
|
263
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.passwordResetConfirm), payload);
|
|
264
|
+
return response.data;
|
|
265
|
+
};
|
|
266
|
+
const changePassword = async (payload) => {
|
|
267
|
+
const response = await createAuthenticatedAxiosWithRefresh().post(withBaseUrl(endpoints.passwordResetChange), payload);
|
|
268
|
+
return response.data;
|
|
269
|
+
};
|
|
270
|
+
const refreshToken = async (payload) => {
|
|
271
|
+
const response = await createPublicAxios().post(withBaseUrl(endpoints.refresh), {
|
|
272
|
+
refresh: payload?.refreshToken
|
|
273
|
+
});
|
|
274
|
+
const nextTokens = getRefreshTokenFromResponse(response);
|
|
275
|
+
if (nextTokens.accessToken) {
|
|
276
|
+
setAccessToken(nextTokens.accessToken);
|
|
277
|
+
}
|
|
278
|
+
saveRefreshToken(nextTokens.refreshToken);
|
|
279
|
+
return nextTokens;
|
|
280
|
+
};
|
|
281
|
+
const switchProfile = async (payload) => {
|
|
282
|
+
const response = await createAuthenticatedAxios().post(withBaseUrl(endpoints.switchProfile), withClientPayload(payload, defaultClient));
|
|
283
|
+
const accessToken = response.data.tokens?.accessToken;
|
|
284
|
+
const refreshTokenValue = response.data.tokens?.refreshToken;
|
|
285
|
+
if (accessToken) {
|
|
286
|
+
setAccessToken(accessToken);
|
|
287
|
+
}
|
|
288
|
+
saveRefreshToken(refreshTokenValue);
|
|
289
|
+
return response.data;
|
|
290
|
+
};
|
|
291
|
+
const logout = () => {
|
|
292
|
+
clearSession();
|
|
293
|
+
clearStoredRefreshToken();
|
|
294
|
+
};
|
|
295
|
+
const createAdminUser = async (endpoint, payload, bootstrapToken) => {
|
|
296
|
+
const headers = bootstrapToken
|
|
297
|
+
? {
|
|
298
|
+
'X-Admin-Bootstrap-Token': bootstrapToken
|
|
299
|
+
}
|
|
300
|
+
: undefined;
|
|
301
|
+
const requestClient = bootstrapToken ? createPublicAxios() : createAuthenticatedAxiosWithRefresh();
|
|
302
|
+
const response = await requestClient.post(withBaseUrl(endpoint), payload, { headers });
|
|
303
|
+
return response.data;
|
|
304
|
+
};
|
|
305
|
+
const createSuperuser = async (payload, bootstrapToken) => {
|
|
306
|
+
return createAdminUser(endpoints.adminCreateSuperuser, payload, bootstrapToken);
|
|
307
|
+
};
|
|
308
|
+
const createStaffUser = async (payload, bootstrapToken) => {
|
|
309
|
+
return createAdminUser(endpoints.adminCreateStaff, payload, bootstrapToken);
|
|
310
|
+
};
|
|
311
|
+
return {
|
|
312
|
+
endpoints,
|
|
313
|
+
tokenStorage,
|
|
314
|
+
getAccessToken,
|
|
315
|
+
setAccessToken,
|
|
316
|
+
clearSession,
|
|
317
|
+
createPublicAxios,
|
|
318
|
+
createAuthenticatedAxios,
|
|
319
|
+
createAuthenticatedAxiosWithRefresh,
|
|
320
|
+
loginBasic,
|
|
321
|
+
loginSocial,
|
|
322
|
+
linkSocial,
|
|
323
|
+
unlinkSocial,
|
|
324
|
+
requestOtp,
|
|
325
|
+
verifyOtp,
|
|
326
|
+
register,
|
|
327
|
+
confirmAccountEmail,
|
|
328
|
+
resendAccountConfirmation,
|
|
329
|
+
getMe,
|
|
330
|
+
updateProfilePicture,
|
|
331
|
+
updateAccount,
|
|
332
|
+
deleteAccount,
|
|
333
|
+
getProfiles,
|
|
334
|
+
getProfileById,
|
|
335
|
+
createProfile,
|
|
336
|
+
updateProfile,
|
|
337
|
+
deleteProfile,
|
|
338
|
+
requestPasswordReset,
|
|
339
|
+
confirmPasswordReset,
|
|
340
|
+
changePassword,
|
|
341
|
+
refreshToken,
|
|
342
|
+
switchProfile,
|
|
343
|
+
createSuperuser,
|
|
344
|
+
createStaffUser,
|
|
345
|
+
logout
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
export const createAuthClientFromJBWebConfig = (appConfig, overrides) => {
|
|
349
|
+
return createAuthClient({
|
|
350
|
+
apiBaseUrl: getApiBaseUrl(appConfig),
|
|
351
|
+
apiBasePath: getAuthBasePath(appConfig),
|
|
352
|
+
...(overrides ?? {})
|
|
353
|
+
});
|
|
354
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SelectOption } from '../../forms';
|
|
2
|
+
export type CountryCallingCodeOption = SelectOption<string> & {
|
|
3
|
+
iso2: string;
|
|
4
|
+
countryName: string;
|
|
5
|
+
dialCode: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const COUNTRY_CALLING_CODE_OPTIONS: CountryCallingCodeOption[];
|
|
8
|
+
export declare const DEFAULT_OTP_COUNTRY_CODE = "+52";
|
|
9
|
+
//# sourceMappingURL=countryCallingCodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countryCallingCodes.d.ts","sourceRoot":"","sources":["../../../src/auth/constants/countryCallingCodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,wBAAwB,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,wBAAwB,EA+MlE,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAQ,CAAC"}
|