@nubitio/core 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Johan Guerreros
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @nubitio/core
2
+
3
+ Runtime foundation for the Nubit admin stack: HTTP client, event bus, i18n integration, date utilities, Mercure (SSE) support, and the CoreProvider.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @nubitio/core
9
+ ```
10
+
11
+ ## Peer dependencies
12
+
13
+ ```json
14
+ "i18next": "^23",
15
+ "react": "^19",
16
+ "react-dom": "^19",
17
+ "react-i18next": "^14"
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ ```tsx
23
+ import { CoreProvider } from '@nubitio/core';
24
+
25
+ export function App() {
26
+ return (
27
+ <CoreProvider
28
+ apiBaseUrl="https://api.example.com"
29
+ timezone="UTC"
30
+ locale="en"
31
+ >
32
+ {/* your app */}
33
+ </CoreProvider>
34
+ );
35
+ }
36
+ ```
37
+
38
+ ## Timezone handling
39
+
40
+ Timezone (and other core settings) are configured once via `CoreConfigProvider` (recommended) or `configureCore()`:
41
+
42
+ ```tsx
43
+ <CoreConfigProvider locale="es" timezone="America/Santiago">
44
+ <App />
45
+ </CoreConfigProvider>
46
+ ```
47
+
48
+ - `getCoreTimezone()` and `DateUtils` read from this config (works in React and non-React code).
49
+ - Default is `UTC`. Use `DEFAULT_TIMEZONE` only as a fallback constant if you need one outside the provider.
50
+
51
+ ## API Base URL
52
+
53
+ The base URL for your API is configured the same way as locale and timezone:
54
+
55
+ ```tsx
56
+ <CoreConfigProvider
57
+ locale="es"
58
+ timezone="America/Santiago"
59
+ apiBaseUrl="https://api.example.com/api/"
60
+ >
61
+ <App />
62
+ </CoreConfigProvider>
63
+ ```
64
+
65
+ - Use `getCoreApiBaseUrl()` to read it from anywhere (including at module top level inside `defineResource`, `entityField`, etc.).
66
+ - When you create an HTTP client via `CoreProvider` / `CoreHttpProvider` **without** explicitly passing `baseUrl`, it will automatically use the value from `CoreConfig`.
67
+ - Default: `/api/`
68
+
69
+ This design allows the Nubit packages to be used in other projects with almost zero configuration beyond the provider.
70
+
71
+ ## HTTP client & authentication strategies
72
+
73
+ `CoreHttpClient` includes a built-in convenience refresh loop for **cookie-based** auth (the most common case for API Platform backends).
74
+
75
+ ```ts
76
+ const httpConfig = {
77
+ baseUrl: 'https://api.example.com',
78
+ refreshPath: 'auth/refresh',
79
+ loginPath: 'auth/login',
80
+ // autoRefresh: true (default)
81
+ };
82
+ ```
83
+
84
+ **For other auth models (Bearer JWT, custom headers, OAuth, etc.)** we strongly recommend:
85
+
86
+ ```ts
87
+ <CoreProvider
88
+ http={{
89
+ baseUrl: '...',
90
+ autoRefresh: false, // disable built-in cookie refresh
91
+ onUnauthorized: (err) => {
92
+ // your global logout / redirect logic
93
+ authStore.logout();
94
+ },
95
+ }}
96
+ >
97
+ ```
98
+
99
+ You can also provide a full `refreshFn` if you want the client to still participate in refresh, but with your own logic (e.g. refreshing a Bearer token).
100
+
101
+ See `CoreHttpClientConfig` for all options.
102
+
103
+ ## Key exports
104
+
105
+ | Export | Description |
106
+ |--------|-------------|
107
+ | `CoreProvider` | Root provider — wraps HTTP, i18n, React Query, and runtime config |
108
+ | `CoreHttpClient` | Type-safe HTTP client with error normalisation + pluggable auth refresh |
109
+ | `dispatch` / `useEvents` | Lightweight event bus for cross-component communication |
110
+ | `createCrudEvents` | Factory for typed CRUD event sets |
111
+ | `MercureProvider` | Real-time SSE integration via Mercure hub |
112
+ | `DateUtils` | Timezone-aware date formatting powered by Luxon |
113
+ | `coreTranslationsEs` / `coreTranslationsEn` | Built-in translations for Spanish and English |