@tagadapay/plugin-sdk 2.4.24 → 2.4.25

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.
@@ -4,6 +4,4 @@ export declare function useCustomer(): {
4
4
  isAuthenticated: boolean;
5
5
  isLoading: boolean;
6
6
  isAnonymous: boolean;
7
- refreshCustomer: () => Promise<Customer | undefined>;
8
- error: Error | null;
9
7
  };
@@ -1,59 +1,14 @@
1
1
  'use client';
2
- import { useEffect, useState } from 'react';
3
2
  /**
4
3
  * useCustomer - Hook to access current customer data
5
4
  */
6
5
  import { useTagadaContext } from '../providers/TagadaProvider';
7
- import { usePluginConfig } from './usePluginConfig';
8
- import { useSession } from './useSession';
9
6
  export function useCustomer() {
10
- const { storeId } = usePluginConfig();
11
- const { customerId } = useSession();
12
- const [customer, setCustomer] = useState(null);
13
- const { apiService } = useTagadaContext();
14
- const [isLoading, setIsLoading] = useState(false);
15
- const [error, setError] = useState(null);
16
- const fetchCustomer = async (customerId, storeId) => {
17
- try {
18
- setIsLoading(true);
19
- const customer = await apiService.fetch(`/api/v1/customers/${customerId}`, {
20
- method: 'GET',
21
- params: {
22
- storeId,
23
- },
24
- });
25
- console.log('customer', customer);
26
- setCustomer(customer);
27
- return customer;
28
- }
29
- catch (error) {
30
- setError(error);
31
- console.error('Error fetching customer:', error);
32
- }
33
- finally {
34
- setIsLoading(false);
35
- }
36
- };
37
- useEffect(() => {
38
- if (customerId && storeId) {
39
- fetchCustomer(customerId, storeId);
40
- }
41
- }, [customerId, storeId]);
42
- const refreshCustomer = async () => {
43
- if (!customerId) {
44
- throw new Error('No customer ID available');
45
- }
46
- if (!storeId) {
47
- throw new Error('No store ID available');
48
- }
49
- return await fetchCustomer(customerId, storeId);
50
- };
7
+ const { customer, isLoading } = useTagadaContext();
51
8
  return {
52
9
  customer,
53
10
  isAuthenticated: customer?.isAuthenticated || false,
54
11
  isLoading,
55
12
  isAnonymous: customer?.role === 'anonymous',
56
- refreshCustomer,
57
- error,
58
13
  };
59
14
  }
@@ -211,6 +211,7 @@ localConfig, blockUntilSessionReady = false, // Default to new non-blocking beha
211
211
  storeId: sessionData.storeId,
212
212
  accountId: sessionData.accountId,
213
213
  customerId: sessionData.customerId,
214
+ role: sessionData.role,
214
215
  browserLocale,
215
216
  queryLocale: urlParams.locale,
216
217
  queryCurrency: urlParams.currency,
@@ -1,4 +1,4 @@
1
- import { EnvironmentConfig } from '../types';
1
+ import { EnvironmentConfig, SessionRole } from '../types';
2
2
  export interface ApiServiceOptions {
3
3
  environmentConfig: EnvironmentConfig;
4
4
  token?: string | null;
@@ -39,7 +39,7 @@ export interface SessionInitResponse {
39
39
  lastName?: string;
40
40
  phone?: string;
41
41
  isAuthenticated: boolean;
42
- role: 'authenticated' | 'anonymous';
42
+ role: SessionRole;
43
43
  };
44
44
  }
45
45
  export declare class ApiService {
@@ -75,6 +75,7 @@ export declare class ApiService {
75
75
  storeId: string;
76
76
  accountId: string;
77
77
  customerId: string;
78
+ role: SessionRole;
78
79
  browserLocale?: string;
79
80
  queryLocale?: string;
80
81
  queryCurrency?: string;
@@ -31,12 +31,13 @@ export interface Customer {
31
31
  isAuthenticated: boolean;
32
32
  role: 'authenticated' | 'anonymous';
33
33
  }
34
+ export type SessionRole = 'authenticated' | 'anonymous';
34
35
  export interface Session {
35
36
  sessionId: string;
36
37
  storeId: string;
37
38
  accountId: string;
38
39
  customerId: string;
39
- role: 'authenticated' | 'anonymous';
40
+ role: SessionRole;
40
41
  isValid: boolean;
41
42
  isLoading: boolean;
42
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.4.24",
3
+ "version": "2.4.25",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",