levix-bot 4.5.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/app.cjs +32 -7
  2. package/package.json +2 -2
  3. package/public/dashboard/assets/index-RnT7DAde.js +540 -0
  4. package/public/dashboard/assets/index-UcqCdCvG.css +2 -0
  5. package/public/dashboard/index.html +4 -3
  6. package/public/dashboard.css +123 -53
  7. package/public/gateway-i18n.js +295 -0
  8. package/public/gateway.js +30 -1
  9. package/public/ui-boot.js +71 -0
  10. package/src/bootstrap/core.js +9 -0
  11. package/src/commands/autodelete.cjs +213 -0
  12. package/src/commands/pack.cjs +46 -25
  13. package/src/commands/packs.cjs +4 -1
  14. package/src/commands/shortlink.cjs +273 -66
  15. package/src/commands/stickers.cjs +26 -8
  16. package/src/config/defaults.cjs +1 -0
  17. package/src/config/settings.cjs +10 -0
  18. package/src/core/session.js +9 -1
  19. package/src/db/db.cjs +57 -0
  20. package/src/db/store.cjs +250 -0
  21. package/src/diagnostics/crashReports.cjs +491 -0
  22. package/src/diagnostics/device.cjs +119 -0
  23. package/src/diagnostics/sanitize.cjs +90 -0
  24. package/src/handlers/command.handler.js +1 -0
  25. package/src/handlers/message.handler.js +15 -0
  26. package/src/index.js +9 -1
  27. package/src/panel/feedback.cjs +13 -1
  28. package/src/routes/dashboard.api.esm.js +188 -4
  29. package/src/services/autoDelete.cjs +578 -0
  30. package/src/stickers/errors.cjs +7 -6
  31. package/src/stickers/library.cjs +118 -13
  32. package/src/utils/bidi.cjs +21 -0
  33. package/src/utils/storage.cjs +14 -0
  34. package/src/utils/storage.esm.js +15 -0
  35. package/views/dashboard.ejs +2 -1
  36. package/views/login.ejs +102 -71
  37. package/views/qr.ejs +59 -30
  38. package/views/setup.ejs +34 -30
  39. package/public/dashboard/assets/index-COI8zgqa.css +0 -2
  40. package/public/dashboard/assets/index-IZMBuNAZ.js +0 -505
@@ -28,7 +28,25 @@ const {
28
28
 
29
29
  const SOURCES = new Set(["BOT_COMMAND", "PANEL_UPLOAD", "WHATSAPP_STICKER", "MEDIA_HUB"]);
30
30
  const ID_RE = /^[0-9a-f]{16}$/;
31
- const PACK_NAME_RE = /^[\p{L}\p{N}\p{M} _-]+$/u;
31
+ // Letters, marks, numbers, the allowed punctuation, variation selectors and
32
+ // emoji with their modifiers. A control or bidi-format character is rejected
33
+ // before this test and is not in the class either, so a newline cannot slip
34
+ // through collapsed to a space. ZWNJ/ZWJ (Persian, Urdu, and the joiners inside
35
+ // an emoji sequence) are stripped before the test: they are only meaningful
36
+ // between two already-valid characters, which a character class cannot say.
37
+ const PACK_NAME_CHARS =
38
+ /^[\p{L}\p{N}\p{M}\p{Extended_Pictographic}\p{Emoji_Modifier}\p{Regional_Indicator} _'’.&,-]+$/u;
39
+ const NAME_JOINERS_RE = /[\u200C\u200D]/g;
40
+ const FORBIDDEN_NAME_RE = /[\p{Cc}\u202A-\u202E\u2066-\u2069]/u;
41
+ const QUOTE_PAIRS = [
42
+ ['"', '"'],
43
+ ["'", "'"],
44
+ ["“", "”"],
45
+ ["«", "»"],
46
+ ["„", "‟"],
47
+ ["‹", "›"],
48
+ ];
49
+ const GRAPHEMES = new Intl.Segmenter("en", { granularity: "grapheme" });
32
50
  const SORTS = new Set(["newest", "oldest", "name", "recent"]);
33
51
  const FILTERS = new Set(["all", "favorites", "recent", "animated", "static"]);
34
52
  const DEFAULT_LIBRARY_LIMIT = 1000;
@@ -39,12 +57,51 @@ function assertEpoch(captured) {
39
57
  if (captured !== undefined && captured !== epoch) throw new StickerError("CANCELLED");
40
58
  }
41
59
 
60
+ function graphemeCount(text) {
61
+ let n = 0;
62
+ for (const _ of GRAPHEMES.segment(text)) n += 1;
63
+ return n;
64
+ }
65
+
66
+ // ZWNJ/ZWJ are allowed only as joiners between valid characters, so they are
67
+ // dropped before the charset test (see PACK_NAME_CHARS).
68
+ function isAllowedPackName(name) {
69
+ return PACK_NAME_CHARS.test(name.replace(NAME_JOINERS_RE, ""));
70
+ }
71
+
72
+ // One pair of surrounding quotes is decoration, not part of the name: users
73
+ // type `!pack create "My Pack"` and `!pack create "حزمة العيد"`. A lone
74
+ // apostrophe inside a name (Abdo's pack) is not a pair and is kept.
75
+ function stripQuotes(raw) {
76
+ const text = String(raw ?? "").trim();
77
+ if (text.length < 2) return text;
78
+ for (const [open, close] of QUOTE_PAIRS) {
79
+ if (
80
+ text.startsWith(open) &&
81
+ text.endsWith(close) &&
82
+ text.length > open.length + close.length - 1
83
+ ) {
84
+ return text.slice(open.length, text.length - close.length).trim();
85
+ }
86
+ }
87
+ return text;
88
+ }
89
+
90
+ // The key a name is stored and matched by: case-insensitive, NFC. Names saved
91
+ // before NFC normalization used NFKC keys, so both forms are looked up; that
92
+ // keeps every already-stored pack addressable without a migration.
93
+ function normalizationKeys(name) {
94
+ const keys = [name.normalize("NFC").toLowerCase()];
95
+ const compat = name.normalize("NFKC").toLowerCase();
96
+ if (compat !== keys[0]) keys.push(compat);
97
+ return keys;
98
+ }
99
+
42
100
  const RESERVED_PACK_NAMES = new Set();
43
101
  for (const words of Object.values(PACK_SUBCOMMANDS)) {
44
102
  for (const word of words) {
45
- RESERVED_PACK_NAMES.add(
46
- String(word).normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase(),
47
- );
103
+ const text = String(word).replace(/\s+/g, " ").trim();
104
+ for (const key of normalizationKeys(text)) RESERVED_PACK_NAMES.add(key);
48
105
  }
49
106
  }
50
107
 
@@ -106,18 +163,38 @@ function sanitizeStickerName(raw) {
106
163
  return [...text].slice(0, STICKER_NAME_MAX).join("");
107
164
  }
108
165
 
166
+ // The one entry point for a pack name: a single surrounding quote pair is
167
+ // decoration (see stripQuotes), a control or bidi-format character is refused
168
+ // outright rather than collapsed away, then NFC, collapsed internal runs of
169
+ // whitespace, a grapheme-count length check, and a charset test. Returns the
170
+ // stored name plus every key it may already live under (NFC now, NFKC for
171
+ // packs stored before this normalization).
109
172
  function normalizePackName(raw) {
110
173
  if (typeof raw !== "string") throw new StickerError("INVALID_NAME");
111
- const name = raw.normalize("NFKC").replace(/\s+/g, " ").trim();
112
- const length = [...name].length;
113
- if (length < 1 || length > PACK_NAME_MAX || !PACK_NAME_RE.test(name)) {
174
+ const stripped = stripQuotes(raw);
175
+ if (FORBIDDEN_NAME_RE.test(stripped)) {
176
+ throw new StickerError("INVALID_NAME", { reason: "forbidden" });
177
+ }
178
+ const name = stripped.normalize("NFC").replace(/\s+/g, " ").trim();
179
+ const length = graphemeCount(name);
180
+ if (length < 1 || length > PACK_NAME_MAX || !isAllowedPackName(name)) {
114
181
  throw new StickerError("INVALID_NAME");
115
182
  }
116
- const nameKey = name.toLowerCase();
117
- if (RESERVED_PACK_NAMES.has(nameKey)) {
183
+ const nameKeys = normalizationKeys(name);
184
+ if (nameKeys.some((key) => RESERVED_PACK_NAMES.has(key))) {
118
185
  throw new StickerError("INVALID_NAME", { reason: "reserved" });
119
186
  }
120
- return { name, nameKey };
187
+ return { name, nameKey: nameKeys[0], nameKeys };
188
+ }
189
+
190
+ // A name may have been stored under the NFC or the NFKC key, so every lookup
191
+ // checks both. The first match wins.
192
+ function packByAnyKey(bound, nameKeys) {
193
+ for (const key of nameKeys) {
194
+ const row = store.stickerPackByKey(bound.key, key);
195
+ if (row) return row;
196
+ }
197
+ return null;
121
198
  }
122
199
 
123
200
  function isUnique(error) {
@@ -497,7 +574,7 @@ function touch(owner, ids) {
497
574
  function createPack(owner, name) {
498
575
  const bound = bind(owner);
499
576
  const parsed = normalizePackName(name);
500
- if (store.stickerPackByKey(bound.key, parsed.nameKey)) {
577
+ if (packByAnyKey(bound, parsed.nameKeys)) {
501
578
  throw new StickerError("PACK_EXISTS", { name: parsed.name });
502
579
  }
503
580
  if (store.stickerPackCount(bound.key) >= PACKS_MAX_PER_OWNER) {
@@ -537,7 +614,7 @@ function updatePack(owner, id, name) {
537
614
  const bound = bind(owner);
538
615
  const pack = requirePack(bound, id);
539
616
  const parsed = normalizePackName(name);
540
- const other = store.stickerPackByKey(bound.key, parsed.nameKey);
617
+ const other = packByAnyKey(bound, parsed.nameKeys);
541
618
  if (other && other.id !== pack.id) throw new StickerError("PACK_EXISTS", { name: parsed.name });
542
619
  store.stickerPackRename(pack.id, parsed.name, parsed.nameKey, Date.now());
543
620
  return packDto(store.stickerPackGet(bound.key, pack.id));
@@ -565,10 +642,35 @@ function findPackByName(owner, name) {
565
642
  if (error instanceof StickerError && error.code === "INVALID_NAME") return null;
566
643
  throw error;
567
644
  }
568
- const row = store.stickerPackByKey(bound.key, parsed.nameKey);
645
+ const row = packByAnyKey(bound, parsed.nameKeys);
569
646
  return row ? packDto(row) : null;
570
647
  }
571
648
 
649
+ // Resolve the pack a rename refers to when the sender did not use `|`: the
650
+ // longest leading run of words that names an existing pack is the target and
651
+ // everything after it is the new name. `!pack rename My Pack New Name` moves
652
+ // `My Pack` to `New Name`; `!pack rename حزمة العيد عيد` moves `حزمة` to
653
+ // `العيد عيد` only if `حزمة العيد` itself is not a pack. A quoted pair is
654
+ // handled by normalizePackName inside findPackByName, so `"My Pack"` matches.
655
+ function findLeadingPackName(owner, text) {
656
+ const bound = bind(owner);
657
+ const raw = String(text ?? "").trim();
658
+ if (!raw) return null;
659
+ const words = raw.split(/\s+/);
660
+ for (let count = words.length - 1; count >= 1; count -= 1) {
661
+ const candidate = words.slice(0, count).join(" ");
662
+ let pack;
663
+ try {
664
+ pack = findPackByName(bound, candidate);
665
+ } catch (error) {
666
+ if (error instanceof StickerError && error.code === "INVALID_NAME") continue;
667
+ throw error;
668
+ }
669
+ if (pack) return { pack, newName: words.slice(count).join(" ").trim() };
670
+ }
671
+ return null;
672
+ }
673
+
572
674
  function membershipResult(bound, packId, ids, mutate) {
573
675
  const list = eachId(ids);
574
676
  return store.withImmediateTransaction(() => {
@@ -701,6 +803,9 @@ module.exports = {
701
803
  updatePack,
702
804
  deletePack,
703
805
  findPackByName,
806
+ findLeadingPackName,
807
+ normalizePackName,
808
+ stripQuotes,
704
809
  addToPack,
705
810
  removeFromPack,
706
811
  moveToPack,
@@ -0,0 +1,21 @@
1
+ // Display isolation for a value interpolated into a sentence.
2
+ //
3
+ // A Latin pack name inside an Arabic reply (or the reverse) reorders around the
4
+ // punctuation next to it: "حُفظ الملصق في My Pack." can render as
5
+ // "My Pack. حُفظ الملصق في". First-Strong-Isolate / Pop-Directional-Isolate
6
+ // (U+2068 … U+2069) pin the value's own direction without leaking it to the
7
+ // surrounding text. The characters are invisible; they only order the run.
8
+ //
9
+ // Keep this dependency-free: the sticker errors, the bot helpers and the
10
+ // commands all reach it, and none of them may form a cycle.
11
+
12
+ const FSI = "\u2068";
13
+ const PDI = "\u2069";
14
+
15
+ /** Isolate `value` for safe interpolation into a message. */
16
+ function isolate(value) {
17
+ const text = String(value ?? "");
18
+ return text ? `${FSI}${text}${PDI}` : text;
19
+ }
20
+
21
+ module.exports = { isolate, FSI, PDI };
@@ -91,4 +91,18 @@ module.exports = {
91
91
  countSchedules: store.countSchedules,
92
92
  // AI conversation history
93
93
  deleteAllChatHistories: store.deleteAllChatHistories,
94
+ // Keyword auto-delete
95
+ listAutoDeleteRules: store.listAutoDeleteRules,
96
+ getAutoDeleteRule: store.getAutoDeleteRule,
97
+ countAutoDeleteRules: store.countAutoDeleteRules,
98
+ insertAutoDeleteRule: store.insertAutoDeleteRule,
99
+ updateAutoDeleteRule: store.updateAutoDeleteRule,
100
+ deleteAutoDeleteRule: store.deleteAutoDeleteRule,
101
+ incrementAutoDeleteCounter: store.incrementAutoDeleteCounter,
102
+ resetAutoDeleteCounter: store.resetAutoDeleteCounter,
103
+ insertAutoDeleteLog: store.insertAutoDeleteLog,
104
+ listAutoDeleteLog: store.listAutoDeleteLog,
105
+ countAutoDeleteLog: store.countAutoDeleteLog,
106
+ clearAutoDeleteLog: store.clearAutoDeleteLog,
107
+ clearAutoDeleteOnUnlink: store.clearAutoDeleteOnUnlink,
94
108
  };
@@ -106,3 +106,18 @@ export const countSchedules = store.countSchedules;
106
106
 
107
107
  // ===== AI conversation history =====
108
108
  export const deleteAllChatHistories = store.deleteAllChatHistories;
109
+
110
+ // ===== Keyword auto-delete =====
111
+ export const listAutoDeleteRules = store.listAutoDeleteRules;
112
+ export const getAutoDeleteRule = store.getAutoDeleteRule;
113
+ export const countAutoDeleteRules = store.countAutoDeleteRules;
114
+ export const insertAutoDeleteRule = store.insertAutoDeleteRule;
115
+ export const updateAutoDeleteRule = store.updateAutoDeleteRule;
116
+ export const deleteAutoDeleteRule = store.deleteAutoDeleteRule;
117
+ export const incrementAutoDeleteCounter = store.incrementAutoDeleteCounter;
118
+ export const resetAutoDeleteCounter = store.resetAutoDeleteCounter;
119
+ export const insertAutoDeleteLog = store.insertAutoDeleteLog;
120
+ export const listAutoDeleteLog = store.listAutoDeleteLog;
121
+ export const countAutoDeleteLog = store.countAutoDeleteLog;
122
+ export const clearAutoDeleteLog = store.clearAutoDeleteLog;
123
+ export const clearAutoDeleteOnUnlink = store.clearAutoDeleteOnUnlink;
@@ -1,6 +1,7 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
2
+ <html>
3
3
  <head>
4
+ <script src="/ui-boot.js"></script>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
7
  <title><%= brand.name %> · Control panel</title>
package/views/login.ejs CHANGED
@@ -1,25 +1,26 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
2
+ <html data-brand="<%= brand.name %>">
3
3
  <head>
4
+ <script src="/ui-boot.js"></script>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title><%= brand.name %> · Sign in</title>
7
+ <title data-i18n="titleLogin"><%= brand.name %> · Sign in</title>
7
8
  <link rel="icon" type="image/png" sizes="32x32" href="/brand/icon-32.png" />
8
9
  <link rel="apple-touch-icon" href="/brand/apple-touch-icon.png" />
9
10
  <link rel="stylesheet" href="/dashboard.css" />
10
11
  </head>
11
12
  <body class="gateway-page">
12
13
  <main class="gateway-shell">
13
- <section class="gateway-story" aria-label="About <%= brand.name %>">
14
+ <section class="gateway-story" aria-label="About <%= brand.name %>" data-i18n-aria-label="storyAbout">
14
15
  <div class="brand-lockup" aria-label="<%= brand.name %>">
15
16
  <img src="/brand/mark.svg" alt="" />
16
- <span><strong><%= brand.name %></strong><small><%= brand.tagline %></small></span>
17
+ <span><strong><%= brand.name %></strong><small data-i18n="tagline"><%= brand.tagline %></small></span>
17
18
  </div>
18
19
 
19
20
  <div class="gateway-copy">
20
- <span class="eyebrow">Self-hosted by design</span>
21
- <h2>The quiet control room behind every chat.</h2>
22
- <p>Connection, commands, memory, and moderation stay together—on your server and within reach.</p>
21
+ <span class="eyebrow" data-i18n="selfHosted">Self-hosted by design</span>
22
+ <h2 data-i18n="loginHeadline">The quiet control room behind every chat.</h2>
23
+ <p data-i18n="loginLede">Connection, commands, memory, and moderation stay together—on your server and within reach.</p>
23
24
  </div>
24
25
 
25
26
  <div class="gateway-mark" aria-hidden="true">
@@ -27,7 +28,7 @@
27
28
  <img src="/brand/mark.svg" alt="" />
28
29
  </div>
29
30
 
30
- <p class="gateway-trust"><span></span> Private workspace · direct control</p>
31
+ <p class="gateway-trust" data-i18n-html="loginTrust"><span></span> Private workspace · direct control</p>
31
32
  </section>
32
33
 
33
34
  <section class="gateway-panel">
@@ -35,26 +36,27 @@
35
36
  <form class="card auth-card" id="login-card" action="/login" method="post">
36
37
  <button type="button" class="gateway-back-btn" id="login-back-app" hidden>
37
38
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
38
- <span>Back to app</span>
39
+ <span data-i18n="backToApp">Back to app</span>
39
40
  </button>
40
41
  <div class="auth-head">
41
- <span class="eyebrow">Secure access</span>
42
- <h1>Welcome back</h1>
43
- <p class="sub">Sign in to manage your Levix workspace.</p>
42
+ <span class="eyebrow" data-i18n="secureAccess">Secure access</span>
43
+ <h1 data-i18n="welcomeBack">Welcome back</h1>
44
+ <p class="sub" data-i18n="loginSub">Sign in to manage your Levix workspace.</p>
44
45
  </div>
45
46
 
46
47
  <label class="field">
47
- <span>Control panel password</span>
48
+ <span data-i18n="passwordLabel">Control panel password</span>
48
49
  <div class="input-wrap">
49
50
  <input
50
- type="password"
51
+ type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off"
51
52
  name="password"
52
53
  autocomplete="current-password"
53
54
  placeholder="Enter your password"
55
+ data-i18n-placeholder="passwordPlaceholder"
54
56
  autofocus
55
57
  required
56
58
  />
57
- <button type="button" class="eye-btn" aria-label="Show password">
59
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
58
60
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
59
61
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
60
62
  </button>
@@ -62,41 +64,41 @@
62
64
  </label>
63
65
 
64
66
  <button type="submit" class="btn btn-primary auth-submit">
65
- Open workspace
67
+ <span data-i18n="openWorkspace">Open workspace</span>
66
68
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
67
69
  </button>
68
70
 
69
71
  <% if (error) { %>
70
- <div class="error" role="alert"><%= error %></div>
72
+ <div class="error" role="alert" data-i18n-error="<%= errorCode %>" data-i18n-n="<%= minLength %>"><%= error %></div>
71
73
  <% } %>
72
74
 
73
75
  <div class="auth-alt">
74
- <button type="button" class="link-btn" id="forgot-link">Forgot password?</button>
76
+ <button type="button" class="link-btn" id="forgot-link" data-i18n="forgotPassword">Forgot password?</button>
75
77
  </div>
76
78
  </form>
77
79
 
78
80
  <div class="card auth-card" id="reset-card" hidden>
79
81
  <button type="button" class="gateway-back-btn" id="reset-back">
80
82
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
81
- <span>Back to sign in</span>
83
+ <span data-i18n="backToSignIn">Back to sign in</span>
82
84
  </button>
83
85
  <div class="auth-head">
84
- <span class="eyebrow">Password reset</span>
85
- <h1>Reset your password</h1>
86
- <p class="sub">
86
+ <span class="eyebrow" data-i18n="resetEyebrow">Password reset</span>
87
+ <h1 data-i18n="resetTitle">Reset your password</h1>
88
+ <p class="sub" data-i18n="resetSubtitle">
87
89
  Levix sends a one-time code to your WhatsApp — the linked account's own chat.
88
90
  The code works for 10 minutes.
89
91
  </p>
90
92
  </div>
91
93
 
92
94
  <button type="button" class="btn btn-primary auth-submit" id="reset-send">
93
- Send code to WhatsApp
95
+ <span data-i18n="resetSend">Send code to WhatsApp</span>
94
96
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
95
97
  </button>
96
98
 
97
99
  <form id="reset-form" hidden>
98
100
  <label class="field">
99
- <span>Reset code</span>
101
+ <span data-i18n="resetCodeLabel">Reset code</span>
100
102
  <input
101
103
  type="text"
102
104
  id="reset-code"
@@ -104,22 +106,25 @@
104
106
  autocomplete="one-time-code"
105
107
  maxlength="6"
106
108
  placeholder="6 digits"
109
+ data-i18n-placeholder="resetCodePlaceholder"
107
110
  required
108
111
  />
109
112
  </label>
110
113
 
111
114
  <label class="field">
112
- <span>New password</span>
115
+ <span data-i18n="newPassword">New password</span>
113
116
  <div class="input-wrap">
114
117
  <input
115
- type="password"
118
+ type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off"
116
119
  id="reset-pass"
117
120
  autocomplete="new-password"
118
121
  placeholder="At least <%= minLength %> characters"
122
+ data-i18n-placeholder="minLengthPlaceholder"
123
+ data-i18n-n="<%= minLength %>"
119
124
  minlength="<%= minLength %>"
120
125
  required
121
126
  />
122
- <button type="button" class="eye-btn" aria-label="Show password">
127
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
123
128
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
124
129
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
125
130
  </button>
@@ -127,17 +132,18 @@
127
132
  </label>
128
133
 
129
134
  <label class="field">
130
- <span>Repeat password</span>
135
+ <span data-i18n="repeatPassword">Repeat password</span>
131
136
  <div class="input-wrap">
132
137
  <input
133
- type="password"
138
+ type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off"
134
139
  id="reset-confirm"
135
140
  autocomplete="new-password"
136
141
  placeholder="Type it again"
142
+ data-i18n-placeholder="repeatPlaceholder"
137
143
  minlength="<%= minLength %>"
138
144
  required
139
145
  />
140
- <button type="button" class="eye-btn" aria-label="Show password">
146
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
141
147
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
142
148
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
143
149
  </button>
@@ -145,7 +151,7 @@
145
151
  </label>
146
152
 
147
153
  <button type="submit" class="btn btn-primary auth-submit">
148
- Set new password
154
+ <span data-i18n="resetSubmit">Set new password</span>
149
155
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
150
156
  </button>
151
157
  </form>
@@ -154,35 +160,25 @@
154
160
 
155
161
  </div>
156
162
 
157
- <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
163
+ <div class="foot"><%= brand.name %> <span data-i18n="by">by</span> <%= brand.developer %> · <%= brand.studio %></div>
158
164
  </div>
159
165
  </section>
160
166
  </main>
161
167
 
168
+ <script src="/gateway-i18n.js"></script>
162
169
  <script src="/gateway.js"></script>
163
170
  <script>
164
171
  (function () {
165
- // Android app: show back-to-app buttons, localize labels
172
+ var t = window.LevixGatewayI18n.t;
173
+
174
+ // Android app: show the back-to-app button. Its label is already in
175
+ // whichever language the page loaded in.
166
176
  var inApp = typeof window.LevixHost !== "undefined" && typeof window.LevixHost.closePanel === "function";
167
177
  if (inApp) {
168
- var isAr = false;
169
- try { isAr = localStorage.getItem("levix_lang") === "ar"; } catch(e) {}
170
- var backLabel = isAr ? "العودة للتطبيق" : "Back to app";
171
- var resetBackLabel = isAr ? "العودة لتسجيل الدخول" : "Back to sign in";
172
- ["login-back-app"].forEach(function(id) {
173
- var btn = document.getElementById(id);
174
- if (btn) {
175
- btn.hidden = false;
176
- btn.querySelector("span").textContent = backLabel;
177
- if (isAr) { btn.dir = "rtl"; btn.style.direction = "rtl"; }
178
- btn.addEventListener("click", function() { window.LevixHost.closePanel(); });
179
- }
180
- });
181
- var resetBackBtn = document.getElementById("reset-back");
182
- if (resetBackBtn && isAr) {
183
- resetBackBtn.querySelector("span").textContent = resetBackLabel;
184
- resetBackBtn.dir = "rtl";
185
- resetBackBtn.style.direction = "rtl";
178
+ var backBtn = document.getElementById("login-back-app");
179
+ if (backBtn) {
180
+ backBtn.hidden = false;
181
+ backBtn.addEventListener("click", function() { window.LevixHost.closePanel(); });
186
182
  }
187
183
  }
188
184
 
@@ -201,13 +197,52 @@
201
197
  loginCard.hidden = false;
202
198
  document.getElementById("forgot-link").focus();
203
199
  }
204
- function showError(text) {
205
- errorBox.textContent = text;
200
+ var getT = function () {
201
+ return window.LevixGatewayI18n ? window.LevixGatewayI18n.t : function (k) { return k; };
202
+ };
203
+ var currentErrorState = null;
204
+
205
+ function renderCurrentError() {
206
+ if (!currentErrorState) return;
207
+ var t = getT();
208
+ if (currentErrorState.type === "simple") {
209
+ errorBox.textContent = t(currentErrorState.key, currentErrorState.vars);
210
+ } else if (currentErrorState.type === "wrong_code") {
211
+ var msg = t("resetErrWrongCode");
212
+ if (currentErrorState.attemptsLeft) {
213
+ msg += " " + t("resetErrAttemptsLeft", { n: currentErrorState.attemptsLeft });
214
+ }
215
+ errorBox.textContent = msg;
216
+ } else if (currentErrorState.type === "invalid_password") {
217
+ errorBox.textContent =
218
+ window.LevixGatewayI18n && window.LevixGatewayI18n.lang === "ar"
219
+ ? t("resetErrInvalidPassword")
220
+ : currentErrorState.message || t("resetErrInvalidPassword");
221
+ } else if (currentErrorState.type === "raw") {
222
+ errorBox.textContent = currentErrorState.text;
223
+ }
206
224
  errorBox.hidden = false;
207
225
  }
226
+
227
+ function showErrorKey(key, vars) {
228
+ currentErrorState = { type: "simple", key: key, vars: vars };
229
+ renderCurrentError();
230
+ }
231
+ function showError(text) {
232
+ currentErrorState = { type: "raw", text: text };
233
+ renderCurrentError();
234
+ }
208
235
  function hideError() {
236
+ currentErrorState = null;
209
237
  errorBox.hidden = true;
210
238
  }
239
+
240
+ window.addEventListener("levix-gateway-lang", renderCurrentError);
241
+ window.addEventListener("levix-ui-prefs", renderCurrentError);
242
+ window.addEventListener("storage", function (e) {
243
+ if (e.key === "levix_lang") renderCurrentError();
244
+ });
245
+
211
246
  async function postJson(url, body) {
212
247
  const response = await fetch(url, {
213
248
  method: "POST",
@@ -240,19 +275,16 @@
240
275
  form.hidden = false;
241
276
  document.getElementById("reset-code").focus();
242
277
  } else if (result.reason === "throttled") {
243
- showError("Too many requests. Try again in " + (result.retryAfter || 60) + " seconds.");
278
+ showErrorKey("resetErrThrottled", { n: String(result.retryAfter || 60) });
244
279
  } else if (result.reason === "no_session") {
245
- showError(
246
- "WhatsApp isn't connected, so the code can't be sent. " +
247
- "Sign in on the server and run `levix reset-password`, or start the WhatsApp session first."
248
- );
280
+ showErrorKey("resetErrNoSession");
249
281
  } else if (result.reason === "send_failed") {
250
- showError("Couldn't send the WhatsApp message. Try again in a minute.");
282
+ showErrorKey("resetErrSendFailed");
251
283
  } else {
252
- showError("Couldn't start the reset. Try again.");
284
+ showErrorKey("resetErrStart");
253
285
  }
254
286
  } catch {
255
- showError("Couldn't reach the server. Try again.");
287
+ showErrorKey("resetErrServer");
256
288
  }
257
289
  sendBtn.disabled = false;
258
290
  });
@@ -269,34 +301,33 @@
269
301
  if (result.ok) {
270
302
  form.hidden = true;
271
303
  sendBtn.hidden = true;
272
- showError("Password updated. Taking you to sign in…");
304
+ showErrorKey("resetDone");
273
305
  setTimeout(function () {
274
306
  window.location.href = "/";
275
307
  }, 900);
276
308
  return;
277
309
  }
278
310
  if (result.reason === "wrong_code") {
279
- showError(
280
- "Wrong code." +
281
- (result.attemptsLeft ? " " + result.attemptsLeft + " attempts left." : "")
282
- );
311
+ currentErrorState = { type: "wrong_code", attemptsLeft: result.attemptsLeft };
312
+ renderCurrentError();
283
313
  } else if (
284
314
  result.reason === "expired" ||
285
315
  result.reason === "no_pending" ||
286
316
  result.reason === "too_many_attempts"
287
317
  ) {
288
- showError("That code is no longer valid. Send a new one.");
318
+ showErrorKey("resetErrExpired");
289
319
  form.hidden = true;
290
320
  sendBtn.hidden = false;
291
321
  } else if (result.reason === "mismatch") {
292
- showError("The two passwords don't match.");
322
+ showErrorKey("resetErrMismatch");
293
323
  } else if (result.reason === "invalid_password") {
294
- showError(result.message || "That password isn't allowed.");
324
+ currentErrorState = { type: "invalid_password", message: result.message };
325
+ renderCurrentError();
295
326
  } else {
296
- showError("Couldn't reset the password. Try again.");
327
+ showErrorKey("resetErrFailed");
297
328
  }
298
329
  } catch {
299
- showError("Couldn't reach the server. Try again.");
330
+ showErrorKey("resetErrServer");
300
331
  }
301
332
  });
302
333
  })();