@forg3t/sdk 0.1.0 → 0.1.2
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/README.md +60 -0
- package/dist/index.d.mts +64 -15
- package/dist/index.d.ts +64 -15
- package/dist/index.js +102 -9
- package/dist/index.mjs +109 -9
- package/package.json +3 -4
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @forg3t/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the Forg3t Protocol. This SDK allows you to interact with the Forg3t Control Plane to manage projects, submit jobs, verify evidence, and handle webhooks.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @forg3t/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @forg3t/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @forg3t/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Initialize the client with your project's API key.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { Forg3tClient } from '@forg3t/sdk';
|
|
21
|
+
|
|
22
|
+
const client = new Forg3tClient({
|
|
23
|
+
apiUrl: 'https://api.forg3t.io', // or your self-hosted instance
|
|
24
|
+
apiKey: 'f3_sk_...',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
// Get Project Overview
|
|
29
|
+
const project = await client.getProjectOverview('your-project-id');
|
|
30
|
+
console.log('Project:', project);
|
|
31
|
+
|
|
32
|
+
// Submit a Job
|
|
33
|
+
const job = await client.submitJob('your-project-id', {
|
|
34
|
+
type: 'unlearning',
|
|
35
|
+
parameters: {
|
|
36
|
+
modelId: 'llama-2-7b',
|
|
37
|
+
datasetId: 'copyrighted-books-subset'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
console.log('Job Submitted:', job.id);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main().catch(console.error);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- **Project Management**: View project details and stats.
|
|
49
|
+
- **Job Submission**: Submit unlearning and verification jobs.
|
|
50
|
+
- **Evidence Retrieval**: Fetch cryptographic evidence and PDF reports.
|
|
51
|
+
- **API Key Management**: Create, rotate, and revoke API keys programmatically.
|
|
52
|
+
- **Webhooks**: Manage and replay webhook deliveries.
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
|
|
56
|
+
For full documentation, visit [docs.forg3t.io](https://docs.forg3t.io).
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -55,24 +55,48 @@ interface AuditEventListResponse {
|
|
|
55
55
|
events: AuditEvent[];
|
|
56
56
|
nextCursor?: string;
|
|
57
57
|
}
|
|
58
|
+
type JobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'aborted';
|
|
59
|
+
type JobType = 'VERIFY' | 'RAG_UNLEARN' | 'ADAPTER_UNLEARN' | 'MODEL_UNLEARN';
|
|
60
|
+
type ClaimType = 'PII' | 'CONCEPT' | 'ENTITY' | 'DOCUMENT' | 'EMBEDDING_CLUSTER';
|
|
61
|
+
type ClaimScope = 'global' | 'project' | 'tenant' | 'adapter' | 'index';
|
|
62
|
+
type ClaimAssertion = 'must_not_be_recalled' | 'must_be_refused' | 'must_return_null';
|
|
63
|
+
interface UnlearningClaim {
|
|
64
|
+
claim_type: ClaimType;
|
|
65
|
+
claim_payload: string;
|
|
66
|
+
scope: ClaimScope;
|
|
67
|
+
assertion: ClaimAssertion;
|
|
68
|
+
}
|
|
69
|
+
interface JobConfig {
|
|
70
|
+
target_adapter: string;
|
|
71
|
+
target_config: Record<string, any>;
|
|
72
|
+
sensitivity: string;
|
|
73
|
+
parameters: Record<string, any>;
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}
|
|
58
76
|
interface Job {
|
|
59
77
|
id: string;
|
|
60
78
|
projectId: string;
|
|
61
|
-
type:
|
|
62
|
-
status:
|
|
63
|
-
payload:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
type: JobType;
|
|
80
|
+
status: JobStatus;
|
|
81
|
+
payload: {
|
|
82
|
+
claim: UnlearningClaim;
|
|
83
|
+
config: JobConfig;
|
|
84
|
+
};
|
|
85
|
+
result?: {
|
|
86
|
+
final_verdict?: 'PASS' | 'FAIL';
|
|
87
|
+
report_hash?: string;
|
|
88
|
+
false_positive_rate?: number;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
} | null;
|
|
91
|
+
created_at: string;
|
|
92
|
+
updated_at: string;
|
|
93
|
+
started_at?: string | null;
|
|
94
|
+
completed_at?: string | null;
|
|
71
95
|
}
|
|
72
96
|
interface SubmitJobRequest {
|
|
73
|
-
type:
|
|
74
|
-
|
|
75
|
-
|
|
97
|
+
type: JobType;
|
|
98
|
+
claim: UnlearningClaim;
|
|
99
|
+
config: JobConfig;
|
|
76
100
|
}
|
|
77
101
|
interface ClaimJobsRequest {
|
|
78
102
|
limit?: number;
|
|
@@ -129,6 +153,14 @@ interface EvidenceArtifact {
|
|
|
129
153
|
createdAt: string;
|
|
130
154
|
artifacts: unknown[];
|
|
131
155
|
}
|
|
156
|
+
interface EvidencePdfResponse {
|
|
157
|
+
data: Uint8Array;
|
|
158
|
+
headers: {
|
|
159
|
+
'content-type': string;
|
|
160
|
+
'content-disposition': string;
|
|
161
|
+
'x-forg3t-report-hash': string;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
132
164
|
|
|
133
165
|
declare class Forg3tClient {
|
|
134
166
|
private transport;
|
|
@@ -153,11 +185,15 @@ declare class Forg3tClient {
|
|
|
153
185
|
listDeadJobs(projectId: string, requestId?: string): Promise<Job[]>;
|
|
154
186
|
replayJob(projectId: string, jobId: string, requestId?: string): Promise<Job>;
|
|
155
187
|
getEvidence(jobId: string, requestId?: string): Promise<EvidenceArtifact>;
|
|
188
|
+
getEvidencePdf(jobId: string, options?: {
|
|
189
|
+
saveToPath?: string;
|
|
190
|
+
}): Promise<EvidencePdfResponse>;
|
|
191
|
+
private savePdfToFile;
|
|
156
192
|
/**
|
|
157
193
|
* @deprecated The current Control Plane version does not support direct artifact downloads.
|
|
158
194
|
* Please use getEvidence() to retrieve the artifact metadata and content.
|
|
159
195
|
*/
|
|
160
|
-
downloadEvidenceArtifact(
|
|
196
|
+
downloadEvidenceArtifact(_jobId: string, _requestId?: string): Promise<void>;
|
|
161
197
|
listWebhooks(projectId: string, requestId?: string): Promise<Webhook[]>;
|
|
162
198
|
createWebhook(projectId: string, data: CreateWebhookRequest, requestId?: string): Promise<Webhook>;
|
|
163
199
|
updateWebhook(webhookId: string, data: UpdateWebhookRequest, requestId?: string): Promise<Webhook>;
|
|
@@ -166,7 +202,20 @@ declare class Forg3tClient {
|
|
|
166
202
|
enableWebhook(webhookId: string, requestId?: string): Promise<Webhook>;
|
|
167
203
|
disableWebhook(webhookId: string, requestId?: string): Promise<Webhook>;
|
|
168
204
|
listWebhookDeliveries(webhookId: string, filters?: WebhookDeliveryFilters, requestId?: string): Promise<WebhookDelivery[]>;
|
|
205
|
+
registerAgent(name: string, capabilities: string[], requestId?: string): Promise<{
|
|
206
|
+
agentId: string;
|
|
207
|
+
apiKey: string;
|
|
208
|
+
}>;
|
|
169
209
|
replayWebhookDelivery(deliveryId: string, requestId?: string): Promise<WebhookDelivery>;
|
|
210
|
+
pollForVerificationJob(workerId: string, requestId?: string): Promise<{
|
|
211
|
+
job: Job | null;
|
|
212
|
+
}>;
|
|
213
|
+
uploadEvidenceChunk(jobId: string, chunk: any, requestId?: string): Promise<void>;
|
|
214
|
+
finalizeJob(jobId: string, result: {
|
|
215
|
+
final_verdict: string;
|
|
216
|
+
report_hash: string;
|
|
217
|
+
false_positive_rate: number;
|
|
218
|
+
}, requestId?: string): Promise<void>;
|
|
170
219
|
}
|
|
171
220
|
|
|
172
221
|
declare class Forg3tError extends Error {
|
|
@@ -189,4 +238,4 @@ declare class Forg3tApiConnectionError extends Forg3tError {
|
|
|
189
238
|
constructor(message: string);
|
|
190
239
|
}
|
|
191
240
|
|
|
192
|
-
export { type ApiKey, type AuditEvent, type AuditEventFilters, type AuditEventListResponse, type ClaimJobsRequest, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateWebhookRequest, type EvidenceArtifact, Forg3tApiConnectionError, Forg3tAuthenticationError, Forg3tClient, type Forg3tClientOptions, Forg3tError, Forg3tNotFoundError, Forg3tRateLimitError, type Job, type JobError, type JobResult, type PaginationParams, type Project, type SubmitJobRequest, type UpdateWebhookRequest, type Webhook, type WebhookDelivery, type WebhookDeliveryFilters };
|
|
241
|
+
export { type ApiKey, type AuditEvent, type AuditEventFilters, type AuditEventListResponse, type ClaimAssertion, type ClaimJobsRequest, type ClaimScope, type ClaimType, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateWebhookRequest, type EvidenceArtifact, type EvidencePdfResponse, Forg3tApiConnectionError, Forg3tAuthenticationError, Forg3tClient, type Forg3tClientOptions, Forg3tError, Forg3tNotFoundError, Forg3tRateLimitError, type Job, type JobConfig, type JobError, type JobResult, type JobStatus, type JobType, type PaginationParams, type Project, type SubmitJobRequest, type UnlearningClaim, type UpdateWebhookRequest, type Webhook, type WebhookDelivery, type WebhookDeliveryFilters };
|
package/dist/index.d.ts
CHANGED
|
@@ -55,24 +55,48 @@ interface AuditEventListResponse {
|
|
|
55
55
|
events: AuditEvent[];
|
|
56
56
|
nextCursor?: string;
|
|
57
57
|
}
|
|
58
|
+
type JobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'aborted';
|
|
59
|
+
type JobType = 'VERIFY' | 'RAG_UNLEARN' | 'ADAPTER_UNLEARN' | 'MODEL_UNLEARN';
|
|
60
|
+
type ClaimType = 'PII' | 'CONCEPT' | 'ENTITY' | 'DOCUMENT' | 'EMBEDDING_CLUSTER';
|
|
61
|
+
type ClaimScope = 'global' | 'project' | 'tenant' | 'adapter' | 'index';
|
|
62
|
+
type ClaimAssertion = 'must_not_be_recalled' | 'must_be_refused' | 'must_return_null';
|
|
63
|
+
interface UnlearningClaim {
|
|
64
|
+
claim_type: ClaimType;
|
|
65
|
+
claim_payload: string;
|
|
66
|
+
scope: ClaimScope;
|
|
67
|
+
assertion: ClaimAssertion;
|
|
68
|
+
}
|
|
69
|
+
interface JobConfig {
|
|
70
|
+
target_adapter: string;
|
|
71
|
+
target_config: Record<string, any>;
|
|
72
|
+
sensitivity: string;
|
|
73
|
+
parameters: Record<string, any>;
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}
|
|
58
76
|
interface Job {
|
|
59
77
|
id: string;
|
|
60
78
|
projectId: string;
|
|
61
|
-
type:
|
|
62
|
-
status:
|
|
63
|
-
payload:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
type: JobType;
|
|
80
|
+
status: JobStatus;
|
|
81
|
+
payload: {
|
|
82
|
+
claim: UnlearningClaim;
|
|
83
|
+
config: JobConfig;
|
|
84
|
+
};
|
|
85
|
+
result?: {
|
|
86
|
+
final_verdict?: 'PASS' | 'FAIL';
|
|
87
|
+
report_hash?: string;
|
|
88
|
+
false_positive_rate?: number;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
} | null;
|
|
91
|
+
created_at: string;
|
|
92
|
+
updated_at: string;
|
|
93
|
+
started_at?: string | null;
|
|
94
|
+
completed_at?: string | null;
|
|
71
95
|
}
|
|
72
96
|
interface SubmitJobRequest {
|
|
73
|
-
type:
|
|
74
|
-
|
|
75
|
-
|
|
97
|
+
type: JobType;
|
|
98
|
+
claim: UnlearningClaim;
|
|
99
|
+
config: JobConfig;
|
|
76
100
|
}
|
|
77
101
|
interface ClaimJobsRequest {
|
|
78
102
|
limit?: number;
|
|
@@ -129,6 +153,14 @@ interface EvidenceArtifact {
|
|
|
129
153
|
createdAt: string;
|
|
130
154
|
artifacts: unknown[];
|
|
131
155
|
}
|
|
156
|
+
interface EvidencePdfResponse {
|
|
157
|
+
data: Uint8Array;
|
|
158
|
+
headers: {
|
|
159
|
+
'content-type': string;
|
|
160
|
+
'content-disposition': string;
|
|
161
|
+
'x-forg3t-report-hash': string;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
132
164
|
|
|
133
165
|
declare class Forg3tClient {
|
|
134
166
|
private transport;
|
|
@@ -153,11 +185,15 @@ declare class Forg3tClient {
|
|
|
153
185
|
listDeadJobs(projectId: string, requestId?: string): Promise<Job[]>;
|
|
154
186
|
replayJob(projectId: string, jobId: string, requestId?: string): Promise<Job>;
|
|
155
187
|
getEvidence(jobId: string, requestId?: string): Promise<EvidenceArtifact>;
|
|
188
|
+
getEvidencePdf(jobId: string, options?: {
|
|
189
|
+
saveToPath?: string;
|
|
190
|
+
}): Promise<EvidencePdfResponse>;
|
|
191
|
+
private savePdfToFile;
|
|
156
192
|
/**
|
|
157
193
|
* @deprecated The current Control Plane version does not support direct artifact downloads.
|
|
158
194
|
* Please use getEvidence() to retrieve the artifact metadata and content.
|
|
159
195
|
*/
|
|
160
|
-
downloadEvidenceArtifact(
|
|
196
|
+
downloadEvidenceArtifact(_jobId: string, _requestId?: string): Promise<void>;
|
|
161
197
|
listWebhooks(projectId: string, requestId?: string): Promise<Webhook[]>;
|
|
162
198
|
createWebhook(projectId: string, data: CreateWebhookRequest, requestId?: string): Promise<Webhook>;
|
|
163
199
|
updateWebhook(webhookId: string, data: UpdateWebhookRequest, requestId?: string): Promise<Webhook>;
|
|
@@ -166,7 +202,20 @@ declare class Forg3tClient {
|
|
|
166
202
|
enableWebhook(webhookId: string, requestId?: string): Promise<Webhook>;
|
|
167
203
|
disableWebhook(webhookId: string, requestId?: string): Promise<Webhook>;
|
|
168
204
|
listWebhookDeliveries(webhookId: string, filters?: WebhookDeliveryFilters, requestId?: string): Promise<WebhookDelivery[]>;
|
|
205
|
+
registerAgent(name: string, capabilities: string[], requestId?: string): Promise<{
|
|
206
|
+
agentId: string;
|
|
207
|
+
apiKey: string;
|
|
208
|
+
}>;
|
|
169
209
|
replayWebhookDelivery(deliveryId: string, requestId?: string): Promise<WebhookDelivery>;
|
|
210
|
+
pollForVerificationJob(workerId: string, requestId?: string): Promise<{
|
|
211
|
+
job: Job | null;
|
|
212
|
+
}>;
|
|
213
|
+
uploadEvidenceChunk(jobId: string, chunk: any, requestId?: string): Promise<void>;
|
|
214
|
+
finalizeJob(jobId: string, result: {
|
|
215
|
+
final_verdict: string;
|
|
216
|
+
report_hash: string;
|
|
217
|
+
false_positive_rate: number;
|
|
218
|
+
}, requestId?: string): Promise<void>;
|
|
170
219
|
}
|
|
171
220
|
|
|
172
221
|
declare class Forg3tError extends Error {
|
|
@@ -189,4 +238,4 @@ declare class Forg3tApiConnectionError extends Forg3tError {
|
|
|
189
238
|
constructor(message: string);
|
|
190
239
|
}
|
|
191
240
|
|
|
192
|
-
export { type ApiKey, type AuditEvent, type AuditEventFilters, type AuditEventListResponse, type ClaimJobsRequest, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateWebhookRequest, type EvidenceArtifact, Forg3tApiConnectionError, Forg3tAuthenticationError, Forg3tClient, type Forg3tClientOptions, Forg3tError, Forg3tNotFoundError, Forg3tRateLimitError, type Job, type JobError, type JobResult, type PaginationParams, type Project, type SubmitJobRequest, type UpdateWebhookRequest, type Webhook, type WebhookDelivery, type WebhookDeliveryFilters };
|
|
241
|
+
export { type ApiKey, type AuditEvent, type AuditEventFilters, type AuditEventListResponse, type ClaimAssertion, type ClaimJobsRequest, type ClaimScope, type ClaimType, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateWebhookRequest, type EvidenceArtifact, type EvidencePdfResponse, Forg3tApiConnectionError, Forg3tAuthenticationError, Forg3tClient, type Forg3tClientOptions, Forg3tError, Forg3tNotFoundError, Forg3tRateLimitError, type Job, type JobConfig, type JobError, type JobResult, type JobStatus, type JobType, type PaginationParams, type Project, type SubmitJobRequest, type UnlearningClaim, type UpdateWebhookRequest, type Webhook, type WebhookDelivery, type WebhookDeliveryFilters };
|
package/dist/index.js
CHANGED
|
@@ -205,6 +205,42 @@ var Transport = class {
|
|
|
205
205
|
throw new Forg3tApiConnectionError(error instanceof Error ? error.message : "Network error");
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
+
async requestRaw(path, options = {}, requestId) {
|
|
209
|
+
const url = `${this.baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
210
|
+
const headers = {
|
|
211
|
+
"Accept": "*/*",
|
|
212
|
+
// Accept any type for raw response
|
|
213
|
+
...options.headers || {}
|
|
214
|
+
};
|
|
215
|
+
if (this.apiKey) {
|
|
216
|
+
headers["x-api-key"] = this.apiKey;
|
|
217
|
+
}
|
|
218
|
+
if (requestId) {
|
|
219
|
+
headers["x-request-id"] = requestId;
|
|
220
|
+
}
|
|
221
|
+
const controller = new AbortController();
|
|
222
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
223
|
+
const signal = controller.signal;
|
|
224
|
+
try {
|
|
225
|
+
const response = await fetch(url, {
|
|
226
|
+
...options,
|
|
227
|
+
headers,
|
|
228
|
+
signal
|
|
229
|
+
// Add the abort signal
|
|
230
|
+
});
|
|
231
|
+
clearTimeout(timeoutId);
|
|
232
|
+
return response;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
clearTimeout(timeoutId);
|
|
235
|
+
if (error instanceof Forg3tError) {
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
239
|
+
throw new Forg3tApiConnectionError(`Request timeout after ${this.timeoutMs}ms`);
|
|
240
|
+
}
|
|
241
|
+
throw new Forg3tApiConnectionError(error instanceof Error ? error.message : "Network error");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
208
244
|
};
|
|
209
245
|
|
|
210
246
|
// src/client.ts
|
|
@@ -253,14 +289,6 @@ var Forg3tClient = class {
|
|
|
253
289
|
method: "POST",
|
|
254
290
|
body: JSON.stringify(data)
|
|
255
291
|
}, requestId);
|
|
256
|
-
if (res && res.jobId && !res.id) {
|
|
257
|
-
return {
|
|
258
|
-
...res,
|
|
259
|
-
id: res.jobId,
|
|
260
|
-
projectId
|
|
261
|
-
// Ensure projectId is present if server omits it in minimal response
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
292
|
return res;
|
|
265
293
|
}
|
|
266
294
|
async getJob(projectId, jobId, requestId) {
|
|
@@ -304,11 +332,50 @@ var Forg3tClient = class {
|
|
|
304
332
|
async getEvidence(jobId, requestId) {
|
|
305
333
|
return this.transport.request(`/v1/jobs/evidence/${jobId}`, { method: "GET" }, requestId);
|
|
306
334
|
}
|
|
335
|
+
async getEvidencePdf(jobId, options) {
|
|
336
|
+
const response = await this.transport.requestRaw(`/v1/jobs/${jobId}/evidence.pdf`, { method: "GET" });
|
|
337
|
+
const buffer = await response.arrayBuffer();
|
|
338
|
+
const data = new Uint8Array(buffer);
|
|
339
|
+
const headers = {};
|
|
340
|
+
response.headers.forEach((value, key) => {
|
|
341
|
+
headers[key.toLowerCase()] = value;
|
|
342
|
+
});
|
|
343
|
+
const result = {
|
|
344
|
+
data,
|
|
345
|
+
headers: {
|
|
346
|
+
"content-type": headers["content-type"],
|
|
347
|
+
"content-disposition": headers["content-disposition"],
|
|
348
|
+
"x-forg3t-report-hash": headers["x-forg3t-report-hash"]
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
if (options?.saveToPath) {
|
|
352
|
+
await this.savePdfToFile(data, options.saveToPath);
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
async savePdfToFile(data, filePath) {
|
|
357
|
+
if (typeof global !== "undefined" && typeof require !== "undefined") {
|
|
358
|
+
try {
|
|
359
|
+
const fs = require("fs");
|
|
360
|
+
const path = require("path");
|
|
361
|
+
const dir = path.dirname(filePath);
|
|
362
|
+
if (!fs.existsSync(dir)) {
|
|
363
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
364
|
+
}
|
|
365
|
+
fs.writeFileSync(filePath, Buffer.from(data));
|
|
366
|
+
} catch (error) {
|
|
367
|
+
console.error("Failed to save PDF to file:", error);
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
throw new Error("File saving is only supported in Node.js environment");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
307
374
|
/**
|
|
308
375
|
* @deprecated The current Control Plane version does not support direct artifact downloads.
|
|
309
376
|
* Please use getEvidence() to retrieve the artifact metadata and content.
|
|
310
377
|
*/
|
|
311
|
-
async downloadEvidenceArtifact(
|
|
378
|
+
async downloadEvidenceArtifact(_jobId, _requestId) {
|
|
312
379
|
throw new Error("Artifact download not supported by current API version. Use getEvidence() to retrieve content.");
|
|
313
380
|
}
|
|
314
381
|
// --- Webhooks ---
|
|
@@ -348,9 +415,35 @@ var Forg3tClient = class {
|
|
|
348
415
|
if (filters.offset) params.append("offset", filters.offset.toString());
|
|
349
416
|
return this.transport.request(`/v1/webhooks/${webhookId}/deliveries?${params.toString()}`, { method: "GET" }, requestId);
|
|
350
417
|
}
|
|
418
|
+
// --- Agent Security ---
|
|
419
|
+
async registerAgent(name, capabilities, requestId) {
|
|
420
|
+
return this.transport.request(`/v1/agents/register`, {
|
|
421
|
+
method: "POST",
|
|
422
|
+
body: JSON.stringify({ name, capabilities })
|
|
423
|
+
}, requestId);
|
|
424
|
+
}
|
|
351
425
|
async replayWebhookDelivery(deliveryId, requestId) {
|
|
352
426
|
return this.transport.request(`/v1/webhook-deliveries/${deliveryId}/replay`, { method: "POST" }, requestId);
|
|
353
427
|
}
|
|
428
|
+
// --- Worker / Agent APIs ---
|
|
429
|
+
async pollForVerificationJob(workerId, requestId) {
|
|
430
|
+
return this.transport.request(`/v1/worker/poll`, {
|
|
431
|
+
method: "POST",
|
|
432
|
+
body: JSON.stringify({ workerId })
|
|
433
|
+
}, requestId);
|
|
434
|
+
}
|
|
435
|
+
async uploadEvidenceChunk(jobId, chunk, requestId) {
|
|
436
|
+
return this.transport.request(`/v1/worker/jobs/${jobId}/evidence`, {
|
|
437
|
+
method: "POST",
|
|
438
|
+
body: JSON.stringify(chunk)
|
|
439
|
+
}, requestId);
|
|
440
|
+
}
|
|
441
|
+
async finalizeJob(jobId, result, requestId) {
|
|
442
|
+
return this.transport.request(`/v1/worker/jobs/${jobId}/finalize`, {
|
|
443
|
+
method: "POST",
|
|
444
|
+
body: JSON.stringify(result)
|
|
445
|
+
}, requestId);
|
|
446
|
+
}
|
|
354
447
|
};
|
|
355
448
|
// Annotate the CommonJS export names for ESM import in node:
|
|
356
449
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/errors.ts
|
|
2
9
|
var Forg3tError = class extends Error {
|
|
3
10
|
constructor(message, status, code, requestId, details) {
|
|
@@ -174,6 +181,42 @@ var Transport = class {
|
|
|
174
181
|
throw new Forg3tApiConnectionError(error instanceof Error ? error.message : "Network error");
|
|
175
182
|
}
|
|
176
183
|
}
|
|
184
|
+
async requestRaw(path, options = {}, requestId) {
|
|
185
|
+
const url = `${this.baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
186
|
+
const headers = {
|
|
187
|
+
"Accept": "*/*",
|
|
188
|
+
// Accept any type for raw response
|
|
189
|
+
...options.headers || {}
|
|
190
|
+
};
|
|
191
|
+
if (this.apiKey) {
|
|
192
|
+
headers["x-api-key"] = this.apiKey;
|
|
193
|
+
}
|
|
194
|
+
if (requestId) {
|
|
195
|
+
headers["x-request-id"] = requestId;
|
|
196
|
+
}
|
|
197
|
+
const controller = new AbortController();
|
|
198
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
199
|
+
const signal = controller.signal;
|
|
200
|
+
try {
|
|
201
|
+
const response = await fetch(url, {
|
|
202
|
+
...options,
|
|
203
|
+
headers,
|
|
204
|
+
signal
|
|
205
|
+
// Add the abort signal
|
|
206
|
+
});
|
|
207
|
+
clearTimeout(timeoutId);
|
|
208
|
+
return response;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
clearTimeout(timeoutId);
|
|
211
|
+
if (error instanceof Forg3tError) {
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
215
|
+
throw new Forg3tApiConnectionError(`Request timeout after ${this.timeoutMs}ms`);
|
|
216
|
+
}
|
|
217
|
+
throw new Forg3tApiConnectionError(error instanceof Error ? error.message : "Network error");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
177
220
|
};
|
|
178
221
|
|
|
179
222
|
// src/client.ts
|
|
@@ -222,14 +265,6 @@ var Forg3tClient = class {
|
|
|
222
265
|
method: "POST",
|
|
223
266
|
body: JSON.stringify(data)
|
|
224
267
|
}, requestId);
|
|
225
|
-
if (res && res.jobId && !res.id) {
|
|
226
|
-
return {
|
|
227
|
-
...res,
|
|
228
|
-
id: res.jobId,
|
|
229
|
-
projectId
|
|
230
|
-
// Ensure projectId is present if server omits it in minimal response
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
268
|
return res;
|
|
234
269
|
}
|
|
235
270
|
async getJob(projectId, jobId, requestId) {
|
|
@@ -273,11 +308,50 @@ var Forg3tClient = class {
|
|
|
273
308
|
async getEvidence(jobId, requestId) {
|
|
274
309
|
return this.transport.request(`/v1/jobs/evidence/${jobId}`, { method: "GET" }, requestId);
|
|
275
310
|
}
|
|
311
|
+
async getEvidencePdf(jobId, options) {
|
|
312
|
+
const response = await this.transport.requestRaw(`/v1/jobs/${jobId}/evidence.pdf`, { method: "GET" });
|
|
313
|
+
const buffer = await response.arrayBuffer();
|
|
314
|
+
const data = new Uint8Array(buffer);
|
|
315
|
+
const headers = {};
|
|
316
|
+
response.headers.forEach((value, key) => {
|
|
317
|
+
headers[key.toLowerCase()] = value;
|
|
318
|
+
});
|
|
319
|
+
const result = {
|
|
320
|
+
data,
|
|
321
|
+
headers: {
|
|
322
|
+
"content-type": headers["content-type"],
|
|
323
|
+
"content-disposition": headers["content-disposition"],
|
|
324
|
+
"x-forg3t-report-hash": headers["x-forg3t-report-hash"]
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
if (options?.saveToPath) {
|
|
328
|
+
await this.savePdfToFile(data, options.saveToPath);
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
async savePdfToFile(data, filePath) {
|
|
333
|
+
if (typeof global !== "undefined" && typeof __require !== "undefined") {
|
|
334
|
+
try {
|
|
335
|
+
const fs = __require("fs");
|
|
336
|
+
const path = __require("path");
|
|
337
|
+
const dir = path.dirname(filePath);
|
|
338
|
+
if (!fs.existsSync(dir)) {
|
|
339
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
340
|
+
}
|
|
341
|
+
fs.writeFileSync(filePath, Buffer.from(data));
|
|
342
|
+
} catch (error) {
|
|
343
|
+
console.error("Failed to save PDF to file:", error);
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
throw new Error("File saving is only supported in Node.js environment");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
276
350
|
/**
|
|
277
351
|
* @deprecated The current Control Plane version does not support direct artifact downloads.
|
|
278
352
|
* Please use getEvidence() to retrieve the artifact metadata and content.
|
|
279
353
|
*/
|
|
280
|
-
async downloadEvidenceArtifact(
|
|
354
|
+
async downloadEvidenceArtifact(_jobId, _requestId) {
|
|
281
355
|
throw new Error("Artifact download not supported by current API version. Use getEvidence() to retrieve content.");
|
|
282
356
|
}
|
|
283
357
|
// --- Webhooks ---
|
|
@@ -317,9 +391,35 @@ var Forg3tClient = class {
|
|
|
317
391
|
if (filters.offset) params.append("offset", filters.offset.toString());
|
|
318
392
|
return this.transport.request(`/v1/webhooks/${webhookId}/deliveries?${params.toString()}`, { method: "GET" }, requestId);
|
|
319
393
|
}
|
|
394
|
+
// --- Agent Security ---
|
|
395
|
+
async registerAgent(name, capabilities, requestId) {
|
|
396
|
+
return this.transport.request(`/v1/agents/register`, {
|
|
397
|
+
method: "POST",
|
|
398
|
+
body: JSON.stringify({ name, capabilities })
|
|
399
|
+
}, requestId);
|
|
400
|
+
}
|
|
320
401
|
async replayWebhookDelivery(deliveryId, requestId) {
|
|
321
402
|
return this.transport.request(`/v1/webhook-deliveries/${deliveryId}/replay`, { method: "POST" }, requestId);
|
|
322
403
|
}
|
|
404
|
+
// --- Worker / Agent APIs ---
|
|
405
|
+
async pollForVerificationJob(workerId, requestId) {
|
|
406
|
+
return this.transport.request(`/v1/worker/poll`, {
|
|
407
|
+
method: "POST",
|
|
408
|
+
body: JSON.stringify({ workerId })
|
|
409
|
+
}, requestId);
|
|
410
|
+
}
|
|
411
|
+
async uploadEvidenceChunk(jobId, chunk, requestId) {
|
|
412
|
+
return this.transport.request(`/v1/worker/jobs/${jobId}/evidence`, {
|
|
413
|
+
method: "POST",
|
|
414
|
+
body: JSON.stringify(chunk)
|
|
415
|
+
}, requestId);
|
|
416
|
+
}
|
|
417
|
+
async finalizeJob(jobId, result, requestId) {
|
|
418
|
+
return this.transport.request(`/v1/worker/jobs/${jobId}/finalize`, {
|
|
419
|
+
method: "POST",
|
|
420
|
+
body: JSON.stringify(result)
|
|
421
|
+
}, requestId);
|
|
422
|
+
}
|
|
323
423
|
};
|
|
324
424
|
export {
|
|
325
425
|
Forg3tApiConnectionError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forg3t/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Official TypeScript SDK for Forg3t Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.mjs",
|
|
11
|
-
"require": "./dist/index.js"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
11
|
+
"require": "./dist/index.js"
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
"engines": {
|
|
@@ -47,4 +46,4 @@
|
|
|
47
46
|
"@types/node": "^20.0.0"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {}
|
|
50
|
-
}
|
|
49
|
+
}
|