@defarm/sdk 0.1.3 → 0.1.5
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/client.js +22 -7
- package/dist/modules.d.ts +7 -1
- package/dist/modules.js +8 -0
- package/dist/types.d.ts +48 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -28,13 +28,28 @@ export class DefarmHttpClient {
|
|
|
28
28
|
if (this.apiKey) {
|
|
29
29
|
headers["x-api-key"] = this.apiKey;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
let response;
|
|
32
|
+
try {
|
|
33
|
+
response = await undiciRequest(url, {
|
|
34
|
+
method,
|
|
35
|
+
headers,
|
|
36
|
+
body: body == null ? undefined : JSON.stringify(body),
|
|
37
|
+
headersTimeout: this.config.timeoutMs,
|
|
38
|
+
bodyTimeout: this.config.timeoutMs,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
43
|
+
if (msg.includes('Headers Timeout') ||
|
|
44
|
+
msg.includes('Body Timeout') ||
|
|
45
|
+
msg.includes('UND_ERR_HEADERS_TIMEOUT') ||
|
|
46
|
+
msg.includes('UND_ERR_BODY_TIMEOUT')) {
|
|
47
|
+
throw new Error(`Request to ${url} timed out after ${this.config.timeoutMs}ms. ` +
|
|
48
|
+
`Check if the gateway is reachable and the service is healthy.`);
|
|
49
|
+
}
|
|
50
|
+
// Enrich other transport errors with URL context
|
|
51
|
+
throw new Error(`Request to ${url} failed: ${msg}`);
|
|
52
|
+
}
|
|
38
53
|
const text = await response.body.text();
|
|
39
54
|
const parsed = text ? safeJsonParse(text) : null;
|
|
40
55
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
package/dist/modules.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DefarmHttpClient } from "./client.js";
|
|
2
|
-
import { AuthResponse, Circuit, DisclosureRequest, DisclosureResponse, Event, Item, ReceiptSummary } from "./types.js";
|
|
2
|
+
import { AuthResponse, Circuit, DisclosureRequest, DisclosureResponse, Event, Item, PartnerIntakeResponse, ReceiptSummary } from "./types.js";
|
|
3
3
|
export declare class AuthApi {
|
|
4
4
|
private readonly http;
|
|
5
5
|
constructor(http: DefarmHttpClient);
|
|
@@ -33,6 +33,12 @@ export declare class ItemsApi {
|
|
|
33
33
|
list(circuitId?: string): Promise<Item[]>;
|
|
34
34
|
show(id: string): Promise<unknown>;
|
|
35
35
|
create(payload: Record<string, unknown>): Promise<unknown>;
|
|
36
|
+
createViaIngestion(payload: {
|
|
37
|
+
source_circuit_id: string;
|
|
38
|
+
item: Record<string, unknown>;
|
|
39
|
+
auto_create_circuit?: boolean;
|
|
40
|
+
fallback_to_source_circuit?: boolean;
|
|
41
|
+
}): Promise<PartnerIntakeResponse>;
|
|
36
42
|
update(id: string, payload: Record<string, unknown>): Promise<unknown>;
|
|
37
43
|
}
|
|
38
44
|
export declare class EventsApi {
|
package/dist/modules.js
CHANGED
|
@@ -65,6 +65,14 @@ export class ItemsApi {
|
|
|
65
65
|
async create(payload) {
|
|
66
66
|
return this.http.request("POST", "/api/items", payload);
|
|
67
67
|
}
|
|
68
|
+
async createViaIngestion(payload) {
|
|
69
|
+
return this.http.request("POST", "/v1/partner/ingestions", {
|
|
70
|
+
source_circuit_id: payload.source_circuit_id,
|
|
71
|
+
auto_create_circuit: payload.auto_create_circuit ?? false,
|
|
72
|
+
fallback_to_source_circuit: payload.fallback_to_source_circuit ?? true,
|
|
73
|
+
items: [payload.item],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
68
76
|
async update(id, payload) {
|
|
69
77
|
return this.http.request("PUT", `/api/items/${id}`, payload);
|
|
70
78
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -43,6 +43,54 @@ export interface Item {
|
|
|
43
43
|
status: string;
|
|
44
44
|
metadata?: Record<string, unknown>;
|
|
45
45
|
}
|
|
46
|
+
export interface PartnerIntakeRoute {
|
|
47
|
+
route_type: string;
|
|
48
|
+
route_value: string;
|
|
49
|
+
circuit_id?: string;
|
|
50
|
+
rows: number;
|
|
51
|
+
status: string;
|
|
52
|
+
items: number;
|
|
53
|
+
}
|
|
54
|
+
export interface PartnerIntakeItem {
|
|
55
|
+
dfid?: string;
|
|
56
|
+
url?: string;
|
|
57
|
+
partner_reference?: string;
|
|
58
|
+
asset_reference?: {
|
|
59
|
+
identifier_type: string;
|
|
60
|
+
value: string;
|
|
61
|
+
};
|
|
62
|
+
routes: PartnerIntakeRoute[];
|
|
63
|
+
}
|
|
64
|
+
export interface PartnerIntakeError {
|
|
65
|
+
row_index?: number;
|
|
66
|
+
partner_reference?: string;
|
|
67
|
+
reason_code: string;
|
|
68
|
+
message: string;
|
|
69
|
+
value_chain?: string;
|
|
70
|
+
identifier_type?: string;
|
|
71
|
+
identifier_value?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface PartnerIntakeResponse {
|
|
74
|
+
dry_run?: boolean;
|
|
75
|
+
ingestion_id?: string;
|
|
76
|
+
summary: {
|
|
77
|
+
status: string;
|
|
78
|
+
total_rows: number;
|
|
79
|
+
processed_rows: number;
|
|
80
|
+
unresolved_rows: number;
|
|
81
|
+
routes: number;
|
|
82
|
+
items: number;
|
|
83
|
+
created_circuits: number;
|
|
84
|
+
impacted_circuits: number;
|
|
85
|
+
items_created: number;
|
|
86
|
+
items_enriched: number;
|
|
87
|
+
events_detected?: number;
|
|
88
|
+
warnings?: string[];
|
|
89
|
+
};
|
|
90
|
+
items: PartnerIntakeItem[];
|
|
91
|
+
errors: PartnerIntakeError[];
|
|
92
|
+
routes: PartnerIntakeRoute[];
|
|
93
|
+
}
|
|
46
94
|
export interface Event {
|
|
47
95
|
id: string;
|
|
48
96
|
event_type: string;
|