@tagadapay/plugin-sdk 2.4.31 → 2.4.34

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,14 @@
1
+ import type { OrderWithRelations } from '../types';
2
+ export interface UseCustomerOrdersOptions {
3
+ customerId?: string | null;
4
+ enabled?: boolean;
5
+ }
6
+ export interface UseCustomerOrdersResult {
7
+ data: {
8
+ orders: OrderWithRelations[];
9
+ } | null;
10
+ isLoading: boolean;
11
+ error: Error | null;
12
+ refetch: () => Promise<void>;
13
+ }
14
+ export declare function useCustomerOrders(options: UseCustomerOrdersOptions): UseCustomerOrdersResult;
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
+ import { useTagadaContext } from '../providers/TagadaProvider';
4
+ import { usePluginConfig } from './usePluginConfig';
5
+ export function useCustomerOrders(options) {
6
+ const { apiService } = useTagadaContext();
7
+ const { storeId } = usePluginConfig();
8
+ const stableOptions = useMemo(() => {
9
+ return {
10
+ customerId: options.customerId ?? null,
11
+ enabled: options.enabled ?? true,
12
+ };
13
+ }, [options.customerId, options.enabled]);
14
+ const isEnabled = useMemo(() => {
15
+ return Boolean(stableOptions.enabled && stableOptions.customerId && storeId);
16
+ }, [stableOptions.enabled, stableOptions.customerId, storeId]);
17
+ const [data, setData] = useState(null);
18
+ const [isLoading, setIsLoading] = useState(false);
19
+ const [error, setError] = useState(null);
20
+ const fetchOrders = useCallback(async () => {
21
+ if (!isEnabled)
22
+ return;
23
+ if (!stableOptions.customerId || !storeId)
24
+ return;
25
+ setIsLoading(true);
26
+ setError(null);
27
+ try {
28
+ const response = await apiService.fetch(`/api/v1/orders/customer/${stableOptions.customerId}`, {
29
+ method: 'GET',
30
+ params: { storeId },
31
+ });
32
+ setData(response ?? null);
33
+ }
34
+ catch (err) {
35
+ const safeError = err instanceof Error ? err : new Error('Failed to fetch customer orders');
36
+ setError(safeError);
37
+ }
38
+ finally {
39
+ setIsLoading(false);
40
+ }
41
+ }, [apiService, isEnabled, stableOptions.customerId, storeId]);
42
+ useEffect(() => {
43
+ void fetchOrders();
44
+ }, [fetchOrders]);
45
+ return {
46
+ data,
47
+ isLoading,
48
+ error,
49
+ refetch: fetchOrders,
50
+ };
51
+ }
@@ -8,6 +8,7 @@ export { useClubOffers } from './hooks/useClubOffers';
8
8
  export { useCurrency } from './hooks/useCurrency';
9
9
  export { useCustomer } from './hooks/useCustomer';
10
10
  export { useCustomerInfos } from './hooks/useCustomerInfos';
11
+ export { useCustomerOrders } from './hooks/useCustomerOrders';
11
12
  export { useCustomerSubscriptions } from './hooks/useCustomerSubscriptions';
12
13
  export { useDiscounts } from './hooks/useDiscounts';
13
14
  export { useEnvironment } from './hooks/useEnvironment';
@@ -11,6 +11,7 @@ export { useClubOffers } from './hooks/useClubOffers';
11
11
  export { useCurrency } from './hooks/useCurrency';
12
12
  export { useCustomer } from './hooks/useCustomer';
13
13
  export { useCustomerInfos } from './hooks/useCustomerInfos';
14
+ export { useCustomerOrders } from './hooks/useCustomerOrders';
14
15
  export { useCustomerSubscriptions } from './hooks/useCustomerSubscriptions';
15
16
  export { useDiscounts } from './hooks/useDiscounts';
16
17
  export { useEnvironment } from './hooks/useEnvironment';
@@ -150,6 +150,47 @@ export interface Order {
150
150
  };
151
151
  relatedOrders?: Order[];
152
152
  }
153
+ export interface PaymentSummary {
154
+ id: string;
155
+ status: string;
156
+ amount: number;
157
+ currency: string;
158
+ createdAt: string;
159
+ updatedAt?: string;
160
+ provider?: string;
161
+ metadata?: Record<string, any>;
162
+ }
163
+ export interface PromotionSummary {
164
+ id: string;
165
+ code?: string | null;
166
+ type?: string;
167
+ amount?: number;
168
+ description?: string | null;
169
+ }
170
+ export interface OrderAdjustmentSummary {
171
+ type: string;
172
+ amount: number;
173
+ description: string;
174
+ }
175
+ export interface OrderWithRelations extends Order {
176
+ customer?: Customer;
177
+ store?: Store;
178
+ account?: {
179
+ id: string;
180
+ name?: string;
181
+ } | undefined;
182
+ items: OrderItem[];
183
+ payments?: PaymentSummary[];
184
+ summaries: OrderSummary[];
185
+ checkoutSession?: {
186
+ id?: string;
187
+ returnUrl?: string;
188
+ [key: string]: any;
189
+ };
190
+ promotions?: PromotionSummary[];
191
+ subscriptions?: any[];
192
+ adjustments: OrderAdjustmentSummary[];
193
+ }
153
194
  export interface CustomerAddress {
154
195
  company?: string;
155
196
  firstName: string;
@@ -194,25 +235,27 @@ export interface CustomerOrderSummary {
194
235
  metadata?: Record<string, any>;
195
236
  }
196
237
  export interface CustomerInfos {
197
- id: string;
198
- email: string | null;
199
- firstName: string | null;
200
- lastName: string | null;
201
- externalCustomerId: string | null;
202
- lastOrderId: string | null;
203
- accountId: string;
204
- storeId: string;
205
- billingAddress: CustomerAddress | null;
206
- shippingAddress: Omit<CustomerAddress, 'email'> | null;
207
- currency: string | null;
208
- locale: string | null;
209
- draft: boolean;
210
- acceptsMarketing: boolean;
211
- createdAt: string;
212
- updatedAt: string;
213
- metadata: Record<string, any>;
214
- device: any | null;
215
- orders: CustomerOrderSummary[];
216
- subscriptions: any[];
238
+ customer: {
239
+ id: string;
240
+ email: string | null;
241
+ firstName: string | null;
242
+ lastName: string | null;
243
+ externalCustomerId: string | null;
244
+ lastOrderId: string | null;
245
+ accountId: string;
246
+ storeId: string;
247
+ billingAddress: CustomerAddress | null;
248
+ shippingAddress: Omit<CustomerAddress, 'email'> | null;
249
+ currency: string | null;
250
+ locale: string | null;
251
+ draft: boolean;
252
+ acceptsMarketing: boolean;
253
+ createdAt: string;
254
+ updatedAt: string;
255
+ metadata: Record<string, any>;
256
+ device: any | null;
257
+ orders: CustomerOrderSummary[];
258
+ subscriptions: any[];
259
+ };
217
260
  promotionCodes: any[];
218
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.4.31",
3
+ "version": "2.4.34",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",