@oxyhq/core 15.0.1 → 16.1.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 (39) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/OxyServices.errors.js +33 -1
  3. package/dist/cjs/OxyServices.js +2 -1
  4. package/dist/cjs/index.js +8 -5
  5. package/dist/cjs/mixins/OxyServices.assets.js +31 -8
  6. package/dist/cjs/mixins/OxyServices.deviceBoot.js +5 -5
  7. package/dist/cjs/utils/accountUtils.js +6 -1
  8. package/dist/cjs/utils/displayNamePolicyRanges.generated.js +28 -3
  9. package/dist/cjs/utils/validationUtils.js +110 -21
  10. package/dist/esm/.tsbuildinfo +1 -1
  11. package/dist/esm/OxyServices.errors.js +31 -0
  12. package/dist/esm/OxyServices.js +2 -2
  13. package/dist/esm/index.js +2 -2
  14. package/dist/esm/mixins/OxyServices.assets.js +32 -9
  15. package/dist/esm/mixins/OxyServices.deviceBoot.js +5 -5
  16. package/dist/esm/utils/accountUtils.js +6 -1
  17. package/dist/esm/utils/displayNamePolicyRanges.generated.js +27 -2
  18. package/dist/esm/utils/validationUtils.js +110 -21
  19. package/dist/types/.tsbuildinfo +1 -1
  20. package/dist/types/OxyServices.d.ts +2 -2
  21. package/dist/types/OxyServices.errors.d.ts +33 -0
  22. package/dist/types/index.d.ts +2 -2
  23. package/dist/types/mixins/OxyServices.assets.d.ts +17 -5
  24. package/dist/types/mixins/OxyServices.deviceBoot.d.ts +5 -5
  25. package/dist/types/utils/displayNamePolicyRanges.generated.d.ts +27 -2
  26. package/dist/types/utils/validationUtils.d.ts +104 -20
  27. package/package.json +2 -2
  28. package/src/OxyServices.errors.ts +45 -0
  29. package/src/OxyServices.ts +2 -2
  30. package/src/index.ts +3 -1
  31. package/src/mixins/OxyServices.assets.ts +36 -9
  32. package/src/mixins/OxyServices.deviceBoot.ts +5 -5
  33. package/src/mixins/__tests__/OxyServices.serviceAssetMetadata.test.ts +52 -3
  34. package/src/utils/__tests__/accountUtils.test.ts +22 -0
  35. package/src/utils/__tests__/coldBoot.test.ts +9 -4
  36. package/src/utils/__tests__/validationUtils.test.ts +292 -1
  37. package/src/utils/accountUtils.ts +9 -1
  38. package/src/utils/displayNamePolicyRanges.generated.ts +31 -2
  39. package/src/utils/validationUtils.ts +113 -20
@@ -7,8 +7,15 @@ import {
7
7
  DISPLAY_NAME_COMBINING_MARKS_RANGES,
8
8
  DISPLAY_NAME_SPACE_SEPARATORS_RANGES,
9
9
  DISPLAY_NAME_LETTERS_RANGES,
10
+ DISPLAY_NAME_NAME_SEPARATORS_RANGES,
10
11
  } from './displayNamePolicyRanges.generated';
11
12
 
13
+ /**
14
+ * Maximum stored length of a display name, in code units after cleaning.
15
+ * Shared by the API write path and client input surfaces.
16
+ */
17
+ export const MAX_DISPLAY_NAME_LENGTH = 80;
18
+
12
19
  /**
13
20
  * Email validation regex
14
21
  */
@@ -61,7 +68,16 @@ export function isValidPassword(password: string): boolean {
61
68
  * ideographic space, …) — but NOT control whitespace such as tab, newline,
62
69
  * or carriage return, which would break layout or enable multi-line
63
70
  * spoofing,
64
- * - the straight apostrophe (`'`, e.g. "O'Brien").
71
+ * - the straight apostrophe (`'`, e.g. "O'Brien"),
72
+ * - four name SEPARATORS — `·` U+00B7, `־` U+05BE, `་` U+0F0B, `・` U+30FB —
73
+ * but ONLY directly between two letters (`Codeur·euses`, `お坐・エガード`,
74
+ * `אברמסקי־קרוננברג`, `འོད་ཟེར`). Every one is General_Category P, so the
75
+ * letters intersection strips them by default; they are re-admitted because
76
+ * stripping them SPLITS a real name in two. The flanking condition is not a
77
+ * refinement but the whole point: the same characters are also used as
78
+ * ornament (a trailing `Roberto ·`), and unconditional admission would let
79
+ * that through. See {@link DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE}. The
80
+ * ASCII hyphen is NOT among them — `Jean-Luc` stays rejected.
65
81
  *
66
82
  * Everything else is rejected: emoji (🐧), symbols (⁂ ⏚), `:emoji:` shortcodes,
67
83
  * digits, hyphens, dots, control whitespace (tab/newline/CR), letters from
@@ -71,7 +87,15 @@ export function isValidPassword(password: string): boolean {
71
87
  *
72
88
  * The allowlist is expressed with Unicode Script_Extensions (scx=…) so a letter
73
89
  * shared by several scripts (e.g. a Han ideograph used in both Chinese and
74
- * Japanese) still matches. It is the set of scripts Unicode UTS #39 marks
90
+ * Japanese) still matches, INTERSECTED with General_Category L so only the
91
+ * scripts' LETTERS are admitted. That intersection is load-bearing, not a
92
+ * refinement: `scx=X` also carries script X's own digits, punctuation and
93
+ * symbols, so the un-intersected allowlist admitted 1831 non-letter code points
94
+ * — script digits (`٠١٢`, `०१२`), 1082 symbols (`֍ ۞ ৳`), 180 punctuation marks
95
+ * (`։ ، ؛ ।`), and 9 INVISIBLE format/control characters, among them U+061C
96
+ * ARABIC LETTER MARK (a bidi control that can visually reorder a name) and
97
+ * U+180E MONGOLIAN VOWEL SEPARATOR. Without it the rejections listed above held
98
+ * for ASCII input only. It is the set of scripts Unicode UTS #39 marks
75
99
  * "Recommended" for general interchange / identifiers, plus Cherokee and
76
100
  * Mongolian (both in real modern name use). "Common" script is deliberately
77
101
  * EXCLUDED — that is where ASCII digits and general punctuation live, and this
@@ -79,6 +103,29 @@ export function isValidPassword(password: string): boolean {
79
103
  * name needs are added back explicitly. Limited-use / excluded / historic
80
104
  * scripts (Batak, Runic, Deseret, Adlam, …) are simply absent.
81
105
  *
106
+ * CODE-POINT DENYLIST — a character policy classifies FORM, never MEANING, so a
107
+ * code point can be a perfectly ordinary letter to Unicode and a hate symbol to
108
+ * a reader. `卐` U+5350 and `卍` U+534D are the case in point: both are CJK
109
+ * Unified Ideographs (General_Category Lo, Script_Extensions Han), i.e. the same
110
+ * kind of thing as `山` in `山田太郎`, so NO script-level or category-level rule
111
+ * can separate them — every rule that would exclude these two also excludes Han
112
+ * itself, rejecting every real Chinese, Japanese and Korean name. They are
113
+ * therefore enumerated and SUBTRACTED from the allowlist at generation time (see
114
+ * `SYMBOL_LETTER_DENYLIST` in `scripts/generateDisplayNamePolicyRanges.mjs`).
115
+ * Because the subtraction happens inside the one emitted allowlist, every
116
+ * consumer enforces it with no extra probe and none can forget it; the generator
117
+ * additionally REFUSES an entry that an existing lever already excludes (e.g.
118
+ * the Tibetan svasti signs U+0FD5–U+0FD8, General_Category So, already dropped
119
+ * by the intersection above), so the list cannot silently accumulate dead
120
+ * weight.
121
+ *
122
+ * REMAINING LIMIT — that closes the "letter that reads as a symbol" gap, not the
123
+ * other one: slurs and abusive phrasing spelled in ordinary allowlisted letters
124
+ * pass by construction, because they are built from exactly the characters every
125
+ * real name needs. No character-level rule — allowlist, intersection, or
126
+ * denylist — can reject them; that needs a word-level moderation layer, which is
127
+ * deliberately not attempted here.
128
+ *
82
129
  * HERMES / RANGES: the class bodies below are built from explicit Unicode
83
130
  * code-point RANGES ({@link DISPLAY_NAME_ALLOWED_SCRIPTS_RANGES} et al. from
84
131
  * `./displayNamePolicyRanges.generated`), NOT from `scx`/General_Category
@@ -100,21 +147,28 @@ export function isValidPassword(password: string): boolean {
100
147
 
101
148
  /**
102
149
  * The curated allowlist of Unicode scripts permitted in a display name, as a
103
- * character-class body of explicit code-point ranges (the compressed union of
104
- * the 30 allowlisted Script_Extensions, generated on V8). Interpolated into the
105
- * negated class below.
150
+ * character-class body of explicit code-point ranges: the union of the 30
151
+ * allowlisted Script_Extensions, INTERSECTED with General_Category L (so letters
152
+ * only), MINUS the symbol-letter denylist — 120823 code points. Interpolated
153
+ * into the negated class below, which is why both the reject gate here and the
154
+ * `@oxyhq/api` strip path inherit the denylist without a second pattern.
106
155
  */
107
156
  export const DISPLAY_NAME_ALLOWED_SCRIPTS = DISPLAY_NAME_ALLOWED_SCRIPTS_RANGES;
108
157
 
109
158
  /**
110
159
  * Source of the disallowed-character pattern: the negation of the full allowed
111
160
  * set (allowlisted scripts + combining marks + space separators + the straight
112
- * apostrophe). Consumers compile this with the `u` flag (and `g` for a global
113
- * strip). The whitespace class is space separators only (General_Category Zs),
114
- * NOT `\s` — the latter would admit tab/newline/carriage return, which break
115
- * layout and enable multi-line spoofing.
161
+ * apostrophe + the name separators). Consumers compile this with the `u` flag
162
+ * (and `g` for a global strip). The whitespace class is space separators only
163
+ * (General_Category Zs), NOT `\s` — the latter would admit tab/newline/carriage
164
+ * return, which break layout and enable multi-line spoofing.
165
+ *
166
+ * The name separators are admitted here only as CHARACTERS. Their position rule
167
+ * is a separate pattern ({@link DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE}), for
168
+ * the same reason combining marks are: a negated character class cannot express
169
+ * "allowed only in this context". Both halves must be applied together.
116
170
  */
117
- export const DISPLAY_NAME_DISALLOWED_SOURCE = `[^${DISPLAY_NAME_ALLOWED_SCRIPTS}${DISPLAY_NAME_COMBINING_MARKS_RANGES}${DISPLAY_NAME_SPACE_SEPARATORS_RANGES}']`;
171
+ export const DISPLAY_NAME_DISALLOWED_SOURCE = `[^${DISPLAY_NAME_ALLOWED_SCRIPTS}${DISPLAY_NAME_COMBINING_MARKS_RANGES}${DISPLAY_NAME_SPACE_SEPARATORS_RANGES}${DISPLAY_NAME_NAME_SEPARATORS_RANGES}']`;
118
172
 
119
173
  /**
120
174
  * Source of the orphaned combining-mark pattern: a run of combining marks NOT
@@ -129,29 +183,68 @@ export const DISPLAY_NAME_DISALLOWED_SOURCE = `[^${DISPLAY_NAME_ALLOWED_SCRIPTS}
129
183
  */
130
184
  export const DISPLAY_NAME_ORPHANED_MARK_SOURCE = `(?<![${DISPLAY_NAME_LETTERS_RANGES}${DISPLAY_NAME_COMBINING_MARKS_RANGES}])[${DISPLAY_NAME_COMBINING_MARKS_RANGES}]+`;
131
185
 
186
+ /**
187
+ * Source of the unflanked name-separator pattern — the positional half of the
188
+ * name-separator rule, and the exact counterpart of
189
+ * {@link DISPLAY_NAME_ORPHANED_MARK_SOURCE}: a combining mark is allowed only
190
+ * when it rides a base letter, and a name separator is allowed only when it JOINS
191
+ * two letters. Matches a separator that is missing a letter on either side, so
192
+ * consumers can reject it (non-global probe) or strip it (`g` flag).
193
+ *
194
+ * Two alternatives, one per side, because JS has no "not surrounded by" atom:
195
+ * - `(?<![letters][marks])[sep]` — nothing letter-like immediately BEFORE.
196
+ * - `[sep](?![letters])` — no letter immediately AFTER.
197
+ *
198
+ * The left-hand class deliberately includes combining marks as well as letters:
199
+ * a base letter can carry an accent (`Renée·euses`, or a decomposed `e`+◌́), and
200
+ * that mark sits between the letter and the separator. Treating a mark as
201
+ * letter-like is what stops an accent from defeating the flanking test — the
202
+ * same reason the orphaned-mark lookbehind uses the identical pair of classes.
203
+ * The right-hand class is letters only: a mark AFTER a separator has no base and
204
+ * is removed by the orphaned-mark rule, so the separator is genuinely unflanked.
205
+ *
206
+ * Both lookarounds are single-character (no variable-length lookbehind), and the
207
+ * classes are explicit code-point ranges, so the compiled regex is within what
208
+ * Hermes accepts.
209
+ *
210
+ * `Codeur·euses` and `お坐・エガード` match NOTHING here and survive. A leading
211
+ * `·Roberto`, a trailing `Roberto ·`, and a doubled `a··b` each match and are
212
+ * stripped — which is what keeps a decorative middle dot from riding in on the
213
+ * back of the orthographic one.
214
+ */
215
+ export const DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE = `(?<![${DISPLAY_NAME_LETTERS_RANGES}${DISPLAY_NAME_COMBINING_MARKS_RANGES}])[${DISPLAY_NAME_NAME_SEPARATORS_RANGES}]|[${DISPLAY_NAME_NAME_SEPARATORS_RANGES}](?![${DISPLAY_NAME_LETTERS_RANGES}])`;
216
+
132
217
  /** Non-global probe for the presence of a disallowed character. */
133
218
  const DISALLOWED_PROBE = new RegExp(DISPLAY_NAME_DISALLOWED_SOURCE, 'u');
134
219
 
135
220
  /** Non-global probe for the presence of an orphaned combining mark. */
136
221
  const ORPHANED_MARK_PROBE = new RegExp(DISPLAY_NAME_ORPHANED_MARK_SOURCE, 'u');
137
222
 
223
+ /** Non-global probe for the presence of an unflanked name separator. */
224
+ const UNFLANKED_SEPARATOR_PROBE = new RegExp(DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE, 'u');
225
+
138
226
  /**
139
227
  * Whether `raw` already satisfies the display-name policy, i.e. it contains no
140
- * disallowed characters AND no orphaned combining marks. Used to REJECT native
141
- * (signup / profile edit) names with a 400 rather than silently stripping them,
142
- * and to validate inline in the client editor.
228
+ * disallowed characters, no orphaned combining marks, and no unflanked name
229
+ * separator. Used to REJECT native (signup / profile edit) names with a 400
230
+ * rather than silently stripping them, and to validate inline in the client
231
+ * editor.
143
232
  *
144
- * The orphaned-mark probe runs on the NFC-normalized form so a legitimate
145
- * decomposed accent (`e`+◌́) which normalization recomposes into `é` is NOT
146
- * rejected, while a lone, base-less mark (e.g. `"༘"`) IS.
233
+ * The two positional probes run on the NFC-normalized form, the character probe
234
+ * on the raw input. Normalization matters for both: a legitimate decomposed
235
+ * accent (`e`+◌́) recomposes into `é`, so it is NOT rejected as an orphaned mark,
236
+ * and a separator after that accent sees a base letter rather than a mark.
147
237
  *
148
- * The function only checks the character set; an empty or whitespace-only string
149
- * is considered valid (`true`). Call sites that require a non-empty name enforce
150
- * that separately.
238
+ * The function only checks the character set and separator placement; an empty
239
+ * or whitespace-only string is considered valid (`true`). Call sites that require
240
+ * a non-empty name enforce that separately.
151
241
  */
152
242
  export function isValidDisplayName(raw: string): boolean {
243
+ const normalized = raw.normalize('NFC');
153
244
  return (
154
- !DISALLOWED_PROBE.test(raw) && !ORPHANED_MARK_PROBE.test(raw.normalize('NFC'))
245
+ !DISALLOWED_PROBE.test(raw) &&
246
+ !ORPHANED_MARK_PROBE.test(normalized) &&
247
+ !UNFLANKED_SEPARATOR_PROBE.test(normalized)
155
248
  );
156
249
  }
157
250