@ethitrust/sdk 1.0.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +177 -0
  3. package/dist/client.d.ts +42 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +45 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/errors.d.ts +66 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +115 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/http.d.ts +49 -0
  12. package/dist/http.d.ts.map +1 -0
  13. package/dist/http.js +193 -0
  14. package/dist/http.js.map +1 -0
  15. package/dist/index.d.ts +10 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +7 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/resources/orgEscrows.d.ts +53 -0
  20. package/dist/resources/orgEscrows.d.ts.map +1 -0
  21. package/dist/resources/orgEscrows.js +168 -0
  22. package/dist/resources/orgEscrows.js.map +1 -0
  23. package/dist/types.d.ts +229 -0
  24. package/dist/types.d.ts.map +1 -0
  25. package/dist/types.js +6 -0
  26. package/dist/types.js.map +1 -0
  27. package/dist/utils/idempotency.d.ts +9 -0
  28. package/dist/utils/idempotency.d.ts.map +1 -0
  29. package/dist/utils/idempotency.js +25 -0
  30. package/dist/utils/idempotency.js.map +1 -0
  31. package/dist/utils/query.d.ts +8 -0
  32. package/dist/utils/query.d.ts.map +1 -0
  33. package/dist/utils/query.js +35 -0
  34. package/dist/utils/query.js.map +1 -0
  35. package/package.json +51 -0
  36. package/src/client.ts +69 -0
  37. package/src/errors.ts +140 -0
  38. package/src/http.ts +246 -0
  39. package/src/index.ts +23 -0
  40. package/src/resources/orgEscrows.ts +246 -0
  41. package/src/types.ts +286 -0
  42. package/src/utils/idempotency.ts +23 -0
  43. package/src/utils/query.ts +31 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Typed models for the Ethitrust org-escrows API.
3
+ * Generated by hand from the OpenAPI spec (ethi-mono v0.1.0).
4
+ */
5
+ export type EscrowType = 'onetime' | 'milestone' | 'recurring';
6
+ export type EscrowStatus = 'invited' | 'counter_pending_initiator' | 'counter_pending_counterparty' | 'rejected' | 'expired' | 'pending' | 'active' | 'submitted' | 'in_review' | 'completed' | 'disputed' | 'cancelled' | 'refunded';
7
+ export type InitiatorActorType = 'user' | 'organization';
8
+ export type InitiatorRole = 'buyer' | 'seller';
9
+ export type FeePayer = 'buyer' | 'seller' | 'split';
10
+ export type CounterStatus = 'none' | 'awaiting_initiator' | 'awaiting_counterparty' | 'accepted' | 'rejected';
11
+ export type RiskSeverity = 'low' | 'medium' | 'high';
12
+ export type MilestoneStatus = 'pending' | 'in_progress' | 'delivered' | 'completed' | 'disputed';
13
+ export interface RiskFlag {
14
+ code: string;
15
+ message: string;
16
+ severity: RiskSeverity;
17
+ }
18
+ export interface LatestEvent {
19
+ event_type: string;
20
+ actor: string;
21
+ timestamp: string;
22
+ metadata?: Record<string, unknown> | null;
23
+ }
24
+ export interface EscrowVolumePoint {
25
+ date: string;
26
+ count: number;
27
+ total_amount: number;
28
+ }
29
+ export interface MilestoneRequest {
30
+ title: string;
31
+ description?: string | null;
32
+ amount: number;
33
+ due_date?: string | null;
34
+ /** Defaults to 48 on the server. */
35
+ inspection_hrs?: number;
36
+ }
37
+ export interface MilestoneResponse {
38
+ id: string;
39
+ escrow_id: string;
40
+ title: string;
41
+ description: string | null;
42
+ amount: number;
43
+ due_date: string | null;
44
+ inspection_hrs: number;
45
+ status: MilestoneStatus;
46
+ delivered_at: string | null;
47
+ completed_at: string | null;
48
+ sort_order: number;
49
+ }
50
+ export interface OrganizationInitializeEscrowRequest {
51
+ invitee_email: string;
52
+ /** Defaults to 'onetime'. */
53
+ escrow_type?: EscrowType;
54
+ title: string;
55
+ description?: string | null;
56
+ /** Defaults to 'ETB'. */
57
+ currency?: string;
58
+ amount: number;
59
+ acceptance_criteria?: string | null;
60
+ /** Hours. Defaults to 48. */
61
+ inspection_period?: number;
62
+ delivery_date?: string | null;
63
+ /** Hours. Defaults to 72. */
64
+ dispute_window?: number;
65
+ /** Defaults to 'buyer'. */
66
+ who_pays_fees?: FeePayer;
67
+ milestones?: MilestoneRequest[] | null;
68
+ }
69
+ export interface ListOrgEscrowsParams {
70
+ status?: string;
71
+ is_active?: boolean;
72
+ /** ISO 8601 date-time. */
73
+ date_from?: string | Date;
74
+ /** ISO 8601 date-time. */
75
+ date_to?: string | Date;
76
+ search?: string;
77
+ page?: number;
78
+ page_size?: number;
79
+ }
80
+ export interface OrgEscrowReportParams {
81
+ /** ISO 8601 date-time. */
82
+ date_from?: string | Date;
83
+ /** ISO 8601 date-time. */
84
+ date_to?: string | Date;
85
+ }
86
+ export interface InitializeEscrowResponse {
87
+ id: string;
88
+ escrow_type: EscrowType;
89
+ status: EscrowStatus;
90
+ initiator_actor_type: InitiatorActorType;
91
+ initiator_id: string | null;
92
+ initiator_org_id: string | null;
93
+ receiver_id: string | null;
94
+ receiver_email: string | null;
95
+ initiator_role: InitiatorRole;
96
+ title: string;
97
+ description: string | null;
98
+ currency: string;
99
+ amount: number;
100
+ fee_amount: number;
101
+ acceptance_criteria: string | null;
102
+ inspection_period: number;
103
+ delivery_date: string | null;
104
+ dispute_window: number;
105
+ who_pays_fees: FeePayer;
106
+ org_id: string | null;
107
+ offer_version: number;
108
+ counter_status: CounterStatus;
109
+ active_counter_offer_version: number | null;
110
+ created_at: string;
111
+ updated_at: string;
112
+ invitation_sent?: boolean;
113
+ }
114
+ export interface OrgEscrowCancelResponse extends InitializeEscrowResponse {
115
+ refunded?: boolean;
116
+ }
117
+ export interface OrgEscrowListItem {
118
+ escrow_id: string;
119
+ organization_id: string | null;
120
+ title: string;
121
+ status: string;
122
+ is_active: boolean;
123
+ amount: number;
124
+ currency: string;
125
+ receiver_email?: string | null;
126
+ funded_amount: number;
127
+ created_at: string;
128
+ updated_at: string;
129
+ expires_at?: string | null;
130
+ }
131
+ export interface OrgEscrowListResponse {
132
+ items: OrgEscrowListItem[];
133
+ page: number;
134
+ page_size: number;
135
+ total: number;
136
+ total_pages: number;
137
+ }
138
+ export interface OrgEscrowStatusResponse {
139
+ escrow_id: string;
140
+ organization_id: string | null;
141
+ status: string;
142
+ is_active: boolean;
143
+ can_cancel: boolean;
144
+ can_resend_invite: boolean;
145
+ can_accept: boolean;
146
+ expires_at: string | null;
147
+ funded_amount: number;
148
+ currency: string;
149
+ amount: number;
150
+ updated_at: string;
151
+ }
152
+ export interface OrgEscrowDetailResponse extends OrgEscrowStatusResponse {
153
+ title: string;
154
+ description?: string | null;
155
+ escrow_type: string;
156
+ initiator_role: string;
157
+ receiver_email?: string | null;
158
+ receiver_id?: string | null;
159
+ fee_amount: number;
160
+ who_pays_fees: string;
161
+ created_at: string;
162
+ /** 0-100. */
163
+ progress_percentage: number;
164
+ current_phase: string;
165
+ next_action?: string | null;
166
+ risk_flags?: RiskFlag[];
167
+ latest_event?: LatestEvent | null;
168
+ }
169
+ export interface OrgEscrowHealthResponse {
170
+ escrow_id: string;
171
+ is_active: boolean;
172
+ is_expired: boolean;
173
+ is_fundable: boolean;
174
+ is_cancellable: boolean;
175
+ is_disputable: boolean;
176
+ is_settled: boolean;
177
+ }
178
+ export interface OrgEscrowReportResponse {
179
+ organization_id: string;
180
+ period_from: string;
181
+ period_to: string;
182
+ total_escrows: number;
183
+ active_escrow_count: number;
184
+ completion_rate: number;
185
+ dispute_rate: number;
186
+ avg_settlement_time_hours?: number | null;
187
+ volume_over_time?: EscrowVolumePoint[];
188
+ }
189
+ export interface OrgEscrowAuditEvent {
190
+ event_id: string;
191
+ escrow_id: string;
192
+ actor: string;
193
+ action: string;
194
+ timestamp: string;
195
+ metadata?: Record<string, unknown> | null;
196
+ }
197
+ export interface OrgEscrowAuditTrailResponse {
198
+ escrow_id: string;
199
+ events: OrgEscrowAuditEvent[];
200
+ total: number;
201
+ }
202
+ export interface WebhookLogEntry {
203
+ id: string;
204
+ event_type: string;
205
+ target_url: string;
206
+ http_status: number | null;
207
+ attempt: number;
208
+ delivery_status: string;
209
+ error_message?: string | null;
210
+ created_at: string;
211
+ next_retry_at?: string | null;
212
+ }
213
+ export interface WebhookTestResponse {
214
+ success: boolean;
215
+ http_status?: number | null;
216
+ error?: string | null;
217
+ target_url?: string | null;
218
+ }
219
+ export interface ValidationErrorItem {
220
+ loc: Array<string | number>;
221
+ msg: string;
222
+ type: string;
223
+ input?: unknown;
224
+ ctx?: Record<string, unknown>;
225
+ }
226
+ export interface HTTPValidationError {
227
+ detail?: ValidationErrorItem[];
228
+ }
229
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,2BAA2B,GAC3B,8BAA8B,GAC9B,UAAU,GACV,SAAS,GACT,SAAS,GACT,QAAQ,GACR,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,GACV,WAAW,GACX,UAAU,CAAC;AAEf,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,cAAc,CAAC;AACzD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,CAAC;AAC/C,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AACpD,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,oBAAoB,GACpB,uBAAuB,GACvB,UAAU,GACV,UAAU,CAAC;AACf,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AACrD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,aAAa,GACb,WAAW,GACX,WAAW,GACX,UAAU,CAAC;AAIf,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAA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AmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAID,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAChC"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Typed models for the Ethitrust org-escrows API.
3
+ * Generated by hand from the OpenAPI spec (ethi-mono v0.1.0).
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generate a RFC-4122 v4 idempotency key suitable for the
3
+ * `X-Idempotency-Key` header.
4
+ *
5
+ * Falls back to the Web Crypto API when `node:crypto` is unavailable
6
+ * (e.g. edge runtimes).
7
+ */
8
+ export declare function generateIdempotencyKey(prefix?: string): string;
9
+ //# sourceMappingURL=idempotency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../../src/utils/idempotency.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAa9D"}
@@ -0,0 +1,25 @@
1
+ import { randomUUID, randomBytes } from 'node:crypto';
2
+ /**
3
+ * Generate a RFC-4122 v4 idempotency key suitable for the
4
+ * `X-Idempotency-Key` header.
5
+ *
6
+ * Falls back to the Web Crypto API when `node:crypto` is unavailable
7
+ * (e.g. edge runtimes).
8
+ */
9
+ export function generateIdempotencyKey(prefix) {
10
+ let id;
11
+ try {
12
+ id = randomUUID();
13
+ }
14
+ catch {
15
+ const g = globalThis;
16
+ if (g.crypto?.randomUUID) {
17
+ id = g.crypto.randomUUID();
18
+ }
19
+ else {
20
+ id = randomBytes(16).toString('hex');
21
+ }
22
+ }
23
+ return prefix ? `${prefix}_${id}` : id;
24
+ }
25
+ //# sourceMappingURL=idempotency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../../src/utils/idempotency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAe;IACpD,IAAI,EAAU,CAAC;IACf,IAAI,CAAC;QACH,EAAE,GAAG,UAAU,EAAE,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,CAAC,GAAG,UAAwD,CAAC;QACnE,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;YACzB,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Serialise a flat record to a URLSearchParams instance.
3
+ * - `undefined` / `null` values are skipped.
4
+ * - `Date` objects are serialised to ISO 8601.
5
+ * - Arrays are repeated as `?key=a&key=b`.
6
+ */
7
+ export declare function toQueryString(params: Record<string, unknown> | undefined): string;
8
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/utils/query.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC1C,MAAM,CAgBR"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Serialise a flat record to a URLSearchParams instance.
3
+ * - `undefined` / `null` values are skipped.
4
+ * - `Date` objects are serialised to ISO 8601.
5
+ * - Arrays are repeated as `?key=a&key=b`.
6
+ */
7
+ export function toQueryString(params) {
8
+ if (!params)
9
+ return '';
10
+ const usp = new URLSearchParams();
11
+ for (const [k, v] of Object.entries(params)) {
12
+ if (v === undefined || v === null)
13
+ continue;
14
+ if (Array.isArray(v)) {
15
+ for (const item of v) {
16
+ if (item === undefined || item === null)
17
+ continue;
18
+ usp.append(k, serialiseScalar(item));
19
+ }
20
+ }
21
+ else {
22
+ usp.append(k, serialiseScalar(v));
23
+ }
24
+ }
25
+ const s = usp.toString();
26
+ return s ? `?${s}` : '';
27
+ }
28
+ function serialiseScalar(v) {
29
+ if (v instanceof Date)
30
+ return v.toISOString();
31
+ if (typeof v === 'boolean')
32
+ return v ? 'true' : 'false';
33
+ return String(v);
34
+ }
35
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/utils/query.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA2C;IAE3C,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,IAAI,eAAe,EAAE,CAAC;IAClC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;YAAE,SAAS;QAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC;gBACrB,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;oBAAE,SAAS;gBAClD,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IACD,MAAM,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACzB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,CAAU;IACjC,IAAI,CAAC,YAAY,IAAI;QAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9C,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACxD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@ethitrust/sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official TypeScript/Node SDK for the Ethitrust org-escrows API",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "keywords": [
22
+ "ethitrust",
23
+ "escrow",
24
+ "sdk",
25
+ "api",
26
+ "typescript"
27
+ ],
28
+ "author": "Ethitrust",
29
+ "license": "MIT",
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "devEngines": {
34
+ "packageManager": {
35
+ "name": "pnpm",
36
+ "version": "^11.1.2",
37
+ "onFail": "download"
38
+ }
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^22.19.19",
42
+ "tsx": "^4.22.0",
43
+ "typescript": "^5.6.3"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json",
47
+ "clean": "rm -rf dist",
48
+ "test": "node --test test/*.test.mjs",
49
+ "example": "tsx examples/basic.ts"
50
+ }
51
+ }
package/src/client.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { HttpClient, type HttpClientOptions } from './http.js';
2
+ import { OrgEscrowsResource } from './resources/orgEscrows.js';
3
+
4
+ export interface EthitrustClientOptions {
5
+ /** Organization API key. Sent as `X-API-Key` (configurable). */
6
+ apiKey: string;
7
+ /**
8
+ * Base URL. Defaults to `https://api.ethitrust.me`. Accepts host with or
9
+ * without scheme — if missing, `https://` is assumed.
10
+ */
11
+ baseUrl?: string;
12
+ /** Header carrying the API key. Defaults to `X-API-Key`. */
13
+ apiKeyHeader?: string;
14
+ /** Per-request timeout (ms). Defaults to 30 000. */
15
+ timeoutMs?: number;
16
+ /** Max retries for transient failures (GET / 429 / 5xx). Defaults to 2. */
17
+ maxRetries?: number;
18
+ /** Custom fetch (e.g. undici, node-fetch). */
19
+ fetch?: typeof fetch;
20
+ /** Extra headers applied to every request. */
21
+ defaultHeaders?: Record<string, string>;
22
+ /** User agent string. */
23
+ userAgent?: string;
24
+ }
25
+
26
+ const DEFAULT_BASE_URL = 'https://api.ethitrust.me';
27
+
28
+ /**
29
+ * Top-level entry point.
30
+ *
31
+ * ```ts
32
+ * import { EthitrustClient } from '@ethitrust/sdk';
33
+ * const client = new EthitrustClient({ apiKey: process.env.ETHITRUST_API_KEY! });
34
+ * const escrow = await client.orgEscrows.create({
35
+ * invitee_email: 'buyer@example.com',
36
+ * title: 'Website redesign',
37
+ * amount: 5000,
38
+ * });
39
+ * ```
40
+ */
41
+ export class EthitrustClient {
42
+ readonly http: HttpClient;
43
+ readonly orgEscrows: OrgEscrowsResource;
44
+
45
+ constructor(opts: EthitrustClientOptions) {
46
+ if (!opts.apiKey) {
47
+ throw new Error('EthitrustClient: `apiKey` is required.');
48
+ }
49
+ const baseUrl = normaliseBaseUrl(opts.baseUrl ?? DEFAULT_BASE_URL);
50
+ const httpOpts: HttpClientOptions = {
51
+ apiKey: opts.apiKey,
52
+ apiKeyHeader: opts.apiKeyHeader,
53
+ baseUrl,
54
+ timeoutMs: opts.timeoutMs,
55
+ maxRetries: opts.maxRetries,
56
+ fetch: opts.fetch,
57
+ defaultHeaders: opts.defaultHeaders,
58
+ userAgent: opts.userAgent,
59
+ };
60
+ this.http = new HttpClient(httpOpts);
61
+ this.orgEscrows = new OrgEscrowsResource(this.http);
62
+ }
63
+ }
64
+
65
+ function normaliseBaseUrl(input: string): string {
66
+ const trimmed = input.trim();
67
+ if (/^https?:\/\//i.test(trimmed)) return trimmed;
68
+ return `https://${trimmed}`;
69
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,140 @@
1
+ import type { HTTPValidationError, ValidationErrorItem } from './types.js';
2
+
3
+ /** Base class for every error thrown by the SDK. */
4
+ export class EthitrustError extends Error {
5
+ constructor(message: string) {
6
+ super(message);
7
+ this.name = 'EthitrustError';
8
+ }
9
+ }
10
+
11
+ /** Thrown when the server returns a non-2xx HTTP status. */
12
+ export class EthitrustApiError extends EthitrustError {
13
+ readonly status: number;
14
+ readonly statusText: string;
15
+ readonly requestId?: string;
16
+ readonly url: string;
17
+ readonly method: string;
18
+ readonly body: unknown;
19
+
20
+ constructor(opts: {
21
+ status: number;
22
+ statusText: string;
23
+ url: string;
24
+ method: string;
25
+ body: unknown;
26
+ requestId?: string;
27
+ message?: string;
28
+ }) {
29
+ const detail =
30
+ opts.message ??
31
+ extractMessage(opts.body) ??
32
+ `${opts.status} ${opts.statusText}`;
33
+ super(`Ethitrust API error ${opts.status}: ${detail}`);
34
+ this.name = 'EthitrustApiError';
35
+ this.status = opts.status;
36
+ this.statusText = opts.statusText;
37
+ this.url = opts.url;
38
+ this.method = opts.method;
39
+ this.body = opts.body;
40
+ this.requestId = opts.requestId;
41
+ }
42
+ }
43
+
44
+ /** 422 Unprocessable Entity (FastAPI validation failure). */
45
+ export class EthitrustValidationError extends EthitrustApiError {
46
+ readonly errors: ValidationErrorItem[];
47
+
48
+ constructor(opts: ConstructorParameters<typeof EthitrustApiError>[0]) {
49
+ super(opts);
50
+ this.name = 'EthitrustValidationError';
51
+ const body = opts.body as HTTPValidationError | undefined;
52
+ this.errors = body?.detail ?? [];
53
+ }
54
+ }
55
+
56
+ /** 401 / 403 — invalid or insufficient credentials. */
57
+ export class EthitrustAuthError extends EthitrustApiError {
58
+ constructor(opts: ConstructorParameters<typeof EthitrustApiError>[0]) {
59
+ super(opts);
60
+ this.name = 'EthitrustAuthError';
61
+ }
62
+ }
63
+
64
+ /** 404. */
65
+ export class EthitrustNotFoundError extends EthitrustApiError {
66
+ constructor(opts: ConstructorParameters<typeof EthitrustApiError>[0]) {
67
+ super(opts);
68
+ this.name = 'EthitrustNotFoundError';
69
+ }
70
+ }
71
+
72
+ /** 409 — idempotency or business-rule conflict. */
73
+ export class EthitrustConflictError extends EthitrustApiError {
74
+ constructor(opts: ConstructorParameters<typeof EthitrustApiError>[0]) {
75
+ super(opts);
76
+ this.name = 'EthitrustConflictError';
77
+ }
78
+ }
79
+
80
+ /** 429 — too many requests. */
81
+ export class EthitrustRateLimitError extends EthitrustApiError {
82
+ readonly retryAfter?: number;
83
+ constructor(
84
+ opts: ConstructorParameters<typeof EthitrustApiError>[0] & {
85
+ retryAfter?: number;
86
+ },
87
+ ) {
88
+ super(opts);
89
+ this.name = 'EthitrustRateLimitError';
90
+ this.retryAfter = opts.retryAfter;
91
+ }
92
+ }
93
+
94
+ /** Network / fetch / timeout level failure. */
95
+ export class EthitrustNetworkError extends EthitrustError {
96
+ readonly cause?: unknown;
97
+ constructor(message: string, cause?: unknown) {
98
+ super(message);
99
+ this.name = 'EthitrustNetworkError';
100
+ this.cause = cause;
101
+ }
102
+ }
103
+
104
+ /** Request was aborted (timeout or user signal). */
105
+ export class EthitrustAbortError extends EthitrustError {
106
+ constructor(message = 'Request aborted') {
107
+ super(message);
108
+ this.name = 'EthitrustAbortError';
109
+ }
110
+ }
111
+
112
+ function extractMessage(body: unknown): string | undefined {
113
+ if (!body || typeof body !== 'object') return undefined;
114
+ const b = body as Record<string, unknown>;
115
+ if (typeof b.message === 'string') return b.message;
116
+ if (typeof b.error === 'string') return b.error;
117
+ if (typeof b.detail === 'string') return b.detail;
118
+ if (Array.isArray(b.detail) && b.detail.length > 0) {
119
+ const first = b.detail[0] as ValidationErrorItem;
120
+ return `${first.msg} (at ${first.loc?.join('.') ?? '?'})`;
121
+ }
122
+ return undefined;
123
+ }
124
+
125
+ export function buildApiError(opts: {
126
+ status: number;
127
+ statusText: string;
128
+ url: string;
129
+ method: string;
130
+ body: unknown;
131
+ requestId?: string;
132
+ retryAfter?: number;
133
+ }): EthitrustApiError {
134
+ if (opts.status === 401 || opts.status === 403) return new EthitrustAuthError(opts);
135
+ if (opts.status === 404) return new EthitrustNotFoundError(opts);
136
+ if (opts.status === 409) return new EthitrustConflictError(opts);
137
+ if (opts.status === 422) return new EthitrustValidationError(opts);
138
+ if (opts.status === 429) return new EthitrustRateLimitError(opts);
139
+ return new EthitrustApiError(opts);
140
+ }