@waffo/pancake-ts 0.1.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,1258 @@
1
+ interface WaffoPancakeConfig {
2
+ /** Merchant ID (X-Merchant-Id header) */
3
+ merchantId: string;
4
+ /** RSA private key in PEM format for request signing */
5
+ privateKey: string;
6
+ /** Base URL override (default: https://waffo-pancake-auth-service.vercel.app) */
7
+ baseUrl?: string;
8
+ /** Custom fetch implementation (default: global fetch) */
9
+ fetch?: typeof fetch;
10
+ }
11
+ /**
12
+ * Single error object within the `errors` array.
13
+ *
14
+ * @example
15
+ * { message: "Store slug already exists", layer: "store" }
16
+ */
17
+ interface ApiError {
18
+ /** Error message */
19
+ message: string;
20
+ /** Layer where the error originated */
21
+ layer: `${ErrorLayer}`;
22
+ }
23
+ /** Successful API response envelope. */
24
+ interface ApiSuccessResponse<T> {
25
+ data: T;
26
+ }
27
+ /**
28
+ * Error API response envelope.
29
+ *
30
+ * `errors` are ordered by call stack: `[0]` is the deepest layer, `[n]` is the outermost.
31
+ */
32
+ interface ApiErrorResponse {
33
+ data: null;
34
+ errors: ApiError[];
35
+ }
36
+ /** Union type of success and error API responses. */
37
+ type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
38
+ /**
39
+ * Environment type.
40
+ * @see waffo-pancake-order-service/app/lib/types.ts
41
+ */
42
+ declare enum Environment {
43
+ Test = "test",
44
+ Prod = "prod"
45
+ }
46
+ /**
47
+ * Tax category for products.
48
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
49
+ */
50
+ declare enum TaxCategory {
51
+ DigitalGoods = "digital_goods",
52
+ SaaS = "saas",
53
+ Software = "software",
54
+ Ebook = "ebook",
55
+ OnlineCourse = "online_course",
56
+ Consulting = "consulting",
57
+ ProfessionalService = "professional_service"
58
+ }
59
+ /**
60
+ * Subscription billing period.
61
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
62
+ */
63
+ declare enum BillingPeriod {
64
+ Weekly = "weekly",
65
+ Monthly = "monthly",
66
+ Quarterly = "quarterly",
67
+ Yearly = "yearly"
68
+ }
69
+ /**
70
+ * Product version status.
71
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
72
+ */
73
+ declare enum ProductVersionStatus {
74
+ Active = "active",
75
+ Inactive = "inactive"
76
+ }
77
+ /**
78
+ * Store entity status.
79
+ * @see waffo-pancake-store-service/app/lib/resources/store.ts
80
+ */
81
+ declare enum EntityStatus {
82
+ Active = "active",
83
+ Inactive = "inactive",
84
+ Suspended = "suspended"
85
+ }
86
+ /**
87
+ * Store member role.
88
+ * @see waffo-pancake-store-service/app/lib/resources/store.ts
89
+ */
90
+ declare enum StoreRole {
91
+ Owner = "owner",
92
+ Admin = "admin",
93
+ Member = "member"
94
+ }
95
+ /**
96
+ * One-time order status.
97
+ * @see waffo-pancake-order-service/app/lib/resources/onetime-order.ts
98
+ */
99
+ declare enum OnetimeOrderStatus {
100
+ Pending = "pending",
101
+ Completed = "completed",
102
+ Canceled = "canceled"
103
+ }
104
+ /**
105
+ * Subscription order status.
106
+ *
107
+ * State machine:
108
+ * - pending -> active, canceled
109
+ * - active -> canceling, past_due, canceled, expired
110
+ * - canceling -> active, canceled
111
+ * - past_due -> active, canceled
112
+ * - canceled -> terminal
113
+ * - expired -> terminal
114
+ *
115
+ * @see waffo-pancake-order-service/app/lib/resources/subscription-order.ts
116
+ */
117
+ declare enum SubscriptionOrderStatus {
118
+ Pending = "pending",
119
+ Active = "active",
120
+ Canceling = "canceling",
121
+ Canceled = "canceled",
122
+ PastDue = "past_due",
123
+ Expired = "expired"
124
+ }
125
+ /**
126
+ * Payment status.
127
+ * @see waffo-pancake-order-service/app/lib/resources/payment.ts
128
+ */
129
+ declare enum PaymentStatus {
130
+ Pending = "pending",
131
+ Succeeded = "succeeded",
132
+ Failed = "failed",
133
+ Canceled = "canceled"
134
+ }
135
+ /**
136
+ * Refund ticket status.
137
+ * @see waffo-pancake-order-service/app/lib/resources/refund-ticket.ts
138
+ */
139
+ declare enum RefundTicketStatus {
140
+ Pending = "pending",
141
+ Approved = "approved",
142
+ Rejected = "rejected",
143
+ Processing = "processing",
144
+ Succeeded = "succeeded",
145
+ Failed = "failed"
146
+ }
147
+ /**
148
+ * Refund status.
149
+ * @see waffo-pancake-order-service/app/lib/resources/refund.ts
150
+ */
151
+ declare enum RefundStatus {
152
+ Succeeded = "succeeded",
153
+ Failed = "failed"
154
+ }
155
+ /**
156
+ * Media asset type.
157
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
158
+ */
159
+ declare enum MediaType {
160
+ Image = "image",
161
+ Video = "video"
162
+ }
163
+ /**
164
+ * Checkout session product type.
165
+ * @see waffo-pancake-order-service/app/lib/types.ts
166
+ */
167
+ declare enum CheckoutSessionProductType {
168
+ Onetime = "onetime",
169
+ Subscription = "subscription"
170
+ }
171
+ /** Error layer identifier in the call stack. */
172
+ declare enum ErrorLayer {
173
+ Gateway = "gateway",
174
+ User = "user",
175
+ Store = "store",
176
+ Product = "product",
177
+ Order = "order",
178
+ GraphQL = "graphql",
179
+ Resource = "resource",
180
+ Email = "email"
181
+ }
182
+ /**
183
+ * Parameters for issuing a buyer session token.
184
+ * @see waffo-pancake-user-service/app/lib/utils/jwt.ts IssueSessionTokenRequest
185
+ */
186
+ interface IssueSessionTokenParams {
187
+ /** Buyer identity (email or any merchant-provided identifier string) */
188
+ buyerIdentity: string;
189
+ /** Store ID */
190
+ storeId: string;
191
+ }
192
+ /**
193
+ * Issued session token response.
194
+ *
195
+ * @example
196
+ * { token: "eyJhbGciOi...", expiresAt: "2026-03-10T09:00:00.000Z" }
197
+ */
198
+ interface SessionToken {
199
+ /** JWT token string */
200
+ token: string;
201
+ /** Expiration time (ISO 8601 UTC) */
202
+ expiresAt: string;
203
+ }
204
+ /**
205
+ * Webhook configuration for test and production environments.
206
+ * @see waffo-pancake-store-service/app/lib/types.ts
207
+ */
208
+ interface WebhookSettings {
209
+ /** Test environment webhook URL */
210
+ testWebhookUrl: string | null;
211
+ /** Production environment webhook URL */
212
+ prodWebhookUrl: string | null;
213
+ /** Event types subscribed in test environment */
214
+ testEvents: string[];
215
+ /** Event types subscribed in production environment */
216
+ prodEvents: string[];
217
+ }
218
+ /**
219
+ * Notification settings (all default to true).
220
+ * @see waffo-pancake-store-service/app/lib/types.ts
221
+ */
222
+ interface NotificationSettings {
223
+ emailOrderConfirmation: boolean;
224
+ emailSubscriptionConfirmation: boolean;
225
+ emailSubscriptionCycled: boolean;
226
+ emailSubscriptionCanceled: boolean;
227
+ emailSubscriptionRevoked: boolean;
228
+ emailSubscriptionPastDue: boolean;
229
+ notifyNewOrders: boolean;
230
+ notifyNewSubscriptions: boolean;
231
+ }
232
+ /**
233
+ * Single-theme checkout page styling.
234
+ * @see waffo-pancake-store-service/app/lib/types.ts
235
+ */
236
+ interface CheckoutThemeSettings {
237
+ checkoutLogo: string | null;
238
+ checkoutColorPrimary: string;
239
+ checkoutColorBackground: string;
240
+ checkoutColorCard: string;
241
+ checkoutColorText: string;
242
+ checkoutColorTextSecondary: string;
243
+ checkoutBorderRadius: string;
244
+ }
245
+ /**
246
+ * Checkout page configuration (light and dark themes).
247
+ * @see waffo-pancake-store-service/app/lib/types.ts
248
+ */
249
+ interface CheckoutSettings {
250
+ light: CheckoutThemeSettings;
251
+ dark: CheckoutThemeSettings;
252
+ }
253
+ /**
254
+ * Store entity.
255
+ * @see waffo-pancake-store-service/app/lib/resources/store.ts
256
+ */
257
+ interface Store {
258
+ id: string;
259
+ name: string;
260
+ status: EntityStatus;
261
+ logo: string | null;
262
+ supportEmail: string | null;
263
+ website: string | null;
264
+ slug: string | null;
265
+ isPublic: boolean;
266
+ prodEnabled: boolean;
267
+ webhookSettings: WebhookSettings | null;
268
+ notificationSettings: NotificationSettings | null;
269
+ checkoutSettings: CheckoutSettings | null;
270
+ deletedAt: string | null;
271
+ createdAt: string;
272
+ updatedAt: string;
273
+ }
274
+ /** Parameters for creating a store. */
275
+ interface CreateStoreParams {
276
+ /** Store name (slug is auto-generated) */
277
+ name: string;
278
+ }
279
+ /** Parameters for updating a store. */
280
+ interface UpdateStoreParams {
281
+ /** Store ID */
282
+ id: string;
283
+ name?: string;
284
+ status?: EntityStatus;
285
+ logo?: string | null;
286
+ supportEmail?: string | null;
287
+ website?: string | null;
288
+ isPublic?: boolean;
289
+ webhookSettings?: WebhookSettings | null;
290
+ notificationSettings?: NotificationSettings | null;
291
+ checkoutSettings?: CheckoutSettings | null;
292
+ }
293
+ /** Parameters for deleting (soft-delete) a store. */
294
+ interface DeleteStoreParams {
295
+ /** Store ID */
296
+ id: string;
297
+ }
298
+ /** Parameters for adding a merchant to a store. */
299
+ interface AddMerchantParams {
300
+ storeId: string;
301
+ email: string;
302
+ role: "admin" | "member";
303
+ }
304
+ /** Result of adding a merchant to a store. */
305
+ interface AddMerchantResult {
306
+ storeId: string;
307
+ merchantId: string;
308
+ email: string;
309
+ role: string;
310
+ status: string;
311
+ addedAt: string;
312
+ }
313
+ /** Parameters for removing a merchant from a store. */
314
+ interface RemoveMerchantParams {
315
+ storeId: string;
316
+ merchantId: string;
317
+ }
318
+ /** Result of removing a merchant from a store. */
319
+ interface RemoveMerchantResult {
320
+ message: string;
321
+ removedAt: string;
322
+ }
323
+ /** Parameters for updating a merchant's role. */
324
+ interface UpdateRoleParams {
325
+ storeId: string;
326
+ merchantId: string;
327
+ role: "admin" | "member";
328
+ }
329
+ /** Result of updating a merchant's role. */
330
+ interface UpdateRoleResult {
331
+ storeId: string;
332
+ merchantId: string;
333
+ role: string;
334
+ updatedAt: string;
335
+ }
336
+ /**
337
+ * Price for a single currency.
338
+ *
339
+ * Amounts are stored in the smallest currency unit (e.g. cents, yen)
340
+ * to avoid floating-point precision issues.
341
+ *
342
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
343
+ *
344
+ * @example
345
+ * // USD $9.99
346
+ * { amount: 999, taxIncluded: true, taxCategory: "saas" }
347
+ *
348
+ * @example
349
+ * // JPY ¥1000
350
+ * { amount: 1000, taxIncluded: false, taxCategory: "software" }
351
+ */
352
+ interface PriceInfo {
353
+ /** Price amount in smallest currency unit */
354
+ amount: number;
355
+ /** Whether the price is tax-inclusive */
356
+ taxIncluded: boolean;
357
+ /** Tax category */
358
+ taxCategory: TaxCategory;
359
+ }
360
+ /**
361
+ * Multi-currency prices (keyed by ISO 4217 currency code).
362
+ *
363
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
364
+ *
365
+ * @example
366
+ * {
367
+ * "USD": { amount: 999, taxIncluded: true, taxCategory: "saas" },
368
+ * "EUR": { amount: 899, taxIncluded: true, taxCategory: "saas" }
369
+ * }
370
+ */
371
+ type Prices = Record<string, PriceInfo>;
372
+ /**
373
+ * Media asset (image or video).
374
+ * @see waffo-pancake-product-service/app/lib/resources/types.ts
375
+ */
376
+ interface MediaItem {
377
+ /** Media type */
378
+ type: `${MediaType}`;
379
+ /** Asset URL */
380
+ url: string;
381
+ /** Alt text */
382
+ alt?: string;
383
+ /** Thumbnail URL */
384
+ thumbnail?: string;
385
+ }
386
+ /**
387
+ * One-time product detail (public API shape).
388
+ * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts OnetimeProductDetail
389
+ */
390
+ interface OnetimeProductDetail {
391
+ id: string;
392
+ storeId: string;
393
+ name: string;
394
+ description: string | null;
395
+ prices: Prices;
396
+ media: MediaItem[];
397
+ successUrl: string | null;
398
+ metadata: Record<string, unknown>;
399
+ status: ProductVersionStatus;
400
+ createdAt: string;
401
+ updatedAt: string;
402
+ }
403
+ /**
404
+ * Parameters for creating a one-time product.
405
+ * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts CreateOnetimeProductRequestBody
406
+ */
407
+ interface CreateOnetimeProductParams {
408
+ storeId: string;
409
+ name: string;
410
+ prices: Prices;
411
+ description?: string;
412
+ media?: MediaItem[];
413
+ successUrl?: string;
414
+ metadata?: Record<string, unknown>;
415
+ }
416
+ /**
417
+ * Parameters for updating a one-time product (creates a new version; skips if unchanged).
418
+ * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts UpdateOnetimeProductContentRequestBody
419
+ */
420
+ interface UpdateOnetimeProductParams {
421
+ id: string;
422
+ name: string;
423
+ prices: Prices;
424
+ description?: string;
425
+ media?: MediaItem[];
426
+ successUrl?: string;
427
+ metadata?: Record<string, unknown>;
428
+ }
429
+ /** Parameters for publishing a one-time product's test version to production. */
430
+ interface PublishOnetimeProductParams {
431
+ /** Product ID */
432
+ id: string;
433
+ }
434
+ /**
435
+ * Parameters for updating a one-time product's status.
436
+ * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts UpdateOnetimeStatusRequestBody
437
+ */
438
+ interface UpdateOnetimeStatusParams {
439
+ id: string;
440
+ status: ProductVersionStatus;
441
+ }
442
+ /**
443
+ * Subscription product detail (public API shape).
444
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts SubscriptionProductDetail
445
+ */
446
+ interface SubscriptionProductDetail {
447
+ id: string;
448
+ storeId: string;
449
+ name: string;
450
+ description: string | null;
451
+ billingPeriod: BillingPeriod;
452
+ prices: Prices;
453
+ media: MediaItem[];
454
+ successUrl: string | null;
455
+ metadata: Record<string, unknown>;
456
+ status: ProductVersionStatus;
457
+ createdAt: string;
458
+ updatedAt: string;
459
+ }
460
+ /**
461
+ * Parameters for creating a subscription product.
462
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts CreateSubscriptionProductRequestBody
463
+ */
464
+ interface CreateSubscriptionProductParams {
465
+ storeId: string;
466
+ name: string;
467
+ billingPeriod: BillingPeriod;
468
+ prices: Prices;
469
+ description?: string;
470
+ media?: MediaItem[];
471
+ successUrl?: string;
472
+ metadata?: Record<string, unknown>;
473
+ }
474
+ /**
475
+ * Parameters for updating a subscription product (creates a new version; skips if unchanged).
476
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts UpdateSubscriptionProductContentRequestBody
477
+ */
478
+ interface UpdateSubscriptionProductParams {
479
+ id: string;
480
+ name: string;
481
+ billingPeriod: BillingPeriod;
482
+ prices: Prices;
483
+ description?: string;
484
+ media?: MediaItem[];
485
+ successUrl?: string;
486
+ metadata?: Record<string, unknown>;
487
+ }
488
+ /** Parameters for publishing a subscription product's test version to production. */
489
+ interface PublishSubscriptionProductParams {
490
+ /** Product ID */
491
+ id: string;
492
+ }
493
+ /**
494
+ * Parameters for updating a subscription product's status.
495
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts UpdateSubscriptionStatusRequestBody
496
+ */
497
+ interface UpdateSubscriptionStatusParams {
498
+ id: string;
499
+ status: ProductVersionStatus;
500
+ }
501
+ /**
502
+ * Group rules for subscription product groups.
503
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts
504
+ */
505
+ interface GroupRules {
506
+ /** Whether trial period is shared across products in the group */
507
+ sharedTrial: boolean;
508
+ }
509
+ /**
510
+ * Subscription product group entity.
511
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts
512
+ */
513
+ interface SubscriptionProductGroup {
514
+ id: string;
515
+ storeId: string;
516
+ name: string;
517
+ description: string | null;
518
+ rules: GroupRules;
519
+ productIds: string[];
520
+ environment: Environment;
521
+ createdAt: string;
522
+ updatedAt: string;
523
+ }
524
+ /**
525
+ * Parameters for creating a subscription product group.
526
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts CreateGroupRequestBody
527
+ */
528
+ interface CreateSubscriptionProductGroupParams {
529
+ storeId: string;
530
+ name: string;
531
+ description?: string;
532
+ rules?: GroupRules;
533
+ productIds?: string[];
534
+ }
535
+ /**
536
+ * Parameters for updating a subscription product group (`productIds` is a full replacement).
537
+ * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts UpdateGroupRequestBody
538
+ */
539
+ interface UpdateSubscriptionProductGroupParams {
540
+ id: string;
541
+ name?: string;
542
+ description?: string;
543
+ rules?: GroupRules;
544
+ productIds?: string[];
545
+ }
546
+ /** Parameters for hard-deleting a subscription product group. */
547
+ interface DeleteSubscriptionProductGroupParams {
548
+ /** Group ID */
549
+ id: string;
550
+ }
551
+ /** Parameters for publishing a test-environment group to production (upsert). */
552
+ interface PublishSubscriptionProductGroupParams {
553
+ /** Group ID */
554
+ id: string;
555
+ }
556
+ /** Parameters for canceling a subscription order. */
557
+ interface CancelSubscriptionParams {
558
+ /** Order ID */
559
+ orderId: string;
560
+ }
561
+ /**
562
+ * Result of canceling a subscription order.
563
+ * @see waffo-pancake-order-service cancel-order route.ts
564
+ */
565
+ interface CancelSubscriptionResult {
566
+ orderId: string;
567
+ /** Status after cancellation (`"canceled"` or `"canceling"`) */
568
+ status: `${SubscriptionOrderStatus}`;
569
+ }
570
+ /**
571
+ * Buyer billing details for checkout.
572
+ * @see waffo-pancake-order-service/app/lib/types.ts
573
+ */
574
+ interface BillingDetail {
575
+ /** Country code (ISO 3166-1 alpha-2) */
576
+ country: string;
577
+ /** Whether this is a business purchase */
578
+ isBusiness: boolean;
579
+ /** Postal / ZIP code */
580
+ postcode?: string;
581
+ /** State / province code (required for US/CA) */
582
+ state?: string;
583
+ /** Business name (required when isBusiness=true) */
584
+ businessName?: string;
585
+ /** Tax ID (required for EU businesses) */
586
+ taxId?: string;
587
+ }
588
+ /**
589
+ * Parameters for creating a checkout session.
590
+ * @see waffo-pancake-order-service/app/lib/types.ts CreateCheckoutSessionRequest
591
+ */
592
+ interface CreateCheckoutSessionParams {
593
+ /** Store ID */
594
+ storeId?: string;
595
+ /** Product ID */
596
+ productId: string;
597
+ /** Product type */
598
+ productType: `${CheckoutSessionProductType}`;
599
+ /** Currency code (ISO 4217) */
600
+ currency: string;
601
+ /** Optional price snapshot override (reads from DB if omitted) */
602
+ priceSnapshot?: PriceInfo;
603
+ /** Trial toggle override (subscription only) */
604
+ withTrial?: boolean;
605
+ /** Pre-filled buyer email */
606
+ buyerEmail?: string;
607
+ /** Pre-filled billing details */
608
+ billingDetail?: BillingDetail;
609
+ /** Redirect URL after successful payment */
610
+ successUrl?: string;
611
+ /** Session expiration in seconds (default: 7 days) */
612
+ expiresInSeconds?: number;
613
+ /** Custom metadata */
614
+ metadata?: Record<string, string>;
615
+ }
616
+ /** Result of creating a checkout session. */
617
+ interface CheckoutSessionResult {
618
+ /** Session ID */
619
+ sessionId: string;
620
+ /** URL to redirect the customer to */
621
+ checkoutUrl: string;
622
+ /** Session expiration time (ISO 8601 UTC) */
623
+ expiresAt: string;
624
+ }
625
+ /** Parameters for a GraphQL query. */
626
+ interface GraphQLParams {
627
+ /** GraphQL query string */
628
+ query: string;
629
+ /** Query variables */
630
+ variables?: Record<string, unknown>;
631
+ }
632
+ /** GraphQL response envelope. */
633
+ interface GraphQLResponse<T = Record<string, unknown>> {
634
+ data: T | null;
635
+ errors?: Array<{
636
+ message: string;
637
+ locations?: Array<{
638
+ line: number;
639
+ column: number;
640
+ }>;
641
+ path?: string[];
642
+ }>;
643
+ }
644
+ /**
645
+ * Webhook event types.
646
+ * @see docs/api-reference/webhooks.mdx
647
+ */
648
+ declare enum WebhookEventType {
649
+ /** One-time order first payment succeeded */
650
+ OrderCompleted = "order.completed",
651
+ /** Subscription first payment succeeded (newly activated) */
652
+ SubscriptionActivated = "subscription.activated",
653
+ /** Subscription renewal payment succeeded */
654
+ SubscriptionPaymentSucceeded = "subscription.payment_succeeded",
655
+ /** Buyer initiated cancellation (expires at end of current period) */
656
+ SubscriptionCanceling = "subscription.canceling",
657
+ /** Buyer withdrew cancellation (subscription restored) */
658
+ SubscriptionUncanceled = "subscription.uncanceled",
659
+ /** Subscription product changed (upgrade/downgrade) */
660
+ SubscriptionUpdated = "subscription.updated",
661
+ /** Subscription fully terminated */
662
+ SubscriptionCanceled = "subscription.canceled",
663
+ /** Renewal payment failed (past due) */
664
+ SubscriptionPastDue = "subscription.past_due",
665
+ /** Refund succeeded */
666
+ RefundSucceeded = "refund.succeeded",
667
+ /** Refund failed */
668
+ RefundFailed = "refund.failed"
669
+ }
670
+ /**
671
+ * Common data fields in a webhook event payload.
672
+ * @see docs/api-reference/webhooks.mdx
673
+ */
674
+ interface WebhookEventData {
675
+ orderId: string;
676
+ buyerEmail: string;
677
+ currency: string;
678
+ /** Amount in smallest currency unit */
679
+ amount: number;
680
+ /** Tax amount in smallest currency unit */
681
+ taxAmount: number;
682
+ productName: string;
683
+ }
684
+ /**
685
+ * Webhook event payload.
686
+ *
687
+ * @see docs/api-reference/webhooks.mdx
688
+ *
689
+ * @example
690
+ * {
691
+ * id: "550e8400-...",
692
+ * timestamp: "2026-03-10T08:30:00.000Z",
693
+ * eventType: "order.completed",
694
+ * eventId: "pay_660e8400-...",
695
+ * storeId: "770e8400-...",
696
+ * mode: "prod",
697
+ * data: { orderId: "...", buyerEmail: "...", currency: "USD", amount: 2900, taxAmount: 290, productName: "Pro Plan" }
698
+ * }
699
+ */
700
+ interface WebhookEvent<T = WebhookEventData> {
701
+ /** Delivery record unique ID (UUID), usable for idempotent deduplication */
702
+ id: string;
703
+ /** Event timestamp (ISO 8601 UTC) */
704
+ timestamp: string;
705
+ /** Event type */
706
+ eventType: `${WebhookEventType}` | (string & {});
707
+ /** Business event ID (e.g. payment ID, order ID) */
708
+ eventId: string;
709
+ /** Store ID the event belongs to */
710
+ storeId: string;
711
+ /** Environment identifier */
712
+ mode: `${Environment}`;
713
+ /** Event data */
714
+ data: T;
715
+ }
716
+ /** Options for {@link verifyWebhook}. */
717
+ interface VerifyWebhookOptions {
718
+ /**
719
+ * Specify which environment's public key to use for verification.
720
+ * When omitted, both keys are tried automatically (prod first).
721
+ */
722
+ environment?: `${Environment}`;
723
+ /**
724
+ * Timestamp tolerance window in milliseconds for replay protection.
725
+ * Set to 0 to skip timestamp checking.
726
+ * @default 300000 (5 minutes)
727
+ */
728
+ toleranceMs?: number;
729
+ }
730
+
731
+ /**
732
+ * Internal HTTP client that auto-signs requests and attaches idempotency keys.
733
+ *
734
+ * Not exported publicly — used by resource classes via {@link WaffoPancake}.
735
+ */
736
+ declare class HttpClient {
737
+ private readonly merchantId;
738
+ private readonly privateKey;
739
+ private readonly baseUrl;
740
+ private readonly _fetch;
741
+ constructor(config: WaffoPancakeConfig);
742
+ /**
743
+ * Send a signed POST request and return the parsed `data` field.
744
+ *
745
+ * Behavior:
746
+ * - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
747
+ * - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
748
+ * - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
749
+ *
750
+ * @param path - API path (e.g. `/v1/actions/store/create-store`)
751
+ * @param body - Request body object
752
+ * @returns Parsed `data` field from the response
753
+ * @throws {WaffoPancakeError} When the API returns errors
754
+ */
755
+ post<T>(path: string, body: object): Promise<T>;
756
+ }
757
+
758
+ /** Authentication resource — issue session tokens for buyers. */
759
+ declare class AuthResource {
760
+ private readonly http;
761
+ constructor(http: HttpClient);
762
+ /**
763
+ * Issue a session token for a buyer.
764
+ *
765
+ * @param params - Token issuance parameters
766
+ * @returns Issued session token with expiration
767
+ *
768
+ * @example
769
+ * const { token, expiresAt } = await client.auth.issueSessionToken({
770
+ * storeId: "store_xxx",
771
+ * buyerIdentity: "customer@example.com",
772
+ * });
773
+ */
774
+ issueSessionToken(params: IssueSessionTokenParams): Promise<SessionToken>;
775
+ }
776
+
777
+ /** Checkout resource — create checkout sessions for payments. */
778
+ declare class CheckoutResource {
779
+ private readonly http;
780
+ constructor(http: HttpClient);
781
+ /**
782
+ * Create a checkout session. Returns a URL to redirect the customer to.
783
+ *
784
+ * @param params - Checkout session parameters
785
+ * @returns Session ID, checkout URL, and expiration
786
+ *
787
+ * @example
788
+ * const session = await client.checkout.createSession({
789
+ * storeId: "store_xxx",
790
+ * productId: "prod_xxx",
791
+ * productType: "onetime",
792
+ * currency: "USD",
793
+ * buyerEmail: "customer@example.com",
794
+ * });
795
+ * // Redirect to session.checkoutUrl
796
+ */
797
+ createSession(params: CreateCheckoutSessionParams): Promise<CheckoutSessionResult>;
798
+ }
799
+
800
+ /** GraphQL query resource (Query only, no Mutations). */
801
+ declare class GraphQLResource {
802
+ private readonly http;
803
+ constructor(http: HttpClient);
804
+ /**
805
+ * Execute a GraphQL query (Query only, no Mutations).
806
+ *
807
+ * @param params - GraphQL query and optional variables
808
+ * @returns GraphQL response with data and optional errors
809
+ *
810
+ * @example
811
+ * const result = await client.graphql.query<{ stores: Array<{ id: string; name: string }> }>({
812
+ * query: `query { stores { id name status } }`,
813
+ * });
814
+ * console.log(result.data?.stores);
815
+ *
816
+ * @example
817
+ * const result = await client.graphql.query({
818
+ * query: `query ($id: ID!) { onetimeProduct(id: $id) { id name prices } }`,
819
+ * variables: { id: "prod_xxx" },
820
+ * });
821
+ */
822
+ query<T = Record<string, unknown>>(params: GraphQLParams): Promise<GraphQLResponse<T>>;
823
+ }
824
+
825
+ /** One-time product management resource. */
826
+ declare class OnetimeProductsResource {
827
+ private readonly http;
828
+ constructor(http: HttpClient);
829
+ /**
830
+ * Create a one-time product with multi-currency pricing.
831
+ *
832
+ * @param params - Product creation parameters
833
+ * @returns Created product detail
834
+ *
835
+ * @example
836
+ * const { product } = await client.onetimeProducts.create({
837
+ * storeId: "store_xxx",
838
+ * name: "E-Book",
839
+ * prices: { USD: { amount: 2900, taxIncluded: false, taxCategory: "digital_goods" } },
840
+ * });
841
+ */
842
+ create(params: CreateOnetimeProductParams): Promise<{
843
+ product: OnetimeProductDetail;
844
+ }>;
845
+ /**
846
+ * Update a one-time product. Creates a new version; skips if unchanged.
847
+ *
848
+ * @param params - Product update parameters (all content fields required)
849
+ * @returns Updated product detail
850
+ *
851
+ * @example
852
+ * const { product } = await client.onetimeProducts.update({
853
+ * id: "prod_xxx",
854
+ * name: "E-Book v2",
855
+ * prices: { USD: { amount: 3900, taxIncluded: false, taxCategory: "digital_goods" } },
856
+ * });
857
+ */
858
+ update(params: UpdateOnetimeProductParams): Promise<{
859
+ product: OnetimeProductDetail;
860
+ }>;
861
+ /**
862
+ * Publish a one-time product's test version to production.
863
+ *
864
+ * @param params - Product to publish
865
+ * @returns Published product detail
866
+ *
867
+ * @example
868
+ * const { product } = await client.onetimeProducts.publish({ id: "prod_xxx" });
869
+ */
870
+ publish(params: PublishOnetimeProductParams): Promise<{
871
+ product: OnetimeProductDetail;
872
+ }>;
873
+ /**
874
+ * Update a one-time product's status (active/inactive).
875
+ *
876
+ * @param params - Status update parameters
877
+ * @returns Updated product detail
878
+ *
879
+ * @example
880
+ * const { product } = await client.onetimeProducts.updateStatus({
881
+ * id: "prod_xxx",
882
+ * status: ProductVersionStatus.Inactive,
883
+ * });
884
+ */
885
+ updateStatus(params: UpdateOnetimeStatusParams): Promise<{
886
+ product: OnetimeProductDetail;
887
+ }>;
888
+ }
889
+
890
+ /** Order management resource. */
891
+ declare class OrdersResource {
892
+ private readonly http;
893
+ constructor(http: HttpClient);
894
+ /**
895
+ * Cancel a subscription order.
896
+ *
897
+ * - pending -> canceled (immediate)
898
+ * - active/trialing -> canceling (PSP cancel, webhook updates later)
899
+ *
900
+ * @param params - Order to cancel
901
+ * @returns Order ID and resulting status
902
+ *
903
+ * @example
904
+ * const { orderId, status } = await client.orders.cancelSubscription({
905
+ * orderId: "order_xxx",
906
+ * });
907
+ * // status: "canceled" or "canceling"
908
+ */
909
+ cancelSubscription(params: CancelSubscriptionParams): Promise<CancelSubscriptionResult>;
910
+ }
911
+
912
+ /** Store merchant management resource (coming soon — endpoints return 501). */
913
+ declare class StoreMerchantsResource {
914
+ private readonly http;
915
+ constructor(http: HttpClient);
916
+ /**
917
+ * Add a merchant to a store.
918
+ *
919
+ * @param params - Merchant addition parameters
920
+ * @returns Added merchant details
921
+ *
922
+ * @example
923
+ * const result = await client.storeMerchants.add({
924
+ * storeId: "store_xxx",
925
+ * email: "member@example.com",
926
+ * role: "admin",
927
+ * });
928
+ */
929
+ add(params: AddMerchantParams): Promise<AddMerchantResult>;
930
+ /**
931
+ * Remove a merchant from a store.
932
+ *
933
+ * @param params - Merchant removal parameters
934
+ * @returns Removal confirmation
935
+ *
936
+ * @example
937
+ * const result = await client.storeMerchants.remove({
938
+ * storeId: "store_xxx",
939
+ * merchantId: "merchant_xxx",
940
+ * });
941
+ */
942
+ remove(params: RemoveMerchantParams): Promise<RemoveMerchantResult>;
943
+ /**
944
+ * Update a merchant's role in a store.
945
+ *
946
+ * @param params - Role update parameters
947
+ * @returns Updated role details
948
+ *
949
+ * @example
950
+ * const result = await client.storeMerchants.updateRole({
951
+ * storeId: "store_xxx",
952
+ * merchantId: "merchant_xxx",
953
+ * role: "member",
954
+ * });
955
+ */
956
+ updateRole(params: UpdateRoleParams): Promise<UpdateRoleResult>;
957
+ }
958
+
959
+ /** Store management resource — create, update, and delete stores. */
960
+ declare class StoresResource {
961
+ private readonly http;
962
+ constructor(http: HttpClient);
963
+ /**
964
+ * Create a new store. Slug is auto-generated from the name.
965
+ *
966
+ * @param params - Store creation parameters
967
+ * @returns Created store entity
968
+ *
969
+ * @example
970
+ * const { store } = await client.stores.create({ name: "My Store" });
971
+ */
972
+ create(params: CreateStoreParams): Promise<{
973
+ store: Store;
974
+ }>;
975
+ /**
976
+ * Update an existing store's settings.
977
+ *
978
+ * @param params - Fields to update (only provided fields are changed)
979
+ * @returns Updated store entity
980
+ *
981
+ * @example
982
+ * const { store } = await client.stores.update({
983
+ * id: "store_xxx",
984
+ * name: "Updated Name",
985
+ * supportEmail: "help@example.com",
986
+ * });
987
+ */
988
+ update(params: UpdateStoreParams): Promise<{
989
+ store: Store;
990
+ }>;
991
+ /**
992
+ * Soft-delete a store. Only the owner can delete.
993
+ *
994
+ * @param params - Store to delete
995
+ * @returns Deleted store entity (with `deletedAt` set)
996
+ *
997
+ * @example
998
+ * const { store } = await client.stores.delete({ id: "store_xxx" });
999
+ */
1000
+ delete(params: DeleteStoreParams): Promise<{
1001
+ store: Store;
1002
+ }>;
1003
+ }
1004
+
1005
+ /** Subscription product group management resource (shared trial, plan switching). */
1006
+ declare class SubscriptionProductGroupsResource {
1007
+ private readonly http;
1008
+ constructor(http: HttpClient);
1009
+ /**
1010
+ * Create a subscription product group for shared-trial or plan switching.
1011
+ *
1012
+ * @param params - Group creation parameters
1013
+ * @returns Created group entity
1014
+ *
1015
+ * @example
1016
+ * const { group } = await client.subscriptionProductGroups.create({
1017
+ * storeId: "store_xxx",
1018
+ * name: "Pro Plans",
1019
+ * rules: { sharedTrial: true },
1020
+ * productIds: ["prod_aaa", "prod_bbb"],
1021
+ * });
1022
+ */
1023
+ create(params: CreateSubscriptionProductGroupParams): Promise<{
1024
+ group: SubscriptionProductGroup;
1025
+ }>;
1026
+ /**
1027
+ * Update a subscription product group. `productIds` is a full replacement.
1028
+ *
1029
+ * @param params - Group update parameters
1030
+ * @returns Updated group entity
1031
+ *
1032
+ * @example
1033
+ * const { group } = await client.subscriptionProductGroups.update({
1034
+ * id: "group_xxx",
1035
+ * productIds: ["prod_aaa", "prod_bbb", "prod_ccc"],
1036
+ * });
1037
+ */
1038
+ update(params: UpdateSubscriptionProductGroupParams): Promise<{
1039
+ group: SubscriptionProductGroup;
1040
+ }>;
1041
+ /**
1042
+ * Hard-delete a subscription product group.
1043
+ *
1044
+ * @param params - Group to delete
1045
+ * @returns Deleted group entity
1046
+ *
1047
+ * @example
1048
+ * const { group } = await client.subscriptionProductGroups.delete({ id: "group_xxx" });
1049
+ */
1050
+ delete(params: DeleteSubscriptionProductGroupParams): Promise<{
1051
+ group: SubscriptionProductGroup;
1052
+ }>;
1053
+ /**
1054
+ * Publish a test-environment group to production (upsert).
1055
+ *
1056
+ * @param params - Group to publish
1057
+ * @returns Published group entity
1058
+ *
1059
+ * @example
1060
+ * const { group } = await client.subscriptionProductGroups.publish({ id: "group_xxx" });
1061
+ */
1062
+ publish(params: PublishSubscriptionProductGroupParams): Promise<{
1063
+ group: SubscriptionProductGroup;
1064
+ }>;
1065
+ }
1066
+
1067
+ /** Subscription product management resource. */
1068
+ declare class SubscriptionProductsResource {
1069
+ private readonly http;
1070
+ constructor(http: HttpClient);
1071
+ /**
1072
+ * Create a subscription product with billing period and multi-currency pricing.
1073
+ *
1074
+ * @param params - Product creation parameters
1075
+ * @returns Created product detail
1076
+ *
1077
+ * @example
1078
+ * const { product } = await client.subscriptionProducts.create({
1079
+ * storeId: "store_xxx",
1080
+ * name: "Pro Plan",
1081
+ * billingPeriod: "monthly",
1082
+ * prices: { USD: { amount: 999, taxIncluded: false, taxCategory: "saas" } },
1083
+ * });
1084
+ */
1085
+ create(params: CreateSubscriptionProductParams): Promise<{
1086
+ product: SubscriptionProductDetail;
1087
+ }>;
1088
+ /**
1089
+ * Update a subscription product. Creates a new version; skips if unchanged.
1090
+ *
1091
+ * @param params - Product update parameters (all content fields required)
1092
+ * @returns Updated product detail
1093
+ *
1094
+ * @example
1095
+ * const { product } = await client.subscriptionProducts.update({
1096
+ * id: "prod_xxx",
1097
+ * name: "Pro Plan v2",
1098
+ * billingPeriod: "monthly",
1099
+ * prices: { USD: { amount: 1499, taxIncluded: false, taxCategory: "saas" } },
1100
+ * });
1101
+ */
1102
+ update(params: UpdateSubscriptionProductParams): Promise<{
1103
+ product: SubscriptionProductDetail;
1104
+ }>;
1105
+ /**
1106
+ * Publish a subscription product's test version to production.
1107
+ *
1108
+ * @param params - Product to publish
1109
+ * @returns Published product detail
1110
+ *
1111
+ * @example
1112
+ * const { product } = await client.subscriptionProducts.publish({ id: "prod_xxx" });
1113
+ */
1114
+ publish(params: PublishSubscriptionProductParams): Promise<{
1115
+ product: SubscriptionProductDetail;
1116
+ }>;
1117
+ /**
1118
+ * Update a subscription product's status (active/inactive).
1119
+ *
1120
+ * @param params - Status update parameters
1121
+ * @returns Updated product detail
1122
+ *
1123
+ * @example
1124
+ * const { product } = await client.subscriptionProducts.updateStatus({
1125
+ * id: "prod_xxx",
1126
+ * status: ProductVersionStatus.Active,
1127
+ * });
1128
+ */
1129
+ updateStatus(params: UpdateSubscriptionStatusParams): Promise<{
1130
+ product: SubscriptionProductDetail;
1131
+ }>;
1132
+ }
1133
+
1134
+ /**
1135
+ * Waffo Pancake TypeScript SDK client.
1136
+ *
1137
+ * Uses Merchant API Key (RSA-SHA256) authentication. All requests are
1138
+ * automatically signed — no manual header construction needed.
1139
+ *
1140
+ * @example
1141
+ * import { WaffoPancake } from "@waffo/pancake-ts";
1142
+ *
1143
+ * const client = new WaffoPancake({
1144
+ * merchantId: process.env.WAFFO_MERCHANT_ID!,
1145
+ * privateKey: process.env.WAFFO_PRIVATE_KEY!,
1146
+ * });
1147
+ *
1148
+ * // Create a store
1149
+ * const { store } = await client.stores.create({ name: "My Store" });
1150
+ *
1151
+ * // Create a product
1152
+ * const { product } = await client.onetimeProducts.create({
1153
+ * storeId: store.id,
1154
+ * name: "E-Book",
1155
+ * prices: { USD: { amount: 2900, taxIncluded: false, taxCategory: "digital_goods" } },
1156
+ * });
1157
+ *
1158
+ * // Create a checkout session
1159
+ * const session = await client.checkout.createSession({
1160
+ * storeId: store.id,
1161
+ * productId: product.id,
1162
+ * productType: "onetime",
1163
+ * currency: "USD",
1164
+ * });
1165
+ * // => redirect customer to session.checkoutUrl
1166
+ *
1167
+ * // Query data via GraphQL
1168
+ * const result = await client.graphql.query({
1169
+ * query: `query { stores { id name status } }`,
1170
+ * });
1171
+ */
1172
+ declare class WaffoPancake {
1173
+ private readonly http;
1174
+ readonly auth: AuthResource;
1175
+ readonly stores: StoresResource;
1176
+ readonly storeMerchants: StoreMerchantsResource;
1177
+ readonly onetimeProducts: OnetimeProductsResource;
1178
+ readonly subscriptionProducts: SubscriptionProductsResource;
1179
+ readonly subscriptionProductGroups: SubscriptionProductGroupsResource;
1180
+ readonly orders: OrdersResource;
1181
+ readonly checkout: CheckoutResource;
1182
+ readonly graphql: GraphQLResource;
1183
+ constructor(config: WaffoPancakeConfig);
1184
+ }
1185
+
1186
+ /**
1187
+ * Error thrown when the API returns a non-success response.
1188
+ *
1189
+ * @example
1190
+ * try {
1191
+ * await client.stores.create({ name: "My Store" });
1192
+ * } catch (err) {
1193
+ * if (err instanceof WaffoPancakeError) {
1194
+ * console.log(err.status); // 400
1195
+ * console.log(err.errors[0]); // { message: "...", layer: "store" }
1196
+ * }
1197
+ * }
1198
+ */
1199
+ declare class WaffoPancakeError extends Error {
1200
+ readonly status: number;
1201
+ readonly errors: ApiError[];
1202
+ constructor(status: number, errors: ApiError[]);
1203
+ }
1204
+
1205
+ /**
1206
+ * Verify and parse an incoming Waffo Pancake webhook event.
1207
+ *
1208
+ * Uses built-in Waffo public keys (RSA-SHA256) for signature verification.
1209
+ * Test and production environments use different key pairs; both are embedded in the SDK.
1210
+ *
1211
+ * Behavior:
1212
+ * - Parses the `X-Waffo-Signature` header (`t=<timestamp>,v1=<base64sig>`)
1213
+ * - Builds signature input `${t}.${rawBody}` and verifies with RSA-SHA256
1214
+ * - When `environment` is not specified, tries prod key first, then test key
1215
+ * - Optional: checks timestamp to prevent replay attacks (default 5-minute tolerance)
1216
+ *
1217
+ * @param payload - Raw request body string (must be unparsed)
1218
+ * @param signatureHeader - Value of the `X-Waffo-Signature` header
1219
+ * @param options - Verification options
1220
+ * @returns Parsed webhook event
1221
+ * @throws Error if header is missing/malformed, signature is invalid, or timestamp is stale
1222
+ *
1223
+ * @example
1224
+ * // Express (use raw body!)
1225
+ * app.post("/webhooks", express.raw({ type: "application/json" }), (req, res) => {
1226
+ * try {
1227
+ * const event = verifyWebhook(
1228
+ * req.body.toString("utf-8"),
1229
+ * req.headers["x-waffo-signature"] as string,
1230
+ * );
1231
+ * res.status(200).send("OK");
1232
+ * handleEventAsync(event).catch(console.error);
1233
+ * } catch {
1234
+ * res.status(401).send("Invalid signature");
1235
+ * }
1236
+ * });
1237
+ *
1238
+ * @example
1239
+ * // Next.js App Router
1240
+ * export async function POST(request: Request) {
1241
+ * const body = await request.text();
1242
+ * const sig = request.headers.get("x-waffo-signature");
1243
+ * const event = verifyWebhook(body, sig);
1244
+ * // handle event ...
1245
+ * return new Response("OK");
1246
+ * }
1247
+ *
1248
+ * @example
1249
+ * // Specify environment explicitly
1250
+ * const event = verifyWebhook(body, sig, { environment: "prod" });
1251
+ *
1252
+ * @example
1253
+ * // Disable replay protection
1254
+ * const event = verifyWebhook(body, sig, { toleranceMs: 0 });
1255
+ */
1256
+ declare function verifyWebhook<T = Record<string, unknown>>(payload: string, signatureHeader: string | undefined | null, options?: VerifyWebhookOptions): WebhookEvent<T>;
1257
+
1258
+ export { type AddMerchantParams, type AddMerchantResult, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type BillingDetail, BillingPeriod, type CancelSubscriptionParams, type CancelSubscriptionResult, CheckoutSessionProductType, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, PaymentStatus, type PriceInfo, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, RefundStatus, RefundTicketStatus, type RemoveMerchantParams, type RemoveMerchantResult, type SessionToken, type Store, StoreRole, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookSettings, verifyWebhook };