@makroz/mobile 1.0.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/LICENSE +33 -0
- package/README.md +19 -0
- package/dist/auth/MkAuthContext.d.ts +72 -0
- package/dist/auth/MkAuthContext.d.ts.map +1 -0
- package/dist/auth/MkAuthContext.js +19 -0
- package/dist/auth/MkAuthContext.js.map +1 -0
- package/dist/auth/MkAuthForm.d.ts +31 -0
- package/dist/auth/MkAuthForm.d.ts.map +1 -0
- package/dist/auth/MkAuthForm.js +180 -0
- package/dist/auth/MkAuthForm.js.map +1 -0
- package/dist/auth/MkAuthProvider.d.ts +57 -0
- package/dist/auth/MkAuthProvider.d.ts.map +1 -0
- package/dist/auth/MkAuthProvider.js +282 -0
- package/dist/auth/MkAuthProvider.js.map +1 -0
- package/dist/auth/secureStorage.d.ts +63 -0
- package/dist/auth/secureStorage.d.ts.map +1 -0
- package/dist/auth/secureStorage.js +104 -0
- package/dist/auth/secureStorage.js.map +1 -0
- package/dist/auth/types.d.ts +65 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +10 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/useMkAuth.d.ts +17 -0
- package/dist/auth/useMkAuth.d.ts.map +1 -0
- package/dist/auth/useMkAuth.js +24 -0
- package/dist/auth/useMkAuth.js.map +1 -0
- package/dist/components/MkAccordion.d.ts +19 -0
- package/dist/components/MkAccordion.d.ts.map +1 -0
- package/dist/components/MkAccordion.js +49 -0
- package/dist/components/MkAccordion.js.map +1 -0
- package/dist/components/MkAlert.d.ts +18 -0
- package/dist/components/MkAlert.d.ts.map +1 -0
- package/dist/components/MkAlert.js +35 -0
- package/dist/components/MkAlert.js.map +1 -0
- package/dist/components/MkAvatar.d.ts +12 -0
- package/dist/components/MkAvatar.d.ts.map +1 -0
- package/dist/components/MkAvatar.js +33 -0
- package/dist/components/MkAvatar.js.map +1 -0
- package/dist/components/MkBadge.d.ts +11 -0
- package/dist/components/MkBadge.d.ts.map +1 -0
- package/dist/components/MkBadge.js +22 -0
- package/dist/components/MkBadge.js.map +1 -0
- package/dist/components/MkButton.d.ts +13 -0
- package/dist/components/MkButton.d.ts.map +1 -0
- package/dist/components/MkButton.js +53 -0
- package/dist/components/MkButton.js.map +1 -0
- package/dist/components/MkCard.d.ts +15 -0
- package/dist/components/MkCard.d.ts.map +1 -0
- package/dist/components/MkCard.js +25 -0
- package/dist/components/MkCard.js.map +1 -0
- package/dist/components/MkCheck.d.ts +18 -0
- package/dist/components/MkCheck.d.ts.map +1 -0
- package/dist/components/MkCheck.js +33 -0
- package/dist/components/MkCheck.js.map +1 -0
- package/dist/components/MkDatePicker.d.ts +30 -0
- package/dist/components/MkDatePicker.d.ts.map +1 -0
- package/dist/components/MkDatePicker.js +87 -0
- package/dist/components/MkDatePicker.js.map +1 -0
- package/dist/components/MkDivider.d.ts +11 -0
- package/dist/components/MkDivider.d.ts.map +1 -0
- package/dist/components/MkDivider.js +28 -0
- package/dist/components/MkDivider.js.map +1 -0
- package/dist/components/MkDropDown.d.ts +37 -0
- package/dist/components/MkDropDown.d.ts.map +1 -0
- package/dist/components/MkDropDown.js +82 -0
- package/dist/components/MkDropDown.js.map +1 -0
- package/dist/components/MkEmptyState.d.ts +11 -0
- package/dist/components/MkEmptyState.d.ts.map +1 -0
- package/dist/components/MkEmptyState.js +16 -0
- package/dist/components/MkEmptyState.js.map +1 -0
- package/dist/components/MkFileUpload.d.ts +63 -0
- package/dist/components/MkFileUpload.d.ts.map +1 -0
- package/dist/components/MkFileUpload.js +80 -0
- package/dist/components/MkFileUpload.js.map +1 -0
- package/dist/components/MkIcons.d.ts +15 -0
- package/dist/components/MkIcons.d.ts.map +1 -0
- package/dist/components/MkIcons.js +35 -0
- package/dist/components/MkIcons.js.map +1 -0
- package/dist/components/MkInfiniteList.d.ts +22 -0
- package/dist/components/MkInfiniteList.d.ts.map +1 -0
- package/dist/components/MkInfiniteList.js +62 -0
- package/dist/components/MkInfiniteList.js.map +1 -0
- package/dist/components/MkInput.d.ts +16 -0
- package/dist/components/MkInput.d.ts.map +1 -0
- package/dist/components/MkInput.js +66 -0
- package/dist/components/MkInput.js.map +1 -0
- package/dist/components/MkLoading.d.ts +12 -0
- package/dist/components/MkLoading.d.ts.map +1 -0
- package/dist/components/MkLoading.js +20 -0
- package/dist/components/MkLoading.js.map +1 -0
- package/dist/components/MkModal.d.ts +20 -0
- package/dist/components/MkModal.d.ts.map +1 -0
- package/dist/components/MkModal.js +71 -0
- package/dist/components/MkModal.js.map +1 -0
- package/dist/components/MkProgressBar.d.ts +13 -0
- package/dist/components/MkProgressBar.d.ts.map +1 -0
- package/dist/components/MkProgressBar.js +27 -0
- package/dist/components/MkProgressBar.js.map +1 -0
- package/dist/components/MkRadio.d.ts +20 -0
- package/dist/components/MkRadio.d.ts.map +1 -0
- package/dist/components/MkRadio.js +35 -0
- package/dist/components/MkRadio.js.map +1 -0
- package/dist/components/MkSearchInput.d.ts +21 -0
- package/dist/components/MkSearchInput.d.ts.map +1 -0
- package/dist/components/MkSearchInput.js +44 -0
- package/dist/components/MkSearchInput.js.map +1 -0
- package/dist/components/MkSelect.d.ts +16 -0
- package/dist/components/MkSelect.d.ts.map +1 -0
- package/dist/components/MkSelect.js +75 -0
- package/dist/components/MkSelect.js.map +1 -0
- package/dist/components/MkSkeleton.d.ts +13 -0
- package/dist/components/MkSkeleton.d.ts.map +1 -0
- package/dist/components/MkSkeleton.js +32 -0
- package/dist/components/MkSkeleton.js.map +1 -0
- package/dist/components/MkSwitch.d.ts +13 -0
- package/dist/components/MkSwitch.d.ts.map +1 -0
- package/dist/components/MkSwitch.js +68 -0
- package/dist/components/MkSwitch.js.map +1 -0
- package/dist/components/MkTable.d.ts +39 -0
- package/dist/components/MkTable.d.ts.map +1 -0
- package/dist/components/MkTable.js +47 -0
- package/dist/components/MkTable.js.map +1 -0
- package/dist/components/MkTabs.d.ts +19 -0
- package/dist/components/MkTabs.d.ts.map +1 -0
- package/dist/components/MkTabs.js +38 -0
- package/dist/components/MkTabs.js.map +1 -0
- package/dist/components/MkTextArea.d.ts +17 -0
- package/dist/components/MkTextArea.d.ts.map +1 -0
- package/dist/components/MkTextArea.js +18 -0
- package/dist/components/MkTextArea.js.map +1 -0
- package/dist/components/MkToastRenderer.d.ts +3 -0
- package/dist/components/MkToastRenderer.d.ts.map +1 -0
- package/dist/components/MkToastRenderer.js +133 -0
- package/dist/components/MkToastRenderer.js.map +1 -0
- package/dist/components/MkTooltip.d.ts +15 -0
- package/dist/components/MkTooltip.d.ts.map +1 -0
- package/dist/components/MkTooltip.js +36 -0
- package/dist/components/MkTooltip.js.map +1 -0
- package/dist/components/MkWindowList.d.ts +47 -0
- package/dist/components/MkWindowList.d.ts.map +1 -0
- package/dist/components/MkWindowList.js +50 -0
- package/dist/components/MkWindowList.js.map +1 -0
- package/dist/components/index.d.ts +30 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +33 -0
- package/dist/components/index.js.map +1 -0
- package/dist/context/MkApiContext.d.ts +15 -0
- package/dist/context/MkApiContext.d.ts.map +1 -0
- package/dist/context/MkApiContext.js +27 -0
- package/dist/context/MkApiContext.js.map +1 -0
- package/dist/context/MkAuthContext.d.ts +19 -0
- package/dist/context/MkAuthContext.d.ts.map +1 -0
- package/dist/context/MkAuthContext.js +86 -0
- package/dist/context/MkAuthContext.js.map +1 -0
- package/dist/context/MkConfirmContext.d.ts +8 -0
- package/dist/context/MkConfirmContext.d.ts.map +1 -0
- package/dist/context/MkConfirmContext.js +36 -0
- package/dist/context/MkConfirmContext.js.map +1 -0
- package/dist/context/MkToastContext.d.ts +19 -0
- package/dist/context/MkToastContext.d.ts.map +1 -0
- package/dist/context/MkToastContext.js +86 -0
- package/dist/context/MkToastContext.js.map +1 -0
- package/dist/hooks/filePicker.types.d.ts +13 -0
- package/dist/hooks/filePicker.types.d.ts.map +1 -0
- package/dist/hooks/filePicker.types.js +7 -0
- package/dist/hooks/filePicker.types.js.map +1 -0
- package/dist/hooks/useApi.d.ts +19 -0
- package/dist/hooks/useApi.d.ts.map +1 -0
- package/dist/hooks/useApi.js +78 -0
- package/dist/hooks/useApi.js.map +1 -0
- package/dist/hooks/useApi.test.d.ts +2 -0
- package/dist/hooks/useApi.test.d.ts.map +1 -0
- package/dist/hooks/useApi.test.js +10 -0
- package/dist/hooks/useApi.test.js.map +1 -0
- package/dist/hooks/useMkCrud.d.ts +39 -0
- package/dist/hooks/useMkCrud.d.ts.map +1 -0
- package/dist/hooks/useMkCrud.js +118 -0
- package/dist/hooks/useMkCrud.js.map +1 -0
- package/dist/hooks/useMkDebounce.d.ts +24 -0
- package/dist/hooks/useMkDebounce.d.ts.map +1 -0
- package/dist/hooks/useMkDebounce.js +36 -0
- package/dist/hooks/useMkDebounce.js.map +1 -0
- package/dist/hooks/useMkEffectDebug.d.ts +6 -0
- package/dist/hooks/useMkEffectDebug.d.ts.map +1 -0
- package/dist/hooks/useMkEffectDebug.js +23 -0
- package/dist/hooks/useMkEffectDebug.js.map +1 -0
- package/dist/hooks/useMkEvent.d.ts +42 -0
- package/dist/hooks/useMkEvent.d.ts.map +1 -0
- package/dist/hooks/useMkEvent.js +49 -0
- package/dist/hooks/useMkEvent.js.map +1 -0
- package/dist/hooks/useMkFilePickerCli.d.ts +59 -0
- package/dist/hooks/useMkFilePickerCli.d.ts.map +1 -0
- package/dist/hooks/useMkFilePickerCli.js +68 -0
- package/dist/hooks/useMkFilePickerCli.js.map +1 -0
- package/dist/hooks/useMkFilePickerExpo.d.ts +38 -0
- package/dist/hooks/useMkFilePickerExpo.d.ts.map +1 -0
- package/dist/hooks/useMkFilePickerExpo.js +68 -0
- package/dist/hooks/useMkFilePickerExpo.js.map +1 -0
- package/dist/hooks/useMkForm.d.ts +43 -0
- package/dist/hooks/useMkForm.d.ts.map +1 -0
- package/dist/hooks/useMkForm.js +115 -0
- package/dist/hooks/useMkForm.js.map +1 -0
- package/dist/hooks/useMkInfiniteList.d.ts +16 -0
- package/dist/hooks/useMkInfiniteList.d.ts.map +1 -0
- package/dist/hooks/useMkInfiniteList.js +58 -0
- package/dist/hooks/useMkInfiniteList.js.map +1 -0
- package/dist/hooks/useMkList.d.ts +61 -0
- package/dist/hooks/useMkList.d.ts.map +1 -0
- package/dist/hooks/useMkList.js +55 -0
- package/dist/hooks/useMkList.js.map +1 -0
- package/dist/hooks/useMkLocalStorage.d.ts +6 -0
- package/dist/hooks/useMkLocalStorage.d.ts.map +1 -0
- package/dist/hooks/useMkLocalStorage.js +28 -0
- package/dist/hooks/useMkLocalStorage.js.map +1 -0
- package/dist/hooks/useMkPrevious.d.ts +6 -0
- package/dist/hooks/useMkPrevious.d.ts.map +1 -0
- package/dist/hooks/useMkPrevious.js +13 -0
- package/dist/hooks/useMkPrevious.js.map +1 -0
- package/dist/hooks/useMkToggle.d.ts +6 -0
- package/dist/hooks/useMkToggle.d.ts.map +1 -0
- package/dist/hooks/useMkToggle.js +13 -0
- package/dist/hooks/useMkToggle.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/theme/MkThemeProvider.d.ts +14 -0
- package/dist/theme/MkThemeProvider.d.ts.map +1 -0
- package/dist/theme/MkThemeProvider.js +22 -0
- package/dist/theme/MkThemeProvider.js.map +1 -0
- package/eslint-plugin-mk/index.js +20 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# LICENSE
|
|
2
|
+
|
|
3
|
+
**Proprietary License - MK-Director**
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026 Condaty. All rights reserved.
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") are the proprietary property of Condaty ("Owner"). The Software may not be copied, modified, merged, published, distributed, sublicensed, and/or sold without the express written permission of the Owner.
|
|
8
|
+
|
|
9
|
+
## Terms of Use
|
|
10
|
+
|
|
11
|
+
1. **Authorization**: Access to this software is granted only to authorized users who have purchased a valid license from Condaty.
|
|
12
|
+
|
|
13
|
+
2. **Restrictions**: Without prior written permission from the Owner, you may not:
|
|
14
|
+
- Copy, modify, or create derivative works
|
|
15
|
+
- Distribute, sublicense, or sell copies of the Software
|
|
16
|
+
- Reverse engineer, decompile, or disassemble the Software
|
|
17
|
+
- Use the Software for commercial purposes without a valid license
|
|
18
|
+
|
|
19
|
+
3. **No Warranty**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
|
|
21
|
+
4. **Liability**: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
5. **Termination**: This license is effective until terminated. Your rights under this license will terminate automatically without notice if you fail to comply with any of its terms and conditions.
|
|
24
|
+
|
|
25
|
+
## Contact
|
|
26
|
+
|
|
27
|
+
For licensing inquiries, please contact:
|
|
28
|
+
- **Email**: licensing@condaty.com
|
|
29
|
+
- **Website**: https://www.conday.com
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
*Last updated: April 2026*
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @makroz/mobile
|
|
2
|
+
|
|
3
|
+
Librería de componentes UI para React Native. Mantiene paridad de diseño y tokens con la versión web.
|
|
4
|
+
|
|
5
|
+
## Características Core
|
|
6
|
+
- **MkThemeProvider**: Contexto para manejar Light/Dark mode y customización de tokens.
|
|
7
|
+
- **Tokens Parity**: Mismos nombres y escalas de colores que `@makroz/web`.
|
|
8
|
+
- **useApi Native**: Hook optimizado para peticiones a MK-Director desde dispositivos móviles.
|
|
9
|
+
|
|
10
|
+
## Uso
|
|
11
|
+
```typescript
|
|
12
|
+
import { MkThemeProvider, MkButton } from '@makroz/mobile';
|
|
13
|
+
|
|
14
|
+
const App = () => (
|
|
15
|
+
<MkThemeProvider>
|
|
16
|
+
<MkButton label="Hola MK" variant="primary" />
|
|
17
|
+
</MkThemeProvider>
|
|
18
|
+
);
|
|
19
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth context shape + the React context object.
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally side-effect free (it only defines
|
|
5
|
+
* the context + the type). The provider lives in
|
|
6
|
+
* `MkAuthProvider.tsx` and the consumer hook lives in
|
|
7
|
+
* `useMkAuth.ts`. Splitting them this way keeps circular imports
|
|
8
|
+
* out of the picture and lets tests import the context type
|
|
9
|
+
* without pulling in the full provider tree.
|
|
10
|
+
*/
|
|
11
|
+
import type { AdminDto, LoginInput, AuthTokens } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Public auth context value exposed by `MkAuthProvider` and
|
|
14
|
+
* consumed by `useMkAuth`.
|
|
15
|
+
*
|
|
16
|
+
* Design notes:
|
|
17
|
+
* - `isAuthenticated` is derived state from `user`, but it is
|
|
18
|
+
* exposed as a first-class field so call sites don't have to
|
|
19
|
+
* remember the null-vs-false distinction that the legacy
|
|
20
|
+
* `MkAuthContext.tsx` introduced (here we use `null` only,
|
|
21
|
+
* matching the SecureStore contract).
|
|
22
|
+
* - `hasAbility(ability)` accepts a single string and returns
|
|
23
|
+
* whether the current user has *any* permission for that
|
|
24
|
+
* ability. The underlying `canUser` from `@mk/core` can also
|
|
25
|
+
* take an action verb — consumers that need action-level
|
|
26
|
+
* granularity should call `canUser` directly with
|
|
27
|
+
* `user.role.abilities`.
|
|
28
|
+
*/
|
|
29
|
+
export interface MkAuthContextValue {
|
|
30
|
+
/** The currently authenticated admin, or `null` if not signed in. */
|
|
31
|
+
user: AdminDto | null;
|
|
32
|
+
/** Convenience: `user !== null`. */
|
|
33
|
+
isAuthenticated: boolean;
|
|
34
|
+
/** `true` while the provider is hydrating from SecureStore or waiting on a network call. */
|
|
35
|
+
isLoading: boolean;
|
|
36
|
+
/** Last login/refresh/logout error, or `null` if no error. */
|
|
37
|
+
error: Error | null;
|
|
38
|
+
/**
|
|
39
|
+
* Authenticate with email + password. On success persists
|
|
40
|
+
* the new tokens in SecureStore and updates `user`.
|
|
41
|
+
*
|
|
42
|
+
* Throws on network / server errors so callers can decide
|
|
43
|
+
* whether to surface the error.
|
|
44
|
+
*/
|
|
45
|
+
login: (input: LoginInput) => Promise<AdminDto>;
|
|
46
|
+
/**
|
|
47
|
+
* Best-effort logout. Tells the backend (if reachable) and
|
|
48
|
+
* then unconditionally clears local SecureStore state.
|
|
49
|
+
*
|
|
50
|
+
* Never throws — even if the backend call fails the local
|
|
51
|
+
* session is cleared.
|
|
52
|
+
*/
|
|
53
|
+
logout: () => Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Force a refresh of the access token using the stored
|
|
56
|
+
* refresh token. Returns the new tokens or `null` if the
|
|
57
|
+
* refresh failed (in which case the user is logged out).
|
|
58
|
+
*/
|
|
59
|
+
refresh: () => Promise<AuthTokens | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Check whether the current user has any permission for the
|
|
62
|
+
* given ability. Returns `false` for unauthenticated users.
|
|
63
|
+
*/
|
|
64
|
+
hasAbility: (ability: string) => boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The React context. Default value is `undefined` so the
|
|
68
|
+
* `useMkAuth` hook can throw a helpful error when used outside
|
|
69
|
+
* the provider.
|
|
70
|
+
*/
|
|
71
|
+
export declare const MkAuthContext: import("react").Context<MkAuthContextValue | undefined>;
|
|
72
|
+
//# sourceMappingURL=MkAuthContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MkAuthContext.d.ts","sourceRoot":"","sources":["../../src/auth/MkAuthContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,kBAAkB;IAC/B,qEAAqE;IACrE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,oCAAoC;IACpC,eAAe,EAAE,OAAO,CAAC;IACzB,4FAA4F;IAC5F,SAAS,EAAE,OAAO,CAAC;IACnB,8DAA8D;IAC9D,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB;;;;;;OAMG;IACH,KAAK,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEhD;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;OAIG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAE1C;;;OAGG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5C;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,yDAA2D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth context shape + the React context object.
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally side-effect free (it only defines
|
|
5
|
+
* the context + the type). The provider lives in
|
|
6
|
+
* `MkAuthProvider.tsx` and the consumer hook lives in
|
|
7
|
+
* `useMkAuth.ts`. Splitting them this way keeps circular imports
|
|
8
|
+
* out of the picture and lets tests import the context type
|
|
9
|
+
* without pulling in the full provider tree.
|
|
10
|
+
*/
|
|
11
|
+
import { createContext } from 'react';
|
|
12
|
+
/**
|
|
13
|
+
* The React context. Default value is `undefined` so the
|
|
14
|
+
* `useMkAuth` hook can throw a helpful error when used outside
|
|
15
|
+
* the provider.
|
|
16
|
+
*/
|
|
17
|
+
export const MkAuthContext = createContext(undefined);
|
|
18
|
+
MkAuthContext.displayName = 'MkAuthContext';
|
|
19
|
+
//# sourceMappingURL=MkAuthContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MkAuthContext.js","sourceRoot":"","sources":["../../src/auth/MkAuthContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AA8DtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAiC,SAAS,CAAC,CAAC;AAEtF,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MkAuthForm` — a mobile-friendly login form.
|
|
3
|
+
*
|
|
4
|
+
* Self-contained: it owns its own email/password state, calls
|
|
5
|
+
* `login()` from `useMkAuth`, and renders inline error + loading
|
|
6
|
+
* states. Consumers only need to wrap it inside an
|
|
7
|
+
* `<MkAuthProvider>` and (optionally) a `<MkThemeProvider>` so
|
|
8
|
+
* the input/button pick up the design tokens.
|
|
9
|
+
*
|
|
10
|
+
* Styling is plain `StyleSheet` (no NativeWind dependency) so
|
|
11
|
+
* the form works out of the box in any Expo / RN app.
|
|
12
|
+
*/
|
|
13
|
+
export interface MkAuthFormProps {
|
|
14
|
+
/**
|
|
15
|
+
* Override the submit button label. Defaults to `"Sign in"`.
|
|
16
|
+
*/
|
|
17
|
+
submitLabel?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Called after a successful login. Use this to navigate
|
|
20
|
+
* (e.g. `router.replace('/admin')`) instead of letting the
|
|
21
|
+
* form own the navigation state.
|
|
22
|
+
*/
|
|
23
|
+
onSuccess?: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Optional container style override.
|
|
26
|
+
*/
|
|
27
|
+
style?: object;
|
|
28
|
+
}
|
|
29
|
+
export declare function MkAuthForm({ submitLabel, onSuccess, style, }: MkAuthFormProps): React.JSX.Element;
|
|
30
|
+
export default MkAuthForm;
|
|
31
|
+
//# sourceMappingURL=MkAuthForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MkAuthForm.d.ts","sourceRoot":"","sources":["../../src/auth/MkAuthForm.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAkBH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAsBD,wBAAgB,UAAU,CAAC,EACvB,WAAuB,EACvB,SAAS,EACT,KAAK,GACR,EAAE,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA4KrC;AA6GD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `MkAuthForm` — a mobile-friendly login form.
|
|
4
|
+
*
|
|
5
|
+
* Self-contained: it owns its own email/password state, calls
|
|
6
|
+
* `login()` from `useMkAuth`, and renders inline error + loading
|
|
7
|
+
* states. Consumers only need to wrap it inside an
|
|
8
|
+
* `<MkAuthProvider>` and (optionally) a `<MkThemeProvider>` so
|
|
9
|
+
* the input/button pick up the design tokens.
|
|
10
|
+
*
|
|
11
|
+
* Styling is plain `StyleSheet` (no NativeWind dependency) so
|
|
12
|
+
* the form works out of the box in any Expo / RN app.
|
|
13
|
+
*/
|
|
14
|
+
import { useState, useCallback } from 'react';
|
|
15
|
+
import { ActivityIndicator, KeyboardAvoidingView, Platform, StyleSheet, Text, TextInput, TouchableOpacity, View, } from 'react-native';
|
|
16
|
+
import { useMkTheme } from '../theme/MkThemeProvider';
|
|
17
|
+
import { tokens } from '@mk/core';
|
|
18
|
+
import { useMkAuth } from './useMkAuth';
|
|
19
|
+
function validate(email, password) {
|
|
20
|
+
const errors = {};
|
|
21
|
+
if (!email) {
|
|
22
|
+
errors.email = 'Email is required';
|
|
23
|
+
}
|
|
24
|
+
else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
25
|
+
errors.email = 'Enter a valid email address';
|
|
26
|
+
}
|
|
27
|
+
if (!password) {
|
|
28
|
+
errors.password = 'Password is required';
|
|
29
|
+
}
|
|
30
|
+
else if (password.length < 6) {
|
|
31
|
+
errors.password = 'Password must be at least 6 characters';
|
|
32
|
+
}
|
|
33
|
+
return errors;
|
|
34
|
+
}
|
|
35
|
+
export function MkAuthForm({ submitLabel = 'Sign in', onSuccess, style, }) {
|
|
36
|
+
var _a;
|
|
37
|
+
const { theme } = useMkTheme();
|
|
38
|
+
const { login, isLoading, error } = useMkAuth();
|
|
39
|
+
const [email, setEmail] = useState('');
|
|
40
|
+
const [password, setPassword] = useState('');
|
|
41
|
+
const [fieldErrors, setFieldErrors] = useState({});
|
|
42
|
+
const [submitting, setSubmitting] = useState(false);
|
|
43
|
+
const handleSubmit = useCallback(async (e) => {
|
|
44
|
+
var _a;
|
|
45
|
+
// PreventDefault isn't a thing in RN, but the
|
|
46
|
+
// signature keeps the component drop-in compatible
|
|
47
|
+
// with web code if someone wraps it later.
|
|
48
|
+
(_a = e === null || e === void 0 ? void 0 : e.preventDefault) === null || _a === void 0 ? void 0 : _a.call(e);
|
|
49
|
+
const errors = validate(email, password);
|
|
50
|
+
setFieldErrors(errors);
|
|
51
|
+
if (Object.keys(errors).length > 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setSubmitting(true);
|
|
55
|
+
try {
|
|
56
|
+
await login({ email, password });
|
|
57
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
|
|
58
|
+
}
|
|
59
|
+
catch (_b) {
|
|
60
|
+
// Error is exposed via `useMkAuth().error` — we
|
|
61
|
+
// don't need to do anything here. Clearing the
|
|
62
|
+
// password on a failed attempt is a common UX
|
|
63
|
+
// pattern, so we do that.
|
|
64
|
+
setPassword('');
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
setSubmitting(false);
|
|
68
|
+
}
|
|
69
|
+
}, [email, password, login, onSuccess]);
|
|
70
|
+
const busy = isLoading || submitting;
|
|
71
|
+
const submitError = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : null;
|
|
72
|
+
return (_jsxs(KeyboardAvoidingView, { behavior: Platform.OS === 'ios' ? 'padding' : undefined, style: [styles.container, style], children: [_jsxs(View, { style: styles.field, children: [_jsx(Text, { style: [styles.label, { color: theme.foreground }], children: "Email" }), _jsx(View, { style: [
|
|
73
|
+
styles.inputWrapper,
|
|
74
|
+
{
|
|
75
|
+
backgroundColor: theme.background,
|
|
76
|
+
borderColor: fieldErrors.email
|
|
77
|
+
? theme.error
|
|
78
|
+
: theme.border,
|
|
79
|
+
},
|
|
80
|
+
], children: _jsx(TouchableOpacity
|
|
81
|
+
// Make the inner View behave like a
|
|
82
|
+
// tap target that focuses the TextInput.
|
|
83
|
+
// The actual <TextInput> sits inside.
|
|
84
|
+
, {
|
|
85
|
+
// Make the inner View behave like a
|
|
86
|
+
// tap target that focuses the TextInput.
|
|
87
|
+
// The actual <TextInput> sits inside.
|
|
88
|
+
activeOpacity: 1, style: styles.touchTarget, children: _jsx(EmailInput, { value: email, onChangeText: (text) => {
|
|
89
|
+
setEmail(text);
|
|
90
|
+
if (fieldErrors.email) {
|
|
91
|
+
setFieldErrors((prev) => (Object.assign(Object.assign({}, prev), { email: undefined })));
|
|
92
|
+
}
|
|
93
|
+
}, editable: !busy, textColor: theme.foreground, placeholderColor: theme.mutedForeground }) }) }), fieldErrors.email ? (_jsx(Text, { style: [styles.errorText, { color: theme.error }], children: fieldErrors.email })) : null] }), _jsxs(View, { style: styles.field, children: [_jsx(Text, { style: [styles.label, { color: theme.foreground }], children: "Password" }), _jsx(View, { style: [
|
|
94
|
+
styles.inputWrapper,
|
|
95
|
+
{
|
|
96
|
+
backgroundColor: theme.background,
|
|
97
|
+
borderColor: fieldErrors.password
|
|
98
|
+
? theme.error
|
|
99
|
+
: theme.border,
|
|
100
|
+
},
|
|
101
|
+
], children: _jsx(TouchableOpacity, { activeOpacity: 1, style: styles.touchTarget, children: _jsx(PasswordInput, { value: password, onChangeText: (text) => {
|
|
102
|
+
setPassword(text);
|
|
103
|
+
if (fieldErrors.password) {
|
|
104
|
+
setFieldErrors((prev) => (Object.assign(Object.assign({}, prev), { password: undefined })));
|
|
105
|
+
}
|
|
106
|
+
}, editable: !busy, textColor: theme.foreground, placeholderColor: theme.mutedForeground }) }) }), fieldErrors.password ? (_jsx(Text, { style: [styles.errorText, { color: theme.error }], children: fieldErrors.password })) : null] }), submitError ? (_jsx(View, { style: [
|
|
107
|
+
styles.submitErrorBox,
|
|
108
|
+
{ backgroundColor: theme.error + '22', borderColor: theme.error },
|
|
109
|
+
], children: _jsx(Text, { style: [styles.submitErrorText, { color: theme.error }], children: submitError }) })) : null, _jsx(TouchableOpacity, { onPress: () => {
|
|
110
|
+
void handleSubmit();
|
|
111
|
+
}, disabled: busy, activeOpacity: 0.8, style: [
|
|
112
|
+
styles.button,
|
|
113
|
+
{ backgroundColor: theme.primary, opacity: busy ? 0.6 : 1 },
|
|
114
|
+
], children: busy ? (_jsx(ActivityIndicator, { color: theme.primaryForeground, size: "small" })) : (_jsx(Text, { style: [styles.buttonText, { color: theme.primaryForeground }], children: submitLabel })) })] }));
|
|
115
|
+
}
|
|
116
|
+
function EmailInput(props) {
|
|
117
|
+
return (_jsx(TextInput, { style: [styles.input, { color: props.textColor }], placeholder: "you@example.com", placeholderTextColor: props.placeholderColor, value: props.value, onChangeText: props.onChangeText, editable: props.editable, autoCapitalize: "none", autoCorrect: false, keyboardType: "email-address", textContentType: "emailAddress", autoComplete: "email" }));
|
|
118
|
+
}
|
|
119
|
+
function PasswordInput(props) {
|
|
120
|
+
return (_jsx(TextInput, { style: [styles.input, { color: props.textColor }], placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022", placeholderTextColor: props.placeholderColor, value: props.value, onChangeText: props.onChangeText, editable: props.editable, autoCapitalize: "none", autoCorrect: false, secureTextEntry: true, textContentType: "password", autoComplete: "password" }));
|
|
121
|
+
}
|
|
122
|
+
const styles = StyleSheet.create({
|
|
123
|
+
container: {
|
|
124
|
+
width: '100%',
|
|
125
|
+
paddingVertical: 8,
|
|
126
|
+
},
|
|
127
|
+
field: {
|
|
128
|
+
marginBottom: 16,
|
|
129
|
+
},
|
|
130
|
+
label: {
|
|
131
|
+
fontSize: 14,
|
|
132
|
+
fontWeight: '500',
|
|
133
|
+
marginBottom: 6,
|
|
134
|
+
opacity: 0.9,
|
|
135
|
+
},
|
|
136
|
+
inputWrapper: {
|
|
137
|
+
flexDirection: 'row',
|
|
138
|
+
alignItems: 'center',
|
|
139
|
+
borderWidth: 1,
|
|
140
|
+
borderRadius: tokens.shared.radius,
|
|
141
|
+
height: 48,
|
|
142
|
+
},
|
|
143
|
+
touchTarget: {
|
|
144
|
+
flex: 1,
|
|
145
|
+
},
|
|
146
|
+
input: {
|
|
147
|
+
flex: 1,
|
|
148
|
+
height: 48,
|
|
149
|
+
paddingHorizontal: 12,
|
|
150
|
+
fontSize: 16,
|
|
151
|
+
},
|
|
152
|
+
errorText: {
|
|
153
|
+
marginTop: 4,
|
|
154
|
+
fontSize: 12,
|
|
155
|
+
fontWeight: '500',
|
|
156
|
+
},
|
|
157
|
+
submitErrorBox: {
|
|
158
|
+
borderWidth: 1,
|
|
159
|
+
borderRadius: tokens.shared.radius,
|
|
160
|
+
padding: 10,
|
|
161
|
+
marginBottom: 12,
|
|
162
|
+
},
|
|
163
|
+
submitErrorText: {
|
|
164
|
+
fontSize: 13,
|
|
165
|
+
fontWeight: '500',
|
|
166
|
+
},
|
|
167
|
+
button: {
|
|
168
|
+
height: 48,
|
|
169
|
+
borderRadius: tokens.shared.radius,
|
|
170
|
+
alignItems: 'center',
|
|
171
|
+
justifyContent: 'center',
|
|
172
|
+
marginTop: 4,
|
|
173
|
+
},
|
|
174
|
+
buttonText: {
|
|
175
|
+
fontSize: 16,
|
|
176
|
+
fontWeight: '600',
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
export default MkAuthForm;
|
|
180
|
+
//# sourceMappingURL=MkAuthForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MkAuthForm.js","sourceRoot":"","sources":["../../src/auth/MkAuthForm.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,SAAS,EACT,gBAAgB,EAChB,IAAI,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA0BxC,SAAS,QAAQ,CAAC,KAAa,EAAE,QAAgB;IAC7C,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,MAAM,CAAC,KAAK,GAAG,mBAAmB,CAAC;IACvC,CAAC;SAAM,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,KAAK,GAAG,6BAA6B,CAAC;IACjD,CAAC;IACD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,MAAM,CAAC,QAAQ,GAAG,sBAAsB,CAAC;IAC7C,CAAC;SAAM,IAAI,QAAQ,CAA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uth`.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Hydrate tokens + user from `expo-secure-store` on mount.
|
|
6
|
+
* - Expose `login`, `logout`, `refresh`, `hasAbility` via context.
|
|
7
|
+
* - Provide a memoised `authedFetch` helper that automatically
|
|
8
|
+
* attaches the access token and refreshes once on 401.
|
|
9
|
+
*
|
|
10
|
+
* Networking note: this provider does NOT use TanStack Query
|
|
11
|
+
* (the mk-director monorepo does not currently declare it as a
|
|
12
|
+
* peer dep). It uses the same plain `fetch`-based pattern that
|
|
13
|
+
* the legacy `useApi.ts` hook uses, so the surface stays
|
|
14
|
+
* consistent across the package. Consumers that need query
|
|
15
|
+
* caching should layer TanStack Query on top of `authedFetch`
|
|
16
|
+
* at the call site.
|
|
17
|
+
*/
|
|
18
|
+
import type { ReactNode } from 'react';
|
|
19
|
+
/**
|
|
20
|
+
* Props for `MkAuthProvider`.
|
|
21
|
+
*/
|
|
22
|
+
export interface MkAuthProviderProps {
|
|
23
|
+
/**
|
|
24
|
+
* The auth scope — used to build the URL prefix
|
|
25
|
+
* `/api/${scope}/auth/...`. Example: `"admin"`.
|
|
26
|
+
*/
|
|
27
|
+
scope: string;
|
|
28
|
+
/**
|
|
29
|
+
* Base URL of the backend (no trailing slash). Example:
|
|
30
|
+
* `"http://localhost:8000"` for a dev API.
|
|
31
|
+
*/
|
|
32
|
+
apiBaseUrl: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional override of the per-request timeout in ms.
|
|
35
|
+
* Defaults to 15s — long enough for slow mobile networks
|
|
36
|
+
* but short enough that the UI doesn't appear to hang.
|
|
37
|
+
*
|
|
38
|
+
* Reserved for a future AbortController-based timeout
|
|
39
|
+
* implementation; the current provider does not enforce
|
|
40
|
+
* it but accepts the prop for forward compatibility.
|
|
41
|
+
*/
|
|
42
|
+
requestTimeoutMs?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Children.
|
|
45
|
+
*/
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The provider component.
|
|
50
|
+
*
|
|
51
|
+
* Marked `'use client'` equivalent — RN doesn't use the Next.js
|
|
52
|
+
* `'use client'` directive, but conceptually this component is
|
|
53
|
+
* a Client Component (it owns state, effects, and side effects).
|
|
54
|
+
*/
|
|
55
|
+
export declare function MkAuthProvider({ scope, apiBaseUrl, requestTimeoutMs: _requestTimeoutMs, children, }: MkAuthProviderProps): React.JSX.Element;
|
|
56
|
+
export default MkAuthProvider;
|
|
57
|
+
//# sourceMappingURL=MkAuthProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MkAuthProvider.d.ts","sourceRoot":"","sources":["../../src/auth/MkAuthProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAavC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;CACvB;AA4CD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAC3B,KAAK,EACL,UAAU,EAEV,gBAAgB,EAAE,iBAA0B,EAC5C,QAAQ,GACX,EAAE,mBAAmB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAmQzC;AAED,eAAe,cAAc,CAAC"}
|