@waffo/pancake-ts 0.1.9 → 0.2.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.
package/dist/index.d.cts CHANGED
@@ -150,11 +150,14 @@ declare enum PaymentStatus {
150
150
  */
151
151
  declare enum RefundTicketStatus {
152
152
  Pending = "pending",
153
+ UnderReview = "under_review",
153
154
  Approved = "approved",
154
155
  Rejected = "rejected",
156
+ Returned = "returned",
155
157
  Processing = "processing",
156
158
  Succeeded = "succeeded",
157
- Failed = "failed"
159
+ Failed = "failed",
160
+ Cancelled = "cancelled"
158
161
  }
159
162
  /**
160
163
  * Refund status.
@@ -191,7 +194,9 @@ declare enum ErrorLayer {
191
194
  GraphQL = "graphql",
192
195
  Resource = "resource",
193
196
  /** SDK-specific layer for email delivery errors (not part of the service-side error layers). */
194
- Email = "email"
197
+ Email = "email",
198
+ /** SDK-side input validation (caught before network request). */
199
+ Sdk = "sdk"
195
200
  }
196
201
  /**
197
202
  * Parameters for issuing a buyer session token.
@@ -367,7 +372,7 @@ interface UpdateRoleResult {
367
372
  *
368
373
  * @example
369
374
  * // JPY ¥1000
370
- * { amount: 1000, taxCategory: "software" }
375
+ * { amount: "1000", taxCategory: "software" }
371
376
  */
372
377
  interface PriceInfo {
373
378
  /** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
@@ -383,7 +388,7 @@ interface PriceInfo {
383
388
  * @example
384
389
  * {
385
390
  * "USD": { amount: "9.99", taxCategory: "saas" },
386
- * "EUR": { amount: 899, taxCategory: "saas" }
391
+ * "EUR": { amount: "8.99", taxCategory: "saas" }
387
392
  * }
388
393
  */
389
394
  type Prices = Record<string, PriceInfo>;
@@ -642,8 +647,98 @@ interface CheckoutSessionResult {
642
647
  /** Session expiration time (ISO 8601 UTC) */
643
648
  expiresAt: string;
644
649
  }
650
+ /** Parameters for canceling a one-time order (buyer-side). */
651
+ interface CancelOnetimeOrderParams {
652
+ /** Order ID */
653
+ orderId: string;
654
+ }
655
+ /** Result of canceling a one-time order. */
656
+ interface CancelOnetimeOrderResult {
657
+ /** Order ID */
658
+ orderId: string;
659
+ /** Resulting status (`"canceled"`) */
660
+ status: string;
661
+ }
662
+ /** Parameters for reactivating a subscription (buyer-side). */
663
+ interface ReactivateSubscriptionParams {
664
+ /** Subscription order ID */
665
+ orderId: string;
666
+ }
667
+ /** Result of reactivating a subscription. */
668
+ interface ReactivateSubscriptionResult {
669
+ /** Order ID */
670
+ orderId: string;
671
+ /** Resulting status (`"active"`) */
672
+ status: string;
673
+ }
674
+ /** Requested refund amount. */
675
+ interface RequestedAmount {
676
+ /** Refund amount in display format (e.g., `"29.00"`) */
677
+ amount: string;
678
+ /** Currency code (ISO 4217) */
679
+ currency: string;
680
+ }
681
+ /** Parameters for creating a refund ticket (buyer-side). */
682
+ interface CreateRefundTicketParams {
683
+ /** Payment ID to refund */
684
+ paymentId: string;
685
+ /** Reason for the refund request */
686
+ reason: string;
687
+ /** Requested refund amount */
688
+ requestedAmount: RequestedAmount;
689
+ /** Custom metadata */
690
+ metadata?: Record<string, unknown>;
691
+ }
692
+ /** Parameters for resubmitting a rejected refund ticket (buyer-side). */
693
+ interface ResubmitRefundTicketParams {
694
+ /** Existing ticket ID */
695
+ ticketId: string;
696
+ /** Payment ID */
697
+ paymentId: string;
698
+ /** Updated reason */
699
+ reason: string;
700
+ /** Updated requested amount */
701
+ requestedAmount: RequestedAmount;
702
+ }
703
+ /** Refund ticket entity returned from create/resubmit operations. */
704
+ interface RefundTicket {
705
+ /** Ticket ID */
706
+ id: string;
707
+ /** Ticket type (e.g., `"refund"`) */
708
+ type: string;
709
+ /** Ticket status (e.g., `"pending"`, `"approved"`, `"rejected"`) */
710
+ status: string;
711
+ /** Associated payment ID */
712
+ subjectId: string;
713
+ /** Submitter identifier (email or merchant ID) */
714
+ submitterId: string;
715
+ /** Submitter type (e.g., `"customer"`, `"merchant"`) */
716
+ submitterType: string;
717
+ /** Current version ID */
718
+ currentVersionId: string | null;
719
+ /** Reviewer ID (null if not yet reviewed) */
720
+ reviewerId: string | null;
721
+ /** Review timestamp (ISO 8601, null if not yet reviewed) */
722
+ reviewedAt: string | null;
723
+ /** Reviewer's note */
724
+ reviewNote: string | null;
725
+ /** Rejection reason (null if approved or pending) */
726
+ rejectReason: string | null;
727
+ /** Execution timestamp (ISO 8601, null if not yet executed) */
728
+ executedAt: string | null;
729
+ /** Custom metadata */
730
+ metadata: Record<string, unknown>;
731
+ /** Current version number */
732
+ versionNumber: number | null;
733
+ /** Current version data (includes reason, amount, etc.) */
734
+ versionData: Record<string, unknown> | null;
735
+ /** Creation timestamp (ISO 8601) */
736
+ createdAt: string;
737
+ /** Last update timestamp (ISO 8601) */
738
+ updatedAt: string;
739
+ }
645
740
  /**
646
- * Parameters for anonymous checkout (visitor → shopper).
741
+ * Parameters for anonymous checkout.
647
742
  *
648
743
  * The buyer enters the checkout page without a session token and fills in
649
744
  * billing details manually. No identity is provided upfront.
@@ -680,7 +775,7 @@ interface AnonymousCheckoutParams {
680
775
  metadata?: Record<string, string>;
681
776
  }
682
777
  /**
683
- * Parameters for authenticated checkout (customer).
778
+ * Parameters for authenticated checkout.
684
779
  *
685
780
  * The merchant provides a buyer identity; the SDK issues a session token
686
781
  * and appends it to the checkout URL as a URL fragment.
@@ -812,7 +907,7 @@ interface WebhookEventData {
812
907
  * eventId: "PAY_5xK9mRtYvWnPqLsJ3hBfDe",
813
908
  * storeId: "STO_2aUyqjCzEIiEcYMKj7TZtw",
814
909
  * mode: "prod",
815
- * data: { orderId: "...", buyerEmail: "...", currency: "USD", amount: 2900, taxAmount: 290, productName: "Pro Plan" }
910
+ * data: { orderId: "...", buyerEmail: "...", currency: "USD", amount: "29.00", taxAmount: "2.90", productName: "Pro Plan" }
816
911
  * }
817
912
  */
818
913
  interface WebhookEvent<T = WebhookEventData> {
@@ -925,7 +1020,136 @@ declare class AuthResource {
925
1020
  }
926
1021
 
927
1022
  /**
928
- * Anonymous checkout visitor enters without a session token.
1023
+ * Internal HTTP client for buyer-side requests using Bearer token authentication.
1024
+ *
1025
+ * Unlike {@link HttpClient} which signs requests with RSA-SHA256 (API Key auth),
1026
+ * this client attaches a session token as `Authorization: Bearer <token>`.
1027
+ *
1028
+ * Not exported publicly — used internally by {@link BuyerSession}.
1029
+ */
1030
+ declare class BuyerHttpClient {
1031
+ private readonly token;
1032
+ private readonly baseUrl;
1033
+ private readonly _fetch;
1034
+ constructor(token: string, config: Pick<WaffoPancakeConfig, "baseUrl" | "fetch">);
1035
+ /**
1036
+ * Send a Bearer-authenticated POST request and return the parsed `data` field.
1037
+ *
1038
+ * @param path - API path
1039
+ * @param body - Request body object
1040
+ * @returns Parsed `data` field from the response
1041
+ * @throws {WaffoPancakeError} When the API returns errors
1042
+ */
1043
+ post<T>(path: string, body: object): Promise<T>;
1044
+ }
1045
+
1046
+ /**
1047
+ * Buyer session — lets authenticated buyers manage their own orders and subscriptions.
1048
+ *
1049
+ * Created via `client.buyer(token)` using a session token issued by
1050
+ * `client.auth.issueSessionToken()`. All requests use Bearer token authentication.
1051
+ *
1052
+ * @example
1053
+ * const { token } = await client.auth.issueSessionToken({
1054
+ * storeId: "STO_xxx",
1055
+ * buyerIdentity: "customer@example.com",
1056
+ * });
1057
+ * const buyer = client.buyer(token);
1058
+ * await buyer.cancelSubscription({ orderId: "ORD_xxx" });
1059
+ */
1060
+ declare class BuyerSession {
1061
+ private readonly http;
1062
+ /** GraphQL query access scoped to the buyer's data. */
1063
+ readonly graphql: BuyerGraphQL;
1064
+ constructor(http: BuyerHttpClient);
1065
+ /**
1066
+ * Cancel a subscription order.
1067
+ *
1068
+ * @param params - Order to cancel
1069
+ * @returns Order ID and resulting status
1070
+ *
1071
+ * @example
1072
+ * const { orderId, status } = await buyer.cancelSubscription({ orderId: "ORD_xxx" });
1073
+ * // status: "canceled" (was pending) or "canceling" (was active)
1074
+ */
1075
+ cancelSubscription(params: CancelSubscriptionParams): Promise<CancelSubscriptionResult>;
1076
+ /**
1077
+ * Cancel a one-time order (only while payment is still pending).
1078
+ *
1079
+ * @param params - Order to cancel
1080
+ * @returns Order ID and resulting status
1081
+ *
1082
+ * @example
1083
+ * const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: "ORD_xxx" });
1084
+ */
1085
+ cancelOnetimeOrder(params: CancelOnetimeOrderParams): Promise<CancelOnetimeOrderResult>;
1086
+ /**
1087
+ * Reactivate a subscription that is in `canceling` status.
1088
+ *
1089
+ * @param params - Order to reactivate
1090
+ * @returns Order ID and resulting status
1091
+ *
1092
+ * @example
1093
+ * const { orderId, status } = await buyer.reactivateSubscription({ orderId: "ORD_xxx" });
1094
+ * // status: "active"
1095
+ */
1096
+ reactivateSubscription(params: ReactivateSubscriptionParams): Promise<ReactivateSubscriptionResult>;
1097
+ /**
1098
+ * Submit a refund request for a payment.
1099
+ *
1100
+ * @param params - Refund ticket details
1101
+ * @returns Created refund ticket
1102
+ *
1103
+ * @example
1104
+ * const { ticket } = await buyer.createRefundTicket({
1105
+ * paymentId: "PAY_xxx",
1106
+ * reason: "Product not as described",
1107
+ * requestedAmount: { amount: "29.00", currency: "USD" },
1108
+ * });
1109
+ */
1110
+ createRefundTicket(params: CreateRefundTicketParams): Promise<{
1111
+ ticket: RefundTicket;
1112
+ }>;
1113
+ /**
1114
+ * Resubmit a previously rejected refund ticket with updated details.
1115
+ *
1116
+ * @param params - Updated ticket details
1117
+ * @returns Updated refund ticket
1118
+ *
1119
+ * @example
1120
+ * const { ticket } = await buyer.resubmitRefundTicket({
1121
+ * ticketId: "TKT_xxx",
1122
+ * paymentId: "PAY_xxx",
1123
+ * reason: "Updated reason with more detail",
1124
+ * requestedAmount: { amount: "29.00", currency: "USD" },
1125
+ * });
1126
+ */
1127
+ resubmitRefundTicket(params: ResubmitRefundTicketParams): Promise<{
1128
+ ticket: RefundTicket;
1129
+ }>;
1130
+ }
1131
+ /**
1132
+ * GraphQL access scoped to the buyer's session token.
1133
+ */
1134
+ declare class BuyerGraphQL {
1135
+ private readonly http;
1136
+ constructor(http: BuyerHttpClient);
1137
+ /**
1138
+ * Execute a GraphQL query scoped to the buyer's data.
1139
+ *
1140
+ * @param params - GraphQL query and variables
1141
+ * @returns GraphQL response
1142
+ *
1143
+ * @example
1144
+ * const result = await buyer.graphql.query({
1145
+ * query: `query { orders { id status } }`,
1146
+ * });
1147
+ */
1148
+ query<T = Record<string, unknown>>(params: GraphQLParams): Promise<GraphQLResponse<T>>;
1149
+ }
1150
+
1151
+ /**
1152
+ * Anonymous checkout — no buyer identity provided.
929
1153
  *
930
1154
  * The buyer fills in billing details manually on the checkout page.
931
1155
  * Internally creates a checkout session and returns the redirect URL.
@@ -990,13 +1214,13 @@ declare class CheckoutAuthenticatedResource {
990
1214
  * Checkout resource — create checkout sessions for payments.
991
1215
  *
992
1216
  * Provides two convenience sub-resources for the common checkout flows:
993
- * - `anonymous` — visitor enters without identity (empty form)
994
- * - `authenticated` — merchant provides buyer identity (pre-filled form + token)
1217
+ * - `anonymous` — no buyer identity, empty form
1218
+ * - `authenticated` — merchant provides buyer identity, pre-filled form + token
995
1219
  *
996
1220
  * The low-level `createSession()` method is still available for full control.
997
1221
  *
998
1222
  * @example
999
- * // Anonymous checkout (visitor → shopper)
1223
+ * // Anonymous checkout (no identity)
1000
1224
  * const result = await client.checkout.anonymous.create({
1001
1225
  * storeId: "STO_xxx",
1002
1226
  * productId: "PROD_xxx",
@@ -1005,7 +1229,7 @@ declare class CheckoutAuthenticatedResource {
1005
1229
  * });
1006
1230
  *
1007
1231
  * @example
1008
- * // Authenticated checkout (customer)
1232
+ * // Authenticated checkout (with buyer identity)
1009
1233
  * const result = await client.checkout.authenticated.create({
1010
1234
  * storeId: "STO_xxx",
1011
1235
  * productId: "PROD_xxx",
@@ -1017,7 +1241,7 @@ declare class CheckoutAuthenticatedResource {
1017
1241
  */
1018
1242
  declare class CheckoutResource {
1019
1243
  private readonly http;
1020
- /** Anonymous checkout — visitor enters without a session token. */
1244
+ /** Anonymous checkout — no buyer identity, empty form. */
1021
1245
  readonly anonymous: CheckoutAnonymousResource;
1022
1246
  /** Authenticated checkout — merchant provides buyer identity. */
1023
1247
  readonly authenticated: CheckoutAuthenticatedResource;
@@ -1439,7 +1663,7 @@ declare class WebhooksResource {
1439
1663
  * const { product } = await client.onetimeProducts.create({
1440
1664
  * storeId: store.id, // "STO_..."
1441
1665
  * name: "E-Book",
1442
- * prices: { USD: { amount: 2900, taxCategory: "digital_goods" } },
1666
+ * prices: { USD: { amount: "29.00", taxCategory: "digital_goods" } },
1443
1667
  * });
1444
1668
  * // => product.id = "PROD_..."
1445
1669
  *
@@ -1471,6 +1695,7 @@ declare class WebhooksResource {
1471
1695
  */
1472
1696
  declare class WaffoPancake {
1473
1697
  private readonly http;
1698
+ private readonly config;
1474
1699
  readonly auth: AuthResource;
1475
1700
  readonly stores: StoresResource;
1476
1701
  readonly storeMerchants: StoreMerchantsResource;
@@ -1482,6 +1707,25 @@ declare class WaffoPancake {
1482
1707
  readonly graphql: GraphQLResource;
1483
1708
  readonly webhooks: WebhooksResource;
1484
1709
  constructor(config: WaffoPancakeConfig);
1710
+ /**
1711
+ * Create a buyer session for self-service operations.
1712
+ *
1713
+ * The returned session uses Bearer token authentication and provides
1714
+ * methods for order cancellation, subscription management, refund tickets,
1715
+ * and scoped GraphQL queries.
1716
+ *
1717
+ * @param token - Session token from `client.auth.issueSessionToken()`
1718
+ * @returns A buyer session with self-service methods
1719
+ *
1720
+ * @example
1721
+ * const { token } = await client.auth.issueSessionToken({
1722
+ * storeId: "STO_xxx",
1723
+ * buyerIdentity: "customer@example.com",
1724
+ * });
1725
+ * const buyer = client.buyer(token);
1726
+ * await buyer.cancelSubscription({ orderId: "ORD_xxx" });
1727
+ */
1728
+ buyer(token: string): BuyerSession;
1485
1729
  }
1486
1730
 
1487
1731
  /**
@@ -1560,4 +1804,4 @@ declare class WaffoPancakeError extends Error {
1560
1804
  */
1561
1805
  declare function verifyWebhook<T = Record<string, unknown>>(payload: string, signatureHeader: string | undefined | null, options?: VerifyWebhookOptions): WebhookEvent<T>;
1562
1806
 
1563
- export { type AddMerchantParams, type AddMerchantResult, type AnonymousCheckoutParams, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, 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 WebhookPublicKeys, type WebhookSettings, verifyWebhook };
1807
+ export { type AddMerchantParams, type AddMerchantResult, type AnonymousCheckoutParams, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, CheckoutSessionProductType, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, 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, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RemoveMerchantParams, type RemoveMerchantResult, type RequestedAmount, type ResubmitRefundTicketParams, 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 WebhookPublicKeys, type WebhookSettings, verifyWebhook };