@proofrails/sdk 1.4.0 → 1.5.1

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.
@@ -0,0 +1,461 @@
1
+ /**
2
+ * Common types used across the SDK
3
+ */
4
+ type Network = 'coston2' | 'flare';
5
+ type ReceiptStatus = 'pending' | 'anchored' | 'failed';
6
+ interface SDKConfig {
7
+ /** Your ProofRails API key */
8
+ apiKey?: string;
9
+ /** Admin token for administrative operations */
10
+ adminToken?: string;
11
+ /** Network to use (coston2 or flare) */
12
+ network?: Network;
13
+ /** Base URL of the middleware (optional, defaults to production) */
14
+ baseUrl?: string;
15
+ /** Request timeout in milliseconds */
16
+ timeout?: number;
17
+ /** Number of retry attempts for failed requests (default: 3) */
18
+ retries?: number;
19
+ /** Delay between retries in milliseconds (default: 1000) */
20
+ retryDelay?: number;
21
+ }
22
+ interface APIResponse<T> {
23
+ data: T;
24
+ success: boolean;
25
+ error?: string;
26
+ }
27
+ interface PaginatedResponse<T> {
28
+ items: T[];
29
+ total: number;
30
+ page: number;
31
+ limit: number;
32
+ }
33
+ declare class ProofRailsError extends Error {
34
+ code?: string | undefined;
35
+ statusCode?: number | undefined;
36
+ details?: unknown | undefined;
37
+ constructor(message: string, code?: string | undefined, statusCode?: number | undefined, details?: unknown | undefined);
38
+ }
39
+
40
+ /**
41
+ * Core HTTP client for ProofRails API
42
+ */
43
+
44
+ interface RateLimitInfo {
45
+ limit: number;
46
+ remaining: number;
47
+ reset: number;
48
+ resetDate: Date;
49
+ }
50
+ declare class APIClient {
51
+ private baseUrl;
52
+ private apiKey?;
53
+ private adminToken?;
54
+ private timeout;
55
+ private retries;
56
+ private retryDelay;
57
+ private rateLimitInfo;
58
+ constructor(config?: SDKConfig);
59
+ getRateLimitInfo(): RateLimitInfo | null;
60
+ get<T>(endpoint: string, options?: RequestInit): Promise<T>;
61
+ post<T>(endpoint: string, body?: unknown, options?: RequestInit): Promise<T>;
62
+ put<T>(endpoint: string, body?: unknown, options?: RequestInit): Promise<T>;
63
+ delete<T>(endpoint: string, options?: RequestInit): Promise<T>;
64
+ private request;
65
+ private shouldRetry;
66
+ private retryRequest;
67
+ private extractRateLimitInfo;
68
+ setApiKey(apiKey: string): void;
69
+ setAdminToken(adminToken: string): void;
70
+ getBaseUrl(): string;
71
+ }
72
+
73
+ /**
74
+ * Project and API key related types
75
+ */
76
+ interface Project {
77
+ projectId: string;
78
+ label?: string;
79
+ createdAt: string;
80
+ receiptsCount?: number;
81
+ }
82
+ interface APIKey {
83
+ apiKey: string;
84
+ projectId: string;
85
+ label?: string;
86
+ createdAt: string;
87
+ }
88
+ interface CreateProjectOptions {
89
+ label?: string;
90
+ network?: 'coston2' | 'flare';
91
+ baseUrl?: string;
92
+ }
93
+ interface CreateAPIKeyOptions {
94
+ projectId: string;
95
+ label?: string;
96
+ }
97
+ interface WhoAmIResponse {
98
+ projectId: string;
99
+ label?: string;
100
+ }
101
+
102
+ /**
103
+ * Project and API key management module
104
+ */
105
+
106
+ declare class ProjectsModule {
107
+ private client;
108
+ constructor(client: APIClient);
109
+ getInfo(): Promise<WhoAmIResponse>;
110
+ rotateKey(): Promise<APIKey>;
111
+ create(options?: CreateProjectOptions): Promise<APIKey>;
112
+ }
113
+ declare class AdminModule {
114
+ private client;
115
+ constructor(client: APIClient);
116
+ createKey(options: CreateAPIKeyOptions): Promise<APIKey>;
117
+ deleteKey(keyId: string): Promise<void>;
118
+ }
119
+
120
+ /**
121
+ * Receipt related types
122
+ */
123
+
124
+ interface CreateReceiptOptions {
125
+ transactionHash: string;
126
+ chain: Network;
127
+ amount: string | number;
128
+ currency: string;
129
+ sender: string;
130
+ receiver: string;
131
+ reference: string;
132
+ callbackUrl?: string;
133
+ }
134
+ interface Receipt {
135
+ id: string;
136
+ status: ReceiptStatus;
137
+ transactionHash: string;
138
+ chain: Network;
139
+ amount: string;
140
+ currency: string;
141
+ sender: string;
142
+ receiver: string;
143
+ reference: string;
144
+ createdAt: string;
145
+ anchoredAt?: string;
146
+ anchorTx?: string;
147
+ bundleHash?: string;
148
+ projectId?: string;
149
+ onChain?: boolean;
150
+ valid?: boolean;
151
+ }
152
+ interface ReceiptArtifacts {
153
+ pain001Url?: string;
154
+ pain002Url?: string;
155
+ pain007Url?: string;
156
+ pain008Url?: string;
157
+ camt054Url?: string;
158
+ bundleUrl?: string;
159
+ manifestUrl?: string;
160
+ }
161
+ interface ListReceiptsOptions {
162
+ limit?: number;
163
+ page?: number;
164
+ status?: ReceiptStatus;
165
+ }
166
+ interface ReceiptUpdate {
167
+ id: string;
168
+ status: ReceiptStatus;
169
+ anchorTx?: string;
170
+ bundleHash?: string;
171
+ timestamp: string;
172
+ }
173
+
174
+ /**
175
+ * Receipt operations module
176
+ */
177
+
178
+ declare class ReceiptsModule {
179
+ private client;
180
+ constructor(client: APIClient);
181
+ create(options: CreateReceiptOptions): Promise<Receipt>;
182
+ get(receiptId: string): Promise<Receipt>;
183
+ list(options?: ListReceiptsOptions): Promise<PaginatedResponse<Receipt>>;
184
+ getArtifacts(receiptId: string): Promise<ReceiptArtifacts>;
185
+ }
186
+
187
+ /**
188
+ * Verification related types
189
+ */
190
+ interface VerificationResult {
191
+ valid: boolean;
192
+ bundleHash: string;
193
+ onChain: boolean;
194
+ anchorTx?: string;
195
+ blockNumber?: number;
196
+ timestamp?: string;
197
+ signature?: string;
198
+ details?: Record<string, unknown>;
199
+ }
200
+ interface VerificationProof {
201
+ receiptId: string;
202
+ bundleHash: string;
203
+ anchorTx: string;
204
+ blockNumber: number;
205
+ timestamp: string;
206
+ signature: string;
207
+ network: string;
208
+ contractAddress: string;
209
+ }
210
+
211
+ /**
212
+ * Verification module
213
+ */
214
+
215
+ declare class VerificationModule {
216
+ private client;
217
+ constructor(client: APIClient);
218
+ byReceiptId(receiptId: string): Promise<VerificationResult>;
219
+ byUrl(bundleUrl: string): Promise<VerificationResult>;
220
+ byHash(bundleHash: string): Promise<VerificationResult>;
221
+ getProof(receiptId: string): Promise<VerificationProof>;
222
+ }
223
+
224
+ /**
225
+ * ISO 20022 message types
226
+ */
227
+ type ISOMessageType = 'pain.001' | 'pain.002' | 'pain.007' | 'pain.008' | 'camt.052' | 'camt.053' | 'camt.054';
228
+ interface ISOMessage {
229
+ type: ISOMessageType;
230
+ messageId: string;
231
+ url: string;
232
+ createdAt: string;
233
+ }
234
+ interface GenerateStatementOptions {
235
+ dateFrom?: string;
236
+ dateTo?: string;
237
+ accountId?: string;
238
+ }
239
+ interface Statement {
240
+ type: 'camt.052' | 'camt.053';
241
+ url: string;
242
+ downloadUrl: string;
243
+ messageId: string;
244
+ createdAt: string;
245
+ }
246
+
247
+ /**
248
+ * Statements module
249
+ */
250
+
251
+ declare class StatementsModule {
252
+ private client;
253
+ constructor(client: APIClient);
254
+ intraday(options?: GenerateStatementOptions): Promise<Statement>;
255
+ endOfDay(options?: GenerateStatementOptions): Promise<Statement>;
256
+ }
257
+
258
+ /**
259
+ * Events module for live updates
260
+ */
261
+
262
+ interface EventListener {
263
+ stop: () => void;
264
+ }
265
+ declare class EventsModule {
266
+ private client;
267
+ constructor(client: APIClient);
268
+ listen(receiptId: string, callback: (update: ReceiptUpdate) => void): EventListener;
269
+ }
270
+
271
+ /**
272
+ * Embed module for generating embeddable widgets
273
+ */
274
+
275
+ interface EmbedOptions {
276
+ theme?: 'light' | 'dark';
277
+ width?: string;
278
+ height?: string;
279
+ }
280
+ interface WidgetResult {
281
+ iframeHtml: string;
282
+ embedUrl: string;
283
+ }
284
+ declare class EmbedModule {
285
+ private client;
286
+ constructor(client: APIClient);
287
+ widget(receiptId: string, options?: EmbedOptions): WidgetResult;
288
+ fullPage(receiptId: string): string;
289
+ }
290
+
291
+ /**
292
+ * Payment template - For simple payments between two parties
293
+ */
294
+
295
+ interface PaymentTemplateOptions {
296
+ /** Payment amount */
297
+ amount: number;
298
+ /** Who is sending the payment */
299
+ from: string;
300
+ /** Who is receiving the payment */
301
+ to: string;
302
+ /** What the payment is for */
303
+ purpose: string;
304
+ /** Blockchain transaction hash */
305
+ transactionHash: string;
306
+ /** Sender's wallet address (optional, defaults to transaction sender) */
307
+ senderWallet?: string;
308
+ /** Receiver's wallet address (optional, defaults to transaction receiver) */
309
+ receiverWallet?: string;
310
+ /** Chain/network (optional, auto-detected if not provided) */
311
+ chain?: 'coston2' | 'flare';
312
+ /** Currency (optional, auto-detected if not provided) */
313
+ currency?: string;
314
+ }
315
+ declare function createPaymentReceipt(receiptsModule: ReceiptsModule, options: PaymentTemplateOptions): Promise<Receipt>;
316
+
317
+ /**
318
+ * Donation template - For charitable donations
319
+ */
320
+
321
+ interface DonationTemplateOptions {
322
+ /** Donation amount */
323
+ amount: number;
324
+ /** Name of the donor */
325
+ donor: string;
326
+ /** Name of the organization receiving the donation */
327
+ organization: string;
328
+ /** Campaign or cause name */
329
+ campaign: string;
330
+ /** Blockchain transaction hash */
331
+ transactionHash: string;
332
+ /** Donor's wallet address (optional) */
333
+ donorWallet?: string;
334
+ /** Organization's wallet address (optional) */
335
+ organizationWallet?: string;
336
+ }
337
+ declare function createDonationReceipt(receiptsModule: ReceiptsModule, options: DonationTemplateOptions): Promise<Receipt>;
338
+
339
+ /**
340
+ * Escrow template - For escrow releases
341
+ */
342
+
343
+ interface EscrowTemplateOptions {
344
+ /** Amount being released from escrow */
345
+ amount: number;
346
+ /** Buyer's name */
347
+ buyer: string;
348
+ /** Seller's name */
349
+ seller: string;
350
+ /** Escrow identifier */
351
+ escrowId: string;
352
+ /** Reason for release */
353
+ releaseReason: string;
354
+ /** Blockchain transaction hash */
355
+ transactionHash: string;
356
+ /** Buyer's wallet address (optional) */
357
+ buyerWallet?: string;
358
+ /** Seller's wallet address (optional) */
359
+ sellerWallet?: string;
360
+ }
361
+ declare function createEscrowReceipt(receiptsModule: ReceiptsModule, options: EscrowTemplateOptions): Promise<Receipt>;
362
+
363
+ /**
364
+ * Grant template - For grant disbursements
365
+ */
366
+
367
+ interface GrantTemplateOptions {
368
+ /** Grant amount */
369
+ amount: number;
370
+ /** Name of the grantee (recipient) */
371
+ grantee: string;
372
+ /** Name of the grantor (funder) */
373
+ grantor: string;
374
+ /** Grant identifier */
375
+ grantId: string;
376
+ /** Purpose of the grant */
377
+ purpose: string;
378
+ /** Blockchain transaction hash */
379
+ transactionHash: string;
380
+ /** Grantor's wallet address (optional) */
381
+ grantorWallet?: string;
382
+ /** Grantee's wallet address (optional) */
383
+ granteeWallet?: string;
384
+ }
385
+ declare function createGrantReceipt(receiptsModule: ReceiptsModule, options: GrantTemplateOptions): Promise<Receipt>;
386
+
387
+ /**
388
+ * Refund template - For refunds
389
+ */
390
+
391
+ interface RefundTemplateOptions {
392
+ /** Refund amount */
393
+ amount: number;
394
+ /** Original receipt ID being refunded */
395
+ originalPayment: string;
396
+ /** Reason for refund */
397
+ reason: string;
398
+ /** Customer name */
399
+ customer: string;
400
+ /** Blockchain transaction hash */
401
+ transactionHash: string;
402
+ /** Business wallet address (optional) */
403
+ businessWallet?: string;
404
+ /** Customer wallet address (optional) */
405
+ customerWallet?: string;
406
+ }
407
+ declare function createRefundReceipt(receiptsModule: ReceiptsModule, options: RefundTemplateOptions): Promise<Receipt>;
408
+
409
+ /**
410
+ * Main ProofRails SDK class
411
+ */
412
+
413
+ declare class ProofRails {
414
+ private client;
415
+ /** Project and API key management */
416
+ readonly project: ProjectsModule;
417
+ /** Admin operations (requires admin token) */
418
+ readonly admin: AdminModule;
419
+ /** Receipt operations */
420
+ readonly receipts: ReceiptsModule;
421
+ /** Verification operations */
422
+ readonly verify: VerificationModule;
423
+ /** Statement generation */
424
+ readonly statements: StatementsModule;
425
+ /** Live event updates */
426
+ readonly events: EventsModule;
427
+ /** Embeddable widgets */
428
+ readonly embed: EmbedModule;
429
+ /** Beginner-friendly templates */
430
+ readonly templates: {
431
+ payment: (options: PaymentTemplateOptions) => ReturnType<typeof createPaymentReceipt>;
432
+ donation: (options: DonationTemplateOptions) => ReturnType<typeof createDonationReceipt>;
433
+ escrow: (options: EscrowTemplateOptions) => ReturnType<typeof createEscrowReceipt>;
434
+ grant: (options: GrantTemplateOptions) => ReturnType<typeof createGrantReceipt>;
435
+ refund: (options: RefundTemplateOptions) => ReturnType<typeof createRefundReceipt>;
436
+ };
437
+ constructor(config?: SDKConfig);
438
+ /**
439
+ * Create a new project with API key (self-serve)
440
+ * This is a convenience method for beginners
441
+ */
442
+ static createProject(options?: {
443
+ label?: string;
444
+ network?: Network;
445
+ baseUrl?: string;
446
+ }): Promise<{
447
+ client: ProofRails;
448
+ apiKey: string;
449
+ projectId: string;
450
+ }>;
451
+ /**
452
+ * Update the API key for this client
453
+ */
454
+ setApiKey(apiKey: string): void;
455
+ /**
456
+ * Update the admin token for this client
457
+ */
458
+ setAdminToken(adminToken: string): void;
459
+ }
460
+
461
+ export { type APIResponse as A, type CreateProjectOptions as C, type DonationTemplateOptions as D, type EscrowTemplateOptions as E, type GrantTemplateOptions as G, type ISOMessageType as I, type ListReceiptsOptions as L, type Network as N, ProofRails as P, type Receipt as R, type SDKConfig as S, type VerificationResult as V, type WhoAmIResponse as W, type PaymentTemplateOptions as a, type RefundTemplateOptions as b, ProofRailsError as c, type RateLimitInfo as d, type ReceiptStatus as e, type PaginatedResponse as f, type Project as g, type APIKey as h, type CreateAPIKeyOptions as i, type CreateReceiptOptions as j, type ReceiptArtifacts as k, type ReceiptUpdate as l, type ISOMessage as m, type GenerateStatementOptions as n, type Statement as o, type VerificationProof as p };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proofrails/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Beginner-friendly SDK for ProofRails ISO 20022 Middleware - Create blockchain-verifiable payment receipts with zero coding knowledge",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",