@nocios/crudify-ui 5.0.4 → 5.0.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/coverage/coverage-final.json +36 -36
- package/coverage/index.html +160 -160
- package/dist/chunk-3OA4S6UT.mjs +1 -0
- package/dist/{chunk-KQ2XC5PN.js → chunk-5HFI5CZ5.js} +1 -1
- package/dist/chunk-6M4Z5KHH.mjs +1 -0
- package/dist/{chunk-QPTL5FLE.mjs → chunk-A5CDJL6G.mjs} +1 -1
- package/dist/{chunk-OGAGYHG4.mjs → chunk-JNEWPO2J.mjs} +1 -1
- package/dist/{chunk-NXTXGTU6.js → chunk-MFYHD6S5.js} +1 -1
- package/dist/{chunk-6BQGRZYB.mjs → chunk-MGJZTOEM.mjs} +1 -1
- package/dist/chunk-PYLSSR7W.js +1 -0
- package/dist/{chunk-LVSNJ4OM.js → chunk-Q4RHNYTI.js} +1 -1
- package/dist/chunk-SFIIFYMZ.js +1 -0
- package/dist/components.js +1 -1
- package/dist/components.mjs +1 -1
- package/dist/hooks.js +1 -1
- package/dist/hooks.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-3XZ3TEKQ.js +0 -1
- package/dist/chunk-5VOTRIDB.js +0 -1
- package/dist/chunk-NSA6YDHY.mjs +0 -1
- package/dist/chunk-PARX2RMU.mjs +0 -1
package/coverage/index.html
CHANGED
|
@@ -23,30 +23,30 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">
|
|
26
|
+
<span class="strong">53.06% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>7862/14815</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">80.87% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>
|
|
35
|
+
<span class='fraction'>1091/1349</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">
|
|
40
|
+
<span class="strong">80.28% </span>
|
|
41
41
|
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>
|
|
42
|
+
<span class='fraction'>224/279</span>
|
|
43
43
|
</div>
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">
|
|
47
|
+
<span class="strong">53.06% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>7862/14815</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</div>
|
|
62
62
|
</template>
|
|
63
63
|
</div>
|
|
64
|
-
<div class='status-line
|
|
64
|
+
<div class='status-line medium'></div>
|
|
65
65
|
<div class="pad1">
|
|
66
66
|
<table class="coverage-summary">
|
|
67
67
|
<thead>
|
|
@@ -94,18 +94,18 @@
|
|
|
94
94
|
</tr>
|
|
95
95
|
|
|
96
96
|
<tr>
|
|
97
|
-
<td class="file
|
|
98
|
-
<td data-value="
|
|
99
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
97
|
+
<td class="file medium" data-value="src/components"><a href="src/components/index.html">src/components</a></td>
|
|
98
|
+
<td data-value="65.83" class="pic medium">
|
|
99
|
+
<div class="chart"><div class="cover-fill" style="width: 65%"></div><div class="cover-empty" style="width: 35%"></div></div>
|
|
100
100
|
</td>
|
|
101
|
-
<td data-value="
|
|
102
|
-
<td data-value="2236" class="abs
|
|
103
|
-
<td data-value="
|
|
104
|
-
<td data-value="
|
|
105
|
-
<td data-value="
|
|
106
|
-
<td data-value="
|
|
107
|
-
<td data-value="
|
|
108
|
-
<td data-value="2236" class="abs
|
|
101
|
+
<td data-value="65.83" class="pct medium">65.83%</td>
|
|
102
|
+
<td data-value="2236" class="abs medium">1472/2236</td>
|
|
103
|
+
<td data-value="75.92" class="pct medium">75.92%</td>
|
|
104
|
+
<td data-value="216" class="abs medium">164/216</td>
|
|
105
|
+
<td data-value="71.87" class="pct medium">71.87%</td>
|
|
106
|
+
<td data-value="32" class="abs medium">23/32</td>
|
|
107
|
+
<td data-value="65.83" class="pct medium">65.83%</td>
|
|
108
|
+
<td data-value="2236" class="abs medium">1472/2236</td>
|
|
109
109
|
</tr>
|
|
110
110
|
|
|
111
111
|
<tr>
|
|
@@ -154,63 +154,63 @@
|
|
|
154
154
|
</tr>
|
|
155
155
|
|
|
156
156
|
<tr>
|
|
157
|
-
<td class="file
|
|
158
|
-
<td data-value="
|
|
159
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
157
|
+
<td class="file high" data-value="src/components/CrudifyLogin/context"><a href="src/components/CrudifyLogin/context/index.html">src/components/CrudifyLogin/context</a></td>
|
|
158
|
+
<td data-value="80.36" class="pic high">
|
|
159
|
+
<div class="chart"><div class="cover-fill" style="width: 80%"></div><div class="cover-empty" style="width: 20%"></div></div>
|
|
160
160
|
</td>
|
|
161
|
-
<td data-value="
|
|
162
|
-
<td data-value="
|
|
163
|
-
<td data-value="
|
|
164
|
-
<td data-value="
|
|
165
|
-
<td data-value="
|
|
166
|
-
<td data-value="
|
|
167
|
-
<td data-value="
|
|
168
|
-
<td data-value="
|
|
161
|
+
<td data-value="80.36" class="pct high">80.36%</td>
|
|
162
|
+
<td data-value="596" class="abs high">479/596</td>
|
|
163
|
+
<td data-value="87.65" class="pct high">87.65%</td>
|
|
164
|
+
<td data-value="81" class="abs high">71/81</td>
|
|
165
|
+
<td data-value="86.66" class="pct high">86.66%</td>
|
|
166
|
+
<td data-value="15" class="abs high">13/15</td>
|
|
167
|
+
<td data-value="80.36" class="pct high">80.36%</td>
|
|
168
|
+
<td data-value="596" class="abs high">479/596</td>
|
|
169
169
|
</tr>
|
|
170
170
|
|
|
171
171
|
<tr>
|
|
172
|
-
<td class="file
|
|
173
|
-
<td data-value="
|
|
174
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
172
|
+
<td class="file high" data-value="src/components/CrudifyLogin/hooks"><a href="src/components/CrudifyLogin/hooks/index.html">src/components/CrudifyLogin/hooks</a></td>
|
|
173
|
+
<td data-value="88.88" class="pic high">
|
|
174
|
+
<div class="chart"><div class="cover-fill" style="width: 88%"></div><div class="cover-empty" style="width: 12%"></div></div>
|
|
175
175
|
</td>
|
|
176
|
-
<td data-value="
|
|
177
|
-
<td data-value="171" class="abs
|
|
178
|
-
<td data-value="
|
|
179
|
-
<td data-value="
|
|
180
|
-
<td data-value="
|
|
181
|
-
<td data-value="2" class="abs
|
|
182
|
-
<td data-value="
|
|
183
|
-
<td data-value="171" class="abs
|
|
176
|
+
<td data-value="88.88" class="pct high">88.88%</td>
|
|
177
|
+
<td data-value="171" class="abs high">152/171</td>
|
|
178
|
+
<td data-value="85.71" class="pct high">85.71%</td>
|
|
179
|
+
<td data-value="28" class="abs high">24/28</td>
|
|
180
|
+
<td data-value="100" class="pct high">100%</td>
|
|
181
|
+
<td data-value="2" class="abs high">2/2</td>
|
|
182
|
+
<td data-value="88.88" class="pct high">88.88%</td>
|
|
183
|
+
<td data-value="171" class="abs high">152/171</td>
|
|
184
184
|
</tr>
|
|
185
185
|
|
|
186
186
|
<tr>
|
|
187
|
-
<td class="file
|
|
188
|
-
<td data-value="
|
|
189
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
187
|
+
<td class="file high" data-value="src/components/CrudifyLogin/utils"><a href="src/components/CrudifyLogin/utils/index.html">src/components/CrudifyLogin/utils</a></td>
|
|
188
|
+
<td data-value="85.27" class="pic high">
|
|
189
|
+
<div class="chart"><div class="cover-fill" style="width: 85%"></div><div class="cover-empty" style="width: 15%"></div></div>
|
|
190
190
|
</td>
|
|
191
|
-
<td data-value="
|
|
192
|
-
<td data-value="258" class="abs
|
|
193
|
-
<td data-value="
|
|
194
|
-
<td data-value="
|
|
195
|
-
<td data-value="
|
|
196
|
-
<td data-value="
|
|
197
|
-
<td data-value="
|
|
198
|
-
<td data-value="258" class="abs
|
|
191
|
+
<td data-value="85.27" class="pct high">85.27%</td>
|
|
192
|
+
<td data-value="258" class="abs high">220/258</td>
|
|
193
|
+
<td data-value="80.7" class="pct high">80.7%</td>
|
|
194
|
+
<td data-value="57" class="abs high">46/57</td>
|
|
195
|
+
<td data-value="93.75" class="pct high">93.75%</td>
|
|
196
|
+
<td data-value="16" class="abs high">15/16</td>
|
|
197
|
+
<td data-value="85.27" class="pct high">85.27%</td>
|
|
198
|
+
<td data-value="258" class="abs high">220/258</td>
|
|
199
199
|
</tr>
|
|
200
200
|
|
|
201
201
|
<tr>
|
|
202
202
|
<td class="file low" data-value="src/components/PublicPolicies"><a href="src/components/PublicPolicies/index.html">src/components/PublicPolicies</a></td>
|
|
203
|
-
<td data-value="
|
|
204
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
203
|
+
<td data-value="6.38" class="pic low">
|
|
204
|
+
<div class="chart"><div class="cover-fill" style="width: 6%"></div><div class="cover-empty" style="width: 94%"></div></div>
|
|
205
205
|
</td>
|
|
206
|
+
<td data-value="6.38" class="pct low">6.38%</td>
|
|
207
|
+
<td data-value="188" class="abs low">12/188</td>
|
|
206
208
|
<td data-value="0" class="pct low">0%</td>
|
|
207
|
-
<td data-value="
|
|
208
|
-
<td data-value="0" class="pct low">0%</td>
|
|
209
|
-
<td data-value="3" class="abs low">0/3</td>
|
|
210
|
-
<td data-value="0" class="pct low">0%</td>
|
|
211
|
-
<td data-value="3" class="abs low">0/3</td>
|
|
209
|
+
<td data-value="2" class="abs low">0/2</td>
|
|
212
210
|
<td data-value="0" class="pct low">0%</td>
|
|
213
|
-
<td data-value="
|
|
211
|
+
<td data-value="2" class="abs low">0/2</td>
|
|
212
|
+
<td data-value="6.38" class="pct low">6.38%</td>
|
|
213
|
+
<td data-value="188" class="abs low">12/188</td>
|
|
214
214
|
</tr>
|
|
215
215
|
|
|
216
216
|
<tr>
|
|
@@ -244,48 +244,48 @@
|
|
|
244
244
|
</tr>
|
|
245
245
|
|
|
246
246
|
<tr>
|
|
247
|
-
<td class="file
|
|
248
|
-
<td data-value="
|
|
249
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
247
|
+
<td class="file high" data-value="src/components/Routing"><a href="src/components/Routing/index.html">src/components/Routing</a></td>
|
|
248
|
+
<td data-value="96.12" class="pic high">
|
|
249
|
+
<div class="chart"><div class="cover-fill" style="width: 96%"></div><div class="cover-empty" style="width: 4%"></div></div>
|
|
250
250
|
</td>
|
|
251
|
-
<td data-value="
|
|
252
|
-
<td data-value="129" class="abs
|
|
253
|
-
<td data-value="
|
|
254
|
-
<td data-value="
|
|
255
|
-
<td data-value="
|
|
256
|
-
<td data-value="3" class="abs
|
|
257
|
-
<td data-value="
|
|
258
|
-
<td data-value="129" class="abs
|
|
251
|
+
<td data-value="96.12" class="pct high">96.12%</td>
|
|
252
|
+
<td data-value="129" class="abs high">124/129</td>
|
|
253
|
+
<td data-value="94.73" class="pct high">94.73%</td>
|
|
254
|
+
<td data-value="19" class="abs high">18/19</td>
|
|
255
|
+
<td data-value="66.66" class="pct medium">66.66%</td>
|
|
256
|
+
<td data-value="3" class="abs medium">2/3</td>
|
|
257
|
+
<td data-value="96.12" class="pct high">96.12%</td>
|
|
258
|
+
<td data-value="129" class="abs high">124/129</td>
|
|
259
259
|
</tr>
|
|
260
260
|
|
|
261
261
|
<tr>
|
|
262
|
-
<td class="file
|
|
263
|
-
<td data-value="
|
|
264
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
262
|
+
<td class="file high" data-value="src/components/SessionLoadingScreen"><a href="src/components/SessionLoadingScreen/index.html">src/components/SessionLoadingScreen</a></td>
|
|
263
|
+
<td data-value="100" class="pic high">
|
|
264
|
+
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
|
265
265
|
</td>
|
|
266
|
-
<td data-value="
|
|
267
|
-
<td data-value="101" class="abs
|
|
268
|
-
<td data-value="
|
|
269
|
-
<td data-value="
|
|
270
|
-
<td data-value="
|
|
271
|
-
<td data-value="
|
|
272
|
-
<td data-value="
|
|
273
|
-
<td data-value="101" class="abs
|
|
266
|
+
<td data-value="100" class="pct high">100%</td>
|
|
267
|
+
<td data-value="101" class="abs high">101/101</td>
|
|
268
|
+
<td data-value="100" class="pct high">100%</td>
|
|
269
|
+
<td data-value="3" class="abs high">3/3</td>
|
|
270
|
+
<td data-value="100" class="pct high">100%</td>
|
|
271
|
+
<td data-value="2" class="abs high">2/2</td>
|
|
272
|
+
<td data-value="100" class="pct high">100%</td>
|
|
273
|
+
<td data-value="101" class="abs high">101/101</td>
|
|
274
274
|
</tr>
|
|
275
275
|
|
|
276
276
|
<tr>
|
|
277
|
-
<td class="file
|
|
278
|
-
<td data-value="
|
|
279
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
277
|
+
<td class="file high" data-value="src/components/SessionTimeIndicator"><a href="src/components/SessionTimeIndicator/index.html">src/components/SessionTimeIndicator</a></td>
|
|
278
|
+
<td data-value="100" class="pic high">
|
|
279
|
+
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
|
280
280
|
</td>
|
|
281
|
-
<td data-value="
|
|
282
|
-
<td data-value="140" class="abs
|
|
283
|
-
<td data-value="
|
|
284
|
-
<td data-value="
|
|
285
|
-
<td data-value="
|
|
286
|
-
<td data-value="1" class="abs
|
|
287
|
-
<td data-value="
|
|
288
|
-
<td data-value="140" class="abs
|
|
281
|
+
<td data-value="100" class="pct high">100%</td>
|
|
282
|
+
<td data-value="140" class="abs high">140/140</td>
|
|
283
|
+
<td data-value="100" class="pct high">100%</td>
|
|
284
|
+
<td data-value="16" class="abs high">16/16</td>
|
|
285
|
+
<td data-value="100" class="pct high">100%</td>
|
|
286
|
+
<td data-value="1" class="abs high">1/1</td>
|
|
287
|
+
<td data-value="100" class="pct high">100%</td>
|
|
288
|
+
<td data-value="140" class="abs high">140/140</td>
|
|
289
289
|
</tr>
|
|
290
290
|
|
|
291
291
|
<tr>
|
|
@@ -304,18 +304,18 @@
|
|
|
304
304
|
</tr>
|
|
305
305
|
|
|
306
306
|
<tr>
|
|
307
|
-
<td class="file
|
|
308
|
-
<td data-value="
|
|
309
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
307
|
+
<td class="file medium" data-value="src/core"><a href="src/core/index.html">src/core</a></td>
|
|
308
|
+
<td data-value="52.86" class="pic medium">
|
|
309
|
+
<div class="chart"><div class="cover-fill" style="width: 52%"></div><div class="cover-empty" style="width: 48%"></div></div>
|
|
310
310
|
</td>
|
|
311
|
-
<td data-value="
|
|
312
|
-
<td data-value="
|
|
313
|
-
<td data-value="
|
|
314
|
-
<td data-value="
|
|
315
|
-
<td data-value="
|
|
316
|
-
<td data-value="
|
|
317
|
-
<td data-value="
|
|
318
|
-
<td data-value="
|
|
311
|
+
<td data-value="52.86" class="pct medium">52.86%</td>
|
|
312
|
+
<td data-value="1101" class="abs medium">582/1101</td>
|
|
313
|
+
<td data-value="76.82" class="pct medium">76.82%</td>
|
|
314
|
+
<td data-value="82" class="abs medium">63/82</td>
|
|
315
|
+
<td data-value="68.75" class="pct medium">68.75%</td>
|
|
316
|
+
<td data-value="32" class="abs medium">22/32</td>
|
|
317
|
+
<td data-value="52.86" class="pct medium">52.86%</td>
|
|
318
|
+
<td data-value="1101" class="abs medium">582/1101</td>
|
|
319
319
|
</tr>
|
|
320
320
|
|
|
321
321
|
<tr>
|
|
@@ -335,77 +335,77 @@
|
|
|
335
335
|
|
|
336
336
|
<tr>
|
|
337
337
|
<td class="file low" data-value="src/hooks"><a href="src/hooks/index.html">src/hooks</a></td>
|
|
338
|
-
<td data-value="
|
|
339
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
338
|
+
<td data-value="30.22" class="pic low">
|
|
339
|
+
<div class="chart"><div class="cover-fill" style="width: 30%"></div><div class="cover-empty" style="width: 70%"></div></div>
|
|
340
340
|
</td>
|
|
341
|
-
<td data-value="
|
|
342
|
-
<td data-value="3100" class="abs low">
|
|
343
|
-
<td data-value="
|
|
344
|
-
<td data-value="
|
|
345
|
-
<td data-value="
|
|
346
|
-
<td data-value="
|
|
347
|
-
<td data-value="
|
|
348
|
-
<td data-value="3100" class="abs low">
|
|
341
|
+
<td data-value="30.22" class="pct low">30.22%</td>
|
|
342
|
+
<td data-value="3100" class="abs low">937/3100</td>
|
|
343
|
+
<td data-value="77.77" class="pct medium">77.77%</td>
|
|
344
|
+
<td data-value="135" class="abs medium">105/135</td>
|
|
345
|
+
<td data-value="53.33" class="pct medium">53.33%</td>
|
|
346
|
+
<td data-value="15" class="abs medium">8/15</td>
|
|
347
|
+
<td data-value="30.22" class="pct low">30.22%</td>
|
|
348
|
+
<td data-value="3100" class="abs low">937/3100</td>
|
|
349
349
|
</tr>
|
|
350
350
|
|
|
351
351
|
<tr>
|
|
352
|
-
<td class="file
|
|
353
|
-
<td data-value="
|
|
354
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
352
|
+
<td class="file medium" data-value="src/providers"><a href="src/providers/index.html">src/providers</a></td>
|
|
353
|
+
<td data-value="51.99" class="pic medium">
|
|
354
|
+
<div class="chart"><div class="cover-fill" style="width: 51%"></div><div class="cover-empty" style="width: 49%"></div></div>
|
|
355
355
|
</td>
|
|
356
|
-
<td data-value="
|
|
357
|
-
<td data-value="877" class="abs
|
|
358
|
-
<td data-value="
|
|
359
|
-
<td data-value="
|
|
360
|
-
<td data-value="
|
|
361
|
-
<td data-value="
|
|
362
|
-
<td data-value="
|
|
363
|
-
<td data-value="877" class="abs
|
|
356
|
+
<td data-value="51.99" class="pct medium">51.99%</td>
|
|
357
|
+
<td data-value="877" class="abs medium">456/877</td>
|
|
358
|
+
<td data-value="70.37" class="pct medium">70.37%</td>
|
|
359
|
+
<td data-value="81" class="abs medium">57/81</td>
|
|
360
|
+
<td data-value="85.71" class="pct high">85.71%</td>
|
|
361
|
+
<td data-value="7" class="abs high">6/7</td>
|
|
362
|
+
<td data-value="51.99" class="pct medium">51.99%</td>
|
|
363
|
+
<td data-value="877" class="abs medium">456/877</td>
|
|
364
364
|
</tr>
|
|
365
365
|
|
|
366
366
|
<tr>
|
|
367
|
-
<td class="file
|
|
368
|
-
<td data-value="
|
|
369
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
367
|
+
<td class="file high" data-value="src/services"><a href="src/services/index.html">src/services</a></td>
|
|
368
|
+
<td data-value="90.5" class="pic high">
|
|
369
|
+
<div class="chart"><div class="cover-fill" style="width: 90%"></div><div class="cover-empty" style="width: 10%"></div></div>
|
|
370
370
|
</td>
|
|
371
|
-
<td data-value="
|
|
372
|
-
<td data-value="706" class="abs
|
|
373
|
-
<td data-value="
|
|
374
|
-
<td data-value="
|
|
375
|
-
<td data-value="
|
|
376
|
-
<td data-value="
|
|
377
|
-
<td data-value="
|
|
378
|
-
<td data-value="706" class="abs
|
|
371
|
+
<td data-value="90.5" class="pct high">90.5%</td>
|
|
372
|
+
<td data-value="706" class="abs high">639/706</td>
|
|
373
|
+
<td data-value="80.81" class="pct high">80.81%</td>
|
|
374
|
+
<td data-value="172" class="abs high">139/172</td>
|
|
375
|
+
<td data-value="95.91" class="pct high">95.91%</td>
|
|
376
|
+
<td data-value="49" class="abs high">47/49</td>
|
|
377
|
+
<td data-value="90.5" class="pct high">90.5%</td>
|
|
378
|
+
<td data-value="706" class="abs high">639/706</td>
|
|
379
379
|
</tr>
|
|
380
380
|
|
|
381
381
|
<tr>
|
|
382
|
-
<td class="file
|
|
383
|
-
<td data-value="
|
|
384
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
382
|
+
<td class="file high" data-value="src/translations"><a href="src/translations/index.html">src/translations</a></td>
|
|
383
|
+
<td data-value="100" class="pic high">
|
|
384
|
+
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
|
385
385
|
</td>
|
|
386
|
-
<td data-value="
|
|
387
|
-
<td data-value="309" class="abs
|
|
388
|
-
<td data-value="
|
|
389
|
-
<td data-value="
|
|
390
|
-
<td data-value="
|
|
391
|
-
<td data-value="
|
|
392
|
-
<td data-value="
|
|
393
|
-
<td data-value="309" class="abs
|
|
386
|
+
<td data-value="100" class="pct high">100%</td>
|
|
387
|
+
<td data-value="309" class="abs high">309/309</td>
|
|
388
|
+
<td data-value="100" class="pct high">100%</td>
|
|
389
|
+
<td data-value="3" class="abs high">3/3</td>
|
|
390
|
+
<td data-value="100" class="pct high">100%</td>
|
|
391
|
+
<td data-value="2" class="abs high">2/2</td>
|
|
392
|
+
<td data-value="100" class="pct high">100%</td>
|
|
393
|
+
<td data-value="309" class="abs high">309/309</td>
|
|
394
394
|
</tr>
|
|
395
395
|
|
|
396
396
|
<tr>
|
|
397
|
-
<td class="file
|
|
398
|
-
<td data-value="
|
|
399
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
397
|
+
<td class="file high" data-value="src/utils"><a href="src/utils/index.html">src/utils</a></td>
|
|
398
|
+
<td data-value="93.25" class="pic high">
|
|
399
|
+
<div class="chart"><div class="cover-fill" style="width: 93%"></div><div class="cover-empty" style="width: 7%"></div></div>
|
|
400
400
|
</td>
|
|
401
|
-
<td data-value="
|
|
402
|
-
<td data-value="2401" class="abs
|
|
403
|
-
<td data-value="
|
|
404
|
-
<td data-value="
|
|
405
|
-
<td data-value="
|
|
406
|
-
<td data-value="
|
|
407
|
-
<td data-value="
|
|
408
|
-
<td data-value="2401" class="abs
|
|
401
|
+
<td data-value="93.25" class="pct high">93.25%</td>
|
|
402
|
+
<td data-value="2401" class="abs high">2239/2401</td>
|
|
403
|
+
<td data-value="87.01" class="pct high">87.01%</td>
|
|
404
|
+
<td data-value="439" class="abs high">382/439</td>
|
|
405
|
+
<td data-value="94.18" class="pct high">94.18%</td>
|
|
406
|
+
<td data-value="86" class="abs high">81/86</td>
|
|
407
|
+
<td data-value="93.25" class="pct high">93.25%</td>
|
|
408
|
+
<td data-value="2401" class="abs high">2239/2401</td>
|
|
409
409
|
</tr>
|
|
410
410
|
|
|
411
411
|
</tbody>
|
|
@@ -416,7 +416,7 @@
|
|
|
416
416
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
417
417
|
Code coverage generated by
|
|
418
418
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
419
|
-
at
|
|
419
|
+
at 2026-01-01T23:03:56.521Z
|
|
420
420
|
</div>
|
|
421
421
|
<script src="prettify.js"></script>
|
|
422
422
|
<script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as g,c as de,e as M,f as ve,g as Te,h as be,i as Ae,j as Ie,k as ke,l as Se,p as we,q as xe,r as Pe}from"./chunk-MGJZTOEM.mjs";var Ne="crudify_storage_version",Re=2,a=class a{static setStorageType(i){a.storageType=i}static async initialize(){if(!(a.encryptionKey&&a.salt))return a.initPromise||(a.initPromise=(async()=>{try{a.checkStorageVersion(),a.salt=a.getOrCreateSalt(),a.fingerprint=await a.generateFingerprint(),a.encryptionKey=await Te(a.fingerprint,a.salt)}catch(i){throw g.error("Crudify: Failed to initialize encryption",i instanceof Error?i:{message:String(i)}),i}})()),a.initPromise}static checkStorageVersion(){try{if(parseInt(localStorage.getItem(Ne)||"1",10)<Re){let e=a.getStorage();e&&e.removeItem(a.TOKEN_KEY),localStorage.removeItem(a.ENCRYPTION_KEY_STORAGE),localStorage.removeItem(a.SALT_KEY),localStorage.setItem(Ne,Re.toString()),g.info("Crudify: Storage upgraded to v2, tokens cleared for security")}}catch{}}static getOrCreateSalt(){try{let e=localStorage.getItem(a.SALT_KEY);if(e){let t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}}catch{}let i=Ie();try{let e="";for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);localStorage.setItem(a.SALT_KEY,btoa(e))}catch{g.warn("Crudify: Cannot persist salt, encryption may not persist across sessions")}return i}static async generateFingerprint(){let i=new Uint8Array(16);crypto.getRandomValues(i);let e=Array.from(i,o=>o.toString(16).padStart(2,"0")).join(""),t=[navigator.userAgent,navigator.language,navigator.platform,screen.width,screen.height,e].join("|");try{let o=localStorage.getItem(a.ENCRYPTION_KEY_STORAGE);if(o&&o.length>=32)return o}catch{}let n=await ve(t);try{localStorage.setItem(a.ENCRYPTION_KEY_STORAGE,n)}catch{g.warn("Crudify: Cannot persist encryption key hash")}return n}static isStorageAvailable(i){try{let e=window[i],t="__storage_test__";return e.setItem(t,"test"),e.removeItem(t),!0}catch{return!1}}static getStorage(){return a.storageType==="none"?null:a.isStorageAvailable(a.storageType)?window[a.storageType]:(g.warn(`Crudify: ${a.storageType} not available, tokens won't persist`),null)}static async encryptData(i){if(await a.initialize(),!a.encryptionKey||!a.salt)throw new Error("Encryption not initialized");return be(i,a.encryptionKey,a.salt)}static async decryptData(i){if(await a.initialize(),!a.fingerprint)throw new Error("Encryption not initialized");return ke(i)?Ae(i,a.fingerprint):(g.warn("Crudify: Legacy encrypted data detected, cannot decrypt"),null)}static async saveTokens(i){let e=a.getStorage();if(e)try{let t={accessToken:i.accessToken,refreshToken:i.refreshToken,expiresAt:i.expiresAt,refreshExpiresAt:i.refreshExpiresAt,savedAt:Date.now()},n=await a.encryptData(JSON.stringify(t));e.setItem(a.TOKEN_KEY,n),g.debug("Crudify: Tokens saved successfully")}catch(t){g.error("Crudify: Failed to save tokens",t instanceof Error?t:{message:String(t)})}}static async getTokens(){let i=a.getStorage();if(!i)return null;try{let e=i.getItem(a.TOKEN_KEY);if(!e)return null;let t=await a.decryptData(e);if(!t)return g.warn("Crudify: Failed to decrypt tokens, clearing storage"),await a.clearTokens(),null;let n=JSON.parse(t);return!n.accessToken||!n.refreshToken||!n.expiresAt||!n.refreshExpiresAt?(g.warn("Crudify: Incomplete token data found, clearing storage"),await a.clearTokens(),null):Date.now()>=n.refreshExpiresAt?(g.info("Crudify: Refresh token expired, clearing storage"),await a.clearTokens(),null):{accessToken:n.accessToken,refreshToken:n.refreshToken,expiresAt:n.expiresAt,refreshExpiresAt:n.refreshExpiresAt}}catch(e){return g.error("Crudify: Failed to retrieve tokens",e instanceof Error?e:{message:String(e)}),await a.clearTokens(),null}}static async clearTokens(){let i=a.getStorage();if(i)try{i.removeItem(a.TOKEN_KEY),g.debug("Crudify: Tokens cleared from storage")}catch(e){g.error("Crudify: Failed to clear tokens",e instanceof Error?e:{message:String(e)})}}static async rotateEncryptionKey(){try{await a.clearTokens(),a.encryptionKey=null,a.salt=null,a.fingerprint=null,a.initPromise=null;try{localStorage.removeItem(a.ENCRYPTION_KEY_STORAGE),localStorage.removeItem(a.SALT_KEY)}catch{}g.info("Crudify: Encryption key rotated successfully")}catch(i){g.error("Crudify: Failed to rotate encryption key",i instanceof Error?i:{message:String(i)})}}static async hasValidTokens(){return await a.getTokens()!==null}static async getExpirationInfo(){let i=await a.getTokens();if(!i)return null;let e=Date.now();return{accessExpired:e>=i.expiresAt,refreshExpired:e>=i.refreshExpiresAt,accessExpiresIn:Math.max(0,i.expiresAt-e),refreshExpiresIn:Math.max(0,i.refreshExpiresAt-e)}}static async updateAccessToken(i,e){let t=await a.getTokens();if(!t){g.warn("Crudify: Cannot update access token, no existing tokens found");return}await a.saveTokens({...t,accessToken:i,expiresAt:e})}static createSyncEvent(i,e,t){return{type:i,tokens:e,hadPreviousTokens:t}}static subscribeToChanges(i){let e=async t=>{if(t.key!==a.TOKEN_KEY)return;let n=t.oldValue!==null&&t.oldValue!=="";if(t.newValue===null){g.debug("Crudify: Tokens removed in another tab"),i(null,a.SYNC_EVENTS.TOKENS_CLEARED,n);return}if(t.newValue){g.debug("Crudify: Tokens updated in another tab");let o=await a.getTokens();i(o,a.SYNC_EVENTS.TOKENS_UPDATED,n)}};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}};a.TOKEN_KEY="crudify_tokens",a.ENCRYPTION_KEY_STORAGE="crudify_enc_key",a.SALT_KEY="crudify_enc_salt",a.encryptionKey=null,a.salt=null,a.fingerprint=null,a.storageType="localStorage",a.initPromise=null,a.SYNC_EVENTS={TOKENS_CLEARED:"TOKENS_CLEARED",TOKENS_UPDATED:"TOKENS_UPDATED"};var b=a;import L from"@nocios/crudify-browser";var ee=class r{constructor(){this.config={};this.initialized=!1;this.crudifyInitialized=!1;this.lastActivityTime=0;this.isRefreshingLocally=!1;this.refreshPromise=null}static getInstance(){return r.instance||(r.instance=new r),r.instance}async initialize(i={}){if(!this.initialized){if(this.config={storageType:"localStorage",autoRestore:!0,enableLogging:!1,env:"stg",...i},b.setStorageType(this.config.storageType||"localStorage"),this.config.publicApiKey&&!this.crudifyInitialized&&await this.ensureCrudifyInitialized(),L.setTokenInvalidationCallback(()=>{this.log("Tokens invalidated by crudify-core"),M.emit("SESSION_EXPIRED",{message:"Your session has expired. Please log in again.",source:"crudify-core.clearTokensAndRefreshState"})}),this.config.apiEndpointAdmin&&this.config.apiKeyEndpointAdmin){let e=await b.getTokens();e?await b.saveTokens({...e,apiEndpointAdmin:this.config.apiEndpointAdmin,apiKeyEndpointAdmin:this.config.apiKeyEndpointAdmin}):await b.saveTokens({accessToken:"",refreshToken:"",expiresAt:0,refreshExpiresAt:0,apiEndpointAdmin:this.config.apiEndpointAdmin,apiKeyEndpointAdmin:this.config.apiKeyEndpointAdmin})}this.config.autoRestore&&await this.restoreSession(),this.initialized=!0}}async login(i,e){try{let t=await L.login(i,e);if(!t.success)return{success:!1,error:this.formatError(t.errors),rawResponse:t};let n=await b.getTokens(),o=t.data,m={accessToken:o.token,refreshToken:o.refreshToken,expiresAt:o.expiresAt,refreshExpiresAt:o.refreshExpiresAt,apiEndpointAdmin:n?.apiEndpointAdmin||this.config.apiEndpointAdmin,apiKeyEndpointAdmin:n?.apiKeyEndpointAdmin||this.config.apiKeyEndpointAdmin};return await b.saveTokens(m),this.lastActivityTime=Date.now(),this.config.onLoginSuccess?.(m),{success:!0,tokens:m,data:o}}catch(t){return g.error("[SessionManager] Login error",t instanceof Error?t:{message:String(t)}),{success:!1,error:t instanceof Error?t.message:"Unknown error"}}}async logout(){try{this.log("Logging out..."),M.emit("LOGOUT",{message:"User logged out",source:"SessionManager.logout"}),await L.logout(),await b.clearTokens(),this.log("Logout successful"),this.config.onLogout?.()}catch(i){this.log("Logout error",{error:i instanceof Error?i.message:String(i)}),await b.clearTokens()}}async restoreSession(){try{this.log("Attempting to restore session...");let i=await b.getTokens();if(!i)return this.log("No valid tokens found in storage"),!1;if(Date.now()>=i.refreshExpiresAt)return this.log("Refresh token expired, clearing storage"),await b.clearTokens(),!1;if(L.setTokens({accessToken:i.accessToken,refreshToken:i.refreshToken,expiresAt:i.expiresAt,refreshExpiresAt:i.refreshExpiresAt}),L.getTokenData().isValid===!1){if(this.log("Restored access token is invalid or expired"),Date.now()<i.refreshExpiresAt&&(this.log("Access token expired but refresh is valid, attempting refresh..."),await this.refreshTokens())){this.log("Session restored successfully via token refresh");let n=await b.getTokens();return n&&this.config.onSessionRestored?.(n),!0}return await b.clearTokens(),await L.logout(),!1}return this.log("Session restored successfully"),this.lastActivityTime=Date.now(),this.config.onSessionRestored?.(i),!0}catch(i){return this.log("Session restore error",{error:i instanceof Error?i.message:String(i)}),await b.clearTokens(),await L.logout(),!1}}async isAuthenticated(){return L.isLogin()||await b.hasValidTokens()}async getTokenInfo(){let i=L.getTokenData(),e=await b.getExpirationInfo(),t=await b.getTokens();return{isLoggedIn:await this.isAuthenticated(),crudifyTokens:i,storageInfo:e,hasValidTokens:await b.hasValidTokens(),apiEndpointAdmin:t?.apiEndpointAdmin,apiKeyEndpointAdmin:t?.apiKeyEndpointAdmin}}async refreshTokens(){if(this.isRefreshingLocally&&this.refreshPromise)return this.log("Refresh already in progress, waiting for existing promise..."),this.refreshPromise;this.isRefreshingLocally=!0,this.refreshPromise=this._performRefresh();try{return await this.refreshPromise}finally{this.isRefreshingLocally=!1,this.refreshPromise=null}}async _performRefresh(){try{this.log("Starting token refresh...");let i=await L.refreshAccessToken();if(!i.success)return this.log("Token refresh failed",{errors:i.errors}),await b.clearTokens(),this.config.showNotification?.(this.getSessionExpiredMessage(),"warning"),this.config.onSessionExpired?.(),!1;let e=i.data,t={accessToken:e.token,refreshToken:e.refreshToken,expiresAt:e.expiresAt,refreshExpiresAt:e.refreshExpiresAt};return await b.saveTokens(t),this.log("Tokens refreshed and saved successfully"),this.lastActivityTime=Date.now(),!0}catch(i){return this.log("Token refresh error",{error:i instanceof Error?i.message:String(i)}),await b.clearTokens(),this.config.showNotification?.(this.getSessionExpiredMessage(),"warning"),this.config.onSessionExpired?.(),!1}}isRefreshing(){return this.isRefreshingLocally}setupResponseInterceptor(){L.setResponseInterceptor(async i=>{this.updateLastActivity();let e=this.detectAuthorizationError(i);if(e.isAuthError){if(this.log("\u{1F6A8} Authorization error detected:",{errorType:e.errorType,shouldLogout:e.shouldTriggerLogout}),e.isRefreshTokenInvalid||e.isTokenRefreshFailed)return this.log("Refresh token invalid, emitting TOKEN_REFRESH_FAILED event"),M.emit("TOKEN_REFRESH_FAILED",{message:e.userFriendlyMessage,error:e.errorDetails,source:"SessionManager.setupResponseInterceptor"}),i;e.shouldTriggerLogout&&(await b.hasValidTokens()&&!e.isIrrecoverable?(this.log("Access token expired, emitting TOKEN_EXPIRED event"),M.emit("TOKEN_EXPIRED",{message:"Access token expired, refresh needed",error:e.errorDetails,source:"SessionManager.setupResponseInterceptor"})):(this.log("No valid tokens or irrecoverable error, emitting SESSION_EXPIRED event"),M.emit("SESSION_EXPIRED",{message:e.userFriendlyMessage,error:e.errorDetails,source:"SessionManager.setupResponseInterceptor"})))}return i}),this.log("Response interceptor configured (non-blocking mode)")}async ensureCrudifyInitialized(){if(!this.crudifyInitialized)try{this.log("Initializing crudify SDK...");let i=L.getTokenData();if(i&&i.endpoint){this.log("Crudify already initialized by another service"),this.crudifyInitialized=!0;return}let e=this.config.env||"stg";L.config(e);let t=this.config.publicApiKey,n=this.config.enableLogging?"debug":"none",o=await L.init(t,n);if(o&&o.success===!1&&o.errors)throw new Error(`Failed to initialize crudify: ${JSON.stringify(o.errors)}`);this.crudifyInitialized=!0,this.log("Crudify SDK initialized successfully")}catch(i){throw g.error("[SessionManager] Failed to initialize crudify",i instanceof Error?i:{message:String(i)}),i}}detectAuthorizationError(i){let e={isAuthError:!1,isRefreshTokenInvalid:!1,isTokenRefreshFailed:!1,isTokenExpired:!1,isUnauthorized:!1,isIrrecoverable:!1,shouldTriggerLogout:!1,errorType:"",errorDetails:null,userFriendlyMessage:""};if(i.errors&&Array.isArray(i.errors)){let t=i.errors.find(n=>n.errorType==="Unauthorized"||n.message?.includes("Unauthorized")||n.message?.includes("Not Authorized")||n.message?.includes("NOT_AUTHORIZED")||n.message?.includes("Token")||n.message?.includes("TOKEN")||n.message?.includes("Authentication")||n.message?.includes("UNAUTHENTICATED")||n.extensions?.code==="UNAUTHENTICATED"||n.extensions?.code==="FORBIDDEN");t&&(e.isAuthError=!0,e.errorType="GraphQL Array",e.errorDetails=t,e.shouldTriggerLogout=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.",(t.message?.includes("TOKEN")||t.message?.includes("Token"))&&(e.isTokenExpired=!0),t.extensions?.code==="UNAUTHENTICATED"&&(e.isUnauthorized=!0))}if(!e.isAuthError&&i.errors&&typeof i.errors=="object"&&!Array.isArray(i.errors)){let n=Object.values(i.errors).flat().find(o=>typeof o=="string"&&(o.includes("NOT_AUTHORIZED")||o.includes("TOKEN_REFRESH_FAILED")||o.includes("TOKEN_HAS_EXPIRED")||o.includes("PLEASE_LOGIN")||o.includes("Unauthorized")||o.includes("UNAUTHENTICATED")||o.includes("SESSION_EXPIRED")||o.includes("INVALID_TOKEN")));n&&typeof n=="string"&&(e.isAuthError=!0,e.errorType="GraphQL Object",e.errorDetails=i.errors,e.shouldTriggerLogout=!0,n.includes("TOKEN_REFRESH_FAILED")?(e.isTokenRefreshFailed=!0,e.isRefreshTokenInvalid=!0,e.isIrrecoverable=!0,e.userFriendlyMessage="Tu sesi\xF3n ha caducado. Por favor, inicia sesi\xF3n nuevamente."):n.includes("TOKEN_HAS_EXPIRED")||n.includes("SESSION_EXPIRED")?(e.isTokenExpired=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente."):n.includes("INVALID_TOKEN")?(e.isTokenExpired=!0,e.isIrrecoverable=!0,e.userFriendlyMessage="Token inv\xE1lido. Por favor, inicia sesi\xF3n nuevamente."):e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.")}if(!e.isAuthError&&i.data?.response?.status){let t=i.data.response.status.toUpperCase();(t==="UNAUTHORIZED"||t==="UNAUTHENTICATED")&&(e.isAuthError=!0,e.errorType="Status",e.errorDetails=i.data.response,e.isUnauthorized=!0,e.shouldTriggerLogout=!0,e.isIrrecoverable=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.")}if(!e.isAuthError&&i.data?.response?.data)try{let t=typeof i.data.response.data=="string"?JSON.parse(i.data.response.data):i.data.response.data;(t.error==="REFRESH_TOKEN_INVALID"||t.error==="TOKEN_EXPIRED"||t.error==="INVALID_TOKEN")&&(e.isAuthError=!0,e.errorType="Parsed Data",e.errorDetails=t,e.shouldTriggerLogout=!0,e.isIrrecoverable=!0,t.error==="REFRESH_TOKEN_INVALID"?(e.isRefreshTokenInvalid=!0,e.isTokenRefreshFailed=!0,e.userFriendlyMessage="Tu sesi\xF3n ha caducado. Por favor, inicia sesi\xF3n nuevamente."):(e.isTokenExpired=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente."))}catch{}if(!e.isAuthError&&i.errorCode){let t=String(i.errorCode).toUpperCase();(t==="UNAUTHORIZED"||t==="UNAUTHENTICATED"||t==="TOKEN_EXPIRED"||t==="INVALID_TOKEN")&&(e.isAuthError=!0,e.errorType="Error Code",e.errorDetails={errorCode:t},e.shouldTriggerLogout=!0,t==="TOKEN_EXPIRED"?e.isTokenExpired=!0:e.isUnauthorized=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.")}return e}updateLastActivity(){this.lastActivityTime=Date.now(),this.log("Last activity updated")}getTimeSinceLastActivity(){return this.lastActivityTime===0?0:Date.now()-this.lastActivityTime}checkInactivity(){let i=this.getTimeSinceLastActivity();if(this.lastActivityTime===0)return"none";let e=1800*1e3;return i>e?(this.log(`Inactivity timeout: ${Math.floor(i/6e4)} minutes since last activity`),"logout"):"none"}async clearSession(){await b.clearTokens(),await L.logout(),this.lastActivityTime=0,this.log("Session cleared completely")}getSessionExpiredMessage(){return this.config.translateFn?Se("SESSION_EXPIRED",{translateFn:this.config.translateFn,enableDebug:this.config.enableLogging}):"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente."}log(i,e){this.config.enableLogging&&g.debug(`[SessionManager] ${i}`,e)}formatError(i){return i?typeof i=="string"?i:typeof i=="object"?Object.values(i).flat().map(String).join(", "):"Authentication failed":"Unknown error"}};import{useState as fi,useEffect as ie,useCallback as W}from"react";function Ce(r={}){let[i,e]=fi({isAuthenticated:!1,isLoading:!0,isInitialized:!1,tokens:null,error:null}),t=ee.getInstance(),n=W(async()=>{try{e(s=>({...s,isLoading:!0,error:null}));let u={autoRestore:r.autoRestore??!0,enableLogging:r.enableLogging??!1,showNotification:r.showNotification,translateFn:r.translateFn,apiEndpointAdmin:r.apiEndpointAdmin,apiKeyEndpointAdmin:r.apiKeyEndpointAdmin,publicApiKey:r.publicApiKey,env:r.env||"stg",onSessionExpired:()=>{e(s=>({...s,isAuthenticated:!1,tokens:null,error:"Session expired"})),r.onSessionExpired?.()},onSessionRestored:s=>{e(E=>({...E,isAuthenticated:!0,tokens:s,error:null})),r.onSessionRestored?.(s)},onLoginSuccess:s=>{e(E=>({...E,isAuthenticated:!0,tokens:s,error:null}))},onLogout:()=>{e(s=>({...s,isAuthenticated:!1,tokens:null,error:null}))}};await t.initialize(u),t.setupResponseInterceptor();let l=await t.isAuthenticated(),f=await t.getTokenInfo();e(s=>({...s,isAuthenticated:l,isInitialized:!0,isLoading:!1,tokens:f.crudifyTokens.accessToken?{accessToken:f.crudifyTokens.accessToken,refreshToken:f.crudifyTokens.refreshToken,expiresAt:f.crudifyTokens.expiresAt,refreshExpiresAt:f.crudifyTokens.refreshExpiresAt}:null}))}catch(u){let l=u instanceof Error?u.message:"Initialization failed";g.error("[useSession] Initialize failed",u instanceof Error?u:{message:l}),e(f=>({...f,isLoading:!1,isInitialized:!0,error:l}))}},[r.autoRestore,r.enableLogging,r.onSessionExpired,r.onSessionRestored]),o=W(async(u,l)=>{e(f=>({...f,isLoading:!0,error:null}));try{let f=await t.login(u,l);return f.success&&f.tokens?e(s=>({...s,isAuthenticated:!0,tokens:f.tokens,isLoading:!1,error:null})):e(s=>({...s,isAuthenticated:!1,tokens:null,isLoading:!1,error:null})),f}catch(f){let s=f instanceof Error?f.message:"Login failed";g.error("[useSession] Login error",f instanceof Error?f:{message:s});let E=s.includes("INVALID_CREDENTIALS")||s.includes("Invalid email")||s.includes("Invalid password")||s.includes("credentials");return e(k=>({...k,isAuthenticated:!1,tokens:null,isLoading:!1,error:E?null:s})),{success:!1,error:s}}},[t]),m=W(async()=>{e(u=>({...u,isLoading:!0}));try{await t.logout(),e(u=>({...u,isAuthenticated:!1,tokens:null,isLoading:!1,error:null}))}catch(u){e(l=>({...l,isAuthenticated:!1,tokens:null,isLoading:!1,error:u instanceof Error?u.message:"Logout error"}))}},[t]),T=W(async()=>{try{let u=await t.refreshTokens();if(u){let l=await t.getTokenInfo();e(f=>({...f,tokens:l.crudifyTokens.accessToken?{accessToken:l.crudifyTokens.accessToken,refreshToken:l.crudifyTokens.refreshToken,expiresAt:l.crudifyTokens.expiresAt,refreshExpiresAt:l.crudifyTokens.refreshExpiresAt}:null,error:null}))}else e(l=>({...l,isAuthenticated:!1,tokens:null,error:"Token refresh failed"}));return u}catch(u){return e(l=>({...l,isAuthenticated:!1,tokens:null,error:u instanceof Error?u.message:"Token refresh failed"})),!1}},[t]),x=W(()=>{e(u=>({...u,error:null}))},[]),A=W(async()=>t.getTokenInfo(),[t]);ie(()=>{n()},[n]),ie(()=>{if(!i.isAuthenticated||!i.tokens)return;let u=we.getInstance(),l=()=>{t.updateLastActivity()},f=u.subscribe(l);window.addEventListener("popstate",l);let s=async()=>{let R=(await t.getTokenInfo()).crudifyTokens.expiresIn||0;return R<300*1e3?30*1e3:R<1800*1e3?60*1e3:120*1e3},E,k=async()=>{let S=await s();E=setTimeout(async()=>{if(t.isRefreshing()){k();return}let R=await t.getTokenInfo(),w=R.crudifyTokens.expiresIn||0,C=((R.crudifyTokens.expiresAt||0)-(Date.now()-w))*.5;if(w>0&&w<=C)if(e(K=>({...K,isLoading:!0})),await t.refreshTokens()){let K=await t.getTokenInfo();e(ce=>({...ce,isLoading:!1,tokens:K.crudifyTokens.accessToken?{accessToken:K.crudifyTokens.accessToken,refreshToken:K.crudifyTokens.refreshToken,expiresAt:K.crudifyTokens.expiresAt,refreshExpiresAt:K.crudifyTokens.refreshExpiresAt}:null}))}else e(K=>({...K,isLoading:!1,isAuthenticated:!1,tokens:null}));let v=t.getTimeSinceLastActivity(),X=1800*1e3;v>X?await m():k()},S)};return k(),()=>{clearTimeout(E),window.removeEventListener("popstate",l),f()}},[i.isAuthenticated,i.tokens,t,r.enableLogging,m]),ie(()=>{let u=M.subscribe(async l=>{if(l.type==="TOKEN_EXPIRED"){if(t.isRefreshing())return;e(f=>({...f,isLoading:!0}));try{if(await t.refreshTokens()){let s=await t.getTokenInfo();e(E=>({...E,isLoading:!1,tokens:s.crudifyTokens.accessToken?{accessToken:s.crudifyTokens.accessToken,refreshToken:s.crudifyTokens.refreshToken,expiresAt:s.crudifyTokens.expiresAt,refreshExpiresAt:s.crudifyTokens.refreshExpiresAt}:null}))}else M.emit("SESSION_EXPIRED",{message:"Failed to refresh token after detecting expiration",source:"useSession.TOKEN_EXPIRED handler"})}catch(f){M.emit("SESSION_EXPIRED",{message:f instanceof Error?f.message:"Unknown error during refresh",source:"useSession.TOKEN_EXPIRED handler (error)"})}}(l.type==="SESSION_EXPIRED"||l.type==="TOKEN_REFRESH_FAILED")&&(e(f=>({...f,isAuthenticated:!1,tokens:null,isLoading:!1,error:l.details?.message||"Session expired"})),r.onSessionExpired?.())});return()=>u()},[r.onSessionExpired,t]),ie(()=>{let u=b.subscribeToChanges((l,f,s)=>{f===b.SYNC_EVENTS.TOKENS_CLEARED?s&&i.isAuthenticated?(g.debug("[useSession] Cross-tab logout detected"),e(E=>({...E,isAuthenticated:!1,tokens:null})),r.onSessionExpired?.()):s&&e(E=>({...E,isAuthenticated:!1,tokens:null})):f===b.SYNC_EVENTS.TOKENS_UPDATED&&l&&(g.debug("[useSession] Cross-tab login/refresh detected"),e(E=>({...E,tokens:l,isAuthenticated:!0,error:null})))});return()=>u()},[i.isAuthenticated,r.onSessionExpired]);let F=W(()=>{t.updateLastActivity()},[t]);return{...i,login:o,logout:m,refreshTokens:T,clearError:x,getTokenInfo:A,updateActivity:F,isExpiringSoon:i.tokens?i.tokens.expiresAt-Date.now()<300*1e3:!1,expiresIn:i.tokens?Math.max(0,i.tokens.expiresAt-Date.now()):0,refreshExpiresIn:i.tokens?Math.max(0,i.tokens.refreshExpiresAt-Date.now()):0}}import{useState as De,createContext as gi,useContext as pi,useCallback as te,useEffect as mi}from"react";import{Snackbar as yi,Alert as hi,Box as Ei,Portal as vi}from"@mui/material";import{v4 as Ti}from"uuid";import bi from"dompurify";import{jsx as B,jsxs as ki}from"react/jsx-runtime";var Le=gi(null),Ai=r=>bi.sanitize(r,{ALLOWED_TAGS:["b","i","em","strong","br","span"],ALLOWED_ATTR:["class"],FORBID_TAGS:["script","iframe","object","embed"],FORBID_ATTR:["onload","onerror","onclick","onmouseover","onfocus","onblur"],WHOLE_DOCUMENT:!1,RETURN_DOM:!1,RETURN_DOM_FRAGMENT:!1,RETURN_TRUSTED_TYPE:!1}),fe=({children:r,maxNotifications:i=5,defaultAutoHideDuration:e=6e3,position:t={vertical:"top",horizontal:"right"},enabled:n=!1,allowHtml:o=!1})=>{let[m,T]=De([]),x=te((l,f="info",s)=>{if(!n)return"";if(!l||typeof l!="string")return g.warn("GlobalNotificationProvider: Invalid message provided"),"";l.length>1e3&&(g.warn("GlobalNotificationProvider: Message too long, truncating"),l=l.substring(0,1e3)+"...");let E=Ti(),k={id:E,message:l,severity:f,autoHideDuration:s?.autoHideDuration??e,persistent:s?.persistent??!1,allowHtml:s?.allowHtml??o};return T(S=>[...S.length>=i?S.slice(-(i-1)):S,k]),E},[i,e,n,o]),A=te(l=>{T(f=>f.filter(s=>s.id!==l))},[]),F=te(()=>{T([])},[]),u={showNotification:x,hideNotification:A,clearAllNotifications:F};return ki(Le.Provider,{value:u,children:[r,n&&B(vi,{children:B(Ei,{sx:{position:"fixed",zIndex:9999,[t.vertical]:(t.vertical==="top",24),[t.horizontal]:t.horizontal==="right"||t.horizontal==="left"?24:"50%",...t.horizontal==="center"&&{transform:"translateX(-50%)"},display:"flex",flexDirection:t.vertical==="top"?"column":"column-reverse",gap:1,maxWidth:"400px",width:"auto"},children:m.map(l=>B(Ii,{notification:l,onClose:()=>A(l.id)},l.id))})})]})},Ii=({notification:r,onClose:i})=>{let[e,t]=De(!0),n=te((o,m)=>{m!=="clickaway"&&(t(!1),setTimeout(i,300))},[i]);return mi(()=>{if(!r.persistent&&r.autoHideDuration){let o=setTimeout(()=>{n()},r.autoHideDuration);return()=>clearTimeout(o)}},[r.autoHideDuration,r.persistent,n]),B(yi,{open:e,onClose:n,sx:{position:"relative","& .MuiSnackbarContent-root":{minWidth:"auto"}},TransitionProps:{enter:!0,exit:!0},children:B(hi,{variant:"filled",severity:r.severity,onClose:n,sx:{width:"100%",minWidth:"280px",maxWidth:"400px",wordBreak:"break-word"},children:r.allowHtml?B("span",{dangerouslySetInnerHTML:{__html:Ai(r.message)}}):B("span",{children:r.message})})})},Fe=()=>{let r=pi(Le);if(!r)throw new Error("useGlobalNotification debe ser usado dentro de un GlobalNotificationProvider");return r};import{createContext as Si,useContext as wi,useEffect as xi,useState as j}from"react";import J from"@nocios/crudify-browser";var ge=class r{constructor(){this.listeners=[];this.credentials=null;this.isReady=!1}static getInstance(){return r.instance||(r.instance=new r),r.instance}notifyCredentialsReady(i){this.credentials=i,this.isReady=!0,this.listeners.forEach(e=>{try{e(i)}catch(t){g.error("[CredentialsEventBus] Error in listener",t instanceof Error?t:{message:String(t)})}}),this.listeners=[]}waitForCredentials(){return this.isReady&&this.credentials?Promise.resolve(this.credentials):new Promise(i=>{this.listeners.push(i)})}reset(){this.credentials=null,this.isReady=!1,this.listeners=[]}areCredentialsReady(){return this.isReady&&this.credentials!==null}},re=ge.getInstance();import{jsx as Pi}from"react/jsx-runtime";var ze=Si(void 0),Ke=({config:r,children:i})=>{let[e,t]=j(!0),[n,o]=j(null),[m,T]=j(!1),[x,A]=j(""),[F,u]=j();xi(()=>{if(!r.publicApiKey){o("No publicApiKey provided"),t(!1),T(!1);return}let f=`${r.publicApiKey}-${r.env}`;if(f===x&&m){t(!1);return}(async()=>{t(!0),o(null),T(!1);try{J.config(r.env||"prod");let E=await J.init(r.publicApiKey,"none");if(u(E),typeof J.transaction=="function"&&typeof J.login=="function")T(!0),A(f),E.apiEndpointAdmin&&E.apiKeyEndpointAdmin&&re.notifyCredentialsReady({apiUrl:E.apiEndpointAdmin,apiKey:E.apiKeyEndpointAdmin});else throw new Error("Crudify methods not properly initialized")}catch(E){let k=E instanceof Error?E.message:"Failed to initialize Crudify";g.error("[CrudifyProvider] Initialization error",E instanceof Error?E:{message:String(E)}),o(k),T(!1)}finally{t(!1)}})()},[r.publicApiKey,r.env,x,m]);let l={crudify:m?J:null,isLoading:e,error:n,isInitialized:m,adminCredentials:F};return Pi(ze.Provider,{value:l,children:i})},Ue=()=>{let r=wi(ze);if(r===void 0)throw new Error("useCrudify must be used within a CrudifyProvider");return r};import Ni,{createContext as Ri,useContext as Ci,useMemo as pe}from"react";import{Fragment as Li,jsx as D,jsxs as G}from"react/jsx-runtime";var He=Ri(void 0);function Oe({children:r,options:i={},config:e,showNotifications:t=!1,notificationOptions:n={}}){let o;try{let{showNotification:s}=Fe();o=s}catch{}let m={};try{let s=Ue();s.isInitialized&&s.adminCredentials&&(m=s.adminCredentials)}catch{}let T=pe(()=>{let s=de({publicApiKey:e?.publicApiKey,env:e?.env,enableDebug:i?.enableLogging});return{publicApiKey:s.publicApiKey,env:s.env||"prod"}},[e,i?.enableLogging]),x=Ni.useMemo(()=>({...i,showNotification:o,apiEndpointAdmin:m.apiEndpointAdmin,apiKeyEndpointAdmin:m.apiKeyEndpointAdmin,publicApiKey:T.publicApiKey,env:T.env,onSessionExpired:()=>{i.onSessionExpired?.()}}),[i,o,m.apiEndpointAdmin,m.apiKeyEndpointAdmin,T]),A=Ce(x),F=pe(()=>{let s=de({publicApiKey:e?.publicApiKey,env:e?.env,appName:e?.appName,logo:e?.logo,loginActions:e?.loginActions,enableDebug:i?.enableLogging});return{publicApiKey:s.publicApiKey,env:s.env,appName:s.appName,loginActions:s.loginActions,logo:s.logo}},[e,i?.enableLogging]),u=pe(()=>{if(!A.tokens?.accessToken||!A.isAuthenticated)return null;try{let s=xe(A.tokens.accessToken);if(s&&s.sub&&s.email&&s.subscriber){let E={_id:s.sub,email:s.email,subscriberKey:s.subscriber};return Object.keys(s).forEach(k=>{["sub","email","subscriber"].includes(k)||(E[k]=s[k])}),E}}catch(s){g.error("Error decoding JWT token for sessionData",s instanceof Error?s:{message:String(s)})}return null},[A.tokens?.accessToken,A.isAuthenticated]),l={...A,sessionData:u,config:F},f={enabled:t,maxNotifications:n.maxNotifications||5,defaultAutoHideDuration:n.defaultAutoHideDuration||6e3,position:n.position||{vertical:"top",horizontal:"right"}};return D(He.Provider,{value:l,children:r})}function Ft(r){let i={enabled:r.showNotifications,maxNotifications:r.notificationOptions?.maxNotifications||5,defaultAutoHideDuration:r.notificationOptions?.defaultAutoHideDuration||6e3,position:r.notificationOptions?.position||{vertical:"top",horizontal:"right"},allowHtml:r.notificationOptions?.allowHtml||!1};return r.config?.publicApiKey?D(Ke,{config:{publicApiKey:r.config.publicApiKey,env:r.config.env||"prod",appName:r.config.appName,loginActions:r.config.loginActions,logo:r.config.logo},children:D(fe,{...i,children:D(Oe,{...r})})}):D(fe,{...i,children:D(Oe,{...r})})}function Di(){let r=Ci(He);if(r===void 0)throw new Error("useSessionContext must be used within a SessionProvider");return r}function zt(){let r=Di();return r.isInitialized?G("div",{style:{padding:"10px",margin:"10px",border:"1px solid #ccc",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace"},children:[D("h4",{children:"Session Debug Info"}),G("div",{children:[D("strong",{children:"Authenticated:"})," ",r.isAuthenticated?"Yes":"No"]}),G("div",{children:[D("strong",{children:"Loading:"})," ",r.isLoading?"Yes":"No"]}),G("div",{children:[D("strong",{children:"Error:"})," ",r.error||"None"]}),r.tokens&&G(Li,{children:[G("div",{children:[D("strong",{children:"Access Token:"})," ",r.tokens.accessToken.substring(0,20),"..."]}),G("div",{children:[D("strong",{children:"Refresh Token:"})," ",r.tokens.refreshToken.substring(0,20),"..."]}),G("div",{children:[D("strong",{children:"Access Expires In:"})," ",Math.round(r.expiresIn/1e3/60)," minutes"]}),G("div",{children:[D("strong",{children:"Refresh Expires In:"})," ",Math.round(r.refreshExpiresIn/1e3/60/60)," hours"]}),G("div",{children:[D("strong",{children:"Expiring Soon:"})," ",r.isExpiringSoon?"Yes":"No"]})]})]}):D("div",{children:"Session not initialized"})}import{useState as ne,useEffect as Me,useCallback as Ge,useRef as se}from"react";import Fi from"@nocios/crudify-browser";var Gt=(r={})=>{let{autoFetch:i=!0,retryOnError:e=!1,maxRetries:t=3}=r,[n,o]=ne(null),[m,T]=ne(!1),[x,A]=ne(null),[F,u]=ne({}),l=se(null),f=se(!0),s=se(0),E=se(0),k=Ge(()=>{o(null),A(null),T(!1),u({})},[]),S=Ge(async()=>{let R=Pe();if(!R){f.current&&(A("No user email available"),T(!1));return}l.current&&l.current.abort();let w=new AbortController;l.current=w;let z=++s.current;try{f.current&&(T(!0),A(null));let U=await Fi.readItems("users",{filter:{email:R},pagination:{limit:1}});if(z===s.current&&f.current&&!w.signal.aborted){let C=U.data;if(U.success&&C&&C.length>0){let v=C[0];o(v);let X={fullProfile:v,totalFields:Object.keys(v).length,displayData:{id:v.id,email:v.email,username:v.username,firstName:v.firstName,lastName:v.lastName,fullName:v.fullName||`${v.firstName||""} ${v.lastName||""}`.trim(),role:v.role,permissions:v.permissions||[],isActive:v.isActive,lastLogin:v.lastLogin,createdAt:v.createdAt,updatedAt:v.updatedAt,...Object.keys(v).filter(V=>!["id","email","username","firstName","lastName","fullName","role","permissions","isActive","lastLogin","createdAt","updatedAt"].includes(V)).reduce((V,K)=>({...V,[K]:v[K]}),{})}};u(X),A(null),E.current=0}else A("User profile not found"),o(null),u({})}}catch(U){if(z===s.current&&f.current){let C=U;if(C.name==="AbortError")return;e&&E.current<t&&(C.message?.includes("Network Error")||C.message?.includes("Failed to fetch"))?(E.current++,setTimeout(()=>{f.current&&S()},1e3*E.current)):(A("Failed to load user profile"),o(null),u({}))}}finally{z===s.current&&f.current&&T(!1),l.current===w&&(l.current=null)}},[e,t]);return Me(()=>{i&&S()},[i,S]),Me(()=>(f.current=!0,()=>{f.current=!1,l.current&&(l.current.abort(),l.current=null)}),[]),{userProfile:n,loading:m,error:x,extendedData:F,refreshProfile:S,clearProfile:k}};import{useState as me,useEffect as zi,useCallback as oe,useRef as Ki}from"react";import Ui from"@nocios/crudify-browser";var $t=(r,i={})=>{let{autoFetch:e=!0,onSuccess:t,onError:n}=i,{prefix:o,padding:m=0,separator:T=""}=r,[x,A]=me(""),[F,u]=me(!1),[l,f]=me(null),s=Ki(!1),E=oe(w=>{let z=String(w).padStart(m,"0");return`${o}${T}${z}`},[o,m,T]),k=oe(async()=>{u(!0),f(null);try{let w=await Ui.getNextSequence(o),z=w.data;if(w.success&&z?.value){let U=E(z.value);A(U),t?.(U)}else{let U=w.errors?._error?.[0]||"Failed to generate code";f(U),n?.(U)}}catch(w){let z=w instanceof Error?w.message:"Unknown error";f(z),n?.(z)}finally{u(!1)}},[o,E,t,n]),S=oe(async()=>{await k()},[k]),R=oe(()=>{f(null)},[]);return zi(()=>{e&&!x&&!s.current&&(s.current=!0,k())},[e,x,k]),{value:x,loading:F,error:l,regenerate:S,clearError:R}};import ye from"@nocios/crudify-browser";var he=class r{constructor(){this.state={status:"UNINITIALIZED",priority:null,publicApiKey:null,env:null,error:null,initializedBy:null};this.initializationPromise=null;this.highPriorityInitializerPresent=!1;this.waitingForHighPriority=new Set;this.HIGH_PRIORITY_WAIT_TIMEOUT=100}static getInstance(){return r.instance||(r.instance=new r),r.instance}registerHighPriorityInitializer(){this.highPriorityInitializerPresent=!0}isHighPriorityInitializerPresent(){return this.highPriorityInitializerPresent}getState(){return{...this.state}}async initialize(i){let{priority:e,publicApiKey:t,env:n,enableLogging:o,requestedBy:m}=i;if(this.state.status==="INITIALIZED"){this.state.publicApiKey!==t&&g.warn(`[CrudifyInitialization] ${m} attempted to initialize with different key. Already initialized with key: ${this.state.publicApiKey?.slice(0,10)}... by ${this.state.initializedBy}`);return}if(this.initializationPromise)return o&&g.debug(`[CrudifyInitialization] ${m} waiting for ongoing initialization...`),this.initializationPromise;if(e==="LOW"&&this.highPriorityInitializerPresent&&this.state.status==="UNINITIALIZED"){if(o&&g.debug(`[CrudifyInitialization] ${m} (LOW priority) waiting for HIGH priority initializer...`),this.waitingForHighPriority.add(m),await this.waitForHighPriorityOrTimeout(o),this.waitingForHighPriority.delete(m),this.getState().status==="INITIALIZED"){o&&g.debug(`[CrudifyInitialization] ${m} found initialization completed by HIGH priority`);return}o&&g.warn(`[CrudifyInitialization] ${m} timeout waiting for HIGH priority, initializing with LOW priority`)}e==="HIGH"&&this.state.status==="INITIALIZING"&&this.state.priority==="LOW"&&(g.warn(`[CrudifyInitialization] HIGH priority request from ${m} interrupting LOW priority initialization by ${this.state.initializedBy}`),this.state.status="UNINITIALIZED",this.initializationPromise=null),o&&g.debug(`[CrudifyInitialization] ${m} starting initialization (${e} priority)...`),this.state.status="INITIALIZING",this.state.priority=e,this.state.initializedBy=m,this.initializationPromise=this.performInitialization(t,n,o);try{await this.initializationPromise,this.state.status="INITIALIZED",this.state.publicApiKey=t,this.state.env=n,this.state.error=null,o&&g.info(`[CrudifyInitialization] Successfully initialized by ${m} (${e} priority)`)}catch(T){throw this.state.status="ERROR",this.state.error=T instanceof Error?T:new Error(String(T)),this.initializationPromise=null,g.error(`[CrudifyInitialization] Initialization failed for ${m}`,T instanceof Error?T:{message:String(T)}),T}}async waitForHighPriorityOrTimeout(i){return new Promise(e=>{let n=0,o=setInterval(()=>{if(n+=10,this.state.status==="INITIALIZED"&&this.state.priority==="HIGH"){clearInterval(o),e();return}if(this.state.status==="INITIALIZING"&&this.state.priority==="HIGH"){n=0;return}n>=this.HIGH_PRIORITY_WAIT_TIMEOUT&&(clearInterval(o),i&&g.debug(`[CrudifyInitialization] Timeout waiting for HIGH priority (${this.HIGH_PRIORITY_WAIT_TIMEOUT}ms)`),e())},10)})}async performInitialization(i,e,t){let n=ye.getTokenData();if(n&&n.endpoint){t&&g.debug("[CrudifyInitialization] SDK already initialized externally");return}ye.config(e);let o=t?"debug":"none",m=await ye.init(i,o);if(m.success===!1)throw new Error(`Crudify initialization failed: ${JSON.stringify(m.errors||"Unknown error")}`);m.apiEndpointAdmin&&m.apiKeyEndpointAdmin&&re.notifyCredentialsReady({apiUrl:m.apiEndpointAdmin,apiKey:m.apiKeyEndpointAdmin})}reset(){this.state={status:"UNINITIALIZED",priority:null,publicApiKey:null,env:null,error:null,initializedBy:null},this.initializationPromise=null,this.highPriorityInitializerPresent=!1,this.waitingForHighPriority.clear()}isInitialized(){return this.state.status==="INITIALIZED"}getDiagnostics(){return{...this.state,waitingCount:this.waitingForHighPriority.size,waitingComponents:Array.from(this.waitingForHighPriority),hasActivePromise:this.initializationPromise!==null}}},Q=he.getInstance();import{useState as ae,useCallback as N,useRef as Oi,useMemo as q}from"react";import le from"@nocios/crudify-browser";var _e=r=>{let i=new Uint8Array(r);return crypto.getRandomValues(i),Array.from(i,e=>e.toString(36).padStart(2,"0")).join("").substring(0,r)},Ve=()=>`file_${Date.now()}_${_e(7)}`,Hi=r=>{let i=r.lastIndexOf("."),e=i>0?r.substring(i):"",t=Date.now(),n=_e(6);return`${t}_${n}${e}`},Ee=(r,i)=>{if(r.startsWith("http://")||r.startsWith("https://"))try{let e=new URL(r);return e.pathname.startsWith("/")?e.pathname.substring(1):e.pathname}catch{if(i&&r.startsWith(i))return r.substring(i.length)}return i&&r.startsWith(i)?r.substring(i.length):r},ir=(r={})=>{let{acceptedTypes:i,maxFileSize:e=10*1024*1024,maxFiles:t,minFiles:n=0,visibility:o="private",onUploadComplete:m,onUploadError:T,onFileRemoved:x,onFilesChange:A,mode:F="edit"}=r,[u,l]=ae([]),[f,s]=ae(!1),[E,k]=ae(!1),[S,R]=ae([]),w=Oi(new Map),z=N(()=>{s(!0)},[]),U=N(()=>{k(!0),s(!0)},[]),C=N((c,p)=>{l(d=>d.map(h=>h.id===c?{...h,...p}:h))},[]),v=N(c=>{A?.(c)},[A]),X=N(c=>i&&i.length>0&&!i.includes(c.type)?{valid:!1,error:`File type not allowed: ${c.type}`}:c.size>e?{valid:!1,error:`File exceeds maximum size of ${(e/1048576).toFixed(1)}MB`}:{valid:!0},[i,e]),V=N(async(c,p)=>{try{if(!Q.isInitialized())throw new Error("Crudify is not initialized. Please wait for the application to finish loading.");let d=Hi(p.name),y=await le.generateSignedUrl({fileName:d,contentType:p.type,visibility:o});if(!y.success||!y.data)throw new Error("Failed to get upload URL");let h=y.data,{uploadUrl:P,s3Key:I,publicUrl:H}=h;if(!P||!I)throw new Error("Incomplete signed URL response");let Y=I.indexOf("/"),ci=Y>0?I.substring(Y+1):I;C(c.id,{status:"uploading",progress:0}),await new Promise((ue,$)=>{let O=new XMLHttpRequest;O.upload.addEventListener("progress",_=>{if(_.lengthComputable){let di=Math.round(_.loaded/_.total*100);C(c.id,{progress:di})}}),O.addEventListener("load",()=>{O.status>=200&&O.status<300?ue():$(new Error(`Upload failed with status ${O.status}`))}),O.addEventListener("error",()=>{$(new Error("Network error during upload"))}),O.addEventListener("abort",()=>{$(new Error("Upload cancelled"))}),O.open("PUT",P),O.setRequestHeader("Content-Type",p.type),O.send(p)});let ui={status:"completed",progress:100,filePath:ci,visibility:o,publicUrl:o==="public"?H:void 0,file:void 0};l(ue=>{let $=ue.map(_=>_.id===c.id?{..._,...ui}:_);v($);let O=$.find(_=>_.id===c.id);return O&&m?.(O),$})}catch(d){let y=d instanceof Error?d.message:"Unknown error";C(c.id,{status:"error",progress:0,errorMessage:y}),l(h=>{let P=h.find(I=>I.id===c.id);return P&&T?.(P,y),h})}},[C,m,T,o]),K=N(async c=>{let p=Array.from(c),d=[];l(y=>{if(t!==void 0){let I=y.filter(Y=>Y.status!=="pendingDeletion"&&Y.status!=="error").length,H=t-I;if(H<=0)return g.warn(`File limit of ${t} already reached`),y;p.length>H&&(p=p.slice(0,H),g.warn(`Only ${H} files will be added to not exceed limit`))}let h=[];for(let I of p){let H=X(I),Y={id:Ve(),name:I.name,size:I.size,contentType:I.type,status:H.valid?"pending":"error",progress:0,createdAt:Date.now(),file:H.valid?I:void 0,errorMessage:H.error,isExisting:!1};h.push(Y)}d=h;let P=[...y,...h];return v(P),P}),setTimeout(()=>{let y=d.filter(h=>h.status==="pending"&&h.file);for(let h of y)if(h.file){let P=V(h,h.file);w.current.set(h.id,P),P.finally(()=>{w.current.delete(h.id)})}},0)},[t,X,V,v]),ce=N(async c=>{let p=u.find(y=>y.id===c);if(!p)return{needsConfirmation:!1,isExisting:!1};let d=p.isExisting===!0;return F==="create"||!d?{needsConfirmation:!0,isExisting:d}:(R(y=>[...y,c]),l(y=>{let h=y.map(I=>I.id===c?{...I,status:"pendingDeletion"}:I),P=h.filter(I=>I.status!=="pendingDeletion");return v(P),h}),{needsConfirmation:!1,isExisting:d})},[u,F,v]),Ye=N(async c=>{let p=u.find(d=>d.id===c);if(!p)return{success:!1,error:"File not found"};if(!p.filePath)return l(d=>{let y=d.filter(h=>h.id!==c);return v(y),y}),{success:!0};try{if(!Q.isInitialized())return{success:!1,error:"Crudify not initialized"};let d=Ee(p.filePath);return(await le.disableFile({filePath:d})).success?(l(h=>{let P=h.filter(I=>I.id!==c);return v(P),P}),x?.(p),{success:!0}):{success:!1,error:"Failed to delete file"}}catch(d){return{success:!1,error:d instanceof Error?d.message:"Unknown error"}}},[u,v,x]),$e=N(c=>{let p=u.find(d=>d.id===c);return!p||!p.isExisting?!1:(R(d=>d.filter(y=>y!==c)),l(d=>{let y=d.map(h=>h.id===c?{...h,status:"completed"}:h);return v(y),y}),!0)},[u,v]),We=N(()=>{S.length!==0&&(l(c=>{let p=c.map(d=>S.includes(d.id)?{...d,status:"completed"}:d);return v(p),p}),R([]))},[S,v]),Be=N(async()=>{if(S.length===0)return{success:!0,errors:[]};let c=[],p=[];if(!Q.isInitialized())return{success:!1,errors:["Crudify is not initialized. Please wait for the application to finish loading."]};for(let d of S){let y=u.find(h=>h.id===d);if(!y?.filePath){p.push(d);continue}try{let h=Ee(y.filePath);(await le.disableFile({filePath:h})).success?(p.push(d),x?.(y)):c.push(`Failed to delete ${y.name}`)}catch(h){c.push(`Error deleting ${y.name}: ${h instanceof Error?h.message:"Unknown error"}`)}}return p.length>0&&(l(d=>d.filter(h=>!p.includes(h.id))),R(d=>d.filter(y=>!p.includes(y)))),{success:c.length===0,errors:c}},[u,S,x]),Xe=N(()=>{l([]),v([])},[v]),Ze=N(async c=>{let p=u.find(y=>y.id===c);if(!p||p.status!=="error"||!p.file){g.warn("Cannot retry: file not found or no original file");return}C(c,{status:"pending",progress:0,errorMessage:void 0});let d=V(p,p.file);w.current.set(c,d),d.finally(()=>{w.current.delete(c)})},[u,C,V]),qe=N(async()=>{let c=Array.from(w.current.values());return c.length>0&&await Promise.allSettled(c),new Promise(p=>{setTimeout(()=>{l(d=>{let y=d.filter(h=>h.status==="completed"&&h.filePath).map(h=>h.filePath);return p(y),d})},0)})},[]),je=c=>{let p=c.split(".").pop()?.toLowerCase()||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",txt:"text/plain",csv:"text/csv",mp3:"audio/mpeg",wav:"audio/wav",mp4:"video/mp4",webm:"video/webm",zip:"application/zip",rar:"application/x-rar-compressed",json:"application/json",xml:"application/xml"}[p]||"application/octet-stream"},Je=N((c,p)=>{let d=c.map(y=>{let h=Ee(y.filePath,p),P=h.includes("/public/")||h.startsWith("public/")?"public":"private",I=y.contentType||je(y.name);return{id:Ve(),name:y.name,size:y.size||0,contentType:I,status:"completed",progress:100,filePath:h,visibility:P,createdAt:Date.now(),isExisting:!0}});l(d),v(d)},[v]),Qe=N(async c=>{let p=u.find(d=>d.id===c);if(!p||!p.filePath)return null;if(p.visibility==="public"&&p.publicUrl)return p.publicUrl;try{if(!Q.isInitialized())return null;let d=await le.getFileUrl({filePath:p.filePath,expiresIn:3600}),y=d.data;return d.success&&y?.url?y.url:null}catch{return null}},[u]),ei=q(()=>u.some(c=>c.status==="uploading"||c.status==="pending"),[u]),ii=q(()=>u.filter(c=>c.status==="uploading"||c.status==="pending").length,[u]),ti=q(()=>u.filter(c=>c.status==="completed"&&c.filePath).map(c=>c.filePath),[u]),Z=q(()=>u.filter(c=>c.status!=="pendingDeletion"),[u]),ri=q(()=>Z.filter(c=>c.status==="completed"||c.status==="pending"||c.status==="uploading").length,[Z]),{isValid:ni,validationError:si,validationErrorKey:oi,validationErrorParams:ai}=q(()=>{let c=Z.filter(d=>d.status==="completed").length;if(c<n){let d=n===1?"file.validation.minFilesRequired":"file.validation.minFilesRequiredPlural";return{isValid:!1,validationError:d,validationErrorKey:d,validationErrorParams:{count:n}}}return t!==void 0&&c>t?{isValid:!1,validationError:"file.validation.maxFilesExceeded",validationErrorKey:"file.validation.maxFilesExceeded",validationErrorParams:{count:t}}:Z.some(d=>d.status==="error")?{isValid:!1,validationError:"file.validation.filesWithErrors",validationErrorKey:"file.validation.filesWithErrors",validationErrorParams:{}}:{isValid:!0,validationError:null,validationErrorKey:null,validationErrorParams:{}}},[Z,n,t]),li=S.length>0;return{files:u,activeFiles:Z,activeFileCount:ri,isUploading:ei,pendingCount:ii,addFiles:K,removeFile:ce,deleteFileImmediately:Ye,restoreFile:$e,clearFiles:Xe,retryUpload:Ze,isValid:ni,validationError:si,validationErrorKey:oi,validationErrorParams:ai,waitForUploads:qe,completedFilePaths:ti,initializeFiles:Je,isTouched:f,markAsTouched:z,isSubmitted:E,markAsSubmitted:U,getPreviewUrl:Qe,pendingDeletions:S,hasPendingDeletions:li,commitDeletions:Be,restorePendingDeletions:We}};export{b as a,ee as b,Ce as c,fe as d,Fe as e,re as f,Ke as g,Ue as h,Ft as i,Di as j,zt as k,Gt as l,$t as m,he as n,Q as o,ir as p};
|