@oxy.so/contracts 4.16.0 → 4.21.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 (135) hide show
  1. package/dist/cjs/accountAccess.js +72 -0
  2. package/dist/cjs/accountEmail.js +12 -34
  3. package/dist/cjs/accountGraph.js +22 -320
  4. package/dist/cjs/agency.js +112 -1
  5. package/dist/cjs/agentKeys.js +11 -13
  6. package/dist/cjs/applicationRoles.js +211 -0
  7. package/dist/cjs/client/accountEmail.js +48 -0
  8. package/dist/cjs/client/accountGraph.js +323 -0
  9. package/dist/cjs/client/agentKeys.js +77 -0
  10. package/dist/cjs/client/check.js +475 -0
  11. package/dist/cjs/client/deviceBoot.js +22 -0
  12. package/dist/cjs/client/deviceDirectory.js +51 -0
  13. package/dist/cjs/client/deviceSession.js +63 -0
  14. package/dist/cjs/client/externalIdentity.js +19 -0
  15. package/dist/cjs/client/identity.js +45 -0
  16. package/dist/cjs/client/identityLink.js +55 -0
  17. package/dist/cjs/client/identityProof.js +109 -0
  18. package/dist/cjs/client/index.js +211 -0
  19. package/dist/cjs/client/organizations.js +114 -0
  20. package/dist/cjs/client/products.js +153 -0
  21. package/dist/cjs/client/recommendations.js +33 -0
  22. package/dist/cjs/client/reputation.js +41 -0
  23. package/dist/cjs/client/safety.js +196 -0
  24. package/dist/cjs/client/sessionStatus.js +23 -0
  25. package/dist/cjs/client/signIn.js +159 -0
  26. package/dist/cjs/client/userResponse.js +15 -0
  27. package/dist/cjs/client/username.js +173 -0
  28. package/dist/cjs/deviceSession.js +3 -16
  29. package/dist/cjs/identityLink.js +13 -34
  30. package/dist/cjs/identityProof.js +18 -106
  31. package/dist/cjs/index.js +13 -3
  32. package/dist/cjs/organizations.js +21 -41
  33. package/dist/cjs/reputation.js +3 -34
  34. package/dist/cjs/safety.js +430 -1
  35. package/dist/cjs/serviceToken.js +14 -0
  36. package/dist/cjs/signIn.js +33 -111
  37. package/dist/cjs/username.js +23 -158
  38. package/dist/esm/accountAccess.js +69 -0
  39. package/dist/esm/accountEmail.js +4 -32
  40. package/dist/esm/accountGraph.js +4 -309
  41. package/dist/esm/agency.js +111 -0
  42. package/dist/esm/agentKeys.js +4 -10
  43. package/dist/esm/applicationRoles.js +207 -0
  44. package/dist/esm/client/accountEmail.js +45 -0
  45. package/dist/esm/client/accountGraph.js +314 -0
  46. package/dist/esm/client/agentKeys.js +74 -0
  47. package/dist/esm/client/check.js +436 -0
  48. package/dist/esm/client/deviceBoot.js +19 -0
  49. package/dist/esm/client/deviceDirectory.js +48 -0
  50. package/dist/esm/client/deviceSession.js +60 -0
  51. package/dist/esm/client/externalIdentity.js +16 -0
  52. package/dist/esm/client/identity.js +42 -0
  53. package/dist/esm/client/identityLink.js +50 -0
  54. package/dist/esm/client/identityProof.js +104 -0
  55. package/dist/esm/client/index.js +37 -0
  56. package/dist/esm/client/organizations.js +111 -0
  57. package/dist/esm/client/products.js +150 -0
  58. package/dist/esm/client/recommendations.js +30 -0
  59. package/dist/esm/client/reputation.js +37 -0
  60. package/dist/esm/client/safety.js +193 -0
  61. package/dist/esm/client/sessionStatus.js +20 -0
  62. package/dist/esm/client/signIn.js +153 -0
  63. package/dist/esm/client/userResponse.js +12 -0
  64. package/dist/esm/client/username.js +167 -0
  65. package/dist/esm/deviceSession.js +1 -15
  66. package/dist/esm/identityLink.js +4 -27
  67. package/dist/esm/identityProof.js +4 -99
  68. package/dist/esm/index.js +4 -1
  69. package/dist/esm/organizations.js +4 -31
  70. package/dist/esm/reputation.js +1 -32
  71. package/dist/esm/safety.js +423 -0
  72. package/dist/esm/serviceToken.js +11 -0
  73. package/dist/esm/signIn.js +4 -96
  74. package/dist/esm/username.js +4 -148
  75. package/dist/types/accountAccess.d.ts +128 -0
  76. package/dist/types/accountEmail.d.ts +4 -36
  77. package/dist/types/accountGraph.d.ts +12 -208
  78. package/dist/types/agency.d.ts +351 -26
  79. package/dist/types/agentKeys.d.ts +14 -12
  80. package/dist/types/applicationRoles.d.ts +438 -0
  81. package/dist/types/client/accountEmail.d.ts +44 -0
  82. package/dist/types/client/accountGraph.d.ts +203 -0
  83. package/dist/types/client/agentKeys.d.ts +113 -0
  84. package/dist/types/client/check.d.ts +187 -0
  85. package/dist/types/client/deviceBoot.d.ts +6 -0
  86. package/dist/types/client/deviceDirectory.d.ts +134 -0
  87. package/dist/types/client/deviceSession.d.ts +91 -0
  88. package/dist/types/client/externalIdentity.d.ts +14 -0
  89. package/dist/types/client/identity.d.ts +8 -0
  90. package/dist/types/client/identityLink.d.ts +21 -0
  91. package/dist/types/client/identityProof.d.ts +73 -0
  92. package/dist/types/client/index.d.ts +37 -0
  93. package/dist/types/client/organizations.d.ts +167 -0
  94. package/dist/types/client/products.d.ts +145 -0
  95. package/dist/types/client/recommendations.d.ts +27 -0
  96. package/dist/types/client/reputation.d.ts +28 -0
  97. package/dist/types/client/safety.d.ts +213 -0
  98. package/dist/types/client/sessionStatus.d.ts +19 -0
  99. package/dist/types/client/signIn.d.ts +107 -0
  100. package/dist/types/client/userResponse.d.ts +7 -0
  101. package/dist/types/client/username.d.ts +126 -0
  102. package/dist/types/deviceDirectory.d.ts +28 -28
  103. package/dist/types/deviceSession.d.ts +5 -16
  104. package/dist/types/email/messages.d.ts +2 -2
  105. package/dist/types/externalIdentity.d.ts +15 -15
  106. package/dist/types/identityLink.d.ts +3 -11
  107. package/dist/types/identityProof.d.ts +2 -65
  108. package/dist/types/index.d.ts +5 -2
  109. package/dist/types/inference/accountBilling.d.ts +2 -2
  110. package/dist/types/inference/catalogue.d.ts +22 -22
  111. package/dist/types/inference/decisions.d.ts +10 -10
  112. package/dist/types/inference/embeddings.d.ts +16 -16
  113. package/dist/types/inference/errors.d.ts +8 -8
  114. package/dist/types/inference/inbox.d.ts +8 -8
  115. package/dist/types/inference/privateAutoExecution.d.ts +6 -6
  116. package/dist/types/inference/providerConnection.d.ts +4 -4
  117. package/dist/types/inference/realtime.d.ts +92 -92
  118. package/dist/types/inference/request.d.ts +48 -48
  119. package/dist/types/inference/streamEvents.d.ts +16 -16
  120. package/dist/types/inference/usage.d.ts +4 -4
  121. package/dist/types/oauth.d.ts +2 -2
  122. package/dist/types/organizations.d.ts +8 -10
  123. package/dist/types/products/access.d.ts +4 -4
  124. package/dist/types/products/billing.d.ts +3 -0
  125. package/dist/types/reputation.d.ts +1 -11
  126. package/dist/types/safety.d.ts +2374 -2
  127. package/dist/types/serviceToken.d.ts +11 -0
  128. package/dist/types/sessionStatus.d.ts +2 -2
  129. package/dist/types/signIn.d.ts +11 -94
  130. package/dist/types/userResponse.d.ts +22 -22
  131. package/dist/types/username.d.ts +1 -96
  132. package/package.json +24 -20
  133. package/dist/cjs/.tsbuildinfo +0 -1
  134. package/dist/esm/.tsbuildinfo +0 -1
  135. package/dist/types/.tsbuildinfo +0 -1
@@ -0,0 +1,323 @@
1
+ "use strict";
2
+ /**
3
+ * Account kinds and categories, without Zod. Schemas: `../accountGraph.ts`.
4
+ *
5
+ * Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ACCOUNT_CATEGORY_KINDS = exports.MAX_ACCOUNT_CATEGORIES = exports.SELECTABLE_ACCOUNT_CATEGORY_IDS = exports.RETIRED_ACCOUNT_CATEGORY_IDS = exports.ACCOUNT_CATEGORY_IDS = exports.CHILD_ACCOUNT_KINDS = exports.ACCOUNT_KINDS = void 0;
9
+ exports.isDelegatedActAsEligibleKind = isDelegatedActAsEligibleKind;
10
+ exports.isOperatorSwitchTargetKind = isOperatorSwitchTargetKind;
11
+ exports.isAccountKind = isAccountKind;
12
+ exports.isSelectableAccountCategoryId = isSelectableAccountCategoryId;
13
+ exports.newlyAddedRetiredCategories = newlyAddedRetiredCategories;
14
+ exports.kindAcceptsAccountCategories = kindAcceptsAccountCategories;
15
+ /**
16
+ * The union is spelled out above and the array proves coverage BOTH ways
17
+ * (`satisfies` here, the `Gap` alias below) — the same shape this package's
18
+ * `ACCOUNT_CATEGORY_IDS` / `TRUST_TIERS` pairs use, and the one
19
+ * `db/schema/users.ts` mirrors to keep the `users_kind_check` CHECK honest.
20
+ *
21
+ * Deriving the union from the array instead would cost nothing here and be paid
22
+ * by consumers: `kind` travels into `@oxy.so/services` on every device-directory
23
+ * context (`deviceContextSchema.kind` → `DeviceContext` → the switcher rows),
24
+ * and an indexed-access type is materially more expensive to check there than a
25
+ * literal union.
26
+ */
27
+ exports.ACCOUNT_KINDS = [
28
+ 'personal',
29
+ 'organization',
30
+ 'project',
31
+ 'bot',
32
+ 'channel',
33
+ ];
34
+ exports.CHILD_ACCOUNT_KINDS = [
35
+ 'organization',
36
+ 'project',
37
+ 'bot',
38
+ 'channel',
39
+ ];
40
+ /**
41
+ * Whether an account of this kind may be the SUBJECT OF A DELEGATION — an
42
+ * application acting as it on some person's authority. `POST /internal/accounts/
43
+ * :id/service-switch` and the OAuth delegated subject both gate on this.
44
+ *
45
+ * It is NOT the question an account switcher asks. See
46
+ * {@link isOperatorSwitchTargetKind}, and the note below on why the difference
47
+ * is `bot`.
48
+ *
49
+ * Two kinds are refused, for opposite reasons:
50
+ *
51
+ * - `personal` is a human login, so assuming it would be impersonation.
52
+ * - `channel` is a CONTENT identity, not an operating one. A channel exists so
53
+ * that posts can be authored BY it; it is never a seat anybody occupies. Its
54
+ * operators act on it through their own membership, and an application
55
+ * publishes to it with its own credential. Refusing act-as is what makes
56
+ * "no login, ever" structural rather than incidental: no session can be
57
+ * minted whose subject is a channel, so no bearer exists that could add an
58
+ * auth method to one (every auth-method write resolves its target from the
59
+ * authenticated subject, never from a parameter).
60
+ *
61
+ * Consumers must gate on this predicate rather than testing `kind === 'personal'`,
62
+ * which silently admits every kind added after it was written.
63
+ *
64
+ * Being act-as-eligible is NOT being without an identity of one's own. A bot is
65
+ * act-as-eligible AND its own actor (`accountKindActorNature` → `'agent'` in
66
+ * `accountSubject.ts`): an application acting as it on a person's authority
67
+ * records that person as the actor, and the bot acting with nobody operating it
68
+ * records the bot. Neither ever records the bot's owner in the bot's place.
69
+ */
70
+ function isDelegatedActAsEligibleKind(kind) {
71
+ return kind === 'organization' || kind === 'project' || kind === 'bot';
72
+ }
73
+ /**
74
+ * Whether a PERSON may switch into an account of this kind — become it, in an
75
+ * account switcher, for the rest of their session.
76
+ *
77
+ * ## Why this is not the same question as {@link isDelegatedActAsEligibleKind}
78
+ *
79
+ * The two differ on exactly one kind, `bot`, and that difference is the whole
80
+ * reason both exist.
81
+ *
82
+ * **A bot is not something you become. It is somebody of its own.** It is an
83
+ * agent's identity, with its own resources, roles, plan and balance, and it is
84
+ * the actor of what it does unoperated. A person may still act AS it on their
85
+ * own authority — that is delegation, recorded with the person as actor, and it
86
+ * is what {@link isDelegatedActAsEligibleKind} admits it for. What a person
87
+ * never does is occupy its seat. This is a refusal of a SEAT, not a capability
88
+ * restriction: nothing a bot may do depends on this predicate.
89
+ *
90
+ * Handing a person the bot's seat instead inverts that. It puts a human inside
91
+ * the identity that exists to act without one, and it does so on the human's own
92
+ * device, next to their personal login — which is precisely what happened: a
93
+ * `bot` account held a live session on a person's device, offered to them by a
94
+ * switcher that had asked the delegation question by mistake.
95
+ *
96
+ * `channel` is refused here as well, for the reason set out above, and
97
+ * `personal` because assuming somebody else's login is impersonation.
98
+ *
99
+ * ## This is the narrower predicate, deliberately
100
+ *
101
+ * Everything a person may become, a service may also act as; the reverse does
102
+ * not hold. A caller that is unsure which question it is asking wants THIS one:
103
+ * being wrong here withholds an affordance, while being wrong the other way
104
+ * hands out a seat.
105
+ */
106
+ function isOperatorSwitchTargetKind(kind) {
107
+ return kind === 'organization' || kind === 'project';
108
+ }
109
+ /**
110
+ * Narrow an unknown value to an {@link AccountKind}.
111
+ *
112
+ * The user-DTO serializers read from structurally-permissive `unknown` sources
113
+ * (a Drizzle row, a raw document, an already-formatted object), so each one
114
+ * would otherwise hand-roll this check and they would drift on what counts.
115
+ */
116
+ function isAccountKind(value) {
117
+ return typeof value === 'string' && exports.ACCOUNT_KINDS.includes(value);
118
+ }
119
+ // ===========================================================================
120
+ // Account categories
121
+ //
122
+ // Four rules govern this taxonomy. Each one is here because the obvious
123
+ // alternative fails silently rather than loudly.
124
+ //
125
+ // 1. AN ID IS AN OPAQUE, IMMUTABLE SLUG — the LABEL is not stored anywhere.
126
+ // Every value below is an identifier that no rename may ever change. The
127
+ // human-readable label lives in each client's own translation catalogue,
128
+ // keyed by the id. Re-labelling `agency` from "Real estate agency" to
129
+ // "Agency" is therefore a one-line locale edit that touches no row; moving
130
+ // the label into the column or the DTO would make the same edit a data
131
+ // migration, and would pin every reader to the language of whoever chose it.
132
+ //
133
+ // 2. THE PRIMARY CATEGORY IS THE FIRST ELEMENT of an ordered list. Not a
134
+ // separate flag, and not a second field: a flag admits two primaries and
135
+ // admits none, and ordering makes both unrepresentable. The cost is that
136
+ // ORDER IS DATA — anything that re-serializes, sorts or de-duplicates this
137
+ // list can change which category is primary without erroring, so no layer
138
+ // between the column and the client may reorder it.
139
+ //
140
+ // 3. THE VOCABULARY IS APPEND-ONLY. `ACCOUNT_CATEGORY_IDS` may gain ids and may
141
+ // never lose one, because rows already carry the ids it holds. Withdrawing a
142
+ // category means listing it in {@link RETIRED_ACCOUNT_CATEGORY_IDS}, which
143
+ // removes it from the picker while leaving it readable and re-writable. The
144
+ // database enforces the same asymmetry: its CHECK is re-evaluated on EVERY
145
+ // update to a row, so narrowing the allowed set makes an unrelated write —
146
+ // saving a bio — fail on any account that had picked the withdrawn value.
147
+ // Measured on a real Postgres, `NOT VALID` included; it does not help.
148
+ //
149
+ // 4. THE SET IS CLOSED. An id nobody can validate is an id no client can render:
150
+ // the label comes from a translation key derived from the id, so an invented
151
+ // value paints as a blank or a raw slug in every app at once. Closing it also
152
+ // costs nothing that rule 3 does not already charge — adding a category needs
153
+ // a migration to widen the CHECK whether or not the enum exists, so an open
154
+ // list would buy back no work, only the validation.
155
+ // ===========================================================================
156
+ /**
157
+ * Every account category, by stable id.
158
+ *
159
+ * Grouped by comment for readability only; the storage, the wire and the picker
160
+ * all treat this as one flat list. `other` is the escape hatch for an account
161
+ * that fits nothing here.
162
+ *
163
+ * TO ADD ONE: append an id (lowercase ASCII, `snake_case`) here, publish
164
+ * `@oxy.so/contracts`, then ship a migration that widens
165
+ * `users_account_categories_check` — never edit an existing migration — and add
166
+ * an `accounts.accountCategory.<id>` label to each client's locales.
167
+ *
168
+ * TO WITHDRAW ONE: leave the id here and add it to
169
+ * {@link RETIRED_ACCOUNT_CATEGORY_IDS}. See rule 3 above.
170
+ */
171
+ exports.ACCOUNT_CATEGORY_IDS = [
172
+ // ---- media & public information -----------------------------------------
173
+ 'news',
174
+ 'politics',
175
+ // ---- business & economy --------------------------------------------------
176
+ 'business',
177
+ 'startup',
178
+ 'finance',
179
+ 'crypto',
180
+ 'marketplace',
181
+ 'retail',
182
+ // The four ids the single-valued `organizationCategory` field used to hold,
183
+ // carried forward VERBATIM. Their labels may be rewritten freely; their ids
184
+ // may not, because live rows hold them.
185
+ 'real_estate',
186
+ 'agency',
187
+ 'landlord',
188
+ 'cooperative',
189
+ 'architecture',
190
+ // ---- technology ----------------------------------------------------------
191
+ 'technology',
192
+ 'software',
193
+ 'ai',
194
+ 'security',
195
+ 'automation',
196
+ // ---- knowledge -----------------------------------------------------------
197
+ 'science',
198
+ 'education',
199
+ 'books',
200
+ // ---- health --------------------------------------------------------------
201
+ 'health',
202
+ 'fitness',
203
+ // ---- sport & play --------------------------------------------------------
204
+ 'sports',
205
+ 'gaming',
206
+ // ---- culture & entertainment ---------------------------------------------
207
+ //
208
+ // There is deliberately NO generic `entertainment` here, and re-adding one is
209
+ // a regression rather than a gap. It is the only id this list ever carried
210
+ // that was dominated by its own specifics — `film`, `music`, `gaming` and
211
+ // `comedy` all exist — and a generic drawer sitting beside its four
212
+ // concretions collects the lazy pick, which degrades the data for all four at
213
+ // once: the accounts that would have said `film` say `entertainment` instead,
214
+ // and `film` stops meaning what it meant.
215
+ //
216
+ // The other overlaps in this vocabulary are NOT the same case and must not be
217
+ // merged on this reasoning: `sports`/`fitness`, `art`/`photography`,
218
+ // `business`/`startup`, `finance`/`crypto`, `home_garden`/`diy` and
219
+ // `technology`/`software`/`security` are genuinely different audiences, and
220
+ // with a cap of four the granularity is cheap.
221
+ 'music',
222
+ 'film',
223
+ 'podcast',
224
+ 'art',
225
+ 'photography',
226
+ 'comedy',
227
+ // ---- everyday life -------------------------------------------------------
228
+ 'food',
229
+ 'travel',
230
+ 'fashion',
231
+ 'home_garden',
232
+ 'diy',
233
+ 'automotive',
234
+ 'animals',
235
+ 'family',
236
+ // ---- society -------------------------------------------------------------
237
+ 'nonprofit',
238
+ 'government',
239
+ 'community',
240
+ 'activism',
241
+ 'environment',
242
+ 'religion',
243
+ // ---- fallback ------------------------------------------------------------
244
+ 'other',
245
+ ];
246
+ /**
247
+ * Ids withdrawn from the picker. Empty today.
248
+ *
249
+ * A withdrawn id keeps working everywhere it is already stored: it validates,
250
+ * it survives a round-trip save, it still renders from its label key, and it
251
+ * stays PRIMARY if it was primary. Nothing rewrites a stored list — a read-time
252
+ * or migration-time demotion would silently replace a choice its owner made,
253
+ * which is precisely what stable ids exist to prevent. The owner drops it on
254
+ * their next edit; until then it is honoured.
255
+ *
256
+ * What withdrawal changes is only this: the id leaves
257
+ * {@link SELECTABLE_ACCOUNT_CATEGORY_IDS}, so no picker offers it, and
258
+ * {@link newlyAddedRetiredCategories} refuses to let a write ADD it to an
259
+ * account that did not already have it.
260
+ */
261
+ exports.RETIRED_ACCOUNT_CATEGORY_IDS = [];
262
+ /** Whether a category may still be OFFERED. A stored one is readable either way. */
263
+ function isSelectableAccountCategoryId(id) {
264
+ return !exports.RETIRED_ACCOUNT_CATEGORY_IDS.includes(id);
265
+ }
266
+ /** The ids a picker may offer, in declaration order. */
267
+ exports.SELECTABLE_ACCOUNT_CATEGORY_IDS = exports.ACCOUNT_CATEGORY_IDS.filter(isSelectableAccountCategoryId);
268
+ /**
269
+ * Which of `next` are withdrawn ids the account did not already carry — i.e.
270
+ * the ones a write must be refused for.
271
+ *
272
+ * `retired` is a parameter rather than a module read so the rule can be
273
+ * exercised against a non-empty set while the production one is empty; a test
274
+ * over `RETIRED_ACCOUNT_CATEGORY_IDS` alone would pass vacuously today and stay
275
+ * passing if the rule were deleted.
276
+ */
277
+ function newlyAddedRetiredCategories(next, previous, retired) {
278
+ return next.filter((id) => retired.includes(id) && !previous.includes(id));
279
+ }
280
+ /**
281
+ * How many categories one account may carry.
282
+ *
283
+ * Four, not "as many as you like". Three reasons, in the order they bind:
284
+ *
285
+ * - The primary has to MEAN something. At ten categories the first element
286
+ * reads as a sort artifact rather than a choice, and rule 2 above is the
287
+ * entire mechanism by which a primary exists.
288
+ * - The profile RENDERS them as a row of chips; four labels of this length is
289
+ * what fits a phone-width profile header before the row wraps or truncates.
290
+ * - Four is enough to place a genuinely compound account without a tag cloud:
291
+ * a housing cooperative that is also a non-profit serving a local community
292
+ * spends `cooperative`, `nonprofit`, `community`, `real_estate` — and is the
293
+ * most compound real example in the ecosystem.
294
+ *
295
+ * One constant, read by the wire schema, the database CHECK and the picker, so
296
+ * changing it is one edit plus a migration.
297
+ */
298
+ exports.MAX_ACCOUNT_CATEGORIES = 4;
299
+ /**
300
+ * Kinds that may carry categories: every kind EXCEPT `personal`.
301
+ *
302
+ * A person has interests, not a sector — and their interests are not a
303
+ * classification anybody else gets to read off their profile. Spelled out
304
+ * positively, like {@link isDelegatedActAsEligibleKind} and for the same reason: a `kind
305
+ * !== 'personal'` test silently admits every kind invented after it was
306
+ * written, whereas this list forces whoever adds one to decide.
307
+ */
308
+ exports.ACCOUNT_CATEGORY_KINDS = [
309
+ 'organization',
310
+ 'project',
311
+ 'bot',
312
+ 'channel',
313
+ ];
314
+ /**
315
+ * Whether an account of this kind may carry categories.
316
+ *
317
+ * The API refuses the write and the `users_account_categories_kind_check`
318
+ * constraint makes it unrepresentable; both derive from
319
+ * {@link ACCOUNT_CATEGORY_KINDS}, so they cannot disagree.
320
+ */
321
+ function kindAcceptsAccountCategories(kind) {
322
+ return exports.ACCOUNT_CATEGORY_KINDS.includes(kind ?? '');
323
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * Agent-key constants and checks, without Zod. Schemas: `../agentKeys.ts`.
4
+ *
5
+ * Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.agentKeyListResponseCheck = exports.agentKeyOperationResultCheck = exports.agentKeyOperationChallengeCheck = exports.executeAgentKeyOperationCheck = exports.agentKeyOperationCheck = exports.agentVerifyRequestCheck = exports.agentChallengeRequestCheck = exports.agentProofClaimsCheck = exports.ACCOUNT_AUTH_METHODS = exports.AGENT_PROOF_ACTIONS = exports.AGENT_PROOF_TTL_MS = exports.AGENT_PROOF_AUDIENCE = void 0;
9
+ const check_1 = require("./check");
10
+ const signIn_1 = require("./signIn");
11
+ exports.AGENT_PROOF_AUDIENCE = 'oxy-api/agent';
12
+ exports.AGENT_PROOF_TTL_MS = 60000;
13
+ exports.AGENT_PROOF_ACTIONS = [
14
+ 'agent_signin',
15
+ 'agent_enroll',
16
+ 'agent_rotate',
17
+ 'agent_recover',
18
+ 'agent_governance',
19
+ ];
20
+ exports.ACCOUNT_AUTH_METHODS = ['identity', 'agent_key'];
21
+ /* -------------------------------------------------------------------------- */
22
+ /* Checks */
23
+ /* -------------------------------------------------------------------------- */
24
+ const hex64 = (0, check_1.string)((0, check_1.pattern)(/^[0-9a-f]{64}$/));
25
+ const hexSignature = (0, check_1.string)((0, check_1.pattern)(/^[0-9a-f]+$/i), (0, check_1.maxLength)(160));
26
+ const timestamp = (0, check_1.number)(check_1.int, check_1.positive);
27
+ const publicKey = (0, check_1.string)(check_1.trim, (0, check_1.minLength)(1), (0, check_1.maxLength)(130));
28
+ const label = (0, check_1.string)(check_1.trim, (0, check_1.minLength)(1), (0, check_1.maxLength)(120));
29
+ exports.agentProofClaimsCheck = (0, check_1.exact)()((0, check_1.strictObject)({
30
+ version: (0, check_1.literal)(1),
31
+ audience: (0, check_1.literal)(exports.AGENT_PROOF_AUDIENCE),
32
+ action: (0, check_1.oneOf)(exports.AGENT_PROOF_ACTIONS),
33
+ accountId: (0, check_1.string)((0, check_1.minLength)(1)),
34
+ actorId: (0, check_1.string)((0, check_1.minLength)(1)),
35
+ authMethodId: (0, check_1.nullable)((0, check_1.string)()),
36
+ publicKey: (0, check_1.string)((0, check_1.minLength)(1)),
37
+ payloadDigest: hex64,
38
+ challenge: hex64,
39
+ expiresAt: (0, check_1.number)(check_1.int, check_1.positive),
40
+ }));
41
+ exports.agentChallengeRequestCheck = (0, check_1.exact)()((0, check_1.strictObject)({ publicKey }));
42
+ exports.agentVerifyRequestCheck = (0, check_1.exact)()((0, check_1.strictObject)({ challenge: hex64, signature: hexSignature, timestamp, publicKey }));
43
+ exports.agentKeyOperationCheck = (0, check_1.exact)()((0, check_1.discriminatedUnion)('operation', {
44
+ enroll: (0, check_1.strictObject)({ operation: (0, check_1.literal)('enroll'), publicKey, label }),
45
+ recover: (0, check_1.strictObject)({ operation: (0, check_1.literal)('recover'), publicKey, label }),
46
+ rotate: (0, check_1.strictObject)({
47
+ operation: (0, check_1.literal)('rotate'),
48
+ publicKey,
49
+ label,
50
+ retireCurrent: (0, check_1.optional)(check_1.boolean),
51
+ }),
52
+ revoke: (0, check_1.strictObject)({ operation: (0, check_1.literal)('revoke'), methodId: (0, check_1.string)((0, check_1.minLength)(1)) }),
53
+ }));
54
+ exports.executeAgentKeyOperationCheck = (0, check_1.exact)()((0, check_1.strictObject)({
55
+ operation: exports.agentKeyOperationCheck,
56
+ proof: (0, check_1.strictObject)({
57
+ challenge: hex64,
58
+ timestamp,
59
+ keySignature: (0, check_1.optional)(hexSignature),
60
+ governorSignature: (0, check_1.optional)(hexSignature),
61
+ reauth: (0, check_1.optional)(signIn_1.reauthProofCheck),
62
+ }),
63
+ }));
64
+ exports.agentKeyOperationChallengeCheck = (0, check_1.exact)()((0, check_1.strictObject)({ claims: exports.agentProofClaimsCheck, governorPublicKey: (0, check_1.nullable)((0, check_1.string)()) }));
65
+ exports.agentKeyOperationResultCheck = (0, check_1.exact)()((0, check_1.strictObject)({ methodId: (0, check_1.nullable)((0, check_1.string)()), revokedMethodIds: (0, check_1.array)((0, check_1.string)()) }));
66
+ exports.agentKeyListResponseCheck = (0, check_1.exact)()((0, check_1.strictObject)({
67
+ keys: (0, check_1.array)((0, check_1.strictObject)({
68
+ id: (0, check_1.string)(),
69
+ publicKey: (0, check_1.string)(),
70
+ label: (0, check_1.string)(),
71
+ enrolledByUserId: (0, check_1.nullable)((0, check_1.string)()),
72
+ enrollmentMethod: (0, check_1.oneOf)(['governor', 'rotation', 'recovery']),
73
+ linkedAt: (0, check_1.string)(check_1.datetime),
74
+ lastUsedAt: (0, check_1.nullable)((0, check_1.string)(check_1.datetime)),
75
+ revokedAt: (0, check_1.nullable)((0, check_1.string)(check_1.datetime)),
76
+ })),
77
+ }));