@nocios/crudify-ui 1.3.2 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -39
- package/README_DEPTH.md +400 -216
- package/dist/index.d.mts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +728 -143
- package/dist/index.mjs +703 -88
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1290,6 +1290,9 @@ __export(index_exports, {
|
|
|
1290
1290
|
ERROR_CODES: () => ERROR_CODES,
|
|
1291
1291
|
ERROR_SEVERITY_MAP: () => ERROR_SEVERITY_MAP,
|
|
1292
1292
|
LoginComponent: () => LoginComponent,
|
|
1293
|
+
POLICY_ACTIONS: () => POLICY_ACTIONS,
|
|
1294
|
+
PREFERRED_POLICY_ORDER: () => PREFERRED_POLICY_ORDER,
|
|
1295
|
+
Policies: () => Policies_default,
|
|
1293
1296
|
ProtectedRoute: () => ProtectedRoute,
|
|
1294
1297
|
SessionDebugInfo: () => SessionDebugInfo,
|
|
1295
1298
|
SessionManager: () => SessionManager,
|
|
@@ -3321,34 +3324,613 @@ var UserProfileDisplay = ({
|
|
|
3321
3324
|
};
|
|
3322
3325
|
var UserProfileDisplay_default = UserProfileDisplay;
|
|
3323
3326
|
|
|
3327
|
+
// src/components/PublicPolicies/Policies.tsx
|
|
3328
|
+
var import_react15 = require("react");
|
|
3329
|
+
var import_react_i18next3 = require("react-i18next");
|
|
3330
|
+
var import_material10 = require("@mui/material");
|
|
3331
|
+
var import_icons_material4 = require("@mui/icons-material");
|
|
3332
|
+
|
|
3333
|
+
// src/components/PublicPolicies/PolicyItem/PolicyItem.tsx
|
|
3334
|
+
var import_react14 = require("react");
|
|
3335
|
+
var import_react_i18next2 = require("react-i18next");
|
|
3336
|
+
var import_material9 = require("@mui/material");
|
|
3337
|
+
var import_icons_material3 = require("@mui/icons-material");
|
|
3338
|
+
|
|
3339
|
+
// src/components/PublicPolicies/FieldSelector/FieldSelector.tsx
|
|
3340
|
+
var import_react13 = require("react");
|
|
3341
|
+
var import_react_i18next = require("react-i18next");
|
|
3342
|
+
var import_material8 = require("@mui/material");
|
|
3343
|
+
var import_icons_material2 = require("@mui/icons-material");
|
|
3344
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
3345
|
+
var FieldSelector = ({
|
|
3346
|
+
value,
|
|
3347
|
+
onChange,
|
|
3348
|
+
availableFields,
|
|
3349
|
+
error,
|
|
3350
|
+
disabled = false
|
|
3351
|
+
}) => {
|
|
3352
|
+
const { t } = (0, import_react_i18next.useTranslation)();
|
|
3353
|
+
const [mode, setMode] = (0, import_react13.useState)("custom");
|
|
3354
|
+
const isUpdatingRef = (0, import_react13.useRef)(false);
|
|
3355
|
+
(0, import_react13.useEffect)(() => {
|
|
3356
|
+
const current = value || { allow: [], owner_allow: [], deny: [] };
|
|
3357
|
+
const all = new Set(availableFields);
|
|
3358
|
+
const allow = (current.allow || []).filter((f) => all.has(f));
|
|
3359
|
+
const owner = (current.owner_allow || []).filter((f) => all.has(f));
|
|
3360
|
+
const deny = (current.deny || []).filter((f) => all.has(f));
|
|
3361
|
+
availableFields.forEach((f) => {
|
|
3362
|
+
if (!allow.includes(f) && !owner.includes(f) && !deny.includes(f)) deny.push(f);
|
|
3363
|
+
});
|
|
3364
|
+
const normalized = { allow, owner_allow: owner, deny };
|
|
3365
|
+
if (JSON.stringify(normalized) !== JSON.stringify(current)) {
|
|
3366
|
+
onChange(normalized);
|
|
3367
|
+
}
|
|
3368
|
+
if (allow.length === availableFields.length) setMode("all");
|
|
3369
|
+
else if (deny.length === availableFields.length) setMode("none");
|
|
3370
|
+
else setMode("custom");
|
|
3371
|
+
}, [availableFields, value]);
|
|
3372
|
+
const setAllAllow = () => {
|
|
3373
|
+
isUpdatingRef.current = true;
|
|
3374
|
+
onChange({ allow: [...availableFields], owner_allow: [], deny: [] });
|
|
3375
|
+
setMode("all");
|
|
3376
|
+
setTimeout(() => {
|
|
3377
|
+
isUpdatingRef.current = false;
|
|
3378
|
+
}, 0);
|
|
3379
|
+
};
|
|
3380
|
+
const setAllDeny = () => {
|
|
3381
|
+
isUpdatingRef.current = true;
|
|
3382
|
+
onChange({ allow: [], owner_allow: [], deny: [...availableFields] });
|
|
3383
|
+
setMode("none");
|
|
3384
|
+
setTimeout(() => {
|
|
3385
|
+
isUpdatingRef.current = false;
|
|
3386
|
+
}, 0);
|
|
3387
|
+
};
|
|
3388
|
+
const getFieldState = (fieldName) => {
|
|
3389
|
+
if (value?.allow?.includes(fieldName)) return "allow";
|
|
3390
|
+
if (value?.owner_allow?.includes(fieldName)) return "owner_allow";
|
|
3391
|
+
return "deny";
|
|
3392
|
+
};
|
|
3393
|
+
const setFieldState = (fieldName, state) => {
|
|
3394
|
+
isUpdatingRef.current = true;
|
|
3395
|
+
const allow = new Set(value?.allow || []);
|
|
3396
|
+
const owner = new Set(value?.owner_allow || []);
|
|
3397
|
+
const deny = new Set(value?.deny || []);
|
|
3398
|
+
allow.delete(fieldName);
|
|
3399
|
+
owner.delete(fieldName);
|
|
3400
|
+
deny.delete(fieldName);
|
|
3401
|
+
if (state === "allow") allow.add(fieldName);
|
|
3402
|
+
if (state === "owner_allow") owner.add(fieldName);
|
|
3403
|
+
if (state === "deny") deny.add(fieldName);
|
|
3404
|
+
onChange({ allow: Array.from(allow), owner_allow: Array.from(owner), deny: Array.from(deny) });
|
|
3405
|
+
setMode("custom");
|
|
3406
|
+
setTimeout(() => {
|
|
3407
|
+
isUpdatingRef.current = false;
|
|
3408
|
+
}, 0);
|
|
3409
|
+
};
|
|
3410
|
+
if (availableFields.length === 0) {
|
|
3411
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { children: [
|
|
3412
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 1 }, children: t("modules.form.publicPolicies.fields.conditions.label") }),
|
|
3413
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", sx: { fontStyle: "italic" }, children: t("modules.form.publicPolicies.fields.conditions.noFieldsAvailable") }),
|
|
3414
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.FormHelperText, { error: true, sx: { mt: 1 }, children: error })
|
|
3415
|
+
] });
|
|
3416
|
+
}
|
|
3417
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { children: [
|
|
3418
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t("modules.form.publicPolicies.fields.conditions.label") }),
|
|
3419
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Stack, { direction: "row", spacing: 1, sx: { mb: 3 }, children: [
|
|
3420
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3421
|
+
import_material8.Button,
|
|
3422
|
+
{
|
|
3423
|
+
variant: mode === "all" ? "contained" : "outlined",
|
|
3424
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material2.SelectAll, {}),
|
|
3425
|
+
onClick: setAllAllow,
|
|
3426
|
+
disabled,
|
|
3427
|
+
size: "small",
|
|
3428
|
+
sx: {
|
|
3429
|
+
minWidth: 120,
|
|
3430
|
+
...mode === "all" && {
|
|
3431
|
+
backgroundColor: "#16a34a",
|
|
3432
|
+
"&:hover": { backgroundColor: "#15803d" }
|
|
3433
|
+
}
|
|
3434
|
+
},
|
|
3435
|
+
children: t("modules.form.publicPolicies.fields.conditions.allFields")
|
|
3436
|
+
}
|
|
3437
|
+
),
|
|
3438
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3439
|
+
import_material8.Button,
|
|
3440
|
+
{
|
|
3441
|
+
variant: mode === "none" ? "contained" : "outlined",
|
|
3442
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material2.ClearAll, {}),
|
|
3443
|
+
onClick: setAllDeny,
|
|
3444
|
+
disabled,
|
|
3445
|
+
size: "small",
|
|
3446
|
+
sx: {
|
|
3447
|
+
minWidth: 120,
|
|
3448
|
+
...mode === "none" && {
|
|
3449
|
+
backgroundColor: "#cf222e",
|
|
3450
|
+
"&:hover": { backgroundColor: "#bc1f2c" }
|
|
3451
|
+
}
|
|
3452
|
+
},
|
|
3453
|
+
children: t("modules.form.publicPolicies.fields.conditions.noFields")
|
|
3454
|
+
}
|
|
3455
|
+
)
|
|
3456
|
+
] }),
|
|
3457
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { sx: { p: 2, border: "1px solid #d1d9e0", borderRadius: 1, backgroundColor: "#f6f8fa" }, children: [
|
|
3458
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t("modules.form.publicPolicies.fields.conditions.help") }),
|
|
3459
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Stack, { spacing: 1, children: availableFields.map((fieldName) => {
|
|
3460
|
+
const fieldState = getFieldState(fieldName);
|
|
3461
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Stack, { direction: "row", spacing: 1, alignItems: "center", children: [
|
|
3462
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", sx: { minWidth: 100, fontFamily: "monospace" }, children: fieldName }),
|
|
3463
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.ToggleButtonGroup, { value: fieldState, exclusive: true, size: "small", children: [
|
|
3464
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
3465
|
+
import_material8.ToggleButton,
|
|
3466
|
+
{
|
|
3467
|
+
value: "allow",
|
|
3468
|
+
onClick: () => setFieldState(fieldName, "allow"),
|
|
3469
|
+
disabled,
|
|
3470
|
+
sx: {
|
|
3471
|
+
px: 2,
|
|
3472
|
+
color: fieldState === "allow" ? "#ffffff" : "#6b7280",
|
|
3473
|
+
backgroundColor: fieldState === "allow" ? "#16a34a" : "#f3f4f6",
|
|
3474
|
+
borderColor: fieldState === "allow" ? "#16a34a" : "#d1d5db",
|
|
3475
|
+
"&:hover": {
|
|
3476
|
+
backgroundColor: fieldState === "allow" ? "#15803d" : "#e5e7eb",
|
|
3477
|
+
borderColor: fieldState === "allow" ? "#15803d" : "#9ca3af"
|
|
3478
|
+
},
|
|
3479
|
+
"&.Mui-selected": {
|
|
3480
|
+
backgroundColor: "#16a34a",
|
|
3481
|
+
color: "#ffffff",
|
|
3482
|
+
"&:hover": {
|
|
3483
|
+
backgroundColor: "#15803d"
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
},
|
|
3487
|
+
children: [
|
|
3488
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material2.CheckCircle, { sx: { fontSize: 16, mr: 0.5 } }),
|
|
3489
|
+
t("modules.form.publicPolicies.fields.conditions.states.allow")
|
|
3490
|
+
]
|
|
3491
|
+
}
|
|
3492
|
+
),
|
|
3493
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3494
|
+
import_material8.ToggleButton,
|
|
3495
|
+
{
|
|
3496
|
+
value: "owner_allow",
|
|
3497
|
+
onClick: () => setFieldState(fieldName, "owner_allow"),
|
|
3498
|
+
disabled,
|
|
3499
|
+
sx: {
|
|
3500
|
+
px: 2,
|
|
3501
|
+
color: fieldState === "owner_allow" ? "#ffffff" : "#6b7280",
|
|
3502
|
+
backgroundColor: fieldState === "owner_allow" ? "#0ea5e9" : "#f3f4f6",
|
|
3503
|
+
borderColor: fieldState === "owner_allow" ? "#0ea5e9" : "#d1d5db",
|
|
3504
|
+
"&:hover": {
|
|
3505
|
+
backgroundColor: fieldState === "owner_allow" ? "#0284c7" : "#e5e7eb",
|
|
3506
|
+
borderColor: fieldState === "owner_allow" ? "#0284c7" : "#9ca3af"
|
|
3507
|
+
},
|
|
3508
|
+
"&.Mui-selected": {
|
|
3509
|
+
backgroundColor: "#0ea5e9",
|
|
3510
|
+
color: "#ffffff",
|
|
3511
|
+
"&:hover": {
|
|
3512
|
+
backgroundColor: "#0284c7"
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
},
|
|
3516
|
+
children: t("modules.form.publicPolicies.fields.conditions.states.ownerAllow")
|
|
3517
|
+
}
|
|
3518
|
+
),
|
|
3519
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
3520
|
+
import_material8.ToggleButton,
|
|
3521
|
+
{
|
|
3522
|
+
value: "deny",
|
|
3523
|
+
onClick: () => setFieldState(fieldName, "deny"),
|
|
3524
|
+
disabled,
|
|
3525
|
+
sx: {
|
|
3526
|
+
px: 2,
|
|
3527
|
+
color: fieldState === "deny" ? "#ffffff" : "#6b7280",
|
|
3528
|
+
backgroundColor: fieldState === "deny" ? "#dc2626" : "#f3f4f6",
|
|
3529
|
+
borderColor: fieldState === "deny" ? "#dc2626" : "#d1d5db",
|
|
3530
|
+
"&:hover": {
|
|
3531
|
+
backgroundColor: fieldState === "deny" ? "#b91c1c" : "#e5e7eb",
|
|
3532
|
+
borderColor: fieldState === "deny" ? "#b91c1c" : "#9ca3af"
|
|
3533
|
+
},
|
|
3534
|
+
"&.Mui-selected": {
|
|
3535
|
+
backgroundColor: "#dc2626",
|
|
3536
|
+
color: "#ffffff",
|
|
3537
|
+
"&:hover": {
|
|
3538
|
+
backgroundColor: "#b91c1c"
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
},
|
|
3542
|
+
children: [
|
|
3543
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material2.Cancel, { sx: { fontSize: 16, mr: 0.5 } }),
|
|
3544
|
+
t("modules.form.publicPolicies.fields.conditions.states.deny")
|
|
3545
|
+
]
|
|
3546
|
+
}
|
|
3547
|
+
)
|
|
3548
|
+
] })
|
|
3549
|
+
] }, fieldName);
|
|
3550
|
+
}) })
|
|
3551
|
+
] }),
|
|
3552
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.FormHelperText, { error: true, sx: { mt: 1 }, children: error })
|
|
3553
|
+
] });
|
|
3554
|
+
};
|
|
3555
|
+
var FieldSelector_default = FieldSelector;
|
|
3556
|
+
|
|
3557
|
+
// src/components/PublicPolicies/constants.ts
|
|
3558
|
+
var POLICY_ACTIONS = ["create", "read", "update", "delete"];
|
|
3559
|
+
var PREFERRED_POLICY_ORDER = [
|
|
3560
|
+
"create",
|
|
3561
|
+
"read",
|
|
3562
|
+
"update",
|
|
3563
|
+
"delete"
|
|
3564
|
+
];
|
|
3565
|
+
|
|
3566
|
+
// src/components/PublicPolicies/PolicyItem/PolicyItem.tsx
|
|
3567
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3568
|
+
var PolicyItem = (0, import_react14.forwardRef)(({
|
|
3569
|
+
policy,
|
|
3570
|
+
onChange,
|
|
3571
|
+
onRemove,
|
|
3572
|
+
availableFields,
|
|
3573
|
+
isSubmitting = false,
|
|
3574
|
+
usedActions,
|
|
3575
|
+
error
|
|
3576
|
+
}, ref) => {
|
|
3577
|
+
const { t } = (0, import_react_i18next2.useTranslation)();
|
|
3578
|
+
const takenActions = new Set(Array.from(usedActions || []));
|
|
3579
|
+
takenActions.delete(policy.action);
|
|
3580
|
+
const actionOptions = POLICY_ACTIONS.map((a) => ({
|
|
3581
|
+
value: a,
|
|
3582
|
+
label: t(`modules.form.publicPolicies.fields.action.options.${a}`)
|
|
3583
|
+
}));
|
|
3584
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
3585
|
+
import_material9.Paper,
|
|
3586
|
+
{
|
|
3587
|
+
ref,
|
|
3588
|
+
sx: {
|
|
3589
|
+
p: 3,
|
|
3590
|
+
border: "1px solid #d1d9e0",
|
|
3591
|
+
borderRadius: 2,
|
|
3592
|
+
position: "relative",
|
|
3593
|
+
backgroundColor: "#ffffff"
|
|
3594
|
+
},
|
|
3595
|
+
children: [
|
|
3596
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", mb: 3 }, children: [
|
|
3597
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3598
|
+
import_material9.Typography,
|
|
3599
|
+
{
|
|
3600
|
+
variant: "subtitle1",
|
|
3601
|
+
sx: {
|
|
3602
|
+
fontWeight: 600,
|
|
3603
|
+
color: "#111418",
|
|
3604
|
+
fontSize: "1rem"
|
|
3605
|
+
},
|
|
3606
|
+
children: t("modules.form.publicPolicies.policyTitle")
|
|
3607
|
+
}
|
|
3608
|
+
),
|
|
3609
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3610
|
+
import_material9.IconButton,
|
|
3611
|
+
{
|
|
3612
|
+
onClick: onRemove,
|
|
3613
|
+
size: "small",
|
|
3614
|
+
disabled: isSubmitting,
|
|
3615
|
+
"aria-label": t("modules.form.publicPolicies.removePolicy"),
|
|
3616
|
+
sx: {
|
|
3617
|
+
color: "#656d76",
|
|
3618
|
+
"&:hover": {
|
|
3619
|
+
color: "#cf222e",
|
|
3620
|
+
backgroundColor: "rgba(207, 34, 46, 0.1)"
|
|
3621
|
+
}
|
|
3622
|
+
},
|
|
3623
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material3.Delete, {})
|
|
3624
|
+
}
|
|
3625
|
+
)
|
|
3626
|
+
] }),
|
|
3627
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Stack, { spacing: 3, children: [
|
|
3628
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Stack, { direction: { xs: "column", md: "row" }, spacing: 2, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Box, { sx: { flex: 1, minWidth: 200 }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.FormControl, { fullWidth: true, children: [
|
|
3629
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.InputLabel, { children: t("modules.form.publicPolicies.fields.action.label") }),
|
|
3630
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3631
|
+
import_material9.Select,
|
|
3632
|
+
{
|
|
3633
|
+
value: policy.action,
|
|
3634
|
+
label: t("modules.form.publicPolicies.fields.action.label"),
|
|
3635
|
+
disabled: isSubmitting,
|
|
3636
|
+
onChange: (e) => {
|
|
3637
|
+
const newAction = e.target.value;
|
|
3638
|
+
const next = { ...policy, action: newAction };
|
|
3639
|
+
if (newAction === "delete") {
|
|
3640
|
+
next.permission = "deny";
|
|
3641
|
+
delete next.fields;
|
|
3642
|
+
} else {
|
|
3643
|
+
next.fields = { allow: [], owner_allow: [], deny: availableFields };
|
|
3644
|
+
delete next.permission;
|
|
3645
|
+
}
|
|
3646
|
+
onChange(next);
|
|
3647
|
+
},
|
|
3648
|
+
sx: {
|
|
3649
|
+
backgroundColor: "#ffffff",
|
|
3650
|
+
"&:hover .MuiOutlinedInput-notchedOutline": {
|
|
3651
|
+
borderColor: "#8c959f"
|
|
3652
|
+
},
|
|
3653
|
+
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
|
|
3654
|
+
borderColor: "#0969da",
|
|
3655
|
+
borderWidth: 2
|
|
3656
|
+
}
|
|
3657
|
+
},
|
|
3658
|
+
children: actionOptions.map((option) => {
|
|
3659
|
+
const disabledOption = takenActions.has(option.value);
|
|
3660
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.MenuItem, { value: option.value, disabled: disabledOption, children: option.label }, option.value);
|
|
3661
|
+
})
|
|
3662
|
+
}
|
|
3663
|
+
),
|
|
3664
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.FormHelperText, { error: true, children: error })
|
|
3665
|
+
] }) }) }),
|
|
3666
|
+
policy.action === "delete" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { children: [
|
|
3667
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t("modules.form.publicPolicies.fields.conditions.label") }),
|
|
3668
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Stack, { direction: "row", spacing: 1, sx: { mb: 3 }, children: [
|
|
3669
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3670
|
+
import_material9.Button,
|
|
3671
|
+
{
|
|
3672
|
+
variant: policy.permission === "*" ? "contained" : "outlined",
|
|
3673
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material3.SelectAll, {}),
|
|
3674
|
+
onClick: () => onChange({ ...policy, permission: "*" }),
|
|
3675
|
+
disabled: isSubmitting,
|
|
3676
|
+
size: "small",
|
|
3677
|
+
sx: {
|
|
3678
|
+
minWidth: 140,
|
|
3679
|
+
whiteSpace: "nowrap",
|
|
3680
|
+
...policy.permission === "*" && {
|
|
3681
|
+
backgroundColor: "#16a34a",
|
|
3682
|
+
"&:hover": { backgroundColor: "#15803d" }
|
|
3683
|
+
}
|
|
3684
|
+
},
|
|
3685
|
+
children: t("modules.form.publicPolicies.fields.conditions.allFields")
|
|
3686
|
+
}
|
|
3687
|
+
),
|
|
3688
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3689
|
+
import_material9.Button,
|
|
3690
|
+
{
|
|
3691
|
+
variant: policy.permission === "owner" ? "contained" : "outlined",
|
|
3692
|
+
onClick: () => onChange({ ...policy, permission: "owner" }),
|
|
3693
|
+
disabled: isSubmitting,
|
|
3694
|
+
size: "small",
|
|
3695
|
+
sx: {
|
|
3696
|
+
minWidth: 140,
|
|
3697
|
+
whiteSpace: "nowrap",
|
|
3698
|
+
...policy.permission === "owner" && {
|
|
3699
|
+
backgroundColor: "#0ea5e9",
|
|
3700
|
+
"&:hover": { backgroundColor: "#0284c7" }
|
|
3701
|
+
}
|
|
3702
|
+
},
|
|
3703
|
+
children: t("modules.form.publicPolicies.fields.conditions.states.ownerAllow")
|
|
3704
|
+
}
|
|
3705
|
+
),
|
|
3706
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3707
|
+
import_material9.Button,
|
|
3708
|
+
{
|
|
3709
|
+
variant: policy.permission === "deny" ? "contained" : "outlined",
|
|
3710
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material3.ClearAll, {}),
|
|
3711
|
+
onClick: () => onChange({ ...policy, permission: "deny" }),
|
|
3712
|
+
disabled: isSubmitting,
|
|
3713
|
+
size: "small",
|
|
3714
|
+
sx: {
|
|
3715
|
+
minWidth: 140,
|
|
3716
|
+
whiteSpace: "nowrap",
|
|
3717
|
+
...policy.permission === "deny" && {
|
|
3718
|
+
backgroundColor: "#cf222e",
|
|
3719
|
+
"&:hover": { backgroundColor: "#bc1f2c" }
|
|
3720
|
+
}
|
|
3721
|
+
},
|
|
3722
|
+
children: t("modules.form.publicPolicies.fields.conditions.noFields")
|
|
3723
|
+
}
|
|
3724
|
+
)
|
|
3725
|
+
] })
|
|
3726
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3727
|
+
FieldSelector_default,
|
|
3728
|
+
{
|
|
3729
|
+
value: policy.fields || { allow: [], owner_allow: [], deny: [] },
|
|
3730
|
+
onChange: (nextFields) => onChange({ ...policy, fields: nextFields }),
|
|
3731
|
+
availableFields,
|
|
3732
|
+
disabled: isSubmitting
|
|
3733
|
+
}
|
|
3734
|
+
),
|
|
3735
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Paper, { variant: "outlined", sx: { p: 2, backgroundColor: "#f9fafb" }, children: policy.action === "delete" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3736
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { component: "span", sx: {
|
|
3737
|
+
color: policy.permission === "*" ? "#16a34a" : policy.permission === "owner" ? "#0ea5e9" : "#dc2626"
|
|
3738
|
+
}, children: [
|
|
3739
|
+
t("modules.form.publicPolicies.fields.conditions.states.allow"),
|
|
3740
|
+
":"
|
|
3741
|
+
] }),
|
|
3742
|
+
" ",
|
|
3743
|
+
policy.permission || "-"
|
|
3744
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Stack, { spacing: 0.5, divider: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Divider, { sx: { borderColor: "#e5e7eb" } }), children: [
|
|
3745
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3746
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { component: "span", sx: { color: "#16a34a" }, children: [
|
|
3747
|
+
t("modules.form.publicPolicies.fields.conditions.states.allow"),
|
|
3748
|
+
":"
|
|
3749
|
+
] }),
|
|
3750
|
+
" ",
|
|
3751
|
+
(policy?.fields?.allow || []).join(", ") || "-"
|
|
3752
|
+
] }),
|
|
3753
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3754
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { component: "span", sx: { color: "#0ea5e9" }, children: [
|
|
3755
|
+
t("modules.form.publicPolicies.fields.conditions.states.ownerAllow"),
|
|
3756
|
+
":"
|
|
3757
|
+
] }),
|
|
3758
|
+
" ",
|
|
3759
|
+
(policy?.fields?.owner_allow || []).join(", ") || "-"
|
|
3760
|
+
] }),
|
|
3761
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3762
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { component: "span", sx: { color: "#dc2626" }, children: [
|
|
3763
|
+
t("modules.form.publicPolicies.fields.conditions.states.deny"),
|
|
3764
|
+
":"
|
|
3765
|
+
] }),
|
|
3766
|
+
" ",
|
|
3767
|
+
(policy?.fields?.deny || []).join(", ") || "-"
|
|
3768
|
+
] })
|
|
3769
|
+
] }) })
|
|
3770
|
+
] })
|
|
3771
|
+
]
|
|
3772
|
+
}
|
|
3773
|
+
);
|
|
3774
|
+
});
|
|
3775
|
+
var PolicyItem_default = PolicyItem;
|
|
3776
|
+
|
|
3777
|
+
// src/components/PublicPolicies/Policies.tsx
|
|
3778
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
3779
|
+
var generateId = () => {
|
|
3780
|
+
const c = globalThis?.crypto;
|
|
3781
|
+
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
3782
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
3783
|
+
};
|
|
3784
|
+
var Policies = ({
|
|
3785
|
+
policies,
|
|
3786
|
+
onChange,
|
|
3787
|
+
availableFields,
|
|
3788
|
+
errors,
|
|
3789
|
+
isSubmitting = false
|
|
3790
|
+
}) => {
|
|
3791
|
+
const { t } = (0, import_react_i18next3.useTranslation)();
|
|
3792
|
+
const policyRefs = (0, import_react15.useRef)({});
|
|
3793
|
+
const takenActions = new Set((policies || []).map((p) => p.action).filter(Boolean));
|
|
3794
|
+
const remainingActions = PREFERRED_POLICY_ORDER.filter((a) => !takenActions.has(a));
|
|
3795
|
+
const canAddPolicy = remainingActions.length > 0;
|
|
3796
|
+
const addPolicy = () => {
|
|
3797
|
+
const defaultAction = remainingActions[0] || "create";
|
|
3798
|
+
const newPolicy = {
|
|
3799
|
+
id: generateId(),
|
|
3800
|
+
action: defaultAction
|
|
3801
|
+
};
|
|
3802
|
+
if (defaultAction === "delete") {
|
|
3803
|
+
newPolicy.permission = "deny";
|
|
3804
|
+
} else {
|
|
3805
|
+
newPolicy.fields = {
|
|
3806
|
+
allow: [],
|
|
3807
|
+
owner_allow: [],
|
|
3808
|
+
deny: availableFields
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
const next = [...policies || [], newPolicy];
|
|
3812
|
+
onChange(next);
|
|
3813
|
+
setTimeout(() => {
|
|
3814
|
+
const newIndex = next.length - 1;
|
|
3815
|
+
const el = policyRefs.current[newIndex];
|
|
3816
|
+
if (el) {
|
|
3817
|
+
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
3818
|
+
}
|
|
3819
|
+
}, 100);
|
|
3820
|
+
};
|
|
3821
|
+
const removePolicy = (index) => {
|
|
3822
|
+
const next = [...policies];
|
|
3823
|
+
next.splice(index, 1);
|
|
3824
|
+
onChange(next);
|
|
3825
|
+
};
|
|
3826
|
+
const arrayError = (() => {
|
|
3827
|
+
if (!errors) return null;
|
|
3828
|
+
if (typeof errors === "string") return errors;
|
|
3829
|
+
const msg = errors._error;
|
|
3830
|
+
return typeof msg === "string" ? msg : null;
|
|
3831
|
+
})();
|
|
3832
|
+
const usedActions = new Set((policies || []).map((p) => p.action));
|
|
3833
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
3834
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Divider, { sx: { borderColor: "#e0e4e7" } }),
|
|
3835
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { children: [
|
|
3836
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Box, { display: "flex", justifyContent: "space-between", alignItems: "center", mb: 3, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { children: [
|
|
3837
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3838
|
+
import_material10.Typography,
|
|
3839
|
+
{
|
|
3840
|
+
variant: "h6",
|
|
3841
|
+
sx: {
|
|
3842
|
+
fontWeight: 600,
|
|
3843
|
+
color: "#111418",
|
|
3844
|
+
mb: 1
|
|
3845
|
+
},
|
|
3846
|
+
children: t("modules.form.publicPolicies.title")
|
|
3847
|
+
}
|
|
3848
|
+
),
|
|
3849
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3850
|
+
import_material10.Typography,
|
|
3851
|
+
{
|
|
3852
|
+
variant: "body2",
|
|
3853
|
+
color: "text.secondary",
|
|
3854
|
+
sx: { fontSize: "0.875rem" },
|
|
3855
|
+
children: t("modules.form.publicPolicies.description")
|
|
3856
|
+
}
|
|
3857
|
+
)
|
|
3858
|
+
] }) }),
|
|
3859
|
+
arrayError && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Alert, { severity: "error", sx: { mb: 3 }, children: arrayError }),
|
|
3860
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Stack, { spacing: 3, children: [
|
|
3861
|
+
(policies || []).length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Alert, { severity: "info", children: t("modules.form.publicPolicies.noPolicies") }) : policies.map((policy, index) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3862
|
+
PolicyItem_default,
|
|
3863
|
+
{
|
|
3864
|
+
ref: (el) => {
|
|
3865
|
+
policyRefs.current[index] = el;
|
|
3866
|
+
},
|
|
3867
|
+
policy,
|
|
3868
|
+
onChange: (nextPolicy) => {
|
|
3869
|
+
const next = [...policies];
|
|
3870
|
+
next[index] = nextPolicy;
|
|
3871
|
+
onChange(next);
|
|
3872
|
+
},
|
|
3873
|
+
onRemove: () => removePolicy(index),
|
|
3874
|
+
availableFields,
|
|
3875
|
+
isSubmitting,
|
|
3876
|
+
usedActions,
|
|
3877
|
+
error: typeof errors === "object" && errors && policy.id in errors ? errors[policy.id] : void 0
|
|
3878
|
+
},
|
|
3879
|
+
policy.id
|
|
3880
|
+
)),
|
|
3881
|
+
canAddPolicy && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3882
|
+
import_material10.Button,
|
|
3883
|
+
{
|
|
3884
|
+
type: "button",
|
|
3885
|
+
variant: "outlined",
|
|
3886
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons_material4.Add, {}),
|
|
3887
|
+
onClick: addPolicy,
|
|
3888
|
+
disabled: isSubmitting,
|
|
3889
|
+
sx: {
|
|
3890
|
+
borderColor: "#d0d7de",
|
|
3891
|
+
color: "#656d76",
|
|
3892
|
+
"&:hover": {
|
|
3893
|
+
borderColor: "#8c959f",
|
|
3894
|
+
backgroundColor: "transparent"
|
|
3895
|
+
}
|
|
3896
|
+
},
|
|
3897
|
+
children: t("modules.form.publicPolicies.addPolicy")
|
|
3898
|
+
}
|
|
3899
|
+
) })
|
|
3900
|
+
] })
|
|
3901
|
+
] })
|
|
3902
|
+
] });
|
|
3903
|
+
};
|
|
3904
|
+
var Policies_default = Policies;
|
|
3905
|
+
|
|
3324
3906
|
// src/index.ts
|
|
3325
3907
|
init_CrudifyDataProvider();
|
|
3326
3908
|
|
|
3327
3909
|
// src/hooks/useCrudifyUser.ts
|
|
3328
|
-
var
|
|
3910
|
+
var import_react16 = require("react");
|
|
3329
3911
|
var import_crudify_browser5 = __toESM(require("@nocios/crudify-browser"));
|
|
3330
3912
|
init_CrudifyDataProvider();
|
|
3331
3913
|
var useCrudifyUser = (options = {}) => {
|
|
3332
3914
|
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
3333
3915
|
const { isAuthenticated, isInitialized, user: jwtUser, token } = useCrudifyDataContext();
|
|
3334
|
-
const [userData, setUserData] = (0,
|
|
3335
|
-
const [loading, setLoading] = (0,
|
|
3336
|
-
const [error, setError] = (0,
|
|
3337
|
-
const abortControllerRef = (0,
|
|
3338
|
-
const mountedRef = (0,
|
|
3339
|
-
const requestIdRef = (0,
|
|
3340
|
-
const retryCountRef = (0,
|
|
3341
|
-
const getUserEmailFromJWT = (0,
|
|
3916
|
+
const [userData, setUserData] = (0, import_react16.useState)(null);
|
|
3917
|
+
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
3918
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
3919
|
+
const abortControllerRef = (0, import_react16.useRef)(null);
|
|
3920
|
+
const mountedRef = (0, import_react16.useRef)(true);
|
|
3921
|
+
const requestIdRef = (0, import_react16.useRef)(0);
|
|
3922
|
+
const retryCountRef = (0, import_react16.useRef)(0);
|
|
3923
|
+
const getUserEmailFromJWT = (0, import_react16.useCallback)(() => {
|
|
3342
3924
|
if (!jwtUser) return null;
|
|
3343
3925
|
return jwtUser.email || jwtUser["cognito:username"] || null;
|
|
3344
3926
|
}, [jwtUser]);
|
|
3345
|
-
const clearProfile = (0,
|
|
3927
|
+
const clearProfile = (0, import_react16.useCallback)(() => {
|
|
3346
3928
|
setUserData(null);
|
|
3347
3929
|
setError(null);
|
|
3348
3930
|
setLoading(false);
|
|
3349
3931
|
retryCountRef.current = 0;
|
|
3350
3932
|
}, []);
|
|
3351
|
-
const refreshProfile = (0,
|
|
3933
|
+
const refreshProfile = (0, import_react16.useCallback)(async () => {
|
|
3352
3934
|
const userEmail = getUserEmailFromJWT();
|
|
3353
3935
|
console.log("\u{1F464} useCrudifyUser - Refreshing profile for:", userEmail);
|
|
3354
3936
|
if (!userEmail) {
|
|
@@ -3480,14 +4062,14 @@ var useCrudifyUser = (options = {}) => {
|
|
|
3480
4062
|
}
|
|
3481
4063
|
}
|
|
3482
4064
|
}, [isInitialized, getUserEmailFromJWT, retryOnError, maxRetries]);
|
|
3483
|
-
(0,
|
|
4065
|
+
(0, import_react16.useEffect)(() => {
|
|
3484
4066
|
if (autoFetch && isAuthenticated && isInitialized) {
|
|
3485
4067
|
refreshProfile();
|
|
3486
4068
|
} else if (!isAuthenticated) {
|
|
3487
4069
|
clearProfile();
|
|
3488
4070
|
}
|
|
3489
4071
|
}, [autoFetch, isAuthenticated, isInitialized, refreshProfile, clearProfile]);
|
|
3490
|
-
(0,
|
|
4072
|
+
(0, import_react16.useEffect)(() => {
|
|
3491
4073
|
mountedRef.current = true;
|
|
3492
4074
|
return () => {
|
|
3493
4075
|
mountedRef.current = false;
|
|
@@ -3511,7 +4093,7 @@ var useCrudifyUser = (options = {}) => {
|
|
|
3511
4093
|
};
|
|
3512
4094
|
|
|
3513
4095
|
// src/hooks/useCrudifyData.ts
|
|
3514
|
-
var
|
|
4096
|
+
var import_react17 = require("react");
|
|
3515
4097
|
var import_crudify_browser6 = __toESM(require("@nocios/crudify-browser"));
|
|
3516
4098
|
init_CrudifyDataProvider();
|
|
3517
4099
|
var useCrudifyData = () => {
|
|
@@ -3520,10 +4102,10 @@ var useCrudifyData = () => {
|
|
|
3520
4102
|
isInitializing,
|
|
3521
4103
|
initializationError
|
|
3522
4104
|
} = useCrudifyDataContext();
|
|
3523
|
-
const isReady = (0,
|
|
4105
|
+
const isReady = (0, import_react17.useCallback)(() => {
|
|
3524
4106
|
return isInitialized && !initializationError && !isInitializing;
|
|
3525
4107
|
}, [isInitialized, initializationError, isInitializing]);
|
|
3526
|
-
const waitForReady = (0,
|
|
4108
|
+
const waitForReady = (0, import_react17.useCallback)(async () => {
|
|
3527
4109
|
if (isReady()) return;
|
|
3528
4110
|
if (initializationError) {
|
|
3529
4111
|
throw new Error(`Crudify initialization failed: ${initializationError}`);
|
|
@@ -3547,13 +4129,13 @@ var useCrudifyData = () => {
|
|
|
3547
4129
|
check();
|
|
3548
4130
|
});
|
|
3549
4131
|
}, [isReady, initializationError]);
|
|
3550
|
-
const ensureReady = (0,
|
|
4132
|
+
const ensureReady = (0, import_react17.useCallback)((operationName) => {
|
|
3551
4133
|
if (!isReady()) {
|
|
3552
4134
|
const error = initializationError ? `Crudify initialization failed: ${initializationError}` : isInitializing ? "Crudify is still initializing. Please wait." : "Crudify is not initialized";
|
|
3553
4135
|
throw new Error(`Cannot perform ${operationName}: ${error}`);
|
|
3554
4136
|
}
|
|
3555
4137
|
}, [isReady, initializationError, isInitializing]);
|
|
3556
|
-
const readItems = (0,
|
|
4138
|
+
const readItems = (0, import_react17.useCallback)(async (moduleKey, filter, options) => {
|
|
3557
4139
|
ensureReady("readItems");
|
|
3558
4140
|
console.log("\u{1F4CA} useCrudifyData - readItems called with:");
|
|
3559
4141
|
console.log(" - moduleKey:", moduleKey);
|
|
@@ -3572,7 +4154,7 @@ var useCrudifyData = () => {
|
|
|
3572
4154
|
throw error;
|
|
3573
4155
|
}
|
|
3574
4156
|
}, [ensureReady]);
|
|
3575
|
-
const readItem = (0,
|
|
4157
|
+
const readItem = (0, import_react17.useCallback)(async (moduleKey, filter, options) => {
|
|
3576
4158
|
ensureReady("readItem");
|
|
3577
4159
|
console.log("\u{1F4CA} useCrudifyData - readItem:", { moduleKey, filter, options });
|
|
3578
4160
|
try {
|
|
@@ -3584,7 +4166,7 @@ var useCrudifyData = () => {
|
|
|
3584
4166
|
throw error;
|
|
3585
4167
|
}
|
|
3586
4168
|
}, [ensureReady]);
|
|
3587
|
-
const createItem = (0,
|
|
4169
|
+
const createItem = (0, import_react17.useCallback)(async (moduleKey, data, options) => {
|
|
3588
4170
|
ensureReady("createItem");
|
|
3589
4171
|
console.log("\u{1F4CA} useCrudifyData - createItem:", { moduleKey, data, options });
|
|
3590
4172
|
try {
|
|
@@ -3596,7 +4178,7 @@ var useCrudifyData = () => {
|
|
|
3596
4178
|
throw error;
|
|
3597
4179
|
}
|
|
3598
4180
|
}, [ensureReady]);
|
|
3599
|
-
const updateItem = (0,
|
|
4181
|
+
const updateItem = (0, import_react17.useCallback)(async (moduleKey, data, options) => {
|
|
3600
4182
|
ensureReady("updateItem");
|
|
3601
4183
|
console.log("\u{1F4CA} useCrudifyData - updateItem:", { moduleKey, data, options });
|
|
3602
4184
|
try {
|
|
@@ -3608,7 +4190,7 @@ var useCrudifyData = () => {
|
|
|
3608
4190
|
throw error;
|
|
3609
4191
|
}
|
|
3610
4192
|
}, [ensureReady]);
|
|
3611
|
-
const deleteItem = (0,
|
|
4193
|
+
const deleteItem = (0, import_react17.useCallback)(async (moduleKey, id, options) => {
|
|
3612
4194
|
ensureReady("deleteItem");
|
|
3613
4195
|
console.log("\u{1F4CA} useCrudifyData - deleteItem:", { moduleKey, id, options });
|
|
3614
4196
|
try {
|
|
@@ -3620,7 +4202,7 @@ var useCrudifyData = () => {
|
|
|
3620
4202
|
throw error;
|
|
3621
4203
|
}
|
|
3622
4204
|
}, [ensureReady]);
|
|
3623
|
-
const transaction = (0,
|
|
4205
|
+
const transaction = (0, import_react17.useCallback)(async (operations, options) => {
|
|
3624
4206
|
ensureReady("transaction");
|
|
3625
4207
|
console.log("\u{1F4CA} useCrudifyData - transaction:", { operations, options });
|
|
3626
4208
|
try {
|
|
@@ -3632,7 +4214,7 @@ var useCrudifyData = () => {
|
|
|
3632
4214
|
throw error;
|
|
3633
4215
|
}
|
|
3634
4216
|
}, [ensureReady]);
|
|
3635
|
-
const login = (0,
|
|
4217
|
+
const login = (0, import_react17.useCallback)(async (email, password) => {
|
|
3636
4218
|
ensureReady("login");
|
|
3637
4219
|
console.log("\u{1F4CA} useCrudifyData - login:", { email });
|
|
3638
4220
|
try {
|
|
@@ -3665,7 +4247,7 @@ var useCrudifyData = () => {
|
|
|
3665
4247
|
};
|
|
3666
4248
|
|
|
3667
4249
|
// src/hooks/useCrudifyInstance.ts
|
|
3668
|
-
var
|
|
4250
|
+
var import_react18 = require("react");
|
|
3669
4251
|
var import_crudify_browser7 = __toESM(require("@nocios/crudify-browser"));
|
|
3670
4252
|
init_CrudifyDataProvider();
|
|
3671
4253
|
var useCrudifyInstance = () => {
|
|
@@ -3675,7 +4257,7 @@ var useCrudifyInstance = () => {
|
|
|
3675
4257
|
initializationError
|
|
3676
4258
|
} = useCrudifyDataContext();
|
|
3677
4259
|
const isReady = isInitialized && !initializationError && !isInitializing;
|
|
3678
|
-
const waitForReady = (0,
|
|
4260
|
+
const waitForReady = (0, import_react18.useCallback)(async () => {
|
|
3679
4261
|
console.log("\u{1F504} useCrudifyInstance - waitForReady: Starting wait");
|
|
3680
4262
|
console.log(" - isReady:", isReady);
|
|
3681
4263
|
console.log(" - isInitialized:", isInitialized);
|
|
@@ -3703,14 +4285,14 @@ var useCrudifyInstance = () => {
|
|
|
3703
4285
|
throw error;
|
|
3704
4286
|
}
|
|
3705
4287
|
}, [isReady, initializationError, isInitialized, isInitializing]);
|
|
3706
|
-
const ensureReady = (0,
|
|
4288
|
+
const ensureReady = (0, import_react18.useCallback)(async (operationName) => {
|
|
3707
4289
|
if (!isReady) {
|
|
3708
4290
|
console.log(`\u{1F504} useCrudifyInstance - ${operationName}: Waiting for crudify to be ready...`);
|
|
3709
4291
|
await waitForReady();
|
|
3710
4292
|
console.log(`\u2705 useCrudifyInstance - ${operationName}: Crudify is ready`);
|
|
3711
4293
|
}
|
|
3712
4294
|
}, [isReady, waitForReady]);
|
|
3713
|
-
const ensureTokenSync = (0,
|
|
4295
|
+
const ensureTokenSync = (0, import_react18.useCallback)(async () => {
|
|
3714
4296
|
console.log("\u{1F504} useCrudifyInstance - ensureTokenSync: Starting token sync check");
|
|
3715
4297
|
const { tokenManager: tokenManager2 } = await Promise.resolve().then(() => (init_TokenManager(), TokenManager_exports));
|
|
3716
4298
|
const tmToken = tokenManager2.getToken();
|
|
@@ -3725,7 +4307,7 @@ var useCrudifyInstance = () => {
|
|
|
3725
4307
|
console.log("\u{1F504} useCrudifyInstance - No token sync needed, tokens match or no token");
|
|
3726
4308
|
}
|
|
3727
4309
|
}, []);
|
|
3728
|
-
const getStructure = (0,
|
|
4310
|
+
const getStructure = (0, import_react18.useCallback)(async (options) => {
|
|
3729
4311
|
console.log("\u{1F4E1} useCrudifyInstance - getStructure: Starting");
|
|
3730
4312
|
await ensureReady("getStructure");
|
|
3731
4313
|
try {
|
|
@@ -3746,7 +4328,7 @@ var useCrudifyInstance = () => {
|
|
|
3746
4328
|
throw error;
|
|
3747
4329
|
}
|
|
3748
4330
|
}, [ensureReady, ensureTokenSync]);
|
|
3749
|
-
const getStructurePublic = (0,
|
|
4331
|
+
const getStructurePublic = (0, import_react18.useCallback)(async (options) => {
|
|
3750
4332
|
console.log("\u{1F4E1} useCrudifyInstance - getStructurePublic: Starting");
|
|
3751
4333
|
await ensureReady("getStructurePublic");
|
|
3752
4334
|
try {
|
|
@@ -3759,7 +4341,7 @@ var useCrudifyInstance = () => {
|
|
|
3759
4341
|
throw error;
|
|
3760
4342
|
}
|
|
3761
4343
|
}, [ensureReady]);
|
|
3762
|
-
const readItems = (0,
|
|
4344
|
+
const readItems = (0, import_react18.useCallback)(async (moduleKey, filter, options) => {
|
|
3763
4345
|
await ensureReady("readItems");
|
|
3764
4346
|
await ensureTokenSync();
|
|
3765
4347
|
if (moduleKey === "__test_connection__") {
|
|
@@ -3774,7 +4356,7 @@ var useCrudifyInstance = () => {
|
|
|
3774
4356
|
throw error;
|
|
3775
4357
|
}
|
|
3776
4358
|
}, [ensureReady, ensureTokenSync]);
|
|
3777
|
-
const readItem = (0,
|
|
4359
|
+
const readItem = (0, import_react18.useCallback)(async (moduleKey, filter, options) => {
|
|
3778
4360
|
await ensureReady("readItem");
|
|
3779
4361
|
try {
|
|
3780
4362
|
const response = await import_crudify_browser7.default.readItem(moduleKey, filter, options);
|
|
@@ -3784,7 +4366,7 @@ var useCrudifyInstance = () => {
|
|
|
3784
4366
|
throw error;
|
|
3785
4367
|
}
|
|
3786
4368
|
}, [ensureReady]);
|
|
3787
|
-
const createItem = (0,
|
|
4369
|
+
const createItem = (0, import_react18.useCallback)(async (moduleKey, data, options) => {
|
|
3788
4370
|
await ensureReady("createItem");
|
|
3789
4371
|
try {
|
|
3790
4372
|
const response = await import_crudify_browser7.default.createItem(moduleKey, data, options);
|
|
@@ -3794,7 +4376,7 @@ var useCrudifyInstance = () => {
|
|
|
3794
4376
|
throw error;
|
|
3795
4377
|
}
|
|
3796
4378
|
}, [ensureReady]);
|
|
3797
|
-
const updateItem = (0,
|
|
4379
|
+
const updateItem = (0, import_react18.useCallback)(async (moduleKey, data, options) => {
|
|
3798
4380
|
await ensureReady("updateItem");
|
|
3799
4381
|
try {
|
|
3800
4382
|
const response = await import_crudify_browser7.default.updateItem(moduleKey, data, options);
|
|
@@ -3804,7 +4386,7 @@ var useCrudifyInstance = () => {
|
|
|
3804
4386
|
throw error;
|
|
3805
4387
|
}
|
|
3806
4388
|
}, [ensureReady]);
|
|
3807
|
-
const deleteItem = (0,
|
|
4389
|
+
const deleteItem = (0, import_react18.useCallback)(async (moduleKey, id, options) => {
|
|
3808
4390
|
await ensureReady("deleteItem");
|
|
3809
4391
|
try {
|
|
3810
4392
|
const response = await import_crudify_browser7.default.deleteItem(moduleKey, id, options);
|
|
@@ -3814,7 +4396,7 @@ var useCrudifyInstance = () => {
|
|
|
3814
4396
|
throw error;
|
|
3815
4397
|
}
|
|
3816
4398
|
}, [ensureReady]);
|
|
3817
|
-
const transaction = (0,
|
|
4399
|
+
const transaction = (0, import_react18.useCallback)(async (operations, options) => {
|
|
3818
4400
|
await ensureReady("transaction");
|
|
3819
4401
|
try {
|
|
3820
4402
|
const response = await import_crudify_browser7.default.transaction(operations, options);
|
|
@@ -3824,7 +4406,7 @@ var useCrudifyInstance = () => {
|
|
|
3824
4406
|
throw error;
|
|
3825
4407
|
}
|
|
3826
4408
|
}, [ensureReady]);
|
|
3827
|
-
const login = (0,
|
|
4409
|
+
const login = (0, import_react18.useCallback)(async (email, password) => {
|
|
3828
4410
|
await ensureReady("login");
|
|
3829
4411
|
try {
|
|
3830
4412
|
const response = await import_crudify_browser7.default.login(email, password);
|
|
@@ -4265,9 +4847,9 @@ var SessionManager = class _SessionManager {
|
|
|
4265
4847
|
};
|
|
4266
4848
|
|
|
4267
4849
|
// src/hooks/useSession.ts
|
|
4268
|
-
var
|
|
4850
|
+
var import_react19 = require("react");
|
|
4269
4851
|
function useSession(options = {}) {
|
|
4270
|
-
const [state, setState] = (0,
|
|
4852
|
+
const [state, setState] = (0, import_react19.useState)({
|
|
4271
4853
|
isAuthenticated: false,
|
|
4272
4854
|
isLoading: true,
|
|
4273
4855
|
isInitialized: false,
|
|
@@ -4275,7 +4857,7 @@ function useSession(options = {}) {
|
|
|
4275
4857
|
error: null
|
|
4276
4858
|
});
|
|
4277
4859
|
const sessionManager = SessionManager.getInstance();
|
|
4278
|
-
const initialize = (0,
|
|
4860
|
+
const initialize = (0, import_react19.useCallback)(async () => {
|
|
4279
4861
|
try {
|
|
4280
4862
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
4281
4863
|
const config = {
|
|
@@ -4341,7 +4923,7 @@ function useSession(options = {}) {
|
|
|
4341
4923
|
}));
|
|
4342
4924
|
}
|
|
4343
4925
|
}, [options.autoRestore, options.enableLogging, options.onSessionExpired, options.onSessionRestored]);
|
|
4344
|
-
const login = (0,
|
|
4926
|
+
const login = (0, import_react19.useCallback)(async (email, password) => {
|
|
4345
4927
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
4346
4928
|
try {
|
|
4347
4929
|
const result = await sessionManager.login(email, password);
|
|
@@ -4378,7 +4960,7 @@ function useSession(options = {}) {
|
|
|
4378
4960
|
};
|
|
4379
4961
|
}
|
|
4380
4962
|
}, [sessionManager]);
|
|
4381
|
-
const logout = (0,
|
|
4963
|
+
const logout = (0, import_react19.useCallback)(async () => {
|
|
4382
4964
|
setState((prev) => ({ ...prev, isLoading: true }));
|
|
4383
4965
|
try {
|
|
4384
4966
|
await sessionManager.logout();
|
|
@@ -4399,7 +4981,7 @@ function useSession(options = {}) {
|
|
|
4399
4981
|
}));
|
|
4400
4982
|
}
|
|
4401
4983
|
}, [sessionManager]);
|
|
4402
|
-
const refreshTokens = (0,
|
|
4984
|
+
const refreshTokens = (0, import_react19.useCallback)(async () => {
|
|
4403
4985
|
try {
|
|
4404
4986
|
const success = await sessionManager.refreshTokens();
|
|
4405
4987
|
if (success) {
|
|
@@ -4433,13 +5015,13 @@ function useSession(options = {}) {
|
|
|
4433
5015
|
return false;
|
|
4434
5016
|
}
|
|
4435
5017
|
}, [sessionManager]);
|
|
4436
|
-
const clearError = (0,
|
|
5018
|
+
const clearError = (0, import_react19.useCallback)(() => {
|
|
4437
5019
|
setState((prev) => ({ ...prev, error: null }));
|
|
4438
5020
|
}, []);
|
|
4439
|
-
const getTokenInfo = (0,
|
|
5021
|
+
const getTokenInfo = (0, import_react19.useCallback)(() => {
|
|
4440
5022
|
return sessionManager.getTokenInfo();
|
|
4441
5023
|
}, [sessionManager]);
|
|
4442
|
-
(0,
|
|
5024
|
+
(0, import_react19.useEffect)(() => {
|
|
4443
5025
|
initialize();
|
|
4444
5026
|
}, [initialize]);
|
|
4445
5027
|
return {
|
|
@@ -4460,13 +5042,13 @@ function useSession(options = {}) {
|
|
|
4460
5042
|
}
|
|
4461
5043
|
|
|
4462
5044
|
// src/providers/SessionProvider.tsx
|
|
4463
|
-
var
|
|
5045
|
+
var import_react20 = require("react");
|
|
4464
5046
|
init_jwtUtils();
|
|
4465
|
-
var
|
|
4466
|
-
var SessionContext = (0,
|
|
5047
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
5048
|
+
var SessionContext = (0, import_react20.createContext)(void 0);
|
|
4467
5049
|
function SessionProvider({ children, options = {} }) {
|
|
4468
5050
|
const sessionHook = useSession(options);
|
|
4469
|
-
const sessionData = (0,
|
|
5051
|
+
const sessionData = (0, import_react20.useMemo)(() => {
|
|
4470
5052
|
if (!sessionHook.tokens?.accessToken || !sessionHook.isAuthenticated) {
|
|
4471
5053
|
return null;
|
|
4472
5054
|
}
|
|
@@ -4494,10 +5076,10 @@ function SessionProvider({ children, options = {} }) {
|
|
|
4494
5076
|
...sessionHook,
|
|
4495
5077
|
sessionData
|
|
4496
5078
|
};
|
|
4497
|
-
return /* @__PURE__ */ (0,
|
|
5079
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SessionContext.Provider, { value: contextValue, children });
|
|
4498
5080
|
}
|
|
4499
5081
|
function useSessionContext() {
|
|
4500
|
-
const context = (0,
|
|
5082
|
+
const context = (0, import_react20.useContext)(SessionContext);
|
|
4501
5083
|
if (context === void 0) {
|
|
4502
5084
|
throw new Error("useSessionContext must be used within a SessionProvider");
|
|
4503
5085
|
}
|
|
@@ -4505,28 +5087,28 @@ function useSessionContext() {
|
|
|
4505
5087
|
}
|
|
4506
5088
|
function ProtectedRoute({
|
|
4507
5089
|
children,
|
|
4508
|
-
fallback = /* @__PURE__ */ (0,
|
|
5090
|
+
fallback = /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { children: "Please log in to access this content" }),
|
|
4509
5091
|
redirectTo
|
|
4510
5092
|
}) {
|
|
4511
5093
|
const { isAuthenticated, isLoading, isInitialized } = useSessionContext();
|
|
4512
5094
|
if (!isInitialized || isLoading) {
|
|
4513
|
-
return /* @__PURE__ */ (0,
|
|
5095
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { children: "Loading..." });
|
|
4514
5096
|
}
|
|
4515
5097
|
if (!isAuthenticated) {
|
|
4516
5098
|
if (redirectTo) {
|
|
4517
5099
|
redirectTo();
|
|
4518
5100
|
return null;
|
|
4519
5101
|
}
|
|
4520
|
-
return /* @__PURE__ */ (0,
|
|
5102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: fallback });
|
|
4521
5103
|
}
|
|
4522
|
-
return /* @__PURE__ */ (0,
|
|
5104
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
4523
5105
|
}
|
|
4524
5106
|
function SessionDebugInfo() {
|
|
4525
5107
|
const session = useSessionContext();
|
|
4526
5108
|
if (!session.isInitialized) {
|
|
4527
|
-
return /* @__PURE__ */ (0,
|
|
5109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { children: "Session not initialized" });
|
|
4528
5110
|
}
|
|
4529
|
-
return /* @__PURE__ */ (0,
|
|
5111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { style: {
|
|
4530
5112
|
padding: "10px",
|
|
4531
5113
|
margin: "10px",
|
|
4532
5114
|
border: "1px solid #ccc",
|
|
@@ -4534,49 +5116,49 @@ function SessionDebugInfo() {
|
|
|
4534
5116
|
fontSize: "12px",
|
|
4535
5117
|
fontFamily: "monospace"
|
|
4536
5118
|
}, children: [
|
|
4537
|
-
/* @__PURE__ */ (0,
|
|
4538
|
-
/* @__PURE__ */ (0,
|
|
4539
|
-
/* @__PURE__ */ (0,
|
|
5119
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("h4", { children: "Session Debug Info" }),
|
|
5120
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5121
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Authenticated:" }),
|
|
4540
5122
|
" ",
|
|
4541
5123
|
session.isAuthenticated ? "Yes" : "No"
|
|
4542
5124
|
] }),
|
|
4543
|
-
/* @__PURE__ */ (0,
|
|
4544
|
-
/* @__PURE__ */ (0,
|
|
5125
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5126
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Loading:" }),
|
|
4545
5127
|
" ",
|
|
4546
5128
|
session.isLoading ? "Yes" : "No"
|
|
4547
5129
|
] }),
|
|
4548
|
-
/* @__PURE__ */ (0,
|
|
4549
|
-
/* @__PURE__ */ (0,
|
|
5130
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5131
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Error:" }),
|
|
4550
5132
|
" ",
|
|
4551
5133
|
session.error || "None"
|
|
4552
5134
|
] }),
|
|
4553
|
-
session.tokens && /* @__PURE__ */ (0,
|
|
4554
|
-
/* @__PURE__ */ (0,
|
|
4555
|
-
/* @__PURE__ */ (0,
|
|
5135
|
+
session.tokens && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
5136
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5137
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Access Token:" }),
|
|
4556
5138
|
" ",
|
|
4557
5139
|
session.tokens.accessToken.substring(0, 20),
|
|
4558
5140
|
"..."
|
|
4559
5141
|
] }),
|
|
4560
|
-
/* @__PURE__ */ (0,
|
|
4561
|
-
/* @__PURE__ */ (0,
|
|
5142
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5143
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Refresh Token:" }),
|
|
4562
5144
|
" ",
|
|
4563
5145
|
session.tokens.refreshToken.substring(0, 20),
|
|
4564
5146
|
"..."
|
|
4565
5147
|
] }),
|
|
4566
|
-
/* @__PURE__ */ (0,
|
|
4567
|
-
/* @__PURE__ */ (0,
|
|
5148
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5149
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Access Expires In:" }),
|
|
4568
5150
|
" ",
|
|
4569
5151
|
Math.round(session.expiresIn / 1e3 / 60),
|
|
4570
5152
|
" minutes"
|
|
4571
5153
|
] }),
|
|
4572
|
-
/* @__PURE__ */ (0,
|
|
4573
|
-
/* @__PURE__ */ (0,
|
|
5154
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5155
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Refresh Expires In:" }),
|
|
4574
5156
|
" ",
|
|
4575
5157
|
Math.round(session.refreshExpiresIn / 1e3 / 60 / 60),
|
|
4576
5158
|
" hours"
|
|
4577
5159
|
] }),
|
|
4578
|
-
/* @__PURE__ */ (0,
|
|
4579
|
-
/* @__PURE__ */ (0,
|
|
5160
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
|
|
5161
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Expiring Soon:" }),
|
|
4580
5162
|
" ",
|
|
4581
5163
|
session.isExpiringSoon ? "Yes" : "No"
|
|
4582
5164
|
] })
|
|
@@ -4585,13 +5167,13 @@ function SessionDebugInfo() {
|
|
|
4585
5167
|
}
|
|
4586
5168
|
|
|
4587
5169
|
// src/components/LoginComponent.tsx
|
|
4588
|
-
var
|
|
4589
|
-
var
|
|
4590
|
-
var
|
|
5170
|
+
var import_react21 = require("react");
|
|
5171
|
+
var import_material11 = require("@mui/material");
|
|
5172
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
4591
5173
|
function LoginComponent() {
|
|
4592
|
-
const [email, setEmail] = (0,
|
|
4593
|
-
const [password, setPassword] = (0,
|
|
4594
|
-
const [showForm, setShowForm] = (0,
|
|
5174
|
+
const [email, setEmail] = (0, import_react21.useState)("");
|
|
5175
|
+
const [password, setPassword] = (0, import_react21.useState)("");
|
|
5176
|
+
const [showForm, setShowForm] = (0, import_react21.useState)(false);
|
|
4595
5177
|
const {
|
|
4596
5178
|
isAuthenticated,
|
|
4597
5179
|
isLoading,
|
|
@@ -4622,31 +5204,31 @@ function LoginComponent() {
|
|
|
4622
5204
|
await refreshTokens();
|
|
4623
5205
|
};
|
|
4624
5206
|
if (isAuthenticated) {
|
|
4625
|
-
return /* @__PURE__ */ (0,
|
|
4626
|
-
/* @__PURE__ */ (0,
|
|
4627
|
-
/* @__PURE__ */ (0,
|
|
4628
|
-
/* @__PURE__ */ (0,
|
|
4629
|
-
/* @__PURE__ */ (0,
|
|
4630
|
-
/* @__PURE__ */ (0,
|
|
5207
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Box, { sx: { maxWidth: 600, mx: "auto", p: 3 }, children: [
|
|
5208
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Typography, { variant: "h4", gutterBottom: true, children: "Welcome! \u{1F389}" }),
|
|
5209
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Alert, { severity: "success", sx: { mb: 3 }, children: "You are successfully logged in with Refresh Token Pattern enabled" }),
|
|
5210
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Box, { sx: { mb: 3, p: 2, bgcolor: "background.paper", border: 1, borderColor: "divider", borderRadius: 1 }, children: [
|
|
5211
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Typography, { variant: "h6", gutterBottom: true, children: "Token Status" }),
|
|
5212
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Typography, { variant: "body2", color: "text.secondary", children: [
|
|
4631
5213
|
"Access Token expires in: ",
|
|
4632
5214
|
Math.round(expiresIn / 1e3 / 60),
|
|
4633
5215
|
" minutes"
|
|
4634
5216
|
] }),
|
|
4635
|
-
isExpiringSoon && /* @__PURE__ */ (0,
|
|
5217
|
+
isExpiringSoon && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Alert, { severity: "warning", sx: { mt: 1 }, children: "Token expires soon - automatic refresh will happen" })
|
|
4636
5218
|
] }),
|
|
4637
|
-
/* @__PURE__ */ (0,
|
|
4638
|
-
/* @__PURE__ */ (0,
|
|
4639
|
-
|
|
5219
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Box, { sx: { display: "flex", gap: 2, flexWrap: "wrap" }, children: [
|
|
5220
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5221
|
+
import_material11.Button,
|
|
4640
5222
|
{
|
|
4641
5223
|
variant: "contained",
|
|
4642
5224
|
onClick: handleRefreshTokens,
|
|
4643
5225
|
disabled: isLoading,
|
|
4644
|
-
startIcon: isLoading ? /* @__PURE__ */ (0,
|
|
5226
|
+
startIcon: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.CircularProgress, { size: 16 }) : null,
|
|
4645
5227
|
children: "Refresh Tokens"
|
|
4646
5228
|
}
|
|
4647
5229
|
),
|
|
4648
|
-
/* @__PURE__ */ (0,
|
|
4649
|
-
|
|
5230
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5231
|
+
import_material11.Button,
|
|
4650
5232
|
{
|
|
4651
5233
|
variant: "outlined",
|
|
4652
5234
|
color: "error",
|
|
@@ -4656,14 +5238,14 @@ function LoginComponent() {
|
|
|
4656
5238
|
}
|
|
4657
5239
|
)
|
|
4658
5240
|
] }),
|
|
4659
|
-
error && /* @__PURE__ */ (0,
|
|
5241
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Alert, { severity: "error", sx: { mt: 2 }, onClose: clearError, children: error })
|
|
4660
5242
|
] });
|
|
4661
5243
|
}
|
|
4662
|
-
return /* @__PURE__ */ (0,
|
|
4663
|
-
/* @__PURE__ */ (0,
|
|
4664
|
-
/* @__PURE__ */ (0,
|
|
4665
|
-
!showForm ? /* @__PURE__ */ (0,
|
|
4666
|
-
|
|
5244
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Box, { sx: { maxWidth: 400, mx: "auto", p: 3 }, children: [
|
|
5245
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Typography, { variant: "h4", gutterBottom: true, align: "center", children: "Login with Refresh Tokens" }),
|
|
5246
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Alert, { severity: "info", sx: { mb: 3 }, children: "This demo shows the new Refresh Token Pattern with automatic session management" }),
|
|
5247
|
+
!showForm ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5248
|
+
import_material11.Button,
|
|
4667
5249
|
{
|
|
4668
5250
|
fullWidth: true,
|
|
4669
5251
|
variant: "contained",
|
|
@@ -4672,9 +5254,9 @@ function LoginComponent() {
|
|
|
4672
5254
|
sx: { mt: 2 },
|
|
4673
5255
|
children: "Show Login Form"
|
|
4674
5256
|
}
|
|
4675
|
-
) : /* @__PURE__ */ (0,
|
|
4676
|
-
/* @__PURE__ */ (0,
|
|
4677
|
-
|
|
5257
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("form", { onSubmit: handleLogin, children: [
|
|
5258
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5259
|
+
import_material11.TextField,
|
|
4678
5260
|
{
|
|
4679
5261
|
fullWidth: true,
|
|
4680
5262
|
label: "Email",
|
|
@@ -4686,8 +5268,8 @@ function LoginComponent() {
|
|
|
4686
5268
|
autoComplete: "email"
|
|
4687
5269
|
}
|
|
4688
5270
|
),
|
|
4689
|
-
/* @__PURE__ */ (0,
|
|
4690
|
-
|
|
5271
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5272
|
+
import_material11.TextField,
|
|
4691
5273
|
{
|
|
4692
5274
|
fullWidth: true,
|
|
4693
5275
|
label: "Password",
|
|
@@ -4699,37 +5281,37 @@ function LoginComponent() {
|
|
|
4699
5281
|
autoComplete: "current-password"
|
|
4700
5282
|
}
|
|
4701
5283
|
),
|
|
4702
|
-
/* @__PURE__ */ (0,
|
|
4703
|
-
|
|
5284
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5285
|
+
import_material11.Button,
|
|
4704
5286
|
{
|
|
4705
5287
|
type: "submit",
|
|
4706
5288
|
fullWidth: true,
|
|
4707
5289
|
variant: "contained",
|
|
4708
5290
|
size: "large",
|
|
4709
5291
|
disabled: isLoading,
|
|
4710
|
-
startIcon: isLoading ? /* @__PURE__ */ (0,
|
|
5292
|
+
startIcon: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.CircularProgress, { size: 16 }) : null,
|
|
4711
5293
|
sx: { mt: 3, mb: 2 },
|
|
4712
5294
|
children: isLoading ? "Logging in..." : "Login"
|
|
4713
5295
|
}
|
|
4714
5296
|
)
|
|
4715
5297
|
] }),
|
|
4716
|
-
error && /* @__PURE__ */ (0,
|
|
5298
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Alert, { severity: "error", sx: { mt: 2 }, onClose: clearError, children: error })
|
|
4717
5299
|
] });
|
|
4718
5300
|
}
|
|
4719
5301
|
function SessionStatus() {
|
|
4720
5302
|
const { isAuthenticated, isLoading, isExpiringSoon, expiresIn } = useSessionContext();
|
|
4721
5303
|
if (isLoading) {
|
|
4722
|
-
return /* @__PURE__ */ (0,
|
|
4723
|
-
/* @__PURE__ */ (0,
|
|
4724
|
-
/* @__PURE__ */ (0,
|
|
5304
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
5305
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.CircularProgress, { size: 16 }),
|
|
5306
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Typography, { variant: "caption", children: "Loading session..." })
|
|
4725
5307
|
] });
|
|
4726
5308
|
}
|
|
4727
5309
|
if (!isAuthenticated) {
|
|
4728
|
-
return /* @__PURE__ */ (0,
|
|
5310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Typography, { variant: "caption", color: "text.secondary", children: "Not logged in" });
|
|
4729
5311
|
}
|
|
4730
|
-
return /* @__PURE__ */ (0,
|
|
4731
|
-
/* @__PURE__ */ (0,
|
|
4732
|
-
isExpiringSoon && /* @__PURE__ */ (0,
|
|
5312
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Box, { children: [
|
|
5313
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material11.Typography, { variant: "caption", color: "success.main", children: "\u2713 Authenticated" }),
|
|
5314
|
+
isExpiringSoon && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material11.Typography, { variant: "caption", color: "warning.main", display: "block", children: [
|
|
4733
5315
|
"\u26A0 Token expires in ",
|
|
4734
5316
|
Math.round(expiresIn / 1e3 / 60),
|
|
4735
5317
|
" min"
|
|
@@ -4738,29 +5320,29 @@ function SessionStatus() {
|
|
|
4738
5320
|
}
|
|
4739
5321
|
|
|
4740
5322
|
// src/hooks/useUserData.ts
|
|
4741
|
-
var
|
|
5323
|
+
var import_react22 = require("react");
|
|
4742
5324
|
var import_crudify_browser9 = __toESM(require("@nocios/crudify-browser"));
|
|
4743
5325
|
var useUserData = (options = {}) => {
|
|
4744
5326
|
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
4745
5327
|
const { isAuthenticated, isInitialized, sessionData, tokens } = useSessionContext();
|
|
4746
|
-
const [userData, setUserData] = (0,
|
|
4747
|
-
const [loading, setLoading] = (0,
|
|
4748
|
-
const [error, setError] = (0,
|
|
4749
|
-
const abortControllerRef = (0,
|
|
4750
|
-
const mountedRef = (0,
|
|
4751
|
-
const requestIdRef = (0,
|
|
4752
|
-
const retryCountRef = (0,
|
|
4753
|
-
const getUserEmail = (0,
|
|
5328
|
+
const [userData, setUserData] = (0, import_react22.useState)(null);
|
|
5329
|
+
const [loading, setLoading] = (0, import_react22.useState)(false);
|
|
5330
|
+
const [error, setError] = (0, import_react22.useState)(null);
|
|
5331
|
+
const abortControllerRef = (0, import_react22.useRef)(null);
|
|
5332
|
+
const mountedRef = (0, import_react22.useRef)(true);
|
|
5333
|
+
const requestIdRef = (0, import_react22.useRef)(0);
|
|
5334
|
+
const retryCountRef = (0, import_react22.useRef)(0);
|
|
5335
|
+
const getUserEmail = (0, import_react22.useCallback)(() => {
|
|
4754
5336
|
if (!sessionData) return null;
|
|
4755
5337
|
return sessionData.email || sessionData["cognito:username"] || null;
|
|
4756
5338
|
}, [sessionData]);
|
|
4757
|
-
const clearProfile = (0,
|
|
5339
|
+
const clearProfile = (0, import_react22.useCallback)(() => {
|
|
4758
5340
|
setUserData(null);
|
|
4759
5341
|
setError(null);
|
|
4760
5342
|
setLoading(false);
|
|
4761
5343
|
retryCountRef.current = 0;
|
|
4762
5344
|
}, []);
|
|
4763
|
-
const refreshProfile = (0,
|
|
5345
|
+
const refreshProfile = (0, import_react22.useCallback)(async () => {
|
|
4764
5346
|
const userEmail = getUserEmail();
|
|
4765
5347
|
console.log("\u{1F464} useUserData - Refreshing profile for:", userEmail);
|
|
4766
5348
|
if (!userEmail) {
|
|
@@ -4892,14 +5474,14 @@ var useUserData = (options = {}) => {
|
|
|
4892
5474
|
}
|
|
4893
5475
|
}
|
|
4894
5476
|
}, [isInitialized, getUserEmail, retryOnError, maxRetries]);
|
|
4895
|
-
(0,
|
|
5477
|
+
(0, import_react22.useEffect)(() => {
|
|
4896
5478
|
if (autoFetch && isAuthenticated && isInitialized) {
|
|
4897
5479
|
refreshProfile();
|
|
4898
5480
|
} else if (!isAuthenticated) {
|
|
4899
5481
|
clearProfile();
|
|
4900
5482
|
}
|
|
4901
5483
|
}, [autoFetch, isAuthenticated, isInitialized, refreshProfile, clearProfile]);
|
|
4902
|
-
(0,
|
|
5484
|
+
(0, import_react22.useEffect)(() => {
|
|
4903
5485
|
mountedRef.current = true;
|
|
4904
5486
|
return () => {
|
|
4905
5487
|
mountedRef.current = false;
|
|
@@ -4925,7 +5507,7 @@ var useUserData = (options = {}) => {
|
|
|
4925
5507
|
};
|
|
4926
5508
|
|
|
4927
5509
|
// src/hooks/useAuth.ts
|
|
4928
|
-
var
|
|
5510
|
+
var import_react23 = require("react");
|
|
4929
5511
|
var useAuth = () => {
|
|
4930
5512
|
const {
|
|
4931
5513
|
isAuthenticated,
|
|
@@ -4943,7 +5525,7 @@ var useAuth = () => {
|
|
|
4943
5525
|
expiresIn,
|
|
4944
5526
|
refreshExpiresIn
|
|
4945
5527
|
} = useSessionContext();
|
|
4946
|
-
const setToken = (0,
|
|
5528
|
+
const setToken = (0, import_react23.useCallback)((token) => {
|
|
4947
5529
|
if (token) {
|
|
4948
5530
|
console.warn("useAuth.setToken() is deprecated. Use login() method instead for better security.");
|
|
4949
5531
|
} else {
|
|
@@ -4978,7 +5560,7 @@ var useAuth = () => {
|
|
|
4978
5560
|
};
|
|
4979
5561
|
|
|
4980
5562
|
// src/hooks/useData.ts
|
|
4981
|
-
var
|
|
5563
|
+
var import_react24 = require("react");
|
|
4982
5564
|
var import_crudify_browser10 = __toESM(require("@nocios/crudify-browser"));
|
|
4983
5565
|
var useData = () => {
|
|
4984
5566
|
const {
|
|
@@ -4988,10 +5570,10 @@ var useData = () => {
|
|
|
4988
5570
|
isAuthenticated,
|
|
4989
5571
|
login: sessionLogin
|
|
4990
5572
|
} = useSessionContext();
|
|
4991
|
-
const isReady = (0,
|
|
5573
|
+
const isReady = (0, import_react24.useCallback)(() => {
|
|
4992
5574
|
return isInitialized && !isLoading && !error;
|
|
4993
5575
|
}, [isInitialized, isLoading, error]);
|
|
4994
|
-
const waitForReady = (0,
|
|
5576
|
+
const waitForReady = (0, import_react24.useCallback)(async () => {
|
|
4995
5577
|
return new Promise((resolve, reject) => {
|
|
4996
5578
|
const checkReady = () => {
|
|
4997
5579
|
if (isReady()) {
|
|
@@ -5005,36 +5587,36 @@ var useData = () => {
|
|
|
5005
5587
|
checkReady();
|
|
5006
5588
|
});
|
|
5007
5589
|
}, [isReady, error]);
|
|
5008
|
-
const ensureReady = (0,
|
|
5590
|
+
const ensureReady = (0, import_react24.useCallback)(async () => {
|
|
5009
5591
|
if (!isReady()) {
|
|
5010
5592
|
throw new Error("System not ready. Check isInitialized, isLoading, and error states.");
|
|
5011
5593
|
}
|
|
5012
5594
|
}, [isReady]);
|
|
5013
|
-
const readItems = (0,
|
|
5595
|
+
const readItems = (0, import_react24.useCallback)(async (moduleKey, filter, options) => {
|
|
5014
5596
|
await ensureReady();
|
|
5015
5597
|
return await import_crudify_browser10.default.readItems(moduleKey, filter || {}, options);
|
|
5016
5598
|
}, [ensureReady]);
|
|
5017
|
-
const readItem = (0,
|
|
5599
|
+
const readItem = (0, import_react24.useCallback)(async (moduleKey, filter, options) => {
|
|
5018
5600
|
await ensureReady();
|
|
5019
5601
|
return await import_crudify_browser10.default.readItem(moduleKey, filter, options);
|
|
5020
5602
|
}, [ensureReady]);
|
|
5021
|
-
const createItem = (0,
|
|
5603
|
+
const createItem = (0, import_react24.useCallback)(async (moduleKey, data, options) => {
|
|
5022
5604
|
await ensureReady();
|
|
5023
5605
|
return await import_crudify_browser10.default.createItem(moduleKey, data, options);
|
|
5024
5606
|
}, [ensureReady]);
|
|
5025
|
-
const updateItem = (0,
|
|
5607
|
+
const updateItem = (0, import_react24.useCallback)(async (moduleKey, data, options) => {
|
|
5026
5608
|
await ensureReady();
|
|
5027
5609
|
return await import_crudify_browser10.default.updateItem(moduleKey, data, options);
|
|
5028
5610
|
}, [ensureReady]);
|
|
5029
|
-
const deleteItem = (0,
|
|
5611
|
+
const deleteItem = (0, import_react24.useCallback)(async (moduleKey, id, options) => {
|
|
5030
5612
|
await ensureReady();
|
|
5031
5613
|
return await import_crudify_browser10.default.deleteItem(moduleKey, id, options);
|
|
5032
5614
|
}, [ensureReady]);
|
|
5033
|
-
const transaction = (0,
|
|
5615
|
+
const transaction = (0, import_react24.useCallback)(async (operations, options) => {
|
|
5034
5616
|
await ensureReady();
|
|
5035
5617
|
return await import_crudify_browser10.default.transaction(operations, options);
|
|
5036
5618
|
}, [ensureReady]);
|
|
5037
|
-
const login = (0,
|
|
5619
|
+
const login = (0, import_react24.useCallback)(async (email, password) => {
|
|
5038
5620
|
try {
|
|
5039
5621
|
const result = await sessionLogin(email, password);
|
|
5040
5622
|
if (result.success) {
|
|
@@ -5081,6 +5663,9 @@ var useData = () => {
|
|
|
5081
5663
|
ERROR_CODES,
|
|
5082
5664
|
ERROR_SEVERITY_MAP,
|
|
5083
5665
|
LoginComponent,
|
|
5666
|
+
POLICY_ACTIONS,
|
|
5667
|
+
PREFERRED_POLICY_ORDER,
|
|
5668
|
+
Policies,
|
|
5084
5669
|
ProtectedRoute,
|
|
5085
5670
|
SessionDebugInfo,
|
|
5086
5671
|
SessionManager,
|