@oxyhq/contracts 0.18.0 → 0.20.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.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Canonical contract for the "Sign in with Oxy" approval handoff.
3
+ *
4
+ * SINGLE SOURCE OF TRUTH for the closed set of reasons an approver may attach
5
+ * when it DENIES a pending request via
6
+ * `POST /auth/session/deny/:authorizeCode`.
7
+ *
8
+ * That endpoint is UNAUTHENTICATED — the public `authorizeCode` is the only
9
+ * credential — so a free-form string from it is never stored: it would be an
10
+ * unauthenticated write of arbitrary text onto a record other surfaces read.
11
+ * The set is therefore deliberately tiny, and closed:
12
+ *
13
+ * - `'declined'` the approver rejected a request they recognised ("Not now").
14
+ * - `'not_me'` the approver did not start the request ("This wasn't me").
15
+ * The ONE value that records the denial as suspicious rather
16
+ * than an ordinary cancel, so a UI may only offer it where the
17
+ * user genuinely said so.
18
+ *
19
+ * Why this lives in `@oxyhq/contracts` rather than in either consumer: the same
20
+ * closed set is enforced in three places — the request schema of the API route,
21
+ * the `enum` of the persisted `AuthSession.deniedReason` field, and the client
22
+ * SDK's `denyCommonsSignIn` parameter. Two hand-maintained copies of a wire
23
+ * contract drift the moment a value is added on one side only, and the failure
24
+ * lands at runtime, in an auth path, as a generic validation error. One
25
+ * declaration makes that impossible.
26
+ *
27
+ * Platform-agnostic — zod only, no react/react-native/expo. ESM-safe (no
28
+ * `require()`).
29
+ */
30
+ import { z } from 'zod';
31
+ /**
32
+ * The closed set, as a value — consumed directly where a runtime list is
33
+ * required (e.g. the Mongoose `enum` of `AuthSession.deniedReason`, which is
34
+ * the storage-level guarantee that an unauthenticated caller can never write
35
+ * free-form text into the field).
36
+ */
37
+ export const COMMONS_DENY_REASONS = ['declined', 'not_me'];
38
+ /**
39
+ * The same set as a zod enum — the edge validator. Anything outside it
40
+ * (including free-form text) is rejected with 400 before any handler runs.
41
+ */
42
+ export const commonsDenyReasonSchema = z.enum(COMMONS_DENY_REASONS);
43
+ /**
44
+ * Android notification channel id the identity-approval push is sent on.
45
+ *
46
+ * A wire contract for the same reason the deny set is: Android 8+ DROPS a
47
+ * notification whose channel id the app has not created, silently and with no
48
+ * client-side error. The API attaches this id when it sends, and the vault
49
+ * creates the channel with it before registering a push token — two hand-typed
50
+ * copies of that string would fail as "the notification never arrived", which
51
+ * is the single hardest push symptom to diagnose.
52
+ *
53
+ * The channel's user-visible NAME and description are deliberately NOT here:
54
+ * those are localized app copy, and the vault owns them.
55
+ */
56
+ export const IDENTITY_APPROVAL_PUSH_CHANNEL = 'auth-approval';
@@ -57,28 +57,6 @@ export const deviceTokenMintResponseSchema = z.object({
57
57
  state: deviceSessionStateSchema,
58
58
  });
59
59
  /* -------------------------------------------------------------------------- */
60
- /* Hub ticket — server-side cross-origin device credential sync */
61
- /* -------------------------------------------------------------------------- */
62
- /** Request body for `POST /session/device/hub-ticket`. */
63
- export const deviceHubTicketIssueRequestSchema = z.object({
64
- returnOrigin: z.string().min(1),
65
- });
66
- /** Response from `POST /session/device/hub-ticket`. */
67
- export const deviceHubTicketIssueResponseSchema = z.object({
68
- ticket: z.string().min(1),
69
- expiresIn: z.number().int().positive(),
70
- });
71
- /** Request body for `POST /session/device/redeem-ticket`. */
72
- export const deviceHubTicketRedeemRequestSchema = z.object({
73
- ticket: z.string().min(1),
74
- returnOrigin: z.string().min(1),
75
- });
76
- /** Response from `POST /session/device/redeem-ticket`. */
77
- export const deviceHubTicketRedeemResponseSchema = z.object({
78
- deviceId: z.string().min(1),
79
- deviceSecret: z.string().min(1),
80
- });
81
- /* -------------------------------------------------------------------------- */
82
60
  /* Instant cross-app session sync (token-free socket signal) */
83
61
  /* -------------------------------------------------------------------------- */
84
62
  /**
@@ -119,3 +97,64 @@ export const sessionAccountsChangedEventSchema = z.object({
119
97
  revision: z.number().int().nonnegative(),
120
98
  reason: sessionAccountsChangedReasonSchema,
121
99
  });
100
+ /* -------------------------------------------------------------------------- */
101
+ /* Background credential — native background code with no JS runtime */
102
+ /* -------------------------------------------------------------------------- */
103
+ /**
104
+ * Response from `POST /session/device/background-credential` — provisioned by
105
+ * the SDK WHILE THE APP IS RUNNING (bearer required, `deviceId` and account
106
+ * derived server-side from it) and consumed afterwards only by native
107
+ * background code, which has no JS runtime to mint a token for itself.
108
+ *
109
+ * Deliberately a SEPARATE credential from the rotating `deviceSecret`: that one
110
+ * rotates on every mint, so background code presenting it would become a second
111
+ * writer of a value the JS runtime depends on, and background code killed
112
+ * mid-rotation would silently sign the user out on the next cold start. Against
113
+ * this credential background code is the sole writer, and it can never rotate
114
+ * anything JS reads.
115
+ *
116
+ * The raw `secret` is returned exactly once, at provision time — never stored
117
+ * retrievably, never logged, never re-read. A caller that loses it provisions
118
+ * a new one.
119
+ *
120
+ * `expiresAt` is an unvalidated string, like every other expiry in this file:
121
+ * no consumer on the JS path interprets it (native background code parses it
122
+ * itself), and a `.datetime()` here alone would leave one strict field beside
123
+ * two lax ones. If expiry is ever validated it goes on all three at once, with
124
+ * the API's serializers checked against it — the producer is the same server.
125
+ */
126
+ export const deviceBackgroundCredentialResponseSchema = z.object({
127
+ deviceId: z.string().min(1),
128
+ secret: z.string().min(1),
129
+ accountId: z.string().min(1),
130
+ expiresAt: z.string(),
131
+ });
132
+ /**
133
+ * Request body for `POST /session/device/background-token` — presented by
134
+ * native background code with NO bearer and NO cookies: possession of the
135
+ * background `secret` IS the proof, as it is for the device-secret mint.
136
+ *
137
+ * Unlike that mint this one NEVER rotates the presented secret (hence no
138
+ * `next…` field to persist in the response), so background code interrupted
139
+ * anywhere between request and response leaves the credential intact and
140
+ * usable on its next run.
141
+ */
142
+ export const deviceBackgroundTokenRequestSchema = z.object({
143
+ deviceId: z.string().min(1),
144
+ secret: z.string().min(1),
145
+ });
146
+ /**
147
+ * Wire shape of a successful `POST /session/device/background-token`: the short
148
+ * access token, its expiry, and the account the token belongs to — the last so
149
+ * a caller can key cached data per account and drop data belonging to a
150
+ * foreign one.
151
+ *
152
+ * Carries NO device state — no account list, no `activeAccountId`, no
153
+ * `revision`, unlike {@link deviceTokenMintResponseSchema} — deliberately, to
154
+ * cap what a compromised credential record yields.
155
+ */
156
+ export const deviceBackgroundTokenResponseSchema = z.object({
157
+ accessToken: z.string(),
158
+ expiresAt: z.string(),
159
+ accountId: z.string().min(1),
160
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Canonical contract for Inbox new-mail push notifications.
3
+ *
4
+ * The Android channel id and payload `type` are wire contracts: Android 8+
5
+ * drops a notification whose channel the app has not created, and the client
6
+ * only routes taps it recognises. Two hand-typed copies of either string fail as
7
+ * "the notification never arrived" or "tapping does nothing" — the hardest push
8
+ * symptoms to diagnose.
9
+ *
10
+ * Platform-agnostic — zod only, no react/react-native/expo.
11
+ */
12
+ import { z } from 'zod';
13
+ /** Android notification channel id the new-mail push is sent on. */
14
+ export const INBOX_EMAIL_PUSH_CHANNEL = 'email';
15
+ /** Runtime type discriminator of the new-mail push payload. */
16
+ export const INBOX_EMAIL_PUSH_TYPE = 'oxy_inbox_new_message';
17
+ export const inboxEmailPushDataSchema = z.object({
18
+ type: z.literal(INBOX_EMAIL_PUSH_TYPE),
19
+ messageId: z.string().min(1),
20
+ mailboxId: z.string().min(1),
21
+ });
package/dist/esm/index.js CHANGED
@@ -19,6 +19,12 @@ export {
19
19
  // Schemas
20
20
  applicationTypeSchema, publicApplicationSchema, sessionStatusSchema, } from './sessionStatus.js';
21
21
  export {
22
+ // Closed set of denial reasons for POST /auth/session/deny/:authorizeCode —
23
+ // shared by the API request schema, the persisted `AuthSession.deniedReason`
24
+ // enum, and the SDK's `denyCommonsSignIn`.
25
+ COMMONS_DENY_REASONS, commonsDenyReasonSchema, IDENTITY_APPROVAL_PUSH_CHANNEL, } from './commonsSignIn.js';
26
+ export { INBOX_EMAIL_PUSH_CHANNEL, INBOX_EMAIL_PUSH_TYPE, inboxEmailPushDataSchema, } from './inboxPush.js';
27
+ export {
22
28
  // Schemas
23
29
  recommendationExcludeTypeSchema, recommendationBoostSchema, recommendationSignalWeightsSchema, recommendationRequestSchema, recommendationCountSchema, recommendationItemSchema, recommendationResponseSchema, appEndorsementInputSchema, appInterestInputSchema, appUserSignalIngestSchema, appAffinityEventTypeSchema, appAffinityEventSchema, appAffinityEventsIngestSchema, } from './recommendations.js';
24
30
  export {
@@ -36,9 +42,22 @@ publicCardSchema, signedPublicCardSchema, realLifeAttestationRecordSchema, realL
36
42
  // Verifiable Credentials (Fase 4 — NEW)
37
43
  credentialRecordSchema, verifiableCredentialResponseSchema, credentialIssueResultSchema, credentialListResultSchema, credentialVerifyResultSchema, } from './civic.js';
38
44
  export {
45
+ // Closed value sets — shared by the API's mongoose enums, the API's request
46
+ // validation, and the SDK's unions, so a new category/tier/status cannot be
47
+ // added on one side only.
48
+ REPUTATION_CATEGORIES, REPUTATION_TRANSACTION_STATUSES, TRUST_TIERS, REPUTATION_TARGET_ENTITY_TYPES, REPUTATION_DISPUTE_STATUSES, REPUTATION_INFLUENCE_CONTEXTS,
49
+ // Schemas — closed value sets
50
+ reputationCategorySchema, reputationTransactionStatusSchema, trustTierSchema, reputationTargetEntityTypeSchema, reputationDisputeStatusSchema, reputationInfluenceContextSchema,
51
+ // Schemas — responses
52
+ reputationTransactionSchema, reputationBalanceBreakdownSchema, reputationInfluenceSchema, reputationReliabilitySchema, reputationBalanceSummarySchema, reputationBalanceSchema, reputationDisputeSchema, reputationRuleSchema, reputationLeaderboardUserSchema, reputationLeaderboardEntrySchema, reputationInfluenceResultSchema, reverseReputationTransactionResultSchema,
53
+ // Schemas — request bodies
54
+ awardReputationSchema, createReputationDisputeSchema, resolveReputationDisputeSchema, upsertReputationRuleSchema, reverseReputationTransactionSchema,
55
+ // Narrows the two balance views apart at runtime.
56
+ isFullReputationBalance, } from './reputation.js';
57
+ export {
39
58
  // Schemas
40
59
  linkPreviewSchema, linkPreviewBatchRequestSchema, linkPreviewBatchResponseSchema, linkPreviewResponseSchema, } from './links.js';
41
- export { sessionAccountSchema, deviceSessionStateSchema, activeTokenSchema, deviceSessionSyncSchema, deviceTokenMintRequestSchema, deviceTokenMintResponseSchema, deviceHubTicketIssueRequestSchema, deviceHubTicketIssueResponseSchema, deviceHubTicketRedeemRequestSchema, deviceHubTicketRedeemResponseSchema, SESSION_ACCOUNTS_CHANGED_EVENT, sessionAccountsChangedReasonSchema, sessionAccountsChangedEventSchema, } from './deviceSession.js';
60
+ export { sessionAccountSchema, deviceSessionStateSchema, activeTokenSchema, deviceSessionSyncSchema, deviceTokenMintRequestSchema, deviceTokenMintResponseSchema, deviceBackgroundCredentialResponseSchema, deviceBackgroundTokenRequestSchema, deviceBackgroundTokenResponseSchema, SESSION_ACCOUNTS_CHANGED_EVENT, sessionAccountsChangedReasonSchema, sessionAccountsChangedEventSchema, } from './deviceSession.js';
42
61
  export {
43
62
  // Schemas
44
63
  loginResultSchema, } from './deviceBoot.js';
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Oxy Trust — reputation API contracts.
3
+ *
4
+ * SINGLE SOURCE OF TRUTH for the reputation ledger's wire shapes: the closed
5
+ * value sets (`REPUTATION_CATEGORIES`, `TRUST_TIERS`, …), the response entities
6
+ * (`ReputationTransaction`, the two balance views, `ReputationDispute`,
7
+ * `ReputationRule`, the leaderboard entry) and the request bodies the write
8
+ * endpoints accept. The API validates its OUTPUT against these schemas and its
9
+ * INPUT with the same request schemas the SDK's input types are derived from;
10
+ * `@oxyhq/core`'s reputation mixin imports every type from here rather than
11
+ * declaring its own.
12
+ *
13
+ * Why this module exists: the balance endpoint was view-split server-side
14
+ * without the SDK type moving with it, and for hours the SDK affirmatively
15
+ * type-checked a read of `balance.reliability.reportAccuracyScore` against a
16
+ * response that no longer carried `reliability`. Nothing structural connected
17
+ * the API's hand-written serializers (which returned `Record<string, unknown>`)
18
+ * to the SDK's interfaces — only human attention. With the serializers
19
+ * annotated against these definitions, that divergence is a build failure.
20
+ *
21
+ * Design anchors:
22
+ * - **Ids are strings, timestamps are ISO 8601 strings.** The server holds
23
+ * `ObjectId`s and `Date`s; every serializer converts at the boundary, so a
24
+ * `Date` leaking into a field this module types as `string` fails to compile.
25
+ * - **The balance has two views, and the union is the contract.** See
26
+ * {@link ReputationBalanceView} — the compile-time assertions below are what
27
+ * stop the private view's fields becoming reachable on a stranger's balance.
28
+ * - **The closed value sets live here, not beside the mongoose models.** The
29
+ * API's model enums and the SDK's unions are the same `as const` tuple, so a
30
+ * seventh category cannot be added on one side only.
31
+ *
32
+ * The response entities are declared as explicit `interface`s with their runtime
33
+ * schemas annotated `z.ZodType<Interface>`, following `./links` and
34
+ * `./userResponse`: a `z.infer<>` of a nested-object schema can degrade to `{}`
35
+ * under a consumer's `moduleResolution: "node"` (node10) resolution, while a
36
+ * literal interface emits the field types verbatim in the `.d.ts` and survives
37
+ * both `node` and `bundler`.
38
+ *
39
+ * Platform-agnostic — zod only, no react/react-native/expo. ESM-safe (no
40
+ * `require()`).
41
+ */
42
+ import { z } from 'zod';
43
+ import { userNameSchema } from './userResponse.js';
44
+ /* -------------------------------------------------------------------------- */
45
+ /* Closed value sets */
46
+ /* -------------------------------------------------------------------------- */
47
+ /**
48
+ * Category bucket a reputation transaction falls into. Drives the per-category
49
+ * balance breakdown; every rule and transaction carries exactly one.
50
+ *
51
+ * - `content` — posts, comments, media a user authored.
52
+ * - `social` — follows, likes, social interactions.
53
+ * - `trust` — identity / verification / trust-graph signals.
54
+ * - `moderation` — reports filed, moderation actions, review outcomes.
55
+ * - `physical` — real-world signals (event check-ins, verified purchases).
56
+ * - `penalty` — negative adjustments for abuse / policy violations.
57
+ * - `other` — anything that does not fit the buckets above.
58
+ */
59
+ export const REPUTATION_CATEGORIES = [
60
+ 'content',
61
+ 'social',
62
+ 'trust',
63
+ 'moderation',
64
+ 'physical',
65
+ 'penalty',
66
+ 'other',
67
+ ];
68
+ export const reputationCategorySchema = z.enum(REPUTATION_CATEGORIES);
69
+ /**
70
+ * Transaction lifecycle status.
71
+ *
72
+ * - `active` — counts toward the balance.
73
+ * - `disputed` — under dispute; still counts until the dispute resolves.
74
+ * - `reversed` — superseded by a compensating reversal transaction; excluded.
75
+ * - `voided` — administratively excluded with no compensating entry.
76
+ */
77
+ export const REPUTATION_TRANSACTION_STATUSES = [
78
+ 'active',
79
+ 'disputed',
80
+ 'reversed',
81
+ 'voided',
82
+ ];
83
+ export const reputationTransactionStatusSchema = z.enum(REPUTATION_TRANSACTION_STATUSES);
84
+ /**
85
+ * Trust tiers, lowest → highest trust, plus the punitive `restricted`.
86
+ *
87
+ * Publicly visible: this is the contribution ladder the reputation system
88
+ * exists to publish. Note it doubles as the sanction marker — a `restricted`
89
+ * account is publicly identifiable as such.
90
+ */
91
+ export const TRUST_TIERS = ['restricted', 'new', 'trusted', 'high_trust', 'verified'];
92
+ export const trustTierSchema = z.enum(TRUST_TIERS);
93
+ /** Kind of entity a transaction may target. */
94
+ export const REPUTATION_TARGET_ENTITY_TYPES = [
95
+ 'post',
96
+ 'comment',
97
+ 'report',
98
+ 'purchase',
99
+ 'event',
100
+ 'check_in',
101
+ 'manual_review',
102
+ 'user',
103
+ 'other',
104
+ ];
105
+ export const reputationTargetEntityTypeSchema = z.enum(REPUTATION_TARGET_ENTITY_TYPES);
106
+ /** Dispute lifecycle status. */
107
+ export const REPUTATION_DISPUTE_STATUSES = [
108
+ 'open',
109
+ 'accepted',
110
+ 'rejected',
111
+ 'needs_review',
112
+ ];
113
+ export const reputationDisputeStatusSchema = z.enum(REPUTATION_DISPUTE_STATUSES);
114
+ /** Influence context selecting which capped weight axis to read. */
115
+ export const REPUTATION_INFLUENCE_CONTEXTS = [
116
+ 'default',
117
+ 'report',
118
+ 'moderation',
119
+ 'ranking',
120
+ ];
121
+ export const reputationInfluenceContextSchema = z.enum(REPUTATION_INFLUENCE_CONTEXTS);
122
+ export const reputationTransactionSchema = z.object({
123
+ id: z.string(),
124
+ userId: z.string(),
125
+ points: z.number(),
126
+ actionType: z.string(),
127
+ category: reputationCategorySchema,
128
+ applicationId: z.string().optional(),
129
+ credentialId: z.string().optional(),
130
+ sourceActionId: z.string().optional(),
131
+ sourceActionType: z.string().optional(),
132
+ targetEntityId: z.string().optional(),
133
+ targetEntityType: reputationTargetEntityTypeSchema.optional(),
134
+ status: reputationTransactionStatusSchema,
135
+ reversedTransactionId: z.string().optional(),
136
+ reason: z.string().optional(),
137
+ metadata: z.record(z.unknown()).optional(),
138
+ createdByUserId: z.string().optional(),
139
+ reviewedByUserId: z.string().optional(),
140
+ reviewedAt: z.string().optional(),
141
+ createdAt: z.string(),
142
+ updatedAt: z.string(),
143
+ });
144
+ export const reputationBalanceBreakdownSchema = z.object({
145
+ content: z.number(),
146
+ social: z.number(),
147
+ trust: z.number(),
148
+ moderation: z.number(),
149
+ physical: z.number(),
150
+ penalties: z.number(),
151
+ });
152
+ export const reputationInfluenceSchema = z.object({
153
+ defaultWeight: z.number(),
154
+ reportWeight: z.number(),
155
+ moderationWeight: z.number(),
156
+ rankingFeedbackWeight: z.number(),
157
+ });
158
+ export const reputationReliabilitySchema = z.object({
159
+ accurateReports: z.number(),
160
+ rejectedReports: z.number(),
161
+ reportAccuracyScore: z.number(),
162
+ abuseScore: z.number(),
163
+ });
164
+ /** The fields both balance views share. Kept as a shape so the full view can spread it. */
165
+ const balanceSummaryShape = {
166
+ userId: z.string(),
167
+ total: z.number(),
168
+ trustTier: trustTierSchema,
169
+ };
170
+ export const reputationBalanceSummarySchema = z.object(balanceSummaryShape);
171
+ export const reputationBalanceSchema = z.object({
172
+ ...balanceSummaryShape,
173
+ positive: z.number(),
174
+ negative: z.number(),
175
+ breakdown: reputationBalanceBreakdownSchema,
176
+ influence: reputationInfluenceSchema,
177
+ reliability: reputationReliabilitySchema,
178
+ recalculatedAt: z.string(),
179
+ updatedAt: z.string(),
180
+ });
181
+ /**
182
+ * Every field the full {@link ReputationBalance} carries beyond the public
183
+ * {@link ReputationBalanceSummary}. The runtime discriminant between the two
184
+ * views — the API sends this set all-or-nothing.
185
+ */
186
+ const FULL_BALANCE_FIELDS = [
187
+ 'positive',
188
+ 'negative',
189
+ 'breakdown',
190
+ 'influence',
191
+ 'reliability',
192
+ 'recalculatedAt',
193
+ 'updatedAt',
194
+ ];
195
+ /**
196
+ * Whether a balance came back as the SUBJECT view, and so carries the
197
+ * breakdown / influence / reliability blocks.
198
+ *
199
+ * Checks every extra field rather than one representative: the point of the
200
+ * guard is that the caller then dereferences those blocks, so a partial payload
201
+ * must not narrow.
202
+ *
203
+ * @param balance - A balance from `getReputationBalance`.
204
+ */
205
+ export function isFullReputationBalance(balance) {
206
+ return FULL_BALANCE_FIELDS.every((field) => field in balance);
207
+ }
208
+ export const reputationDisputeSchema = z.object({
209
+ id: z.string(),
210
+ transactionId: z.string(),
211
+ userId: z.string(),
212
+ reason: z.string(),
213
+ status: reputationDisputeStatusSchema,
214
+ evidence: z.array(z.string()).optional(),
215
+ resolvedAt: z.string().optional(),
216
+ resolvedByUserId: z.string().optional(),
217
+ createdAt: z.string(),
218
+ updatedAt: z.string(),
219
+ });
220
+ export const reputationRuleSchema = z.object({
221
+ id: z.string(),
222
+ actionType: z.string(),
223
+ points: z.number(),
224
+ category: reputationCategorySchema,
225
+ description: z.string(),
226
+ cooldownInMinutes: z.number(),
227
+ isEnabled: z.boolean(),
228
+ });
229
+ export const reputationLeaderboardUserSchema = z.object({
230
+ id: z.string(),
231
+ username: z.string(),
232
+ name: userNameSchema,
233
+ avatar: z.string().optional(),
234
+ publicKey: z.string().optional(),
235
+ });
236
+ export const reputationLeaderboardEntrySchema = z.object({
237
+ user: reputationLeaderboardUserSchema,
238
+ total: z.number(),
239
+ trustTier: trustTierSchema,
240
+ rank: z.number(),
241
+ });
242
+ export const reputationInfluenceResultSchema = z.object({
243
+ context: reputationInfluenceContextSchema,
244
+ weight: z.number(),
245
+ influence: reputationInfluenceSchema,
246
+ });
247
+ export const reverseReputationTransactionResultSchema = z.object({
248
+ original: reputationTransactionSchema,
249
+ reversal: reputationTransactionSchema,
250
+ });
251
+ export const awardReputationSchema = z.object({
252
+ userId: z.string().trim().min(1),
253
+ actionType: z.string().trim().min(1),
254
+ applicationId: z.string().trim().min(1).optional(),
255
+ credentialId: z.string().trim().min(1).optional(),
256
+ sourceActionId: z.string().trim().min(1).optional(),
257
+ sourceActionType: z.string().trim().min(1).optional(),
258
+ targetEntityId: z.string().trim().min(1).optional(),
259
+ targetEntityType: reputationTargetEntityTypeSchema.optional(),
260
+ reason: z.string().trim().max(500).optional(),
261
+ metadata: z.record(z.unknown()).optional(),
262
+ });
263
+ export const createReputationDisputeSchema = z.object({
264
+ transactionId: z.string().trim().min(1),
265
+ reason: z.string().trim().min(1).max(1000),
266
+ evidence: z.array(z.string().trim().min(1)).max(20).optional(),
267
+ });
268
+ export const resolveReputationDisputeSchema = z.object({
269
+ status: z.enum(['accepted', 'rejected']),
270
+ });
271
+ export const upsertReputationRuleSchema = z.object({
272
+ actionType: z.string().trim().min(1),
273
+ points: z.number(),
274
+ category: reputationCategorySchema,
275
+ description: z.string().trim().min(1).max(500),
276
+ cooldownInMinutes: z.number().int().min(0).default(0),
277
+ isEnabled: z.boolean().default(true),
278
+ });
279
+ export const reverseReputationTransactionSchema = z.object({
280
+ reason: z.string().trim().max(500).optional(),
281
+ });