@puul/partner-sdk 1.2.0 → 1.3.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/dist/index.d.mts CHANGED
@@ -172,7 +172,85 @@ interface WithdrawResult {
172
172
  payoutReference: string | null;
173
173
  status: string;
174
174
  }
175
- type WebhookEventType = 'user.created' | 'prediction.placed' | 'prediction.settled' | 'prediction.voided' | 'market.closed' | 'market.settled' | 'deposit.confirmed' | 'withdrawal.completed' | 'withdrawal.failed';
175
+ type LotteryPoolType = 'winner_takes_all' | 'tiered';
176
+ type LotteryPoolFrequency = 'daily' | 'weekly' | 'monthly' | 'quarterly';
177
+ type LotteryPoolStatus = 'upcoming' | 'open' | 'drawing' | 'settled' | 'cancelled';
178
+ type LotteryEntryStatus = 'active' | 'won' | 'lost' | 'refunded';
179
+ interface PrizeTier {
180
+ /** 1-based rank (1 = first place) */
181
+ rank: number;
182
+ /** Percentage of distributable pool in basis points (5000 = 50%) */
183
+ pct: number;
184
+ }
185
+ interface LotteryPool {
186
+ id: string;
187
+ title: string;
188
+ description: string | null;
189
+ type: LotteryPoolType;
190
+ frequency: LotteryPoolFrequency;
191
+ status: LotteryPoolStatus;
192
+ ticket_price: string;
193
+ currency: string;
194
+ max_tickets: number | null;
195
+ max_tickets_per_user: number | null;
196
+ total_entries: number;
197
+ total_pool_amount: string;
198
+ opens_at: string;
199
+ draws_at: string;
200
+ drawn_at: string | null;
201
+ winning_numbers: number[];
202
+ prize_tiers: PrizeTier[];
203
+ takeout_rate_bps: number;
204
+ }
205
+ interface LotteryEntry {
206
+ id: string;
207
+ pool_id: string;
208
+ user_id: string | null;
209
+ user_external_id: string | null;
210
+ ticket_number: number;
211
+ amount_paid: string;
212
+ currency: string;
213
+ status: LotteryEntryStatus;
214
+ prize_amount: string | null;
215
+ prize_tier: number | null;
216
+ purchased_at: string;
217
+ }
218
+ interface LotteryEntriesResponse {
219
+ entries: LotteryEntry[];
220
+ total: number;
221
+ }
222
+ interface BuyTicketParams {
223
+ /** Puul user ID of the linked user */
224
+ userId: string;
225
+ /** Unique key to prevent duplicate purchases */
226
+ idempotencyKey: string;
227
+ /** Number of tickets (default: 1) */
228
+ quantity?: number;
229
+ /** Your external user ID (for tracking) */
230
+ userExternalId?: string;
231
+ }
232
+ interface BuyTicketResponse {
233
+ entries: LotteryEntry[];
234
+ }
235
+ interface LotteryDrawResult {
236
+ pool_id: string;
237
+ status: string;
238
+ drawn_at: string | null;
239
+ winning_numbers: number[];
240
+ total_pool_amount: string;
241
+ your_entries: Array<{
242
+ id: string;
243
+ ticket_number: number;
244
+ user_id: string | null;
245
+ user_external_id: string | null;
246
+ status: string;
247
+ prize_amount: string | null;
248
+ prize_tier: number | null;
249
+ }>;
250
+ your_winners: number;
251
+ your_total_winnings: number;
252
+ }
253
+ type WebhookEventType = 'user.created' | 'prediction.placed' | 'prediction.settled' | 'prediction.voided' | 'market.closed' | 'market.settled' | 'deposit.confirmed' | 'withdrawal.completed' | 'withdrawal.failed' | 'lottery.pool.drawn' | 'lottery.ticket.won';
176
254
  interface WebhookEvent<T = unknown> {
177
255
  event: WebhookEventType;
178
256
  timestamp: string;
@@ -284,6 +362,30 @@ interface WithdrawalFailedData {
284
362
  reason: string;
285
363
  failed_at: string;
286
364
  }
365
+ interface LotteryPoolDrawnData {
366
+ pool_id: string;
367
+ pool_title: string;
368
+ drawn_at: string;
369
+ winning_numbers: number[];
370
+ total_pool_amount: number;
371
+ total_entries: number;
372
+ takeout_amount: number;
373
+ total_payout: number;
374
+ your_entries: number;
375
+ your_winners: number;
376
+ your_total_winnings: number;
377
+ }
378
+ interface LotteryTicketWonData {
379
+ entry_id: string;
380
+ pool_id: string;
381
+ pool_title: string;
382
+ user_id: string;
383
+ user_external_id: string | null;
384
+ ticket_number: number;
385
+ prize_amount: number;
386
+ prize_tier: number;
387
+ drawn_at: string;
388
+ }
287
389
  interface PuulApiError {
288
390
  statusCode: number;
289
391
  message: string | string[];
@@ -335,6 +437,7 @@ declare class PuulPartner {
335
437
  readonly markets: MarketsAPI;
336
438
  readonly predictions: PredictionsAPI;
337
439
  readonly wallet: WalletAPI;
440
+ readonly lottery: LotteryAPI;
338
441
  constructor(config: PuulPartnerConfig);
339
442
  /** Get a valid access token, refreshing if needed */
340
443
  getAccessToken(): Promise<string>;
@@ -404,6 +507,41 @@ declare class WalletAPI {
404
507
  */
405
508
  withdraw(params: WithdrawParams): Promise<WithdrawResult>;
406
509
  }
510
+ declare class LotteryAPI {
511
+ private readonly client;
512
+ constructor(client: PuulPartner);
513
+ /** List lottery pools, optionally filtered by status and frequency */
514
+ listPools(options?: {
515
+ status?: LotteryPoolStatus;
516
+ frequency?: string;
517
+ limit?: number;
518
+ }): Promise<LotteryPool[]>;
519
+ /** Get a specific pool by ID */
520
+ getPool(poolId: string): Promise<LotteryPool>;
521
+ /**
522
+ * Buy ticket(s) for a linked user.
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * const result = await puul.lottery.buyTicket('pool-uuid', {
527
+ * userId: 'puul-user-uuid',
528
+ * idempotencyKey: 'lottery-user456-pool1-001',
529
+ * quantity: 3,
530
+ * });
531
+ * ```
532
+ */
533
+ buyTicket(poolId: string, params: BuyTicketParams): Promise<BuyTicketResponse>;
534
+ /** List lottery entries for your partner account */
535
+ listEntries(options?: {
536
+ poolId?: string;
537
+ status?: LotteryEntryStatus;
538
+ limit?: number;
539
+ }): Promise<LotteryEntriesResponse>;
540
+ /** Get a single lottery entry by ID */
541
+ getEntry(entryId: string): Promise<LotteryEntry>;
542
+ /** Get draw results for a completed pool */
543
+ getDrawResults(poolId: string): Promise<LotteryDrawResult>;
544
+ }
407
545
 
408
546
  /**
409
547
  * Verify a webhook signature from Puul.
@@ -469,6 +607,10 @@ declare function isDepositConfirmedEvent(event: WebhookEvent): event is WebhookE
469
607
  declare function isWithdrawalCompletedEvent(event: WebhookEvent): event is WebhookEvent<WithdrawalCompletedData>;
470
608
  /** Type guard for withdrawal.failed events. */
471
609
  declare function isWithdrawalFailedEvent(event: WebhookEvent): event is WebhookEvent<WithdrawalFailedData>;
610
+ /** Type guard for lottery.pool.drawn events. */
611
+ declare function isLotteryPoolDrawnEvent(event: WebhookEvent): event is WebhookEvent<LotteryPoolDrawnData>;
612
+ /** Type guard for lottery.ticket.won events. */
613
+ declare function isLotteryTicketWonEvent(event: WebhookEvent): event is WebhookEvent<LotteryTicketWonData>;
472
614
  /**
473
615
  * Convenience cast for prediction.settled event data.
474
616
  * Call after verifying with `isPredictionSettledEvent`.
@@ -479,5 +621,15 @@ declare function asPredictionSettledData(event: WebhookEvent): PredictionSettled
479
621
  * Call after verifying with `isMarketSettledEvent`.
480
622
  */
481
623
  declare function asMarketSettledData(event: WebhookEvent): MarketSettledData;
624
+ /**
625
+ * Convenience cast for lottery.pool.drawn event data.
626
+ * Call after verifying with `isLotteryPoolDrawnEvent`.
627
+ */
628
+ declare function asLotteryPoolDrawnData(event: WebhookEvent): LotteryPoolDrawnData;
629
+ /**
630
+ * Convenience cast for lottery.ticket.won event data.
631
+ * Call after verifying with `isLotteryTicketWonEvent`.
632
+ */
633
+ declare function asLotteryTicketWonData(event: WebhookEvent): LotteryTicketWonData;
482
634
 
483
- export { type AccessTokenResponse, type CreateLinkTokenParams, type CreatePendingPredictionParams, type CreateQuoteParams, type Currency, type DepositAccountInfo, type DepositConfirmedData, type DepositParams, type LinkTokenResponse, type Market, type MarketClosedData, type MarketOutcome, type MarketSettledData, type PendingPrediction, type PlacePredictionParams, type Prediction, type PredictionListResponse, type PredictionPlacedData, type PredictionSettledData, type PredictionStatus, type PredictionVoidedData, type PuulApiError, PuulError, PuulPartner, type PuulPartnerConfig, type QuoteResponse, type SessionResponse, type UserCreatedData, type WalletBalance, type WebhookEvent, type WebhookEventType, type WithdrawMethod, type WithdrawParams, type WithdrawResult, type WithdrawalCompletedData, type WithdrawalFailedData, asMarketSettledData, asPredictionSettledData, isDepositConfirmedEvent, isMarketClosedEvent, isMarketSettledEvent, isPredictionPlacedEvent, isPredictionSettledEvent, isPredictionVoidedEvent, isWithdrawalCompletedEvent, isWithdrawalFailedEvent, parseWebhookEvent, verifyWebhookSignature };
635
+ export { type AccessTokenResponse, type BuyTicketParams, type BuyTicketResponse, type CreateLinkTokenParams, type CreatePendingPredictionParams, type CreateQuoteParams, type Currency, type DepositAccountInfo, type DepositConfirmedData, type DepositParams, type LinkTokenResponse, type LotteryDrawResult, type LotteryEntriesResponse, type LotteryEntry, type LotteryEntryStatus, type LotteryPool, type LotteryPoolDrawnData, type LotteryPoolFrequency, type LotteryPoolStatus, type LotteryPoolType, type LotteryTicketWonData, type Market, type MarketClosedData, type MarketOutcome, type MarketSettledData, type PendingPrediction, type PlacePredictionParams, type Prediction, type PredictionListResponse, type PredictionPlacedData, type PredictionSettledData, type PredictionStatus, type PredictionVoidedData, type PrizeTier, type PuulApiError, PuulError, PuulPartner, type PuulPartnerConfig, type QuoteResponse, type SessionResponse, type UserCreatedData, type WalletBalance, type WebhookEvent, type WebhookEventType, type WithdrawMethod, type WithdrawParams, type WithdrawResult, type WithdrawalCompletedData, type WithdrawalFailedData, asLotteryPoolDrawnData, asLotteryTicketWonData, asMarketSettledData, asPredictionSettledData, isDepositConfirmedEvent, isLotteryPoolDrawnEvent, isLotteryTicketWonEvent, isMarketClosedEvent, isMarketSettledEvent, isPredictionPlacedEvent, isPredictionSettledEvent, isPredictionVoidedEvent, isWithdrawalCompletedEvent, isWithdrawalFailedEvent, parseWebhookEvent, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -172,7 +172,85 @@ interface WithdrawResult {
172
172
  payoutReference: string | null;
173
173
  status: string;
174
174
  }
175
- type WebhookEventType = 'user.created' | 'prediction.placed' | 'prediction.settled' | 'prediction.voided' | 'market.closed' | 'market.settled' | 'deposit.confirmed' | 'withdrawal.completed' | 'withdrawal.failed';
175
+ type LotteryPoolType = 'winner_takes_all' | 'tiered';
176
+ type LotteryPoolFrequency = 'daily' | 'weekly' | 'monthly' | 'quarterly';
177
+ type LotteryPoolStatus = 'upcoming' | 'open' | 'drawing' | 'settled' | 'cancelled';
178
+ type LotteryEntryStatus = 'active' | 'won' | 'lost' | 'refunded';
179
+ interface PrizeTier {
180
+ /** 1-based rank (1 = first place) */
181
+ rank: number;
182
+ /** Percentage of distributable pool in basis points (5000 = 50%) */
183
+ pct: number;
184
+ }
185
+ interface LotteryPool {
186
+ id: string;
187
+ title: string;
188
+ description: string | null;
189
+ type: LotteryPoolType;
190
+ frequency: LotteryPoolFrequency;
191
+ status: LotteryPoolStatus;
192
+ ticket_price: string;
193
+ currency: string;
194
+ max_tickets: number | null;
195
+ max_tickets_per_user: number | null;
196
+ total_entries: number;
197
+ total_pool_amount: string;
198
+ opens_at: string;
199
+ draws_at: string;
200
+ drawn_at: string | null;
201
+ winning_numbers: number[];
202
+ prize_tiers: PrizeTier[];
203
+ takeout_rate_bps: number;
204
+ }
205
+ interface LotteryEntry {
206
+ id: string;
207
+ pool_id: string;
208
+ user_id: string | null;
209
+ user_external_id: string | null;
210
+ ticket_number: number;
211
+ amount_paid: string;
212
+ currency: string;
213
+ status: LotteryEntryStatus;
214
+ prize_amount: string | null;
215
+ prize_tier: number | null;
216
+ purchased_at: string;
217
+ }
218
+ interface LotteryEntriesResponse {
219
+ entries: LotteryEntry[];
220
+ total: number;
221
+ }
222
+ interface BuyTicketParams {
223
+ /** Puul user ID of the linked user */
224
+ userId: string;
225
+ /** Unique key to prevent duplicate purchases */
226
+ idempotencyKey: string;
227
+ /** Number of tickets (default: 1) */
228
+ quantity?: number;
229
+ /** Your external user ID (for tracking) */
230
+ userExternalId?: string;
231
+ }
232
+ interface BuyTicketResponse {
233
+ entries: LotteryEntry[];
234
+ }
235
+ interface LotteryDrawResult {
236
+ pool_id: string;
237
+ status: string;
238
+ drawn_at: string | null;
239
+ winning_numbers: number[];
240
+ total_pool_amount: string;
241
+ your_entries: Array<{
242
+ id: string;
243
+ ticket_number: number;
244
+ user_id: string | null;
245
+ user_external_id: string | null;
246
+ status: string;
247
+ prize_amount: string | null;
248
+ prize_tier: number | null;
249
+ }>;
250
+ your_winners: number;
251
+ your_total_winnings: number;
252
+ }
253
+ type WebhookEventType = 'user.created' | 'prediction.placed' | 'prediction.settled' | 'prediction.voided' | 'market.closed' | 'market.settled' | 'deposit.confirmed' | 'withdrawal.completed' | 'withdrawal.failed' | 'lottery.pool.drawn' | 'lottery.ticket.won';
176
254
  interface WebhookEvent<T = unknown> {
177
255
  event: WebhookEventType;
178
256
  timestamp: string;
@@ -284,6 +362,30 @@ interface WithdrawalFailedData {
284
362
  reason: string;
285
363
  failed_at: string;
286
364
  }
365
+ interface LotteryPoolDrawnData {
366
+ pool_id: string;
367
+ pool_title: string;
368
+ drawn_at: string;
369
+ winning_numbers: number[];
370
+ total_pool_amount: number;
371
+ total_entries: number;
372
+ takeout_amount: number;
373
+ total_payout: number;
374
+ your_entries: number;
375
+ your_winners: number;
376
+ your_total_winnings: number;
377
+ }
378
+ interface LotteryTicketWonData {
379
+ entry_id: string;
380
+ pool_id: string;
381
+ pool_title: string;
382
+ user_id: string;
383
+ user_external_id: string | null;
384
+ ticket_number: number;
385
+ prize_amount: number;
386
+ prize_tier: number;
387
+ drawn_at: string;
388
+ }
287
389
  interface PuulApiError {
288
390
  statusCode: number;
289
391
  message: string | string[];
@@ -335,6 +437,7 @@ declare class PuulPartner {
335
437
  readonly markets: MarketsAPI;
336
438
  readonly predictions: PredictionsAPI;
337
439
  readonly wallet: WalletAPI;
440
+ readonly lottery: LotteryAPI;
338
441
  constructor(config: PuulPartnerConfig);
339
442
  /** Get a valid access token, refreshing if needed */
340
443
  getAccessToken(): Promise<string>;
@@ -404,6 +507,41 @@ declare class WalletAPI {
404
507
  */
405
508
  withdraw(params: WithdrawParams): Promise<WithdrawResult>;
406
509
  }
510
+ declare class LotteryAPI {
511
+ private readonly client;
512
+ constructor(client: PuulPartner);
513
+ /** List lottery pools, optionally filtered by status and frequency */
514
+ listPools(options?: {
515
+ status?: LotteryPoolStatus;
516
+ frequency?: string;
517
+ limit?: number;
518
+ }): Promise<LotteryPool[]>;
519
+ /** Get a specific pool by ID */
520
+ getPool(poolId: string): Promise<LotteryPool>;
521
+ /**
522
+ * Buy ticket(s) for a linked user.
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * const result = await puul.lottery.buyTicket('pool-uuid', {
527
+ * userId: 'puul-user-uuid',
528
+ * idempotencyKey: 'lottery-user456-pool1-001',
529
+ * quantity: 3,
530
+ * });
531
+ * ```
532
+ */
533
+ buyTicket(poolId: string, params: BuyTicketParams): Promise<BuyTicketResponse>;
534
+ /** List lottery entries for your partner account */
535
+ listEntries(options?: {
536
+ poolId?: string;
537
+ status?: LotteryEntryStatus;
538
+ limit?: number;
539
+ }): Promise<LotteryEntriesResponse>;
540
+ /** Get a single lottery entry by ID */
541
+ getEntry(entryId: string): Promise<LotteryEntry>;
542
+ /** Get draw results for a completed pool */
543
+ getDrawResults(poolId: string): Promise<LotteryDrawResult>;
544
+ }
407
545
 
408
546
  /**
409
547
  * Verify a webhook signature from Puul.
@@ -469,6 +607,10 @@ declare function isDepositConfirmedEvent(event: WebhookEvent): event is WebhookE
469
607
  declare function isWithdrawalCompletedEvent(event: WebhookEvent): event is WebhookEvent<WithdrawalCompletedData>;
470
608
  /** Type guard for withdrawal.failed events. */
471
609
  declare function isWithdrawalFailedEvent(event: WebhookEvent): event is WebhookEvent<WithdrawalFailedData>;
610
+ /** Type guard for lottery.pool.drawn events. */
611
+ declare function isLotteryPoolDrawnEvent(event: WebhookEvent): event is WebhookEvent<LotteryPoolDrawnData>;
612
+ /** Type guard for lottery.ticket.won events. */
613
+ declare function isLotteryTicketWonEvent(event: WebhookEvent): event is WebhookEvent<LotteryTicketWonData>;
472
614
  /**
473
615
  * Convenience cast for prediction.settled event data.
474
616
  * Call after verifying with `isPredictionSettledEvent`.
@@ -479,5 +621,15 @@ declare function asPredictionSettledData(event: WebhookEvent): PredictionSettled
479
621
  * Call after verifying with `isMarketSettledEvent`.
480
622
  */
481
623
  declare function asMarketSettledData(event: WebhookEvent): MarketSettledData;
624
+ /**
625
+ * Convenience cast for lottery.pool.drawn event data.
626
+ * Call after verifying with `isLotteryPoolDrawnEvent`.
627
+ */
628
+ declare function asLotteryPoolDrawnData(event: WebhookEvent): LotteryPoolDrawnData;
629
+ /**
630
+ * Convenience cast for lottery.ticket.won event data.
631
+ * Call after verifying with `isLotteryTicketWonEvent`.
632
+ */
633
+ declare function asLotteryTicketWonData(event: WebhookEvent): LotteryTicketWonData;
482
634
 
483
- export { type AccessTokenResponse, type CreateLinkTokenParams, type CreatePendingPredictionParams, type CreateQuoteParams, type Currency, type DepositAccountInfo, type DepositConfirmedData, type DepositParams, type LinkTokenResponse, type Market, type MarketClosedData, type MarketOutcome, type MarketSettledData, type PendingPrediction, type PlacePredictionParams, type Prediction, type PredictionListResponse, type PredictionPlacedData, type PredictionSettledData, type PredictionStatus, type PredictionVoidedData, type PuulApiError, PuulError, PuulPartner, type PuulPartnerConfig, type QuoteResponse, type SessionResponse, type UserCreatedData, type WalletBalance, type WebhookEvent, type WebhookEventType, type WithdrawMethod, type WithdrawParams, type WithdrawResult, type WithdrawalCompletedData, type WithdrawalFailedData, asMarketSettledData, asPredictionSettledData, isDepositConfirmedEvent, isMarketClosedEvent, isMarketSettledEvent, isPredictionPlacedEvent, isPredictionSettledEvent, isPredictionVoidedEvent, isWithdrawalCompletedEvent, isWithdrawalFailedEvent, parseWebhookEvent, verifyWebhookSignature };
635
+ export { type AccessTokenResponse, type BuyTicketParams, type BuyTicketResponse, type CreateLinkTokenParams, type CreatePendingPredictionParams, type CreateQuoteParams, type Currency, type DepositAccountInfo, type DepositConfirmedData, type DepositParams, type LinkTokenResponse, type LotteryDrawResult, type LotteryEntriesResponse, type LotteryEntry, type LotteryEntryStatus, type LotteryPool, type LotteryPoolDrawnData, type LotteryPoolFrequency, type LotteryPoolStatus, type LotteryPoolType, type LotteryTicketWonData, type Market, type MarketClosedData, type MarketOutcome, type MarketSettledData, type PendingPrediction, type PlacePredictionParams, type Prediction, type PredictionListResponse, type PredictionPlacedData, type PredictionSettledData, type PredictionStatus, type PredictionVoidedData, type PrizeTier, type PuulApiError, PuulError, PuulPartner, type PuulPartnerConfig, type QuoteResponse, type SessionResponse, type UserCreatedData, type WalletBalance, type WebhookEvent, type WebhookEventType, type WithdrawMethod, type WithdrawParams, type WithdrawResult, type WithdrawalCompletedData, type WithdrawalFailedData, asLotteryPoolDrawnData, asLotteryTicketWonData, asMarketSettledData, asPredictionSettledData, isDepositConfirmedEvent, isLotteryPoolDrawnEvent, isLotteryTicketWonEvent, isMarketClosedEvent, isMarketSettledEvent, isPredictionPlacedEvent, isPredictionSettledEvent, isPredictionVoidedEvent, isWithdrawalCompletedEvent, isWithdrawalFailedEvent, parseWebhookEvent, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -22,9 +22,13 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  PuulError: () => PuulError,
24
24
  PuulPartner: () => PuulPartner,
25
+ asLotteryPoolDrawnData: () => asLotteryPoolDrawnData,
26
+ asLotteryTicketWonData: () => asLotteryTicketWonData,
25
27
  asMarketSettledData: () => asMarketSettledData,
26
28
  asPredictionSettledData: () => asPredictionSettledData,
27
29
  isDepositConfirmedEvent: () => isDepositConfirmedEvent,
30
+ isLotteryPoolDrawnEvent: () => isLotteryPoolDrawnEvent,
31
+ isLotteryTicketWonEvent: () => isLotteryTicketWonEvent,
28
32
  isMarketClosedEvent: () => isMarketClosedEvent,
29
33
  isMarketSettledEvent: () => isMarketSettledEvent,
30
34
  isPredictionPlacedEvent: () => isPredictionPlacedEvent,
@@ -67,6 +71,7 @@ var PuulPartner = class {
67
71
  this.markets = new MarketsAPI(this);
68
72
  this.predictions = new PredictionsAPI(this);
69
73
  this.wallet = new WalletAPI(this);
74
+ this.lottery = new LotteryAPI(this);
70
75
  }
71
76
  // ==========================================================
72
77
  // Internal HTTP layer
@@ -254,21 +259,76 @@ var WalletAPI = class {
254
259
  return this.client.request("POST", "/partner/wallet/withdraw", params);
255
260
  }
256
261
  };
262
+ var LotteryAPI = class {
263
+ constructor(client) {
264
+ this.client = client;
265
+ }
266
+ /** List lottery pools, optionally filtered by status and frequency */
267
+ async listPools(options) {
268
+ const params = new URLSearchParams();
269
+ if (options?.status) params.set("status", options.status);
270
+ if (options?.frequency) params.set("frequency", options.frequency);
271
+ if (options?.limit) params.set("limit", String(options.limit));
272
+ const query = params.toString() ? `?${params.toString()}` : "";
273
+ return this.client.request("GET", `/partner/lottery/pools${query}`);
274
+ }
275
+ /** Get a specific pool by ID */
276
+ async getPool(poolId) {
277
+ return this.client.request("GET", `/partner/lottery/pools/${poolId}`);
278
+ }
279
+ /**
280
+ * Buy ticket(s) for a linked user.
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const result = await puul.lottery.buyTicket('pool-uuid', {
285
+ * userId: 'puul-user-uuid',
286
+ * idempotencyKey: 'lottery-user456-pool1-001',
287
+ * quantity: 3,
288
+ * });
289
+ * ```
290
+ */
291
+ async buyTicket(poolId, params) {
292
+ return this.client.request("POST", `/partner/lottery/pools/${poolId}/buy`, {
293
+ user_id: params.userId,
294
+ idempotency_key: params.idempotencyKey,
295
+ quantity: params.quantity,
296
+ user_external_id: params.userExternalId
297
+ });
298
+ }
299
+ /** List lottery entries for your partner account */
300
+ async listEntries(options) {
301
+ const params = new URLSearchParams();
302
+ if (options?.poolId) params.set("pool_id", options.poolId);
303
+ if (options?.status) params.set("status", options.status);
304
+ if (options?.limit) params.set("limit", String(options.limit));
305
+ const query = params.toString() ? `?${params.toString()}` : "";
306
+ return this.client.request("GET", `/partner/lottery/entries${query}`);
307
+ }
308
+ /** Get a single lottery entry by ID */
309
+ async getEntry(entryId) {
310
+ return this.client.request("GET", `/partner/lottery/entries/${entryId}`);
311
+ }
312
+ /** Get draw results for a completed pool */
313
+ async getDrawResults(poolId) {
314
+ return this.client.request("GET", `/partner/lottery/pools/${poolId}/results`);
315
+ }
316
+ };
257
317
 
258
318
  // src/webhooks.ts
259
- var import_crypto = require("crypto");
319
+ var import_node_crypto = require("crypto");
260
320
  function verifyWebhookSignature(payload, signature, secret) {
261
321
  if (!payload || !signature || !secret) {
262
322
  return false;
263
323
  }
264
- const expectedSignature = (0, import_crypto.createHmac)("sha256", secret).update(payload).digest("hex");
324
+ const expectedSignature = (0, import_node_crypto.createHmac)("sha256", secret).update(payload).digest("hex");
265
325
  try {
266
326
  const sigBuffer = Buffer.from(signature, "hex");
267
327
  const expectedBuffer = Buffer.from(expectedSignature, "hex");
268
328
  if (sigBuffer.length !== expectedBuffer.length) {
269
329
  return false;
270
330
  }
271
- return (0, import_crypto.timingSafeEqual)(sigBuffer, expectedBuffer);
331
+ return (0, import_node_crypto.timingSafeEqual)(sigBuffer, expectedBuffer);
272
332
  } catch {
273
333
  return false;
274
334
  }
@@ -279,7 +339,7 @@ function parseWebhookEvent(body) {
279
339
  }
280
340
  const event = body;
281
341
  if (typeof event.event !== "string") {
282
- throw new Error('Invalid webhook body: missing "event" field');
342
+ throw new TypeError('Invalid webhook body: missing "event" field');
283
343
  }
284
344
  return {
285
345
  event: event.event,
@@ -311,19 +371,35 @@ function isWithdrawalCompletedEvent(event) {
311
371
  function isWithdrawalFailedEvent(event) {
312
372
  return event.event === "withdrawal.failed";
313
373
  }
374
+ function isLotteryPoolDrawnEvent(event) {
375
+ return event.event === "lottery.pool.drawn";
376
+ }
377
+ function isLotteryTicketWonEvent(event) {
378
+ return event.event === "lottery.ticket.won";
379
+ }
314
380
  function asPredictionSettledData(event) {
315
381
  return event.data;
316
382
  }
317
383
  function asMarketSettledData(event) {
318
384
  return event.data;
319
385
  }
386
+ function asLotteryPoolDrawnData(event) {
387
+ return event.data;
388
+ }
389
+ function asLotteryTicketWonData(event) {
390
+ return event.data;
391
+ }
320
392
  // Annotate the CommonJS export names for ESM import in node:
321
393
  0 && (module.exports = {
322
394
  PuulError,
323
395
  PuulPartner,
396
+ asLotteryPoolDrawnData,
397
+ asLotteryTicketWonData,
324
398
  asMarketSettledData,
325
399
  asPredictionSettledData,
326
400
  isDepositConfirmedEvent,
401
+ isLotteryPoolDrawnEvent,
402
+ isLotteryTicketWonEvent,
327
403
  isMarketClosedEvent,
328
404
  isMarketSettledEvent,
329
405
  isPredictionPlacedEvent,
package/dist/index.mjs CHANGED
@@ -28,6 +28,7 @@ var PuulPartner = class {
28
28
  this.markets = new MarketsAPI(this);
29
29
  this.predictions = new PredictionsAPI(this);
30
30
  this.wallet = new WalletAPI(this);
31
+ this.lottery = new LotteryAPI(this);
31
32
  }
32
33
  // ==========================================================
33
34
  // Internal HTTP layer
@@ -215,6 +216,61 @@ var WalletAPI = class {
215
216
  return this.client.request("POST", "/partner/wallet/withdraw", params);
216
217
  }
217
218
  };
219
+ var LotteryAPI = class {
220
+ constructor(client) {
221
+ this.client = client;
222
+ }
223
+ /** List lottery pools, optionally filtered by status and frequency */
224
+ async listPools(options) {
225
+ const params = new URLSearchParams();
226
+ if (options?.status) params.set("status", options.status);
227
+ if (options?.frequency) params.set("frequency", options.frequency);
228
+ if (options?.limit) params.set("limit", String(options.limit));
229
+ const query = params.toString() ? `?${params.toString()}` : "";
230
+ return this.client.request("GET", `/partner/lottery/pools${query}`);
231
+ }
232
+ /** Get a specific pool by ID */
233
+ async getPool(poolId) {
234
+ return this.client.request("GET", `/partner/lottery/pools/${poolId}`);
235
+ }
236
+ /**
237
+ * Buy ticket(s) for a linked user.
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const result = await puul.lottery.buyTicket('pool-uuid', {
242
+ * userId: 'puul-user-uuid',
243
+ * idempotencyKey: 'lottery-user456-pool1-001',
244
+ * quantity: 3,
245
+ * });
246
+ * ```
247
+ */
248
+ async buyTicket(poolId, params) {
249
+ return this.client.request("POST", `/partner/lottery/pools/${poolId}/buy`, {
250
+ user_id: params.userId,
251
+ idempotency_key: params.idempotencyKey,
252
+ quantity: params.quantity,
253
+ user_external_id: params.userExternalId
254
+ });
255
+ }
256
+ /** List lottery entries for your partner account */
257
+ async listEntries(options) {
258
+ const params = new URLSearchParams();
259
+ if (options?.poolId) params.set("pool_id", options.poolId);
260
+ if (options?.status) params.set("status", options.status);
261
+ if (options?.limit) params.set("limit", String(options.limit));
262
+ const query = params.toString() ? `?${params.toString()}` : "";
263
+ return this.client.request("GET", `/partner/lottery/entries${query}`);
264
+ }
265
+ /** Get a single lottery entry by ID */
266
+ async getEntry(entryId) {
267
+ return this.client.request("GET", `/partner/lottery/entries/${entryId}`);
268
+ }
269
+ /** Get draw results for a completed pool */
270
+ async getDrawResults(poolId) {
271
+ return this.client.request("GET", `/partner/lottery/pools/${poolId}/results`);
272
+ }
273
+ };
218
274
 
219
275
  // src/webhooks.ts
220
276
  import { createHmac, timingSafeEqual } from "crypto";
@@ -240,7 +296,7 @@ function parseWebhookEvent(body) {
240
296
  }
241
297
  const event = body;
242
298
  if (typeof event.event !== "string") {
243
- throw new Error('Invalid webhook body: missing "event" field');
299
+ throw new TypeError('Invalid webhook body: missing "event" field');
244
300
  }
245
301
  return {
246
302
  event: event.event,
@@ -272,18 +328,34 @@ function isWithdrawalCompletedEvent(event) {
272
328
  function isWithdrawalFailedEvent(event) {
273
329
  return event.event === "withdrawal.failed";
274
330
  }
331
+ function isLotteryPoolDrawnEvent(event) {
332
+ return event.event === "lottery.pool.drawn";
333
+ }
334
+ function isLotteryTicketWonEvent(event) {
335
+ return event.event === "lottery.ticket.won";
336
+ }
275
337
  function asPredictionSettledData(event) {
276
338
  return event.data;
277
339
  }
278
340
  function asMarketSettledData(event) {
279
341
  return event.data;
280
342
  }
343
+ function asLotteryPoolDrawnData(event) {
344
+ return event.data;
345
+ }
346
+ function asLotteryTicketWonData(event) {
347
+ return event.data;
348
+ }
281
349
  export {
282
350
  PuulError,
283
351
  PuulPartner,
352
+ asLotteryPoolDrawnData,
353
+ asLotteryTicketWonData,
284
354
  asMarketSettledData,
285
355
  asPredictionSettledData,
286
356
  isDepositConfirmedEvent,
357
+ isLotteryPoolDrawnEvent,
358
+ isLotteryTicketWonEvent,
287
359
  isMarketClosedEvent,
288
360
  isMarketSettledEvent,
289
361
  isPredictionPlacedEvent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puul/partner-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Official TypeScript SDK for the Puul Partner API — integrate prediction markets into your platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",