@oxyhq/core 3.1.0 → 3.4.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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/AuthManager.js +14 -3
- package/dist/cjs/HttpService.js +89 -0
- package/dist/cjs/OxyServices.js +2 -1
- package/dist/cjs/constants/version.js +1 -1
- package/dist/cjs/i18n/locales/en-US.json +44 -44
- package/dist/cjs/i18n/locales/es-ES.json +44 -44
- package/dist/cjs/i18n/locales/locales/en-US.json +44 -44
- package/dist/cjs/i18n/locales/locales/es-ES.json +44 -44
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/mixins/OxyServices.applications.js +33 -3
- package/dist/cjs/mixins/OxyServices.reputation.js +244 -0
- package/dist/cjs/mixins/OxyServices.workspaces.js +146 -0
- package/dist/cjs/mixins/index.js +4 -2
- package/dist/cjs/utils/accountUtils.js +12 -5
- package/dist/cjs/utils/ssoReturn.js +80 -33
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/AuthManager.js +14 -3
- package/dist/esm/HttpService.js +89 -0
- package/dist/esm/OxyServices.js +2 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/i18n/locales/en-US.json +44 -44
- package/dist/esm/i18n/locales/es-ES.json +44 -44
- package/dist/esm/i18n/locales/locales/en-US.json +44 -44
- package/dist/esm/i18n/locales/locales/es-ES.json +44 -44
- package/dist/esm/index.js +4 -0
- package/dist/esm/mixins/OxyServices.applications.js +33 -3
- package/dist/esm/mixins/OxyServices.reputation.js +241 -0
- package/dist/esm/mixins/OxyServices.workspaces.js +143 -0
- package/dist/esm/mixins/index.js +4 -2
- package/dist/esm/utils/accountUtils.js +12 -5
- package/dist/esm/utils/ssoReturn.js +80 -33
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +57 -0
- package/dist/types/OxyServices.d.ts +2 -1
- package/dist/types/constants/version.d.ts +2 -2
- package/dist/types/index.d.ts +4 -2
- package/dist/types/mixins/OxyServices.applications.d.ts +86 -10
- package/dist/types/mixins/OxyServices.features.d.ts +0 -1
- package/dist/types/mixins/OxyServices.reputation.d.ts +436 -0
- package/dist/types/mixins/OxyServices.workspaces.d.ts +205 -0
- package/dist/types/mixins/index.d.ts +3 -2
- package/dist/types/models/interfaces.d.ts +24 -26
- package/dist/types/utils/accountUtils.d.ts +17 -4
- package/dist/types/utils/ssoReturn.d.ts +30 -9
- package/package.json +2 -1
- package/src/AuthManager.ts +14 -3
- package/src/HttpService.ts +91 -0
- package/src/OxyServices.ts +2 -1
- package/src/__tests__/authManager.cookiePath.test.ts +49 -0
- package/src/__tests__/httpServiceCache.test.ts +198 -0
- package/src/constants/version.ts +1 -1
- package/src/i18n/locales/en-US.json +44 -44
- package/src/i18n/locales/es-ES.json +44 -44
- package/src/index.ts +51 -4
- package/src/mixins/OxyServices.applications.ts +103 -5
- package/src/mixins/OxyServices.auth.ts +2 -1
- package/src/mixins/OxyServices.features.ts +0 -1
- package/src/mixins/OxyServices.reputation.ts +674 -0
- package/src/mixins/OxyServices.workspaces.ts +315 -0
- package/src/mixins/__tests__/reputation.test.ts +408 -0
- package/src/mixins/index.ts +6 -3
- package/src/models/interfaces.ts +25 -32
- package/src/utils/__tests__/accountUtils.test.ts +142 -0
- package/src/utils/__tests__/consumeSsoReturn.test.ts +229 -37
- package/src/utils/accountUtils.ts +20 -5
- package/src/utils/ssoReturn.ts +98 -37
- package/dist/cjs/mixins/OxyServices.developer.js +0 -97
- package/dist/cjs/mixins/OxyServices.karma.js +0 -108
- package/dist/esm/mixins/OxyServices.developer.js +0 -94
- package/dist/esm/mixins/OxyServices.karma.js +0 -105
- package/dist/types/mixins/OxyServices.developer.d.ts +0 -106
- package/dist/types/mixins/OxyServices.karma.d.ts +0 -92
- package/src/mixins/OxyServices.karma.ts +0 -111
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reputation Methods Mixin (Oxy Trust)
|
|
3
|
+
*
|
|
4
|
+
* Provides typed access to the reputation ledger (#217) and the derived
|
|
5
|
+
* trust-tier / capped-influence model (#219) via the `/reputation` API.
|
|
6
|
+
*
|
|
7
|
+
* The reputation ledger is append-only: transactions are NEVER deleted.
|
|
8
|
+
* A correction is expressed either as a compensating REVERSAL (the original is
|
|
9
|
+
* marked `reversed` and a new `active` transaction with negated points is
|
|
10
|
+
* appended) or a VOID (the original is marked `voided` and excluded from the
|
|
11
|
+
* balance). A user's `ReputationBalance` is a recomputable cache of the sum of
|
|
12
|
+
* their `active` transactions, augmented with a trust tier, capped influence
|
|
13
|
+
* weights, and reliability signals.
|
|
14
|
+
*
|
|
15
|
+
* Reference users by their Mongo `_id` (or publicKey, which the API resolves),
|
|
16
|
+
* transactions by their `id`, and disputes by their `id`.
|
|
17
|
+
*/
|
|
18
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
19
|
+
import type { User } from '../models/interfaces';
|
|
20
|
+
/**
|
|
21
|
+
* Category bucket a reputation transaction falls into. Drives the per-category
|
|
22
|
+
* balance breakdown.
|
|
23
|
+
*/
|
|
24
|
+
export type ReputationCategory = 'content' | 'social' | 'trust' | 'moderation' | 'physical' | 'penalty' | 'other';
|
|
25
|
+
/** Trust tiers, lowest → highest (plus the punitive `restricted`). */
|
|
26
|
+
export type TrustTier = 'new' | 'trusted' | 'high_trust' | 'verified' | 'restricted';
|
|
27
|
+
/**
|
|
28
|
+
* Transaction lifecycle status. Only `active` transactions count toward the
|
|
29
|
+
* balance; `disputed` still counts until the dispute resolves; `reversed` and
|
|
30
|
+
* `voided` are excluded.
|
|
31
|
+
*/
|
|
32
|
+
export type ReputationTransactionStatus = 'active' | 'disputed' | 'reversed' | 'voided';
|
|
33
|
+
/** Kind of entity a transaction may target. */
|
|
34
|
+
export type ReputationTargetEntityType = 'post' | 'comment' | 'report' | 'purchase' | 'event' | 'check_in' | 'manual_review' | 'user' | 'other';
|
|
35
|
+
/** Dispute lifecycle status. */
|
|
36
|
+
export type ReputationDisputeStatus = 'open' | 'accepted' | 'rejected' | 'needs_review';
|
|
37
|
+
/** Influence context selecting which capped weight axis to return. */
|
|
38
|
+
export type ReputationInfluenceContext = 'default' | 'report' | 'moderation' | 'ranking';
|
|
39
|
+
/**
|
|
40
|
+
* A single immutable entry in the reputation ledger. Ids are emitted as strings
|
|
41
|
+
* and dates as ISO strings by the API.
|
|
42
|
+
*/
|
|
43
|
+
export interface ReputationTransaction {
|
|
44
|
+
/** The transaction's Mongo `_id` as a string. */
|
|
45
|
+
id: string;
|
|
46
|
+
/** Subject of the reputation change — the user whose balance moves. */
|
|
47
|
+
userId: string;
|
|
48
|
+
/** Signed point delta. Positive awards, negative penalties/reversals. */
|
|
49
|
+
points: number;
|
|
50
|
+
/** The rule/action key that produced this transaction (e.g. `post_created`). */
|
|
51
|
+
actionType: string;
|
|
52
|
+
/** Category bucket the points fall into. */
|
|
53
|
+
category: ReputationCategory;
|
|
54
|
+
/** Canonical source application that reported the action, if any. */
|
|
55
|
+
applicationId?: string;
|
|
56
|
+
/** The specific credential used by the source application, if any. */
|
|
57
|
+
credentialId?: string;
|
|
58
|
+
/** Opaque id of the originating action in the source system (idempotency key). */
|
|
59
|
+
sourceActionId?: string;
|
|
60
|
+
/** Source-system action type (e.g. `report_confirmed`, `event_check_in`). */
|
|
61
|
+
sourceActionType?: string;
|
|
62
|
+
/** Id of the entity the action targeted (post id, report id, etc.). */
|
|
63
|
+
targetEntityId?: string;
|
|
64
|
+
/** Kind of the targeted entity. */
|
|
65
|
+
targetEntityType?: ReputationTargetEntityType;
|
|
66
|
+
/** Lifecycle status — only `active` transactions count toward the balance. */
|
|
67
|
+
status: ReputationTransactionStatus;
|
|
68
|
+
/**
|
|
69
|
+
* Set ONLY on a compensating reversal transaction; references the original
|
|
70
|
+
* transaction it reverses. The original carries `status: 'reversed'`.
|
|
71
|
+
*/
|
|
72
|
+
reversedTransactionId?: string;
|
|
73
|
+
/** Human-readable reason / note. */
|
|
74
|
+
reason?: string;
|
|
75
|
+
/** Free-form structured metadata from the source system. */
|
|
76
|
+
metadata?: Record<string, unknown>;
|
|
77
|
+
/** The user who caused this change (the liker, the reporting user, staff). */
|
|
78
|
+
createdByUserId?: string;
|
|
79
|
+
/** Staff/service principal who reviewed (reversed/voided) this transaction. */
|
|
80
|
+
reviewedByUserId?: string;
|
|
81
|
+
/** ISO timestamp the transaction was reviewed at, if reviewed. */
|
|
82
|
+
reviewedAt?: string;
|
|
83
|
+
/** ISO creation timestamp. */
|
|
84
|
+
createdAt: string;
|
|
85
|
+
/** ISO last-update timestamp. */
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Per-category sums of a user's ACTIVE transactions. `penalties` is the
|
|
90
|
+
* absolute sum of every negative-point transaction; the named buckets carry the
|
|
91
|
+
* signed sum of transactions in that category.
|
|
92
|
+
*/
|
|
93
|
+
export interface ReputationBalanceBreakdown {
|
|
94
|
+
content: number;
|
|
95
|
+
social: number;
|
|
96
|
+
trust: number;
|
|
97
|
+
moderation: number;
|
|
98
|
+
physical: number;
|
|
99
|
+
penalties: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Capped influence weights (#219). Every weight is clamped to a configured
|
|
103
|
+
* range; restricted users are floored on every axis. Downstream systems
|
|
104
|
+
* (ranking, moderation, reporting) consume these to weight a user's
|
|
105
|
+
* contributions without letting any single user dominate.
|
|
106
|
+
*/
|
|
107
|
+
export interface ReputationInfluence {
|
|
108
|
+
/** General-purpose trust weight derived from the lifetime total. */
|
|
109
|
+
defaultWeight: number;
|
|
110
|
+
/** Weight applied to this user's reports (scales with report accuracy). */
|
|
111
|
+
reportWeight: number;
|
|
112
|
+
/** Weight applied to this user's moderation actions (scales with tier). */
|
|
113
|
+
moderationWeight: number;
|
|
114
|
+
/** Damped weight applied to this user's ranking feedback. */
|
|
115
|
+
rankingFeedbackWeight: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Reliability signals (#219) derived from the user's moderation track record in
|
|
119
|
+
* the ledger.
|
|
120
|
+
*/
|
|
121
|
+
export interface ReputationReliability {
|
|
122
|
+
/** Count of active transactions stamped `report_confirmed`. */
|
|
123
|
+
accurateReports: number;
|
|
124
|
+
/** Count of active transactions stamped `report_rejected`. */
|
|
125
|
+
rejectedReports: number;
|
|
126
|
+
/** accurate / (accurate + rejected), or the neutral 0.5 when no history. */
|
|
127
|
+
reportAccuracyScore: number;
|
|
128
|
+
/** Smoothed 0..1 abuse signal; high values force the `restricted` tier. */
|
|
129
|
+
abuseScore: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Cached, recomputable snapshot of a user's reputation. Shape mirrors the
|
|
133
|
+
* `/reputation/:userId/balance` response (which omits internal `lastTransactionId`
|
|
134
|
+
* and `createdAt`).
|
|
135
|
+
*/
|
|
136
|
+
export interface ReputationBalance {
|
|
137
|
+
userId: string;
|
|
138
|
+
/** Net lifetime total across all active transactions. */
|
|
139
|
+
total: number;
|
|
140
|
+
/** Sum of positive points only. */
|
|
141
|
+
positive: number;
|
|
142
|
+
/** Sum of negative points only (a negative number). */
|
|
143
|
+
negative: number;
|
|
144
|
+
breakdown: ReputationBalanceBreakdown;
|
|
145
|
+
trustTier: TrustTier;
|
|
146
|
+
influence: ReputationInfluence;
|
|
147
|
+
reliability: ReputationReliability;
|
|
148
|
+
/** ISO timestamp the snapshot was last recomputed at. */
|
|
149
|
+
recalculatedAt: string;
|
|
150
|
+
/** ISO last-update timestamp. */
|
|
151
|
+
updatedAt: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A user-initiated dispute against a specific reputation transaction. Ids are
|
|
155
|
+
* strings and dates ISO strings.
|
|
156
|
+
*/
|
|
157
|
+
export interface ReputationDispute {
|
|
158
|
+
/** The dispute's Mongo `_id` as a string. */
|
|
159
|
+
id: string;
|
|
160
|
+
/** The transaction being disputed. */
|
|
161
|
+
transactionId: string;
|
|
162
|
+
/** The user raising the dispute. */
|
|
163
|
+
userId: string;
|
|
164
|
+
/** Why the user believes the transaction is wrong. */
|
|
165
|
+
reason: string;
|
|
166
|
+
status: ReputationDisputeStatus;
|
|
167
|
+
/** Optional supporting evidence (URLs / references). */
|
|
168
|
+
evidence?: string[];
|
|
169
|
+
/** ISO timestamp the dispute was resolved at, if resolved. */
|
|
170
|
+
resolvedAt?: string;
|
|
171
|
+
/** Staff principal who resolved the dispute, if resolved. */
|
|
172
|
+
resolvedByUserId?: string;
|
|
173
|
+
/** ISO creation timestamp. */
|
|
174
|
+
createdAt: string;
|
|
175
|
+
/** ISO last-update timestamp. */
|
|
176
|
+
updatedAt: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A configurable reputation award/penalty rule. The `/reputation/rules`
|
|
180
|
+
* response shape: `id` is the rule's `_id`; no timestamps are emitted.
|
|
181
|
+
*/
|
|
182
|
+
export interface ReputationRule {
|
|
183
|
+
/** The rule's Mongo `_id` as a string. */
|
|
184
|
+
id: string;
|
|
185
|
+
/** Unique action key (e.g. `post_created`). */
|
|
186
|
+
actionType: string;
|
|
187
|
+
/** Signed points the rule awards (may be negative for penalties). */
|
|
188
|
+
points: number;
|
|
189
|
+
/** Category the resulting transaction is filed under. */
|
|
190
|
+
category: ReputationCategory;
|
|
191
|
+
description: string;
|
|
192
|
+
/** Per (user, actionType) cooldown in minutes; 0 disables the cooldown. */
|
|
193
|
+
cooldownInMinutes: number;
|
|
194
|
+
isEnabled: boolean;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* A single leaderboard entry. `user` is the populated user document the API
|
|
198
|
+
* returns alongside the lifetime total, derived trust tier, and 1-based rank.
|
|
199
|
+
*/
|
|
200
|
+
export interface ReputationLeaderboardEntry {
|
|
201
|
+
/** The populated user (id, username, name, avatar, publicKey). */
|
|
202
|
+
user: Pick<User, 'id' | 'username' | 'name' | 'avatar' | 'publicKey'> & Partial<User>;
|
|
203
|
+
/** Net lifetime total. */
|
|
204
|
+
total: number;
|
|
205
|
+
/** Derived trust tier. */
|
|
206
|
+
trustTier: TrustTier;
|
|
207
|
+
/** 1-based rank within the leaderboard (`offset + index + 1`). */
|
|
208
|
+
rank: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Result of `getReputationInfluence` — the requested context, the single capped
|
|
212
|
+
* weight for that context, and the full influence block.
|
|
213
|
+
*/
|
|
214
|
+
export interface ReputationInfluenceResult {
|
|
215
|
+
context: ReputationInfluenceContext;
|
|
216
|
+
weight: number;
|
|
217
|
+
influence: ReputationInfluence;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Result of `reverseReputationTransaction` — the now-`reversed` original plus
|
|
221
|
+
* the compensating `active` reversal entry.
|
|
222
|
+
*/
|
|
223
|
+
export interface ReverseReputationTransactionResult {
|
|
224
|
+
original: ReputationTransaction;
|
|
225
|
+
reversal: ReputationTransaction;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Input for `awardReputation`. Awarding is restricted to service tokens (the
|
|
229
|
+
* canonical path) and platform staff; regular users may NOT award reputation.
|
|
230
|
+
* When called with a service token, `applicationId` / `credentialId` are
|
|
231
|
+
* resolved from the token and any client-supplied values are ignored.
|
|
232
|
+
*/
|
|
233
|
+
export interface AwardReputationInput {
|
|
234
|
+
/** The subject whose reputation changes (`_id` or publicKey). */
|
|
235
|
+
userId: string;
|
|
236
|
+
/** The enabled rule's action key (e.g. `post_created`). */
|
|
237
|
+
actionType: string;
|
|
238
|
+
/** Source application id (ignored for service tokens). */
|
|
239
|
+
applicationId?: string;
|
|
240
|
+
/** Source credential id (ignored for service tokens). */
|
|
241
|
+
credentialId?: string;
|
|
242
|
+
/** Opaque originating-action id used as the idempotency key. */
|
|
243
|
+
sourceActionId?: string;
|
|
244
|
+
/** Source-system action type. */
|
|
245
|
+
sourceActionType?: string;
|
|
246
|
+
/** Id of the targeted entity. */
|
|
247
|
+
targetEntityId?: string;
|
|
248
|
+
/** Kind of the targeted entity. */
|
|
249
|
+
targetEntityType?: ReputationTargetEntityType;
|
|
250
|
+
/** Optional human-readable reason (max 500 chars). */
|
|
251
|
+
reason?: string;
|
|
252
|
+
/** Free-form structured metadata from the source system. */
|
|
253
|
+
metadata?: Record<string, unknown>;
|
|
254
|
+
}
|
|
255
|
+
/** Input for `createReputationDispute`. The disputer is the authenticated user. */
|
|
256
|
+
export interface CreateReputationDisputeInput {
|
|
257
|
+
/** The transaction being disputed. */
|
|
258
|
+
transactionId: string;
|
|
259
|
+
/** Why the transaction is believed to be wrong (1..1000 chars). */
|
|
260
|
+
reason: string;
|
|
261
|
+
/** Optional supporting evidence (URLs / references; max 20). */
|
|
262
|
+
evidence?: string[];
|
|
263
|
+
}
|
|
264
|
+
/** Input for `resolveReputationDispute` (staff). */
|
|
265
|
+
export interface ResolveReputationDisputeInput {
|
|
266
|
+
/** Accepting reverses the disputed transaction; rejecting restores it. */
|
|
267
|
+
status: 'accepted' | 'rejected';
|
|
268
|
+
}
|
|
269
|
+
/** Input for `upsertReputationRule` (staff). Keyed by `actionType`. */
|
|
270
|
+
export interface UpsertReputationRuleInput {
|
|
271
|
+
/** Unique action key (e.g. `post_created`). */
|
|
272
|
+
actionType: string;
|
|
273
|
+
/** Signed points the rule awards (may be negative). */
|
|
274
|
+
points: number;
|
|
275
|
+
/** Category the resulting transaction is filed under. */
|
|
276
|
+
category: ReputationCategory;
|
|
277
|
+
/** Human-readable description (1..500 chars). */
|
|
278
|
+
description: string;
|
|
279
|
+
/** Per (user, actionType) cooldown in minutes; defaults to 0. */
|
|
280
|
+
cooldownInMinutes?: number;
|
|
281
|
+
/** Whether the rule is active; defaults to true. */
|
|
282
|
+
isEnabled?: boolean;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Input for `reverseReputationTransaction` / `voidReputationTransaction`
|
|
286
|
+
* (staff). The reviewing principal is the authenticated user.
|
|
287
|
+
*/
|
|
288
|
+
export interface ReverseReputationTransactionInput {
|
|
289
|
+
/** Optional human-readable reason (max 500 chars). */
|
|
290
|
+
reason?: string;
|
|
291
|
+
}
|
|
292
|
+
export declare function OxyServicesReputationMixin<T extends typeof OxyServicesBase>(Base: T): {
|
|
293
|
+
new (...args: any[]): {
|
|
294
|
+
/**
|
|
295
|
+
* Get a user's cached reputation balance — derived totals, per-category
|
|
296
|
+
* breakdown, trust tier, capped influence weights, and reliability signals.
|
|
297
|
+
* @param userId - The subject user's `_id` or publicKey.
|
|
298
|
+
*/
|
|
299
|
+
getReputationBalance(userId: string): Promise<ReputationBalance>;
|
|
300
|
+
/**
|
|
301
|
+
* Get the reputation leaderboard, ordered by lifetime total descending.
|
|
302
|
+
* @param limit - Page size (server-capped).
|
|
303
|
+
* @param offset - Page offset.
|
|
304
|
+
*/
|
|
305
|
+
getReputationLeaderboard(limit?: number, offset?: number): Promise<ReputationLeaderboardEntry[]>;
|
|
306
|
+
/**
|
|
307
|
+
* List the enabled reputation rules (for client display).
|
|
308
|
+
*/
|
|
309
|
+
getReputationRules(): Promise<ReputationRule[]>;
|
|
310
|
+
/**
|
|
311
|
+
* Get a user's paginated reputation ledger, newest first (auth required).
|
|
312
|
+
* @param userId - The subject user's `_id` or publicKey.
|
|
313
|
+
* @param limit - Page size (server-capped).
|
|
314
|
+
* @param offset - Page offset.
|
|
315
|
+
*/
|
|
316
|
+
getReputationTransactions(userId: string, limit?: number, offset?: number): Promise<ReputationTransaction[]>;
|
|
317
|
+
/**
|
|
318
|
+
* Get a user's capped influence weight for a given context (auth required).
|
|
319
|
+
* @param userId - The subject user's `_id` or publicKey.
|
|
320
|
+
* @param context - The weight axis to read (defaults server-side to `default`).
|
|
321
|
+
*/
|
|
322
|
+
getReputationInfluence(userId: string, context?: ReputationInfluenceContext): Promise<ReputationInfluenceResult>;
|
|
323
|
+
/**
|
|
324
|
+
* Award (or penalise) reputation to a user by `actionType`. Restricted to
|
|
325
|
+
* service tokens and platform staff. Invalidates cached reputation reads.
|
|
326
|
+
* @param input - The award payload (subject, action, source, target, etc.).
|
|
327
|
+
*/
|
|
328
|
+
awardReputation(input: AwardReputationInput): Promise<ReputationTransaction>;
|
|
329
|
+
/**
|
|
330
|
+
* Open a dispute against a transaction (auth required; the disputer is the
|
|
331
|
+
* authenticated user and must own the transaction).
|
|
332
|
+
* @param input - The transaction id, reason, and optional evidence.
|
|
333
|
+
*/
|
|
334
|
+
createReputationDispute(input: CreateReputationDisputeInput): Promise<ReputationDispute>;
|
|
335
|
+
/**
|
|
336
|
+
* List a user's own reputation disputes (auth required; the caller must be
|
|
337
|
+
* the subject or platform staff).
|
|
338
|
+
* @param userId - The subject user's `_id` or publicKey.
|
|
339
|
+
* @param limit - Page size (server-capped).
|
|
340
|
+
* @param offset - Page offset.
|
|
341
|
+
*/
|
|
342
|
+
getUserReputationDisputes(userId: string, limit?: number, offset?: number): Promise<ReputationDispute[]>;
|
|
343
|
+
/**
|
|
344
|
+
* Create or update a reputation rule, keyed by `actionType` (staff only).
|
|
345
|
+
* Invalidates the cached rule list.
|
|
346
|
+
* @param input - The rule definition.
|
|
347
|
+
*/
|
|
348
|
+
upsertReputationRule(input: UpsertReputationRuleInput): Promise<ReputationRule>;
|
|
349
|
+
/**
|
|
350
|
+
* Reverse a transaction (staff only): mark the original `reversed` and append
|
|
351
|
+
* a compensating `active` reversal with negated points. Invalidates cached
|
|
352
|
+
* reputation reads.
|
|
353
|
+
* @param transactionId - The transaction's id.
|
|
354
|
+
* @param input - Optional reason for the reversal.
|
|
355
|
+
*/
|
|
356
|
+
reverseReputationTransaction(transactionId: string, input?: ReverseReputationTransactionInput): Promise<ReverseReputationTransactionResult>;
|
|
357
|
+
/**
|
|
358
|
+
* Void a transaction (staff only): mark it `voided` so it is excluded from
|
|
359
|
+
* the balance, with NO compensating entry. Invalidates cached reputation
|
|
360
|
+
* reads.
|
|
361
|
+
* @param transactionId - The transaction's id.
|
|
362
|
+
* @param input - Optional reason for the void.
|
|
363
|
+
*/
|
|
364
|
+
voidReputationTransaction(transactionId: string, input?: ReverseReputationTransactionInput): Promise<ReputationTransaction>;
|
|
365
|
+
/**
|
|
366
|
+
* Force a recompute of a user's balance snapshot from their active ledger
|
|
367
|
+
* (staff only). Invalidates cached reputation reads.
|
|
368
|
+
* @param userId - The subject user's `_id` or publicKey.
|
|
369
|
+
*/
|
|
370
|
+
recalculateReputation(userId: string): Promise<ReputationBalance>;
|
|
371
|
+
/**
|
|
372
|
+
* Get the open dispute queue across all users (staff only).
|
|
373
|
+
* @param limit - Page size (server-capped).
|
|
374
|
+
* @param offset - Page offset.
|
|
375
|
+
*/
|
|
376
|
+
getReputationDisputeQueue(limit?: number, offset?: number): Promise<ReputationDispute[]>;
|
|
377
|
+
/**
|
|
378
|
+
* Resolve a dispute (staff only). Accepting reverses the disputed
|
|
379
|
+
* transaction; rejecting restores it to `active`. Invalidates cached
|
|
380
|
+
* reputation reads.
|
|
381
|
+
* @param disputeId - The dispute's id.
|
|
382
|
+
* @param input - The resolution (`accepted` or `rejected`).
|
|
383
|
+
*/
|
|
384
|
+
resolveReputationDispute(disputeId: string, input: ResolveReputationDisputeInput): Promise<ReputationDispute>;
|
|
385
|
+
httpService: import("../HttpService").HttpService;
|
|
386
|
+
cloudURL: string;
|
|
387
|
+
config: import("../OxyServices.base").OxyConfig;
|
|
388
|
+
__resetTokensForTests(): void;
|
|
389
|
+
makeRequest<T_1>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: any, options?: import("../HttpService").RequestOptions): Promise<T_1>;
|
|
390
|
+
getBaseURL(): string;
|
|
391
|
+
getSessionBaseUrl(): string;
|
|
392
|
+
getClient(): import("../HttpService").HttpService;
|
|
393
|
+
getMetrics(): {
|
|
394
|
+
totalRequests: number;
|
|
395
|
+
successfulRequests: number;
|
|
396
|
+
failedRequests: number;
|
|
397
|
+
cacheHits: number;
|
|
398
|
+
cacheMisses: number;
|
|
399
|
+
averageResponseTime: number;
|
|
400
|
+
};
|
|
401
|
+
clearCache(): void;
|
|
402
|
+
clearCacheEntry(key: string): void;
|
|
403
|
+
clearCacheByPrefix(prefix: string): number;
|
|
404
|
+
getCacheStats(): {
|
|
405
|
+
size: number;
|
|
406
|
+
hits: number;
|
|
407
|
+
misses: number;
|
|
408
|
+
hitRate: number;
|
|
409
|
+
};
|
|
410
|
+
getCloudURL(): string;
|
|
411
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
412
|
+
clearTokens(): void;
|
|
413
|
+
onTokensChanged(listener: (accessToken: string | null) => void): () => void;
|
|
414
|
+
_cachedUserId: string | null | undefined;
|
|
415
|
+
_cachedAccessToken: string | null;
|
|
416
|
+
getCurrentUserId(): string | null;
|
|
417
|
+
hasValidToken(): boolean;
|
|
418
|
+
getAccessToken(): string | null;
|
|
419
|
+
setActingAs(userId: string | null): void;
|
|
420
|
+
getActingAs(): string | null;
|
|
421
|
+
waitForAuth(timeoutMs?: number): Promise<boolean>;
|
|
422
|
+
withAuthRetry<T_1>(operation: () => Promise<T_1>, operationName: string, options?: {
|
|
423
|
+
maxRetries?: number;
|
|
424
|
+
retryDelay?: number;
|
|
425
|
+
authTimeoutMs?: number;
|
|
426
|
+
}): Promise<T_1>;
|
|
427
|
+
validate(): Promise<boolean>;
|
|
428
|
+
handleError(error: unknown): Error;
|
|
429
|
+
healthCheck(): Promise<{
|
|
430
|
+
status: string;
|
|
431
|
+
users?: number;
|
|
432
|
+
timestamp?: string;
|
|
433
|
+
[key: string]: any;
|
|
434
|
+
}>;
|
|
435
|
+
};
|
|
436
|
+
} & T;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspaces Methods Mixin
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for managing Oxy workspaces and their members via the
|
|
5
|
+
* `/workspaces` API. A workspace is a multi-user container that owns
|
|
6
|
+
* applications and other resources: membership (with a role) grants
|
|
7
|
+
* permissions. A `personal` workspace is created implicitly for every user;
|
|
8
|
+
* `team` workspaces are created explicitly and can invite additional members.
|
|
9
|
+
*
|
|
10
|
+
* Reference workspaces by their Mongo `_id` and members by their member `_id`.
|
|
11
|
+
* Never by name or slug.
|
|
12
|
+
*/
|
|
13
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
14
|
+
/** Role a member holds within a workspace. */
|
|
15
|
+
export type WorkspaceRole = 'owner' | 'admin' | 'member' | 'viewer';
|
|
16
|
+
/** Workspace classification. A `personal` workspace is implicit per user. */
|
|
17
|
+
export type WorkspaceType = 'personal' | 'team';
|
|
18
|
+
/** Lifecycle status of a workspace. */
|
|
19
|
+
export type WorkspaceStatus = 'active' | 'deleted';
|
|
20
|
+
/** Membership lifecycle status. */
|
|
21
|
+
export type WorkspaceMemberStatus = 'active' | 'invited' | 'removed';
|
|
22
|
+
/**
|
|
23
|
+
* Client-facing WorkspaceMember shape. `permissions` is derived from `role`
|
|
24
|
+
* on the server at write time.
|
|
25
|
+
*/
|
|
26
|
+
export interface WorkspaceMember {
|
|
27
|
+
_id: string;
|
|
28
|
+
workspaceId: string;
|
|
29
|
+
userId: string;
|
|
30
|
+
role: WorkspaceRole;
|
|
31
|
+
permissions: string[];
|
|
32
|
+
invitedByUserId?: string | null;
|
|
33
|
+
joinedAt?: string | null;
|
|
34
|
+
status: WorkspaceMemberStatus;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
updatedAt: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Client-facing Workspace shape returned by the `/workspaces` API. Mirrors the
|
|
40
|
+
* server `Workspace` model with `_id` as a string and dates serialized to ISO
|
|
41
|
+
* strings.
|
|
42
|
+
*/
|
|
43
|
+
export interface Workspace {
|
|
44
|
+
_id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
slug: string;
|
|
47
|
+
type: WorkspaceType;
|
|
48
|
+
description?: string | null;
|
|
49
|
+
icon?: string | null;
|
|
50
|
+
ownerId: string;
|
|
51
|
+
status: WorkspaceStatus;
|
|
52
|
+
createdAt: string;
|
|
53
|
+
updatedAt: string;
|
|
54
|
+
/**
|
|
55
|
+
* The calling user's own membership in this workspace, embedded by the API
|
|
56
|
+
* on list (`GET /workspaces`) and detail (`GET /workspaces/:id`) responses.
|
|
57
|
+
* Use `callerMembership.permissions` to gate UI affordances.
|
|
58
|
+
*/
|
|
59
|
+
callerMembership?: WorkspaceMember | null;
|
|
60
|
+
}
|
|
61
|
+
/** Input accepted by `createWorkspace`. */
|
|
62
|
+
export interface CreateWorkspaceInput {
|
|
63
|
+
name: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
icon?: string;
|
|
66
|
+
}
|
|
67
|
+
/** Input accepted by `updateWorkspace`. */
|
|
68
|
+
export interface UpdateWorkspaceInput {
|
|
69
|
+
name?: string;
|
|
70
|
+
description?: string | null;
|
|
71
|
+
icon?: string | null;
|
|
72
|
+
}
|
|
73
|
+
/** Input accepted by `inviteWorkspaceMember`. The owner role cannot be invited. */
|
|
74
|
+
export interface InviteWorkspaceMemberInput {
|
|
75
|
+
/**
|
|
76
|
+
* The username or email of the user to invite. Resolved to a user server-side;
|
|
77
|
+
* an unknown value yields a 404 "User not found".
|
|
78
|
+
*/
|
|
79
|
+
usernameOrEmail: string;
|
|
80
|
+
role: Exclude<WorkspaceRole, 'owner'>;
|
|
81
|
+
}
|
|
82
|
+
/** Input accepted by `updateWorkspaceMember`. The owner role cannot be assigned. */
|
|
83
|
+
export interface UpdateWorkspaceMemberInput {
|
|
84
|
+
role: Exclude<WorkspaceRole, 'owner'>;
|
|
85
|
+
}
|
|
86
|
+
/** Input accepted by `transferWorkspaceOwnership`. */
|
|
87
|
+
export interface TransferWorkspaceOwnershipInput {
|
|
88
|
+
userId: string;
|
|
89
|
+
}
|
|
90
|
+
/** Result of a delete/remove/transfer operation. */
|
|
91
|
+
export interface WorkspaceSuccessResult {
|
|
92
|
+
success: boolean;
|
|
93
|
+
}
|
|
94
|
+
export declare function OxyServicesWorkspacesMixin<T extends typeof OxyServicesBase>(Base: T): {
|
|
95
|
+
new (...args: any[]): {
|
|
96
|
+
/**
|
|
97
|
+
* List workspaces the current user is an active member of.
|
|
98
|
+
*/
|
|
99
|
+
getWorkspaces(): Promise<Workspace[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a new team workspace. The caller becomes its `owner`.
|
|
102
|
+
* @param data - Workspace configuration.
|
|
103
|
+
*/
|
|
104
|
+
createWorkspace(data: CreateWorkspaceInput): Promise<Workspace>;
|
|
105
|
+
/**
|
|
106
|
+
* Fetch a single workspace by id.
|
|
107
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
108
|
+
*/
|
|
109
|
+
getWorkspace(workspaceId: string): Promise<Workspace>;
|
|
110
|
+
/**
|
|
111
|
+
* Update a workspace's mutable fields.
|
|
112
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
113
|
+
* @param data - Subset of updatable fields.
|
|
114
|
+
*/
|
|
115
|
+
updateWorkspace(workspaceId: string, data: UpdateWorkspaceInput): Promise<Workspace>;
|
|
116
|
+
/**
|
|
117
|
+
* Soft-delete a workspace (owner only).
|
|
118
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
119
|
+
*/
|
|
120
|
+
deleteWorkspace(workspaceId: string): Promise<WorkspaceSuccessResult>;
|
|
121
|
+
/**
|
|
122
|
+
* List members of a workspace.
|
|
123
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
124
|
+
*/
|
|
125
|
+
getWorkspaceMembers(workspaceId: string): Promise<WorkspaceMember[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Add a member to a workspace.
|
|
128
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
129
|
+
* @param data - Target user's username or email and role (never `owner`).
|
|
130
|
+
* The server resolves `usernameOrEmail` to a user; an unknown value yields
|
|
131
|
+
* a 404 "User not found".
|
|
132
|
+
*/
|
|
133
|
+
inviteWorkspaceMember(workspaceId: string, data: InviteWorkspaceMemberInput): Promise<WorkspaceMember>;
|
|
134
|
+
/**
|
|
135
|
+
* Change a member's role.
|
|
136
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
137
|
+
* @param memberId - The member's Mongo `_id`.
|
|
138
|
+
* @param data - New role (never `owner`).
|
|
139
|
+
*/
|
|
140
|
+
updateWorkspaceMember(workspaceId: string, memberId: string, data: UpdateWorkspaceMemberInput): Promise<WorkspaceMember>;
|
|
141
|
+
/**
|
|
142
|
+
* Remove a member from a workspace.
|
|
143
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
144
|
+
* @param memberId - The member's Mongo `_id`.
|
|
145
|
+
*/
|
|
146
|
+
removeWorkspaceMember(workspaceId: string, memberId: string): Promise<WorkspaceSuccessResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Transfer ownership of a workspace to another member (owner only).
|
|
149
|
+
* Demotes the current owner and promotes the target to `owner`.
|
|
150
|
+
* @param workspaceId - The workspace's Mongo `_id`.
|
|
151
|
+
* @param data - Target user id.
|
|
152
|
+
*/
|
|
153
|
+
transferWorkspaceOwnership(workspaceId: string, data: TransferWorkspaceOwnershipInput): Promise<WorkspaceSuccessResult>;
|
|
154
|
+
httpService: import("../HttpService").HttpService;
|
|
155
|
+
cloudURL: string;
|
|
156
|
+
config: import("../OxyServices.base").OxyConfig;
|
|
157
|
+
__resetTokensForTests(): void;
|
|
158
|
+
makeRequest<T_1>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: any, options?: import("../HttpService").RequestOptions): Promise<T_1>;
|
|
159
|
+
getBaseURL(): string;
|
|
160
|
+
getSessionBaseUrl(): string;
|
|
161
|
+
getClient(): import("../HttpService").HttpService;
|
|
162
|
+
getMetrics(): {
|
|
163
|
+
totalRequests: number;
|
|
164
|
+
successfulRequests: number;
|
|
165
|
+
failedRequests: number;
|
|
166
|
+
cacheHits: number;
|
|
167
|
+
cacheMisses: number;
|
|
168
|
+
averageResponseTime: number;
|
|
169
|
+
};
|
|
170
|
+
clearCache(): void;
|
|
171
|
+
clearCacheEntry(key: string): void;
|
|
172
|
+
clearCacheByPrefix(prefix: string): number;
|
|
173
|
+
getCacheStats(): {
|
|
174
|
+
size: number;
|
|
175
|
+
hits: number;
|
|
176
|
+
misses: number;
|
|
177
|
+
hitRate: number;
|
|
178
|
+
};
|
|
179
|
+
getCloudURL(): string;
|
|
180
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
181
|
+
clearTokens(): void;
|
|
182
|
+
onTokensChanged(listener: (accessToken: string | null) => void): () => void;
|
|
183
|
+
_cachedUserId: string | null | undefined;
|
|
184
|
+
_cachedAccessToken: string | null;
|
|
185
|
+
getCurrentUserId(): string | null;
|
|
186
|
+
hasValidToken(): boolean;
|
|
187
|
+
getAccessToken(): string | null;
|
|
188
|
+
setActingAs(userId: string | null): void;
|
|
189
|
+
getActingAs(): string | null;
|
|
190
|
+
waitForAuth(timeoutMs?: number): Promise<boolean>;
|
|
191
|
+
withAuthRetry<T_1>(operation: () => Promise<T_1>, operationName: string, options?: {
|
|
192
|
+
maxRetries?: number;
|
|
193
|
+
retryDelay?: number;
|
|
194
|
+
authTimeoutMs?: number;
|
|
195
|
+
}): Promise<T_1>;
|
|
196
|
+
validate(): Promise<boolean>;
|
|
197
|
+
handleError(error: unknown): Error;
|
|
198
|
+
healthCheck(): Promise<{
|
|
199
|
+
status: string;
|
|
200
|
+
users?: number;
|
|
201
|
+
timestamp?: string;
|
|
202
|
+
[key: string]: any;
|
|
203
|
+
}>;
|
|
204
|
+
};
|
|
205
|
+
} & T;
|
|
@@ -14,9 +14,10 @@ import { OxyServicesUserMixin } from './OxyServices.user';
|
|
|
14
14
|
import { OxyServicesPrivacyMixin } from './OxyServices.privacy';
|
|
15
15
|
import { OxyServicesLanguageMixin } from './OxyServices.language';
|
|
16
16
|
import { OxyServicesPaymentMixin } from './OxyServices.payment';
|
|
17
|
-
import {
|
|
17
|
+
import { OxyServicesReputationMixin } from './OxyServices.reputation';
|
|
18
18
|
import { OxyServicesAssetsMixin } from './OxyServices.assets';
|
|
19
19
|
import { OxyServicesApplicationsMixin } from './OxyServices.applications';
|
|
20
|
+
import { OxyServicesWorkspacesMixin } from './OxyServices.workspaces';
|
|
20
21
|
import { OxyServicesLocationMixin } from './OxyServices.location';
|
|
21
22
|
import { OxyServicesAnalyticsMixin } from './OxyServices.analytics';
|
|
22
23
|
import { OxyServicesDevicesMixin } from './OxyServices.devices';
|
|
@@ -36,7 +37,7 @@ import { OxyServicesAppDataMixin } from './OxyServices.appData';
|
|
|
36
37
|
* If you add a new mixin to `MIXIN_PIPELINE`, add it here too so its methods
|
|
37
38
|
* are visible without a cast.
|
|
38
39
|
*/
|
|
39
|
-
type AllMixinInstances = InstanceType<ReturnType<typeof OxyServicesAuthMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesFedCMMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesPopupAuthMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesRedirectAuthMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesSsoMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesUserMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesPrivacyMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesLanguageMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesPaymentMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof
|
|
40
|
+
type AllMixinInstances = InstanceType<ReturnType<typeof OxyServicesAuthMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesFedCMMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesPopupAuthMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesRedirectAuthMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesSsoMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesUserMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesPrivacyMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesLanguageMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesPaymentMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesReputationMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesAssetsMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesApplicationsMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesWorkspacesMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesLocationMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesAnalyticsMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesDevicesMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesSecurityMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesFeaturesMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesTopicsMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesManagedAccountsMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesContactsMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesAppDataMixin<typeof OxyServicesBase>>> & InstanceType<ReturnType<typeof OxyServicesUtilityMixin<typeof OxyServicesBase>>>;
|
|
40
41
|
/**
|
|
41
42
|
* Constructor type for the fully composed mixin pipeline. Each mixin returns
|
|
42
43
|
* a new constructor that augments its input; reducing across the pipeline
|