@famgia/omnify-react-sso 2.2.3 → 2.2.4

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.
Files changed (55) hide show
  1. package/dist/ant/index.cjs +3235 -0
  2. package/dist/ant/index.cjs.map +1 -0
  3. package/dist/ant/index.d.cts +685 -0
  4. package/dist/ant/index.d.ts +685 -0
  5. package/dist/ant/index.js +3268 -0
  6. package/dist/ant/index.js.map +1 -0
  7. package/dist/core/index.cjs +2432 -0
  8. package/dist/core/index.cjs.map +1 -0
  9. package/dist/core/index.d.cts +112 -0
  10. package/dist/core/index.d.ts +112 -0
  11. package/dist/core/index.js +2360 -0
  12. package/dist/core/index.js.map +1 -0
  13. package/dist/{testing → core/testing}/index.cjs +1 -1
  14. package/dist/core/testing/index.cjs.map +1 -0
  15. package/dist/{testing → core/testing}/index.d.cts +1 -1
  16. package/dist/{testing → core/testing}/index.d.ts +1 -1
  17. package/dist/{testing → core/testing}/index.js +1 -1
  18. package/dist/core/testing/index.js.map +1 -0
  19. package/dist/index-CHuDTvHg.d.ts +2250 -0
  20. package/dist/index-DVssHZFD.d.cts +2250 -0
  21. package/dist/index.cjs +2464 -784
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +10 -1822
  24. package/dist/index.d.ts +10 -1822
  25. package/dist/index.js +2528 -771
  26. package/dist/index.js.map +1 -1
  27. package/dist/{types-bD5deLxs.d.cts → types-BxClyvTX.d.cts} +2 -3
  28. package/dist/{types-bD5deLxs.d.ts → types-BxClyvTX.d.ts} +2 -3
  29. package/dist/userService-DH9-vPSg.d.cts +269 -0
  30. package/dist/userService-DH9-vPSg.d.ts +269 -0
  31. package/package.json +27 -48
  32. package/dist/@omnify-base/package.json +0 -16
  33. package/dist/@omnify-base/schemas/Branch.ts +0 -131
  34. package/dist/@omnify-base/schemas/BranchCache.ts +0 -131
  35. package/dist/@omnify-base/schemas/OrganizationCache.ts +0 -117
  36. package/dist/@omnify-base/schemas/Permission.ts +0 -114
  37. package/dist/@omnify-base/schemas/Role.ts +0 -128
  38. package/dist/@omnify-base/schemas/RolePermission.ts +0 -97
  39. package/dist/@omnify-base/schemas/Team.ts +0 -110
  40. package/dist/@omnify-base/schemas/TeamCache.ts +0 -110
  41. package/dist/@omnify-base/schemas/TeamPermission.ts +0 -109
  42. package/dist/@omnify-base/schemas/User.ts +0 -135
  43. package/dist/@omnify-base/schemas/UserCache.ts +0 -142
  44. package/dist/@omnify-base/schemas/common.ts +0 -47
  45. package/dist/@omnify-base/schemas/i18n.ts +0 -118
  46. package/dist/schemas/index.cjs +0 -645
  47. package/dist/schemas/index.cjs.map +0 -1
  48. package/dist/schemas/index.d.cts +0 -260
  49. package/dist/schemas/index.d.ts +0 -260
  50. package/dist/schemas/index.js +0 -557
  51. package/dist/schemas/index.js.map +0 -1
  52. package/dist/testing/index.cjs.map +0 -1
  53. package/dist/testing/index.js.map +0 -1
  54. package/scripts/build-schemas.ts +0 -191
  55. package/scripts/postinstall.cjs +0 -43
@@ -0,0 +1,2432 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/core/index.ts
31
+ var core_exports = {};
32
+ __export(core_exports, {
33
+ BRANCH_HEADERS: () => BRANCH_HEADERS,
34
+ BranchContext: () => BranchContext,
35
+ BranchProvider: () => BranchProvider,
36
+ I18nProvider: () => I18nProvider,
37
+ SsoContext: () => SsoContext,
38
+ SsoProvider: () => SsoProvider,
39
+ changeLanguage: () => changeLanguage,
40
+ createAuthService: () => createAuthService,
41
+ createBranchHeaderSetter: () => createBranchHeaderSetter,
42
+ createBranchService: () => createBranchService,
43
+ createPermissionService: () => createPermissionService,
44
+ createRoleService: () => createRoleService,
45
+ createSsoService: () => createSsoService,
46
+ createTeamService: () => createTeamService,
47
+ createTokenService: () => createTokenService,
48
+ createUserRoleService: () => createUserRoleService,
49
+ createUserService: () => createUserService,
50
+ defaultLocale: () => defaultLocale,
51
+ defaultTranslations: () => defaultTranslations,
52
+ fallbackLocale: () => fallbackLocale,
53
+ getCurrentLocale: () => getCurrentLocale,
54
+ getEffectivePermissions: () => getEffectivePermissions,
55
+ getMessage: () => getMessage,
56
+ getMessages: () => getMessages,
57
+ getScopeLabel: () => getScopeLabel,
58
+ localeNames: () => localeNames,
59
+ locales: () => locales,
60
+ schemas: () => schemas_exports,
61
+ setBranchHeaders: () => setBranchHeaders,
62
+ ssoNamespace: () => ssoNamespace,
63
+ ssoQueryKeys: () => ssoQueryKeys,
64
+ supportedLocales: () => supportedLocales,
65
+ useAuth: () => useAuth,
66
+ useBranch: () => useBranch,
67
+ useBranchContext: () => useBranchContext,
68
+ useLocale: () => useLocale,
69
+ useOrganization: () => useOrganization,
70
+ useSso: () => useSso,
71
+ useSsoContext: () => useSsoContext,
72
+ useSsoTranslation: () => useSsoTranslation,
73
+ useTranslations: () => useTranslations,
74
+ validationMessages: () => validationMessages
75
+ });
76
+ module.exports = __toCommonJS(core_exports);
77
+
78
+ // src/core/context/SsoContext.tsx
79
+ var import_react = require("react");
80
+ var SsoContext = (0, import_react.createContext)(null);
81
+ function useSsoContext() {
82
+ const context = (0, import_react.useContext)(SsoContext);
83
+ if (!context) {
84
+ throw new Error("useSsoContext must be used within a SsoProvider");
85
+ }
86
+ return context;
87
+ }
88
+
89
+ // src/core/context/SsoProvider.tsx
90
+ var import_react2 = require("react");
91
+ var import_jsx_runtime = require("react/jsx-runtime");
92
+ function transformUser(data) {
93
+ return {
94
+ id: data.id,
95
+ consoleUserId: data.console_user_id,
96
+ email: data.email,
97
+ name: data.name
98
+ };
99
+ }
100
+ function transformOrganizations(data) {
101
+ return data.map((org) => ({
102
+ id: org.organization_id,
103
+ slug: org.organization_slug,
104
+ name: org.organization_name,
105
+ orgRole: org.org_role,
106
+ serviceRole: org.service_role
107
+ }));
108
+ }
109
+ function getStorage(type) {
110
+ if (typeof window === "undefined") return null;
111
+ return type === "localStorage" ? window.localStorage : window.sessionStorage;
112
+ }
113
+ function getXsrfToken() {
114
+ if (typeof document === "undefined") return void 0;
115
+ return document.cookie.split("; ").find((row) => row.startsWith("XSRF-TOKEN="))?.split("=")[1];
116
+ }
117
+ function SsoProvider({ children, config, onAuthChange }) {
118
+ const [user, setUser] = (0, import_react2.useState)(null);
119
+ const [organizations, setOrganizations] = (0, import_react2.useState)([]);
120
+ const [currentOrg, setCurrentOrg] = (0, import_react2.useState)(null);
121
+ const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
122
+ const storageKey = config.storageKey ?? "sso_selected_org";
123
+ const storage = getStorage(config.storage ?? "localStorage");
124
+ const loadSelectedOrg = (0, import_react2.useCallback)(
125
+ (orgs) => {
126
+ if (!storage || orgs.length === 0) return null;
127
+ const savedSlug = storage.getItem(storageKey);
128
+ if (savedSlug) {
129
+ const found = orgs.find((o) => o.slug === savedSlug);
130
+ if (found) return found;
131
+ }
132
+ return orgs[0];
133
+ },
134
+ [storage, storageKey]
135
+ );
136
+ const saveSelectedOrg = (0, import_react2.useCallback)(
137
+ (org) => {
138
+ if (!storage) return;
139
+ if (org) {
140
+ storage.setItem(storageKey, org.slug);
141
+ } else {
142
+ storage.removeItem(storageKey);
143
+ }
144
+ },
145
+ [storage, storageKey]
146
+ );
147
+ const fetchUser = (0, import_react2.useCallback)(async () => {
148
+ try {
149
+ const xsrfToken = getXsrfToken();
150
+ const headers = {
151
+ "Accept": "application/json"
152
+ };
153
+ if (xsrfToken) {
154
+ headers["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
155
+ }
156
+ const response = await fetch(`${config.apiUrl}/api/sso/user`, {
157
+ headers,
158
+ credentials: "include"
159
+ });
160
+ if (!response.ok) {
161
+ return null;
162
+ }
163
+ const data = await response.json();
164
+ const transformedUser = transformUser(data.user);
165
+ const transformedOrgs = transformOrganizations(data.organizations);
166
+ return { user: transformedUser, organizations: transformedOrgs };
167
+ } catch {
168
+ return null;
169
+ }
170
+ }, [config.apiUrl]);
171
+ (0, import_react2.useEffect)(() => {
172
+ let mounted = true;
173
+ const init = async () => {
174
+ setIsLoading(true);
175
+ const result = await fetchUser();
176
+ if (!mounted) return;
177
+ if (result) {
178
+ setUser(result.user);
179
+ setOrganizations(result.organizations);
180
+ const selectedOrg = loadSelectedOrg(result.organizations);
181
+ setCurrentOrg(selectedOrg);
182
+ onAuthChange?.(true, result.user);
183
+ } else {
184
+ setUser(null);
185
+ setOrganizations([]);
186
+ setCurrentOrg(null);
187
+ onAuthChange?.(false, null);
188
+ }
189
+ setIsLoading(false);
190
+ };
191
+ init();
192
+ return () => {
193
+ mounted = false;
194
+ };
195
+ }, [fetchUser, loadSelectedOrg, onAuthChange]);
196
+ const login = (0, import_react2.useCallback)(
197
+ (redirectTo) => {
198
+ const callbackUrl = new URL("/sso/callback", window.location.origin);
199
+ if (redirectTo) {
200
+ callbackUrl.searchParams.set("redirect", redirectTo);
201
+ }
202
+ const loginUrl = new URL("/sso/authorize", config.consoleUrl);
203
+ loginUrl.searchParams.set("service", config.serviceSlug);
204
+ loginUrl.searchParams.set("redirect_uri", callbackUrl.toString());
205
+ window.location.href = loginUrl.toString();
206
+ },
207
+ [config.consoleUrl, config.serviceSlug]
208
+ );
209
+ const logout = (0, import_react2.useCallback)(async () => {
210
+ try {
211
+ const xsrfToken = getXsrfToken();
212
+ const headers = {};
213
+ if (xsrfToken) {
214
+ headers["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
215
+ }
216
+ await fetch(`${config.apiUrl}/api/sso/logout`, {
217
+ method: "POST",
218
+ headers,
219
+ credentials: "include"
220
+ });
221
+ } catch {
222
+ }
223
+ setUser(null);
224
+ setOrganizations([]);
225
+ setCurrentOrg(null);
226
+ saveSelectedOrg(null);
227
+ onAuthChange?.(false, null);
228
+ }, [config.apiUrl, saveSelectedOrg, onAuthChange]);
229
+ const globalLogout = (0, import_react2.useCallback)(
230
+ async (redirectTo) => {
231
+ await logout();
232
+ const redirectUri = redirectTo ? new URL(redirectTo, window.location.origin).toString() : window.location.origin;
233
+ const logoutUrl = new URL("/sso/logout", config.consoleUrl);
234
+ logoutUrl.searchParams.set("redirect_uri", redirectUri);
235
+ window.location.href = logoutUrl.toString();
236
+ },
237
+ [logout, config.consoleUrl]
238
+ );
239
+ const switchOrg = (0, import_react2.useCallback)(
240
+ (orgId) => {
241
+ const org = organizations.find((o) => o.slug === orgId);
242
+ if (org) {
243
+ setCurrentOrg(org);
244
+ saveSelectedOrg(org);
245
+ }
246
+ },
247
+ [organizations, saveSelectedOrg]
248
+ );
249
+ const refreshUser = (0, import_react2.useCallback)(async () => {
250
+ const result = await fetchUser();
251
+ if (result) {
252
+ setUser(result.user);
253
+ setOrganizations(result.organizations);
254
+ if (currentOrg) {
255
+ const stillValid = result.organizations.find((o) => o.slug === currentOrg.slug);
256
+ if (!stillValid) {
257
+ const newOrg = loadSelectedOrg(result.organizations);
258
+ setCurrentOrg(newOrg);
259
+ }
260
+ }
261
+ }
262
+ }, [fetchUser, currentOrg, loadSelectedOrg]);
263
+ const getHeaders = (0, import_react2.useCallback)(() => {
264
+ const headers = {};
265
+ if (currentOrg) {
266
+ headers["X-Organization-Id"] = currentOrg.slug;
267
+ }
268
+ return headers;
269
+ }, [currentOrg]);
270
+ const value = (0, import_react2.useMemo)(
271
+ () => ({
272
+ user,
273
+ organizations,
274
+ currentOrg,
275
+ isLoading,
276
+ isAuthenticated: !!user,
277
+ config,
278
+ login,
279
+ logout,
280
+ globalLogout,
281
+ switchOrg,
282
+ refreshUser,
283
+ getHeaders
284
+ }),
285
+ [
286
+ user,
287
+ organizations,
288
+ currentOrg,
289
+ isLoading,
290
+ config,
291
+ login,
292
+ logout,
293
+ globalLogout,
294
+ switchOrg,
295
+ refreshUser,
296
+ getHeaders
297
+ ]
298
+ );
299
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SsoContext.Provider, { value, children });
300
+ }
301
+
302
+ // src/core/context/BranchContext.tsx
303
+ var import_react3 = require("react");
304
+ var BranchContext = (0, import_react3.createContext)(null);
305
+ function useBranchContext() {
306
+ const context = (0, import_react3.useContext)(BranchContext);
307
+ if (!context) {
308
+ throw new Error("useBranchContext must be used within a BranchProvider");
309
+ }
310
+ return context;
311
+ }
312
+
313
+ // src/core/context/BranchProvider.tsx
314
+ var import_react4 = require("react");
315
+ var import_react_query = require("@tanstack/react-query");
316
+
317
+ // src/core/services/utils.ts
318
+ function getXsrfToken2() {
319
+ if (typeof document === "undefined") return void 0;
320
+ return document.cookie.split("; ").find((row) => row.startsWith("XSRF-TOKEN="))?.split("=")[1];
321
+ }
322
+ function buildHeaders(orgId) {
323
+ const headers = {
324
+ "Content-Type": "application/json",
325
+ Accept: "application/json"
326
+ };
327
+ const xsrfToken = getXsrfToken2();
328
+ if (xsrfToken) {
329
+ headers["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
330
+ }
331
+ if (orgId) {
332
+ headers["X-Organization-Id"] = orgId;
333
+ }
334
+ return headers;
335
+ }
336
+ async function csrf(apiUrl) {
337
+ await fetch(`${apiUrl}/sanctum/csrf-cookie`, {
338
+ credentials: "include"
339
+ });
340
+ }
341
+ async function request(apiUrl, path, options = {}) {
342
+ const response = await fetch(`${apiUrl}${path}`, {
343
+ ...options,
344
+ credentials: "include"
345
+ });
346
+ if (!response.ok) {
347
+ const error = await response.json().catch(() => ({}));
348
+ throw new Error(error.message || `HTTP ${response.status}`);
349
+ }
350
+ if (response.status === 204) {
351
+ return void 0;
352
+ }
353
+ return response.json();
354
+ }
355
+
356
+ // src/core/services/branchService.ts
357
+ function createBranchService(config) {
358
+ const { apiUrl } = config;
359
+ return {
360
+ /**
361
+ * Get branches for current user in organization
362
+ * GET /api/sso/branches
363
+ * @param orgId - Organization ID or slug (sent via X-Organization-Id header)
364
+ */
365
+ list: async (orgId) => {
366
+ return request(apiUrl, `/api/sso/branches`, {
367
+ headers: buildHeaders(orgId)
368
+ });
369
+ },
370
+ /**
371
+ * Get a specific branch by ID
372
+ * GET /api/sso/branches/{id}
373
+ */
374
+ get: async (branchId) => {
375
+ const response = await request(
376
+ apiUrl,
377
+ `/api/sso/branches/${branchId}`,
378
+ { headers: buildHeaders() }
379
+ );
380
+ return "data" in response ? response.data : response;
381
+ },
382
+ /**
383
+ * Get headquarters branch for organization
384
+ * @param orgId - Organization ID or slug (sent via X-Organization-Id header)
385
+ */
386
+ getHeadquarters: async (orgId) => {
387
+ try {
388
+ const data = await request(
389
+ apiUrl,
390
+ `/api/sso/branches`,
391
+ { headers: buildHeaders(orgId) }
392
+ );
393
+ return data.branches.find((b) => b.is_headquarters) ?? null;
394
+ } catch {
395
+ return null;
396
+ }
397
+ },
398
+ /**
399
+ * Get primary branch for current user
400
+ * @param orgId - Organization ID or slug (sent via X-Organization-Id header)
401
+ */
402
+ getPrimary: async (orgId) => {
403
+ try {
404
+ const data = await request(
405
+ apiUrl,
406
+ `/api/sso/branches`,
407
+ { headers: buildHeaders(orgId) }
408
+ );
409
+ if (data.primary_branch_id) {
410
+ return data.branches.find((b) => b.id === data.primary_branch_id) ?? null;
411
+ }
412
+ return null;
413
+ } catch {
414
+ return null;
415
+ }
416
+ }
417
+ };
418
+ }
419
+
420
+ // src/core/queryKeys.ts
421
+ var ssoQueryKeys = {
422
+ all: ["sso"],
423
+ // =========================================================================
424
+ // Auth (authService)
425
+ // =========================================================================
426
+ auth: {
427
+ all: () => [...ssoQueryKeys.all, "auth"],
428
+ user: () => [...ssoQueryKeys.auth.all(), "user"],
429
+ globalLogoutUrl: (redirectUri) => [...ssoQueryKeys.auth.all(), "global-logout-url", redirectUri]
430
+ },
431
+ // =========================================================================
432
+ // Tokens (tokenService)
433
+ // =========================================================================
434
+ tokens: {
435
+ all: () => [...ssoQueryKeys.all, "tokens"],
436
+ list: () => [...ssoQueryKeys.tokens.all(), "list"]
437
+ },
438
+ // =========================================================================
439
+ // Roles (roleService)
440
+ // =========================================================================
441
+ roles: {
442
+ all: () => [...ssoQueryKeys.all, "roles"],
443
+ list: () => [...ssoQueryKeys.roles.all(), "list"],
444
+ detail: (id) => [...ssoQueryKeys.roles.all(), "detail", id],
445
+ permissions: (id) => [...ssoQueryKeys.roles.all(), id, "permissions"]
446
+ },
447
+ // =========================================================================
448
+ // Permissions (permissionService)
449
+ // =========================================================================
450
+ permissions: {
451
+ all: () => [...ssoQueryKeys.all, "permissions"],
452
+ list: (params) => [...ssoQueryKeys.permissions.all(), "list", params],
453
+ detail: (id) => [...ssoQueryKeys.permissions.all(), "detail", id],
454
+ matrix: () => [...ssoQueryKeys.permissions.all(), "matrix"]
455
+ },
456
+ // =========================================================================
457
+ // Teams (teamService)
458
+ // =========================================================================
459
+ teams: {
460
+ all: () => [...ssoQueryKeys.all, "teams"],
461
+ list: () => [...ssoQueryKeys.teams.all(), "list"],
462
+ permissions: (teamId) => [...ssoQueryKeys.teams.all(), teamId, "permissions"],
463
+ orphaned: () => [...ssoQueryKeys.teams.all(), "orphaned"]
464
+ },
465
+ // =========================================================================
466
+ // User Roles (userRoleService) - Scoped Role Assignments
467
+ // =========================================================================
468
+ userRoles: {
469
+ all: () => [...ssoQueryKeys.all, "user-roles"],
470
+ list: (userId) => [...ssoQueryKeys.userRoles.all(), userId],
471
+ byBranch: (userId, orgId, branchId) => [...ssoQueryKeys.userRoles.all(), userId, orgId, branchId]
472
+ },
473
+ // =========================================================================
474
+ // Branches (branchService)
475
+ // =========================================================================
476
+ branches: {
477
+ all: () => [...ssoQueryKeys.all, "branches"],
478
+ list: (orgId) => [...ssoQueryKeys.branches.all(), "list", orgId],
479
+ detail: (branchId) => [...ssoQueryKeys.branches.all(), "detail", branchId],
480
+ headquarters: (orgId) => [...ssoQueryKeys.branches.all(), "headquarters", orgId],
481
+ primary: (orgId) => [...ssoQueryKeys.branches.all(), "primary", orgId]
482
+ },
483
+ // =========================================================================
484
+ // Admin variants (with org context)
485
+ // =========================================================================
486
+ admin: {
487
+ roles: {
488
+ all: (orgId) => [...ssoQueryKeys.all, "admin", orgId, "roles"],
489
+ list: (orgId) => [...ssoQueryKeys.admin.roles.all(orgId), "list"],
490
+ detail: (orgId, id) => [...ssoQueryKeys.admin.roles.all(orgId), "detail", id],
491
+ permissions: (orgId, id) => [...ssoQueryKeys.admin.roles.all(orgId), id, "permissions"]
492
+ },
493
+ permissions: {
494
+ all: (orgId) => [...ssoQueryKeys.all, "admin", orgId, "permissions"],
495
+ list: (orgId, params) => [...ssoQueryKeys.admin.permissions.all(orgId), "list", params],
496
+ detail: (orgId, id) => [...ssoQueryKeys.admin.permissions.all(orgId), "detail", id],
497
+ matrix: (orgId) => [...ssoQueryKeys.admin.permissions.all(orgId), "matrix"]
498
+ },
499
+ teams: {
500
+ all: (orgId) => [...ssoQueryKeys.all, "admin", orgId, "teams"],
501
+ list: (orgId) => [...ssoQueryKeys.admin.teams.all(orgId), "list"],
502
+ permissions: (orgId, teamId) => [...ssoQueryKeys.admin.teams.all(orgId), teamId, "permissions"],
503
+ orphaned: (orgId) => [...ssoQueryKeys.admin.teams.all(orgId), "orphaned"]
504
+ },
505
+ userRoles: {
506
+ all: (orgId) => [...ssoQueryKeys.all, "admin", orgId, "user-roles"],
507
+ list: (orgId, userId) => [...ssoQueryKeys.admin.userRoles.all(orgId), userId],
508
+ byBranch: (orgId, userId, consoleOrgId, branchId) => [...ssoQueryKeys.admin.userRoles.all(orgId), userId, consoleOrgId, branchId]
509
+ },
510
+ users: {
511
+ all: (orgId) => [...ssoQueryKeys.all, "admin", orgId, "users"],
512
+ list: (orgId, params) => [...ssoQueryKeys.admin.users.all(orgId), "list", params],
513
+ detail: (orgId, id) => [...ssoQueryKeys.admin.users.all(orgId), "detail", id],
514
+ permissions: (orgId, userId, consoleOrgId, branchId) => [...ssoQueryKeys.admin.users.all(orgId), userId, "permissions", consoleOrgId, branchId]
515
+ }
516
+ }
517
+ };
518
+
519
+ // src/core/context/BranchProvider.tsx
520
+ var import_jsx_runtime2 = require("react/jsx-runtime");
521
+ var DEFAULT_STORAGE_KEY = "omnify_selected_branch";
522
+ function BranchProvider({
523
+ children,
524
+ storage = "localStorage",
525
+ storageKey = DEFAULT_STORAGE_KEY,
526
+ onBranchChange
527
+ }) {
528
+ const { config, currentOrg, isAuthenticated } = useSsoContext();
529
+ const queryClient = (0, import_react_query.useQueryClient)();
530
+ const branchService = (0, import_react4.useMemo)(
531
+ () => createBranchService({ apiUrl: config.apiUrl }),
532
+ [config.apiUrl]
533
+ );
534
+ const getSavedBranchId = (0, import_react4.useCallback)(() => {
535
+ if (typeof window === "undefined") return null;
536
+ const storageObj = storage === "localStorage" ? localStorage : sessionStorage;
537
+ const saved = storageObj.getItem(`${storageKey}_${currentOrg?.slug}`);
538
+ return saved ? parseInt(saved, 10) : null;
539
+ }, [storage, storageKey, currentOrg?.slug]);
540
+ const saveBranchId = (0, import_react4.useCallback)((branchId) => {
541
+ if (typeof window === "undefined" || !currentOrg?.slug) return;
542
+ const storageObj = storage === "localStorage" ? localStorage : sessionStorage;
543
+ if (branchId) {
544
+ storageObj.setItem(`${storageKey}_${currentOrg.slug}`, String(branchId));
545
+ } else {
546
+ storageObj.removeItem(`${storageKey}_${currentOrg.slug}`);
547
+ }
548
+ }, [storage, storageKey, currentOrg?.slug]);
549
+ const [selectedBranchId, setSelectedBranchId] = (0, import_react4.useState)(() => getSavedBranchId());
550
+ const {
551
+ data: branchesData,
552
+ isLoading,
553
+ error,
554
+ refetch
555
+ } = (0, import_react_query.useQuery)({
556
+ queryKey: ssoQueryKeys.branches.list(currentOrg?.slug),
557
+ queryFn: () => branchService.list(currentOrg?.slug),
558
+ enabled: isAuthenticated && !!currentOrg,
559
+ staleTime: 5 * 60 * 1e3
560
+ // 5 minutes
561
+ });
562
+ const branches = branchesData?.branches ?? [];
563
+ const allBranchesAccess = branchesData?.all_branches_access ?? false;
564
+ const primaryBranchId = branchesData?.primary_branch_id ?? null;
565
+ const hasMultipleBranches = branches.length > 1;
566
+ const currentBranch = (0, import_react4.useMemo)(() => {
567
+ if (!branches.length) return null;
568
+ if (branches.length === 1) {
569
+ return branches[0];
570
+ }
571
+ if (selectedBranchId) {
572
+ const found = branches.find((b) => b.id === selectedBranchId);
573
+ if (found) return found;
574
+ }
575
+ if (primaryBranchId) {
576
+ const primary = branches.find((b) => b.id === primaryBranchId);
577
+ if (primary) return primary;
578
+ }
579
+ const hq = branches.find((b) => b.is_headquarters);
580
+ if (hq) return hq;
581
+ return branches[0];
582
+ }, [branches, selectedBranchId, primaryBranchId]);
583
+ (0, import_react4.useEffect)(() => {
584
+ if (currentBranch && currentBranch.id !== selectedBranchId) {
585
+ setSelectedBranchId(currentBranch.id);
586
+ saveBranchId(currentBranch.id);
587
+ onBranchChange?.(currentBranch);
588
+ }
589
+ }, [currentBranch, selectedBranchId, saveBranchId, onBranchChange]);
590
+ (0, import_react4.useEffect)(() => {
591
+ const savedId = getSavedBranchId();
592
+ setSelectedBranchId(savedId);
593
+ }, [currentOrg?.slug, getSavedBranchId]);
594
+ const switchBranch = (0, import_react4.useCallback)((branchId) => {
595
+ const branch = branches.find((b) => b.id === branchId);
596
+ if (branch) {
597
+ setSelectedBranchId(branchId);
598
+ saveBranchId(branchId);
599
+ onBranchChange?.(branch);
600
+ }
601
+ }, [branches, saveBranchId, onBranchChange]);
602
+ const refreshBranches = (0, import_react4.useCallback)(async () => {
603
+ await queryClient.invalidateQueries({
604
+ queryKey: ssoQueryKeys.branches.list(currentOrg?.slug)
605
+ });
606
+ await refetch();
607
+ }, [queryClient, currentOrg?.slug, refetch]);
608
+ const contextValue = (0, import_react4.useMemo)(
609
+ () => ({
610
+ branches,
611
+ currentBranch,
612
+ allBranchesAccess,
613
+ primaryBranchId,
614
+ isLoading,
615
+ error,
616
+ hasMultipleBranches,
617
+ switchBranch,
618
+ refreshBranches
619
+ }),
620
+ [
621
+ branches,
622
+ currentBranch,
623
+ allBranchesAccess,
624
+ primaryBranchId,
625
+ isLoading,
626
+ error,
627
+ hasMultipleBranches,
628
+ switchBranch,
629
+ refreshBranches
630
+ ]
631
+ );
632
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BranchContext.Provider, { value: contextValue, children });
633
+ }
634
+
635
+ // src/core/hooks/useAuth.ts
636
+ var import_react5 = require("react");
637
+ function useAuth() {
638
+ const { user, isLoading, isAuthenticated, login, logout, globalLogout, refreshUser } = useSsoContext();
639
+ const handleLogin = (0, import_react5.useCallback)(
640
+ (redirectTo) => {
641
+ login(redirectTo);
642
+ },
643
+ [login]
644
+ );
645
+ const handleLogout = (0, import_react5.useCallback)(async () => {
646
+ await logout();
647
+ }, [logout]);
648
+ const handleGlobalLogout = (0, import_react5.useCallback)(
649
+ (redirectTo) => {
650
+ globalLogout(redirectTo);
651
+ },
652
+ [globalLogout]
653
+ );
654
+ return {
655
+ user,
656
+ isLoading,
657
+ isAuthenticated,
658
+ login: handleLogin,
659
+ logout: handleLogout,
660
+ globalLogout: handleGlobalLogout,
661
+ refreshUser
662
+ };
663
+ }
664
+
665
+ // src/core/hooks/useOrganization.ts
666
+ var import_react6 = require("react");
667
+ var ROLE_LEVELS = {
668
+ admin: 100,
669
+ manager: 50,
670
+ member: 10
671
+ };
672
+ function useOrganization() {
673
+ const { organizations, currentOrg, switchOrg } = useSsoContext();
674
+ const hasMultipleOrgs = organizations.length > 1;
675
+ const currentRole = currentOrg?.serviceRole ?? null;
676
+ const hasRole = (0, import_react6.useCallback)(
677
+ (role) => {
678
+ if (!currentRole) return false;
679
+ const requiredLevel = ROLE_LEVELS[role] ?? 0;
680
+ const userLevel = ROLE_LEVELS[currentRole] ?? 0;
681
+ return userLevel >= requiredLevel;
682
+ },
683
+ [currentRole]
684
+ );
685
+ const handleSwitchOrg = (0, import_react6.useCallback)(
686
+ (orgId) => {
687
+ switchOrg(orgId);
688
+ },
689
+ [switchOrg]
690
+ );
691
+ return (0, import_react6.useMemo)(
692
+ () => ({
693
+ organizations,
694
+ currentOrg,
695
+ hasMultipleOrgs,
696
+ switchOrg: handleSwitchOrg,
697
+ currentRole,
698
+ hasRole
699
+ }),
700
+ [organizations, currentOrg, hasMultipleOrgs, handleSwitchOrg, currentRole, hasRole]
701
+ );
702
+ }
703
+
704
+ // src/core/hooks/useSso.ts
705
+ var import_react7 = require("react");
706
+ function useSso() {
707
+ const context = useSsoContext();
708
+ return (0, import_react7.useMemo)(
709
+ () => ({
710
+ // Auth
711
+ user: context.user,
712
+ isLoading: context.isLoading,
713
+ isAuthenticated: context.isAuthenticated,
714
+ login: context.login,
715
+ logout: context.logout,
716
+ globalLogout: context.globalLogout,
717
+ refreshUser: context.refreshUser,
718
+ // Organization
719
+ organizations: context.organizations,
720
+ currentOrg: context.currentOrg,
721
+ hasMultipleOrgs: context.organizations.length > 1,
722
+ switchOrg: context.switchOrg,
723
+ // Utilities
724
+ getHeaders: context.getHeaders,
725
+ config: context.config
726
+ }),
727
+ [context]
728
+ );
729
+ }
730
+
731
+ // src/core/hooks/useBranch.ts
732
+ function useBranch() {
733
+ return useBranchContext();
734
+ }
735
+
736
+ // src/core/services/authService.ts
737
+ function createAuthService(config) {
738
+ const { apiUrl } = config;
739
+ return {
740
+ /**
741
+ * Exchange SSO authorization code for tokens
742
+ * POST /api/sso/callback
743
+ */
744
+ callback: async (input) => {
745
+ await csrf(apiUrl);
746
+ return request(apiUrl, "/api/sso/callback", {
747
+ method: "POST",
748
+ headers: buildHeaders(),
749
+ body: JSON.stringify(input)
750
+ });
751
+ },
752
+ /**
753
+ * Logout current user and revoke tokens
754
+ * POST /api/sso/logout
755
+ */
756
+ logout: async () => {
757
+ return request(apiUrl, "/api/sso/logout", {
758
+ method: "POST",
759
+ headers: buildHeaders()
760
+ });
761
+ },
762
+ /**
763
+ * Get current authenticated user with organizations
764
+ * GET /api/sso/user
765
+ */
766
+ getUser: async () => {
767
+ return request(apiUrl, "/api/sso/user", {
768
+ headers: buildHeaders()
769
+ });
770
+ },
771
+ /**
772
+ * Get Console SSO global logout URL
773
+ * GET /api/sso/global-logout-url
774
+ */
775
+ getGlobalLogoutUrl: async (redirectUri) => {
776
+ const params = redirectUri ? `?redirect_uri=${encodeURIComponent(redirectUri)}` : "";
777
+ return request(apiUrl, `/api/sso/global-logout-url${params}`, {
778
+ headers: buildHeaders()
779
+ });
780
+ }
781
+ };
782
+ }
783
+
784
+ // src/core/services/tokenService.ts
785
+ function createTokenService(config) {
786
+ const { apiUrl } = config;
787
+ return {
788
+ /**
789
+ * List all API tokens for current user
790
+ * GET /api/sso/tokens
791
+ */
792
+ list: async () => {
793
+ return request(apiUrl, "/api/sso/tokens", {
794
+ headers: buildHeaders()
795
+ });
796
+ },
797
+ /**
798
+ * Revoke a specific token
799
+ * DELETE /api/sso/tokens/{tokenId}
800
+ */
801
+ revoke: async (tokenId) => {
802
+ return request(apiUrl, `/api/sso/tokens/${tokenId}`, {
803
+ method: "DELETE",
804
+ headers: buildHeaders()
805
+ });
806
+ },
807
+ /**
808
+ * Revoke all tokens except current
809
+ * POST /api/sso/tokens/revoke-others
810
+ */
811
+ revokeOthers: async () => {
812
+ return request(apiUrl, "/api/sso/tokens/revoke-others", {
813
+ method: "POST",
814
+ headers: buildHeaders()
815
+ });
816
+ }
817
+ };
818
+ }
819
+
820
+ // src/core/services/roleService.ts
821
+ function createRoleService(config) {
822
+ const { apiUrl } = config;
823
+ return {
824
+ // =========================================================================
825
+ // Read-only endpoints (authenticated users)
826
+ // =========================================================================
827
+ /**
828
+ * Get all roles
829
+ * GET /api/sso/roles
830
+ */
831
+ list: async () => {
832
+ return request(apiUrl, "/api/sso/roles", {
833
+ headers: buildHeaders()
834
+ });
835
+ },
836
+ /**
837
+ * Get single role with permissions
838
+ * GET /api/sso/roles/{id}
839
+ */
840
+ get: async (id) => {
841
+ return request(apiUrl, `/api/sso/roles/${id}`, {
842
+ headers: buildHeaders()
843
+ });
844
+ },
845
+ // =========================================================================
846
+ // Admin endpoints (requires admin role + org context)
847
+ // =========================================================================
848
+ /**
849
+ * List all roles (admin)
850
+ * GET /api/admin/sso/roles
851
+ */
852
+ adminList: async (orgId, params) => {
853
+ const queryParams = new URLSearchParams();
854
+ if (params) {
855
+ Object.entries(params).forEach(([key, value]) => {
856
+ if (value !== void 0 && value !== null) {
857
+ queryParams.append(key, String(value));
858
+ }
859
+ });
860
+ }
861
+ const query = queryParams.toString();
862
+ const url = `/api/admin/sso/roles${query ? `?${query}` : ""}`;
863
+ return request(apiUrl, url, {
864
+ headers: buildHeaders(orgId)
865
+ });
866
+ },
867
+ /**
868
+ * Get single role (admin)
869
+ * GET /api/admin/sso/roles/{id}
870
+ */
871
+ adminGet: async (id, orgId) => {
872
+ return request(apiUrl, `/api/admin/sso/roles/${id}`, {
873
+ headers: buildHeaders(orgId)
874
+ });
875
+ },
876
+ /**
877
+ * Create role (admin only)
878
+ * POST /api/admin/sso/roles
879
+ */
880
+ create: async (input, orgId) => {
881
+ return request(apiUrl, "/api/admin/sso/roles", {
882
+ method: "POST",
883
+ headers: buildHeaders(orgId),
884
+ body: JSON.stringify(input)
885
+ });
886
+ },
887
+ /**
888
+ * Update role (admin only)
889
+ * PUT /api/admin/sso/roles/{id}
890
+ */
891
+ update: async (id, input, orgId) => {
892
+ return request(apiUrl, `/api/admin/sso/roles/${id}`, {
893
+ method: "PUT",
894
+ headers: buildHeaders(orgId),
895
+ body: JSON.stringify(input)
896
+ });
897
+ },
898
+ /**
899
+ * Delete role (admin only)
900
+ * DELETE /api/admin/sso/roles/{id}
901
+ */
902
+ delete: async (id, orgId) => {
903
+ return request(apiUrl, `/api/admin/sso/roles/${id}`, {
904
+ method: "DELETE",
905
+ headers: buildHeaders(orgId)
906
+ });
907
+ },
908
+ /**
909
+ * Get role's permissions (admin)
910
+ * GET /api/admin/sso/roles/{id}/permissions
911
+ */
912
+ getPermissions: async (id, orgId) => {
913
+ return request(apiUrl, `/api/admin/sso/roles/${id}/permissions`, {
914
+ headers: buildHeaders(orgId)
915
+ });
916
+ },
917
+ /**
918
+ * Sync role's permissions (admin)
919
+ * PUT /api/admin/sso/roles/{id}/permissions
920
+ */
921
+ syncPermissions: async (id, input, orgId) => {
922
+ return request(apiUrl, `/api/admin/sso/roles/${id}/permissions`, {
923
+ method: "PUT",
924
+ headers: buildHeaders(orgId),
925
+ body: JSON.stringify(input)
926
+ });
927
+ }
928
+ };
929
+ }
930
+
931
+ // src/core/services/permissionService.ts
932
+ function createPermissionService(config) {
933
+ const { apiUrl } = config;
934
+ return {
935
+ // =========================================================================
936
+ // Read-only endpoints (authenticated users)
937
+ // =========================================================================
938
+ /**
939
+ * Get all permissions
940
+ * GET /api/sso/permissions
941
+ */
942
+ list: async (params) => {
943
+ const queryString = params ? `?${new URLSearchParams(
944
+ Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => [k, String(v)])
945
+ )}` : "";
946
+ return request(apiUrl, `/api/sso/permissions${queryString}`, {
947
+ headers: buildHeaders()
948
+ });
949
+ },
950
+ /**
951
+ * Get permission matrix (roles x permissions)
952
+ * GET /api/sso/permission-matrix
953
+ */
954
+ getMatrix: async () => {
955
+ return request(apiUrl, "/api/sso/permission-matrix", {
956
+ headers: buildHeaders()
957
+ });
958
+ },
959
+ // =========================================================================
960
+ // Admin endpoints (requires admin role + org context)
961
+ // =========================================================================
962
+ /**
963
+ * List all permissions (admin)
964
+ * GET /api/admin/sso/permissions
965
+ */
966
+ adminList: async (orgId, params) => {
967
+ const queryString = params ? `?${new URLSearchParams(
968
+ Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => [k, String(v)])
969
+ )}` : "";
970
+ return request(apiUrl, `/api/admin/sso/permissions${queryString}`, {
971
+ headers: buildHeaders(orgId)
972
+ });
973
+ },
974
+ /**
975
+ * Get single permission (admin)
976
+ * GET /api/admin/sso/permissions/{id}
977
+ */
978
+ adminGet: async (id, orgId) => {
979
+ return request(apiUrl, `/api/admin/sso/permissions/${id}`, {
980
+ headers: buildHeaders(orgId)
981
+ });
982
+ },
983
+ /**
984
+ * Create permission (admin only)
985
+ * POST /api/admin/sso/permissions
986
+ */
987
+ create: async (input, orgId) => {
988
+ return request(apiUrl, "/api/admin/sso/permissions", {
989
+ method: "POST",
990
+ headers: buildHeaders(orgId),
991
+ body: JSON.stringify(input)
992
+ });
993
+ },
994
+ /**
995
+ * Update permission (admin only)
996
+ * PUT /api/admin/sso/permissions/{id}
997
+ */
998
+ update: async (id, input, orgId) => {
999
+ return request(apiUrl, `/api/admin/sso/permissions/${id}`, {
1000
+ method: "PUT",
1001
+ headers: buildHeaders(orgId),
1002
+ body: JSON.stringify(input)
1003
+ });
1004
+ },
1005
+ /**
1006
+ * Delete permission (admin only)
1007
+ * DELETE /api/admin/sso/permissions/{id}
1008
+ */
1009
+ delete: async (id, orgId) => {
1010
+ return request(apiUrl, `/api/admin/sso/permissions/${id}`, {
1011
+ method: "DELETE",
1012
+ headers: buildHeaders(orgId)
1013
+ });
1014
+ },
1015
+ /**
1016
+ * Get permission matrix (admin)
1017
+ * GET /api/admin/sso/permission-matrix
1018
+ */
1019
+ adminGetMatrix: async (orgId) => {
1020
+ return request(apiUrl, "/api/admin/sso/permission-matrix", {
1021
+ headers: buildHeaders(orgId)
1022
+ });
1023
+ }
1024
+ };
1025
+ }
1026
+
1027
+ // src/core/services/teamService.ts
1028
+ function createTeamService(config) {
1029
+ const { apiUrl } = config;
1030
+ return {
1031
+ /**
1032
+ * Get all teams with their permissions (admin only)
1033
+ * GET /api/admin/sso/teams/permissions
1034
+ */
1035
+ list: async (orgId) => {
1036
+ return request(apiUrl, "/api/admin/sso/teams/permissions", {
1037
+ headers: buildHeaders(orgId)
1038
+ });
1039
+ },
1040
+ /**
1041
+ * Get specific team permissions (admin only)
1042
+ * GET /api/admin/sso/teams/{teamId}/permissions
1043
+ */
1044
+ getPermissions: async (teamId, orgId) => {
1045
+ return request(apiUrl, `/api/admin/sso/teams/${teamId}/permissions`, {
1046
+ headers: buildHeaders(orgId)
1047
+ });
1048
+ },
1049
+ /**
1050
+ * Sync team permissions (admin only)
1051
+ * PUT /api/admin/sso/teams/{teamId}/permissions
1052
+ */
1053
+ syncPermissions: async (teamId, input, orgId) => {
1054
+ return request(apiUrl, `/api/admin/sso/teams/${teamId}/permissions`, {
1055
+ method: "PUT",
1056
+ headers: buildHeaders(orgId),
1057
+ body: JSON.stringify(input)
1058
+ });
1059
+ },
1060
+ /**
1061
+ * Remove all permissions for a team (admin only)
1062
+ * DELETE /api/admin/sso/teams/{teamId}/permissions
1063
+ */
1064
+ removePermissions: async (teamId, orgId) => {
1065
+ return request(apiUrl, `/api/admin/sso/teams/${teamId}/permissions`, {
1066
+ method: "DELETE",
1067
+ headers: buildHeaders(orgId)
1068
+ });
1069
+ },
1070
+ /**
1071
+ * List orphaned team permissions (admin only)
1072
+ * GET /api/admin/sso/teams/orphaned
1073
+ */
1074
+ listOrphaned: async (orgId) => {
1075
+ return request(apiUrl, "/api/admin/sso/teams/orphaned", {
1076
+ headers: buildHeaders(orgId)
1077
+ });
1078
+ },
1079
+ /**
1080
+ * Restore orphaned team permissions (admin only)
1081
+ * POST /api/admin/sso/teams/orphaned/{teamId}/restore
1082
+ */
1083
+ restoreOrphaned: async (teamId, orgId) => {
1084
+ return request(apiUrl, `/api/admin/sso/teams/orphaned/${teamId}/restore`, {
1085
+ method: "POST",
1086
+ headers: buildHeaders(orgId)
1087
+ });
1088
+ },
1089
+ /**
1090
+ * Cleanup orphaned team permissions (admin only)
1091
+ * DELETE /api/admin/sso/teams/orphaned
1092
+ */
1093
+ cleanupOrphaned: async (orgId, input) => {
1094
+ return request(apiUrl, "/api/admin/sso/teams/orphaned", {
1095
+ method: "DELETE",
1096
+ headers: buildHeaders(orgId),
1097
+ body: input ? JSON.stringify(input) : void 0
1098
+ });
1099
+ }
1100
+ };
1101
+ }
1102
+
1103
+ // src/core/services/userRoleService.ts
1104
+ function createUserRoleService(config) {
1105
+ const { apiUrl } = config;
1106
+ return {
1107
+ /**
1108
+ * List user's role assignments with scope information
1109
+ * GET /api/admin/sso/users/{userId}/roles
1110
+ */
1111
+ list: async (userId, orgId) => {
1112
+ const response = await request(
1113
+ apiUrl,
1114
+ `/api/admin/sso/users/${userId}/roles`,
1115
+ { headers: buildHeaders(orgId) }
1116
+ );
1117
+ return response.data;
1118
+ },
1119
+ /**
1120
+ * List user's role assignments filtered by branch context
1121
+ * Returns roles applicable to the given org/branch
1122
+ */
1123
+ listByBranch: async (userId, consoleOrgId, branchId, orgId) => {
1124
+ const all = await request(
1125
+ apiUrl,
1126
+ `/api/admin/sso/users/${userId}/roles`,
1127
+ { headers: buildHeaders(orgId) }
1128
+ );
1129
+ return all.data.filter((a) => {
1130
+ if (a.console_org_id === null) return true;
1131
+ if (a.console_org_id !== consoleOrgId) return false;
1132
+ if (a.console_branch_id === null) return true;
1133
+ return a.console_branch_id === branchId;
1134
+ });
1135
+ },
1136
+ /**
1137
+ * Assign a role to user with scope
1138
+ * POST /api/admin/sso/users/{userId}/roles
1139
+ */
1140
+ assign: async (userId, input, orgId) => {
1141
+ return request(
1142
+ apiUrl,
1143
+ `/api/admin/sso/users/${userId}/roles`,
1144
+ {
1145
+ method: "POST",
1146
+ headers: buildHeaders(orgId),
1147
+ body: JSON.stringify(input)
1148
+ }
1149
+ );
1150
+ },
1151
+ /**
1152
+ * Remove a role assignment from user
1153
+ * DELETE /api/admin/sso/users/{userId}/roles/{roleId}
1154
+ */
1155
+ remove: async (userId, roleId, consoleOrgId, branchId, orgId) => {
1156
+ return request(
1157
+ apiUrl,
1158
+ `/api/admin/sso/users/${userId}/roles/${roleId}`,
1159
+ {
1160
+ method: "DELETE",
1161
+ headers: buildHeaders(orgId),
1162
+ body: JSON.stringify({
1163
+ console_org_id: consoleOrgId ?? null,
1164
+ console_branch_id: branchId ?? null
1165
+ })
1166
+ }
1167
+ );
1168
+ },
1169
+ /**
1170
+ * Sync roles for user in a specific scope
1171
+ * PUT /api/admin/sso/users/{userId}/roles/sync
1172
+ */
1173
+ sync: async (userId, input, orgId) => {
1174
+ return request(
1175
+ apiUrl,
1176
+ `/api/admin/sso/users/${userId}/roles/sync`,
1177
+ {
1178
+ method: "PUT",
1179
+ headers: buildHeaders(orgId),
1180
+ body: JSON.stringify(input)
1181
+ }
1182
+ );
1183
+ }
1184
+ };
1185
+ }
1186
+ var getScopeLabel = (scope, locale = "en") => {
1187
+ const labels = {
1188
+ global: { en: "Global", ja: "\u30B0\u30ED\u30FC\u30D0\u30EB", vi: "To\xE0n h\u1EC7 th\u1ED1ng" },
1189
+ "org-wide": { en: "Organization", ja: "\u7D44\u7E54\u5168\u4F53", vi: "To\xE0n t\u1ED5 ch\u1EE9c" },
1190
+ branch: { en: "Branch", ja: "\u652F\u5E97\u9650\u5B9A", vi: "Chi nh\xE1nh" }
1191
+ };
1192
+ return labels[scope][locale] || labels[scope]["en"];
1193
+ };
1194
+ var getEffectivePermissions = (roleAssignments, allRoles, orgId, branchId) => {
1195
+ const permissions = /* @__PURE__ */ new Set();
1196
+ const applicableAssignments = roleAssignments.filter((a) => {
1197
+ if (a.console_org_id === null) return true;
1198
+ if (a.console_org_id !== orgId) return false;
1199
+ if (a.console_branch_id === null) return true;
1200
+ return a.console_branch_id === branchId;
1201
+ });
1202
+ for (const assignment of applicableAssignments) {
1203
+ const role = allRoles.find((r) => r.id === assignment.role.id);
1204
+ if (role?.permissions) {
1205
+ for (const perm of role.permissions) {
1206
+ if (typeof perm === "string") {
1207
+ permissions.add(perm);
1208
+ } else if (perm.slug) {
1209
+ permissions.add(perm.slug);
1210
+ }
1211
+ }
1212
+ }
1213
+ }
1214
+ return Array.from(permissions);
1215
+ };
1216
+
1217
+ // src/core/services/userService.ts
1218
+ function createUserService(config) {
1219
+ const { apiUrl } = config;
1220
+ return {
1221
+ /**
1222
+ * List users with optional filters
1223
+ * GET /api/admin/sso/users
1224
+ */
1225
+ list: async (params, orgId) => {
1226
+ const queryParams = new URLSearchParams();
1227
+ if (params) {
1228
+ Object.entries(params).forEach(([key, value]) => {
1229
+ if (value !== void 0 && value !== null) {
1230
+ queryParams.append(key, String(value));
1231
+ }
1232
+ });
1233
+ }
1234
+ const query = queryParams.toString();
1235
+ const url = `/api/admin/sso/users${query ? `?${query}` : ""}`;
1236
+ return request(apiUrl, url, {
1237
+ headers: buildHeaders(orgId)
1238
+ });
1239
+ },
1240
+ /**
1241
+ * Get single user by ID
1242
+ * GET /api/admin/sso/users/{userId}
1243
+ */
1244
+ get: async (userId, orgId) => {
1245
+ const response = await request(
1246
+ apiUrl,
1247
+ `/api/admin/sso/users/${userId}`,
1248
+ { headers: buildHeaders(orgId) }
1249
+ );
1250
+ return response.data;
1251
+ },
1252
+ /**
1253
+ * Get user permissions breakdown for specific org/branch context
1254
+ * GET /api/admin/sso/users/{userId}/permissions
1255
+ */
1256
+ getPermissions: async (userId, consoleOrgId, branchId, orgId) => {
1257
+ const queryParams = new URLSearchParams();
1258
+ if (consoleOrgId) queryParams.append("org_id", consoleOrgId);
1259
+ if (branchId) queryParams.append("branch_id", branchId);
1260
+ const query = queryParams.toString();
1261
+ const url = `/api/admin/sso/users/${userId}/permissions${query ? `?${query}` : ""}`;
1262
+ return request(apiUrl, url, {
1263
+ headers: buildHeaders(orgId)
1264
+ });
1265
+ }
1266
+ };
1267
+ }
1268
+
1269
+ // src/core/services/ssoService.ts
1270
+ function getXsrfToken3() {
1271
+ if (typeof document === "undefined") return void 0;
1272
+ return document.cookie.split("; ").find((row) => row.startsWith("XSRF-TOKEN="))?.split("=")[1];
1273
+ }
1274
+ function buildHeaders2(orgId) {
1275
+ const headers = {
1276
+ "Content-Type": "application/json",
1277
+ Accept: "application/json"
1278
+ };
1279
+ const xsrfToken = getXsrfToken3();
1280
+ if (xsrfToken) {
1281
+ headers["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
1282
+ }
1283
+ if (orgId) {
1284
+ headers["X-Organization-Id"] = orgId;
1285
+ }
1286
+ return headers;
1287
+ }
1288
+ async function csrf2(apiUrl) {
1289
+ await fetch(`${apiUrl}/sanctum/csrf-cookie`, {
1290
+ credentials: "include"
1291
+ });
1292
+ }
1293
+ async function request2(apiUrl, path, options = {}) {
1294
+ const response = await fetch(`${apiUrl}${path}`, {
1295
+ ...options,
1296
+ credentials: "include"
1297
+ });
1298
+ if (!response.ok) {
1299
+ const error = await response.json().catch(() => ({}));
1300
+ throw new Error(error.message || `HTTP ${response.status}`);
1301
+ }
1302
+ if (response.status === 204) {
1303
+ return void 0;
1304
+ }
1305
+ return response.json();
1306
+ }
1307
+ function createSsoService(config) {
1308
+ const { apiUrl } = config;
1309
+ return {
1310
+ // =========================================================================
1311
+ // SSO Auth
1312
+ // =========================================================================
1313
+ /**
1314
+ * Exchange SSO authorization code for tokens
1315
+ * POST /api/sso/callback
1316
+ */
1317
+ callback: async (input) => {
1318
+ await csrf2(apiUrl);
1319
+ return request2(apiUrl, "/api/sso/callback", {
1320
+ method: "POST",
1321
+ headers: buildHeaders2(),
1322
+ body: JSON.stringify(input)
1323
+ });
1324
+ },
1325
+ /**
1326
+ * Logout current user and revoke tokens
1327
+ * POST /api/sso/logout
1328
+ */
1329
+ logout: async () => {
1330
+ return request2(apiUrl, "/api/sso/logout", {
1331
+ method: "POST",
1332
+ headers: buildHeaders2()
1333
+ });
1334
+ },
1335
+ /**
1336
+ * Get current authenticated user with organizations
1337
+ * GET /api/sso/user
1338
+ */
1339
+ getUser: async () => {
1340
+ return request2(apiUrl, "/api/sso/user", {
1341
+ headers: buildHeaders2()
1342
+ });
1343
+ },
1344
+ /**
1345
+ * Get Console SSO global logout URL
1346
+ * GET /api/sso/global-logout-url
1347
+ */
1348
+ getGlobalLogoutUrl: async (redirectUri) => {
1349
+ const params = redirectUri ? `?redirect_uri=${encodeURIComponent(redirectUri)}` : "";
1350
+ return request2(apiUrl, `/api/sso/global-logout-url${params}`, {
1351
+ headers: buildHeaders2()
1352
+ });
1353
+ },
1354
+ // =========================================================================
1355
+ // SSO Tokens (for mobile apps)
1356
+ // =========================================================================
1357
+ /**
1358
+ * List all API tokens for current user
1359
+ * GET /api/sso/tokens
1360
+ */
1361
+ getTokens: async () => {
1362
+ return request2(apiUrl, "/api/sso/tokens", {
1363
+ headers: buildHeaders2()
1364
+ });
1365
+ },
1366
+ /**
1367
+ * Revoke a specific token
1368
+ * DELETE /api/sso/tokens/{tokenId}
1369
+ */
1370
+ revokeToken: async (tokenId) => {
1371
+ return request2(apiUrl, `/api/sso/tokens/${tokenId}`, {
1372
+ method: "DELETE",
1373
+ headers: buildHeaders2()
1374
+ });
1375
+ },
1376
+ /**
1377
+ * Revoke all tokens except current
1378
+ * POST /api/sso/tokens/revoke-others
1379
+ */
1380
+ revokeOtherTokens: async () => {
1381
+ return request2(apiUrl, "/api/sso/tokens/revoke-others", {
1382
+ method: "POST",
1383
+ headers: buildHeaders2()
1384
+ });
1385
+ },
1386
+ // =========================================================================
1387
+ // Roles (Read-only for authenticated users)
1388
+ // =========================================================================
1389
+ /**
1390
+ * Get all roles
1391
+ * GET /api/sso/roles
1392
+ */
1393
+ getRoles: async () => {
1394
+ return request2(apiUrl, "/api/sso/roles", {
1395
+ headers: buildHeaders2()
1396
+ });
1397
+ },
1398
+ /**
1399
+ * Get single role with permissions
1400
+ * GET /api/sso/roles/{id}
1401
+ */
1402
+ getRole: async (id) => {
1403
+ return request2(apiUrl, `/api/sso/roles/${id}`, {
1404
+ headers: buildHeaders2()
1405
+ });
1406
+ },
1407
+ // =========================================================================
1408
+ // Permissions (Read-only for authenticated users)
1409
+ // =========================================================================
1410
+ /**
1411
+ * Get all permissions
1412
+ * GET /api/sso/permissions
1413
+ */
1414
+ getPermissions: async (params) => {
1415
+ const queryString = params ? `?${new URLSearchParams(
1416
+ Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => [k, String(v)])
1417
+ )}` : "";
1418
+ return request2(apiUrl, `/api/sso/permissions${queryString}`, {
1419
+ headers: buildHeaders2()
1420
+ });
1421
+ },
1422
+ /**
1423
+ * Get permission matrix (roles x permissions)
1424
+ * GET /api/sso/permission-matrix
1425
+ */
1426
+ getPermissionMatrix: async () => {
1427
+ return request2(apiUrl, "/api/sso/permission-matrix", {
1428
+ headers: buildHeaders2()
1429
+ });
1430
+ },
1431
+ // =========================================================================
1432
+ // Admin - Roles (requires admin role + org context)
1433
+ // =========================================================================
1434
+ /**
1435
+ * List all roles (admin)
1436
+ * GET /api/admin/sso/roles
1437
+ */
1438
+ adminGetRoles: async (orgId) => {
1439
+ return request2(apiUrl, "/api/admin/sso/roles", {
1440
+ headers: buildHeaders2(orgId)
1441
+ });
1442
+ },
1443
+ /**
1444
+ * Get single role (admin)
1445
+ * GET /api/admin/sso/roles/{id}
1446
+ */
1447
+ adminGetRole: async (id, orgId) => {
1448
+ return request2(apiUrl, `/api/admin/sso/roles/${id}`, {
1449
+ headers: buildHeaders2(orgId)
1450
+ });
1451
+ },
1452
+ /**
1453
+ * Create role (admin only)
1454
+ * POST /api/admin/sso/roles
1455
+ */
1456
+ createRole: async (input, orgId) => {
1457
+ return request2(apiUrl, "/api/admin/sso/roles", {
1458
+ method: "POST",
1459
+ headers: buildHeaders2(orgId),
1460
+ body: JSON.stringify(input)
1461
+ });
1462
+ },
1463
+ /**
1464
+ * Update role (admin only)
1465
+ * PUT /api/admin/sso/roles/{id}
1466
+ */
1467
+ updateRole: async (id, input, orgId) => {
1468
+ return request2(apiUrl, `/api/admin/sso/roles/${id}`, {
1469
+ method: "PUT",
1470
+ headers: buildHeaders2(orgId),
1471
+ body: JSON.stringify(input)
1472
+ });
1473
+ },
1474
+ /**
1475
+ * Delete role (admin only)
1476
+ * DELETE /api/admin/sso/roles/{id}
1477
+ */
1478
+ deleteRole: async (id, orgId) => {
1479
+ return request2(apiUrl, `/api/admin/sso/roles/${id}`, {
1480
+ method: "DELETE",
1481
+ headers: buildHeaders2(orgId)
1482
+ });
1483
+ },
1484
+ /**
1485
+ * Get role's permissions (admin)
1486
+ * GET /api/admin/sso/roles/{id}/permissions
1487
+ */
1488
+ getRolePermissions: async (id, orgId) => {
1489
+ return request2(apiUrl, `/api/admin/sso/roles/${id}/permissions`, {
1490
+ headers: buildHeaders2(orgId)
1491
+ });
1492
+ },
1493
+ /**
1494
+ * Sync role's permissions (admin)
1495
+ * PUT /api/admin/sso/roles/{id}/permissions
1496
+ */
1497
+ syncRolePermissions: async (id, input, orgId) => {
1498
+ return request2(apiUrl, `/api/admin/sso/roles/${id}/permissions`, {
1499
+ method: "PUT",
1500
+ headers: buildHeaders2(orgId),
1501
+ body: JSON.stringify(input)
1502
+ });
1503
+ },
1504
+ // =========================================================================
1505
+ // Admin - Permissions (requires admin role + org context)
1506
+ // =========================================================================
1507
+ /**
1508
+ * List all permissions (admin)
1509
+ * GET /api/admin/sso/permissions
1510
+ */
1511
+ adminGetPermissions: async (orgId, params) => {
1512
+ const queryString = params ? `?${new URLSearchParams(
1513
+ Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => [k, String(v)])
1514
+ )}` : "";
1515
+ return request2(apiUrl, `/api/admin/sso/permissions${queryString}`, {
1516
+ headers: buildHeaders2(orgId)
1517
+ });
1518
+ },
1519
+ /**
1520
+ * Get single permission (admin)
1521
+ * GET /api/admin/sso/permissions/{id}
1522
+ */
1523
+ adminGetPermission: async (id, orgId) => {
1524
+ return request2(apiUrl, `/api/admin/sso/permissions/${id}`, {
1525
+ headers: buildHeaders2(orgId)
1526
+ });
1527
+ },
1528
+ /**
1529
+ * Create permission (admin only)
1530
+ * POST /api/admin/sso/permissions
1531
+ */
1532
+ createPermission: async (input, orgId) => {
1533
+ return request2(apiUrl, "/api/admin/sso/permissions", {
1534
+ method: "POST",
1535
+ headers: buildHeaders2(orgId),
1536
+ body: JSON.stringify(input)
1537
+ });
1538
+ },
1539
+ /**
1540
+ * Update permission (admin only)
1541
+ * PUT /api/admin/sso/permissions/{id}
1542
+ */
1543
+ updatePermission: async (id, input, orgId) => {
1544
+ return request2(apiUrl, `/api/admin/sso/permissions/${id}`, {
1545
+ method: "PUT",
1546
+ headers: buildHeaders2(orgId),
1547
+ body: JSON.stringify(input)
1548
+ });
1549
+ },
1550
+ /**
1551
+ * Delete permission (admin only)
1552
+ * DELETE /api/admin/sso/permissions/{id}
1553
+ */
1554
+ deletePermission: async (id, orgId) => {
1555
+ return request2(apiUrl, `/api/admin/sso/permissions/${id}`, {
1556
+ method: "DELETE",
1557
+ headers: buildHeaders2(orgId)
1558
+ });
1559
+ },
1560
+ /**
1561
+ * Get permission matrix (admin)
1562
+ * GET /api/admin/sso/permission-matrix
1563
+ */
1564
+ adminGetPermissionMatrix: async (orgId) => {
1565
+ return request2(apiUrl, "/api/admin/sso/permission-matrix", {
1566
+ headers: buildHeaders2(orgId)
1567
+ });
1568
+ },
1569
+ // =========================================================================
1570
+ // Admin - Team Permissions (requires admin role + org context)
1571
+ // =========================================================================
1572
+ /**
1573
+ * Get all teams with their permissions (admin only)
1574
+ * GET /api/admin/sso/teams/permissions
1575
+ */
1576
+ getTeamPermissions: async (orgId) => {
1577
+ return request2(apiUrl, "/api/admin/sso/teams/permissions", {
1578
+ headers: buildHeaders2(orgId)
1579
+ });
1580
+ },
1581
+ /**
1582
+ * Get specific team permissions (admin only)
1583
+ * GET /api/admin/sso/teams/{teamId}/permissions
1584
+ */
1585
+ getTeamPermission: async (teamId, orgId) => {
1586
+ return request2(apiUrl, `/api/admin/sso/teams/${teamId}/permissions`, {
1587
+ headers: buildHeaders2(orgId)
1588
+ });
1589
+ },
1590
+ /**
1591
+ * Sync team permissions (admin only)
1592
+ * PUT /api/admin/sso/teams/{teamId}/permissions
1593
+ */
1594
+ syncTeamPermissions: async (teamId, input, orgId) => {
1595
+ return request2(apiUrl, `/api/admin/sso/teams/${teamId}/permissions`, {
1596
+ method: "PUT",
1597
+ headers: buildHeaders2(orgId),
1598
+ body: JSON.stringify(input)
1599
+ });
1600
+ },
1601
+ /**
1602
+ * Remove all permissions for a team (admin only)
1603
+ * DELETE /api/admin/sso/teams/{teamId}/permissions
1604
+ */
1605
+ removeTeamPermissions: async (teamId, orgId) => {
1606
+ return request2(apiUrl, `/api/admin/sso/teams/${teamId}/permissions`, {
1607
+ method: "DELETE",
1608
+ headers: buildHeaders2(orgId)
1609
+ });
1610
+ },
1611
+ // =========================================================================
1612
+ // Admin - Orphaned Team Permissions (requires admin role + org context)
1613
+ // =========================================================================
1614
+ /**
1615
+ * List orphaned team permissions (admin only)
1616
+ * GET /api/admin/sso/teams/orphaned
1617
+ */
1618
+ getOrphanedTeamPermissions: async (orgId) => {
1619
+ return request2(apiUrl, "/api/admin/sso/teams/orphaned", {
1620
+ headers: buildHeaders2(orgId)
1621
+ });
1622
+ },
1623
+ /**
1624
+ * Restore orphaned team permissions (admin only)
1625
+ * POST /api/admin/sso/teams/orphaned/{teamId}/restore
1626
+ */
1627
+ restoreOrphanedTeamPermissions: async (teamId, orgId) => {
1628
+ return request2(apiUrl, `/api/admin/sso/teams/orphaned/${teamId}/restore`, {
1629
+ method: "POST",
1630
+ headers: buildHeaders2(orgId)
1631
+ });
1632
+ },
1633
+ /**
1634
+ * Cleanup orphaned team permissions (admin only)
1635
+ * DELETE /api/admin/sso/teams/orphaned
1636
+ */
1637
+ cleanupOrphanedTeamPermissions: async (orgId, input) => {
1638
+ return request2(apiUrl, "/api/admin/sso/teams/orphaned", {
1639
+ method: "DELETE",
1640
+ headers: buildHeaders2(orgId),
1641
+ body: input ? JSON.stringify(input) : void 0
1642
+ });
1643
+ }
1644
+ };
1645
+ }
1646
+
1647
+ // src/core/utils/branchHeaders.ts
1648
+ var BRANCH_HEADERS = {
1649
+ BRANCH_ID: "X-Branch-Id",
1650
+ ORG_ID: "X-Organization-Id"
1651
+ };
1652
+ function createBranchHeaderSetter(axiosInstance) {
1653
+ return (selection) => {
1654
+ if (selection) {
1655
+ axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_ID] = selection.branchId;
1656
+ axiosInstance.defaults.headers.common[BRANCH_HEADERS.ORG_ID] = selection.orgId;
1657
+ } else {
1658
+ delete axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_ID];
1659
+ delete axiosInstance.defaults.headers.common[BRANCH_HEADERS.ORG_ID];
1660
+ }
1661
+ };
1662
+ }
1663
+ function setBranchHeaders(axiosInstance, selection) {
1664
+ createBranchHeaderSetter(axiosInstance)(selection);
1665
+ }
1666
+
1667
+ // src/core/i18n/index.tsx
1668
+ var import_react8 = require("react");
1669
+ var import_react_i18next = require("react-i18next");
1670
+ var import_i18next = __toESM(require("i18next"), 1);
1671
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1672
+ var locales = ["ja", "en", "vi"];
1673
+ var localeNames = {
1674
+ ja: "\u65E5\u672C\u8A9E",
1675
+ en: "English",
1676
+ vi: "Ti\u1EBFng Vi\u1EC7t"
1677
+ };
1678
+ var defaultLocale = "ja";
1679
+ var I18nContext = (0, import_react8.createContext)(null);
1680
+ var i18nInitialized = false;
1681
+ function initializeI18n(initialLocale, fallbackLocale2, translations) {
1682
+ if (i18nInitialized) {
1683
+ return import_i18next.default;
1684
+ }
1685
+ const resources = {};
1686
+ for (const locale of locales) {
1687
+ resources[locale] = {
1688
+ translation: {
1689
+ ...defaultTranslations[locale],
1690
+ ...translations?.[locale] || {}
1691
+ }
1692
+ };
1693
+ }
1694
+ import_i18next.default.use(import_react_i18next.initReactI18next).init({
1695
+ resources,
1696
+ lng: initialLocale,
1697
+ fallbackLng: fallbackLocale2,
1698
+ interpolation: {
1699
+ escapeValue: false
1700
+ },
1701
+ react: {
1702
+ useSuspense: false
1703
+ }
1704
+ });
1705
+ i18nInitialized = true;
1706
+ return import_i18next.default;
1707
+ }
1708
+ function I18nProvider({
1709
+ children,
1710
+ defaultLocale: initialLocale = "ja",
1711
+ fallbackLocale: fallbackLocale2 = "ja",
1712
+ translations
1713
+ }) {
1714
+ const i18nInstance = (0, import_react8.useMemo)(
1715
+ () => initializeI18n(initialLocale, fallbackLocale2, translations),
1716
+ [initialLocale, fallbackLocale2, translations]
1717
+ );
1718
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_i18next.I18nextProvider, { i18n: i18nInstance, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(I18nProviderInner, { initialLocale, children }) });
1719
+ }
1720
+ function I18nProviderInner({
1721
+ children,
1722
+ initialLocale
1723
+ }) {
1724
+ const [locale, setLocaleState] = (0, import_react8.useState)(initialLocale);
1725
+ const { t: translate, i18n: i18nInstance } = (0, import_react_i18next.useTranslation)();
1726
+ const setLocale = (0, import_react8.useCallback)((newLocale) => {
1727
+ setLocaleState(newLocale);
1728
+ i18nInstance?.changeLanguage(newLocale);
1729
+ if (typeof document !== "undefined") {
1730
+ document.cookie = `locale=${newLocale};path=/;max-age=31536000`;
1731
+ }
1732
+ }, [i18nInstance]);
1733
+ const t = (0, import_react8.useCallback)((key, options) => {
1734
+ return String(translate(key, options));
1735
+ }, [translate]);
1736
+ (0, import_react8.useEffect)(() => {
1737
+ if (typeof document !== "undefined") {
1738
+ const cookieLocale = document.cookie.split("; ").find((row) => row.startsWith("locale="))?.split("=")[1];
1739
+ if (cookieLocale && locales.includes(cookieLocale)) {
1740
+ setLocale(cookieLocale);
1741
+ }
1742
+ }
1743
+ }, [setLocale]);
1744
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(I18nContext.Provider, { value: { locale, setLocale, t }, children });
1745
+ }
1746
+ function useLocale() {
1747
+ const context = (0, import_react8.useContext)(I18nContext);
1748
+ const { i18n: i18nInstance } = (0, import_react_i18next.useTranslation)();
1749
+ if (context) {
1750
+ return context.locale;
1751
+ }
1752
+ return i18nInstance?.language || defaultLocale;
1753
+ }
1754
+ function useTranslations() {
1755
+ const { t } = (0, import_react_i18next.useTranslation)();
1756
+ return t;
1757
+ }
1758
+ function useSsoTranslation() {
1759
+ return (0, import_react_i18next.useTranslation)("sso");
1760
+ }
1761
+ function getCurrentLocale() {
1762
+ if (typeof document !== "undefined") {
1763
+ const cookieLocale = document.cookie.split("; ").find((row) => row.startsWith("locale="))?.split("=")[1];
1764
+ if (cookieLocale && locales.includes(cookieLocale)) {
1765
+ return cookieLocale;
1766
+ }
1767
+ }
1768
+ return defaultLocale;
1769
+ }
1770
+ function changeLanguage(locale) {
1771
+ import_i18next.default.changeLanguage(locale);
1772
+ if (typeof document !== "undefined") {
1773
+ document.cookie = `locale=${locale};path=/;max-age=31536000`;
1774
+ }
1775
+ }
1776
+ var ssoNamespace = "sso";
1777
+ var defaultTranslations = {
1778
+ ja: {
1779
+ login: "\u30ED\u30B0\u30A4\u30F3",
1780
+ logout: "\u30ED\u30B0\u30A2\u30A6\u30C8",
1781
+ loading: "\u8AAD\u307F\u8FBC\u307F\u4E2D...",
1782
+ error: "\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
1783
+ retry: "\u518D\u8A66\u884C",
1784
+ cancel: "\u30AD\u30E3\u30F3\u30BB\u30EB",
1785
+ save: "\u4FDD\u5B58",
1786
+ delete: "\u524A\u9664",
1787
+ edit: "\u7DE8\u96C6",
1788
+ create: "\u65B0\u898F\u4F5C\u6210",
1789
+ search: "\u691C\u7D22",
1790
+ reset: "\u30EA\u30BB\u30C3\u30C8",
1791
+ noData: "\u30C7\u30FC\u30BF\u304C\u3042\u308A\u307E\u305B\u3093",
1792
+ confirmDelete: "\u524A\u9664\u3057\u3066\u3082\u3088\u308D\u3057\u3044\u3067\u3059\u304B\uFF1F"
1793
+ },
1794
+ en: {
1795
+ login: "Login",
1796
+ logout: "Logout",
1797
+ loading: "Loading...",
1798
+ error: "An error occurred",
1799
+ retry: "Retry",
1800
+ cancel: "Cancel",
1801
+ save: "Save",
1802
+ delete: "Delete",
1803
+ edit: "Edit",
1804
+ create: "Create",
1805
+ search: "Search",
1806
+ reset: "Reset",
1807
+ noData: "No data",
1808
+ confirmDelete: "Are you sure you want to delete?"
1809
+ },
1810
+ vi: {
1811
+ login: "\u0110\u0103ng nh\u1EADp",
1812
+ logout: "\u0110\u0103ng xu\u1EA5t",
1813
+ loading: "\u0110ang t\u1EA3i...",
1814
+ error: "\u0110\xE3 x\u1EA3y ra l\u1ED7i",
1815
+ retry: "Th\u1EED l\u1EA1i",
1816
+ cancel: "H\u1EE7y",
1817
+ save: "L\u01B0u",
1818
+ delete: "X\xF3a",
1819
+ edit: "S\u1EEDa",
1820
+ create: "T\u1EA1o m\u1EDBi",
1821
+ search: "T\xECm ki\u1EBFm",
1822
+ reset: "\u0110\u1EB7t l\u1EA1i",
1823
+ noData: "Kh\xF4ng c\xF3 d\u1EEF li\u1EC7u",
1824
+ confirmDelete: "B\u1EA1n c\xF3 ch\u1EAFc ch\u1EAFn mu\u1ED1n x\xF3a?"
1825
+ }
1826
+ };
1827
+
1828
+ // src/core/schemas/index.ts
1829
+ var schemas_exports = {};
1830
+ __export(schemas_exports, {
1831
+ branchCacheCreateSchema: () => branchCacheCreateSchema,
1832
+ branchCacheI18n: () => branchCacheI18n,
1833
+ branchCacheSchemas: () => branchCacheSchemas,
1834
+ branchCacheUpdateSchema: () => branchCacheUpdateSchema,
1835
+ defaultLocale: () => defaultLocale2,
1836
+ fallbackLocale: () => fallbackLocale,
1837
+ getBranchCacheFieldLabel: () => getBranchCacheFieldLabel,
1838
+ getBranchCacheFieldPlaceholder: () => getBranchCacheFieldPlaceholder,
1839
+ getBranchCacheLabel: () => getBranchCacheLabel,
1840
+ getMessage: () => getMessage,
1841
+ getMessages: () => getMessages,
1842
+ getOrganizationCacheFieldLabel: () => getOrganizationCacheFieldLabel,
1843
+ getOrganizationCacheFieldPlaceholder: () => getOrganizationCacheFieldPlaceholder,
1844
+ getOrganizationCacheLabel: () => getOrganizationCacheLabel,
1845
+ getPermissionFieldLabel: () => getPermissionFieldLabel,
1846
+ getPermissionFieldPlaceholder: () => getPermissionFieldPlaceholder,
1847
+ getPermissionLabel: () => getPermissionLabel,
1848
+ getRoleFieldLabel: () => getRoleFieldLabel,
1849
+ getRoleFieldPlaceholder: () => getRoleFieldPlaceholder,
1850
+ getRoleLabel: () => getRoleLabel,
1851
+ getRolePermissionFieldLabel: () => getRolePermissionFieldLabel,
1852
+ getRolePermissionFieldPlaceholder: () => getRolePermissionFieldPlaceholder,
1853
+ getRolePermissionLabel: () => getRolePermissionLabel,
1854
+ getTeamCacheFieldLabel: () => getTeamCacheFieldLabel,
1855
+ getTeamCacheFieldPlaceholder: () => getTeamCacheFieldPlaceholder,
1856
+ getTeamCacheLabel: () => getTeamCacheLabel,
1857
+ getTeamPermissionFieldLabel: () => getTeamPermissionFieldLabel,
1858
+ getTeamPermissionFieldPlaceholder: () => getTeamPermissionFieldPlaceholder,
1859
+ getTeamPermissionLabel: () => getTeamPermissionLabel,
1860
+ getUserCacheFieldLabel: () => getUserCacheFieldLabel,
1861
+ getUserCacheFieldPlaceholder: () => getUserCacheFieldPlaceholder,
1862
+ getUserCacheLabel: () => getUserCacheLabel,
1863
+ organizationCacheCreateSchema: () => organizationCacheCreateSchema,
1864
+ organizationCacheI18n: () => organizationCacheI18n,
1865
+ organizationCacheSchemas: () => organizationCacheSchemas,
1866
+ organizationCacheUpdateSchema: () => organizationCacheUpdateSchema,
1867
+ permissionCreateSchema: () => permissionCreateSchema,
1868
+ permissionI18n: () => permissionI18n,
1869
+ permissionSchemas: () => permissionSchemas,
1870
+ permissionUpdateSchema: () => permissionUpdateSchema,
1871
+ roleCreateSchema: () => roleCreateSchema,
1872
+ roleI18n: () => roleI18n,
1873
+ rolePermissionCreateSchema: () => rolePermissionCreateSchema,
1874
+ rolePermissionI18n: () => rolePermissionI18n,
1875
+ rolePermissionSchemas: () => rolePermissionSchemas,
1876
+ rolePermissionUpdateSchema: () => rolePermissionUpdateSchema,
1877
+ roleSchemas: () => roleSchemas,
1878
+ roleUpdateSchema: () => roleUpdateSchema,
1879
+ supportedLocales: () => supportedLocales,
1880
+ teamCacheCreateSchema: () => teamCacheCreateSchema,
1881
+ teamCacheI18n: () => teamCacheI18n,
1882
+ teamCacheSchemas: () => teamCacheSchemas,
1883
+ teamCacheUpdateSchema: () => teamCacheUpdateSchema,
1884
+ teamPermissionCreateSchema: () => teamPermissionCreateSchema,
1885
+ teamPermissionI18n: () => teamPermissionI18n,
1886
+ teamPermissionSchemas: () => teamPermissionSchemas,
1887
+ teamPermissionUpdateSchema: () => teamPermissionUpdateSchema,
1888
+ userCacheCreateSchema: () => userCacheCreateSchema,
1889
+ userCacheI18n: () => userCacheI18n,
1890
+ userCacheSchemas: () => userCacheSchemas,
1891
+ userCacheUpdateSchema: () => userCacheUpdateSchema,
1892
+ validationMessages: () => validationMessages
1893
+ });
1894
+
1895
+ // src/core/schemas/base/i18n.ts
1896
+ var defaultLocale2 = "ja";
1897
+ var fallbackLocale = "en";
1898
+ var supportedLocales = ["ja", "en"];
1899
+ var validationMessages = {
1900
+ "required": {
1901
+ "ja": "${displayName}\u306F\u5FC5\u9808\u3067\u3059",
1902
+ "en": "${displayName} is required"
1903
+ },
1904
+ "minLength": {
1905
+ "ja": "${displayName}\u306F${min}\u6587\u5B57\u4EE5\u4E0A\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
1906
+ "en": "${displayName} must be at least ${min} characters"
1907
+ },
1908
+ "maxLength": {
1909
+ "ja": "${displayName}\u306F${max}\u6587\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
1910
+ "en": "${displayName} must be at most ${max} characters"
1911
+ },
1912
+ "min": {
1913
+ "ja": "${displayName}\u306F${min}\u4EE5\u4E0A\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
1914
+ "en": "${displayName} must be at least ${min}"
1915
+ },
1916
+ "max": {
1917
+ "ja": "${displayName}\u306F${max}\u4EE5\u4E0B\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
1918
+ "en": "${displayName} must be at most ${max}"
1919
+ },
1920
+ "email": {
1921
+ "ja": "\u6709\u52B9\u306A\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
1922
+ "en": "Please enter a valid email address"
1923
+ },
1924
+ "url": {
1925
+ "ja": "\u6709\u52B9\u306AURL\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
1926
+ "en": "Please enter a valid URL"
1927
+ },
1928
+ "pattern": {
1929
+ "ja": "${displayName}\u306E\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",
1930
+ "en": "${displayName} format is invalid"
1931
+ }
1932
+ };
1933
+ function getMessage(key, locale, params = {}) {
1934
+ const messages = validationMessages[key];
1935
+ if (!messages) return key;
1936
+ let message = messages[locale] ?? messages[fallbackLocale] ?? messages[defaultLocale2] ?? key;
1937
+ for (const [param, value] of Object.entries(params)) {
1938
+ message = message.replace(new RegExp(`\\\${${param}}`, "g"), String(value));
1939
+ }
1940
+ return message;
1941
+ }
1942
+ function getMessages(locale) {
1943
+ const result = {};
1944
+ for (const [key, messages] of Object.entries(validationMessages)) {
1945
+ result[key] = messages[locale] ?? messages[fallbackLocale] ?? messages[defaultLocale2] ?? key;
1946
+ }
1947
+ return result;
1948
+ }
1949
+
1950
+ // src/core/schemas/base/BranchCache.ts
1951
+ var import_zod = require("zod");
1952
+ var branchCacheI18n = {
1953
+ /** Model display name */
1954
+ label: { "ja": "\u652F\u5E97\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "Branch Cache" },
1955
+ /** Field labels and placeholders */
1956
+ fields: {
1957
+ console_branch_id: {
1958
+ label: { "ja": "Console Branch ID", "en": "Console Branch ID" }
1959
+ },
1960
+ console_org_id: {
1961
+ label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
1962
+ },
1963
+ code: {
1964
+ label: { "ja": "\u652F\u5E97\u30B3\u30FC\u30C9", "en": "Branch Code" }
1965
+ },
1966
+ name: {
1967
+ label: { "ja": "\u652F\u5E97\u540D", "en": "Branch Name" }
1968
+ },
1969
+ is_headquarters: {
1970
+ label: { "ja": "\u672C\u793E", "en": "Is Headquarters" }
1971
+ },
1972
+ is_active: {
1973
+ label: { "ja": "\u6709\u52B9", "en": "Active" }
1974
+ }
1975
+ }
1976
+ };
1977
+ var baseBranchCacheSchemas = {
1978
+ console_branch_id: import_zod.z.string(),
1979
+ console_org_id: import_zod.z.string(),
1980
+ code: import_zod.z.string().min(1).max(20),
1981
+ name: import_zod.z.string().min(1).max(100),
1982
+ is_headquarters: import_zod.z.boolean(),
1983
+ is_active: import_zod.z.boolean()
1984
+ };
1985
+ var baseBranchCacheCreateSchema = import_zod.z.object({
1986
+ console_branch_id: baseBranchCacheSchemas.console_branch_id,
1987
+ console_org_id: baseBranchCacheSchemas.console_org_id,
1988
+ code: baseBranchCacheSchemas.code,
1989
+ name: baseBranchCacheSchemas.name,
1990
+ is_headquarters: baseBranchCacheSchemas.is_headquarters,
1991
+ is_active: baseBranchCacheSchemas.is_active
1992
+ });
1993
+ var baseBranchCacheUpdateSchema = baseBranchCacheCreateSchema.partial();
1994
+ function getBranchCacheLabel(locale) {
1995
+ return branchCacheI18n.label[locale] ?? branchCacheI18n.label["en"] ?? "BranchCache";
1996
+ }
1997
+ function getBranchCacheFieldLabel(field, locale) {
1998
+ const fieldI18n = branchCacheI18n.fields[field];
1999
+ if (!fieldI18n) return field;
2000
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2001
+ }
2002
+ function getBranchCacheFieldPlaceholder(field, locale) {
2003
+ const fieldI18n = branchCacheI18n.fields[field];
2004
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2005
+ const placeholder = fieldI18n.placeholder;
2006
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2007
+ }
2008
+
2009
+ // src/core/schemas/BranchCache.ts
2010
+ var branchCacheSchemas = { ...baseBranchCacheSchemas };
2011
+ var branchCacheCreateSchema = baseBranchCacheCreateSchema;
2012
+ var branchCacheUpdateSchema = baseBranchCacheUpdateSchema;
2013
+
2014
+ // src/core/schemas/base/OrganizationCache.ts
2015
+ var import_zod2 = require("zod");
2016
+ var organizationCacheI18n = {
2017
+ /** Model display name */
2018
+ label: { "ja": "\u7D44\u7E54\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "Organization Cache" },
2019
+ /** Field labels and placeholders */
2020
+ fields: {
2021
+ console_org_id: {
2022
+ label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
2023
+ },
2024
+ name: {
2025
+ label: { "ja": "\u7D44\u7E54\u540D", "en": "Organization Name" }
2026
+ },
2027
+ code: {
2028
+ label: { "ja": "\u7D44\u7E54\u30B3\u30FC\u30C9", "en": "Organization Code" }
2029
+ },
2030
+ is_active: {
2031
+ label: { "ja": "\u6709\u52B9", "en": "Active" }
2032
+ }
2033
+ }
2034
+ };
2035
+ var baseOrganizationCacheSchemas = {
2036
+ console_org_id: import_zod2.z.string(),
2037
+ name: import_zod2.z.string().min(1).max(100),
2038
+ code: import_zod2.z.string().min(1).max(20),
2039
+ is_active: import_zod2.z.boolean()
2040
+ };
2041
+ var baseOrganizationCacheCreateSchema = import_zod2.z.object({
2042
+ console_org_id: baseOrganizationCacheSchemas.console_org_id,
2043
+ name: baseOrganizationCacheSchemas.name,
2044
+ code: baseOrganizationCacheSchemas.code,
2045
+ is_active: baseOrganizationCacheSchemas.is_active
2046
+ });
2047
+ var baseOrganizationCacheUpdateSchema = baseOrganizationCacheCreateSchema.partial();
2048
+ function getOrganizationCacheLabel(locale) {
2049
+ return organizationCacheI18n.label[locale] ?? organizationCacheI18n.label["en"] ?? "OrganizationCache";
2050
+ }
2051
+ function getOrganizationCacheFieldLabel(field, locale) {
2052
+ const fieldI18n = organizationCacheI18n.fields[field];
2053
+ if (!fieldI18n) return field;
2054
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2055
+ }
2056
+ function getOrganizationCacheFieldPlaceholder(field, locale) {
2057
+ const fieldI18n = organizationCacheI18n.fields[field];
2058
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2059
+ const placeholder = fieldI18n.placeholder;
2060
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2061
+ }
2062
+
2063
+ // src/core/schemas/OrganizationCache.ts
2064
+ var organizationCacheSchemas = { ...baseOrganizationCacheSchemas };
2065
+ var organizationCacheCreateSchema = baseOrganizationCacheCreateSchema;
2066
+ var organizationCacheUpdateSchema = baseOrganizationCacheUpdateSchema;
2067
+
2068
+ // src/core/schemas/base/Permission.ts
2069
+ var import_zod3 = require("zod");
2070
+ var permissionI18n = {
2071
+ /** Model display name */
2072
+ label: { "ja": "\u6A29\u9650", "en": "Permission" },
2073
+ /** Field labels and placeholders */
2074
+ fields: {
2075
+ name: {
2076
+ label: { "ja": "\u6A29\u9650\u540D", "en": "Permission Name" }
2077
+ },
2078
+ slug: {
2079
+ label: { "ja": "\u30B9\u30E9\u30C3\u30B0", "en": "Slug" }
2080
+ },
2081
+ group: {
2082
+ label: { "ja": "\u30B0\u30EB\u30FC\u30D7", "en": "Group" }
2083
+ },
2084
+ roles: {
2085
+ label: { "ja": "\u30ED\u30FC\u30EB", "en": "Roles" }
2086
+ }
2087
+ }
2088
+ };
2089
+ var basePermissionSchemas = {
2090
+ name: import_zod3.z.string().min(1).max(100),
2091
+ slug: import_zod3.z.string().min(1).max(100),
2092
+ group: import_zod3.z.string().max(50).optional().nullable()
2093
+ };
2094
+ var basePermissionCreateSchema = import_zod3.z.object({
2095
+ name: basePermissionSchemas.name,
2096
+ slug: basePermissionSchemas.slug,
2097
+ group: basePermissionSchemas.group
2098
+ });
2099
+ var basePermissionUpdateSchema = basePermissionCreateSchema.partial();
2100
+ function getPermissionLabel(locale) {
2101
+ return permissionI18n.label[locale] ?? permissionI18n.label["en"] ?? "Permission";
2102
+ }
2103
+ function getPermissionFieldLabel(field, locale) {
2104
+ const fieldI18n = permissionI18n.fields[field];
2105
+ if (!fieldI18n) return field;
2106
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2107
+ }
2108
+ function getPermissionFieldPlaceholder(field, locale) {
2109
+ const fieldI18n = permissionI18n.fields[field];
2110
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2111
+ const placeholder = fieldI18n.placeholder;
2112
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2113
+ }
2114
+
2115
+ // src/core/schemas/Permission.ts
2116
+ var permissionSchemas = { ...basePermissionSchemas };
2117
+ var permissionCreateSchema = basePermissionCreateSchema;
2118
+ var permissionUpdateSchema = basePermissionUpdateSchema;
2119
+
2120
+ // src/core/schemas/base/Role.ts
2121
+ var import_zod4 = require("zod");
2122
+ var roleI18n = {
2123
+ /** Model display name */
2124
+ label: { "ja": "\u30ED\u30FC\u30EB", "en": "Role" },
2125
+ /** Field labels and placeholders */
2126
+ fields: {
2127
+ console_org_id: {
2128
+ label: { "ja": "\u7D44\u7E54ID", "en": "Organization ID" }
2129
+ },
2130
+ name: {
2131
+ label: { "ja": "\u30ED\u30FC\u30EB\u540D", "en": "Role Name" }
2132
+ },
2133
+ slug: {
2134
+ label: { "ja": "\u30B9\u30E9\u30C3\u30B0", "en": "Slug" }
2135
+ },
2136
+ description: {
2137
+ label: { "ja": "\u8AAC\u660E", "en": "Description" }
2138
+ },
2139
+ level: {
2140
+ label: { "ja": "\u30EC\u30D9\u30EB", "en": "Level" }
2141
+ },
2142
+ permissions: {
2143
+ label: { "ja": "\u6A29\u9650", "en": "Permissions" }
2144
+ }
2145
+ }
2146
+ };
2147
+ var baseRoleSchemas = {
2148
+ console_org_id: import_zod4.z.string().max(36).optional().nullable(),
2149
+ name: import_zod4.z.string().min(1).max(100),
2150
+ slug: import_zod4.z.string().min(1).max(100),
2151
+ description: import_zod4.z.string().optional().nullable(),
2152
+ level: import_zod4.z.number().int()
2153
+ };
2154
+ var baseRoleCreateSchema = import_zod4.z.object({
2155
+ console_org_id: baseRoleSchemas.console_org_id,
2156
+ name: baseRoleSchemas.name,
2157
+ slug: baseRoleSchemas.slug,
2158
+ description: baseRoleSchemas.description,
2159
+ level: baseRoleSchemas.level
2160
+ });
2161
+ var baseRoleUpdateSchema = baseRoleCreateSchema.partial();
2162
+ function getRoleLabel(locale) {
2163
+ return roleI18n.label[locale] ?? roleI18n.label["en"] ?? "Role";
2164
+ }
2165
+ function getRoleFieldLabel(field, locale) {
2166
+ const fieldI18n = roleI18n.fields[field];
2167
+ if (!fieldI18n) return field;
2168
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2169
+ }
2170
+ function getRoleFieldPlaceholder(field, locale) {
2171
+ const fieldI18n = roleI18n.fields[field];
2172
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2173
+ const placeholder = fieldI18n.placeholder;
2174
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2175
+ }
2176
+
2177
+ // src/core/schemas/Role.ts
2178
+ var roleSchemas = { ...baseRoleSchemas };
2179
+ var roleCreateSchema = baseRoleCreateSchema;
2180
+ var roleUpdateSchema = baseRoleUpdateSchema;
2181
+
2182
+ // src/core/schemas/base/RolePermission.ts
2183
+ var import_zod5 = require("zod");
2184
+ var rolePermissionI18n = {
2185
+ /** Model display name */
2186
+ label: { "ja": "\u30ED\u30FC\u30EB\u6A29\u9650", "en": "Role Permission" },
2187
+ /** Field labels and placeholders */
2188
+ fields: {
2189
+ role: {
2190
+ label: { "ja": "\u30ED\u30FC\u30EB", "en": "Role" }
2191
+ },
2192
+ permission: {
2193
+ label: { "ja": "\u6A29\u9650", "en": "Permission" }
2194
+ }
2195
+ }
2196
+ };
2197
+ var baseRolePermissionSchemas = {};
2198
+ var baseRolePermissionCreateSchema = import_zod5.z.object({});
2199
+ var baseRolePermissionUpdateSchema = baseRolePermissionCreateSchema.partial();
2200
+ function getRolePermissionLabel(locale) {
2201
+ return rolePermissionI18n.label[locale] ?? rolePermissionI18n.label["en"] ?? "RolePermission";
2202
+ }
2203
+ function getRolePermissionFieldLabel(field, locale) {
2204
+ const fieldI18n = rolePermissionI18n.fields[field];
2205
+ if (!fieldI18n) return field;
2206
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2207
+ }
2208
+ function getRolePermissionFieldPlaceholder(field, locale) {
2209
+ const fieldI18n = rolePermissionI18n.fields[field];
2210
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2211
+ const placeholder = fieldI18n.placeholder;
2212
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2213
+ }
2214
+
2215
+ // src/core/schemas/RolePermission.ts
2216
+ var rolePermissionSchemas = { ...baseRolePermissionSchemas };
2217
+ var rolePermissionCreateSchema = baseRolePermissionCreateSchema;
2218
+ var rolePermissionUpdateSchema = baseRolePermissionUpdateSchema;
2219
+
2220
+ // src/core/schemas/base/TeamCache.ts
2221
+ var import_zod6 = require("zod");
2222
+ var teamCacheI18n = {
2223
+ /** Model display name */
2224
+ label: { "ja": "\u30C1\u30FC\u30E0\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "Team Cache" },
2225
+ /** Field labels and placeholders */
2226
+ fields: {
2227
+ console_team_id: {
2228
+ label: { "ja": "Console Team ID", "en": "Console Team ID" }
2229
+ },
2230
+ console_org_id: {
2231
+ label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
2232
+ },
2233
+ name: {
2234
+ label: { "ja": "\u30C1\u30FC\u30E0\u540D", "en": "Team Name" }
2235
+ }
2236
+ }
2237
+ };
2238
+ var baseTeamCacheSchemas = {
2239
+ console_team_id: import_zod6.z.string(),
2240
+ console_org_id: import_zod6.z.string(),
2241
+ name: import_zod6.z.string().min(1).max(100)
2242
+ };
2243
+ var baseTeamCacheCreateSchema = import_zod6.z.object({
2244
+ console_team_id: baseTeamCacheSchemas.console_team_id,
2245
+ console_org_id: baseTeamCacheSchemas.console_org_id,
2246
+ name: baseTeamCacheSchemas.name
2247
+ });
2248
+ var baseTeamCacheUpdateSchema = baseTeamCacheCreateSchema.partial();
2249
+ function getTeamCacheLabel(locale) {
2250
+ return teamCacheI18n.label[locale] ?? teamCacheI18n.label["en"] ?? "TeamCache";
2251
+ }
2252
+ function getTeamCacheFieldLabel(field, locale) {
2253
+ const fieldI18n = teamCacheI18n.fields[field];
2254
+ if (!fieldI18n) return field;
2255
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2256
+ }
2257
+ function getTeamCacheFieldPlaceholder(field, locale) {
2258
+ const fieldI18n = teamCacheI18n.fields[field];
2259
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2260
+ const placeholder = fieldI18n.placeholder;
2261
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2262
+ }
2263
+
2264
+ // src/core/schemas/TeamCache.ts
2265
+ var teamCacheSchemas = { ...baseTeamCacheSchemas };
2266
+ var teamCacheCreateSchema = baseTeamCacheCreateSchema;
2267
+ var teamCacheUpdateSchema = baseTeamCacheUpdateSchema;
2268
+
2269
+ // src/core/schemas/base/TeamPermission.ts
2270
+ var import_zod7 = require("zod");
2271
+ var teamPermissionI18n = {
2272
+ /** Model display name */
2273
+ label: { "ja": "\u30C1\u30FC\u30E0\u6A29\u9650", "en": "Team Permission" },
2274
+ /** Field labels and placeholders */
2275
+ fields: {
2276
+ console_org_id: {
2277
+ label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
2278
+ },
2279
+ console_team_id: {
2280
+ label: { "ja": "Console Team ID", "en": "Console Team ID" }
2281
+ },
2282
+ permission: {
2283
+ label: { "ja": "\u6A29\u9650", "en": "Permission" }
2284
+ }
2285
+ }
2286
+ };
2287
+ var baseTeamPermissionSchemas = {
2288
+ console_org_id: import_zod7.z.string(),
2289
+ console_team_id: import_zod7.z.string()
2290
+ };
2291
+ var baseTeamPermissionCreateSchema = import_zod7.z.object({
2292
+ console_org_id: baseTeamPermissionSchemas.console_org_id,
2293
+ console_team_id: baseTeamPermissionSchemas.console_team_id
2294
+ });
2295
+ var baseTeamPermissionUpdateSchema = baseTeamPermissionCreateSchema.partial();
2296
+ function getTeamPermissionLabel(locale) {
2297
+ return teamPermissionI18n.label[locale] ?? teamPermissionI18n.label["en"] ?? "TeamPermission";
2298
+ }
2299
+ function getTeamPermissionFieldLabel(field, locale) {
2300
+ const fieldI18n = teamPermissionI18n.fields[field];
2301
+ if (!fieldI18n) return field;
2302
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2303
+ }
2304
+ function getTeamPermissionFieldPlaceholder(field, locale) {
2305
+ const fieldI18n = teamPermissionI18n.fields[field];
2306
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2307
+ const placeholder = fieldI18n.placeholder;
2308
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2309
+ }
2310
+
2311
+ // src/core/schemas/TeamPermission.ts
2312
+ var teamPermissionSchemas = { ...baseTeamPermissionSchemas };
2313
+ var teamPermissionCreateSchema = baseTeamPermissionCreateSchema;
2314
+ var teamPermissionUpdateSchema = baseTeamPermissionUpdateSchema;
2315
+
2316
+ // src/core/schemas/base/UserCache.ts
2317
+ var import_zod8 = require("zod");
2318
+ var userCacheI18n = {
2319
+ /** Model display name */
2320
+ label: { "ja": "\u30E6\u30FC\u30B6\u30FC\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "User Cache" },
2321
+ /** Field labels and placeholders */
2322
+ fields: {
2323
+ name: {
2324
+ label: { "ja": "\u540D\u524D", "en": "Name" }
2325
+ },
2326
+ email: {
2327
+ label: { "ja": "\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9", "en": "Email" }
2328
+ },
2329
+ console_user_id: {
2330
+ label: { "ja": "Console User ID", "en": "Console User ID" }
2331
+ },
2332
+ console_org_id: {
2333
+ label: { "ja": "\u6240\u5C5E\u7D44\u7E54ID", "en": "Organization ID" }
2334
+ },
2335
+ console_access_token: {
2336
+ label: { "ja": "Console Access Token", "en": "Console Access Token" }
2337
+ },
2338
+ console_refresh_token: {
2339
+ label: { "ja": "Console Refresh Token", "en": "Console Refresh Token" }
2340
+ },
2341
+ console_token_expires_at: {
2342
+ label: { "ja": "Console Token\u6709\u52B9\u671F\u9650", "en": "Console Token Expiry" }
2343
+ },
2344
+ roles: {
2345
+ label: { "ja": "\u30ED\u30FC\u30EB", "en": "Roles" }
2346
+ }
2347
+ }
2348
+ };
2349
+ var baseUserCacheSchemas = {
2350
+ name: import_zod8.z.string().min(1),
2351
+ email: import_zod8.z.string().min(1),
2352
+ console_user_id: import_zod8.z.string().optional().nullable(),
2353
+ console_org_id: import_zod8.z.string().optional().nullable(),
2354
+ console_access_token: import_zod8.z.string().optional().nullable(),
2355
+ console_refresh_token: import_zod8.z.string().optional().nullable(),
2356
+ console_token_expires_at: import_zod8.z.string().datetime({ offset: true }).optional().nullable()
2357
+ };
2358
+ var baseUserCacheCreateSchema = import_zod8.z.object({
2359
+ name: baseUserCacheSchemas.name,
2360
+ email: baseUserCacheSchemas.email,
2361
+ console_user_id: baseUserCacheSchemas.console_user_id,
2362
+ console_org_id: baseUserCacheSchemas.console_org_id,
2363
+ console_access_token: baseUserCacheSchemas.console_access_token,
2364
+ console_refresh_token: baseUserCacheSchemas.console_refresh_token,
2365
+ console_token_expires_at: baseUserCacheSchemas.console_token_expires_at
2366
+ });
2367
+ var baseUserCacheUpdateSchema = baseUserCacheCreateSchema.partial();
2368
+ function getUserCacheLabel(locale) {
2369
+ return userCacheI18n.label[locale] ?? userCacheI18n.label["en"] ?? "UserCache";
2370
+ }
2371
+ function getUserCacheFieldLabel(field, locale) {
2372
+ const fieldI18n = userCacheI18n.fields[field];
2373
+ if (!fieldI18n) return field;
2374
+ return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
2375
+ }
2376
+ function getUserCacheFieldPlaceholder(field, locale) {
2377
+ const fieldI18n = userCacheI18n.fields[field];
2378
+ if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
2379
+ const placeholder = fieldI18n.placeholder;
2380
+ return placeholder[locale] ?? placeholder["en"] ?? "";
2381
+ }
2382
+
2383
+ // src/core/schemas/UserCache.ts
2384
+ var userCacheSchemas = { ...baseUserCacheSchemas };
2385
+ var userCacheCreateSchema = baseUserCacheCreateSchema;
2386
+ var userCacheUpdateSchema = baseUserCacheUpdateSchema;
2387
+ // Annotate the CommonJS export names for ESM import in node:
2388
+ 0 && (module.exports = {
2389
+ BRANCH_HEADERS,
2390
+ BranchContext,
2391
+ BranchProvider,
2392
+ I18nProvider,
2393
+ SsoContext,
2394
+ SsoProvider,
2395
+ changeLanguage,
2396
+ createAuthService,
2397
+ createBranchHeaderSetter,
2398
+ createBranchService,
2399
+ createPermissionService,
2400
+ createRoleService,
2401
+ createSsoService,
2402
+ createTeamService,
2403
+ createTokenService,
2404
+ createUserRoleService,
2405
+ createUserService,
2406
+ defaultLocale,
2407
+ defaultTranslations,
2408
+ fallbackLocale,
2409
+ getCurrentLocale,
2410
+ getEffectivePermissions,
2411
+ getMessage,
2412
+ getMessages,
2413
+ getScopeLabel,
2414
+ localeNames,
2415
+ locales,
2416
+ schemas,
2417
+ setBranchHeaders,
2418
+ ssoNamespace,
2419
+ ssoQueryKeys,
2420
+ supportedLocales,
2421
+ useAuth,
2422
+ useBranch,
2423
+ useBranchContext,
2424
+ useLocale,
2425
+ useOrganization,
2426
+ useSso,
2427
+ useSsoContext,
2428
+ useSsoTranslation,
2429
+ useTranslations,
2430
+ validationMessages
2431
+ });
2432
+ //# sourceMappingURL=index.cjs.map