@nice2dev/auth 1.0.6 → 1.0.10

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/dist/index.mjs CHANGED
@@ -10,36 +10,63 @@ function X(a = {}) {
10
10
  } catch {
11
11
  }
12
12
  return { isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null };
13
- }), c = x((s) => {
14
- m((h) => {
15
- const p = { ...h, ...s };
16
- return f && typeof window < "u" && (p.isAuthenticated ? localStorage.setItem(u, JSON.stringify({ isAuthenticated: !0, user: p.user })) : localStorage.removeItem(u)), p;
17
- });
18
- }, [f, u]), v = x(async (s, h) => {
19
- c({ loading: !0, error: null });
20
- try {
21
- if (n) {
22
- const p = await n(s, h);
23
- return c({ isAuthenticated: !0, user: p.user, tokens: p.tokens, loading: !1 }), !0;
13
+ }), c = x(
14
+ (s) => {
15
+ m((h) => {
16
+ const p = { ...h, ...s };
17
+ return f && typeof window < "u" && (p.isAuthenticated ? localStorage.setItem(
18
+ u,
19
+ JSON.stringify({ isAuthenticated: !0, user: p.user })
20
+ ) : localStorage.removeItem(u)), p;
21
+ });
22
+ },
23
+ [f, u]
24
+ ), v = x(
25
+ async (s, h) => {
26
+ c({ loading: !0, error: null });
27
+ try {
28
+ if (n) {
29
+ const p = await n(s, h);
30
+ return c({
31
+ isAuthenticated: !0,
32
+ user: p.user,
33
+ tokens: p.tokens,
34
+ loading: !1
35
+ }), !0;
36
+ }
37
+ return c({ loading: !1, error: "No login handler configured" }), !1;
38
+ } catch (p) {
39
+ return c({
40
+ loading: !1,
41
+ error: (p == null ? void 0 : p.message) ?? "Login failed"
42
+ }), !1;
24
43
  }
25
- return c({ loading: !1, error: "No login handler configured" }), !1;
26
- } catch (p) {
27
- return c({ loading: !1, error: (p == null ? void 0 : p.message) ?? "Login failed" }), !1;
28
- }
29
- }, [n, c]), i = x(() => {
44
+ },
45
+ [n, c]
46
+ ), i = x(() => {
30
47
  d == null || d(), c({ isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null });
31
48
  }, [d, c]), k = x(async () => {
32
49
  var s;
33
- if (!((s = r.tokens) != null && s.refreshToken) || !o) return !1;
50
+ if (!((s = r.tokens) != null && s.refreshToken) || !o)
51
+ return !1;
34
52
  try {
35
53
  const h = await o(r.tokens.refreshToken);
36
54
  return c({ tokens: h }), !0;
37
55
  } catch {
38
56
  return i(), !1;
39
57
  }
40
- }, [r.tokens, o, c, i]), b = x((s, h) => {
41
- c({ isAuthenticated: !0, user: s, tokens: h, loading: !1, error: null });
42
- }, [c]), C = x((...s) => r.user ? s.every((h) => r.user.roles.includes(h)) : !1, [r.user]), w = x((...s) => r.user ? s.every((h) => r.user.permissions.includes(h)) : !1, [r.user]), A = x(() => {
58
+ }, [r.tokens, o, c, i]), b = x(
59
+ (s, h) => {
60
+ c({ isAuthenticated: !0, user: s, tokens: h, loading: !1, error: null });
61
+ },
62
+ [c]
63
+ ), C = x(
64
+ (...s) => r.user ? s.every((h) => r.user.roles.includes(h)) : !1,
65
+ [r.user]
66
+ ), w = x(
67
+ (...s) => r.user ? s.every((h) => r.user.permissions.includes(h)) : !1,
68
+ [r.user]
69
+ ), A = x(() => {
43
70
  c({ error: null });
44
71
  }, [c]);
45
72
  return {
@@ -185,186 +212,276 @@ const B = {
185
212
  4: "#2e7d32"
186
213
  };
187
214
  function I(a) {
188
- if (!a) return 0;
215
+ if (!a)
216
+ return 0;
189
217
  let n = 0;
190
218
  return a.length >= 8 && n++, a.length >= 12 && n++, /[a-z]/.test(a) && /[A-Z]/.test(a) && n++, /\d/.test(a) && n++, /[^a-zA-Z0-9]/.test(a) && n++, Math.min(4, n);
191
219
  }
192
- const M = E(({
193
- password: a,
194
- strength: n,
195
- showLabel: o = !0,
196
- labels: d = B,
197
- className: u
198
- }, f) => {
199
- const r = n ?? I(a), m = G[r], c = (r + 1) / 5 * 100;
200
- return /* @__PURE__ */ t("div", { ref: f, className: `nice-password-strength${u ? ` ${u}` : ""}`, children: [
201
- /* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e("div", { className: "nice-password-strength__fill", style: { width: `${c}%`, backgroundColor: m } }) }),
202
- o && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: m }, children: d[r] })
203
- ] });
204
- });
220
+ const M = E(
221
+ ({ password: a, strength: n, showLabel: o = !0, labels: d = B, className: u }, f) => {
222
+ const r = n ?? I(a), m = G[r], c = (r + 1) / 5 * 100;
223
+ return /* @__PURE__ */ t("div", { ref: f, className: `nice-password-strength${u ? ` ${u}` : ""}`, children: [
224
+ /* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e(
225
+ "div",
226
+ {
227
+ className: "nice-password-strength__fill",
228
+ style: { width: `${c}%`, backgroundColor: m }
229
+ }
230
+ ) }),
231
+ o && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: m }, children: d[r] })
232
+ ] });
233
+ }
234
+ );
205
235
  M.displayName = "NicePasswordStrength";
206
- const Q = E(({
207
- onSubmit: a,
208
- loading: n = !1,
209
- error: o,
210
- onLoginClick: d,
211
- showPasswordStrength: u = !0,
212
- minPasswordStrength: f = 2,
213
- termsUrl: r,
214
- privacyUrl: m,
215
- title: c = "Create Account",
216
- logo: v,
217
- footer: i,
218
- className: k,
219
- style: b
220
- }, C) => {
221
- const [w, A] = _(""), [s, h] = _(""), [p, $] = _(""), [g, S] = _(""), [y, T] = _(""), [R, L] = _(!1), P = I(g), F = g === y, D = w && p && g && F && R && P >= f && !n, l = x((N) => {
222
- N.preventDefault(), D && (a == null || a({ firstName: w, lastName: s, email: p, password: g, acceptTerms: R }));
223
- }, [D, w, s, p, g, R, a]);
224
- return /* @__PURE__ */ t(
225
- "form",
226
- {
227
- ref: C,
228
- className: `nice-register-form${k ? ` ${k}` : ""}`,
229
- style: b,
230
- onSubmit: l,
231
- noValidate: !0,
232
- children: [
233
- v && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: v }),
234
- /* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: c }),
235
- o && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: o }),
236
- /* @__PURE__ */ t("div", { className: "nice-register-form__row", children: [
236
+ const Q = E(
237
+ ({
238
+ onSubmit: a,
239
+ loading: n = !1,
240
+ error: o,
241
+ onLoginClick: d,
242
+ showPasswordStrength: u = !0,
243
+ minPasswordStrength: f = 2,
244
+ termsUrl: r,
245
+ privacyUrl: m,
246
+ title: c = "Create Account",
247
+ logo: v,
248
+ footer: i,
249
+ className: k,
250
+ style: b
251
+ }, C) => {
252
+ const [w, A] = _(""), [s, h] = _(""), [p, $] = _(""), [g, S] = _(""), [y, T] = _(""), [R, L] = _(!1), P = I(g), F = g === y, D = w && p && g && F && R && P >= f && !n, l = x(
253
+ (N) => {
254
+ N.preventDefault(), D && (a == null || a({ firstName: w, lastName: s, email: p, password: g, acceptTerms: R }));
255
+ },
256
+ [D, w, s, p, g, R, a]
257
+ );
258
+ return /* @__PURE__ */ t(
259
+ "form",
260
+ {
261
+ ref: C,
262
+ className: `nice-register-form${k ? ` ${k}` : ""}`,
263
+ style: b,
264
+ onSubmit: l,
265
+ noValidate: !0,
266
+ children: [
267
+ v && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: v }),
268
+ /* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: c }),
269
+ o && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: o }),
270
+ /* @__PURE__ */ t("div", { className: "nice-register-form__row", children: [
271
+ /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
272
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
273
+ /* @__PURE__ */ e(
274
+ "input",
275
+ {
276
+ id: "nice-reg-first",
277
+ className: "nice-input",
278
+ type: "text",
279
+ value: w,
280
+ onChange: (N) => A(N.target.value),
281
+ required: !0,
282
+ disabled: n,
283
+ autoComplete: "given-name"
284
+ }
285
+ )
286
+ ] }),
287
+ /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
288
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-last", children: "Last name" }),
289
+ /* @__PURE__ */ e(
290
+ "input",
291
+ {
292
+ id: "nice-reg-last",
293
+ className: "nice-input",
294
+ type: "text",
295
+ value: s,
296
+ onChange: (N) => h(N.target.value),
297
+ disabled: n,
298
+ autoComplete: "family-name"
299
+ }
300
+ )
301
+ ] })
302
+ ] }),
237
303
  /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
238
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
239
- /* @__PURE__ */ e("input", { id: "nice-reg-first", className: "nice-input", type: "text", value: w, onChange: (N) => A(N.target.value), required: !0, disabled: n, autoComplete: "given-name" })
304
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-email", children: "Email *" }),
305
+ /* @__PURE__ */ e(
306
+ "input",
307
+ {
308
+ id: "nice-reg-email",
309
+ className: "nice-input",
310
+ type: "email",
311
+ value: p,
312
+ onChange: (N) => $(N.target.value),
313
+ required: !0,
314
+ disabled: n,
315
+ autoComplete: "email"
316
+ }
317
+ )
240
318
  ] }),
241
319
  /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
242
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-last", children: "Last name" }),
243
- /* @__PURE__ */ e("input", { id: "nice-reg-last", className: "nice-input", type: "text", value: s, onChange: (N) => h(N.target.value), disabled: n, autoComplete: "family-name" })
244
- ] })
245
- ] }),
246
- /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
247
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-email", children: "Email *" }),
248
- /* @__PURE__ */ e("input", { id: "nice-reg-email", className: "nice-input", type: "email", value: p, onChange: (N) => $(N.target.value), required: !0, disabled: n, autoComplete: "email" })
249
- ] }),
250
- /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
251
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-pass", children: "Password *" }),
252
- /* @__PURE__ */ e("input", { id: "nice-reg-pass", className: "nice-input", type: "password", value: g, onChange: (N) => S(N.target.value), required: !0, disabled: n, autoComplete: "new-password" }),
253
- u && g.length > 0 && /* @__PURE__ */ e(M, { password: g })
254
- ] }),
255
- /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
256
- /* @__PURE__ */ e("label", { htmlFor: "nice-reg-confirm", children: "Confirm password *" }),
257
- /* @__PURE__ */ e("input", { id: "nice-reg-confirm", className: "nice-input", type: "password", value: y, onChange: (N) => T(N.target.value), required: !0, disabled: n, autoComplete: "new-password" }),
258
- y && !F && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
259
- ] }),
260
- /* @__PURE__ */ t("label", { className: "nice-register-form__terms", children: [
261
- /* @__PURE__ */ e("input", { type: "checkbox", checked: R, onChange: (N) => L(N.target.checked), disabled: n }),
262
- /* @__PURE__ */ t("span", { children: [
263
- "I accept the",
264
- " ",
265
- r ? /* @__PURE__ */ e("a", { href: r, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
266
- m && /* @__PURE__ */ t(V, { children: [
267
- " and ",
268
- /* @__PURE__ */ e("a", { href: m, target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" })
269
- ] }),
270
- " *"
271
- ] })
272
- ] }),
273
- /* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary nice-register-form__submit", disabled: !D, children: n ? "…" : "Register" }),
274
- d && /* @__PURE__ */ t("div", { className: "nice-register-form__login", children: [
275
- /* @__PURE__ */ e("span", { children: "Already have an account? " }),
276
- /* @__PURE__ */ e("button", { type: "button", onClick: d, children: "Sign in" })
277
- ] }),
278
- i && /* @__PURE__ */ e("div", { className: "nice-register-form__footer", children: i })
279
- ]
280
- }
281
- );
282
- });
283
- Q.displayName = "NiceRegistrationForm";
284
- const z = E(({
285
- requireCurrentPassword: a = !0,
286
- onSubmit: n,
287
- loading: o = !1,
288
- error: d,
289
- success: u,
290
- minPasswordStrength: f = 2,
291
- title: r = "Change Password",
292
- className: m,
293
- style: c
294
- }, v) => {
295
- const [i, k] = _(""), [b, C] = _(""), [w, A] = _(""), s = I(b), h = b === w, p = (!a || i.length > 0) && b.length > 0 && h && s >= f && !o, $ = x((g) => {
296
- g.preventDefault(), p && (n == null || n({
297
- currentPassword: a ? i : void 0,
298
- newPassword: b
299
- }));
300
- }, [p, i, b, a, n]);
301
- return /* @__PURE__ */ t(
302
- "form",
303
- {
304
- ref: v,
305
- className: `nice-change-password${m ? ` ${m}` : ""}`,
306
- style: c,
307
- onSubmit: $,
308
- noValidate: !0,
309
- children: [
310
- /* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: r }),
311
- d && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: d }),
312
- u && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: u }),
313
- a && /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
314
- /* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
315
- /* @__PURE__ */ e(
316
- "input",
317
- {
318
- id: "nice-cp-current",
319
- className: "nice-input",
320
- type: "password",
321
- value: i,
322
- onChange: (g) => k(g.target.value),
323
- autoComplete: "current-password",
324
- disabled: o,
325
- required: !0
326
- }
327
- )
328
- ] }),
329
- /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
330
- /* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
331
- /* @__PURE__ */ e(
332
- "input",
333
- {
334
- id: "nice-cp-new",
335
- className: "nice-input",
336
- type: "password",
337
- value: b,
338
- onChange: (g) => C(g.target.value),
339
- autoComplete: "new-password",
340
- disabled: o,
341
- required: !0
342
- }
343
- ),
344
- b.length > 0 && /* @__PURE__ */ e(M, { password: b })
345
- ] }),
346
- /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
347
- /* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
320
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-pass", children: "Password *" }),
321
+ /* @__PURE__ */ e(
322
+ "input",
323
+ {
324
+ id: "nice-reg-pass",
325
+ className: "nice-input",
326
+ type: "password",
327
+ value: g,
328
+ onChange: (N) => S(N.target.value),
329
+ required: !0,
330
+ disabled: n,
331
+ autoComplete: "new-password"
332
+ }
333
+ ),
334
+ u && g.length > 0 && /* @__PURE__ */ e(M, { password: g })
335
+ ] }),
336
+ /* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
337
+ /* @__PURE__ */ e("label", { htmlFor: "nice-reg-confirm", children: "Confirm password *" }),
338
+ /* @__PURE__ */ e(
339
+ "input",
340
+ {
341
+ id: "nice-reg-confirm",
342
+ className: "nice-input",
343
+ type: "password",
344
+ value: y,
345
+ onChange: (N) => T(N.target.value),
346
+ required: !0,
347
+ disabled: n,
348
+ autoComplete: "new-password"
349
+ }
350
+ ),
351
+ y && !F && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
352
+ ] }),
353
+ /* @__PURE__ */ t("label", { className: "nice-register-form__terms", children: [
354
+ /* @__PURE__ */ e(
355
+ "input",
356
+ {
357
+ type: "checkbox",
358
+ checked: R,
359
+ onChange: (N) => L(N.target.checked),
360
+ disabled: n
361
+ }
362
+ ),
363
+ /* @__PURE__ */ t("span", { children: [
364
+ "I accept the",
365
+ " ",
366
+ r ? /* @__PURE__ */ e("a", { href: r, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
367
+ m && /* @__PURE__ */ t(V, { children: [
368
+ " ",
369
+ "and",
370
+ " ",
371
+ /* @__PURE__ */ e("a", { href: m, target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" })
372
+ ] }),
373
+ " *"
374
+ ] })
375
+ ] }),
348
376
  /* @__PURE__ */ e(
349
- "input",
377
+ "button",
350
378
  {
351
- id: "nice-cp-confirm",
352
- className: "nice-input",
353
- type: "password",
354
- value: w,
355
- onChange: (g) => A(g.target.value),
356
- autoComplete: "new-password",
357
- disabled: o,
358
- required: !0
379
+ type: "submit",
380
+ className: "nice-btn nice-btn--primary nice-register-form__submit",
381
+ disabled: !D,
382
+ children: n ? "…" : "Register"
359
383
  }
360
384
  ),
361
- w && !h && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
362
- ] }),
363
- /* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !p, children: o ? "…" : "Change Password" })
364
- ]
365
- }
366
- );
367
- });
385
+ d && /* @__PURE__ */ t("div", { className: "nice-register-form__login", children: [
386
+ /* @__PURE__ */ e("span", { children: "Already have an account? " }),
387
+ /* @__PURE__ */ e("button", { type: "button", onClick: d, children: "Sign in" })
388
+ ] }),
389
+ i && /* @__PURE__ */ e("div", { className: "nice-register-form__footer", children: i })
390
+ ]
391
+ }
392
+ );
393
+ }
394
+ );
395
+ Q.displayName = "NiceRegistrationForm";
396
+ const z = E(
397
+ ({
398
+ requireCurrentPassword: a = !0,
399
+ onSubmit: n,
400
+ loading: o = !1,
401
+ error: d,
402
+ success: u,
403
+ minPasswordStrength: f = 2,
404
+ title: r = "Change Password",
405
+ className: m,
406
+ style: c
407
+ }, v) => {
408
+ const [i, k] = _(""), [b, C] = _(""), [w, A] = _(""), s = I(b), h = b === w, p = (!a || i.length > 0) && b.length > 0 && h && s >= f && !o, $ = x(
409
+ (g) => {
410
+ g.preventDefault(), p && (n == null || n({
411
+ currentPassword: a ? i : void 0,
412
+ newPassword: b
413
+ }));
414
+ },
415
+ [p, i, b, a, n]
416
+ );
417
+ return /* @__PURE__ */ t(
418
+ "form",
419
+ {
420
+ ref: v,
421
+ className: `nice-change-password${m ? ` ${m}` : ""}`,
422
+ style: c,
423
+ onSubmit: $,
424
+ noValidate: !0,
425
+ children: [
426
+ /* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: r }),
427
+ d && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: d }),
428
+ u && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: u }),
429
+ a && /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
430
+ /* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
431
+ /* @__PURE__ */ e(
432
+ "input",
433
+ {
434
+ id: "nice-cp-current",
435
+ className: "nice-input",
436
+ type: "password",
437
+ value: i,
438
+ onChange: (g) => k(g.target.value),
439
+ autoComplete: "current-password",
440
+ disabled: o,
441
+ required: !0
442
+ }
443
+ )
444
+ ] }),
445
+ /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
446
+ /* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
447
+ /* @__PURE__ */ e(
448
+ "input",
449
+ {
450
+ id: "nice-cp-new",
451
+ className: "nice-input",
452
+ type: "password",
453
+ value: b,
454
+ onChange: (g) => C(g.target.value),
455
+ autoComplete: "new-password",
456
+ disabled: o,
457
+ required: !0
458
+ }
459
+ ),
460
+ b.length > 0 && /* @__PURE__ */ e(M, { password: b })
461
+ ] }),
462
+ /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
463
+ /* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
464
+ /* @__PURE__ */ e(
465
+ "input",
466
+ {
467
+ id: "nice-cp-confirm",
468
+ className: "nice-input",
469
+ type: "password",
470
+ value: w,
471
+ onChange: (g) => A(g.target.value),
472
+ autoComplete: "new-password",
473
+ disabled: o,
474
+ required: !0
475
+ }
476
+ ),
477
+ w && !h && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
478
+ ] }),
479
+ /* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !p, children: o ? "…" : "Change Password" })
480
+ ]
481
+ }
482
+ );
483
+ }
484
+ );
368
485
  z.displayName = "NiceChangePassword";
369
486
  const J = E(({
370
487
  secret: a,
@@ -525,133 +642,148 @@ const U = [
525
642
  }
526
643
  ));
527
644
  Z.displayName = "NiceOAuthButtons";
528
- const Y = E(function(n, o) {
529
- const {
530
- tokens: d,
531
- onCreate: u,
532
- onRevoke: f,
533
- availableScopes: r = [],
534
- maxTokens: m = 10,
535
- title: c = "API Tokens",
536
- className: v,
537
- style: i
538
- } = n, [k, b] = _(!1), [C, w] = _(""), [A, s] = _([]), [h, p] = _("90"), [$, g] = _(null), [S, y] = _(!1), [T, R] = _(null), L = x(async () => {
539
- if (!(!u || !C.trim())) {
540
- y(!0);
541
- try {
542
- const l = h ? parseInt(h, 10) : void 0, N = await u(C.trim(), A, l);
543
- g(N), w(""), s([]), b(!1);
544
- } finally {
545
- y(!1);
546
- }
547
- }
548
- }, [u, C, A, h]), P = x(async (l) => {
549
- if (f) {
550
- R(l);
551
- try {
552
- await f(l);
553
- } finally {
554
- R(null);
645
+ const Y = E(
646
+ function(n, o) {
647
+ const {
648
+ tokens: d,
649
+ onCreate: u,
650
+ onRevoke: f,
651
+ availableScopes: r = [],
652
+ maxTokens: m = 10,
653
+ title: c = "API Tokens",
654
+ className: v,
655
+ style: i
656
+ } = n, [k, b] = _(!1), [C, w] = _(""), [A, s] = _([]), [h, p] = _("90"), [$, g] = _(null), [S, y] = _(!1), [T, R] = _(null), L = x(async () => {
657
+ if (!(!u || !C.trim())) {
658
+ y(!0);
659
+ try {
660
+ const l = h ? parseInt(h, 10) : void 0, N = await u(C.trim(), A, l);
661
+ g(N), w(""), s([]), b(!1);
662
+ } finally {
663
+ y(!1);
664
+ }
555
665
  }
556
- }
557
- }, [f]), F = (l) => {
558
- s((N) => N.includes(l) ? N.filter((O) => O !== l) : [...N, l]);
559
- }, D = d.length < m;
560
- return /* @__PURE__ */ t("div", { ref: o, className: `nice-token-management ${v ?? ""}`, style: i, children: [
561
- /* @__PURE__ */ t("div", { className: "nice-token-management__header", children: [
562
- /* @__PURE__ */ e("h3", { children: c }),
563
- D && /* @__PURE__ */ e("button", { className: "nice-token-management__new-btn", onClick: () => b(!0), disabled: k, children: "+ New Token" })
564
- ] }),
565
- $ && /* @__PURE__ */ t("div", { className: "nice-token-management__reveal", children: [
566
- /* @__PURE__ */ t("p", { children: [
567
- /* @__PURE__ */ e("strong", { children: "New token created!" }),
568
- " Copy it now it won't be shown again."
569
- ] }),
570
- /* @__PURE__ */ e("code", { className: "nice-token-management__token-value", children: $ }),
571
- /* @__PURE__ */ e("button", { onClick: () => g(null), children: "Dismiss" })
572
- ] }),
573
- k && /* @__PURE__ */ t("div", { className: "nice-token-management__create-form", children: [
574
- /* @__PURE__ */ t("label", { children: [
575
- "Name",
576
- /* @__PURE__ */ e(
577
- "input",
666
+ }, [u, C, A, h]), P = x(
667
+ async (l) => {
668
+ if (f) {
669
+ R(l);
670
+ try {
671
+ await f(l);
672
+ } finally {
673
+ R(null);
674
+ }
675
+ }
676
+ },
677
+ [f]
678
+ ), F = (l) => {
679
+ s(
680
+ (N) => N.includes(l) ? N.filter((O) => O !== l) : [...N, l]
681
+ );
682
+ }, D = d.length < m;
683
+ return /* @__PURE__ */ t("div", { ref: o, className: `nice-token-management ${v ?? ""}`, style: i, children: [
684
+ /* @__PURE__ */ t("div", { className: "nice-token-management__header", children: [
685
+ /* @__PURE__ */ e("h3", { children: c }),
686
+ D && /* @__PURE__ */ e(
687
+ "button",
578
688
  {
579
- type: "text",
580
- value: C,
581
- onChange: (l) => w(l.target.value),
582
- placeholder: "My API token",
583
- maxLength: 64
689
+ className: "nice-token-management__new-btn",
690
+ onClick: () => b(!0),
691
+ disabled: k,
692
+ children: "+ New Token"
584
693
  }
585
694
  )
586
695
  ] }),
587
- r.length > 0 && /* @__PURE__ */ t("fieldset", { children: [
588
- /* @__PURE__ */ e("legend", { children: "Scopes" }),
589
- r.map((l) => /* @__PURE__ */ t("label", { className: "nice-token-management__scope", children: [
696
+ $ && /* @__PURE__ */ t("div", { className: "nice-token-management__reveal", children: [
697
+ /* @__PURE__ */ t("p", { children: [
698
+ /* @__PURE__ */ e("strong", { children: "New token created!" }),
699
+ " Copy it now — it won't be shown again."
700
+ ] }),
701
+ /* @__PURE__ */ e("code", { className: "nice-token-management__token-value", children: $ }),
702
+ /* @__PURE__ */ e("button", { onClick: () => g(null), children: "Dismiss" })
703
+ ] }),
704
+ k && /* @__PURE__ */ t("div", { className: "nice-token-management__create-form", children: [
705
+ /* @__PURE__ */ t("label", { children: [
706
+ "Name",
590
707
  /* @__PURE__ */ e(
591
708
  "input",
592
709
  {
593
- type: "checkbox",
594
- checked: A.includes(l),
595
- onChange: () => F(l)
710
+ type: "text",
711
+ value: C,
712
+ onChange: (l) => w(l.target.value),
713
+ placeholder: "My API token",
714
+ maxLength: 64
596
715
  }
597
- ),
598
- l
599
- ] }, l))
600
- ] }),
601
- /* @__PURE__ */ t("label", { children: [
602
- "Expires in (days)",
603
- /* @__PURE__ */ e(
604
- "input",
605
- {
606
- type: "number",
607
- value: h,
608
- onChange: (l) => p(l.target.value),
609
- min: 1,
610
- max: 365
611
- }
612
- )
613
- ] }),
614
- /* @__PURE__ */ t("div", { className: "nice-token-management__create-actions", children: [
615
- /* @__PURE__ */ e("button", { onClick: L, disabled: S || !C.trim(), children: S ? "Creating…" : "Create Token" }),
616
- /* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
617
- ] })
618
- ] }),
619
- d.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ t("table", { className: "nice-token-management__table", children: [
620
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ t("tr", { children: [
621
- /* @__PURE__ */ e("th", { children: "Name" }),
622
- /* @__PURE__ */ e("th", { children: "Prefix" }),
623
- /* @__PURE__ */ e("th", { children: "Created" }),
624
- /* @__PURE__ */ e("th", { children: "Expires" }),
625
- /* @__PURE__ */ e("th", { children: "Last Used" }),
626
- /* @__PURE__ */ e("th", { children: "Scopes" }),
627
- /* @__PURE__ */ e("th", {})
628
- ] }) }),
629
- /* @__PURE__ */ e("tbody", { children: d.map((l) => {
630
- var N;
631
- return /* @__PURE__ */ t("tr", { children: [
632
- /* @__PURE__ */ e("td", { children: l.name }),
633
- /* @__PURE__ */ e("td", { children: /* @__PURE__ */ t("code", { children: [
634
- l.prefix,
635
- "…"
636
- ] }) }),
637
- /* @__PURE__ */ e("td", { children: l.createdAt }),
638
- /* @__PURE__ */ e("td", { children: l.expiresAt ?? "—" }),
639
- /* @__PURE__ */ e("td", { children: l.lastUsedAt ?? "Never" }),
640
- /* @__PURE__ */ e("td", { children: ((N = l.scopes) == null ? void 0 : N.join(", ")) || "—" }),
641
- /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
642
- "button",
716
+ )
717
+ ] }),
718
+ r.length > 0 && /* @__PURE__ */ t("fieldset", { children: [
719
+ /* @__PURE__ */ e("legend", { children: "Scopes" }),
720
+ r.map((l) => /* @__PURE__ */ t("label", { className: "nice-token-management__scope", children: [
721
+ /* @__PURE__ */ e(
722
+ "input",
723
+ {
724
+ type: "checkbox",
725
+ checked: A.includes(l),
726
+ onChange: () => F(l)
727
+ }
728
+ ),
729
+ l
730
+ ] }, l))
731
+ ] }),
732
+ /* @__PURE__ */ t("label", { children: [
733
+ "Expires in (days)",
734
+ /* @__PURE__ */ e(
735
+ "input",
643
736
  {
644
- className: "nice-token-management__revoke-btn",
645
- onClick: () => P(l.id),
646
- disabled: T === l.id,
647
- children: T === l.id ? "Revoking…" : "Revoke"
737
+ type: "number",
738
+ value: h,
739
+ onChange: (l) => p(l.target.value),
740
+ min: 1,
741
+ max: 365
648
742
  }
649
- ) })
650
- ] }, l.id);
651
- }) })
652
- ] })
653
- ] });
654
- });
743
+ )
744
+ ] }),
745
+ /* @__PURE__ */ t("div", { className: "nice-token-management__create-actions", children: [
746
+ /* @__PURE__ */ e("button", { onClick: L, disabled: S || !C.trim(), children: S ? "Creating…" : "Create Token" }),
747
+ /* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
748
+ ] })
749
+ ] }),
750
+ d.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ t("table", { className: "nice-token-management__table", children: [
751
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ t("tr", { children: [
752
+ /* @__PURE__ */ e("th", { children: "Name" }),
753
+ /* @__PURE__ */ e("th", { children: "Prefix" }),
754
+ /* @__PURE__ */ e("th", { children: "Created" }),
755
+ /* @__PURE__ */ e("th", { children: "Expires" }),
756
+ /* @__PURE__ */ e("th", { children: "Last Used" }),
757
+ /* @__PURE__ */ e("th", { children: "Scopes" }),
758
+ /* @__PURE__ */ e("th", {})
759
+ ] }) }),
760
+ /* @__PURE__ */ e("tbody", { children: d.map((l) => {
761
+ var N;
762
+ return /* @__PURE__ */ t("tr", { children: [
763
+ /* @__PURE__ */ e("td", { children: l.name }),
764
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ t("code", { children: [
765
+ l.prefix,
766
+ "…"
767
+ ] }) }),
768
+ /* @__PURE__ */ e("td", { children: l.createdAt }),
769
+ /* @__PURE__ */ e("td", { children: l.expiresAt ?? "—" }),
770
+ /* @__PURE__ */ e("td", { children: l.lastUsedAt ?? "Never" }),
771
+ /* @__PURE__ */ e("td", { children: ((N = l.scopes) == null ? void 0 : N.join(", ")) || "—" }),
772
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
773
+ "button",
774
+ {
775
+ className: "nice-token-management__revoke-btn",
776
+ onClick: () => P(l.id),
777
+ disabled: T === l.id,
778
+ children: T === l.id ? "Revoking…" : "Revoke"
779
+ }
780
+ ) })
781
+ ] }, l.id);
782
+ }) })
783
+ ] })
784
+ ] });
785
+ }
786
+ );
655
787
  export {
656
788
  K as NiceCaptcha,
657
789
  z as NiceChangePassword,