@nocios/crudify-ui 4.4.8 → 4.4.12

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.
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var u=e=>{let t=document.cookie.match(new RegExp("(^|;)\\s*"+e+"=([^;]+)"));return t?t[2]:null};var N=["errors.{category}.{code}","errors.{code}","login.{code}","error.{code}","messages.{code}","{code}"],I={INVALID_CREDENTIALS:"auth",UNAUTHORIZED:"auth",INVALID_API_KEY:"auth",USER_NOT_FOUND:"auth",USER_NOT_ACTIVE:"auth",NO_PERMISSION:"auth",SESSION_EXPIRED:"auth",ITEM_NOT_FOUND:"data",NOT_FOUND:"data",IN_USE:"data",DUPLICATE_ENTRY:"data",FIELD_ERROR:"validation",BAD_REQUEST:"validation",INVALID_EMAIL:"validation",INVALID_CODE:"validation",REQUIRED_FIELD:"validation",INTERNAL_SERVER_ERROR:"system",DATABASE_CONNECTION_ERROR:"system",INVALID_CONFIGURATION:"system",UNKNOWN_OPERATION:"system",TIMEOUT_ERROR:"system",NETWORK_ERROR:"system",TOO_MANY_REQUESTS:"rate_limit"},C={INVALID_CREDENTIALS:"Invalid username or password",UNAUTHORIZED:"You are not authorized to perform this action",SESSION_EXPIRED:"Your session has expired. Please log in again.",USER_NOT_FOUND:"User not found",ITEM_NOT_FOUND:"Item not found",FIELD_ERROR:"Invalid field value",INTERNAL_SERVER_ERROR:"An internal error occurred",NETWORK_ERROR:"Network connection error",TIMEOUT_ERROR:"Request timeout",UNKNOWN_OPERATION:"Unknown operation",INVALID_EMAIL:"Invalid email format",INVALID_CODE:"Invalid code",TOO_MANY_REQUESTS:"Too many requests, please try again later"};function p(e,t){let{translateFn:o,currentLanguage:n,enableDebug:s}=t;s&&console.log(`\u{1F50D} [ErrorTranslation] Translating error code: ${e} (lang: ${n||"unknown"})`);let c=e.toUpperCase(),E=I[c],g=N.map(r=>r.replace("{category}",E||"general").replace("{code}",c));s&&console.log("\u{1F511} [ErrorTranslation] Searching keys:",g);for(let r of g){let a=o(r);if(s&&console.log(`\u{1F50D} [ErrorTranslation] Checking key: "${r}" -> result: "${a}" (same as key: ${a===r})`),a&&a!==r)return s&&console.log(`\u2705 [ErrorTranslation] Found translation at key: ${r} = "${a}"`),a}let i=C[c];if(i)return s&&console.log(`\u{1F504} [ErrorTranslation] Using default message: "${i}"`),i;let d=c.replace(/_/g," ").toLowerCase().replace(/\b\w/g,r=>r.toUpperCase());return s&&console.log(`\u26A0\uFE0F [ErrorTranslation] No translation found, using friendly code: "${d}"`),d}function S(e,t){return e.map(o=>p(o,t))}function O(e,t){let{enableDebug:o}=t;o&&console.log("\u{1F50D} [ErrorTranslation] Translating error:",e);let n=p(e.code,t);return n!==e.code.toUpperCase()&&n!==e.code?(o&&console.log(`\u2705 [ErrorTranslation] Using hierarchical translation: "${n}"`),e.field?`${e.field}: ${n}`:n):e.message&&!e.message.includes("Error:")&&e.message.length>0&&e.message!==e.code?(o&&console.log(`\u{1F504} [ErrorTranslation] No hierarchical translation found, using API message: "${e.message}"`),e.message):(o&&console.log(`\u26A0\uFE0F [ErrorTranslation] Using final fallback: "${n}"`),e.field?`${e.field}: ${n}`:n)}function _(e,t={}){let o={translateFn:e,currentLanguage:t.currentLanguage,enableDebug:t.enableDebug||!1};return{translateErrorCode:n=>p(n,o),translateErrorCodes:n=>S(n,o),translateError:n=>O(n,o),translateApiError:n=>_optionalChain([n, 'optionalAccess', _2 => _2.data, 'optionalAccess', _3 => _3.response, 'optionalAccess', _4 => _4.status])?p(n.data.response.status,o):_optionalChain([n, 'optionalAccess', _5 => _5.status])?p(n.status,o):_optionalChain([n, 'optionalAccess', _6 => _6.code])?p(n.code,o):"Unknown error"}}var y=class e{constructor(){this.listeners=new Set;this.isHandlingAuthError=!1;this.lastErrorTime=0;this.lastEventType=null;this.DEBOUNCE_TIME=1e3}static getInstance(){return e.instance||(e.instance=new e),e.instance}emit(t,o){let n=Date.now();if(this.isHandlingAuthError&&this.lastEventType===t&&n-this.lastErrorTime<this.DEBOUNCE_TIME){console.log(`\u{1F6AB} AuthEventBus: Ignoring duplicate ${t} event (debounced)`);return}this.isHandlingAuthError=!0,this.lastErrorTime=n,this.lastEventType=t,console.log(`\u{1F4E2} AuthEventBus: Emitting ${t} event`,o);let s={type:t,details:o,timestamp:n};this.listeners.forEach(c=>{try{c(s)}catch(E){console.error("AuthEventBus: Error in listener",E)}}),setTimeout(()=>{this.isHandlingAuthError=!1,this.lastEventType=null},2e3)}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}clear(){this.listeners.clear(),this.isHandlingAuthError=!1,this.lastEventType=null}isHandling(){return this.isHandlingAuthError}},w= exports.f =y.getInstance();var l=class l{constructor(){this.isPatched=!1;this.refCount=0;this.listeners=new Set;this.originalPushState=window.history.pushState,this.originalReplaceState=window.history.replaceState}static getInstance(){return l.instance||(l.instance=new l),l.instance}subscribe(t){return this.listeners.add(t),this.refCount++,this.isPatched||this.applyPatches(),()=>{this.unsubscribe(t)}}unsubscribe(t){this.listeners.delete(t),this.refCount--,this.refCount===0&&this.isPatched&&this.removePatches()}applyPatches(){let t=this;window.history.pushState=function(...o){let n=t.originalPushState.apply(this,o);return t.notifyListeners(),n},window.history.replaceState=function(...o){let n=t.originalReplaceState.apply(this,o);return t.notifyListeners(),n},this.isPatched=!0}removePatches(){window.history.pushState=this.originalPushState,window.history.replaceState=this.originalReplaceState,this.isPatched=!1}notifyListeners(){this.listeners.forEach(t=>{try{t()}catch(o){console.error("NavigationTracker: Error in navigation listener",o)}})}static reset(){_optionalChain([l, 'access', _7 => _7.instance, 'optionalAccess', _8 => _8.isPatched])&&l.instance.removePatches(),l.instance=null}getSubscriberCount(){return this.refCount}isActive(){return this.isPatched}};l.instance=null;var T=l;var A=e=>{try{let t=e.split(".");if(t.length!==3)return console.warn("Invalid JWT format: token must have 3 parts"),null;let o=t[1],n=o+"=".repeat((4-o.length%4)%4);return JSON.parse(atob(n))}catch(t){return console.warn("Failed to decode JWT token:",t),null}},L= exports.i =()=>{try{let e=null;if(e=sessionStorage.getItem("authToken"),console.log("\u{1F50D} getCurrentUserEmail - authToken:",e?`${e.substring(0,20)}...`:null),e||(e=sessionStorage.getItem("token"),console.log("\u{1F50D} getCurrentUserEmail - token:",e?`${e.substring(0,20)}...`:null)),e||(e=localStorage.getItem("authToken")||localStorage.getItem("token"),console.log("\u{1F50D} getCurrentUserEmail - localStorage:",e?`${e.substring(0,20)}...`:null)),!e)return console.warn("\u{1F50D} getCurrentUserEmail - No token found in any storage"),null;let t=A(e);if(!t)return console.warn("\u{1F50D} getCurrentUserEmail - Failed to decode token"),null;let o=t.email||t["cognito:username"]||null;return console.log("\u{1F50D} getCurrentUserEmail - Extracted email:",o),o}catch(e){return console.warn("Failed to get current user email:",e),null}},x= exports.j =e=>{try{let t=A(e);if(!t||!t.exp)return!0;let o=Math.floor(Date.now()/1e3);return t.exp<o}catch (e2){return!0}};function b(e={}){let{publicApiKey:t,env:o,appName:n,logo:s,loginActions:c,sections:E,enableDebug:g=!1}=e,i={configSource:"none"},d=u("publicApiKey");if(d){let r=u("environment"),a=u("appName"),h=u("logo"),v=u("loginActions"),m=u("sections"),R=u("theme");return i={publicApiKey:decodeURIComponent(d),env:r&&["dev","stg","api","prod"].includes(r)?r:"prod",appName:a?decodeURIComponent(a):void 0,logo:h?decodeURIComponent(h):void 0,loginActions:v?decodeURIComponent(v).split(",").map(f=>f.trim()).filter(Boolean):void 0,sections:m?decodeURIComponent(m).split(",").map(f=>f.trim()).filter(Boolean):void 0,theme:R?(()=>{try{return JSON.parse(decodeURIComponent(R))}catch(f){console.warn("[ConfigResolver] Failed to parse theme cookie:",f);return}})():void 0,configSource:"cookies"},g&&(console.log("[ConfigResolver] \u2705 Using COOKIES config (production):",i),console.log("[ConfigResolver] Raw cookies:",{publicApiKey:d,environment:r,appName:a,logo:h,loginActions:v,sections:m,theme:R})),g&&typeof window<"u"&&(window.__CRUDIFY_RESOLVED_CONFIG=i),i}return t?(i={publicApiKey:t,env:o||"prod",appName:n,logo:s,loginActions:c,sections:E,configSource:"props"},g&&console.log("[ConfigResolver] \u2705 Using PROPS config (development):",i),i):(g&&console.error("[ConfigResolver] \u274C No configuration found! Neither cookies nor props available."),i)}function K(e={}){return b(e)}exports.a = u; exports.b = p; exports.c = S; exports.d = O; exports.e = _; exports.f = w; exports.g = T; exports.h = A; exports.i = L; exports.j = x; exports.k = b; exports.l = K;