npm package: @namnguyen.repl.it/nn-core
Description: Core utilities for NN apps
Author: NamReplIT
Latest version: 0.1.4

# nn-core

Reusable core modules for React / React Native apps — auth, networking, storage, push notifications, i18n, theming, modals, screen utilities, and auth flow state machines.

## Install

```bash
npm install nn-core
```

## Modules

| Module                                   | Import              | Platform | Description                                          |
| ---------------------------------------- | ------------------- | -------- | ---------------------------------------------------- |
| [**auth**](src/auth/README.md)           | `nn-core/auth`      | Any      | Auth provider, token management, auto-refresh        |
| [**network**](src/network/README.md)     | `nn-core/network`   | Any      | HTTP client, route-based API caller, request signing |
| [**storage**](src/storage/README.md)     | `nn-core/storage`   | Any      | Cross-platform storage & crypto adapters             |
| [**push**](src/push/README.md)           | `nn-core/push`      | RN       | Push notification provider with pub/sub              |
| [**language**](src/language/README.md)   | `nn-core/language`  | Any      | i18n provider (i18next)                              |
| [**theme**](src/theme/README.md)         | `nn-core/theme`     | Any      | Generic theme provider with persistence              |
| [**modal**](src/modal/README.md)         | `nn-core/modal`     | RN       | Bottom sheets, popups, notifications                 |
| [**screen**](src/screen/README.md)       | `nn-core/screen`    | RN       | ScrollView wrapper, animations, sortable list        |
| [**auth-flow**](src/auth-flow/README.md) | `nn-core/auth-flow` | Any      | Login/register/social auth state machines            |
| [**hooks**](src/hooks/README.md)         | `nn-core/hooks`     | Any      | useSubmit, usePaging, useToggle                      |
| [**utils**](src/utils/README.md)         | `nn-core/utils`     | Any      | Currency, delay, number formatting, polling          |

## Quick Start

```tsx
import { createAuthClient, AuthProvider, useAuth } from "nn-core/auth";
import { createAsyncStorageAdapter } from "nn-core/storage";
import { LanguageProvider } from "nn-core/language";
import { ThemeProvider } from "nn-core/theme";
import { ModalProvider } from "nn-core/modal";

const authClient = createAuthClient({
  baseURL: "https://api.example.com",
  routes: {
    /* ... */
  },
  storage: createAsyncStorageAdapter(AsyncStorage),
});

function App() {
  return (
    <AuthProvider client={authClient}>
      <LanguageProvider config={{ defaultLanguage: "en", resources }}>
        <ThemeProvider config={{ themes, defaultVariant: "default" }}>
          <ModalProvider>
            <MainApp />
          </ModalProvider>
        </ThemeProvider>
      </LanguageProvider>
    </AuthProvider>
  );
}
```

## Architecture

```
nn-core/
├── auth/          # AuthProvider + createAuthClient + tokenStore
├── network/       # HttpClient + apiCaller + requestSigner
├── storage/       # StorageAdapter + CryptoAdapter implementations
├── push/          # PushNotificationProvider
├── language/      # LanguageProvider (i18next)
├── theme/         # ThemeProvider<T> (generic)
├── modal/         # ModalProvider + SlideUp + PopUp + Notifications
├── screen/        # ScreenWrapper + AnimateLayout + SortableList
├── auth-flow/     # useLoginFlow + useRegisterFlow + useSocialAuth
├── hooks/         # useSubmit + usePaging + useToggle
└── utils/         # delay + currency + number + misc
```

### Design Principles

- **Adapter pattern** — no hard dependencies on AsyncStorage, Firebase, etc., apps inject their own
- **Generic types** — `ThemeProvider<T>` accepts any shape, `APICaller<TRoutes>` is type-safe
- **Imperative APIs** — `SlideUp().open(...)` callable from anywhere without hooks
- **Pure state machines** — auth-flow hooks return `[state, actions]`, zero UI coupling
- **Tree-shakeable** — import only what you need via subpath exports

## Peer Dependencies

All optional except `react`:

| Dependency                     | Required by         |
| ------------------------------ | ------------------- |
| `react`                        | All modules         |
| `axios`                        | auth, network       |
| `i18next`                      | language            |
| `react-i18next`                | language            |
| `react-native`                 | push, modal, screen |
| `react-native-reanimated`      | modal, screen       |
| `react-native-gesture-handler` | modal, screen       |

## License

MIT