@xnetjs/abuse 0.0.1 → 0.0.3

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.
@@ -1,191 +0,0 @@
1
- /**
2
- * @xnetjs/abuse - Shared abuse decision types.
3
- */
4
- type AbuseSurface = 'transport' | 'remoteMutation' | 'commentThread' | 'messageInbox' | 'searchIndex' | 'feed' | 'crawl' | 'localApi';
5
- type PolicyScope = 'user' | 'workspace' | 'community' | 'hub' | 'appView' | 'protocol';
6
- type AbuseAdmission = 'accept' | 'reject' | 'quarantine';
7
- type AbuseVisibility = 'show' | 'warn' | 'blur' | 'hide';
8
- type AbuseReach = 'normal' | 'demote' | 'exclude';
9
- type AbuseResource = 'normal' | 'throttle' | 'block-peer' | 'require-budget';
10
- type AbuseSeverity = 'low' | 'medium' | 'high' | 'critical';
11
- type AbuseReviewQueue = 'safety' | 'quality' | 'appeal' | 'operator';
12
- type AbuseReasonCode = 'accepted' | 'blocked-by-policy' | 'budget-required' | 'failed-admission' | 'first-contact' | 'invalid-doc-binding' | 'invalid-freshness' | 'invalid-hash' | 'invalid-signature' | 'low-confidence-quality-signal' | 'over-rate-limit' | 'over-size-limit' | 'peer-score-block' | 'peer-score-throttle' | 'quality-risk' | 'trusted-abuse-label' | 'trusted-warning-label' | 'unauthorized' | 'unsigned-update' | 'user-override';
13
- type AbuseLabel = {
14
- value: string;
15
- sourceDID?: string;
16
- sourceWeight: number;
17
- confidence: number;
18
- expiresAt?: number;
19
- evidenceRefs?: readonly string[];
20
- };
21
- type AbuseCryptoFacts = {
22
- hashValid: boolean;
23
- signatureValid: boolean;
24
- authorized: boolean;
25
- freshnessValid: boolean;
26
- docBindingValid: boolean;
27
- };
28
- type AbuseResourceFacts = {
29
- overSizeLimit: boolean;
30
- overRateLimit: boolean;
31
- estimatedCost: number;
32
- budgetRemaining: number | null;
33
- };
34
- type AbuseActorFacts = {
35
- did?: string;
36
- peerId?: string;
37
- firstContact: boolean;
38
- peerScore: number;
39
- localBlocked: boolean;
40
- workspaceBlocked: boolean;
41
- hubBlocked: boolean;
42
- appViewBlocked: boolean;
43
- };
44
- type AbuseQualitySignals = {
45
- duplicateScore: number;
46
- slopScore: number;
47
- citationCoverage: number;
48
- provenanceScore: number;
49
- };
50
- type AbusePolicyFacts = {
51
- peerScoreBlockThreshold: number;
52
- peerScoreThrottleThreshold: number;
53
- abuseLabelHideThreshold: number;
54
- abuseLabelWarnThreshold: number;
55
- qualityReviewThreshold: number;
56
- qualityWarnThreshold: number;
57
- quarantineFirstContact: boolean;
58
- };
59
- type AbuseDecisionOverride = Partial<Pick<AbuseDecision, 'visibility' | 'reach' | 'notify' | 'includeInCounters' | 'includeInSearch'>> & {
60
- reason?: string;
61
- };
62
- type AbuseFacts = {
63
- surface: AbuseSurface;
64
- crypto?: Partial<AbuseCryptoFacts>;
65
- resource?: Partial<AbuseResourceFacts>;
66
- actor?: Partial<AbuseActorFacts>;
67
- labels?: readonly AbuseLabel[];
68
- quality?: Partial<AbuseQualitySignals>;
69
- policy?: Partial<AbusePolicyFacts>;
70
- override?: AbuseDecisionOverride;
71
- now?: number;
72
- };
73
- type NormalizedAbuseFacts = {
74
- surface: AbuseSurface;
75
- crypto: AbuseCryptoFacts;
76
- resource: AbuseResourceFacts;
77
- actor: AbuseActorFacts;
78
- labels: readonly AbuseLabel[];
79
- quality: AbuseQualitySignals;
80
- policy: AbusePolicyFacts;
81
- override?: AbuseDecisionOverride;
82
- now: number;
83
- };
84
- type PendingLabel = {
85
- value: string;
86
- confidence: number;
87
- reason: AbuseReasonCode;
88
- evidenceRefs: readonly string[];
89
- };
90
- type PendingSecurityEvent = {
91
- eventName: string;
92
- severity: AbuseSeverity;
93
- reason: AbuseReasonCode;
94
- };
95
- type AbuseReviewDecision = {
96
- required: false;
97
- } | {
98
- required: true;
99
- queue: AbuseReviewQueue;
100
- priority: number;
101
- };
102
- type AbuseDecision = {
103
- admission: AbuseAdmission;
104
- visibility: AbuseVisibility;
105
- reach: AbuseReach;
106
- resource: AbuseResource;
107
- notify: boolean;
108
- includeInCounters: boolean;
109
- includeInSearch: boolean;
110
- review: AbuseReviewDecision;
111
- reasons: readonly AbuseReasonCode[];
112
- evidenceRefs: readonly string[];
113
- labelsToEmit: readonly PendingLabel[];
114
- telemetry: readonly PendingSecurityEvent[];
115
- };
116
- type DecisionExplanationReason = {
117
- code: AbuseReasonCode;
118
- severity: AbuseSeverity;
119
- message: string;
120
- };
121
- type DecisionExplanation = {
122
- summary: string;
123
- reasons: readonly DecisionExplanationReason[];
124
- };
125
-
126
- /**
127
- * Privacy-preserving telemetry helpers for abuse decisions.
128
- */
129
-
130
- type AbusePeerScoreBucket = 'unknown' | '<=10' | '11-30' | '31-50' | '51-80' | '81-100' | '>100';
131
- type AbuseTelemetryReporter = {
132
- reportSecurityEvent(eventName: string, severity: AbuseSeverity, details?: Record<string, unknown>): unknown;
133
- reportUsage?(metricName: string, value: number): unknown;
134
- };
135
- type RemoteMutationRejectionTelemetry = {
136
- eventName: string;
137
- severity: AbuseSeverity;
138
- details: {
139
- actionTaken: 'remote_mutation_rejected';
140
- surface: AbuseSurface;
141
- primaryReason: AbuseReasonCode;
142
- reasons: readonly AbuseReasonCode[];
143
- peerHash: string;
144
- peerScoreBucket: AbusePeerScoreBucket;
145
- resourceAction: AbuseDecision['resource'];
146
- shouldThrottle: boolean;
147
- };
148
- };
149
- type RemoteMutationRejectionTelemetryInput = {
150
- facts: AbuseFacts;
151
- decision: AbuseDecision;
152
- eventName?: string;
153
- peerHashSalt?: string;
154
- };
155
- declare function bucketAbusePeerScore(score: number | null | undefined): AbusePeerScoreBucket;
156
- declare function hashAbusePeerIdentifier(peerId: string | null | undefined, salt?: string): string;
157
- declare function createRemoteMutationRejectionTelemetry(input: RemoteMutationRejectionTelemetryInput): RemoteMutationRejectionTelemetry | null;
158
- declare function reportRemoteMutationRejection(telemetry: AbuseTelemetryReporter | undefined, input: RemoteMutationRejectionTelemetryInput): boolean;
159
-
160
- /**
161
- * Adapter helpers for wiring local package events into abuse decisions.
162
- */
163
-
164
- type AbuseFactAdapter<TInput> = (input: TInput) => AbuseFacts;
165
- type AbuseDecisionFunction = (facts: AbuseFacts) => AbuseDecision;
166
- type AbuseAdapterResult = {
167
- facts: AbuseFacts;
168
- decision: AbuseDecision;
169
- };
170
- declare function createAbuseFactAdapter<TInput>(adapter: AbuseFactAdapter<TInput>): AbuseFactAdapter<TInput>;
171
- declare function decideWithAdapter<TInput>(input: TInput, adapter: AbuseFactAdapter<TInput>, decide?: AbuseDecisionFunction): AbuseAdapterResult;
172
- declare function createAbuseDecisionAdapter<TInput>(adapter: AbuseFactAdapter<TInput>, decide?: AbuseDecisionFunction): (input: TInput) => AbuseAdapterResult;
173
- type RemoteAdmissionResult = AbuseAdapterResult & {
174
- accepted: boolean;
175
- shouldMutate: boolean;
176
- shouldRelay: boolean;
177
- shouldThrottle: boolean;
178
- };
179
- type RemoteAdmissionPipeline<TInput> = {
180
- evaluate(input: TInput): RemoteAdmissionResult;
181
- };
182
- type RemoteAdmissionPipelineOptions<TInput> = {
183
- adapt: AbuseFactAdapter<TInput>;
184
- decide?: AbuseDecisionFunction;
185
- telemetry?: AbuseTelemetryReporter;
186
- telemetryEventName?: string;
187
- telemetryPeerHashSalt?: string;
188
- };
189
- declare function createRemoteAdmissionPipeline<TInput>(options: RemoteAdmissionPipelineOptions<TInput>): RemoteAdmissionPipeline<TInput>;
190
-
191
- export { type AbuseLabel as A, type RemoteMutationRejectionTelemetryInput as B, type AbuseActorFacts as C, type DecisionExplanation as D, type AbuseAdmission as E, type AbuseCryptoFacts as F, type AbuseDecisionOverride as G, type AbuseResourceFacts as H, type AbuseReviewDecision as I, type AbuseSeverity as J, type PendingLabel as K, type PendingSecurityEvent as L, type NormalizedAbuseFacts as N, type PolicyScope as P, type RemoteAdmissionPipeline as R, type AbuseFacts as a, type AbuseDecision as b, type AbuseReasonCode as c, type DecisionExplanationReason as d, type AbuseSurface as e, type AbuseQualitySignals as f, type AbuseReviewQueue as g, type AbuseVisibility as h, type AbuseReach as i, type AbuseResource as j, createAbuseDecisionAdapter as k, createAbuseFactAdapter as l, createRemoteAdmissionPipeline as m, decideWithAdapter as n, bucketAbusePeerScore as o, createRemoteMutationRejectionTelemetry as p, hashAbusePeerIdentifier as q, reportRemoteMutationRejection as r, type AbuseAdapterResult as s, type AbuseDecisionFunction as t, type AbuseFactAdapter as u, type RemoteAdmissionPipelineOptions as v, type RemoteAdmissionResult as w, type AbusePeerScoreBucket as x, type AbuseTelemetryReporter as y, type RemoteMutationRejectionTelemetry as z };
@@ -1,190 +0,0 @@
1
- /**
2
- * @xnetjs/abuse - Shared abuse decision types.
3
- */
4
- type AbuseSurface = 'transport' | 'remoteMutation' | 'commentThread' | 'messageInbox' | 'searchIndex' | 'feed' | 'crawl' | 'localApi';
5
- type PolicyScope = 'user' | 'workspace' | 'community' | 'hub' | 'appView' | 'protocol';
6
- type AbuseAdmission = 'accept' | 'reject' | 'quarantine';
7
- type AbuseVisibility = 'show' | 'warn' | 'blur' | 'hide';
8
- type AbuseReach = 'normal' | 'demote' | 'exclude';
9
- type AbuseResource = 'normal' | 'throttle' | 'block-peer' | 'require-budget';
10
- type AbuseSeverity = 'low' | 'medium' | 'high' | 'critical';
11
- type AbuseReviewQueue = 'safety' | 'quality' | 'appeal' | 'operator';
12
- type AbuseReasonCode = 'accepted' | 'blocked-by-policy' | 'budget-required' | 'failed-admission' | 'first-contact' | 'invalid-doc-binding' | 'invalid-freshness' | 'invalid-hash' | 'invalid-signature' | 'low-confidence-quality-signal' | 'over-rate-limit' | 'over-size-limit' | 'peer-score-block' | 'peer-score-throttle' | 'quality-risk' | 'trusted-abuse-label' | 'trusted-warning-label' | 'unauthorized' | 'unsigned-update' | 'user-override';
13
- type AbuseLabel = {
14
- value: string;
15
- sourceDID?: string;
16
- sourceWeight: number;
17
- confidence: number;
18
- expiresAt?: number;
19
- evidenceRefs?: readonly string[];
20
- };
21
- type AbuseCryptoFacts = {
22
- hashValid: boolean;
23
- signatureValid: boolean;
24
- authorized: boolean;
25
- freshnessValid: boolean;
26
- docBindingValid: boolean;
27
- };
28
- type AbuseResourceFacts = {
29
- overSizeLimit: boolean;
30
- overRateLimit: boolean;
31
- estimatedCost: number;
32
- budgetRemaining: number | null;
33
- };
34
- type AbuseActorFacts = {
35
- did?: string;
36
- peerId?: string;
37
- firstContact: boolean;
38
- peerScore: number;
39
- localBlocked: boolean;
40
- workspaceBlocked: boolean;
41
- hubBlocked: boolean;
42
- };
43
- type AbuseQualitySignals = {
44
- duplicateScore: number;
45
- slopScore: number;
46
- citationCoverage: number;
47
- provenanceScore: number;
48
- };
49
- type AbusePolicyFacts = {
50
- peerScoreBlockThreshold: number;
51
- peerScoreThrottleThreshold: number;
52
- abuseLabelHideThreshold: number;
53
- abuseLabelWarnThreshold: number;
54
- qualityReviewThreshold: number;
55
- qualityWarnThreshold: number;
56
- quarantineFirstContact: boolean;
57
- };
58
- type AbuseDecisionOverride = Partial<Pick<AbuseDecision, 'visibility' | 'reach' | 'notify' | 'includeInCounters' | 'includeInSearch'>> & {
59
- reason?: string;
60
- };
61
- type AbuseFacts = {
62
- surface: AbuseSurface;
63
- crypto?: Partial<AbuseCryptoFacts>;
64
- resource?: Partial<AbuseResourceFacts>;
65
- actor?: Partial<AbuseActorFacts>;
66
- labels?: readonly AbuseLabel[];
67
- quality?: Partial<AbuseQualitySignals>;
68
- policy?: Partial<AbusePolicyFacts>;
69
- override?: AbuseDecisionOverride;
70
- now?: number;
71
- };
72
- type NormalizedAbuseFacts = {
73
- surface: AbuseSurface;
74
- crypto: AbuseCryptoFacts;
75
- resource: AbuseResourceFacts;
76
- actor: AbuseActorFacts;
77
- labels: readonly AbuseLabel[];
78
- quality: AbuseQualitySignals;
79
- policy: AbusePolicyFacts;
80
- override?: AbuseDecisionOverride;
81
- now: number;
82
- };
83
- type PendingLabel = {
84
- value: string;
85
- confidence: number;
86
- reason: AbuseReasonCode;
87
- evidenceRefs: readonly string[];
88
- };
89
- type PendingSecurityEvent = {
90
- eventName: string;
91
- severity: AbuseSeverity;
92
- reason: AbuseReasonCode;
93
- };
94
- type AbuseReviewDecision = {
95
- required: false;
96
- } | {
97
- required: true;
98
- queue: AbuseReviewQueue;
99
- priority: number;
100
- };
101
- type AbuseDecision = {
102
- admission: AbuseAdmission;
103
- visibility: AbuseVisibility;
104
- reach: AbuseReach;
105
- resource: AbuseResource;
106
- notify: boolean;
107
- includeInCounters: boolean;
108
- includeInSearch: boolean;
109
- review: AbuseReviewDecision;
110
- reasons: readonly AbuseReasonCode[];
111
- evidenceRefs: readonly string[];
112
- labelsToEmit: readonly PendingLabel[];
113
- telemetry: readonly PendingSecurityEvent[];
114
- };
115
- type DecisionExplanationReason = {
116
- code: AbuseReasonCode;
117
- severity: AbuseSeverity;
118
- message: string;
119
- };
120
- type DecisionExplanation = {
121
- summary: string;
122
- reasons: readonly DecisionExplanationReason[];
123
- };
124
-
125
- /**
126
- * Privacy-preserving telemetry helpers for abuse decisions.
127
- */
128
-
129
- type AbusePeerScoreBucket = 'unknown' | '<=10' | '11-30' | '31-50' | '51-80' | '81-100' | '>100';
130
- type AbuseTelemetryReporter = {
131
- reportSecurityEvent(eventName: string, severity: AbuseSeverity, details?: Record<string, unknown>): unknown;
132
- reportUsage?(metricName: string, value: number): unknown;
133
- };
134
- type RemoteMutationRejectionTelemetry = {
135
- eventName: string;
136
- severity: AbuseSeverity;
137
- details: {
138
- actionTaken: 'remote_mutation_rejected';
139
- surface: AbuseSurface;
140
- primaryReason: AbuseReasonCode;
141
- reasons: readonly AbuseReasonCode[];
142
- peerHash: string;
143
- peerScoreBucket: AbusePeerScoreBucket;
144
- resourceAction: AbuseDecision['resource'];
145
- shouldThrottle: boolean;
146
- };
147
- };
148
- type RemoteMutationRejectionTelemetryInput = {
149
- facts: AbuseFacts;
150
- decision: AbuseDecision;
151
- eventName?: string;
152
- peerHashSalt?: string;
153
- };
154
- declare function bucketAbusePeerScore(score: number | null | undefined): AbusePeerScoreBucket;
155
- declare function hashAbusePeerIdentifier(peerId: string | null | undefined, salt?: string): string;
156
- declare function createRemoteMutationRejectionTelemetry(input: RemoteMutationRejectionTelemetryInput): RemoteMutationRejectionTelemetry | null;
157
- declare function reportRemoteMutationRejection(telemetry: AbuseTelemetryReporter | undefined, input: RemoteMutationRejectionTelemetryInput): boolean;
158
-
159
- /**
160
- * Adapter helpers for wiring local package events into abuse decisions.
161
- */
162
-
163
- type AbuseFactAdapter<TInput> = (input: TInput) => AbuseFacts;
164
- type AbuseDecisionFunction = (facts: AbuseFacts) => AbuseDecision;
165
- type AbuseAdapterResult = {
166
- facts: AbuseFacts;
167
- decision: AbuseDecision;
168
- };
169
- declare function createAbuseFactAdapter<TInput>(adapter: AbuseFactAdapter<TInput>): AbuseFactAdapter<TInput>;
170
- declare function decideWithAdapter<TInput>(input: TInput, adapter: AbuseFactAdapter<TInput>, decide?: AbuseDecisionFunction): AbuseAdapterResult;
171
- declare function createAbuseDecisionAdapter<TInput>(adapter: AbuseFactAdapter<TInput>, decide?: AbuseDecisionFunction): (input: TInput) => AbuseAdapterResult;
172
- type RemoteAdmissionResult = AbuseAdapterResult & {
173
- accepted: boolean;
174
- shouldMutate: boolean;
175
- shouldRelay: boolean;
176
- shouldThrottle: boolean;
177
- };
178
- type RemoteAdmissionPipeline<TInput> = {
179
- evaluate(input: TInput): RemoteAdmissionResult;
180
- };
181
- type RemoteAdmissionPipelineOptions<TInput> = {
182
- adapt: AbuseFactAdapter<TInput>;
183
- decide?: AbuseDecisionFunction;
184
- telemetry?: AbuseTelemetryReporter;
185
- telemetryEventName?: string;
186
- telemetryPeerHashSalt?: string;
187
- };
188
- declare function createRemoteAdmissionPipeline<TInput>(options: RemoteAdmissionPipelineOptions<TInput>): RemoteAdmissionPipeline<TInput>;
189
-
190
- export { type AbuseLabel as A, type AbuseDecisionOverride as B, type AbuseResource as C, type DecisionExplanation as D, type AbuseResourceFacts as E, type AbuseReviewDecision as F, type AbuseReviewQueue as G, type AbuseSeverity as H, type AbuseVisibility as I, type PendingLabel as J, type PendingSecurityEvent as K, type NormalizedAbuseFacts as N, type PolicyScope as P, type RemoteAdmissionPipeline as R, type AbuseFacts as a, type AbuseDecision as b, type AbuseReasonCode as c, type DecisionExplanationReason as d, type AbuseSurface as e, type AbuseQualitySignals as f, createAbuseDecisionAdapter as g, createAbuseFactAdapter as h, createRemoteAdmissionPipeline as i, decideWithAdapter as j, bucketAbusePeerScore as k, createRemoteMutationRejectionTelemetry as l, hashAbusePeerIdentifier as m, type AbuseAdapterResult as n, type AbuseDecisionFunction as o, type AbuseFactAdapter as p, type RemoteAdmissionPipelineOptions as q, reportRemoteMutationRejection as r, type RemoteAdmissionResult as s, type AbusePeerScoreBucket as t, type AbuseTelemetryReporter as u, type RemoteMutationRejectionTelemetry as v, type RemoteMutationRejectionTelemetryInput as w, type AbuseActorFacts as x, type AbuseAdmission as y, type AbuseCryptoFacts as z };
@@ -1,196 +0,0 @@
1
- /**
2
- * @xnetjs/abuse - Shared abuse decision types.
3
- */
4
- type AbuseSurface = 'transport' | 'remoteMutation' | 'commentThread' | 'messageInbox' | 'searchIndex' | 'feed' | 'crawl' | 'localApi';
5
- type PolicyScope = 'user' | 'workspace' | 'community' | 'hub' | 'appView' | 'protocol';
6
- type AbuseAdmission = 'accept' | 'reject' | 'quarantine';
7
- type AbuseVisibility = 'show' | 'warn' | 'blur' | 'hide';
8
- type AbuseReach = 'normal' | 'demote' | 'exclude';
9
- type AbuseResource = 'normal' | 'throttle' | 'block-peer' | 'require-budget';
10
- type AbuseSeverity = 'low' | 'medium' | 'high' | 'critical';
11
- type AbuseReviewQueue = 'safety' | 'quality' | 'appeal' | 'operator';
12
- type AbuseReasonCode = 'accepted' | 'blocked-by-policy' | 'budget-required' | 'failed-admission' | 'first-contact' | 'invalid-doc-binding' | 'invalid-freshness' | 'invalid-hash' | 'invalid-signature' | 'low-confidence-quality-signal' | 'over-rate-limit' | 'over-size-limit' | 'peer-score-block' | 'peer-score-throttle' | 'quality-risk' | 'trusted-abuse-label' | 'trusted-warning-label' | 'unauthorized' | 'unsigned-update' | 'policy-override' | 'user-override';
13
- type AbuseLabel = {
14
- id?: string;
15
- value: string;
16
- sourceDID?: string;
17
- sourceWeight: number;
18
- confidence: number;
19
- expiresAt?: number;
20
- evidenceRefs?: readonly string[];
21
- negates?: string;
22
- };
23
- type AbuseCryptoFacts = {
24
- hashValid: boolean;
25
- signatureValid: boolean;
26
- authorized: boolean;
27
- freshnessValid: boolean;
28
- docBindingValid: boolean;
29
- };
30
- type AbuseResourceFacts = {
31
- overSizeLimit: boolean;
32
- overRateLimit: boolean;
33
- estimatedCost: number;
34
- budgetRemaining: number | null;
35
- };
36
- type AbuseActorFacts = {
37
- did?: string;
38
- peerId?: string;
39
- firstContact: boolean;
40
- peerScore: number;
41
- localBlocked: boolean;
42
- workspaceBlocked: boolean;
43
- hubBlocked: boolean;
44
- appViewBlocked: boolean;
45
- };
46
- type AbuseQualitySignals = {
47
- duplicateScore: number;
48
- slopScore: number;
49
- citationCoverage: number;
50
- provenanceScore: number;
51
- };
52
- type AbusePolicyFacts = {
53
- peerScoreBlockThreshold: number;
54
- peerScoreThrottleThreshold: number;
55
- abuseLabelHideThreshold: number;
56
- abuseLabelWarnThreshold: number;
57
- qualityReviewThreshold: number;
58
- qualityWarnThreshold: number;
59
- quarantineFirstContact: boolean;
60
- };
61
- type AbuseDecisionOverrideScope = 'user' | 'workspace' | 'reviewer';
62
- type AbuseDecisionOverride = Partial<Pick<AbuseDecision, 'visibility' | 'reach' | 'notify' | 'includeInCounters' | 'includeInSearch'>> & {
63
- scope?: AbuseDecisionOverrideScope;
64
- sourceDID?: string;
65
- reason?: string;
66
- };
67
- type AbuseFacts = {
68
- surface: AbuseSurface;
69
- crypto?: Partial<AbuseCryptoFacts>;
70
- resource?: Partial<AbuseResourceFacts>;
71
- actor?: Partial<AbuseActorFacts>;
72
- labels?: readonly AbuseLabel[];
73
- quality?: Partial<AbuseQualitySignals>;
74
- policy?: Partial<AbusePolicyFacts>;
75
- override?: AbuseDecisionOverride;
76
- now?: number;
77
- };
78
- type NormalizedAbuseFacts = {
79
- surface: AbuseSurface;
80
- crypto: AbuseCryptoFacts;
81
- resource: AbuseResourceFacts;
82
- actor: AbuseActorFacts;
83
- labels: readonly AbuseLabel[];
84
- quality: AbuseQualitySignals;
85
- policy: AbusePolicyFacts;
86
- override?: AbuseDecisionOverride;
87
- now: number;
88
- };
89
- type PendingLabel = {
90
- value: string;
91
- confidence: number;
92
- reason: AbuseReasonCode;
93
- evidenceRefs: readonly string[];
94
- };
95
- type PendingSecurityEvent = {
96
- eventName: string;
97
- severity: AbuseSeverity;
98
- reason: AbuseReasonCode;
99
- };
100
- type AbuseReviewDecision = {
101
- required: false;
102
- } | {
103
- required: true;
104
- queue: AbuseReviewQueue;
105
- priority: number;
106
- };
107
- type AbuseDecision = {
108
- admission: AbuseAdmission;
109
- visibility: AbuseVisibility;
110
- reach: AbuseReach;
111
- resource: AbuseResource;
112
- notify: boolean;
113
- includeInCounters: boolean;
114
- includeInSearch: boolean;
115
- review: AbuseReviewDecision;
116
- reasons: readonly AbuseReasonCode[];
117
- evidenceRefs: readonly string[];
118
- labelsToEmit: readonly PendingLabel[];
119
- telemetry: readonly PendingSecurityEvent[];
120
- };
121
- type DecisionExplanationReason = {
122
- code: AbuseReasonCode;
123
- severity: AbuseSeverity;
124
- message: string;
125
- };
126
- type DecisionExplanation = {
127
- summary: string;
128
- reasons: readonly DecisionExplanationReason[];
129
- };
130
-
131
- /**
132
- * Privacy-preserving telemetry helpers for abuse decisions.
133
- */
134
-
135
- type AbusePeerScoreBucket = 'unknown' | '<=10' | '11-30' | '31-50' | '51-80' | '81-100' | '>100';
136
- type AbuseTelemetryReporter = {
137
- reportSecurityEvent(eventName: string, severity: AbuseSeverity, details?: Record<string, unknown>): unknown;
138
- reportUsage?(metricName: string, value: number): unknown;
139
- };
140
- type RemoteMutationRejectionTelemetry = {
141
- eventName: string;
142
- severity: AbuseSeverity;
143
- details: {
144
- actionTaken: 'remote_mutation_rejected';
145
- surface: AbuseSurface;
146
- primaryReason: AbuseReasonCode;
147
- reasons: readonly AbuseReasonCode[];
148
- peerHash: string;
149
- peerScoreBucket: AbusePeerScoreBucket;
150
- resourceAction: AbuseDecision['resource'];
151
- shouldThrottle: boolean;
152
- };
153
- };
154
- type RemoteMutationRejectionTelemetryInput = {
155
- facts: AbuseFacts;
156
- decision: AbuseDecision;
157
- eventName?: string;
158
- peerHashSalt?: string;
159
- };
160
- declare function bucketAbusePeerScore(score: number | null | undefined): AbusePeerScoreBucket;
161
- declare function hashAbusePeerIdentifier(peerId: string | null | undefined, salt?: string): string;
162
- declare function createRemoteMutationRejectionTelemetry(input: RemoteMutationRejectionTelemetryInput): RemoteMutationRejectionTelemetry | null;
163
- declare function reportRemoteMutationRejection(telemetry: AbuseTelemetryReporter | undefined, input: RemoteMutationRejectionTelemetryInput): boolean;
164
-
165
- /**
166
- * Adapter helpers for wiring local package events into abuse decisions.
167
- */
168
-
169
- type AbuseFactAdapter<TInput> = (input: TInput) => AbuseFacts;
170
- type AbuseDecisionFunction = (facts: AbuseFacts) => AbuseDecision;
171
- type AbuseAdapterResult = {
172
- facts: AbuseFacts;
173
- decision: AbuseDecision;
174
- };
175
- declare function createAbuseFactAdapter<TInput>(adapter: AbuseFactAdapter<TInput>): AbuseFactAdapter<TInput>;
176
- declare function decideWithAdapter<TInput>(input: TInput, adapter: AbuseFactAdapter<TInput>, decide?: AbuseDecisionFunction): AbuseAdapterResult;
177
- declare function createAbuseDecisionAdapter<TInput>(adapter: AbuseFactAdapter<TInput>, decide?: AbuseDecisionFunction): (input: TInput) => AbuseAdapterResult;
178
- type RemoteAdmissionResult = AbuseAdapterResult & {
179
- accepted: boolean;
180
- shouldMutate: boolean;
181
- shouldRelay: boolean;
182
- shouldThrottle: boolean;
183
- };
184
- type RemoteAdmissionPipeline<TInput> = {
185
- evaluate(input: TInput): RemoteAdmissionResult;
186
- };
187
- type RemoteAdmissionPipelineOptions<TInput> = {
188
- adapt: AbuseFactAdapter<TInput>;
189
- decide?: AbuseDecisionFunction;
190
- telemetry?: AbuseTelemetryReporter;
191
- telemetryEventName?: string;
192
- telemetryPeerHashSalt?: string;
193
- };
194
- declare function createRemoteAdmissionPipeline<TInput>(options: RemoteAdmissionPipelineOptions<TInput>): RemoteAdmissionPipeline<TInput>;
195
-
196
- export { type AbuseLabel as A, type RemoteMutationRejectionTelemetryInput as B, type AbuseActorFacts as C, type DecisionExplanation as D, type AbuseAdmission as E, type AbuseCryptoFacts as F, type AbuseDecisionOverride as G, type AbuseDecisionOverrideScope as H, type AbuseResourceFacts as I, type AbuseReviewDecision as J, type AbuseSeverity as K, type PendingLabel as L, type PendingSecurityEvent as M, type NormalizedAbuseFacts as N, type PolicyScope as P, type RemoteAdmissionPipeline as R, type AbuseFacts as a, type AbuseDecision as b, type AbuseReasonCode as c, type DecisionExplanationReason as d, type AbuseSurface as e, type AbuseQualitySignals as f, type AbuseReviewQueue as g, type AbuseVisibility as h, type AbuseReach as i, type AbuseResource as j, createAbuseDecisionAdapter as k, createAbuseFactAdapter as l, createRemoteAdmissionPipeline as m, decideWithAdapter as n, bucketAbusePeerScore as o, createRemoteMutationRejectionTelemetry as p, hashAbusePeerIdentifier as q, reportRemoteMutationRejection as r, type AbuseAdapterResult as s, type AbuseDecisionFunction as t, type AbuseFactAdapter as u, type RemoteAdmissionPipelineOptions as v, type RemoteAdmissionResult as w, type AbusePeerScoreBucket as x, type AbuseTelemetryReporter as y, type RemoteMutationRejectionTelemetry as z };