@duongthiu/onex-core 0.1.0 → 0.1.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 +44 -65
- package/THEME_API.md +36 -33
- package/dist/api.js +14 -0
- package/dist/api.js.map +1 -0
- package/dist/api.mjs +5 -0
- package/dist/api.mjs.map +1 -0
- package/dist/auth.js +23 -0
- package/dist/auth.js.map +1 -0
- package/dist/auth.mjs +6 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/blog.js +22 -0
- package/dist/blog.js.map +1 -0
- package/dist/blog.mjs +5 -0
- package/dist/blog.mjs.map +1 -0
- package/dist/cart.js +27 -0
- package/dist/cart.js.map +1 -0
- package/dist/cart.mjs +6 -0
- package/dist/cart.mjs.map +1 -0
- package/dist/chunk-2CSWHI3L.js +210 -0
- package/dist/chunk-2CSWHI3L.js.map +1 -0
- package/dist/chunk-2FGHIDUV.js +99 -0
- package/dist/chunk-2FGHIDUV.js.map +1 -0
- package/dist/chunk-2NMEKWO5.js +40 -0
- package/dist/chunk-2NMEKWO5.js.map +1 -0
- package/dist/chunk-43BVHGDT.mjs +131 -0
- package/dist/chunk-43BVHGDT.mjs.map +1 -0
- package/dist/chunk-4JVQJI3I.mjs +290 -0
- package/dist/chunk-4JVQJI3I.mjs.map +1 -0
- package/dist/chunk-5N2EKK5O.js +9550 -0
- package/dist/chunk-5N2EKK5O.js.map +1 -0
- package/dist/chunk-5T6NDVSN.js +76 -0
- package/dist/chunk-5T6NDVSN.js.map +1 -0
- package/dist/chunk-73AINNCI.mjs +201 -0
- package/dist/chunk-73AINNCI.mjs.map +1 -0
- package/dist/chunk-AIXBDAVP.mjs +61 -0
- package/dist/chunk-AIXBDAVP.mjs.map +1 -0
- package/dist/chunk-ALYN5HAC.js +210 -0
- package/dist/chunk-ALYN5HAC.js.map +1 -0
- package/dist/chunk-AREMJR3Q.js +36 -0
- package/dist/chunk-AREMJR3Q.js.map +1 -0
- package/dist/chunk-DXAI6XOI.mjs +33 -0
- package/dist/chunk-DXAI6XOI.mjs.map +1 -0
- package/dist/chunk-F5TFNWFJ.mjs +257 -0
- package/dist/chunk-F5TFNWFJ.mjs.map +1 -0
- package/dist/chunk-FQ7FWUZN.js +265 -0
- package/dist/chunk-FQ7FWUZN.js.map +1 -0
- package/dist/{chunk-3SZX6LHT.js → chunk-J27VGXJH.js} +2 -24
- package/dist/chunk-J27VGXJH.js.map +1 -0
- package/dist/chunk-JZ46LLTZ.js +121 -0
- package/dist/chunk-JZ46LLTZ.js.map +1 -0
- package/dist/chunk-K24UHN6G.mjs +76 -0
- package/dist/chunk-K24UHN6G.mjs.map +1 -0
- package/dist/chunk-KCQGGU5R.mjs +344 -0
- package/dist/chunk-KCQGGU5R.mjs.map +1 -0
- package/dist/chunk-MT22NYKT.mjs +117 -0
- package/dist/chunk-MT22NYKT.mjs.map +1 -0
- package/dist/chunk-NDD472IZ.js +85 -0
- package/dist/chunk-NDD472IZ.js.map +1 -0
- package/dist/chunk-NHOIGGYU.mjs +833 -0
- package/dist/chunk-NHOIGGYU.mjs.map +1 -0
- package/dist/chunk-O3XR7TW3.mjs +12 -0
- package/dist/chunk-O3XR7TW3.mjs.map +1 -0
- package/dist/chunk-OAPYSC2X.mjs +206 -0
- package/dist/chunk-OAPYSC2X.mjs.map +1 -0
- package/dist/{chunk-XE4EOKS4.mjs → chunk-ONJREDYY.mjs} +3 -23
- package/dist/chunk-ONJREDYY.mjs.map +1 -0
- package/dist/chunk-OVT2LUAM.js +197 -0
- package/dist/chunk-OVT2LUAM.js.map +1 -0
- package/dist/chunk-OWNGNGKL.js +331 -0
- package/dist/chunk-OWNGNGKL.js.map +1 -0
- package/dist/chunk-P7SXNZSV.js +298 -0
- package/dist/chunk-P7SXNZSV.js.map +1 -0
- package/dist/chunk-PFJOL3HI.mjs +71 -0
- package/dist/chunk-PFJOL3HI.mjs.map +1 -0
- package/dist/chunk-PPULMWJ6.js +295 -0
- package/dist/chunk-PPULMWJ6.js.map +1 -0
- package/dist/chunk-RGIVKACG.js +359 -0
- package/dist/chunk-RGIVKACG.js.map +1 -0
- package/dist/chunk-RPP5K2LP.js +870 -0
- package/dist/chunk-RPP5K2LP.js.map +1 -0
- package/dist/{chunk-7EON6Q4L.mjs → chunk-RUCHWUD7.mjs} +7651 -6370
- package/dist/chunk-RUCHWUD7.mjs.map +1 -0
- package/dist/chunk-SEVUIX4H.js +137 -0
- package/dist/chunk-SEVUIX4H.js.map +1 -0
- package/dist/chunk-SK2FSHFM.mjs +208 -0
- package/dist/chunk-SK2FSHFM.mjs.map +1 -0
- package/dist/chunk-T6EJ2GAV.mjs +294 -0
- package/dist/chunk-T6EJ2GAV.mjs.map +1 -0
- package/dist/chunk-ULBDOFZI.mjs +302 -0
- package/dist/chunk-ULBDOFZI.mjs.map +1 -0
- package/dist/chunk-V3JIELNV.js +241 -0
- package/dist/chunk-V3JIELNV.js.map +1 -0
- package/dist/chunk-V5E2KWMA.mjs +238 -0
- package/dist/chunk-V5E2KWMA.mjs.map +1 -0
- package/dist/chunk-VJA3ER6A.js +14 -0
- package/dist/chunk-VJA3ER6A.js.map +1 -0
- package/dist/chunk-VLI7ULX5.js +66 -0
- package/dist/chunk-VLI7ULX5.js.map +1 -0
- package/dist/chunk-WFGS5OFH.mjs +189 -0
- package/dist/chunk-WFGS5OFH.mjs.map +1 -0
- package/dist/chunk-WVC5GP24.mjs +96 -0
- package/dist/chunk-WVC5GP24.mjs.map +1 -0
- package/dist/chunk-YOSPWY5K.mjs +36 -0
- package/dist/chunk-YOSPWY5K.mjs.map +1 -0
- package/dist/chunk-ZFFXXLX7.js +205 -0
- package/dist/chunk-ZFFXXLX7.js.map +1 -0
- package/dist/client.js +512 -249
- package/dist/client.mjs +21 -2
- package/dist/components.js +393 -0
- package/dist/components.js.map +1 -0
- package/dist/components.mjs +8 -0
- package/dist/components.mjs.map +1 -0
- package/dist/config.js +17 -0
- package/dist/config.js.map +1 -0
- package/dist/config.mjs +4 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contact.js +22 -0
- package/dist/contact.js.map +1 -0
- package/dist/contact.mjs +5 -0
- package/dist/contact.mjs.map +1 -0
- package/dist/contexts.js +51 -0
- package/dist/contexts.js.map +1 -0
- package/dist/contexts.mjs +6 -0
- package/dist/contexts.mjs.map +1 -0
- package/dist/finance.js +26 -0
- package/dist/finance.js.map +1 -0
- package/dist/finance.mjs +5 -0
- package/dist/finance.mjs.map +1 -0
- package/dist/icons.js +15 -0
- package/dist/icons.js.map +1 -0
- package/dist/icons.mjs +4 -0
- package/dist/icons.mjs.map +1 -0
- package/dist/index.js +512 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal.js +1437 -0
- package/dist/internal.js.map +1 -0
- package/dist/internal.mjs +1404 -0
- package/dist/internal.mjs.map +1 -0
- package/dist/motion.js +51 -0
- package/dist/motion.js.map +1 -0
- package/dist/motion.mjs +38 -0
- package/dist/motion.mjs.map +1 -0
- package/dist/orders.js +22 -0
- package/dist/orders.js.map +1 -0
- package/dist/orders.mjs +5 -0
- package/dist/orders.mjs.map +1 -0
- package/dist/products.js +27 -0
- package/dist/products.js.map +1 -0
- package/dist/products.mjs +6 -0
- package/dist/products.mjs.map +1 -0
- package/dist/registry.js +44 -0
- package/dist/registry.js.map +1 -0
- package/dist/registry.mjs +7 -0
- package/dist/registry.mjs.map +1 -0
- package/dist/renderers.js +51 -0
- package/dist/renderers.js.map +1 -0
- package/dist/renderers.mjs +6 -0
- package/dist/renderers.mjs.map +1 -0
- package/dist/server.js +11 -189
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +3 -186
- package/dist/server.mjs.map +1 -1
- package/dist/types.js +37 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +4 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.js +160 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +7 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/wrappers.js +104 -0
- package/dist/wrappers.js.map +1 -0
- package/dist/wrappers.mjs +96 -0
- package/dist/wrappers.mjs.map +1 -0
- package/package.json +112 -9
- package/dist/api-vuL1Eg5L.d.mts +0 -2961
- package/dist/api-vuL1Eg5L.d.ts +0 -2961
- package/dist/chunk-3SZX6LHT.js.map +0 -1
- package/dist/chunk-7EON6Q4L.mjs.map +0 -1
- package/dist/chunk-WDY773GJ.js +0 -8308
- package/dist/chunk-WDY773GJ.js.map +0 -1
- package/dist/chunk-XE4EOKS4.mjs.map +0 -1
- package/dist/client.d.mts +0 -1461
- package/dist/client.d.ts +0 -1461
- package/dist/index.d.mts +0 -125
- package/dist/index.d.ts +0 -125
- package/dist/server.d.mts +0 -70
- package/dist/server.d.ts +0 -70
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { create } from 'zustand';
|
|
3
|
+
|
|
4
|
+
// src/features/auth/use-auth.ts
|
|
5
|
+
var authService = null;
|
|
6
|
+
var useAuth = create((set, get) => ({
|
|
7
|
+
// Initial state
|
|
8
|
+
user: null,
|
|
9
|
+
isLoading: false,
|
|
10
|
+
isAuthenticated: false,
|
|
11
|
+
error: null,
|
|
12
|
+
isInitialized: false,
|
|
13
|
+
/**
|
|
14
|
+
* Initialize auth state - fetch current user
|
|
15
|
+
*/
|
|
16
|
+
initialize: async () => {
|
|
17
|
+
if (!authService) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (get().isInitialized) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
set({ isLoading: true });
|
|
26
|
+
try {
|
|
27
|
+
const user = await authService.getCurrentUser();
|
|
28
|
+
set({
|
|
29
|
+
user,
|
|
30
|
+
isAuthenticated: !!user,
|
|
31
|
+
isLoading: false,
|
|
32
|
+
isInitialized: true
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
set({
|
|
36
|
+
error: error.message,
|
|
37
|
+
isLoading: false,
|
|
38
|
+
isInitialized: true
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Login with email and password
|
|
44
|
+
*/
|
|
45
|
+
login: async (credentials) => {
|
|
46
|
+
if (!authService) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
set({ isLoading: true, error: null });
|
|
52
|
+
try {
|
|
53
|
+
const user = await authService.login(credentials);
|
|
54
|
+
set({ user, isAuthenticated: true, isLoading: false });
|
|
55
|
+
} catch (error) {
|
|
56
|
+
set({ error: error.message, isLoading: false });
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Signup with email, password, and name
|
|
62
|
+
* Note: Signup returns a message, user must verify email before login
|
|
63
|
+
*/
|
|
64
|
+
signup: async (data) => {
|
|
65
|
+
if (!authService) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
set({ isLoading: true, error: null });
|
|
71
|
+
try {
|
|
72
|
+
await authService.signup(data);
|
|
73
|
+
set({ isLoading: false });
|
|
74
|
+
} catch (error) {
|
|
75
|
+
set({ error: error.message, isLoading: false });
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Logout current user
|
|
81
|
+
*/
|
|
82
|
+
logout: async () => {
|
|
83
|
+
if (!authService) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
set({ isLoading: true });
|
|
89
|
+
try {
|
|
90
|
+
await authService.logout();
|
|
91
|
+
set({ user: null, isAuthenticated: false, isLoading: false });
|
|
92
|
+
} catch (error) {
|
|
93
|
+
set({ error: error.message, isLoading: false });
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Send forgot password email
|
|
99
|
+
*/
|
|
100
|
+
forgotPassword: async (data) => {
|
|
101
|
+
if (!authService) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
set({ isLoading: true, error: null });
|
|
107
|
+
try {
|
|
108
|
+
await authService.forgotPassword(data);
|
|
109
|
+
set({ isLoading: false });
|
|
110
|
+
} catch (error) {
|
|
111
|
+
set({ error: error.message, isLoading: false });
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* Reset password with token
|
|
117
|
+
*/
|
|
118
|
+
resetPassword: async (data) => {
|
|
119
|
+
if (!authService) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
set({ isLoading: true, error: null });
|
|
125
|
+
try {
|
|
126
|
+
await authService.resetPassword(data);
|
|
127
|
+
set({ isLoading: false });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
set({ error: error.message, isLoading: false });
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* Verify code (email verification, 2FA, etc.)
|
|
135
|
+
*/
|
|
136
|
+
verifyCode: async (data) => {
|
|
137
|
+
if (!authService) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
set({ isLoading: true, error: null });
|
|
143
|
+
try {
|
|
144
|
+
await authService.verifyCode(data);
|
|
145
|
+
set({ isLoading: false });
|
|
146
|
+
} catch (error) {
|
|
147
|
+
set({ error: error.message, isLoading: false });
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Verify code for password reset
|
|
153
|
+
*/
|
|
154
|
+
verifyCodeReset: async (data) => {
|
|
155
|
+
if (!authService) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
set({ isLoading: true, error: null });
|
|
161
|
+
try {
|
|
162
|
+
const result = await authService.verifyCodeReset(data);
|
|
163
|
+
set({ isLoading: false });
|
|
164
|
+
return result;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
set({ error: error.message, isLoading: false });
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* Resend verification code
|
|
172
|
+
*/
|
|
173
|
+
resendCode: async (data) => {
|
|
174
|
+
if (!authService) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
set({ isLoading: true, error: null });
|
|
180
|
+
try {
|
|
181
|
+
await authService.resendCode(data);
|
|
182
|
+
set({ isLoading: false });
|
|
183
|
+
} catch (error) {
|
|
184
|
+
set({ error: error.message, isLoading: false });
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* Update user profile
|
|
190
|
+
*/
|
|
191
|
+
updateProfile: async (data) => {
|
|
192
|
+
if (!authService) {
|
|
193
|
+
throw new Error(
|
|
194
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
set({ isLoading: true, error: null });
|
|
198
|
+
try {
|
|
199
|
+
await authService.updateProfile(data);
|
|
200
|
+
const user = await authService.getCurrentUser();
|
|
201
|
+
set({ user, isLoading: false });
|
|
202
|
+
} catch (error) {
|
|
203
|
+
set({ error: error.message, isLoading: false });
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
/**
|
|
208
|
+
* Change password
|
|
209
|
+
*/
|
|
210
|
+
changePassword: async (data) => {
|
|
211
|
+
if (!authService) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"Auth service not initialized. Call initializeOnex() first."
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
set({ isLoading: true, error: null });
|
|
217
|
+
try {
|
|
218
|
+
await authService.changePassword(data);
|
|
219
|
+
set({ isLoading: false });
|
|
220
|
+
} catch (error) {
|
|
221
|
+
set({ error: error.message, isLoading: false });
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
/**
|
|
226
|
+
* Clear error
|
|
227
|
+
*/
|
|
228
|
+
clearError: () => {
|
|
229
|
+
set({ error: null });
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
232
|
+
function initializeAuthService(service) {
|
|
233
|
+
authService = service;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { initializeAuthService, useAuth };
|
|
237
|
+
//# sourceMappingURL=chunk-V5E2KWMA.mjs.map
|
|
238
|
+
//# sourceMappingURL=chunk-V5E2KWMA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/features/auth/use-auth.ts"],"names":[],"mappings":";;;AAyCA,IAAI,WAAA,GAAkC,IAAA;AAE/B,IAAM,OAAA,GAAU,MAAA,CAAkB,CAAC,GAAA,EAAK,GAAA,MAAS;AAAA;AAAA,EAEtD,IAAA,EAAM,IAAA;AAAA,EACN,SAAA,EAAW,KAAA;AAAA,EACX,eAAA,EAAiB,KAAA;AAAA,EACjB,KAAA,EAAO,IAAA;AAAA,EACP,aAAA,EAAe,KAAA;AAAA;AAAA;AAAA;AAAA,EAKf,YAAY,YAAY;AACtB,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAA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,GAAA,CAAI,EAAE,KAAA,EAAO,IAAA,EAAM,CAAA;AAAA,EACrB;AACF,CAAA,CAAE;AAMK,SAAS,sBAAsB,OAAA,EAA4B;AAChE,EAAA,WAAA,GAAc,OAAA;AAChB","file":"chunk-V5E2KWMA.mjs","sourcesContent":["/**\n * Auth Hook\n * Zustand store for authentication state and actions\n */\n\nimport { create } from \"zustand\";\nimport { AuthService } from \"./auth-service\";\nimport type {\n User,\n LoginCredentials,\n SignupData,\n ForgotPasswordData,\n ResetPasswordData,\n VerifyCodeData,\n ResendCodeData,\n ChangePasswordData,\n} from \"./types\";\n\ninterface AuthState {\n // State\n user: User | null;\n isLoading: boolean;\n isAuthenticated: boolean;\n error: string | null;\n isInitialized: boolean;\n\n // Actions\n initialize: () => Promise<void>;\n login: (credentials: LoginCredentials) => Promise<void>;\n signup: (data: SignupData) => Promise<void>;\n logout: () => Promise<void>;\n forgotPassword: (data: ForgotPasswordData) => Promise<void>;\n resetPassword: (data: ResetPasswordData) => Promise<void>;\n verifyCode: (data: VerifyCodeData) => Promise<void>;\n verifyCodeReset: (data: VerifyCodeData) => Promise<{ session: string }>;\n resendCode: (data: ResendCodeData) => Promise<void>;\n updateProfile: (data: Partial<User>) => Promise<void>;\n changePassword: (data: ChangePasswordData) => Promise<void>;\n clearError: () => void;\n}\n\nlet authService: AuthService | null = null;\n\nexport const useAuth = create<AuthState>((set, get) => ({\n // Initial state\n user: null,\n isLoading: false,\n isAuthenticated: false,\n error: null,\n isInitialized: false,\n\n /**\n * Initialize auth state - fetch current user\n */\n initialize: async () => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n if (get().isInitialized) {\n return;\n }\n\n set({ isLoading: true });\n try {\n const user = await authService.getCurrentUser();\n set({\n user,\n isAuthenticated: !!user,\n isLoading: false,\n isInitialized: true,\n });\n } catch (error) {\n set({\n error: (error as Error).message,\n isLoading: false,\n isInitialized: true,\n });\n }\n },\n\n /**\n * Login with email and password\n */\n login: async (credentials) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n const user = await authService.login(credentials);\n set({ user, isAuthenticated: true, isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Signup with email, password, and name\n * Note: Signup returns a message, user must verify email before login\n */\n signup: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.signup(data);\n // Signup successful but user is not logged in yet\n // They need to verify their email first\n set({ isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Logout current user\n */\n logout: async () => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true });\n try {\n await authService.logout();\n set({ user: null, isAuthenticated: false, isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Send forgot password email\n */\n forgotPassword: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.forgotPassword(data);\n set({ isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Reset password with token\n */\n resetPassword: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.resetPassword(data);\n set({ isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Verify code (email verification, 2FA, etc.)\n */\n verifyCode: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.verifyCode(data);\n set({ isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Verify code for password reset\n */\n verifyCodeReset: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n const result = await authService.verifyCodeReset(data);\n set({ isLoading: false });\n return result;\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Resend verification code\n */\n resendCode: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.resendCode(data);\n set({ isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Update user profile\n */\n updateProfile: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.updateProfile(data);\n // Re-fetch user info to get updated data\n const user = await authService.getCurrentUser();\n set({ user, isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Change password\n */\n changePassword: async (data) => {\n if (!authService) {\n throw new Error(\n \"Auth service not initialized. Call initializeOnex() first.\"\n );\n }\n\n set({ isLoading: true, error: null });\n try {\n await authService.changePassword(data);\n set({ isLoading: false });\n } catch (error) {\n set({ error: (error as Error).message, isLoading: false });\n throw error;\n }\n },\n\n /**\n * Clear error\n */\n clearError: () => {\n set({ error: null });\n },\n}));\n\n/**\n * Initialize auth service\n * @internal Called by initializeOnex()\n */\nexport function initializeAuthService(service: AuthService): void {\n authService = service;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var clsx = require('clsx');
|
|
5
|
+
var tailwindMerge = require('tailwind-merge');
|
|
6
|
+
|
|
7
|
+
// src/utils/cn.ts
|
|
8
|
+
function cn(...inputs) {
|
|
9
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.cn = cn;
|
|
13
|
+
//# sourceMappingURL=chunk-VJA3ER6A.js.map
|
|
14
|
+
//# sourceMappingURL=chunk-VJA3ER6A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/cn.ts"],"names":["twMerge","clsx"],"mappings":";;;;;;AAkBO,SAAS,MAAM,MAAA,EAAsB;AAC1C,EAAA,OAAOA,qBAAA,CAAQC,SAAA,CAAK,MAAM,CAAC,CAAA;AAC7B","file":"chunk-VJA3ER6A.js","sourcesContent":["/**\n * Class Name Utility\n * Merge Tailwind CSS classes with proper conflict resolution\n */\n\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n/**\n * Combines class names with Tailwind CSS conflict resolution\n *\n * @param inputs - Class names to merge\n * @returns Merged class string\n *\n * @example\n * cn(\"px-2 py-1\", \"px-4\") // => \"py-1 px-4\"\n * cn(\"text-red-500\", condition && \"text-blue-500\") // => \"text-blue-500\" (if condition is true)\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkZFFXXLX7_js = require('./chunk-ZFFXXLX7.js');
|
|
5
|
+
var chunkOWNGNGKL_js = require('./chunk-OWNGNGKL.js');
|
|
6
|
+
var chunkP7SXNZSV_js = require('./chunk-P7SXNZSV.js');
|
|
7
|
+
var chunkAREMJR3Q_js = require('./chunk-AREMJR3Q.js');
|
|
8
|
+
var chunkSEVUIX4H_js = require('./chunk-SEVUIX4H.js');
|
|
9
|
+
var chunkALYN5HAC_js = require('./chunk-ALYN5HAC.js');
|
|
10
|
+
var chunk5T6NDVSN_js = require('./chunk-5T6NDVSN.js');
|
|
11
|
+
var chunkJZ46LLTZ_js = require('./chunk-JZ46LLTZ.js');
|
|
12
|
+
var chunk2CSWHI3L_js = require('./chunk-2CSWHI3L.js');
|
|
13
|
+
var chunkV3JIELNV_js = require('./chunk-V3JIELNV.js');
|
|
14
|
+
|
|
15
|
+
// src/init.ts
|
|
16
|
+
var isInitialized = false;
|
|
17
|
+
function initializeOnex(config) {
|
|
18
|
+
chunkAREMJR3Q_js.validateConfig(config);
|
|
19
|
+
if (isInitialized) {
|
|
20
|
+
console.warn("[OneX] Already initialized. Skipping re-initialization.");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const apiClient = new chunkSEVUIX4H_js.ApiClient({
|
|
24
|
+
baseURL: config.apiUrl,
|
|
25
|
+
tokenStorage: config.tokenStorage || "localStorage",
|
|
26
|
+
onUnauthorized: config.onUnauthorized,
|
|
27
|
+
headers: config.headers
|
|
28
|
+
});
|
|
29
|
+
const authService = new chunkALYN5HAC_js.AuthService(apiClient);
|
|
30
|
+
const cartService = new chunkZFFXXLX7_js.CartService(apiClient);
|
|
31
|
+
const productsService = new chunkOWNGNGKL_js.ProductsService(apiClient);
|
|
32
|
+
const ordersService = new chunkP7SXNZSV_js.OrdersService(apiClient);
|
|
33
|
+
const financeService = new chunk5T6NDVSN_js.FinanceService(apiClient);
|
|
34
|
+
const contactService = new chunkJZ46LLTZ_js.ContactService(apiClient, config.companyId);
|
|
35
|
+
const blogService = new chunk2CSWHI3L_js.BlogService(apiClient, config.companyId);
|
|
36
|
+
chunkV3JIELNV_js.initializeAuthService(authService);
|
|
37
|
+
chunkZFFXXLX7_js.initializeCartService(cartService);
|
|
38
|
+
chunkOWNGNGKL_js.initializeProductsService(productsService);
|
|
39
|
+
chunkP7SXNZSV_js.initializeOrdersService(ordersService);
|
|
40
|
+
chunk5T6NDVSN_js.initializeFinanceService(financeService);
|
|
41
|
+
chunkJZ46LLTZ_js.initializeContactService(contactService);
|
|
42
|
+
chunk2CSWHI3L_js.initializeBlogService(blogService);
|
|
43
|
+
isInitialized = true;
|
|
44
|
+
if (typeof window !== "undefined") {
|
|
45
|
+
console.log("[OneX] Initialized successfully", {
|
|
46
|
+
apiUrl: config.apiUrl,
|
|
47
|
+
companyId: config.companyId
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function isOnexInitialized() {
|
|
52
|
+
return isInitialized;
|
|
53
|
+
}
|
|
54
|
+
function resetOnexInitialization() {
|
|
55
|
+
isInitialized = false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/client.ts
|
|
59
|
+
var version = "0.1.0";
|
|
60
|
+
|
|
61
|
+
exports.initializeOnex = initializeOnex;
|
|
62
|
+
exports.isOnexInitialized = isOnexInitialized;
|
|
63
|
+
exports.resetOnexInitialization = resetOnexInitialization;
|
|
64
|
+
exports.version = version;
|
|
65
|
+
//# sourceMappingURL=chunk-VLI7ULX5.js.map
|
|
66
|
+
//# sourceMappingURL=chunk-VLI7ULX5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/client.ts"],"names":["validateConfig","ApiClient","AuthService","CartService","ProductsService","OrdersService","FinanceService","ContactService","BlogService","initializeAuthService","initializeCartService","initializeProductsService","initializeOrdersService","initializeFinanceService","initializeContactService","initializeBlogService"],"mappings":";;;;;;;;;;;;;;AAmBA,IAAI,aAAA,GAAgB,KAAA;AAoBb,SAAS,eAAe,MAAA,EAA0B;AAEvD,EAAAA,+BAAA,CAAe,MAAM,CAAA;AAErB,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,OAAA,CAAQ,KAAK,yDAAyD,CAAA;AACtE,IAAA;AAAA,EACF;AAGA,EAAA,MAAM,SAAA,GAAY,IAAIC,0BAAA,CAAU;AAAA,IAC9B,SAAS,MAAA,CAAO,MAAA;AAAA,IAChB,YAAA,EAAc,OAAO,YAAA,IAAgB,cAAA;AAA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X5.js","sourcesContent":["/**\n * OneX Initialization\n * Call this once at app startup to initialize all services\n */\n\nimport { ApiClient } from \"./api/client\";\nimport { AuthService, initializeAuthService } from \"./features/auth\";\nimport { CartService, initializeCartService } from \"./features/cart\";\nimport {\n ProductsService,\n initializeProductsService,\n} from \"./features/products\";\nimport { OrdersService, initializeOrdersService } from \"./features/orders\";\nimport { FinanceService, initializeFinanceService } from \"./features/finance\";\nimport { ContactService, initializeContactService } from \"./features/contact\";\nimport { BlogService, initializeBlogService } from \"./features/blog\";\nimport type { OnexConfig } from \"./config\";\nimport { validateConfig } from \"./config\";\n\nlet isInitialized = false;\n\n/**\n * Initialize OneX SDK with configuration\n * Must be called before using any hooks (useAuth, useCart, etc.)\n *\n * @example\n * ```tsx\n * // In your app's root component or layout\n * import { initializeOnex } from '@duongthiu/onex-core';\n *\n * initializeOnex({\n * apiUrl: 'https://api-dev.onexeos.com',\n * companyId: '9e61d187-426a-45ec-914d-7aea8ca7d42d',\n * onUnauthorized: () => {\n * window.location.href = '/login';\n * }\n * });\n * ```\n */\nexport function initializeOnex(config: OnexConfig): void {\n // Validate config first\n validateConfig(config);\n\n if (isInitialized) {\n console.warn(\"[OneX] Already initialized. Skipping re-initialization.\");\n return;\n }\n\n // Create API client\n const apiClient = new ApiClient({\n baseURL: config.apiUrl,\n tokenStorage: config.tokenStorage || \"localStorage\",\n onUnauthorized: config.onUnauthorized,\n headers: config.headers,\n });\n\n // Initialize all services\n const authService = new AuthService(apiClient);\n const cartService = new CartService(apiClient);\n const productsService = new ProductsService(apiClient);\n const ordersService = new OrdersService(apiClient);\n const financeService = new FinanceService(apiClient);\n const contactService = new ContactService(apiClient, config.companyId);\n const blogService = new BlogService(apiClient, config.companyId);\n\n // Register services with hooks\n initializeAuthService(authService);\n initializeCartService(cartService);\n initializeProductsService(productsService);\n initializeOrdersService(ordersService);\n initializeFinanceService(financeService);\n initializeContactService(contactService);\n initializeBlogService(blogService);\n\n isInitialized = true;\n\n if (typeof window !== \"undefined\") {\n console.log(\"[OneX] Initialized successfully\", {\n apiUrl: config.apiUrl,\n companyId: config.companyId,\n });\n }\n}\n\n/**\n * Check if OneX is initialized\n */\nexport function isOnexInitialized(): boolean {\n return isInitialized;\n}\n\n/**\n * Reset initialization state (useful for testing)\n * @internal\n */\nexport function resetOnexInitialization(): void {\n isInitialized = false;\n}\n","\"use client\";\n\n/**\n * @onex/core/client - Client-Safe Exports\n *\n * This entry point exports only client-safe code that can be used in:\n * - Client Components (\"use client\")\n * - Server Components\n * - Shared utilities\n *\n * Does NOT include:\n * - ThemeRegistryManager (server-only, uses fs/promises)\n */\n\nexport const version = \"0.1.0\";\n\n// Type Definitions (all safe)\nexport * from \"./types\";\n\n// Registry Factories (client-safe - no fs operations)\nexport * from \"./registry/section-registry\";\nexport * from \"./registry/block-registry\";\nexport * from \"./registry/component-registry\";\n// NOTE: theme-registry-manager is NOT exported here (server-only)\n\n// Utility Functions (all pure functions, client-safe)\nexport * from \"./utils\";\n\n// Rendering Engine (all client components)\nexport * from \"./renderers\";\n\n// React Contexts (all client-safe)\nexport * from \"./contexts\";\n\n// Layout Components (all client-safe)\nexport * from \"./components\";\n\n// API Client\nexport { ApiClient } from \"./api/client\";\nexport type { ApiConfig, ApiResponse } from \"./api/client\";\n\n// Features (Auth, Cart, Products)\n// Re-export specific items to avoid conflicts with existing domain types\nexport { useAuth, initializeAuthService, AuthService } from \"./features/auth\";\nexport type {\n User,\n LoginCredentials,\n SignupData,\n ForgotPasswordData,\n ResetPasswordData,\n VerifyCodeData,\n ResendCodeData,\n ChangePasswordData,\n TokenData,\n UserAttribute,\n UserInfoResponse,\n AuthResponse,\n} from \"./features/auth\";\n\nexport { useCart, initializeCartService, CartService } from \"./features/cart\";\nexport type {\n CartItem as CartItemFeature,\n Cart as CartFeature,\n AddToCartData,\n UpdateCartItemData,\n} from \"./features/cart\";\n\nexport {\n useProducts,\n initializeProductsService,\n ProductsService,\n} from \"./features/products\";\nexport type {\n ProductsListResponse,\n ProductsListParams,\n} from \"./features/products\";\n\n// ProductCard Component\nexport { ProductCard } from \"./components/product-card\";\nexport type { ProductCardProps } from \"./components/product-card\";\n\n// Orders Feature\nexport {\n useOrders,\n initializeOrdersService,\n OrdersService,\n} from \"./features/orders\";\nexport type {\n Address,\n OrderItem,\n Order,\n CreateOrderData,\n OrdersListResponse,\n OrdersListParams,\n} from \"./features/orders\";\n\n// Finance Feature\nexport {\n useFinance,\n initializeFinanceService,\n FinanceService,\n BANK_TRANSFER_DATA,\n} from \"./features/finance\";\nexport type { CreateQrPayload, QrResponse } from \"./features/finance\";\n\n// Contact Feature\nexport {\n useContact,\n initializeContactService,\n ContactService,\n} from \"./features/contact\";\nexport type {\n ContactSubmitPayload,\n ContactSubmitResponse,\n ContactInfo,\n ContactFormField,\n} from \"./features/contact\";\n\n// Blog Feature\nexport { useBlog, initializeBlogService, BlogService } from \"./features/blog\";\nexport type {\n Blog,\n BlogCategory,\n BlogAuthor,\n BlogListResponse,\n BlogListParams,\n} from \"./features/blog\";\n\n// Configuration\nexport { validateConfig, createConfigFromEnv } from \"./config\";\nexport type { OnexConfig } from \"./config\";\n\n// Initialization\nexport {\n initializeOnex,\n isOnexInitialized,\n resetOnexInitialization,\n} from \"./init\";\n"]}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createSectionRegistry } from './chunk-ONJREDYY.mjs';
|
|
3
|
+
import 'server-only';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
function toCamelCase(str) {
|
|
8
|
+
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
9
|
+
}
|
|
10
|
+
var ThemeRegistryManager = class {
|
|
11
|
+
constructor(debug = process.env.NODE_ENV === "development") {
|
|
12
|
+
this.registries = /* @__PURE__ */ new Map();
|
|
13
|
+
this.initialized = /* @__PURE__ */ new Set();
|
|
14
|
+
this.debug = debug;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Auto-discover sections from theme directory
|
|
18
|
+
* Reads filesystem to find all section directories
|
|
19
|
+
*/
|
|
20
|
+
async discoverThemeSections(themeId) {
|
|
21
|
+
const sectionsPath = path.join(
|
|
22
|
+
process.cwd(),
|
|
23
|
+
`src/themes/${themeId}/sections`
|
|
24
|
+
);
|
|
25
|
+
try {
|
|
26
|
+
const entries = await fs.readdir(sectionsPath, { withFileTypes: true });
|
|
27
|
+
const sectionNames = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
28
|
+
if (this.debug) {
|
|
29
|
+
}
|
|
30
|
+
return sectionNames;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (this.debug) {
|
|
33
|
+
console.warn(
|
|
34
|
+
`[ThemeRegistry] No sections found for theme "${themeId}" at ${sectionsPath}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initialize a theme's sections
|
|
42
|
+
* Auto-discovers and registers all sections for a theme
|
|
43
|
+
*/
|
|
44
|
+
async initializeTheme(themeId) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (this.initialized.has(themeId)) {
|
|
47
|
+
if (this.debug) ;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const registry = this.getThemeRegistry(themeId);
|
|
51
|
+
const sectionNames = await this.discoverThemeSections(themeId);
|
|
52
|
+
if (sectionNames.length === 0) {
|
|
53
|
+
console.warn(`[ThemeRegistry] No sections found for theme "${themeId}"`);
|
|
54
|
+
this.initialized.add(themeId);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let _successCount = 0;
|
|
58
|
+
let _failureCount = 0;
|
|
59
|
+
for (const sectionName of sectionNames) {
|
|
60
|
+
try {
|
|
61
|
+
const sectionModule = await import(`@/themes/${themeId}/sections/${sectionName}`);
|
|
62
|
+
const camelName = toCamelCase(sectionName);
|
|
63
|
+
const schema = sectionModule[`${camelName}Schema`] || ((_a = sectionModule.default) == null ? void 0 : _a.schema) || sectionModule.schema;
|
|
64
|
+
const components = sectionModule[`${camelName}Components`] || ((_b = sectionModule.default) == null ? void 0 : _b.components) || sectionModule.components;
|
|
65
|
+
if (!schema || !components) {
|
|
66
|
+
console.error(
|
|
67
|
+
`[ThemeRegistry] Section "${sectionName}" in theme "${themeId}" missing schema or components export.`,
|
|
68
|
+
`Expected: "${camelName}Schema" and "${camelName}Components"`
|
|
69
|
+
);
|
|
70
|
+
_failureCount++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const defaultComponent = components.default || Object.values(components)[0];
|
|
74
|
+
if (!defaultComponent) {
|
|
75
|
+
console.error(
|
|
76
|
+
`[ThemeRegistry] Section "${sectionName}" has no default component`
|
|
77
|
+
);
|
|
78
|
+
_failureCount++;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const templates = Object.entries(components).map(
|
|
82
|
+
([templateId, component]) => ({
|
|
83
|
+
definition: schema.templates.find((t) => t.id === templateId) || {
|
|
84
|
+
id: templateId,
|
|
85
|
+
name: templateId,
|
|
86
|
+
description: `${templateId} template`,
|
|
87
|
+
isDefault: templateId === "default",
|
|
88
|
+
settings: schema.settings,
|
|
89
|
+
defaults: schema.defaults
|
|
90
|
+
},
|
|
91
|
+
component
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
registry.register(schema.type, schema, defaultComponent, {
|
|
95
|
+
templates,
|
|
96
|
+
category: schema.category,
|
|
97
|
+
tags: schema.tags
|
|
98
|
+
});
|
|
99
|
+
_successCount++;
|
|
100
|
+
if (this.debug) {
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(
|
|
104
|
+
`[ThemeRegistry] Failed to load section "${themeId}/${sectionName}":`,
|
|
105
|
+
error
|
|
106
|
+
);
|
|
107
|
+
_failureCount++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.initialized.add(themeId);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get or create theme-specific registry
|
|
114
|
+
*/
|
|
115
|
+
getThemeRegistry(themeId) {
|
|
116
|
+
if (!this.registries.has(themeId)) {
|
|
117
|
+
const registry = createSectionRegistry({
|
|
118
|
+
debug: this.debug,
|
|
119
|
+
allowOverride: this.debug
|
|
120
|
+
});
|
|
121
|
+
this.registries.set(themeId, registry);
|
|
122
|
+
if (this.debug) ;
|
|
123
|
+
}
|
|
124
|
+
return this.registries.get(themeId);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check if theme has been initialized
|
|
128
|
+
*/
|
|
129
|
+
isThemeInitialized(themeId) {
|
|
130
|
+
return this.initialized.has(themeId);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Resolve a section component for a specific theme
|
|
134
|
+
* Returns null if not found (no fallback - strict validation)
|
|
135
|
+
*/
|
|
136
|
+
resolveSection(themeId, sectionType, templateId = "default") {
|
|
137
|
+
const registry = this.getThemeRegistry(themeId);
|
|
138
|
+
return registry.getTemplateComponent(sectionType, templateId) || null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get section schema for a specific theme
|
|
142
|
+
*/
|
|
143
|
+
getSectionSchema(themeId, sectionType) {
|
|
144
|
+
const registry = this.getThemeRegistry(themeId);
|
|
145
|
+
return registry.getSchema(sectionType) || null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get all available themes
|
|
149
|
+
*/
|
|
150
|
+
getAvailableThemes() {
|
|
151
|
+
return Array.from(this.registries.keys());
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get all section types for a theme
|
|
155
|
+
*/
|
|
156
|
+
getThemeSections(themeId) {
|
|
157
|
+
const registry = this.registries.get(themeId);
|
|
158
|
+
if (!registry) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const all = registry.getAll();
|
|
162
|
+
return Array.from(all.keys());
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Clear a specific theme's registry
|
|
166
|
+
*/
|
|
167
|
+
clearTheme(themeId) {
|
|
168
|
+
const registry = this.registries.get(themeId);
|
|
169
|
+
if (registry) {
|
|
170
|
+
registry.clear();
|
|
171
|
+
this.initialized.delete(themeId);
|
|
172
|
+
if (this.debug) ;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Clear all theme registries
|
|
177
|
+
*/
|
|
178
|
+
clearAll() {
|
|
179
|
+
this.registries.forEach((registry) => registry.clear());
|
|
180
|
+
this.registries.clear();
|
|
181
|
+
this.initialized.clear();
|
|
182
|
+
if (this.debug) ;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var themeRegistryManager = new ThemeRegistryManager();
|
|
186
|
+
|
|
187
|
+
export { ThemeRegistryManager, themeRegistryManager };
|
|
188
|
+
//# sourceMappingURL=chunk-WFGS5OFH.mjs.map
|
|
189
|
+
//# sourceMappingURL=chunk-WFGS5OFH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/registry/theme-registry-manager.ts"],"names":[],"mappings":";;;;;AAiBA,SAAS,YAAY,GAAA,EAAqB;AACxC,EAAA,OAAO,GAAA,CAAI,QAAQ,WAAA,EAAa,CAAC,MAAM,CAAA,CAAE,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA;AAC3D;AAMO,IAAM,uBAAN,MAA2B;AAAA,EAKhC,WAAA,CAAY,KAAA,GAAiB,OAAA,CAAQ,GAAA,CAAI,aAAa,aAAA,EAAe;AACnE,IAAA,IAAA,CAAK,UAAA,uBAAiB,GAAA,EAAI;AAC1B,IAAA,IAAA,CAAK,WAAA,uBAAkB,GAAA,EAAI;AAC3B,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,sBAAsB,OAAA,EAAoC;AAC9D,IAAA,MAAM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AAA,OAAO,EAAC;AAAA,IACV;AAEA,IAAA,MAAM,GAAA,GAAM,SAAS,MAAA,EAAO;AAC5B,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,CAAA;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,OAAA,EAAuB;AAChC,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,UAAA,CAAW,GAAA,CAAI,OAAO,CAAA;AAC5C,IAAA,IAAI,QAAA,EAAU;AACZ,MAAA,QAAA,CAAS,KAAA,EAAM;AACf,MAAA,IAAA,CAAK,WAAA,CAAY,OAAO,OAAO,CAAA;AAE/B,MAAA,IAAI,KAAK,KAAA,EAAO;AAChB,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAAiB;AACf,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,CAAC,QAAA,KAAa,QAAA,CAAS,OAAO,CAAA;AACtD,IAAA,IAAA,CAAK,WAAW,KAAA,EAAM;AACtB,IAAA,IAAA,CAAK,YAAY,KAAA,EAAM;AAEvB,IAAA,IAAI,KAAK,KAAA,EAAO;AAChB,EACF;AACF;AAKO,IAAM,oBAAA,GAAuB,IAAI,oBAAA","file":"chunk-WFGS5OFH.mjs","sourcesContent":["/**\n * Theme Registry Manager\n * Manages theme-specific section registries with auto-discovery\n *\n * SERVER-ONLY: Uses filesystem operations, cannot run in browser\n */\n\nimport \"server-only\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport type { SectionRegistry } from \"../types/registry\";\nimport type { SectionSchema, SectionComponentProps } from \"../types/section\";\nimport { createSectionRegistry } from \"./section-registry\";\n\n/**\n * Convert kebab-case to camelCase\n */\nfunction toCamelCase(str: string): string {\n return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());\n}\n\n/**\n * Theme Registry Manager\n * Auto-discovers and manages theme-specific section registries\n */\nexport class ThemeRegistryManager {\n private registries: Map<string, SectionRegistry>;\n private initialized: Set<string>;\n private debug: boolean;\n\n constructor(debug: boolean = process.env.NODE_ENV === \"development\") {\n this.registries = new Map();\n this.initialized = new Set();\n this.debug = debug;\n }\n\n /**\n * Auto-discover sections from theme directory\n * Reads filesystem to find all section directories\n */\n async discoverThemeSections(themeId: string): Promise<string[]> {\n const sectionsPath = path.join(\n process.cwd(),\n `src/themes/${themeId}/sections`\n );\n\n try {\n const entries = await fs.readdir(sectionsPath, { withFileTypes: true });\n\n // Return only directories (each directory = one section)\n const sectionNames = entries\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n\n if (this.debug) {\n }\n\n return sectionNames;\n } catch (error) {\n if (this.debug) {\n console.warn(\n `[ThemeRegistry] No sections found for theme \"${themeId}\" at ${sectionsPath}`\n );\n }\n return [];\n }\n }\n\n /**\n * Initialize a theme's sections\n * Auto-discovers and registers all sections for a theme\n */\n async initializeTheme(themeId: string): Promise<void> {\n // Check if already initialized\n if (this.initialized.has(themeId)) {\n if (this.debug) {\n }\n return;\n }\n\n // Get or create registry for this theme\n const registry = this.getThemeRegistry(themeId);\n\n // Discover sections\n const sectionNames = await this.discoverThemeSections(themeId);\n\n if (sectionNames.length === 0) {\n console.warn(`[ThemeRegistry] No sections found for theme \"${themeId}\"`);\n this.initialized.add(themeId);\n return;\n }\n\n // Import and register each section\n\n let _successCount = 0;\n\n let _failureCount = 0;\n\n for (const sectionName of sectionNames) {\n try {\n // Dynamic import of section module\n const sectionModule = await import(\n `@/themes/${themeId}/sections/${sectionName}`\n );\n\n // Extract schema and components from module\n // Try different naming conventions\n const camelName = toCamelCase(sectionName);\n const schema: SectionSchema =\n sectionModule[`${camelName}Schema`] ||\n sectionModule.default?.schema ||\n sectionModule.schema;\n\n const components: Record<\n string,\n React.ComponentType<SectionComponentProps>\n > = sectionModule[`${camelName}Components`] ||\n sectionModule.default?.components ||\n sectionModule.components;\n\n if (!schema || !components) {\n console.error(\n `[ThemeRegistry] Section \"${sectionName}\" in theme \"${themeId}\" missing schema or components export.`,\n `Expected: \"${camelName}Schema\" and \"${camelName}Components\"`\n );\n _failureCount++;\n continue;\n }\n\n // Register section to theme-specific registry\n // Get the default component for backward compatibility\n const defaultComponent =\n components.default || Object.values(components)[0];\n\n if (!defaultComponent) {\n console.error(\n `[ThemeRegistry] Section \"${sectionName}\" has no default component`\n );\n _failureCount++;\n continue;\n }\n\n // Register with templates\n const templates = Object.entries(components).map(\n ([templateId, component]) => ({\n definition: schema.templates.find((t) => t.id === templateId) || {\n id: templateId,\n name: templateId,\n description: `${templateId} template`,\n isDefault: templateId === \"default\",\n settings: schema.settings,\n defaults: schema.defaults,\n },\n component,\n })\n );\n\n registry.register(schema.type, schema, defaultComponent, {\n templates,\n category: schema.category,\n tags: schema.tags,\n });\n\n _successCount++;\n\n if (this.debug) {\n }\n } catch (error) {\n console.error(\n `[ThemeRegistry] Failed to load section \"${themeId}/${sectionName}\":`,\n error\n );\n _failureCount++;\n }\n }\n\n // Mark as initialized\n this.initialized.add(themeId);\n }\n\n /**\n * Get or create theme-specific registry\n */\n getThemeRegistry(themeId: string): SectionRegistry {\n if (!this.registries.has(themeId)) {\n // Create new registry for this theme\n const registry = createSectionRegistry({\n debug: this.debug,\n allowOverride: this.debug,\n });\n\n this.registries.set(themeId, registry);\n\n if (this.debug) {\n }\n }\n\n return this.registries.get(themeId)!;\n }\n\n /**\n * Check if theme has been initialized\n */\n isThemeInitialized(themeId: string): boolean {\n return this.initialized.has(themeId);\n }\n\n /**\n * Resolve a section component for a specific theme\n * Returns null if not found (no fallback - strict validation)\n */\n resolveSection(\n themeId: string,\n sectionType: string,\n templateId: string = \"default\"\n ): React.ComponentType<SectionComponentProps> | null {\n const registry = this.getThemeRegistry(themeId);\n return registry.getTemplateComponent(sectionType, templateId) || null;\n }\n\n /**\n * Get section schema for a specific theme\n */\n getSectionSchema(themeId: string, sectionType: string): SectionSchema | null {\n const registry = this.getThemeRegistry(themeId);\n return registry.getSchema(sectionType) || null;\n }\n\n /**\n * Get all available themes\n */\n getAvailableThemes(): string[] {\n return Array.from(this.registries.keys());\n }\n\n /**\n * Get all section types for a theme\n */\n getThemeSections(themeId: string): string[] {\n const registry = this.registries.get(themeId);\n if (!registry) {\n return [];\n }\n\n const all = registry.getAll();\n return Array.from(all.keys());\n }\n\n /**\n * Clear a specific theme's registry\n */\n clearTheme(themeId: string): void {\n const registry = this.registries.get(themeId);\n if (registry) {\n registry.clear();\n this.initialized.delete(themeId);\n\n if (this.debug) {\n }\n }\n }\n\n /**\n * Clear all theme registries\n */\n clearAll(): void {\n this.registries.forEach((registry) => registry.clear());\n this.registries.clear();\n this.initialized.clear();\n\n if (this.debug) {\n }\n }\n}\n\n/**\n * Global theme registry manager instance\n */\nexport const themeRegistryManager = new ThemeRegistryManager();\n"]}
|