@tagadapay/plugin-sdk 2.6.11 → 2.6.13
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/README.md +1129 -1129
- package/dist/react/hooks/useExpressPayment.d.ts +71 -0
- package/dist/react/hooks/useExpressPayment.js +158 -0
- package/dist/react/providers/TagadaProvider.js +5 -5
- package/dist/v2/core/resources/funnel.d.ts +109 -0
- package/dist/v2/core/resources/funnel.js +38 -0
- package/dist/v2/core/resources/index.d.ts +1 -0
- package/dist/v2/core/resources/index.js +1 -0
- package/dist/v2/core/utils/pluginConfig.js +45 -12
- package/dist/v2/index.d.ts +2 -1
- package/dist/v2/index.js +1 -1
- package/dist/v2/react/hooks/useFunnel.d.ts +51 -0
- package/dist/v2/react/hooks/useFunnel.js +432 -0
- package/dist/v2/react/hooks/useOrderQuery.js +1 -1
- package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +1 -1
- package/dist/v2/react/hooks/usePostPurchasesQuery.js +2 -2
- package/dist/v2/react/index.d.ts +2 -0
- package/dist/v2/react/index.js +2 -0
- package/dist/v2/react/providers/TagadaProvider.js +5 -5
- package/package.json +91 -91
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { CheckoutData } from './useCheckout';
|
|
3
|
+
export interface Address {
|
|
4
|
+
address1: string;
|
|
5
|
+
address2?: string;
|
|
6
|
+
lastName?: string;
|
|
7
|
+
firstName?: string;
|
|
8
|
+
city?: string;
|
|
9
|
+
state?: string;
|
|
10
|
+
country?: string;
|
|
11
|
+
postal?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
}
|
|
15
|
+
type PaymentMethod = {
|
|
16
|
+
id: string;
|
|
17
|
+
type: string;
|
|
18
|
+
title: string;
|
|
19
|
+
iconUrl: string;
|
|
20
|
+
default: boolean;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
type ExpressOrderLineItem = {
|
|
24
|
+
label: string;
|
|
25
|
+
amount: string;
|
|
26
|
+
};
|
|
27
|
+
type ExpressShippingMethod = {
|
|
28
|
+
label: string;
|
|
29
|
+
amount: string;
|
|
30
|
+
identifier: string;
|
|
31
|
+
detail: string;
|
|
32
|
+
};
|
|
33
|
+
export interface ExpressPaymentContextType {
|
|
34
|
+
applePayPaymentMethod?: PaymentMethod;
|
|
35
|
+
googlePayPaymentMethod?: PaymentMethod;
|
|
36
|
+
reComputeOrderSummary: () => Promise<{
|
|
37
|
+
lineItems: ExpressOrderLineItem[];
|
|
38
|
+
total: {
|
|
39
|
+
label: string;
|
|
40
|
+
amount: string;
|
|
41
|
+
};
|
|
42
|
+
shippingMethods: ExpressShippingMethod[];
|
|
43
|
+
} | undefined>;
|
|
44
|
+
loading?: boolean;
|
|
45
|
+
availableExpressPaymentMethodIds: string[];
|
|
46
|
+
setAvailableExpressPaymentMethodIds: (value: string[]) => void;
|
|
47
|
+
shippingMethods: ExpressShippingMethod[];
|
|
48
|
+
lineItems: ExpressOrderLineItem[];
|
|
49
|
+
handleAddExpressId: (id: string) => void;
|
|
50
|
+
updateCheckoutSessionValues: (input: {
|
|
51
|
+
data: {
|
|
52
|
+
shippingAddress: Address;
|
|
53
|
+
billingAddress?: Address | null;
|
|
54
|
+
};
|
|
55
|
+
}) => Promise<void>;
|
|
56
|
+
updateCustomerEmail: (input: {
|
|
57
|
+
data: {
|
|
58
|
+
email: string;
|
|
59
|
+
};
|
|
60
|
+
}) => Promise<void>;
|
|
61
|
+
error: string | null;
|
|
62
|
+
setError: (error: string | null) => void;
|
|
63
|
+
}
|
|
64
|
+
interface ExpressPaymentProviderProps {
|
|
65
|
+
children: ReactNode;
|
|
66
|
+
customerId?: string;
|
|
67
|
+
checkout?: CheckoutData;
|
|
68
|
+
}
|
|
69
|
+
export declare const ExpressPaymentProvider: React.FC<ExpressPaymentProviderProps>;
|
|
70
|
+
export declare const useExpressPayment: () => ExpressPaymentContextType;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
|
3
|
+
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
4
|
+
import { useOrderSummary } from './useOrderSummary';
|
|
5
|
+
import { useShippingRates } from './useShippingRates';
|
|
6
|
+
const ExpressPaymentContext = createContext(undefined);
|
|
7
|
+
export const ExpressPaymentProvider = ({ children, customerId, checkout, }) => {
|
|
8
|
+
const { apiService } = useTagadaContext();
|
|
9
|
+
const [availableExpressPaymentMethodIds, setAvailableExpressPaymentMethodIds] = useState([]);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const [paymentMethods, setPaymentMethods] = useState(null);
|
|
12
|
+
const [isLoadingPaymentMethods, setIsLoadingPaymentMethods] = useState(false);
|
|
13
|
+
const checkoutSessionId = checkout?.checkoutSession.id;
|
|
14
|
+
// Fetch enabled payment methods for this checkout session
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
let mounted = true;
|
|
17
|
+
const fetchPaymentMethods = async () => {
|
|
18
|
+
try {
|
|
19
|
+
if (!checkoutSessionId)
|
|
20
|
+
return;
|
|
21
|
+
setIsLoadingPaymentMethods(true);
|
|
22
|
+
const response = await apiService.fetch(`/api/v1/payment-methods?checkoutSessionId=${encodeURIComponent(checkoutSessionId)}`);
|
|
23
|
+
if (mounted)
|
|
24
|
+
setPaymentMethods(response);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
if (mounted)
|
|
28
|
+
setPaymentMethods([]);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
if (mounted)
|
|
32
|
+
setIsLoadingPaymentMethods(false);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
if (checkout)
|
|
36
|
+
void fetchPaymentMethods();
|
|
37
|
+
return () => {
|
|
38
|
+
mounted = false;
|
|
39
|
+
};
|
|
40
|
+
}, [apiService, checkoutSessionId]);
|
|
41
|
+
const handleAddExpressId = (id) => {
|
|
42
|
+
setAvailableExpressPaymentMethodIds((prev) => (prev.includes(id) ? prev : [...prev, id]));
|
|
43
|
+
};
|
|
44
|
+
// Base data hooks
|
|
45
|
+
const { orderSummary, isLoading: isLoadingOrderSummary, isRefetching: isRefetchingOrderSummary, refetch: refetchOrderSummary, } = useOrderSummary({ sessionId: checkoutSessionId });
|
|
46
|
+
const { shippingRates, refetch: refetchRates } = useShippingRates({ checkout });
|
|
47
|
+
const minorUnitsToCurrencyString = (amountMinor, currency) => {
|
|
48
|
+
if (!amountMinor || !currency)
|
|
49
|
+
return '0.00';
|
|
50
|
+
return (amountMinor / 100).toFixed(2);
|
|
51
|
+
};
|
|
52
|
+
const shippingMethods = useMemo(() => (shippingRates || []).map((rate) => ({
|
|
53
|
+
label: rate.shippingRateName,
|
|
54
|
+
amount: minorUnitsToCurrencyString(rate.amount, rate.currency),
|
|
55
|
+
identifier: rate.id,
|
|
56
|
+
detail: rate.description || '',
|
|
57
|
+
})), [shippingRates]);
|
|
58
|
+
const lineItems = useMemo(() => [
|
|
59
|
+
{
|
|
60
|
+
label: 'Subtotal',
|
|
61
|
+
amount: minorUnitsToCurrencyString(orderSummary?.subtotalAdjustedAmount, orderSummary?.currency),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: 'Shipping',
|
|
65
|
+
amount: minorUnitsToCurrencyString(orderSummary?.shippingCost ?? 0, orderSummary?.currency),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: 'Tax',
|
|
69
|
+
amount: minorUnitsToCurrencyString(orderSummary?.totalTaxAmount, orderSummary?.currency),
|
|
70
|
+
},
|
|
71
|
+
], [
|
|
72
|
+
orderSummary?.subtotalAdjustedAmount,
|
|
73
|
+
orderSummary?.shippingCost,
|
|
74
|
+
orderSummary?.totalTaxAmount,
|
|
75
|
+
orderSummary?.currency,
|
|
76
|
+
]);
|
|
77
|
+
const reComputeOrderSummary = useCallback(async () => {
|
|
78
|
+
try {
|
|
79
|
+
await refetchOrderSummary();
|
|
80
|
+
await refetchRates();
|
|
81
|
+
if (!orderSummary || !shippingRates)
|
|
82
|
+
return;
|
|
83
|
+
const recomputedLineItems = [
|
|
84
|
+
{
|
|
85
|
+
label: 'Subtotal',
|
|
86
|
+
amount: minorUnitsToCurrencyString(orderSummary.subtotalAdjustedAmount, orderSummary.currency),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: 'Shipping',
|
|
90
|
+
amount: minorUnitsToCurrencyString(orderSummary.shippingCost ?? 0, orderSummary.currency),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: 'Tax',
|
|
94
|
+
amount: minorUnitsToCurrencyString(orderSummary.totalTaxAmount, orderSummary.currency),
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
const total = {
|
|
98
|
+
label: 'Order Total',
|
|
99
|
+
amount: minorUnitsToCurrencyString(orderSummary.totalAdjustedAmount, orderSummary.currency),
|
|
100
|
+
};
|
|
101
|
+
const recomputedShippingMethods = (shippingRates || []).map((rate) => ({
|
|
102
|
+
label: rate.shippingRateName,
|
|
103
|
+
amount: minorUnitsToCurrencyString(rate.amount, rate.currency),
|
|
104
|
+
identifier: rate.id,
|
|
105
|
+
detail: rate.description || '',
|
|
106
|
+
}));
|
|
107
|
+
return {
|
|
108
|
+
lineItems: recomputedLineItems,
|
|
109
|
+
total,
|
|
110
|
+
shippingMethods: recomputedShippingMethods,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}, [orderSummary, shippingRates, refetchOrderSummary, refetchRates]);
|
|
117
|
+
const updateCheckoutSessionValues = useCallback(async (input) => {
|
|
118
|
+
await apiService.fetch(`/api/v1/checkout-sessions/${checkoutSessionId}/address`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
body: input,
|
|
121
|
+
});
|
|
122
|
+
}, [apiService, checkoutSessionId]);
|
|
123
|
+
const updateCustomerEmail = useCallback(async (input) => {
|
|
124
|
+
if (!customerId)
|
|
125
|
+
return;
|
|
126
|
+
await apiService.fetch(`/api/v1/customers/${customerId}`, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
body: input,
|
|
129
|
+
});
|
|
130
|
+
}, [apiService, customerId]);
|
|
131
|
+
const enabledApplePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'apple_pay'), [paymentMethods]);
|
|
132
|
+
const enabledGooglePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'google_pay'), [paymentMethods]);
|
|
133
|
+
const loading = !paymentMethods || isLoadingPaymentMethods || isLoadingOrderSummary;
|
|
134
|
+
const contextValue = {
|
|
135
|
+
availableExpressPaymentMethodIds,
|
|
136
|
+
setAvailableExpressPaymentMethodIds,
|
|
137
|
+
applePayPaymentMethod: enabledApplePayPaymentMethod,
|
|
138
|
+
googlePayPaymentMethod: enabledGooglePayPaymentMethod,
|
|
139
|
+
shippingMethods,
|
|
140
|
+
lineItems,
|
|
141
|
+
reComputeOrderSummary,
|
|
142
|
+
loading,
|
|
143
|
+
handleAddExpressId,
|
|
144
|
+
updateCheckoutSessionValues,
|
|
145
|
+
updateCustomerEmail,
|
|
146
|
+
error,
|
|
147
|
+
setError,
|
|
148
|
+
};
|
|
149
|
+
const hasAnyEnabled = Boolean(enabledApplePayPaymentMethod || enabledGooglePayPaymentMethod);
|
|
150
|
+
return (_jsx(ExpressPaymentContext.Provider, { value: contextValue, children: hasAnyEnabled ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, {}) }));
|
|
151
|
+
};
|
|
152
|
+
export const useExpressPayment = () => {
|
|
153
|
+
const context = useContext(ExpressPaymentContext);
|
|
154
|
+
if (context === undefined) {
|
|
155
|
+
throw new Error('useExpressPayment must be used within an ExpressPaymentProvider');
|
|
156
|
+
}
|
|
157
|
+
return context;
|
|
158
|
+
};
|
|
@@ -38,11 +38,11 @@ const InitializationLoader = () => (_jsxs("div", { style: {
|
|
|
38
38
|
borderTop: '1.5px solid #9ca3af',
|
|
39
39
|
borderRadius: '50%',
|
|
40
40
|
animation: 'tagada-spin 1s linear infinite',
|
|
41
|
-
} }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
|
|
42
|
-
@keyframes tagada-spin {
|
|
43
|
-
0% { transform: rotate(0deg); }
|
|
44
|
-
100% { transform: rotate(360deg); }
|
|
45
|
-
}
|
|
41
|
+
} }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
|
|
42
|
+
@keyframes tagada-spin {
|
|
43
|
+
0% { transform: rotate(0deg); }
|
|
44
|
+
100% { transform: rotate(360deg); }
|
|
45
|
+
}
|
|
46
46
|
` })] }));
|
|
47
47
|
const TagadaContext = createContext(null);
|
|
48
48
|
export function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Funnel Resource - API client for funnel navigation and session management
|
|
3
|
+
*/
|
|
4
|
+
import { ApiClient } from './apiClient';
|
|
5
|
+
export interface FunnelEvent {
|
|
6
|
+
type: string;
|
|
7
|
+
data?: any;
|
|
8
|
+
timestamp?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FunnelNavigationAction {
|
|
11
|
+
type: 'redirect' | 'replace' | 'push' | 'external' | 'none';
|
|
12
|
+
url?: string;
|
|
13
|
+
data?: any;
|
|
14
|
+
}
|
|
15
|
+
export interface FunnelNavigationResult {
|
|
16
|
+
stepId: string;
|
|
17
|
+
action: FunnelNavigationAction;
|
|
18
|
+
context: SimpleFunnelContext;
|
|
19
|
+
tracking?: {
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
event: string;
|
|
23
|
+
timestamp: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface SimpleFunnelContext {
|
|
27
|
+
customerId: string;
|
|
28
|
+
storeId: string;
|
|
29
|
+
sessionId: string;
|
|
30
|
+
funnelId: string;
|
|
31
|
+
currentStepId: string;
|
|
32
|
+
previousStepId?: string;
|
|
33
|
+
startedAt: number;
|
|
34
|
+
lastActivityAt: number;
|
|
35
|
+
metadata?: Record<string, any>;
|
|
36
|
+
}
|
|
37
|
+
export interface FunnelInitializeRequest {
|
|
38
|
+
cmsSession: {
|
|
39
|
+
customerId: string;
|
|
40
|
+
storeId: string;
|
|
41
|
+
sessionId: string;
|
|
42
|
+
accountId: string;
|
|
43
|
+
};
|
|
44
|
+
funnelId?: string;
|
|
45
|
+
entryStepId?: string;
|
|
46
|
+
existingSessionId?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface FunnelInitializeResponse {
|
|
49
|
+
success: boolean;
|
|
50
|
+
context?: SimpleFunnelContext;
|
|
51
|
+
error?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface FunnelNavigateRequest {
|
|
54
|
+
sessionId: string;
|
|
55
|
+
event: FunnelEvent;
|
|
56
|
+
contextUpdates?: Partial<SimpleFunnelContext>;
|
|
57
|
+
}
|
|
58
|
+
export interface FunnelNavigateResponse {
|
|
59
|
+
success: boolean;
|
|
60
|
+
result?: {
|
|
61
|
+
stepId: string;
|
|
62
|
+
url?: string;
|
|
63
|
+
tracking?: {
|
|
64
|
+
from: string;
|
|
65
|
+
to: string;
|
|
66
|
+
event: string;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface FunnelContextUpdateRequest {
|
|
73
|
+
contextUpdates: Partial<SimpleFunnelContext>;
|
|
74
|
+
}
|
|
75
|
+
export interface FunnelContextUpdateResponse {
|
|
76
|
+
success: boolean;
|
|
77
|
+
error?: string;
|
|
78
|
+
}
|
|
79
|
+
export declare class FunnelResource {
|
|
80
|
+
private apiClient;
|
|
81
|
+
constructor(apiClient: ApiClient);
|
|
82
|
+
/**
|
|
83
|
+
* Initialize a funnel session
|
|
84
|
+
*/
|
|
85
|
+
initialize(request: FunnelInitializeRequest): Promise<FunnelInitializeResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Navigate to next step in funnel
|
|
88
|
+
*/
|
|
89
|
+
navigate(request: FunnelNavigateRequest): Promise<FunnelNavigateResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Update funnel context
|
|
92
|
+
*/
|
|
93
|
+
updateContext(sessionId: string, request: FunnelContextUpdateRequest): Promise<FunnelContextUpdateResponse>;
|
|
94
|
+
/**
|
|
95
|
+
* End funnel session
|
|
96
|
+
*/
|
|
97
|
+
endSession(sessionId: string): Promise<{
|
|
98
|
+
success: boolean;
|
|
99
|
+
error?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Get funnel session by ID
|
|
103
|
+
*/
|
|
104
|
+
getSession(sessionId: string): Promise<{
|
|
105
|
+
success: boolean;
|
|
106
|
+
context?: SimpleFunnelContext;
|
|
107
|
+
error?: string;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Funnel Resource - API client for funnel navigation and session management
|
|
3
|
+
*/
|
|
4
|
+
export class FunnelResource {
|
|
5
|
+
constructor(apiClient) {
|
|
6
|
+
this.apiClient = apiClient;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Initialize a funnel session
|
|
10
|
+
*/
|
|
11
|
+
async initialize(request) {
|
|
12
|
+
return this.apiClient.post('/api/v1/funnel/initialize', request);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Navigate to next step in funnel
|
|
16
|
+
*/
|
|
17
|
+
async navigate(request) {
|
|
18
|
+
return this.apiClient.post('/api/v1/funnel/navigate', request);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Update funnel context
|
|
22
|
+
*/
|
|
23
|
+
async updateContext(sessionId, request) {
|
|
24
|
+
return this.apiClient.patch(`/api/v1/funnel/context/${sessionId}`, request);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* End funnel session
|
|
28
|
+
*/
|
|
29
|
+
async endSession(sessionId) {
|
|
30
|
+
return this.apiClient.delete(`/api/v1/funnel/session/${sessionId}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get funnel session by ID
|
|
34
|
+
*/
|
|
35
|
+
async getSession(sessionId) {
|
|
36
|
+
return this.apiClient.get(`/api/v1/funnel/session/${sessionId}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -80,33 +80,66 @@ const loadLocalDevConfig = async (configVariant = 'default') => {
|
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Helper to get content from meta tag
|
|
85
|
+
*/
|
|
86
|
+
const getMetaContent = (name) => {
|
|
87
|
+
const metaTag = document.querySelector(`meta[name="${name}"]`);
|
|
88
|
+
return metaTag?.getAttribute('content') || undefined;
|
|
89
|
+
};
|
|
83
90
|
/**
|
|
84
91
|
* Load production config from headers and meta tags
|
|
85
92
|
*/
|
|
86
93
|
const loadProductionConfig = async () => {
|
|
87
94
|
try {
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
// Try to get headers first
|
|
96
|
+
let storeId;
|
|
97
|
+
let accountId;
|
|
98
|
+
let basePath;
|
|
99
|
+
try {
|
|
100
|
+
const response = await fetch(window.location.href, { method: 'HEAD' });
|
|
101
|
+
storeId = response.headers.get('X-Plugin-Store-Id') || undefined;
|
|
102
|
+
accountId = response.headers.get('X-Plugin-Account-Id') || undefined;
|
|
103
|
+
basePath = response.headers.get('X-Plugin-Base-Path') || undefined;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Headers fetch failed, will fallback to meta tags
|
|
107
|
+
}
|
|
108
|
+
// Fallback to meta tags if headers are not available
|
|
109
|
+
if (!storeId) {
|
|
110
|
+
storeId = getMetaContent('x-plugin-store-id');
|
|
111
|
+
}
|
|
112
|
+
if (!accountId) {
|
|
113
|
+
accountId = getMetaContent('x-plugin-account-id');
|
|
114
|
+
}
|
|
115
|
+
if (!basePath) {
|
|
116
|
+
basePath = getMetaContent('x-plugin-base-path') || '/';
|
|
117
|
+
}
|
|
93
118
|
// Get deployment config from meta tags
|
|
94
119
|
let config = {};
|
|
95
120
|
try {
|
|
96
|
-
const
|
|
97
|
-
const encodedConfig = configMeta?.getAttribute('content');
|
|
121
|
+
const encodedConfig = getMetaContent('x-plugin-config');
|
|
98
122
|
if (encodedConfig) {
|
|
99
123
|
const decodedConfig = decodeURIComponent(encodedConfig);
|
|
100
124
|
config = JSON.parse(decodedConfig);
|
|
101
125
|
}
|
|
102
126
|
}
|
|
103
|
-
catch {
|
|
104
|
-
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.warn('Failed to parse plugin config from meta tag:', error);
|
|
129
|
+
}
|
|
130
|
+
// Final validation and warnings
|
|
131
|
+
if (!storeId) {
|
|
132
|
+
console.warn('⚠️ Plugin config: Store ID not found in headers or meta tags');
|
|
105
133
|
}
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
if (!accountId) {
|
|
135
|
+
console.warn('⚠️ Plugin config: Account ID not found in headers or meta tags');
|
|
136
|
+
}
|
|
137
|
+
const result = { storeId, accountId, basePath: basePath || '/', config };
|
|
138
|
+
console.log('🏭 Using production plugin config:', result);
|
|
139
|
+
return result;
|
|
108
140
|
}
|
|
109
|
-
catch {
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.warn('Failed to load production config, using defaults:', error);
|
|
110
143
|
return { basePath: '/', config: {} };
|
|
111
144
|
}
|
|
112
145
|
};
|
package/dist/v2/index.d.ts
CHANGED
|
@@ -20,4 +20,5 @@ export type { ShippingRate, ShippingRatesResponse } from './core/resources/shipp
|
|
|
20
20
|
export type { ApplyDiscountResponse, Discount, DiscountCodeValidation, RemoveDiscountResponse } from './core/resources/discounts';
|
|
21
21
|
export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './core/resources/vipOffers';
|
|
22
22
|
export type { StoreConfig } from './core/resources/storeConfig';
|
|
23
|
-
export {
|
|
23
|
+
export type { FunnelEvent, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext, FunnelInitializeRequest, FunnelInitializeResponse, FunnelNavigateRequest, FunnelNavigateResponse, FunnelContextUpdateRequest, FunnelContextUpdateResponse } from './core/resources/funnel';
|
|
24
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers, useFunnel, useSimpleFunnel } from './react';
|
package/dist/v2/index.js
CHANGED
|
@@ -12,4 +12,4 @@ export * from './core/utils/currency';
|
|
|
12
12
|
export * from './core/utils/pluginConfig';
|
|
13
13
|
export * from './core/utils/products';
|
|
14
14
|
// React exports (hooks and components only, types are exported above)
|
|
15
|
-
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
|
|
15
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers, useFunnel, useSimpleFunnel } from './react';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useFunnel Hook (v2) - TanStack Query-based funnel navigation
|
|
3
|
+
*
|
|
4
|
+
* Modern implementation using TanStack Query for state management
|
|
5
|
+
* and the v2 ApiClient for API calls.
|
|
6
|
+
*/
|
|
7
|
+
import { FunnelEvent, FunnelNavigationResult, SimpleFunnelContext } from '../../core/resources/funnel';
|
|
8
|
+
export interface UseFunnelOptions {
|
|
9
|
+
funnelId?: string;
|
|
10
|
+
currentStepId?: string;
|
|
11
|
+
onNavigate?: (result: FunnelNavigationResult) => void | boolean;
|
|
12
|
+
onError?: (error: Error) => void;
|
|
13
|
+
autoInitialize?: boolean;
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface UseFunnelResult {
|
|
17
|
+
next: (event: FunnelEvent) => Promise<any>;
|
|
18
|
+
goToStep: (stepId: string) => Promise<any>;
|
|
19
|
+
updateContext: (updates: Partial<SimpleFunnelContext>) => Promise<void>;
|
|
20
|
+
currentStep: {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
context: SimpleFunnelContext | null;
|
|
24
|
+
isLoading: boolean;
|
|
25
|
+
isInitialized: boolean;
|
|
26
|
+
initializeSession: (entryStepId?: string) => Promise<void>;
|
|
27
|
+
endSession: () => Promise<void>;
|
|
28
|
+
retryInitialization: () => Promise<void>;
|
|
29
|
+
initializationError: Error | null;
|
|
30
|
+
isSessionLoading: boolean;
|
|
31
|
+
sessionError: Error | null;
|
|
32
|
+
refetch: () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* React Hook for Funnel Navigation (Plugin SDK v2)
|
|
36
|
+
*
|
|
37
|
+
* Modern funnel navigation using TanStack Query for state management
|
|
38
|
+
* and the v2 ApiClient architecture.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useFunnel(options: UseFunnelOptions): UseFunnelResult;
|
|
41
|
+
/**
|
|
42
|
+
* Simplified funnel hook for basic step tracking (v2)
|
|
43
|
+
*/
|
|
44
|
+
export declare function useSimpleFunnel(funnelId: string, initialStepId?: string): {
|
|
45
|
+
currentStepId: string;
|
|
46
|
+
next: (event: FunnelEvent) => Promise<any>;
|
|
47
|
+
goToStep: (stepId: string) => Promise<any>;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
context: SimpleFunnelContext | null;
|
|
50
|
+
};
|
|
51
|
+
export type { FunnelEvent, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext } from '../../core/resources/funnel';
|