@oxy.so/contracts 1.0.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 (147) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +16 -0
  3. package/dist/cjs/.tsbuildinfo +1 -0
  4. package/dist/cjs/accountGraph.js +489 -0
  5. package/dist/cjs/agency.js +439 -0
  6. package/dist/cjs/browserHub.js +215 -0
  7. package/dist/cjs/civic.js +163 -0
  8. package/dist/cjs/commonsSignIn.js +59 -0
  9. package/dist/cjs/deviceBoot.js +50 -0
  10. package/dist/cjs/deviceDirectory.js +189 -0
  11. package/dist/cjs/devicePairing.js +138 -0
  12. package/dist/cjs/deviceSession.js +164 -0
  13. package/dist/cjs/emailAgentContext.js +32 -0
  14. package/dist/cjs/followGraph.js +28 -0
  15. package/dist/cjs/identity.js +258 -0
  16. package/dist/cjs/inboxPush.js +24 -0
  17. package/dist/cjs/index.js +618 -0
  18. package/dist/cjs/inference/accountBilling.js +334 -0
  19. package/dist/cjs/inference/aliaModelRelease.js +262 -0
  20. package/dist/cjs/inference/attribution.js +106 -0
  21. package/dist/cjs/inference/catalogue.js +487 -0
  22. package/dist/cjs/inference/entitlement.js +217 -0
  23. package/dist/cjs/inference/errors.js +309 -0
  24. package/dist/cjs/inference/identifiers.js +224 -0
  25. package/dist/cjs/inference/inbox.js +105 -0
  26. package/dist/cjs/inference/modelDocumentation.js +433 -0
  27. package/dist/cjs/inference/money.js +188 -0
  28. package/dist/cjs/inference/priceVersion.js +110 -0
  29. package/dist/cjs/inference/providerConnection.js +455 -0
  30. package/dist/cjs/inference/request.js +477 -0
  31. package/dist/cjs/inference/routingPolicy.js +318 -0
  32. package/dist/cjs/inference/streamEvents.js +258 -0
  33. package/dist/cjs/inference/usage.js +329 -0
  34. package/dist/cjs/inference/version.js +105 -0
  35. package/dist/cjs/keyRecovery.js +91 -0
  36. package/dist/cjs/keyRotation.js +75 -0
  37. package/dist/cjs/links.js +68 -0
  38. package/dist/cjs/moderationReputation.js +298 -0
  39. package/dist/cjs/oauth.js +66 -0
  40. package/dist/cjs/oxyRecordTypes.js +71 -0
  41. package/dist/cjs/protocol.js +53 -0
  42. package/dist/cjs/recommendations.js +168 -0
  43. package/dist/cjs/reputation.js +297 -0
  44. package/dist/cjs/sessionStatus.js +121 -0
  45. package/dist/cjs/transparency.js +89 -0
  46. package/dist/cjs/updates.js +252 -0
  47. package/dist/cjs/userInvalidation.js +89 -0
  48. package/dist/cjs/userResponse.js +245 -0
  49. package/dist/cjs/username.js +290 -0
  50. package/dist/cjs/webauthn.js +71 -0
  51. package/dist/esm/.tsbuildinfo +1 -0
  52. package/dist/esm/accountGraph.js +480 -0
  53. package/dist/esm/agency.js +436 -0
  54. package/dist/esm/browserHub.js +212 -0
  55. package/dist/esm/civic.js +160 -0
  56. package/dist/esm/commonsSignIn.js +56 -0
  57. package/dist/esm/deviceBoot.js +47 -0
  58. package/dist/esm/deviceDirectory.js +186 -0
  59. package/dist/esm/devicePairing.js +135 -0
  60. package/dist/esm/deviceSession.js +161 -0
  61. package/dist/esm/emailAgentContext.js +29 -0
  62. package/dist/esm/followGraph.js +27 -0
  63. package/dist/esm/identity.js +255 -0
  64. package/dist/esm/inboxPush.js +21 -0
  65. package/dist/esm/index.js +172 -0
  66. package/dist/esm/inference/accountBilling.js +331 -0
  67. package/dist/esm/inference/aliaModelRelease.js +259 -0
  68. package/dist/esm/inference/attribution.js +103 -0
  69. package/dist/esm/inference/catalogue.js +484 -0
  70. package/dist/esm/inference/entitlement.js +214 -0
  71. package/dist/esm/inference/errors.js +306 -0
  72. package/dist/esm/inference/identifiers.js +221 -0
  73. package/dist/esm/inference/inbox.js +102 -0
  74. package/dist/esm/inference/modelDocumentation.js +430 -0
  75. package/dist/esm/inference/money.js +185 -0
  76. package/dist/esm/inference/priceVersion.js +107 -0
  77. package/dist/esm/inference/providerConnection.js +452 -0
  78. package/dist/esm/inference/request.js +474 -0
  79. package/dist/esm/inference/routingPolicy.js +315 -0
  80. package/dist/esm/inference/streamEvents.js +255 -0
  81. package/dist/esm/inference/usage.js +326 -0
  82. package/dist/esm/inference/version.js +102 -0
  83. package/dist/esm/keyRecovery.js +88 -0
  84. package/dist/esm/keyRotation.js +72 -0
  85. package/dist/esm/links.js +65 -0
  86. package/dist/esm/moderationReputation.js +295 -0
  87. package/dist/esm/oauth.js +63 -0
  88. package/dist/esm/oxyRecordTypes.js +68 -0
  89. package/dist/esm/protocol.js +50 -0
  90. package/dist/esm/recommendations.js +165 -0
  91. package/dist/esm/reputation.js +293 -0
  92. package/dist/esm/sessionStatus.js +118 -0
  93. package/dist/esm/transparency.js +86 -0
  94. package/dist/esm/updates.js +249 -0
  95. package/dist/esm/userInvalidation.js +85 -0
  96. package/dist/esm/userResponse.js +240 -0
  97. package/dist/esm/username.js +283 -0
  98. package/dist/esm/webauthn.js +68 -0
  99. package/dist/types/.tsbuildinfo +1 -0
  100. package/dist/types/accountGraph.d.ts +378 -0
  101. package/dist/types/agency.d.ts +2162 -0
  102. package/dist/types/browserHub.d.ts +856 -0
  103. package/dist/types/civic.d.ts +338 -0
  104. package/dist/types/commonsSignIn.d.ts +58 -0
  105. package/dist/types/deviceBoot.d.ts +74 -0
  106. package/dist/types/deviceDirectory.d.ts +1317 -0
  107. package/dist/types/devicePairing.d.ts +130 -0
  108. package/dist/types/deviceSession.d.ts +411 -0
  109. package/dist/types/emailAgentContext.d.ts +248 -0
  110. package/dist/types/followGraph.d.ts +150 -0
  111. package/dist/types/identity.d.ts +402 -0
  112. package/dist/types/inboxPush.d.ts +30 -0
  113. package/dist/types/index.d.ts +100 -0
  114. package/dist/types/inference/accountBilling.d.ts +738 -0
  115. package/dist/types/inference/aliaModelRelease.d.ts +609 -0
  116. package/dist/types/inference/attribution.d.ts +176 -0
  117. package/dist/types/inference/catalogue.d.ts +1618 -0
  118. package/dist/types/inference/entitlement.d.ts +519 -0
  119. package/dist/types/inference/errors.d.ts +242 -0
  120. package/dist/types/inference/identifiers.d.ts +182 -0
  121. package/dist/types/inference/inbox.d.ts +374 -0
  122. package/dist/types/inference/modelDocumentation.d.ts +1603 -0
  123. package/dist/types/inference/money.d.ts +185 -0
  124. package/dist/types/inference/priceVersion.d.ts +182 -0
  125. package/dist/types/inference/providerConnection.d.ts +968 -0
  126. package/dist/types/inference/request.d.ts +2800 -0
  127. package/dist/types/inference/routingPolicy.d.ts +616 -0
  128. package/dist/types/inference/streamEvents.d.ts +950 -0
  129. package/dist/types/inference/usage.d.ts +1164 -0
  130. package/dist/types/inference/version.d.ts +102 -0
  131. package/dist/types/keyRecovery.d.ts +138 -0
  132. package/dist/types/keyRotation.d.ts +103 -0
  133. package/dist/types/links.d.ts +96 -0
  134. package/dist/types/moderationReputation.d.ts +487 -0
  135. package/dist/types/oauth.d.ts +86 -0
  136. package/dist/types/oxyRecordTypes.d.ts +62 -0
  137. package/dist/types/protocol.d.ts +86 -0
  138. package/dist/types/recommendations.d.ts +542 -0
  139. package/dist/types/reputation.d.ts +457 -0
  140. package/dist/types/sessionStatus.d.ts +231 -0
  141. package/dist/types/transparency.d.ts +392 -0
  142. package/dist/types/updates.d.ts +545 -0
  143. package/dist/types/userInvalidation.d.ts +94 -0
  144. package/dist/types/userResponse.d.ts +1706 -0
  145. package/dist/types/username.d.ts +265 -0
  146. package/dist/types/webauthn.d.ts +77 -0
  147. package/package.json +87 -0
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ /**
3
+ * Username policy — the ONE rule, for every kind of account.
4
+ *
5
+ * A username is a HANDLE: the routing key of a profile URL (`/@alice`), the
6
+ * local part of a webfinger `acct:`, and a login identifier. `users.username`
7
+ * carries a single unique index, `lower(btrim(username))`, and people, bots,
8
+ * organizations, projects and channels all draw from it. There is no per-kind
9
+ * NAMESPACE, so no kind may LOOSEN the rule — a bot that could reserve a name a
10
+ * person cannot ask for is a disagreement inside one index, not a variant.
11
+ *
12
+ * One kind TIGHTENS it, and only in that direction: a `bot` handle must also end
13
+ * in `bot` ({@link botUsernameSchema}, at the bottom of this file). That is a
14
+ * label a bot wears, not a name it takes off anybody — everything it accepts,
15
+ * {@link usernameSchema} already accepted. {@link usernameSchemaForAccountKind}
16
+ * is the single place that branch is written.
17
+ *
18
+ * ## Why this file exists
19
+ *
20
+ * Seven rules governed this one namespace: four validators (this package's
21
+ * predecessor in `@oxy.so/api`, `@oxy.so/core`, `@oxy.so/commons`, and one written
22
+ * inline in `AccountService.resolveUniqueUsername`) and three that COERCED —
23
+ * silently deleting the characters they disliked, which hands somebody an
24
+ * account under a name they never chose. They lived in five packages and no test
25
+ * asserted they agreed. `contracts` is where the single declaration can actually
26
+ * live: `api`, `core`, `commons`, `services` and `auth` all already depend on it,
27
+ * so every write path can IMPORT the rule instead of restating it.
28
+ * `__tests__/usernamePolicySingleSource.test.ts` fails if a second one appears.
29
+ *
30
+ * ## The rule, and why each part of it
31
+ *
32
+ * ```
33
+ * 3–30 characters
34
+ * first and last character: [A-Za-z0-9]
35
+ * interior: [A-Za-z0-9_-]
36
+ * never two separators in a row
37
+ * ```
38
+ *
39
+ * - **Hyphens are admitted because the DATABASE already admits them.**
40
+ * `internal_cost_centers_slug_check` is a CHECK constraint —
41
+ * `^[a-z0-9][a-z0-9-]{0,62}$` — and `seed-internal-cost-centers` mints a
42
+ * `project` account whose username IS the slug; four of the five declared
43
+ * centres contain a hyphen. An alphanumeric-only handle rule would contradict
44
+ * a constraint written to permit them, and would make those centres
45
+ * unmintable. This is the argument, not the four hyphenated accounts that
46
+ * happen to exist — they are a symptom.
47
+ * - **Dots are NOT admitted.** A dot is the delimiter that separates handle from
48
+ * domain in the federated form this same column stores for remote actors
49
+ * (`alice@mastodon.social`), it collides with extension-style routing
50
+ * (`/@alice.json`), and `n.ate` beside `nate` is the strongest confusable pair
51
+ * an ASCII handle can produce. Only the inline account rule ever accepted one,
52
+ * and it accepted it by accident: its `[\w.-]` was written for a SLUG.
53
+ * - **A length bound, always.** The account path had none — the only ceiling was
54
+ * a `.max(100)` on the wire schema. 3 is the floor because `oxy`, the platform
55
+ * owner's own organization, is three characters. 30 is the ceiling four of the
56
+ * seven rules and the availability endpoint already published.
57
+ * - **First and last character alphanumeric, and no `--` / `__` / `-_` run.**
58
+ * Both are free — no account uses such a name — and they remove the
59
+ * confusable shapes that admitting two separators would otherwise introduce.
60
+ *
61
+ * ## Case, and what this schema deliberately does not do
62
+ *
63
+ * **Case is PRESERVED.** Uniqueness is decided by the database's
64
+ * `lower(btrim(username))` index, so `Alice` and `alice` cannot coexist, but a
65
+ * name that was typed with a capital keeps it. This schema therefore never
66
+ * lower-cases: rewriting a caller's input is how `resolveUniqueUsername` used to
67
+ * return `mybot` to somebody who asked for `MyBot`.
68
+ *
69
+ * **This is a WRITE-path rule.** It states what may be newly stored, not what may
70
+ * be read. Rows that predate it — including 11 with no username at all — must go
71
+ * on loading, resolving and rendering; validating on a read turns an existing
72
+ * account into a 500.
73
+ *
74
+ * **It does not govern remote actors.** The same column holds ~73k federated
75
+ * rows in `handle@domain` form, written by `POST /users/resolve` through its own
76
+ * normalizer. Those are another server's namespace; this rule would reject every
77
+ * one of them and must never be pointed at that path.
78
+ *
79
+ * ## Usable by a handle GENERATOR, deliberately
80
+ *
81
+ * Slug generators are how the eighth copy of this rule appears. Alia's
82
+ * `suggestAgentUsername` builds one from an agent's name and re-derives a subset
83
+ * of these rules by hand — its own docblock admits it ("A leading digit or an
84
+ * empty slug both fail Oxy's username rules") — and, having no minimum, proposes
85
+ * `al` for an agent called "Al", which the server then refuses.
86
+ *
87
+ * So this module answers a generator's three questions without dragging a server
88
+ * dependency along. It is zod and nothing else, so it imports cleanly into a
89
+ * React Native bundle or another repo's backend:
90
+ *
91
+ * - *Does this candidate pass?* {@link isValidUsername}, or `safeParse` when the
92
+ * reason matters.
93
+ * - *How short is too short, how long is too long?* {@link USERNAME_MIN_LENGTH}
94
+ * and {@link USERNAME_MAX_LENGTH}, so a generator can pad or truncate instead
95
+ * of guessing and being 400ed.
96
+ * - *Which characters survive?* {@link stripDisallowedUsernameCharacters}.
97
+ *
98
+ * A generator PROPOSES; only `POST /accounts` decides, and a taken handle comes
99
+ * back as a 409 for the client to retry with a fresh suggestion. Nothing here
100
+ * knows what is taken, and it must not pretend to.
101
+ */
102
+ Object.defineProperty(exports, "__esModule", { value: true });
103
+ exports.botUsernameSchema = exports.BOT_USERNAME_INVALID_MESSAGE = exports.BOT_USERNAME_SUFFIX = exports.usernameSchema = exports.USERNAME_PATTERN_SOURCE = exports.USERNAME_INVALID_MESSAGE = exports.USERNAME_MAX_LENGTH = exports.USERNAME_MIN_LENGTH = void 0;
104
+ exports.isValidUsername = isValidUsername;
105
+ exports.stripDisallowedUsernameCharacters = stripDisallowedUsernameCharacters;
106
+ exports.usernameSchemaForAccountKind = usernameSchemaForAccountKind;
107
+ exports.applyBotUsernameSuffix = applyBotUsernameSuffix;
108
+ const zod_1 = require("zod");
109
+ /** Shortest storable handle. `oxy` sets the floor. */
110
+ exports.USERNAME_MIN_LENGTH = 3;
111
+ /** Longest storable handle, and the `maxLength` an input field should carry. */
112
+ exports.USERNAME_MAX_LENGTH = 30;
113
+ /** The 400 / inline-validation copy for every path that rejects a handle. */
114
+ exports.USERNAME_INVALID_MESSAGE = 'Username must be 3-30 characters, use only letters, numbers, hyphens and underscores, ' +
115
+ 'start and end with a letter or number, and never repeat a separator';
116
+ /**
117
+ * Alphanumeric runs joined by single separators, as a SOURCE string.
118
+ *
119
+ * A string rather than a literal because the OpenAPI docblocks that publish this
120
+ * rule (`POST /auth/register`, `PUT /users/:userId`) must quote it verbatim, and
121
+ * `usernamePolicySingleSource.test.ts` compares them against THIS constant. A
122
+ * published `pattern:` that drifts from the enforced rule is a lie told to every
123
+ * client that generates from the spec, and it is exactly the kind of copy nobody
124
+ * notices going stale.
125
+ *
126
+ * Deliberately NOT re-exported from the package barrel: it exists for the
127
+ * schema below and for that one gate. Anything validating a username uses
128
+ * {@link usernameSchema}, so there is no second way to ask the question.
129
+ *
130
+ * Written as an unambiguous alternation rather than a lookahead: every character
131
+ * belongs to exactly one branch, so matching is linear and there is no
132
+ * backtracking to bound. It also carries no `\p{…}` property escape, which
133
+ * mobile Hermes throws on at runtime — this module is reachable from every React
134
+ * Native consumer.
135
+ */
136
+ exports.USERNAME_PATTERN_SOURCE = '^[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*$';
137
+ const USERNAME_PATTERN = new RegExp(exports.USERNAME_PATTERN_SOURCE);
138
+ /**
139
+ * The one username policy, as a schema.
140
+ *
141
+ * `.trim()` first, so surrounding whitespace is a typo rather than a rejection —
142
+ * but interior whitespace is NOT removed. It falls to the pattern, because
143
+ * squashing `"al ice"` into `"alice"` would hand the user an account under a name
144
+ * they never chose. Every write path validates through THIS object; nothing
145
+ * re-implements it.
146
+ */
147
+ exports.usernameSchema = zod_1.z
148
+ .string()
149
+ .trim()
150
+ .min(exports.USERNAME_MIN_LENGTH, exports.USERNAME_INVALID_MESSAGE)
151
+ .max(exports.USERNAME_MAX_LENGTH, exports.USERNAME_INVALID_MESSAGE)
152
+ .regex(USERNAME_PATTERN, exports.USERNAME_INVALID_MESSAGE);
153
+ /**
154
+ * Whether a candidate handle is storable — the boolean form, for input surfaces
155
+ * that show a message as somebody types rather than throwing.
156
+ *
157
+ * Answers from {@link usernameSchema}, so a client's inline check and the
158
+ * server's 400 cannot disagree.
159
+ */
160
+ function isValidUsername(candidate) {
161
+ return exports.usernameSchema.safeParse(candidate).success;
162
+ }
163
+ /**
164
+ * Drop the characters the policy forbids, for an input field that filters
165
+ * keystrokes.
166
+ *
167
+ * This is a TYPING aid and nothing else — the result still has to pass
168
+ * {@link usernameSchema}, which is what decides. It does not lower-case (case is
169
+ * preserved, see the header) and it cannot repair a name: a value that is too
170
+ * short, edge-separated or doubly-separated comes back unchanged and fails
171
+ * validation with a message, which is the outcome the coercing rules this
172
+ * replaces used to hide.
173
+ */
174
+ function stripDisallowedUsernameCharacters(input) {
175
+ return input.replace(/[^A-Za-z0-9_-]/g, '');
176
+ }
177
+ /**
178
+ * The label a bot's handle ends in — the ONE exception the policy carries.
179
+ *
180
+ * Lower-case here because it is what a generator appends; the comparison that
181
+ * enforces it folds case, so `MyBot` satisfies it just as `mybot` does.
182
+ *
183
+ * Deliberately NOT re-exported from the package barrel, for the same reason
184
+ * {@link USERNAME_PATTERN_SOURCE} is not: it exists for the schema and the
185
+ * generator aid below. A consumer that wants to SAY the rule uses
186
+ * {@link BOT_USERNAME_INVALID_MESSAGE}, which already quotes it, and one that
187
+ * wants to APPLY it uses {@link applyBotUsernameSuffix} — so there is no second
188
+ * way to spell the check.
189
+ */
190
+ exports.BOT_USERNAME_SUFFIX = 'bot';
191
+ /** The 400 / inline-validation copy for a bot handle that carries no label. */
192
+ exports.BOT_USERNAME_INVALID_MESSAGE = `A bot account's username must end in "${exports.BOT_USERNAME_SUFFIX}"`;
193
+ /**
194
+ * The username policy for an account of kind `bot`: everything above, plus a
195
+ * handle that ends in {@link BOT_USERNAME_SUFFIX}.
196
+ *
197
+ * ## Why a suffix, and why THIS one
198
+ *
199
+ * A bot is not a person, and the handle is the only part of an account that
200
+ * travels — into a URL, a mention, a webfinger `acct:`, a screenshot. Telegram
201
+ * settled this question the same way for the same reason: whatever the
202
+ * surrounding UI shows, `@somethingbot` says what it is at the point of contact.
203
+ * Nothing else in Oxy makes the distinction visible where it is actually read.
204
+ *
205
+ * The form is `bot` at the END, folded for case. Each half of that is decided by
206
+ * what THIS policy already admits, not by copying Telegram:
207
+ *
208
+ * - **The bare label, not `_bot`.** Telegram's common form uses an underscore,
209
+ * but Oxy admits `-` and `_` as equal separators — hyphens are load-bearing
210
+ * (`internal_cost_centers_slug_check`, and the accounts minted from those
211
+ * slugs), so a rule naming one of them would refuse `garden-helper-bot` while
212
+ * accepting `garden_helper_bot`, a distinction no other line of this policy
213
+ * makes. Requiring only the label leaves the separator to whoever chooses the
214
+ * name: `aliabot`, `alia-bot` and `alia_bot` all conform.
215
+ * - **Case-INSENSITIVE.** Case is preserved but uniqueness folds it
216
+ * (`lower(btrim(username))`), so a case-sensitive test would accept `mybot`
217
+ * and refuse `MyBot` — two names the index considers the same one. A rule that
218
+ * disagrees with the index about identity is a rule with two answers.
219
+ * - **The label is all ASCII alphanumerics**, so appending it to any handle that
220
+ * passes {@link usernameSchema} yields another one. That is what makes
221
+ * {@link applyBotUsernameSuffix} safe and a generator's suggestion honest.
222
+ *
223
+ * It is checked LAST, after the base policy: a handle that is illegal for
224
+ * everybody is reported as illegal rather than as a bot that forgot its label,
225
+ * so nobody appends `bot` to `a.b` and is refused twice.
226
+ *
227
+ * ## What it is NOT
228
+ *
229
+ * **Not a namespace.** `users.username` is still one unique index. A bot must be
230
+ * labelled; the label is not RESERVED, so `abbot` and `robot` stay available to
231
+ * anybody — the rule says what a bot's handle must look like, not what everyone
232
+ * else's may not.
233
+ *
234
+ * **Not a rule about the other four kinds.** `personal`, `organization`,
235
+ * `project` and `channel` are governed by {@link usernameSchema}, unchanged.
236
+ * {@link usernameSchemaForAccountKind} is the only branch, and
237
+ * `__tests__/username.test.ts` asserts by identity that the other kinds get the
238
+ * base schema back.
239
+ *
240
+ * **Not a rule about remote actors.** The same column holds ~74k federated rows
241
+ * in `handle@domain` form, some of them bots on their own server. This schema
242
+ * rejects every one of them and must never be pointed at that path — that
243
+ * namespace belongs to another server.
244
+ *
245
+ * **A WRITE-path rule**, like everything else here. Six bot accounts exist and
246
+ * not one of them is labelled (measured 2026-08-26: `community-guide`,
247
+ * `community-maestro`, `community-pulse`, `garden-helper`, `luna`, `verity`).
248
+ * They go on loading and resolving; only a NEW handle is held to this.
249
+ */
250
+ exports.botUsernameSchema = exports.usernameSchema.refine((username) => username.toLowerCase().endsWith(exports.BOT_USERNAME_SUFFIX), exports.BOT_USERNAME_INVALID_MESSAGE);
251
+ /**
252
+ * The policy that governs a handle, given the kind of account that will hold it.
253
+ *
254
+ * The ONE place the exception branches. A call site that writes
255
+ * `kind === 'bot' ? … : …` for itself is the eighth copy of the rule arriving by
256
+ * the usual route, so every write path — account creation, account rename, the
257
+ * profile update — asks this instead.
258
+ *
259
+ * An unknown kind is the BASE policy, never the stricter one: `users.kind`
260
+ * defaults to `personal`, rows predate the column being filled in, and a rename
261
+ * refused because the server could not tell what it was reading is a 400 nobody
262
+ * can act on.
263
+ */
264
+ function usernameSchemaForAccountKind(kind) {
265
+ return kind === 'bot' ? exports.botUsernameSchema : exports.usernameSchema;
266
+ }
267
+ /**
268
+ * Label a proposed bot handle, so a generator PROPOSES something the server will
269
+ * accept.
270
+ *
271
+ * Alia builds an agent's handle from its display name; without this it would
272
+ * propose `garden-helper` for a bot and be 400ed on submit, which is the same
273
+ * "suggest, then refuse" defect the minimum length already caused once.
274
+ *
275
+ * It appends and never inserts: a separator is the caller's choice, so
276
+ * `garden-helper` becomes `garden-helperbot` while a caller who typed
277
+ * `garden-helper-` gets `garden-helper-bot`. It truncates to leave room rather
278
+ * than overflowing {@link USERNAME_MAX_LENGTH}.
279
+ *
280
+ * Like {@link stripDisallowedUsernameCharacters} it is an aid, not a decision: it
281
+ * cannot repair a handle the base policy refuses, and the result still has to
282
+ * pass {@link botUsernameSchema}.
283
+ */
284
+ function applyBotUsernameSuffix(candidate) {
285
+ const trimmed = candidate.trim();
286
+ if (trimmed.toLowerCase().endsWith(exports.BOT_USERNAME_SUFFIX)) {
287
+ return trimmed;
288
+ }
289
+ return trimmed.slice(0, exports.USERNAME_MAX_LENGTH - exports.BOT_USERNAME_SUFFIX.length) + exports.BOT_USERNAME_SUFFIX;
290
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * WebAuthn / passkey ceremony contracts (Fase B/b1).
4
+ *
5
+ * These schemas describe ONLY the outer Oxy envelope that wraps a WebAuthn
6
+ * ceremony request — the username the client is registering/authenticating as,
7
+ * plus the device-session options every first-party sign-in accepts. The browser
8
+ * `RegistrationResponseJSON` / `AuthenticationResponseJSON` payloads are NOT
9
+ * mirrored here: they are validated by `@simplewebauthn/server` inside the route
10
+ * (`verifyRegistrationResponse` / `verifyAuthenticationResponse`), which is the
11
+ * single source of truth for their structure. Re-encoding them in Zod would just
12
+ * create a second, drift-prone definition of a shape we do not own.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.webauthnLoginVerifyRequestSchema = exports.webauthnRegisterVerifyRequestSchema = exports.webauthnLoginOptionsRequestSchema = exports.webauthnRegisterOptionsRequestSchema = void 0;
16
+ const zod_1 = require("zod");
17
+ /**
18
+ * Device-session options shared by every first-party sign-in body
19
+ * (`deviceName`/`deviceFingerprint`). Mirrors what
20
+ * `sessionCreateOptionsFromBody` reads in the API so a WebAuthn login/verify can
21
+ * name its resulting session exactly like `/auth/login` or `/auth/verify`.
22
+ *
23
+ * There is deliberately no `deviceId` here. `createSession` treats an explicit
24
+ * device id as authoritative — `deviceId > stableDeviceKey > UA/IP > random` —
25
+ * and stamps it verbatim, so on an UNAUTHENTICATED sign-in body it is a caller
26
+ * naming somebody else's device and having a session, and then a device secret,
27
+ * minted against it. The legitimate callers that pin a device id are
28
+ * server-side and already authorized (the account-switch route threading the
29
+ * operator's own central device id); they pass it to `createSession` directly
30
+ * and never through a request body.
31
+ */
32
+ const deviceSessionEnvelope = {
33
+ deviceName: zod_1.z.string().trim().min(1).max(120).optional(),
34
+ deviceFingerprint: zod_1.z.string().trim().min(1).max(256).optional(),
35
+ };
36
+ /**
37
+ * `POST /webauthn/register/options` — request registration options. With a bearer
38
+ * token the caller links a passkey to their signed-in account and `username` is
39
+ * ignored; without one it is a prospective signup and `username` is the desired
40
+ * (not-yet-created) handle.
41
+ */
42
+ exports.webauthnRegisterOptionsRequestSchema = zod_1.z.object({
43
+ username: zod_1.z.string().trim().min(1).max(60).optional(),
44
+ });
45
+ /**
46
+ * `POST /webauthn/login/options` — request authentication options. When
47
+ * `username` is present the server scopes `allowCredentials` to that user's
48
+ * passkeys (username-first); when omitted it returns an empty allow-list for the
49
+ * usernameless / discoverable-credential flow (the default).
50
+ */
51
+ exports.webauthnLoginOptionsRequestSchema = zod_1.z.object({
52
+ username: zod_1.z.string().trim().min(1).max(60).optional(),
53
+ });
54
+ /**
55
+ * `POST /webauthn/register/verify` — the outer envelope. The browser
56
+ * `RegistrationResponseJSON` travels alongside these fields under `response` and
57
+ * is validated by `@simplewebauthn/server`, not here. `username` is required only
58
+ * for the prospective-signup branch (no bearer); the linking branch ignores it.
59
+ */
60
+ exports.webauthnRegisterVerifyRequestSchema = zod_1.z.object({
61
+ username: zod_1.z.string().trim().min(1).max(60).optional(),
62
+ ...deviceSessionEnvelope,
63
+ });
64
+ /**
65
+ * `POST /webauthn/login/verify` — the outer envelope. The browser
66
+ * `AuthenticationResponseJSON` travels alongside these fields under `response`
67
+ * and is validated by `@simplewebauthn/server`, not here.
68
+ */
69
+ exports.webauthnLoginVerifyRequestSchema = zod_1.z.object({
70
+ ...deviceSessionEnvelope,
71
+ });