@blazium/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.
- package/LICENSE +22 -0
- package/README.md +306 -0
- package/dist/index.d.mts +333 -0
- package/dist/index.d.ts +333 -0
- package/dist/index.js +530 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +503 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare enum BlaziumChain {
|
|
4
|
+
SOL = "SOL",
|
|
5
|
+
TON = "TON",
|
|
6
|
+
BTC = "BTC"
|
|
7
|
+
}
|
|
8
|
+
declare enum BlaziumFiat {
|
|
9
|
+
USD = "USD",
|
|
10
|
+
EUR = "EUR",
|
|
11
|
+
TRY = "TRY"
|
|
12
|
+
}
|
|
13
|
+
declare enum PaymentStatus {
|
|
14
|
+
CREATED = "CREATED",
|
|
15
|
+
PENDING = "PENDING",
|
|
16
|
+
PARTIALLY_PAID = "PARTIALLY_PAID",
|
|
17
|
+
CONFIRMED = "CONFIRMED",
|
|
18
|
+
FAILED = "FAILED",
|
|
19
|
+
EXPIRED = "EXPIRED",
|
|
20
|
+
CANCELLED = "CANCELLED"
|
|
21
|
+
}
|
|
22
|
+
declare enum BlaziumEnvironment {
|
|
23
|
+
PRODUCTION = "production",
|
|
24
|
+
SANDBOX = "sandbox"
|
|
25
|
+
}
|
|
26
|
+
declare enum WithdrawalStatus {
|
|
27
|
+
PENDING = "PENDING",
|
|
28
|
+
PROCESSING = "PROCESSING",
|
|
29
|
+
COMPLETED = "COMPLETED",
|
|
30
|
+
FAILED = "FAILED",
|
|
31
|
+
CANCELLED = "CANCELLED"
|
|
32
|
+
}
|
|
33
|
+
declare const BlaziumConfigSchema: z.ZodObject<{
|
|
34
|
+
apiKey: z.ZodString;
|
|
35
|
+
baseUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
36
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
37
|
+
environment: z.ZodDefault<z.ZodOptional<z.ZodNativeEnum<typeof BlaziumEnvironment>>>;
|
|
38
|
+
webhookSecret: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
apiKey: string;
|
|
41
|
+
baseUrl: string;
|
|
42
|
+
timeout: number;
|
|
43
|
+
environment: BlaziumEnvironment;
|
|
44
|
+
webhookSecret?: string | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
apiKey: string;
|
|
47
|
+
baseUrl?: string | undefined;
|
|
48
|
+
timeout?: number | undefined;
|
|
49
|
+
environment?: BlaziumEnvironment | undefined;
|
|
50
|
+
webhookSecret?: string | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
type BlaziumConfig = z.input<typeof BlaziumConfigSchema>;
|
|
53
|
+
type BlaziumConfigInternal = z.output<typeof BlaziumConfigSchema>;
|
|
54
|
+
interface Payment {
|
|
55
|
+
id: string;
|
|
56
|
+
status: PaymentStatus;
|
|
57
|
+
amount: number;
|
|
58
|
+
currency: string;
|
|
59
|
+
checkoutUrl: string;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
expiresAt: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
updatedAt?: string;
|
|
65
|
+
payCurrency?: BlaziumChain;
|
|
66
|
+
payAmount?: number;
|
|
67
|
+
payAddress?: string;
|
|
68
|
+
txHash?: string;
|
|
69
|
+
networkFee?: number;
|
|
70
|
+
blockHeight?: string;
|
|
71
|
+
confirmedAt?: string;
|
|
72
|
+
addressIndex?: number;
|
|
73
|
+
quotedRate?: number;
|
|
74
|
+
quoteExpiresAt?: string;
|
|
75
|
+
rewardAmount?: number;
|
|
76
|
+
rewardCurrency?: string;
|
|
77
|
+
rewardData?: Record<string, unknown>;
|
|
78
|
+
rewardDelivered?: boolean;
|
|
79
|
+
partialPayment?: {
|
|
80
|
+
amount: number;
|
|
81
|
+
txHash: string;
|
|
82
|
+
detectedAt: string;
|
|
83
|
+
expectedAmount: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
declare const CreatePaymentSchema: z.ZodObject<{
|
|
87
|
+
amount: z.ZodNumber;
|
|
88
|
+
currency: z.ZodString;
|
|
89
|
+
description: z.ZodOptional<z.ZodString>;
|
|
90
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
91
|
+
redirectUrl: z.ZodOptional<z.ZodString>;
|
|
92
|
+
cancelUrl: z.ZodOptional<z.ZodString>;
|
|
93
|
+
expiresIn: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
rewardAmount: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
rewardCurrency: z.ZodOptional<z.ZodString>;
|
|
96
|
+
rewardData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
amount: number;
|
|
99
|
+
currency: string;
|
|
100
|
+
description?: string | undefined;
|
|
101
|
+
metadata?: Record<string, unknown> | undefined;
|
|
102
|
+
redirectUrl?: string | undefined;
|
|
103
|
+
cancelUrl?: string | undefined;
|
|
104
|
+
expiresIn?: number | undefined;
|
|
105
|
+
rewardAmount?: number | undefined;
|
|
106
|
+
rewardCurrency?: string | undefined;
|
|
107
|
+
rewardData?: Record<string, unknown> | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
amount: number;
|
|
110
|
+
currency: string;
|
|
111
|
+
description?: string | undefined;
|
|
112
|
+
metadata?: Record<string, unknown> | undefined;
|
|
113
|
+
redirectUrl?: string | undefined;
|
|
114
|
+
cancelUrl?: string | undefined;
|
|
115
|
+
expiresIn?: number | undefined;
|
|
116
|
+
rewardAmount?: number | undefined;
|
|
117
|
+
rewardCurrency?: string | undefined;
|
|
118
|
+
rewardData?: Record<string, unknown> | undefined;
|
|
119
|
+
}>;
|
|
120
|
+
type CreatePaymentParams = z.infer<typeof CreatePaymentSchema>;
|
|
121
|
+
interface CreatePaymentOptions {
|
|
122
|
+
idempotencyKey?: string;
|
|
123
|
+
}
|
|
124
|
+
declare enum WebhookEventType {
|
|
125
|
+
PAYMENT_CREATED = "payment.created",
|
|
126
|
+
PAYMENT_PENDING = "payment.pending",
|
|
127
|
+
PAYMENT_CONFIRMED = "payment.confirmed",
|
|
128
|
+
PAYMENT_FAILED = "payment.failed",
|
|
129
|
+
PAYMENT_EXPIRED = "payment.expired",
|
|
130
|
+
PAYMENT_PARTIALLY_PAID = "payment.partially_paid"
|
|
131
|
+
}
|
|
132
|
+
interface WebhookPayload {
|
|
133
|
+
id: string;
|
|
134
|
+
webhook_id: string;
|
|
135
|
+
event: WebhookEventType;
|
|
136
|
+
payment_id: string;
|
|
137
|
+
payment: Payment;
|
|
138
|
+
timestamp: string;
|
|
139
|
+
createdAt: string;
|
|
140
|
+
}
|
|
141
|
+
interface PaymentStats {
|
|
142
|
+
total: number;
|
|
143
|
+
confirmed: number;
|
|
144
|
+
pending: number;
|
|
145
|
+
failed: number;
|
|
146
|
+
totalVolume: number;
|
|
147
|
+
currency: string;
|
|
148
|
+
}
|
|
149
|
+
interface PaginatedResponse<T> {
|
|
150
|
+
data: T[];
|
|
151
|
+
pagination: {
|
|
152
|
+
page: number;
|
|
153
|
+
pageSize: number;
|
|
154
|
+
totalPages: number;
|
|
155
|
+
totalItems: number;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
interface ListPaymentsParams {
|
|
159
|
+
status?: PaymentStatus;
|
|
160
|
+
currency?: string;
|
|
161
|
+
page?: number;
|
|
162
|
+
pageSize?: number;
|
|
163
|
+
startDate?: string;
|
|
164
|
+
endDate?: string;
|
|
165
|
+
}
|
|
166
|
+
interface MerchantBalance {
|
|
167
|
+
chain: string;
|
|
168
|
+
totalEarned: string;
|
|
169
|
+
availableBalance: string;
|
|
170
|
+
pendingBalance: string;
|
|
171
|
+
totalWithdrawn: string;
|
|
172
|
+
holdAmount: string;
|
|
173
|
+
settlementPeriodDays: number;
|
|
174
|
+
}
|
|
175
|
+
interface Withdrawal {
|
|
176
|
+
id: string;
|
|
177
|
+
status: WithdrawalStatus;
|
|
178
|
+
amount: string;
|
|
179
|
+
chain: string;
|
|
180
|
+
destinationAddress: string;
|
|
181
|
+
txHash?: string;
|
|
182
|
+
networkFee?: string;
|
|
183
|
+
finalAmount?: string;
|
|
184
|
+
errorMessage?: string;
|
|
185
|
+
requestedAt: string;
|
|
186
|
+
completedAt?: string;
|
|
187
|
+
}
|
|
188
|
+
interface WithdrawalRequest {
|
|
189
|
+
chain: string;
|
|
190
|
+
amount: number;
|
|
191
|
+
destinationAddress: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare class BlaziumError extends Error {
|
|
195
|
+
code: string;
|
|
196
|
+
details?: unknown;
|
|
197
|
+
constructor(message: string, code?: string, details?: unknown);
|
|
198
|
+
/**
|
|
199
|
+
* Convert error to JSON format
|
|
200
|
+
*/
|
|
201
|
+
toJSON(): {
|
|
202
|
+
name: string;
|
|
203
|
+
message: string;
|
|
204
|
+
code: string;
|
|
205
|
+
details: unknown;
|
|
206
|
+
stack: string | undefined;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
declare class AuthenticationError extends BlaziumError {
|
|
210
|
+
constructor(message?: string);
|
|
211
|
+
}
|
|
212
|
+
declare class ValidationError extends BlaziumError {
|
|
213
|
+
constructor(message: string, errors?: unknown);
|
|
214
|
+
}
|
|
215
|
+
declare class NetworkError extends BlaziumError {
|
|
216
|
+
constructor(message?: string);
|
|
217
|
+
}
|
|
218
|
+
declare class RateLimitError extends BlaziumError {
|
|
219
|
+
retryAfter?: number;
|
|
220
|
+
constructor(message?: string, retryAfter?: number);
|
|
221
|
+
}
|
|
222
|
+
declare class TimeoutError extends BlaziumError {
|
|
223
|
+
constructor(message?: string, code?: string);
|
|
224
|
+
}
|
|
225
|
+
declare class APIError extends BlaziumError {
|
|
226
|
+
statusCode: number;
|
|
227
|
+
constructor(message: string, statusCode: number, code?: string);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* ✅ NEW: Payment specific errors
|
|
231
|
+
*/
|
|
232
|
+
declare class PaymentError extends BlaziumError {
|
|
233
|
+
constructor(message: string, code?: string, details?: unknown);
|
|
234
|
+
}
|
|
235
|
+
declare class PaymentNotFoundError extends PaymentError {
|
|
236
|
+
constructor(paymentId: string);
|
|
237
|
+
}
|
|
238
|
+
declare class PaymentExpiredError extends PaymentError {
|
|
239
|
+
constructor(paymentId: string);
|
|
240
|
+
}
|
|
241
|
+
declare class InsufficientPaymentError extends PaymentError {
|
|
242
|
+
constructor(received: number, expected: number);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* ✅ NEW: Webhook specific errors
|
|
246
|
+
*/
|
|
247
|
+
declare class WebhookError extends BlaziumError {
|
|
248
|
+
constructor(message: string, code?: string, details?: unknown);
|
|
249
|
+
}
|
|
250
|
+
declare class InvalidSignatureError extends WebhookError {
|
|
251
|
+
constructor();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class BlaziumPayClient {
|
|
255
|
+
private client;
|
|
256
|
+
private config;
|
|
257
|
+
constructor(config: BlaziumConfig);
|
|
258
|
+
/**
|
|
259
|
+
* Create a new payment with idempotency support.
|
|
260
|
+
*
|
|
261
|
+
* Note: rewardAmount and rewardCurrency are optional metadata fields for developer reference.
|
|
262
|
+
* BlaziumPay does NOT automatically grant rewards - developers must implement their own
|
|
263
|
+
* logic in webhook handlers to grant premium features, add currency, or perform other actions.
|
|
264
|
+
*/
|
|
265
|
+
createPayment(params: CreatePaymentParams, options?: CreatePaymentOptions): Promise<Payment>;
|
|
266
|
+
/**
|
|
267
|
+
* Get payment details
|
|
268
|
+
*/
|
|
269
|
+
getPayment(paymentId: string): Promise<Payment>;
|
|
270
|
+
/**
|
|
271
|
+
* List payments with filters
|
|
272
|
+
*/
|
|
273
|
+
listPayments(params?: ListPaymentsParams): Promise<PaginatedResponse<Payment>>;
|
|
274
|
+
/**
|
|
275
|
+
* Cancel a payment
|
|
276
|
+
*/
|
|
277
|
+
cancelPayment(paymentId: string): Promise<Payment>;
|
|
278
|
+
/**
|
|
279
|
+
* Get payment statistics
|
|
280
|
+
*/
|
|
281
|
+
getStats(): Promise<PaymentStats>;
|
|
282
|
+
/**
|
|
283
|
+
* Get merchant balance for a specific chain
|
|
284
|
+
*/
|
|
285
|
+
getBalance(chain: string): Promise<MerchantBalance>;
|
|
286
|
+
/**
|
|
287
|
+
* Request withdrawal
|
|
288
|
+
*/
|
|
289
|
+
requestWithdrawal(request: WithdrawalRequest): Promise<Withdrawal>;
|
|
290
|
+
/**
|
|
291
|
+
* List withdrawal history
|
|
292
|
+
*/
|
|
293
|
+
listWithdrawals(): Promise<Withdrawal[]>;
|
|
294
|
+
/**
|
|
295
|
+
* Get specific withdrawal status
|
|
296
|
+
*/
|
|
297
|
+
getWithdrawal(withdrawalId: string): Promise<Withdrawal>;
|
|
298
|
+
/**
|
|
299
|
+
* Wait for a payment to be confirmed (Long Polling helper)
|
|
300
|
+
*/
|
|
301
|
+
waitForPayment(paymentId: string, timeoutMs?: number, pollIntervalMs?: number): Promise<Payment>;
|
|
302
|
+
/**
|
|
303
|
+
* Verify webhook signature
|
|
304
|
+
*
|
|
305
|
+
* Note: Only verified webhooks receive events. Unverified webhooks will not receive
|
|
306
|
+
* any webhook events from BlaziumPay. You must verify your webhook endpoint in the
|
|
307
|
+
* dashboard before it will receive events and require signature verification.
|
|
308
|
+
*/
|
|
309
|
+
verifyWebhookSignature(payload: string, signature: string): boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Parse and verify webhook payload
|
|
312
|
+
*
|
|
313
|
+
* @param rawPayload - Raw JSON string of webhook payload
|
|
314
|
+
* @param signature - Signature from HTTP header 'X-Blazium-Signature'
|
|
315
|
+
* @returns Parsed and verified webhook payload
|
|
316
|
+
*
|
|
317
|
+
* Note: Signature is verified from HTTP header, not from payload.
|
|
318
|
+
* Only verified webhooks receive events. Unverified webhooks will not receive
|
|
319
|
+
* any webhook events from BlaziumPay.
|
|
320
|
+
*/
|
|
321
|
+
parseWebhook(rawPayload: string, signature: string): WebhookPayload;
|
|
322
|
+
private normalizePayment;
|
|
323
|
+
private sleep;
|
|
324
|
+
private isFinalStatus;
|
|
325
|
+
isFinal(payment: Payment): boolean;
|
|
326
|
+
isPaid(payment: Payment): boolean;
|
|
327
|
+
isPartiallyPaid(payment: Payment): boolean;
|
|
328
|
+
isExpired(payment: Payment): boolean;
|
|
329
|
+
getPaymentProgress(payment: Payment): number;
|
|
330
|
+
formatAmount(amount: number, currency: string): string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export { APIError, AuthenticationError, BlaziumChain, type BlaziumConfig, type BlaziumConfigInternal, BlaziumConfigSchema, BlaziumEnvironment, BlaziumError, BlaziumFiat, BlaziumPayClient, type CreatePaymentOptions, type CreatePaymentParams, CreatePaymentSchema, InsufficientPaymentError, InvalidSignatureError, type ListPaymentsParams, type MerchantBalance, NetworkError, type PaginatedResponse, type Payment, PaymentError, PaymentExpiredError, PaymentNotFoundError, type PaymentStats, PaymentStatus, RateLimitError, TimeoutError, ValidationError, WebhookError, WebhookEventType, type WebhookPayload, type Withdrawal, type WithdrawalRequest, WithdrawalStatus };
|