@ciphyrshq/sdk 2.6.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/types.d.ts ADDED
@@ -0,0 +1,382 @@
1
+ // @ciphyrshq/sdk — TypeScript declarations
2
+
3
+ // ── Errors ────────────────────────────────────────────────────────────────────
4
+
5
+ export declare class CiphyrsError extends Error {
6
+ status?: number;
7
+ code?: string;
8
+ constructor(message: string, opts?: { status?: number; code?: string });
9
+ }
10
+ export declare class CiphyrsAuthError extends CiphyrsError {}
11
+ export declare class CiphyrsPermissionError extends CiphyrsError {}
12
+ export declare class CiphyrsNotFoundError extends CiphyrsError {}
13
+ export declare class CiphyrsRateLimitError extends CiphyrsError { retryAfter: number | null; }
14
+ export declare class CiphyrsTimeoutError extends CiphyrsError {}
15
+ export declare class CiphyrsJobTimeoutError extends CiphyrsError { jobId: string; }
16
+
17
+ // ── Shared types ──────────────────────────────────────────────────────────────
18
+
19
+ export type Source = 'PROMPT' | 'PASTE' | 'RAG' | 'TOOL_RESULT' | 'AGENT_MEMORY' | 'FILE_UPLOAD';
20
+ export type Surface = 'vscode' | 'browser' | 'mcp' | 'api' | 'sdk';
21
+ export type JobStatus = 'queued' | 'processing' | 'done' | 'failed';
22
+ export type UserRole = 'owner' | 'admin' | 'member';
23
+ export type Plan = 'free' | 'pro' | 'team' | 'enterprise';
24
+
25
+ export interface EntitySummaryItem {
26
+ type: string;
27
+ count: number;
28
+ }
29
+
30
+ // ── Scan ─────────────────────────────────────────────────────────────────────
31
+
32
+ export interface MaskOptions {
33
+ sessionId?: string;
34
+ entities?: string[];
35
+ source?: Source;
36
+ surface?: Surface;
37
+ llmProvider?: string;
38
+ }
39
+
40
+ export interface MaskResult {
41
+ maskedText: string;
42
+ sessionId: string;
43
+ entitiesFound: number;
44
+ entitySummary: EntitySummaryItem[];
45
+ }
46
+
47
+ export interface MaskAsyncOptions extends MaskOptions {
48
+ webhookUrl?: string;
49
+ }
50
+
51
+ export interface MaskAsyncResult {
52
+ jobId: string;
53
+ sessionId: string;
54
+ status: 'queued';
55
+ }
56
+
57
+ export interface JobResult {
58
+ jobId: string;
59
+ status: JobStatus;
60
+ sessionId: string;
61
+ maskedText?: string;
62
+ entitiesFound?: number;
63
+ entitySummary?: EntitySummaryItem[];
64
+ latencyMs?: number;
65
+ error?: string;
66
+ }
67
+
68
+ export interface RestoreOptions {
69
+ purge?: boolean;
70
+ }
71
+
72
+ export interface RestoreResult {
73
+ restoredText: string;
74
+ tokensRestored: number;
75
+ purged: boolean;
76
+ }
77
+
78
+ export interface WaitForJobOptions {
79
+ pollIntervalMs?: number;
80
+ timeoutMs?: number;
81
+ }
82
+
83
+ export interface ProtectOptions extends MaskOptions {
84
+ /** Default true — purge vault after restore (data minimisation). */
85
+ purge?: boolean;
86
+ }
87
+ export interface ProtectContext {
88
+ sessionId: string;
89
+ entitiesFound: any[];
90
+ }
91
+ export interface ProtectResult {
92
+ /** Unmasked LLM response — return THIS to your end user. */
93
+ output: string;
94
+ /** What was actually sent to the LLM (placeholder version, for audit). */
95
+ maskedInput: string;
96
+ /** What the LLM returned, before unmask (audit). */
97
+ maskedOutput: string;
98
+ sessionId: string;
99
+ entitiesFound: any[];
100
+ tokensRestored: number;
101
+ }
102
+ export type ProtectLLMCall = (masked: string, ctx: ProtectContext) => Promise<string>;
103
+
104
+ export declare class ScanResource {
105
+ mask(text: string, opts?: MaskOptions): Promise<MaskResult>;
106
+ maskAsync(text: string, opts?: MaskAsyncOptions): Promise<MaskAsyncResult>;
107
+ getJob(jobId: string): Promise<JobResult>;
108
+ waitForJob(jobId: string, opts?: WaitForJobOptions): Promise<JobResult>;
109
+ restore(maskedText: string, sessionId: string, opts?: RestoreOptions): Promise<RestoreResult>;
110
+ /** mask → LLM call → restore round-trip in one call. */
111
+ protect(userInput: string, llmCall: ProtectLLMCall, opts?: ProtectOptions): Promise<ProtectResult>;
112
+ }
113
+
114
+ // ── Auth ─────────────────────────────────────────────────────────────────────
115
+
116
+ export interface RegisterResult {
117
+ token: string;
118
+ apiKey: string;
119
+ user: { id: string; email: string; name: string };
120
+ }
121
+
122
+ export interface LoginResult {
123
+ token: string;
124
+ user: { id: string; email: string; name: string; role: UserRole };
125
+ }
126
+
127
+ export interface ApiKey {
128
+ id: string;
129
+ name: string;
130
+ prefix: string;
131
+ scopes: string[];
132
+ isActive: boolean;
133
+ createdAt: string;
134
+ lastUsedAt?: string;
135
+ }
136
+
137
+ export declare class AuthResource {
138
+ register(email: string, password: string, name: string): Promise<RegisterResult>;
139
+ login(email: string, password: string): Promise<LoginResult>;
140
+ createApiKey(opts?: { name?: string; scopes?: string[] }): Promise<{ apiKey: string; key: ApiKey }>;
141
+ listApiKeys(): Promise<{ apiKeys: ApiKey[] }>;
142
+ revokeApiKey(id: string): Promise<void>;
143
+ }
144
+
145
+ // ── Metrics ───────────────────────────────────────────────────────────────────
146
+
147
+ export type TimeRange = '7d' | '30d' | '90d';
148
+
149
+ export interface SummaryResult {
150
+ totalEvents: number;
151
+ totalMasked: number;
152
+ uniqueSessions: number;
153
+ avgLatencyMs: number;
154
+ }
155
+
156
+ export interface TimeseriesPoint {
157
+ date: string;
158
+ events: number;
159
+ masked: number;
160
+ }
161
+
162
+ export interface BreakdownItem {
163
+ label: string;
164
+ count: number;
165
+ }
166
+
167
+ export interface DetectionEvent {
168
+ id: string;
169
+ sessionId: string;
170
+ source: Source;
171
+ surface: Surface;
172
+ totalMasked: number;
173
+ scanLatencyMs: number;
174
+ createdAt: string;
175
+ }
176
+
177
+ export interface ComplianceReport {
178
+ from: string;
179
+ to: string;
180
+ totalEvents: number;
181
+ totalMasked: number;
182
+ bySource: BreakdownItem[];
183
+ bySurface: BreakdownItem[];
184
+ }
185
+
186
+ export interface ApiKeyBreakdown {
187
+ keyName: string;
188
+ keyPrefix: string;
189
+ events: number;
190
+ piiMasked: number;
191
+ avgLatencyMs: number;
192
+ lastUsed: string;
193
+ }
194
+
195
+ export interface LatencyPercentilePoint {
196
+ day: string;
197
+ p50: number;
198
+ p95: number;
199
+ p99: number;
200
+ events: number;
201
+ }
202
+
203
+ export interface PeakHourPoint {
204
+ dow: number;
205
+ hour: number;
206
+ events: number;
207
+ }
208
+
209
+ export declare class MetricsResource {
210
+ summary(): Promise<SummaryResult>;
211
+ timeseries(opts?: { range?: TimeRange }): Promise<{ data: TimeseriesPoint[] }>;
212
+ byEntity(): Promise<{ data: BreakdownItem[] }>;
213
+ bySurface(): Promise<{ data: BreakdownItem[] }>;
214
+ bySource(): Promise<{ data: BreakdownItem[] }>;
215
+ byDeveloper(): Promise<{ data: BreakdownItem[] }>;
216
+ recentEvents(opts?: { limit?: number; offset?: number }): Promise<{ events: DetectionEvent[]; total: number }>;
217
+ eventDetail(eventId: string): Promise<{ event: DetectionEvent }>;
218
+ byApiKey(): Promise<{ by_api_key: ApiKeyBreakdown[] }>;
219
+ latencyPercentiles(): Promise<{ latency_percentiles: LatencyPercentilePoint[] }>;
220
+ peakHours(): Promise<{ peak_hours: PeakHourPoint[] }>;
221
+ complianceReport(opts?: { from?: string; to?: string }): Promise<ComplianceReport>;
222
+ }
223
+
224
+ // ── Tenant ────────────────────────────────────────────────────────────────────
225
+
226
+ export interface TenantProfile {
227
+ id: string;
228
+ name: string;
229
+ plan: Plan;
230
+ status: 'active' | 'suspended';
231
+ seats: number;
232
+ settings: Record<string, unknown>;
233
+ }
234
+
235
+ export interface TeamMember {
236
+ id: string;
237
+ email: string;
238
+ name: string;
239
+ role: UserRole;
240
+ joinedAt: string;
241
+ }
242
+
243
+ export declare class TenantResource {
244
+ profile(): Promise<TenantProfile>;
245
+ members(): Promise<{ members: TeamMember[] }>;
246
+ invite(email: string, role?: UserRole): Promise<void>;
247
+ updateSettings(settings: Record<string, unknown>): Promise<TenantProfile>;
248
+ }
249
+
250
+ // ── CiphyrsClient ─────────────────────────────────────────────────────────────
251
+
252
+ export interface CiphyrsClientOptions {
253
+ /** API key (cyp_live_...) — for server-side integrations */
254
+ apiKey?: string;
255
+ /** JWT token — for dashboard / management endpoints */
256
+ token?: string;
257
+ /** Override gateway URL for VPC or on-prem deployments */
258
+ baseUrl?: string;
259
+ /** Override dashboard API URL */
260
+ dashUrl?: string;
261
+ /** Request timeout in milliseconds (default: 10000) */
262
+ timeout?: number;
263
+ }
264
+
265
+ // ── V58 Guard ────────────────────────────────────────────────────────────
266
+ export type GuardDecision = 'allow' | 'block' | 'review';
267
+ export type GuardPolicyMode = 'block_attacks' | 'block_critical' | 'review' | 'observe';
268
+ export interface GuardCheckParams {
269
+ input?: string;
270
+ output?: string;
271
+ agentName?: string;
272
+ traceId?: string;
273
+ spanId?: string;
274
+ sessionId?: string;
275
+ userId?: string;
276
+ operationName?: string;
277
+ policyOverride?: GuardPolicyMode;
278
+ }
279
+ export interface GuardCheckResult {
280
+ decision_id: string;
281
+ decision: GuardDecision;
282
+ reason: string | null;
283
+ policy_mode: GuardPolicyMode;
284
+ detections: Array<{
285
+ attack_type: string;
286
+ severity: string;
287
+ confidence: number;
288
+ pattern_id: string;
289
+ pattern_name: string;
290
+ source_kind: string;
291
+ }>;
292
+ highest_severity: string | null;
293
+ highest_attack_type: string | null;
294
+ detections_count: number;
295
+ classifier_ms: number;
296
+ total_ms: number;
297
+ }
298
+ export interface GuardWrapResult {
299
+ blocked: boolean;
300
+ output: string | null;
301
+ reason?: string;
302
+ decision: GuardDecision;
303
+ detections?: GuardCheckResult['detections'];
304
+ decision_id: string;
305
+ }
306
+ export type GuardLLMCall = (input: string) => Promise<string>;
307
+
308
+ export declare class GuardResource {
309
+ check(params: GuardCheckParams): Promise<GuardCheckResult>;
310
+ wrap(userInput: string, llmCall: GuardLLMCall, opts?: GuardCheckParams): Promise<GuardWrapResult>;
311
+ getPolicy(): Promise<{ policy_mode: GuardPolicyMode; modes: any[] }>;
312
+ setPolicy(mode: GuardPolicyMode): Promise<{ policy_mode: GuardPolicyMode }>;
313
+ decisions(opts?: { limit?: number; decision?: GuardDecision }): Promise<{ decisions: any[]; total: number }>;
314
+ stats(opts?: { days?: number }): Promise<any>;
315
+ }
316
+
317
+ // ── V55-V59 Security ─────────────────────────────────────────────────────
318
+ export declare class SecurityResource {
319
+ // Detections
320
+ listDetections(params?: { days?: number; limit?: number; severity?: string; attack_type?: string; status?: string; agent_name?: string }): Promise<{ detections: any[]; total: number }>;
321
+ detectionSummary(opts?: { days?: number }): Promise<any>;
322
+ detectionTimeseries(opts?: { days?: number }): Promise<any>;
323
+ detectionsByTrace(traceId: string): Promise<{ trace_id: string; detections: any[]; total: number }>;
324
+ detectionContext(detectionId: string): Promise<any>;
325
+ setDetectionStatus(id: string, status: string, note?: string): Promise<any>;
326
+ // Custom rules
327
+ listRules(): Promise<{ rules: any[]; total: number }>;
328
+ createRule(rule: any): Promise<{ rule: any }>;
329
+ updateRule(id: string, rule: any): Promise<{ rule: any }>;
330
+ deleteRule(id: string): Promise<void>;
331
+ // Canaries
332
+ listCanaries(): Promise<{ canaries: any[]; total: number }>;
333
+ createCanary(canary: { name: string; token?: string; scope?: string; severity?: string; attack_type?: string; environment?: string }): Promise<{ canary: any; token: string; notice: string }>;
334
+ deleteCanary(id: string): Promise<void>;
335
+ // Threat intel
336
+ listIntelFeeds(): Promise<{ feeds: any[]; total: number }>;
337
+ refreshIntelFeed(id: string): Promise<{ result: any }>;
338
+ // Marketplace
339
+ marketplaceList(params?: { q?: string; category?: string; attack_type?: string }): Promise<{ rules: any[]; total: number }>;
340
+ marketplaceInstall(id: string): Promise<{ rule_id: string; notice: string }>;
341
+ // Benchmark
342
+ runBenchmark(target?: string): Promise<{ run: any }>;
343
+ benchmarkRuns(): Promise<{ runs: any[]; total: number }>;
344
+ // SIEM
345
+ listSiemTargets(): Promise<{ targets: any[]; total: number }>;
346
+ createSiemTarget(target: any): Promise<{ target: any }>;
347
+ testSiemTarget(id: string): Promise<{ result: any }>;
348
+ // Replay
349
+ listReplayJobs(): Promise<{ jobs: any[]; total: number }>;
350
+ createReplayJob(body: { pattern_id?: string; rule_id?: string; range_start: string; range_end: string }): Promise<{ job: any }>;
351
+ }
352
+
353
+ // ── V54 Reports ──────────────────────────────────────────────────────────
354
+ export declare class ReportsResource {
355
+ generateProd(opts: { title?: string; rangeStart: string | Date; rangeEnd: string | Date; sections?: string[]; format?: 'pdf' | 'csv' | 'json' }): Promise<{ report: any }>;
356
+ listProd(): Promise<{ reports: any[]; total: number }>;
357
+ downloadProdPdf(reportId: string): Promise<Blob | Buffer>;
358
+ downloadTestRunPdf(runId: string): Promise<Blob | Buffer>;
359
+ share(reportId: string, ttlDays?: number): Promise<{ share_token: string; share_expires_at: string; share_url_path: string }>;
360
+ archive(reportId: string): Promise<void>;
361
+ }
362
+
363
+ export declare class CiphyrsClient {
364
+ readonly scan: ScanResource;
365
+ readonly auth: AuthResource;
366
+ readonly metrics: MetricsResource;
367
+ readonly tenant: TenantResource;
368
+ // V54-V59 — security platform
369
+ readonly guard: GuardResource;
370
+ readonly security: SecurityResource;
371
+ readonly reports: ReportsResource;
372
+
373
+ constructor(opts: CiphyrsClientOptions);
374
+
375
+ // Top-level shortcuts
376
+ mask(text: string, opts?: MaskOptions): Promise<MaskResult>;
377
+ restore(maskedText: string, sessionId: string, opts?: RestoreOptions): Promise<RestoreResult>;
378
+ protect(userInput: string, llmCall: ProtectLLMCall, opts?: ProtectOptions): Promise<ProtectResult>;
379
+ maskAsync(text: string, opts?: MaskAsyncOptions): Promise<MaskAsyncResult>;
380
+ waitForJob(jobId: string, opts?: WaitForJobOptions): Promise<JobResult>;
381
+ createKey(opts?: { name?: string; scopes?: string[] }): Promise<{ apiKey: string; key: ApiKey }>;
382
+ }