@waffo/pancake-nextjs 0.1.9 → 0.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.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
3
  import { AnonymousCheckoutParams, AuthenticatedCheckoutParams, CheckoutSessionResult, AuthenticatedCheckoutResult, IssueSessionTokenParams, SessionToken, GraphQLParams, GraphQLResponse, CancelSubscriptionParams, CancelSubscriptionResult, CancelOnetimeOrderParams, CancelOnetimeOrderResult, ReactivateSubscriptionParams, ReactivateSubscriptionResult, CreateRefundTicketParams, RefundTicket, ResubmitRefundTicketParams, RefundTicketVersionData, VerifyWebhookOptions, WebhookEventData, WebhookEvent } from '@waffo/pancake-ts';
4
- export { BillingDetail, PriceInfo, RefundTicketVersionData, RequestedAmount, TaxCategory, WaffoPancakeError, WebhookEvent, WebhookEventData, WebhookEventType } from '@waffo/pancake-ts';
4
+ export { BillingDetail, CashierLanguage, PriceInfo, RefundTicketVersionData, RequestedAmount, TaxCategory, WaffoPancakeError, WebhookEvent, WebhookEventData, WebhookEventType } from '@waffo/pancake-ts';
5
5
 
6
6
  /** Parameters for the checkout server action */
7
7
  type CheckoutActionParams = ({
@@ -13,61 +13,70 @@ type CheckoutActionParams = ({
13
13
  type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult;
14
14
  /** Server action signature for checkout */
15
15
  type CheckoutAction = (params: CheckoutActionParams) => Promise<CheckoutActionResult>;
16
- /** Server action signature for issuing buyer tokens */
17
- type BuyerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;
18
- /** Buyer action types */
19
- type BuyerSessionActionType = "cancelSubscription" | "cancelOnetimeOrder" | "reactivateSubscription" | "createRefundTicket" | "resubmitRefundTicket" | "query";
20
- /** Server action signature for buyer session operations */
21
- type BuyerSessionAction = (token: string, actionType: BuyerSessionActionType, params: unknown) => Promise<unknown>;
16
+ /** Server action signature for issuing customer tokens */
17
+ type CustomerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;
18
+ /** Customer action types */
19
+ type CustomerSessionActionType = "cancelSubscription" | "cancelOnetimeOrder" | "reactivateSubscription" | "createRefundTicket" | "resubmitRefundTicket" | "query";
20
+ /** Server action signature for customer session operations */
21
+ type CustomerSessionAction = (token: string, actionType: CustomerSessionActionType, params: unknown) => Promise<unknown>;
22
22
  /** Server action signature for merchant GraphQL queries */
23
23
  type MerchantQueryAction = (params: GraphQLParams) => Promise<GraphQLResponse>;
24
+ /** @deprecated Use {@link CustomerTokenAction} instead. */
25
+ type BuyerTokenAction = CustomerTokenAction;
26
+ /** @deprecated Use {@link CustomerSessionAction} instead. */
27
+ type BuyerSessionAction = CustomerSessionAction;
24
28
 
25
- /** Buyer configuration for automatic token management */
26
- interface BuyerConfig {
27
- /** Buyer identity (email or merchant-provided identifier) */
29
+ /** Customer configuration for automatic token management */
30
+ interface CustomerConfig {
31
+ /** Customer identity (email or merchant-provided identifier) */
28
32
  identity: string;
29
33
  /** Store ID (optional when `productId` is provided) */
30
34
  storeId?: string;
31
35
  /** Product ID — used to derive the store when `storeId` is omitted */
32
36
  productId?: string;
33
- /** Server action for issuing tokens — from `createBuyerTokenAction()` */
34
- issueToken: BuyerTokenAction;
35
- /** Server action for buyer operations — from `createBuyerSessionAction()` */
36
- sessionAction: BuyerSessionAction;
37
+ /** Server action for issuing tokens — from `createCustomerTokenAction()` */
38
+ issueToken: CustomerTokenAction;
39
+ /** Server action for customer operations — from `createCustomerSessionAction()` */
40
+ sessionAction: CustomerSessionAction;
37
41
  }
42
+ /** @deprecated Use {@link CustomerConfig} instead. */
43
+ type BuyerConfig = CustomerConfig;
38
44
  interface WaffoPancakeProviderProps {
39
- /** Buyer configuration for automatic token management */
40
- buyer: BuyerConfig;
45
+ /** Customer configuration for automatic token management */
46
+ customer?: CustomerConfig;
47
+ /** @deprecated Use `customer` instead. */
48
+ buyer?: CustomerConfig;
41
49
  children: React.ReactNode;
42
50
  }
43
51
  /**
44
- * Provider that manages buyer token lifecycle via server actions.
52
+ * Provider that manages customer token lifecycle via server actions.
45
53
  *
46
54
  * Auto-issues session tokens on mount and refreshes before expiry.
47
- * All buyer hooks (`useBuyer`, `useBuyerOrders`, etc.) read from context.
55
+ * All customer hooks (`useCustomer`, `useCustomerOrders`, etc.) read from context.
48
56
  *
49
- * The private key never leaves the server — token issuance and buyer
57
+ * The private key never leaves the server — token issuance and customer
50
58
  * operations are delegated to server actions.
51
59
  *
52
60
  * @param props - Provider configuration
53
- * @param props.buyer - Buyer identity and server actions
61
+ * @param props.customer - Customer identity and server actions
62
+ * @param props.buyer - Deprecated alias of `customer`
54
63
  * @param props.children - React children
55
64
  *
56
65
  * @example
57
66
  * ```tsx
58
67
  * // identity must match what you passed as `buyerIdentity` at checkout time —
59
- * // buyer-portal lookups are keyed by merchant_provided_buyer_identity
60
- * <WaffoPancakeProvider buyer={{
68
+ * // customer-portal lookups are keyed by merchant_provided_buyer_identity
69
+ * <WaffoPancakeProvider customer={{
61
70
  * identity: user.id,
62
71
  * storeId: "STO_xxx",
63
- * issueToken, // from createBuyerTokenAction()
64
- * sessionAction, // from createBuyerSessionAction()
72
+ * issueToken, // from createCustomerTokenAction()
73
+ * sessionAction, // from createCustomerSessionAction()
65
74
  * }}>
66
75
  * <App />
67
76
  * </WaffoPancakeProvider>
68
77
  * ```
69
78
  */
70
- declare function WaffoPancakeProvider({ buyer, children }: WaffoPancakeProviderProps): react_jsx_runtime.JSX.Element;
79
+ declare function WaffoPancakeProvider({ customer, buyer, children }: WaffoPancakeProviderProps): react_jsx_runtime.JSX.Element;
71
80
 
72
81
  /** Redirect mode for checkout navigation */
73
82
  type CheckoutMode = "redirect" | "popup";
@@ -92,7 +101,7 @@ interface LinkCheckoutProps extends CheckoutBaseOptions {
92
101
  productId: string;
93
102
  /** Currency code (ISO 4217). If omitted, product page auto-detects. */
94
103
  currency?: string;
95
- /** Pre-fill buyer email */
104
+ /** Pre-fill customer email */
96
105
  email?: string;
97
106
  /** Redirect URL after successful payment */
98
107
  successUrl?: string;
@@ -221,8 +230,8 @@ declare function CheckoutButton(props: CheckoutButtonProps): react_jsx_runtime.J
221
230
  */
222
231
  declare function useCheckout(args: CheckoutProps): UseCheckoutReturn;
223
232
 
224
- /** State of an async buyer action */
225
- interface BuyerActionState<T = unknown> {
233
+ /** State of an async customer action */
234
+ interface CustomerActionState<T = unknown> {
226
235
  /** Execute the action */
227
236
  execute: (params: T) => Promise<void>;
228
237
  /** Whether the action is in progress */
@@ -230,52 +239,58 @@ interface BuyerActionState<T = unknown> {
230
239
  /** Error from the last attempt */
231
240
  error: Error | null;
232
241
  }
233
- /** Return type of useBuyer hook */
234
- interface UseBuyerReturn {
242
+ /** Return type of useCustomer hook */
243
+ interface UseCustomerReturn {
235
244
  /** Cancel a subscription order */
236
- cancelSubscription: BuyerActionState<CancelSubscriptionParams> & {
245
+ cancelSubscription: CustomerActionState<CancelSubscriptionParams> & {
237
246
  data: CancelSubscriptionResult | null;
238
247
  };
239
248
  /** Cancel a one-time order */
240
- cancelOnetimeOrder: BuyerActionState<CancelOnetimeOrderParams> & {
249
+ cancelOnetimeOrder: CustomerActionState<CancelOnetimeOrderParams> & {
241
250
  data: CancelOnetimeOrderResult | null;
242
251
  };
243
252
  /** Reactivate a canceling subscription */
244
- reactivateSubscription: BuyerActionState<ReactivateSubscriptionParams> & {
253
+ reactivateSubscription: CustomerActionState<ReactivateSubscriptionParams> & {
245
254
  data: ReactivateSubscriptionResult | null;
246
255
  };
247
256
  /** Create a refund ticket */
248
- createRefundTicket: BuyerActionState<CreateRefundTicketParams> & {
257
+ createRefundTicket: CustomerActionState<CreateRefundTicketParams> & {
249
258
  data: RefundTicket | null;
250
259
  };
251
260
  /** Resubmit a rejected refund ticket */
252
- resubmitRefundTicket: BuyerActionState<ResubmitRefundTicketParams> & {
261
+ resubmitRefundTicket: CustomerActionState<ResubmitRefundTicketParams> & {
253
262
  data: RefundTicket | null;
254
263
  };
255
264
  /** Execute a GraphQL query */
256
265
  query: <T = Record<string, unknown>>(params: GraphQLParams) => Promise<GraphQLResponse<T>>;
257
266
  }
258
267
  /**
259
- * React hook for buyer self-service actions.
268
+ * React hook for customer self-service actions.
260
269
  *
261
270
  * Must be used within `<WaffoPancakeProvider>`. All operations are executed
262
271
  * via server actions — the private key never leaves the server.
263
272
  *
264
- * @returns Buyer action handlers with loading/error states
273
+ * @returns Customer action handlers with loading/error states
265
274
  *
266
275
  * @example
267
276
  * ```tsx
268
277
  * function AccountPage() {
269
- * const buyer = useBuyer();
278
+ * const customer = useCustomer();
270
279
  * return (
271
- * <button onClick={() => buyer.cancelSubscription.execute({ orderId: "ORD_xxx" })}>
280
+ * <button onClick={() => customer.cancelSubscription.execute({ orderId: "ORD_xxx" })}>
272
281
  * Cancel
273
282
  * </button>
274
283
  * );
275
284
  * }
276
285
  * ```
277
286
  */
278
- declare function useBuyer(): UseBuyerReturn;
287
+ declare function useCustomer(): UseCustomerReturn;
288
+ /** @deprecated Use {@link CustomerActionState} instead. */
289
+ type BuyerActionState<T = unknown> = CustomerActionState<T>;
290
+ /** @deprecated Use {@link UseCustomerReturn} instead. */
291
+ type UseBuyerReturn = UseCustomerReturn;
292
+ /** @deprecated Use {@link useCustomer} instead. */
293
+ declare const useBuyer: typeof useCustomer;
279
294
 
280
295
  /** Query state with typed data */
281
296
  interface QueryState<T> {
@@ -285,8 +300,8 @@ interface QueryState<T> {
285
300
  refetch: () => void;
286
301
  }
287
302
 
288
- /** A buyer's one-time order */
289
- interface BuyerOnetimeOrder {
303
+ /** A customer's one-time order */
304
+ interface CustomerOnetimeOrder {
290
305
  id: string;
291
306
  status: string;
292
307
  currency: string;
@@ -304,8 +319,8 @@ interface BuyerOnetimeOrder {
304
319
  }>;
305
320
  createdAt: string;
306
321
  }
307
- /** A buyer's subscription order */
308
- interface BuyerSubscriptionOrder {
322
+ /** A customer's subscription order */
323
+ interface CustomerSubscriptionOrder {
309
324
  id: string;
310
325
  status: string;
311
326
  currency: string;
@@ -327,8 +342,8 @@ interface BuyerSubscriptionOrder {
327
342
  }>;
328
343
  createdAt: string;
329
344
  }
330
- /** A buyer's payment record */
331
- interface BuyerPayment {
345
+ /** A customer's payment record */
346
+ interface CustomerPayment {
332
347
  id: string;
333
348
  orderId: string;
334
349
  status: string;
@@ -338,27 +353,27 @@ interface BuyerPayment {
338
353
  createdAt: string;
339
354
  }
340
355
  /**
341
- * A buyer's refund ticket.
356
+ * A customer's refund ticket.
342
357
  *
343
358
  * Ticket-level fields are flat; per-version fields (`reason`, `requestedAmount`)
344
- * live under `versionData` because the buyer can resubmit a rejected ticket and
359
+ * live under `versionData` because the customer can resubmit a rejected ticket and
345
360
  * each submission is a versioned record. `versionData` reflects the current
346
361
  * (latest) version. The `versionData` shape is shared with `@waffo/pancake-ts`'s
347
362
  * `RefundTicketVersionData`.
348
363
  */
349
- interface BuyerRefundTicket {
364
+ interface CustomerRefundTicket {
350
365
  id: string;
351
366
  status: string;
352
367
  versionNumber: number | null;
353
368
  versionData: RefundTicketVersionData | null;
354
369
  createdAt: string;
355
370
  }
356
- interface BuyerOrdersData {
357
- onetimeOrders: BuyerOnetimeOrder[];
358
- subscriptionOrders: BuyerSubscriptionOrder[];
371
+ interface CustomerOrdersData {
372
+ onetimeOrders: CustomerOnetimeOrder[];
373
+ subscriptionOrders: CustomerSubscriptionOrder[];
359
374
  }
360
375
  /**
361
- * Fetch the buyer's order history (one-time + subscription).
376
+ * Fetch the customer's order history (one-time + subscription).
362
377
  *
363
378
  * Must be used within `<WaffoPancakeProvider>`. Token is auto-managed.
364
379
  *
@@ -366,13 +381,13 @@ interface BuyerOrdersData {
366
381
  *
367
382
  * @example
368
383
  * ```tsx
369
- * const { data, isLoading, refetch } = useBuyerOrders();
384
+ * const { data, isLoading, refetch } = useCustomerOrders();
370
385
  * // data.onetimeOrders + data.subscriptionOrders
371
386
  * ```
372
387
  */
373
- declare function useBuyerOrders(): QueryState<BuyerOrdersData>;
388
+ declare function useCustomerOrders(): QueryState<CustomerOrdersData>;
374
389
  /**
375
- * Fetch the buyer's payment history.
390
+ * Fetch the customer's payment history.
376
391
  *
377
392
  * Must be used within `<WaffoPancakeProvider>`. Token is auto-managed.
378
393
  *
@@ -380,12 +395,12 @@ declare function useBuyerOrders(): QueryState<BuyerOrdersData>;
380
395
  *
381
396
  * @example
382
397
  * ```tsx
383
- * const { data: payments, isLoading } = useBuyerPayments();
398
+ * const { data: payments, isLoading } = useCustomerPayments();
384
399
  * ```
385
400
  */
386
- declare function useBuyerPayments(): QueryState<BuyerPayment[]>;
401
+ declare function useCustomerPayments(): QueryState<CustomerPayment[]>;
387
402
  /**
388
- * Fetch the buyer's refund tickets.
403
+ * Fetch the customer's refund tickets.
389
404
  *
390
405
  * Must be used within `<WaffoPancakeProvider>`. Token is auto-managed.
391
406
  *
@@ -393,10 +408,24 @@ declare function useBuyerPayments(): QueryState<BuyerPayment[]>;
393
408
  *
394
409
  * @example
395
410
  * ```tsx
396
- * const { data: tickets, isLoading } = useBuyerRefundTickets();
411
+ * const { data: tickets, isLoading } = useCustomerRefundTickets();
397
412
  * ```
398
413
  */
399
- declare function useBuyerRefundTickets(): QueryState<BuyerRefundTicket[]>;
414
+ declare function useCustomerRefundTickets(): QueryState<CustomerRefundTicket[]>;
415
+ /** @deprecated Use {@link CustomerOnetimeOrder} instead. */
416
+ type BuyerOnetimeOrder = CustomerOnetimeOrder;
417
+ /** @deprecated Use {@link CustomerSubscriptionOrder} instead. */
418
+ type BuyerSubscriptionOrder = CustomerSubscriptionOrder;
419
+ /** @deprecated Use {@link CustomerPayment} instead. */
420
+ type BuyerPayment = CustomerPayment;
421
+ /** @deprecated Use {@link CustomerRefundTicket} instead. */
422
+ type BuyerRefundTicket = CustomerRefundTicket;
423
+ /** @deprecated Use {@link useCustomerOrders} instead. */
424
+ declare const useBuyerOrders: typeof useCustomerOrders;
425
+ /** @deprecated Use {@link useCustomerPayments} instead. */
426
+ declare const useBuyerPayments: typeof useCustomerPayments;
427
+ /** @deprecated Use {@link useCustomerRefundTickets} instead. */
428
+ declare const useBuyerRefundTickets: typeof useCustomerRefundTickets;
400
429
 
401
430
  /** A merchant's recent order (one-time or subscription) */
402
431
  interface MerchantOrder {
@@ -527,9 +556,9 @@ interface WebhookConfig {
527
556
  onSubscriptionActivated?: EventHandler;
528
557
  /** Subscription renewal payment succeeded */
529
558
  onSubscriptionPaymentSucceeded?: EventHandler;
530
- /** Buyer initiated cancellation (expires at end of current period) */
559
+ /** Customer initiated cancellation (expires at end of current period) */
531
560
  onSubscriptionCanceling?: EventHandler;
532
- /** Buyer withdrew cancellation (subscription restored) */
561
+ /** Customer withdrew cancellation (subscription restored) */
533
562
  onSubscriptionUncanceled?: EventHandler;
534
563
  /** Subscription product changed (upgrade/downgrade) */
535
564
  onSubscriptionUpdated?: EventHandler;
@@ -574,4 +603,4 @@ interface WebhookConfig {
574
603
  */
575
604
  declare function Webhook(config: WebhookConfig): (request: Request) => Promise<Response>;
576
605
 
577
- export { type AnonymousCheckoutButtonProps, type AnonymousCheckoutProps, type AuthenticatedCheckoutButtonProps, type AuthenticatedCheckoutProps, type BuyerActionState, type BuyerConfig, type BuyerOnetimeOrder, type BuyerPayment, type BuyerRefundTicket, type BuyerSessionAction, type BuyerSubscriptionOrder, type BuyerTokenAction, type CheckoutAction, type CheckoutActionParams, type CheckoutActionResult, type CheckoutBaseOptions, CheckoutButton, type CheckoutButtonProps, type CheckoutMode, type CheckoutProps, type LinkCheckoutButtonProps, type LinkCheckoutProps, type MerchantOrder, type MerchantOrdersOptions, type MerchantQueryAction, type MerchantSubscription, type QueryState, type SalesOverview, type SubscriptionOverview, type UseBuyerReturn, type UseCheckoutReturn, WaffoPancakeProvider, type WaffoPancakeProviderProps, Webhook, type WebhookConfig, useBuyer, useBuyerOrders, useBuyerPayments, useBuyerRefundTickets, useCheckout, useMerchantOrders, useMerchantSales, useMerchantSubscriptions };
606
+ export { type AnonymousCheckoutButtonProps, type AnonymousCheckoutProps, type AuthenticatedCheckoutButtonProps, type AuthenticatedCheckoutProps, type BuyerActionState, type BuyerConfig, type BuyerOnetimeOrder, type BuyerPayment, type BuyerRefundTicket, type BuyerSessionAction, type BuyerSubscriptionOrder, type BuyerTokenAction, type CheckoutAction, type CheckoutActionParams, type CheckoutActionResult, type CheckoutBaseOptions, CheckoutButton, type CheckoutButtonProps, type CheckoutMode, type CheckoutProps, type CustomerActionState, type CustomerConfig, type CustomerOnetimeOrder, type CustomerPayment, type CustomerRefundTicket, type CustomerSessionAction, type CustomerSubscriptionOrder, type CustomerTokenAction, type LinkCheckoutButtonProps, type LinkCheckoutProps, type MerchantOrder, type MerchantOrdersOptions, type MerchantQueryAction, type MerchantSubscription, type QueryState, type SalesOverview, type SubscriptionOverview, type UseBuyerReturn, type UseCheckoutReturn, type UseCustomerReturn, WaffoPancakeProvider, type WaffoPancakeProviderProps, Webhook, type WebhookConfig, useBuyer, useBuyerOrders, useBuyerPayments, useBuyerRefundTickets, useCheckout, useCustomer, useCustomerOrders, useCustomerPayments, useCustomerRefundTickets, useMerchantOrders, useMerchantSales, useMerchantSubscriptions };
package/dist/index.js CHANGED
@@ -5,23 +5,25 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, use
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  var PancakeContext = createContext(null);
7
7
  var REFRESH_BUFFER_MS = 3e4;
8
- function WaffoPancakeProvider({ buyer, children }) {
8
+ function WaffoPancakeProvider({ customer, buyer, children }) {
9
+ const config = customer ?? buyer;
10
+ if (!config) throw new Error("WaffoPancakeProvider: the `customer` prop is required");
9
11
  const tokenRef = useRef(null);
10
12
  const refreshPromiseRef = useRef(null);
11
- const [isBuyerReady, setIsBuyerReady] = useState(false);
13
+ const [isCustomerReady, setIsCustomerReady] = useState(false);
12
14
  const refreshToken = useCallback(async () => {
13
- const result = await buyer.issueToken({
14
- buyerIdentity: buyer.identity,
15
- storeId: buyer.storeId,
16
- productId: buyer.productId
15
+ const result = await config.issueToken({
16
+ buyerIdentity: config.identity,
17
+ storeId: config.storeId,
18
+ productId: config.productId
17
19
  });
18
20
  tokenRef.current = {
19
21
  token: result.token,
20
22
  expiresAt: new Date(result.expiresAt).getTime()
21
23
  };
22
24
  return result.token;
23
- }, [buyer]);
24
- const getBuyerToken = useCallback(async () => {
25
+ }, [config]);
26
+ const getCustomerToken = useCallback(async () => {
25
27
  const current = tokenRef.current;
26
28
  if (current && Date.now() < current.expiresAt - REFRESH_BUFFER_MS) {
27
29
  return current.token;
@@ -34,16 +36,16 @@ function WaffoPancakeProvider({ buyer, children }) {
34
36
  return refreshPromiseRef.current;
35
37
  }, [refreshToken]);
36
38
  useEffect(() => {
37
- refreshToken().then(() => setIsBuyerReady(true)).catch(() => setIsBuyerReady(true));
39
+ refreshToken().then(() => setIsCustomerReady(true)).catch(() => setIsCustomerReady(true));
38
40
  }, [refreshToken]);
39
41
  const value = useMemo(
40
42
  () => ({
41
- getBuyerToken,
42
- buyerSessionAction: buyer.sessionAction,
43
- hasBuyer: true,
44
- isBuyerReady
43
+ getCustomerToken,
44
+ customerSessionAction: config.sessionAction,
45
+ hasCustomer: true,
46
+ isCustomerReady
45
47
  }),
46
- [getBuyerToken, buyer.sessionAction, isBuyerReady]
48
+ [getCustomerToken, config.sessionAction, isCustomerReady]
47
49
  );
48
50
  return /* @__PURE__ */ jsx(PancakeContext.Provider, { value, children });
49
51
  }
@@ -127,9 +129,9 @@ function CheckoutButton(props) {
127
129
  return /* @__PURE__ */ jsx2("button", { type: "button", onClick: checkout, disabled: disabled || isLoading, className, style, children: isLoading ? loadingChildren ?? children : children });
128
130
  }
129
131
 
130
- // src/use-buyer.ts
132
+ // src/use-customer.ts
131
133
  import { useCallback as useCallback3, useContext as useContext2, useMemo as useMemo2, useState as useState3 } from "react";
132
- function useBuyerAction(actionFn) {
134
+ function useCustomerAction(actionFn) {
133
135
  const [isLoading, setIsLoading] = useState3(false);
134
136
  const [error, setError] = useState3(null);
135
137
  const [data, setData] = useState3(null);
@@ -151,34 +153,34 @@ function useBuyerAction(actionFn) {
151
153
  );
152
154
  return { execute, isLoading, error, data };
153
155
  }
154
- function useBuyer() {
156
+ function useCustomer() {
155
157
  const ctx = useContext2(PancakeContext);
156
- if (!ctx) throw new Error("useBuyer: must be used within <WaffoPancakeProvider>");
157
- const { getBuyerToken, buyerSessionAction } = ctx;
158
+ if (!ctx) throw new Error("useCustomer: must be used within <WaffoPancakeProvider>");
159
+ const { getCustomerToken, customerSessionAction } = ctx;
158
160
  const callAction = useCallback3(
159
161
  async (actionType, params) => {
160
- const token = await getBuyerToken();
161
- return buyerSessionAction(token, actionType, params);
162
+ const token = await getCustomerToken();
163
+ return customerSessionAction(token, actionType, params);
162
164
  },
163
- [getBuyerToken, buyerSessionAction]
165
+ [getCustomerToken, customerSessionAction]
164
166
  );
165
- const cancelSubscription = useBuyerAction(
167
+ const cancelSubscription = useCustomerAction(
166
168
  useCallback3((params) => callAction("cancelSubscription", params), [callAction])
167
169
  );
168
- const cancelOnetimeOrder = useBuyerAction(
170
+ const cancelOnetimeOrder = useCustomerAction(
169
171
  useCallback3((params) => callAction("cancelOnetimeOrder", params), [callAction])
170
172
  );
171
- const reactivateSubscription = useBuyerAction(
173
+ const reactivateSubscription = useCustomerAction(
172
174
  useCallback3((params) => callAction("reactivateSubscription", params), [callAction])
173
175
  );
174
- const createRefundTicket = useBuyerAction(
176
+ const createRefundTicket = useCustomerAction(
175
177
  useCallback3((params) => callAction("createRefundTicket", params), [callAction])
176
178
  );
177
179
  const createRefundTicketMapped = useMemo2(
178
180
  () => ({ ...createRefundTicket, data: createRefundTicket.data?.ticket ?? null }),
179
181
  [createRefundTicket]
180
182
  );
181
- const resubmitRefundTicket = useBuyerAction(
183
+ const resubmitRefundTicket = useCustomerAction(
182
184
  useCallback3((params) => callAction("resubmitRefundTicket", params), [callAction])
183
185
  );
184
186
  const resubmitRefundTicketMapped = useMemo2(
@@ -187,10 +189,10 @@ function useBuyer() {
187
189
  );
188
190
  const query = useCallback3(
189
191
  async (params) => {
190
- const token = await getBuyerToken();
191
- return buyerSessionAction(token, "query", params);
192
+ const token = await getCustomerToken();
193
+ return customerSessionAction(token, "query", params);
192
194
  },
193
- [getBuyerToken, buyerSessionAction]
195
+ [getCustomerToken, customerSessionAction]
194
196
  );
195
197
  return {
196
198
  cancelSubscription,
@@ -201,8 +203,9 @@ function useBuyer() {
201
203
  query
202
204
  };
203
205
  }
206
+ var useBuyer = useCustomer;
204
207
 
205
- // src/use-buyer-data.ts
208
+ // src/use-customer-data.ts
206
209
  import { useCallback as useCallback5, useContext as useContext3 } from "react";
207
210
 
208
211
  // src/use-query.ts
@@ -223,8 +226,8 @@ function useQuery(queryFn, ready) {
223
226
  return { data, isLoading, error, refetch: fetch };
224
227
  }
225
228
 
226
- // src/use-buyer-data.ts
227
- var BUYER_ORDERS_QUERY = `query {
229
+ // src/use-customer-data.ts
230
+ var CUSTOMER_ORDERS_QUERY = `query {
228
231
  onetimeOrders(limit: 50) {
229
232
  id status currency buyerEmail createdAt
230
233
  product { id name }
@@ -236,12 +239,12 @@ var BUYER_ORDERS_QUERY = `query {
236
239
  payments { id status snapshotDisplayAmount snapshotDisplayCurrency createdAt }
237
240
  }
238
241
  }`;
239
- var BUYER_PAYMENTS_QUERY = `query {
242
+ var CUSTOMER_PAYMENTS_QUERY = `query {
240
243
  payments(limit: 50) {
241
244
  id orderId status snapshotDisplayAmount snapshotDisplayCurrency failureReason createdAt
242
245
  }
243
246
  }`;
244
- var BUYER_REFUND_TICKETS_QUERY = `query {
247
+ var CUSTOMER_REFUND_TICKETS_QUERY = `query {
245
248
  refundTickets(limit: 50) {
246
249
  id status versionNumber
247
250
  versionData {
@@ -251,28 +254,31 @@ var BUYER_REFUND_TICKETS_QUERY = `query {
251
254
  createdAt
252
255
  }
253
256
  }`;
254
- function useBuyerQuery(query) {
257
+ function useCustomerQuery(query) {
255
258
  const ctx = useContext3(PancakeContext);
256
- if (!ctx) throw new Error("Buyer data hook: must be used within <WaffoPancakeProvider>");
257
- const { getBuyerToken, buyerSessionAction, isBuyerReady } = ctx;
259
+ if (!ctx) throw new Error("Customer data hook: must be used within <WaffoPancakeProvider>");
260
+ const { getCustomerToken, customerSessionAction, isCustomerReady } = ctx;
258
261
  const queryFn = useCallback5(async () => {
259
- const token = await getBuyerToken();
260
- const result = await buyerSessionAction(token, "query", { query });
262
+ const token = await getCustomerToken();
263
+ const result = await customerSessionAction(token, "query", { query });
261
264
  return result.data;
262
- }, [getBuyerToken, buyerSessionAction, query]);
263
- return useQuery(queryFn, isBuyerReady);
265
+ }, [getCustomerToken, customerSessionAction, query]);
266
+ return useQuery(queryFn, isCustomerReady);
264
267
  }
265
- function useBuyerOrders() {
266
- return useBuyerQuery(BUYER_ORDERS_QUERY);
268
+ function useCustomerOrders() {
269
+ return useCustomerQuery(CUSTOMER_ORDERS_QUERY);
267
270
  }
268
- function useBuyerPayments() {
269
- const result = useBuyerQuery(BUYER_PAYMENTS_QUERY);
271
+ function useCustomerPayments() {
272
+ const result = useCustomerQuery(CUSTOMER_PAYMENTS_QUERY);
270
273
  return { ...result, data: result.data?.payments ?? null };
271
274
  }
272
- function useBuyerRefundTickets() {
273
- const result = useBuyerQuery(BUYER_REFUND_TICKETS_QUERY);
275
+ function useCustomerRefundTickets() {
276
+ const result = useCustomerQuery(CUSTOMER_REFUND_TICKETS_QUERY);
274
277
  return { ...result, data: result.data?.refundTickets ?? null };
275
278
  }
279
+ var useBuyerOrders = useCustomerOrders;
280
+ var useBuyerPayments = useCustomerPayments;
281
+ var useBuyerRefundTickets = useCustomerRefundTickets;
276
282
 
277
283
  // src/use-merchant-data.ts
278
284
  import { useCallback as useCallback6 } from "react";
@@ -425,6 +431,10 @@ export {
425
431
  useBuyerPayments,
426
432
  useBuyerRefundTickets,
427
433
  useCheckout,
434
+ useCustomer,
435
+ useCustomerOrders,
436
+ useCustomerPayments,
437
+ useCustomerRefundTickets,
428
438
  useMerchantOrders,
429
439
  useMerchantSales,
430
440
  useMerchantSubscriptions