@rotateprotocol/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 (74) hide show
  1. package/README.md +453 -0
  2. package/dist/catalog.d.ts +112 -0
  3. package/dist/catalog.d.ts.map +1 -0
  4. package/dist/catalog.js +210 -0
  5. package/dist/catalog.js.map +1 -0
  6. package/dist/components/CheckoutForm.d.ts +86 -0
  7. package/dist/components/CheckoutForm.d.ts.map +1 -0
  8. package/dist/components/CheckoutForm.js +332 -0
  9. package/dist/components/CheckoutForm.js.map +1 -0
  10. package/dist/components/HostedCheckout.d.ts +57 -0
  11. package/dist/components/HostedCheckout.d.ts.map +1 -0
  12. package/dist/components/HostedCheckout.js +414 -0
  13. package/dist/components/HostedCheckout.js.map +1 -0
  14. package/dist/components/PaymentButton.d.ts +80 -0
  15. package/dist/components/PaymentButton.d.ts.map +1 -0
  16. package/dist/components/PaymentButton.js +210 -0
  17. package/dist/components/PaymentButton.js.map +1 -0
  18. package/dist/components/RotateProvider.d.ts +115 -0
  19. package/dist/components/RotateProvider.d.ts.map +1 -0
  20. package/dist/components/RotateProvider.js +264 -0
  21. package/dist/components/RotateProvider.js.map +1 -0
  22. package/dist/components/index.d.ts +17 -0
  23. package/dist/components/index.d.ts.map +1 -0
  24. package/dist/components/index.js +27 -0
  25. package/dist/components/index.js.map +1 -0
  26. package/dist/embed.d.ts +85 -0
  27. package/dist/embed.d.ts.map +1 -0
  28. package/dist/embed.js +313 -0
  29. package/dist/embed.js.map +1 -0
  30. package/dist/hooks.d.ts +156 -0
  31. package/dist/hooks.d.ts.map +1 -0
  32. package/dist/hooks.js +280 -0
  33. package/dist/hooks.js.map +1 -0
  34. package/dist/idl/rotate_connect.json +2572 -0
  35. package/dist/index.d.ts +505 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +1197 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/marketplace.d.ts +257 -0
  40. package/dist/marketplace.d.ts.map +1 -0
  41. package/dist/marketplace.js +433 -0
  42. package/dist/marketplace.js.map +1 -0
  43. package/dist/platform.d.ts +234 -0
  44. package/dist/platform.d.ts.map +1 -0
  45. package/dist/platform.js +268 -0
  46. package/dist/platform.js.map +1 -0
  47. package/dist/react.d.ts +140 -0
  48. package/dist/react.d.ts.map +1 -0
  49. package/dist/react.js +429 -0
  50. package/dist/react.js.map +1 -0
  51. package/dist/store.d.ts +213 -0
  52. package/dist/store.d.ts.map +1 -0
  53. package/dist/store.js +404 -0
  54. package/dist/store.js.map +1 -0
  55. package/dist/webhooks.d.ts +149 -0
  56. package/dist/webhooks.d.ts.map +1 -0
  57. package/dist/webhooks.js +371 -0
  58. package/dist/webhooks.js.map +1 -0
  59. package/package.json +114 -0
  60. package/src/catalog.ts +299 -0
  61. package/src/components/CheckoutForm.tsx +608 -0
  62. package/src/components/HostedCheckout.tsx +675 -0
  63. package/src/components/PaymentButton.tsx +348 -0
  64. package/src/components/RotateProvider.tsx +370 -0
  65. package/src/components/index.ts +26 -0
  66. package/src/embed.ts +408 -0
  67. package/src/hooks.ts +518 -0
  68. package/src/idl/rotate_connect.json +2572 -0
  69. package/src/index.ts +1538 -0
  70. package/src/marketplace.ts +642 -0
  71. package/src/platform.ts +403 -0
  72. package/src/react.ts +459 -0
  73. package/src/store.ts +577 -0
  74. package/src/webhooks.ts +506 -0
package/dist/store.js ADDED
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ /**
3
+ * Rotate Store — Product Catalog, Cart & Checkout
4
+ *
5
+ * A complete store layer that sits on top of the Rotate Protocol.
6
+ * Products and cart state are managed client-side / in your database;
7
+ * only the final payment touches the blockchain.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const store = new RotateStore(sdk, {
12
+ * merchantId: 1000000,
13
+ * platformId: 1000000,
14
+ * currency: 'USD',
15
+ * });
16
+ *
17
+ * store.addProduct({ id: 'tshirt-01', name: 'Logo Tee', price: 29.99, inventory: 100 });
18
+ * store.addProduct({ id: 'hoodie-01', name: 'Zip Hoodie', price: 59.99, inventory: 50 });
19
+ *
20
+ * const cart = store.createCart();
21
+ * cart.addItem('tshirt-01', 2);
22
+ * cart.addItem('hoodie-01', 1);
23
+ *
24
+ * const session = await cart.checkout(); // creates on-chain payment link
25
+ * console.log(session.linkId, session.paymentUrl);
26
+ * ```
27
+ *
28
+ * @packageDocumentation
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.RotateCart = exports.RotateStore = void 0;
32
+ const index_1 = require("./index");
33
+ const catalog_1 = require("./catalog");
34
+ // ==================== ROTATE STORE ====================
35
+ class RotateStore {
36
+ constructor(sdk, config) {
37
+ this.sdk = sdk;
38
+ this.config = {
39
+ merchantId: config.merchantId,
40
+ platformId: config.platformId,
41
+ currency: config.currency || 'USD',
42
+ allowTips: config.allowTips ?? false,
43
+ defaultExpiresIn: config.defaultExpiresIn ?? 300,
44
+ platformFeeBps: config.platformFeeBps ?? 0,
45
+ };
46
+ this.catalog = new catalog_1.Catalog((input) => {
47
+ const now = Date.now();
48
+ return { ...input, active: input.active ?? true, createdAt: now, updatedAt: now };
49
+ });
50
+ }
51
+ // ==================== PRODUCT CATALOG (delegated to Catalog) ====================
52
+ addProduct(input) { return this.catalog.addProduct(input); }
53
+ addProducts(inputs) { return this.catalog.addProducts(inputs); }
54
+ updateProduct(id, updates) { return this.catalog.updateProduct(id, updates); }
55
+ removeProduct(id) { return this.catalog.removeProduct(id); }
56
+ getProduct(id) { return this.catalog.getProduct(id); }
57
+ getProducts(filter) { return this.catalog.getProducts(filter); }
58
+ getCategories() { return this.catalog.getCategories(); }
59
+ get productCount() { return this.catalog.productCount; }
60
+ // ==================== INVENTORY (delegated) ====================
61
+ isInStock(productId, quantity = 1) { return this.catalog.isInStock(productId, quantity); }
62
+ reserveInventory(productId, quantity) { this.catalog.reserveInventory(productId, quantity); }
63
+ releaseInventory(productId, quantity) { this.catalog.releaseInventory(productId, quantity); }
64
+ // ==================== DISCOUNTS (delegated) ====================
65
+ addDiscount(input) { return this.catalog.addDiscount(input); }
66
+ getDiscount(code) { return this.catalog.getDiscount(code); }
67
+ isDiscountValid(code, subtotal) { return this.catalog.isDiscountValid(code, subtotal); }
68
+ useDiscount(code) { this.catalog.useDiscount(code); }
69
+ // ==================== CART ====================
70
+ /** Create a new shopping cart */
71
+ createCart() {
72
+ return new RotateCart(this, this.sdk, this.config);
73
+ }
74
+ // ==================== BATCH LINK CREATION ====================
75
+ /**
76
+ * Create payment links for every active product in the catalog.
77
+ * Useful for generating a "Buy Now" link per product upfront.
78
+ * Processes sequentially to respect Solana transaction ordering.
79
+ */
80
+ async createLinksForAllProducts(options) {
81
+ const products = options?.productIds
82
+ ? options.productIds.map((id) => this.catalog.getProduct(id)).filter(Boolean)
83
+ : this.getProducts({ active: true });
84
+ const results = [];
85
+ const concurrency = options?.concurrency || 1; // sequential by default for Solana
86
+ // Process in batches
87
+ for (let i = 0; i < products.length; i += concurrency) {
88
+ const batch = products.slice(i, i + concurrency);
89
+ const batchResults = await Promise.all(batch.map(async (product) => {
90
+ const amountMicro = BigInt(Math.floor(product.price * 1000000));
91
+ const expiresAt = options?.expiresIn
92
+ ? Math.floor(Date.now() / 1000) + options.expiresIn
93
+ : 0;
94
+ const result = await this.sdk.createLinkUsd({
95
+ merchantId: this.config.merchantId,
96
+ platformId: this.config.platformId,
97
+ amount: amountMicro,
98
+ expiresAt,
99
+ allowTips: this.config.allowTips,
100
+ allowPartial: false,
101
+ orderRef: product.id,
102
+ description: product.name,
103
+ });
104
+ return {
105
+ productId: product.id,
106
+ linkId: result.linkId,
107
+ tx: result.tx,
108
+ paymentUrl: this.sdk.getPaymentUrl(result.linkId),
109
+ };
110
+ }));
111
+ results.push(...batchResults);
112
+ }
113
+ return results;
114
+ }
115
+ // ==================== SERIALIZATION ====================
116
+ /** Export the full catalog as JSON (for persistence / API) */
117
+ exportCatalog() {
118
+ return {
119
+ products: this.catalog.exportProducts(),
120
+ discounts: this.catalog.exportDiscounts(),
121
+ };
122
+ }
123
+ /** Import a catalog from JSON */
124
+ importCatalog(data) {
125
+ this.catalog.importProducts(data.products);
126
+ if (data.discounts) {
127
+ this.catalog.importDiscounts(data.discounts);
128
+ }
129
+ }
130
+ }
131
+ exports.RotateStore = RotateStore;
132
+ // ==================== ROTATE CART ====================
133
+ class RotateCart {
134
+ /** @internal */
135
+ constructor(store, sdk, config) {
136
+ this.items = new Map();
137
+ this.appliedDiscounts = [];
138
+ this._metadata = {};
139
+ this.store = store;
140
+ this.sdk = sdk;
141
+ this.config = config;
142
+ }
143
+ // ==================== LINE ITEMS ====================
144
+ /** Add a product to the cart */
145
+ addItem(productId, quantity = 1) {
146
+ if (quantity <= 0)
147
+ throw new Error('Quantity must be positive');
148
+ const product = this.store.getProduct(productId);
149
+ if (!product)
150
+ throw new Error(`Product '${productId}' not found`);
151
+ if (!product.active)
152
+ throw new Error(`Product '${productId}' is not active`);
153
+ const existing = this.items.get(productId);
154
+ const newQty = (existing?.quantity || 0) + quantity;
155
+ if (!this.store.isInStock(productId, newQty)) {
156
+ throw new Error(`Insufficient stock for '${productId}'`);
157
+ }
158
+ const item = {
159
+ product,
160
+ quantity: newQty,
161
+ unitPrice: product.price,
162
+ };
163
+ this.items.set(productId, item);
164
+ return item;
165
+ }
166
+ /** Set exact quantity for a product */
167
+ setItemQuantity(productId, quantity) {
168
+ if (quantity <= 0) {
169
+ this.removeItem(productId);
170
+ return null;
171
+ }
172
+ const product = this.store.getProduct(productId);
173
+ if (!product)
174
+ throw new Error(`Product '${productId}' not found`);
175
+ if (!this.store.isInStock(productId, quantity)) {
176
+ throw new Error(`Insufficient stock for '${productId}'`);
177
+ }
178
+ const item = {
179
+ product,
180
+ quantity,
181
+ unitPrice: product.price,
182
+ };
183
+ this.items.set(productId, item);
184
+ return item;
185
+ }
186
+ /** Remove a product from the cart entirely */
187
+ removeItem(productId) {
188
+ return this.items.delete(productId);
189
+ }
190
+ /** Clear all items */
191
+ clear() {
192
+ this.items.clear();
193
+ this.appliedDiscounts = [];
194
+ this._metadata = {};
195
+ }
196
+ /** Get all line items */
197
+ getItems() {
198
+ return Array.from(this.items.values());
199
+ }
200
+ /** Check if cart is empty */
201
+ get isEmpty() {
202
+ return this.items.size === 0;
203
+ }
204
+ // ==================== DISCOUNTS ====================
205
+ /** Apply a discount code */
206
+ applyDiscount(code) {
207
+ const upperCode = code.toUpperCase();
208
+ if (this.appliedDiscounts.includes(upperCode))
209
+ return false;
210
+ const subtotal = this.calculateSubtotal();
211
+ if (!this.store.isDiscountValid(upperCode, subtotal))
212
+ return false;
213
+ this.appliedDiscounts.push(upperCode);
214
+ return true;
215
+ }
216
+ /** Remove a discount code */
217
+ removeDiscount(code) {
218
+ const idx = this.appliedDiscounts.indexOf(code.toUpperCase());
219
+ if (idx === -1)
220
+ return false;
221
+ this.appliedDiscounts.splice(idx, 1);
222
+ return true;
223
+ }
224
+ // ==================== METADATA ====================
225
+ /** Attach metadata to the order (customer email, shipping address, notes, etc.) */
226
+ setMetadata(key, value) {
227
+ this._metadata[key] = value;
228
+ }
229
+ getMetadata() {
230
+ return { ...this._metadata };
231
+ }
232
+ // ==================== TOTALS ====================
233
+ calculateSubtotal() {
234
+ let subtotal = 0;
235
+ for (const item of this.items.values()) {
236
+ subtotal += item.unitPrice * item.quantity;
237
+ }
238
+ return Math.round(subtotal * 100) / 100; // round to cents
239
+ }
240
+ calculateDiscountAmount(subtotal) {
241
+ let totalDiscount = 0;
242
+ for (const code of this.appliedDiscounts) {
243
+ const d = this.store.getDiscount(code);
244
+ if (!d || !d.active)
245
+ continue;
246
+ if (d.productIds && d.productIds.length > 0) {
247
+ // Product-specific discount
248
+ for (const item of this.items.values()) {
249
+ if (!d.productIds.includes(item.product.id))
250
+ continue;
251
+ const lineTotal = item.unitPrice * item.quantity;
252
+ if (d.type === 'percent') {
253
+ totalDiscount += lineTotal * (d.value / 100);
254
+ }
255
+ else {
256
+ totalDiscount += Math.min(d.value, lineTotal);
257
+ }
258
+ }
259
+ }
260
+ else {
261
+ // Cart-wide discount
262
+ if (d.type === 'percent') {
263
+ totalDiscount += subtotal * (d.value / 100);
264
+ }
265
+ else {
266
+ totalDiscount += d.value;
267
+ }
268
+ }
269
+ }
270
+ return Math.min(Math.round(totalDiscount * 100) / 100, subtotal);
271
+ }
272
+ /** Calculate full cart totals */
273
+ getTotals() {
274
+ const lines = [];
275
+ let subtotal = 0;
276
+ let totalQuantity = 0;
277
+ for (const item of this.items.values()) {
278
+ const lineTotal = Math.round(item.unitPrice * item.quantity * 100) / 100;
279
+ subtotal += lineTotal;
280
+ totalQuantity += item.quantity;
281
+ lines.push({
282
+ productId: item.product.id,
283
+ name: item.product.name,
284
+ quantity: item.quantity,
285
+ unitPrice: item.unitPrice,
286
+ lineTotal,
287
+ });
288
+ }
289
+ subtotal = Math.round(subtotal * 100) / 100;
290
+ const discountAmount = this.calculateDiscountAmount(subtotal);
291
+ let afterDiscount = Math.round((subtotal - discountAmount) * 100) / 100;
292
+ if (afterDiscount < 0)
293
+ afterDiscount = 0;
294
+ // Convert to micro-units for fee calculation
295
+ const amountMicro = Math.floor(afterDiscount * 1000000);
296
+ const feesResult = (0, index_1.calculateFees)(amountMicro, this.config.platformFeeBps);
297
+ // Convert fees back to dollars
298
+ const fees = feesResult.buyerFeeShare / 1000000;
299
+ const total = Math.round((afterDiscount + fees) * 100) / 100;
300
+ const merchantReceives = feesResult.merchantReceives / 1000000;
301
+ return {
302
+ itemCount: this.items.size,
303
+ totalQuantity,
304
+ subtotal,
305
+ discountAmount,
306
+ afterDiscount,
307
+ fees: Math.round(fees * 100) / 100,
308
+ total: Math.round(total * 100) / 100,
309
+ merchantReceives: Math.round(merchantReceives * 100) / 100,
310
+ lines,
311
+ };
312
+ }
313
+ // ==================== CHECKOUT ====================
314
+ /**
315
+ * Finalize the cart and create an on-chain payment link.
316
+ * Returns everything needed to present the payment to the buyer.
317
+ */
318
+ async checkout(options) {
319
+ if (this.isEmpty)
320
+ throw new Error('Cart is empty');
321
+ const totals = this.getTotals();
322
+ if (totals.afterDiscount <= 0)
323
+ throw new Error('Cart total must be greater than zero');
324
+ // Validate all items are still in stock
325
+ for (const item of this.items.values()) {
326
+ if (!this.store.isInStock(item.product.id, item.quantity)) {
327
+ throw new Error(`'${item.product.name}' is out of stock`);
328
+ }
329
+ }
330
+ const currency = options?.currency || this.config.currency;
331
+ const orderRef = options?.orderRef || `order_${Date.now()}_${Math.random().toString(36).substr(2, 6)}`;
332
+ const expiresAt = (options?.expiresIn ?? this.config.defaultExpiresIn) > 0
333
+ ? Math.floor(Date.now() / 1000) + (options?.expiresIn ?? this.config.defaultExpiresIn)
334
+ : 0;
335
+ const allowTips = options?.allowTips ?? this.config.allowTips;
336
+ // Auto-generate description from cart items (e.g. "2x Logo Tee, 1x Zip Hoodie")
337
+ const description = options?.description || totals.lines.map(l => `${l.quantity}x ${l.name}`).join(', ');
338
+ // Convert total to micro-units
339
+ const amountMicro = BigInt(Math.floor(totals.afterDiscount * 1000000));
340
+ let result;
341
+ if (currency === 'SOL') {
342
+ // SOL-denominated link (amount is in lamports)
343
+ const solPrice = await this.sdk.getSolPrice();
344
+ const lamports = BigInt(Math.floor((totals.afterDiscount / solPrice) * 1000000000));
345
+ result = await this.sdk.createLinkSol({
346
+ merchantId: this.config.merchantId,
347
+ platformId: this.config.platformId,
348
+ amount: lamports,
349
+ expiresAt,
350
+ allowTips,
351
+ allowPartial: false,
352
+ orderRef,
353
+ description,
354
+ });
355
+ }
356
+ else if (currency === 'USDC' || currency === 'USDT') {
357
+ result = await this.sdk.createLinkToken({
358
+ merchantId: this.config.merchantId,
359
+ platformId: this.config.platformId,
360
+ amount: amountMicro,
361
+ expiresAt,
362
+ allowTips,
363
+ allowPartial: false,
364
+ orderRef,
365
+ currency,
366
+ description,
367
+ });
368
+ }
369
+ else {
370
+ // USD-denominated (buyer picks SOL / USDC / USDT at pay time)
371
+ result = await this.sdk.createLinkUsd({
372
+ merchantId: this.config.merchantId,
373
+ platformId: this.config.platformId,
374
+ amount: amountMicro,
375
+ expiresAt,
376
+ allowTips,
377
+ allowPartial: false,
378
+ orderRef,
379
+ description,
380
+ });
381
+ }
382
+ // Reserve inventory
383
+ for (const item of this.items.values()) {
384
+ this.store.reserveInventory(item.product.id, item.quantity);
385
+ }
386
+ // Increment discount usage
387
+ for (const code of this.appliedDiscounts) {
388
+ this.store.useDiscount(code);
389
+ }
390
+ return {
391
+ linkId: result.linkId,
392
+ tx: result.tx,
393
+ paymentUrl: this.sdk.getPaymentUrl(result.linkId),
394
+ qrCodeUrl: this.sdk.getQRCodeUrl(result.linkId),
395
+ totals,
396
+ orderRef,
397
+ createdAt: Date.now(),
398
+ };
399
+ }
400
+ }
401
+ exports.RotateCart = RotateCart;
402
+ // ==================== EXPORTS ====================
403
+ exports.default = RotateStore;
404
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAEH,mCAKiB;AACjB,uCAA4F;AA0F5F,yDAAyD;AAEzD,MAAa,WAAW;IAMtB,YAAY,GAAc,EAAE,MAAmB;QAC7C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG;YACZ,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;YAClC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,KAAK;YACpC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,GAAG;YAChD,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,CAAC;SAC3C,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAwB,CAAC,KAAK,EAAE,EAAE;YAC1D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC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AC/C,MAAM;YACN,QAAQ;YACR,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;IACJ,CAAC;CACF;AAxTD,gCAwTC;AAED,oDAAoD;AAEpD,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Rotate Protocol Webhooks
3
+ *
4
+ * Listen to on-chain payment events and receive notifications.
5
+ * This does NOT change the P2P nature - webhooks are notifications only.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { Network } from './index';
10
+ export type WebhookEventType = 'protocol.initialized' | 'protocol.updated' | 'platform.created' | 'platform.updated' | 'merchant.created' | 'merchant.updated' | 'payment.completed' | 'payment.pending' | 'link.created' | 'link.created.usd' | 'link.paid' | 'link.paid.usd' | 'link.cancelled' | 'link.closed' | 'link.expired';
11
+ export interface WebhookEvent {
12
+ /** Unique event ID */
13
+ id: string;
14
+ /** Event type */
15
+ type: WebhookEventType;
16
+ /** Timestamp */
17
+ timestamp: number;
18
+ /** Transaction signature */
19
+ transactionSignature: string;
20
+ /** Event data */
21
+ data: WebhookEventData;
22
+ }
23
+ export interface WebhookEventData {
24
+ linkId?: number;
25
+ merchantId?: number;
26
+ platformId?: number;
27
+ payerWallet?: string;
28
+ merchantWallet?: string;
29
+ platformWallet?: string;
30
+ treasuryWallet?: string;
31
+ amountUsd?: number;
32
+ amountLamports?: number;
33
+ amountTokens?: number;
34
+ protocolFee?: number;
35
+ platformFee?: number;
36
+ tipAmount?: number;
37
+ currency?: 'SOL' | 'USDC' | 'USDT' | 'USD';
38
+ tokenType?: string;
39
+ orderRef?: string;
40
+ status?: string;
41
+ active?: boolean;
42
+ feeBps?: number;
43
+ }
44
+ export interface WebhookConfig {
45
+ /** Webhook endpoint URL */
46
+ url: string;
47
+ /** Events to subscribe to */
48
+ events: WebhookEventType[];
49
+ /** Filter by merchant ID (optional) */
50
+ merchantId?: number;
51
+ /** Filter by platform ID (optional) */
52
+ platformId?: number;
53
+ /** Secret for HMAC signature verification */
54
+ secret: string;
55
+ }
56
+ export type EventHandler = (event: WebhookEvent) => void | Promise<void>;
57
+ /**
58
+ * Verify webhook signature (for webhook receivers)
59
+ */
60
+ export declare function verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
61
+ /**
62
+ * Create webhook signature (for webhook senders)
63
+ */
64
+ export declare function createWebhookSignature(payload: string, secret: string): Promise<string>;
65
+ export interface EventListenerOptions {
66
+ /** Solana network */
67
+ network: Network;
68
+ /** Custom RPC endpoint */
69
+ rpcEndpoint?: string;
70
+ /** Poll interval in ms (default: 5000) */
71
+ pollIntervalMs?: number;
72
+ /** Filter by merchant ID */
73
+ merchantId?: number;
74
+ /** Filter by platform ID */
75
+ platformId?: number;
76
+ }
77
+ /**
78
+ * On-chain event listener
79
+ * Polls the blockchain for new transactions and emits events
80
+ */
81
+ export declare class EventListener {
82
+ private connection;
83
+ private programId;
84
+ private options;
85
+ private handlers;
86
+ private lastSignature;
87
+ private isRunning;
88
+ private pollInterval;
89
+ private coder;
90
+ constructor(options: EventListenerOptions);
91
+ /**
92
+ * Subscribe to an event type
93
+ */
94
+ on(eventType: WebhookEventType, handler: EventHandler): void;
95
+ /**
96
+ * Unsubscribe from an event type
97
+ */
98
+ off(eventType: WebhookEventType, handler: EventHandler): void;
99
+ /**
100
+ * Subscribe to all events
101
+ */
102
+ onAny(handler: EventHandler): void;
103
+ /**
104
+ * Start listening for events
105
+ */
106
+ start(): void;
107
+ /**
108
+ * Stop listening for events
109
+ */
110
+ stop(): void;
111
+ /**
112
+ * Poll for new transactions
113
+ */
114
+ private poll;
115
+ /**
116
+ * Process a transaction and emit decoded events
117
+ */
118
+ private processTransaction;
119
+ /** Map Anchor event name to webhook event type */
120
+ private anchorEventToWebhookType;
121
+ /** Map decoded Anchor event data to WebhookEventData */
122
+ private mapEventData;
123
+ /**
124
+ * Emit event to handlers
125
+ */
126
+ private emit;
127
+ }
128
+ export interface WebhookSenderOptions {
129
+ /** Retry failed webhooks */
130
+ retryCount?: number;
131
+ /** Retry delay in ms */
132
+ retryDelayMs?: number;
133
+ /** Timeout in ms */
134
+ timeoutMs?: number;
135
+ }
136
+ /**
137
+ * Send webhooks to registered endpoints
138
+ */
139
+ export declare class WebhookSender {
140
+ private options;
141
+ constructor(options?: WebhookSenderOptions);
142
+ /**
143
+ * Send webhook to endpoint
144
+ */
145
+ send(config: WebhookConfig, event: WebhookEvent): Promise<boolean>;
146
+ private delay;
147
+ }
148
+ export default EventListener;
149
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAc,OAAO,EAAE,MAAM,SAAS,CAAC;AAK9C,MAAM,MAAM,gBAAgB,GACxB,sBAAsB,GACtB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,mBAAmB,GACnB,iBAAiB,GACjB,cAAc,GACd,kBAAkB,GAClB,WAAW,GACX,eAAe,GACf,gBAAgB,GAChB,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB;IACjB,IAAI,EAAE,gBAAgB,CAAC;IACvB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB;IACjB,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAA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