@tagadapay/plugin-sdk 2.6.18 → 2.7.2
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/react/hooks/usePluginConfig.js +15 -7
- package/dist/v2/core/index.d.ts +1 -0
- package/dist/v2/core/index.js +2 -0
- package/dist/v2/core/pathRemapping.d.ts +156 -0
- package/dist/v2/core/pathRemapping.js +440 -0
- package/dist/v2/core/resources/credits.d.ts +42 -0
- package/dist/v2/core/resources/credits.js +21 -0
- package/dist/v2/core/resources/customer.d.ts +150 -0
- package/dist/v2/core/resources/customer.js +53 -0
- package/dist/v2/core/resources/index.d.ts +4 -1
- package/dist/v2/core/resources/index.js +4 -1
- package/dist/v2/core/resources/session.d.ts +27 -0
- package/dist/v2/core/resources/session.js +56 -0
- package/dist/v2/core/utils/pluginConfig.d.ts +14 -0
- package/dist/v2/core/utils/pluginConfig.js +96 -29
- package/dist/v2/index.d.ts +11 -2
- package/dist/v2/index.js +3 -1
- package/dist/v2/react/hooks/useAuth.d.ts +8 -0
- package/dist/v2/react/hooks/useAuth.js +9 -0
- package/dist/v2/react/hooks/useClubOffers.d.ts +101 -0
- package/dist/v2/react/hooks/useClubOffers.js +126 -0
- package/dist/v2/react/hooks/useCredits.d.ts +67 -0
- package/dist/v2/react/hooks/useCredits.js +80 -0
- package/dist/v2/react/hooks/useCustomer.d.ts +11 -0
- package/dist/v2/react/hooks/useCustomer.js +11 -0
- package/dist/v2/react/hooks/useCustomerInfos.d.ts +12 -0
- package/dist/v2/react/hooks/useCustomerInfos.js +53 -0
- package/dist/v2/react/hooks/useCustomerOrders.d.ts +17 -0
- package/dist/v2/react/hooks/useCustomerOrders.js +51 -0
- package/dist/v2/react/hooks/useCustomerSubscriptions.d.ts +23 -0
- package/dist/v2/react/hooks/useCustomerSubscriptions.js +94 -0
- package/dist/v2/react/hooks/useLogin.d.ts +53 -0
- package/dist/v2/react/hooks/useLogin.js +75 -0
- package/dist/v2/react/hooks/useTranslation.d.ts +40 -3
- package/dist/v2/react/hooks/useTranslation.js +128 -16
- package/dist/v2/react/index.d.ts +18 -1
- package/dist/v2/react/index.js +9 -0
- package/package.json +2 -1
- package/dist/v2/react/hooks/useDiscountQuery.d.ts +0 -79
- package/dist/v2/react/hooks/useDiscountQuery.js +0 -24
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credits Resource Client
|
|
3
|
+
* Handles credits-related API operations
|
|
4
|
+
*/
|
|
5
|
+
export class CreditsResource {
|
|
6
|
+
constructor(apiClient) {
|
|
7
|
+
this.apiClient = apiClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get customer credit balance and transaction history
|
|
11
|
+
*/
|
|
12
|
+
async getCustomerCredits(customerId, storeId) {
|
|
13
|
+
return this.apiClient.get(`/api/v1/credits/balance/${customerId}/${storeId}`);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Redeem a product using credits
|
|
17
|
+
*/
|
|
18
|
+
async redeemProduct(data) {
|
|
19
|
+
return this.apiClient.post('/api/v1/credits/redeem', data);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer Resource Client
|
|
3
|
+
* Handles customer-related API operations
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from './apiClient';
|
|
6
|
+
export interface CustomerAddress {
|
|
7
|
+
firstName: string | null;
|
|
8
|
+
lastName: string | null;
|
|
9
|
+
address1: string | null;
|
|
10
|
+
address2: string | null;
|
|
11
|
+
city: string | null;
|
|
12
|
+
province: string | null;
|
|
13
|
+
country: string | null;
|
|
14
|
+
zip: string | null;
|
|
15
|
+
phone: string | null;
|
|
16
|
+
email?: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface CustomerOrderSummary {
|
|
19
|
+
id: string;
|
|
20
|
+
totalPrice: number;
|
|
21
|
+
currency: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
status: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CustomerInfos {
|
|
26
|
+
customer: {
|
|
27
|
+
id: string;
|
|
28
|
+
email: string | null;
|
|
29
|
+
firstName: string | null;
|
|
30
|
+
lastName: string | null;
|
|
31
|
+
externalCustomerId: string | null;
|
|
32
|
+
lastOrderId: string | null;
|
|
33
|
+
accountId: string;
|
|
34
|
+
storeId: string;
|
|
35
|
+
billingAddress: CustomerAddress | null;
|
|
36
|
+
shippingAddress: Omit<CustomerAddress, 'email'> | null;
|
|
37
|
+
currency: string | null;
|
|
38
|
+
locale: string | null;
|
|
39
|
+
draft: boolean;
|
|
40
|
+
acceptsMarketing: boolean;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
metadata: Record<string, any>;
|
|
44
|
+
device: any | null;
|
|
45
|
+
orders: CustomerOrderSummary[];
|
|
46
|
+
subscriptions: any[];
|
|
47
|
+
};
|
|
48
|
+
promotionCodes: any[];
|
|
49
|
+
}
|
|
50
|
+
export interface OrderWithRelations {
|
|
51
|
+
id: string;
|
|
52
|
+
currency: string;
|
|
53
|
+
paidAmount: number;
|
|
54
|
+
status: string;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
metadata?: Record<string, any>;
|
|
57
|
+
items: any[];
|
|
58
|
+
summaries?: any[];
|
|
59
|
+
shippingAddress?: any;
|
|
60
|
+
billingAddress?: any;
|
|
61
|
+
pickupAddress?: any;
|
|
62
|
+
checkoutSession?: {
|
|
63
|
+
returnUrl?: string;
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
relatedOrders?: any[];
|
|
67
|
+
customer?: any;
|
|
68
|
+
store?: any;
|
|
69
|
+
account?: {
|
|
70
|
+
id: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
};
|
|
73
|
+
payments?: any[];
|
|
74
|
+
promotions?: any[];
|
|
75
|
+
subscriptions?: any[];
|
|
76
|
+
adjustments: any[];
|
|
77
|
+
}
|
|
78
|
+
export interface Subscription {
|
|
79
|
+
id: string;
|
|
80
|
+
status: string;
|
|
81
|
+
createdAt: string;
|
|
82
|
+
currency: string;
|
|
83
|
+
cancelAtPeriodEnd: boolean;
|
|
84
|
+
currentPeriodEnd: string | null;
|
|
85
|
+
currentPeriodStart: string | null;
|
|
86
|
+
quantity: number;
|
|
87
|
+
trialEnd: string | null;
|
|
88
|
+
customerId: string;
|
|
89
|
+
customerEmail: string;
|
|
90
|
+
customerName: string;
|
|
91
|
+
priceCurrencyOptions: Record<string, {
|
|
92
|
+
rate: number;
|
|
93
|
+
amount: number;
|
|
94
|
+
lock: boolean;
|
|
95
|
+
date: string;
|
|
96
|
+
}>;
|
|
97
|
+
priceInterval: string;
|
|
98
|
+
priceIntervalCount: number;
|
|
99
|
+
priceRecurring: boolean;
|
|
100
|
+
productId: string;
|
|
101
|
+
priceId: string;
|
|
102
|
+
productTitle: string;
|
|
103
|
+
}
|
|
104
|
+
export interface SubscriptionsResponse {
|
|
105
|
+
items: Subscription[];
|
|
106
|
+
pagination: {
|
|
107
|
+
page: number;
|
|
108
|
+
pageSize: number;
|
|
109
|
+
hasNext: boolean;
|
|
110
|
+
nextPage: number | null;
|
|
111
|
+
previousPage: number | null;
|
|
112
|
+
totalItems: number;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export declare class CustomerResource {
|
|
116
|
+
private apiClient;
|
|
117
|
+
constructor(apiClient: ApiClient);
|
|
118
|
+
/**
|
|
119
|
+
* Get customer information by ID
|
|
120
|
+
*/
|
|
121
|
+
getCustomerInfos(customerId: string, storeId: string): Promise<CustomerInfos>;
|
|
122
|
+
/**
|
|
123
|
+
* Update customer information
|
|
124
|
+
*/
|
|
125
|
+
updateCustomer(customerId: string, data: {
|
|
126
|
+
email?: string;
|
|
127
|
+
firstName?: string;
|
|
128
|
+
lastName?: string;
|
|
129
|
+
acceptsMarketing?: boolean;
|
|
130
|
+
metadata?: Record<string, any>;
|
|
131
|
+
}): Promise<CustomerInfos>;
|
|
132
|
+
/**
|
|
133
|
+
* Get customer orders
|
|
134
|
+
*/
|
|
135
|
+
getCustomerOrders(customerId: string, storeId: string): Promise<{
|
|
136
|
+
orders: OrderWithRelations[];
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Get customer subscriptions
|
|
140
|
+
*/
|
|
141
|
+
getCustomerSubscriptions(): Promise<SubscriptionsResponse>;
|
|
142
|
+
/**
|
|
143
|
+
* Resume a subscription
|
|
144
|
+
*/
|
|
145
|
+
resumeSubscription(subscriptionId: string): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Cancel a subscription
|
|
148
|
+
*/
|
|
149
|
+
cancelSubscription(subscriptionId: string): Promise<void>;
|
|
150
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer Resource Client
|
|
3
|
+
* Handles customer-related API operations
|
|
4
|
+
*/
|
|
5
|
+
export class CustomerResource {
|
|
6
|
+
constructor(apiClient) {
|
|
7
|
+
this.apiClient = apiClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get customer information by ID
|
|
11
|
+
*/
|
|
12
|
+
async getCustomerInfos(customerId, storeId) {
|
|
13
|
+
return this.apiClient.get(`/api/v1/customers/${customerId}`, {
|
|
14
|
+
params: { storeId },
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Update customer information
|
|
19
|
+
*/
|
|
20
|
+
async updateCustomer(customerId, data) {
|
|
21
|
+
return this.apiClient.patch(`/api/v1/customers/${customerId}`, data);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get customer orders
|
|
25
|
+
*/
|
|
26
|
+
async getCustomerOrders(customerId, storeId) {
|
|
27
|
+
return this.apiClient.get(`/api/v1/orders/customer/${customerId}`, {
|
|
28
|
+
params: { storeId },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get customer subscriptions
|
|
33
|
+
*/
|
|
34
|
+
async getCustomerSubscriptions() {
|
|
35
|
+
return this.apiClient.get('/api/v1/subscriptions');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resume a subscription
|
|
39
|
+
*/
|
|
40
|
+
async resumeSubscription(subscriptionId) {
|
|
41
|
+
return this.apiClient.post('/api/v1/subscriptions/resume', {
|
|
42
|
+
subscriptionId,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Cancel a subscription
|
|
47
|
+
*/
|
|
48
|
+
async cancelSubscription(subscriptionId) {
|
|
49
|
+
return this.apiClient.post('/api/v1/subscriptions/cancel', {
|
|
50
|
+
subscriptionId,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -4,15 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * from './apiClient';
|
|
6
6
|
export * from './checkout';
|
|
7
|
+
export * from './credits';
|
|
8
|
+
export * from './customer';
|
|
7
9
|
export * from './discounts';
|
|
10
|
+
export * from './funnel';
|
|
8
11
|
export * from './offers';
|
|
9
12
|
export * from './orders';
|
|
10
13
|
export * from './payments';
|
|
11
14
|
export * from './postPurchases';
|
|
12
15
|
export * from './products';
|
|
13
16
|
export * from './promotions';
|
|
17
|
+
export * from './session';
|
|
14
18
|
export * from './shippingRates';
|
|
15
19
|
export * from './storeConfig';
|
|
16
20
|
export * from './threeds';
|
|
17
21
|
export * from './vipOffers';
|
|
18
|
-
export * from './funnel';
|
|
@@ -4,15 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * from './apiClient';
|
|
6
6
|
export * from './checkout';
|
|
7
|
+
export * from './credits';
|
|
8
|
+
export * from './customer';
|
|
7
9
|
export * from './discounts';
|
|
10
|
+
export * from './funnel';
|
|
8
11
|
export * from './offers';
|
|
9
12
|
export * from './orders';
|
|
10
13
|
export * from './payments';
|
|
11
14
|
export * from './postPurchases';
|
|
12
15
|
export * from './products';
|
|
13
16
|
export * from './promotions';
|
|
17
|
+
export * from './session';
|
|
14
18
|
export * from './shippingRates';
|
|
15
19
|
export * from './storeConfig';
|
|
16
20
|
export * from './threeds';
|
|
17
21
|
export * from './vipOffers';
|
|
18
|
-
export * from './funnel';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Resource Client
|
|
3
|
+
* Handles authentication and session management
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from './apiClient';
|
|
6
|
+
export interface RequestCodeResponse {
|
|
7
|
+
success: boolean;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface VerifyCodeResponse {
|
|
11
|
+
success: boolean;
|
|
12
|
+
token?: string;
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class SessionResource {
|
|
17
|
+
private apiClient;
|
|
18
|
+
constructor(apiClient: ApiClient);
|
|
19
|
+
/**
|
|
20
|
+
* Request verification code for email
|
|
21
|
+
*/
|
|
22
|
+
requestCode(email: string, storeId: string): Promise<RequestCodeResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Verify code and login
|
|
25
|
+
*/
|
|
26
|
+
verifyCode(email: string, code: string, storeId: string): Promise<VerifyCodeResponse>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Resource Client
|
|
3
|
+
* Handles authentication and session management
|
|
4
|
+
*/
|
|
5
|
+
export class SessionResource {
|
|
6
|
+
constructor(apiClient) {
|
|
7
|
+
this.apiClient = apiClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Request verification code for email
|
|
11
|
+
*/
|
|
12
|
+
async requestCode(email, storeId) {
|
|
13
|
+
try {
|
|
14
|
+
await this.apiClient.post('/api/v1/cms/session/request-code', {
|
|
15
|
+
email,
|
|
16
|
+
storeId,
|
|
17
|
+
});
|
|
18
|
+
return { success: true };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
error: error instanceof Error ? error.message : 'Failed to send code',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Verify code and login
|
|
29
|
+
*/
|
|
30
|
+
async verifyCode(email, code, storeId) {
|
|
31
|
+
try {
|
|
32
|
+
const response = await this.apiClient.post('/api/v1/cms/session/login', {
|
|
33
|
+
email,
|
|
34
|
+
code,
|
|
35
|
+
storeId,
|
|
36
|
+
});
|
|
37
|
+
if (!response) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: 'Invalid code',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
token: response.token,
|
|
46
|
+
sessionId: response.sessionId,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
error: error instanceof Error ? error.message : 'Failed to verify code',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -27,6 +27,20 @@ export type RawPluginConfig<TConfig = Record<string, any>> = {
|
|
|
27
27
|
* Handles local dev, production, and raw config
|
|
28
28
|
*/
|
|
29
29
|
export declare const loadPluginConfig: (configVariant?: string, rawConfig?: RawPluginConfig) => Promise<PluginConfig>;
|
|
30
|
+
/**
|
|
31
|
+
* Helper to load local config file for development (from /config directory)
|
|
32
|
+
* Returns the config object that can be passed to TagadaProvider
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadLocalConfig(configName?: string): Promise<Record<string, unknown> | null>;
|
|
35
|
+
export interface CreateRawPluginConfigOptions {
|
|
36
|
+
config?: any;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a RawPluginConfig object from provided options
|
|
40
|
+
* @param options - Configuration options including storeId, accountId, basePath, configName, or a direct config object
|
|
41
|
+
* @returns A RawPluginConfig object or undefined if required fields are missing
|
|
42
|
+
*/
|
|
43
|
+
export declare function createRawPluginConfig(options?: CreateRawPluginConfigOptions): Promise<RawPluginConfig | undefined>;
|
|
30
44
|
export declare class PluginConfigUtils {
|
|
31
45
|
/**
|
|
32
46
|
* Get plugin configuration from various sources
|
|
@@ -88,33 +88,16 @@ const getMetaContent = (name) => {
|
|
|
88
88
|
return metaTag?.getAttribute('content') || undefined;
|
|
89
89
|
};
|
|
90
90
|
/**
|
|
91
|
-
* Load production config from
|
|
91
|
+
* Load production config from meta tags
|
|
92
|
+
* Meta tags are injected by the plugin middleware during HTML serving
|
|
93
|
+
* This avoids making an additional HEAD request (~300ms savings)
|
|
92
94
|
*/
|
|
93
95
|
const loadProductionConfig = async () => {
|
|
94
96
|
try {
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
}
|
|
97
|
+
// Read store/account info from meta tags (injected by middleware)
|
|
98
|
+
const storeId = getMetaContent('x-plugin-store-id');
|
|
99
|
+
const accountId = getMetaContent('x-plugin-account-id');
|
|
100
|
+
const basePath = getMetaContent('x-plugin-base-path') || '/';
|
|
118
101
|
// Get deployment config from meta tags
|
|
119
102
|
let config = {};
|
|
120
103
|
try {
|
|
@@ -129,17 +112,22 @@ const loadProductionConfig = async () => {
|
|
|
129
112
|
}
|
|
130
113
|
// Final validation and warnings
|
|
131
114
|
if (!storeId) {
|
|
132
|
-
console.warn('⚠️ Plugin config: Store ID not found in
|
|
115
|
+
console.warn('⚠️ Plugin config: Store ID not found in meta tags');
|
|
133
116
|
}
|
|
134
117
|
if (!accountId) {
|
|
135
|
-
console.warn('⚠️ Plugin config: Account ID not found in
|
|
118
|
+
console.warn('⚠️ Plugin config: Account ID not found in meta tags');
|
|
136
119
|
}
|
|
137
|
-
const result = { storeId, accountId, basePath
|
|
138
|
-
console.log('
|
|
120
|
+
const result = { storeId, accountId, basePath, config };
|
|
121
|
+
console.log('🚀 Plugin config loaded from meta tags (no HEAD request needed):', {
|
|
122
|
+
storeId,
|
|
123
|
+
accountId,
|
|
124
|
+
basePath,
|
|
125
|
+
configKeys: Object.keys(config)
|
|
126
|
+
});
|
|
139
127
|
return result;
|
|
140
128
|
}
|
|
141
129
|
catch (error) {
|
|
142
|
-
console.warn('Failed to load production config, using defaults:', error);
|
|
130
|
+
console.warn('⚠️ Failed to load production config from meta tags, using defaults:', error);
|
|
143
131
|
return { basePath: '/', config: {} };
|
|
144
132
|
}
|
|
145
133
|
};
|
|
@@ -166,6 +154,85 @@ export const loadPluginConfig = async (configVariant = 'default', rawConfig) =>
|
|
|
166
154
|
// Fall back to production config
|
|
167
155
|
return loadProductionConfig();
|
|
168
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* Helper to load local config file for development (from /config directory)
|
|
159
|
+
* Returns the config object that can be passed to TagadaProvider
|
|
160
|
+
*/
|
|
161
|
+
export async function loadLocalConfig(configName = 'default') {
|
|
162
|
+
try {
|
|
163
|
+
// Only load in localhost
|
|
164
|
+
const isLocalhost = typeof window !== 'undefined' &&
|
|
165
|
+
(window.location.hostname === 'localhost' ||
|
|
166
|
+
window.location.hostname.includes('.localhost') ||
|
|
167
|
+
window.location.hostname.includes('127.0.0.1'));
|
|
168
|
+
if (!isLocalhost) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
// Try .tgd.json first, then .json, then .config.json
|
|
172
|
+
const possiblePaths = [
|
|
173
|
+
`/config/${configName}.tgd.json`,
|
|
174
|
+
`/config/${configName}.json`,
|
|
175
|
+
`/config/${configName}.config.json`,
|
|
176
|
+
];
|
|
177
|
+
for (const path of possiblePaths) {
|
|
178
|
+
try {
|
|
179
|
+
const response = await fetch(path);
|
|
180
|
+
if (response.ok) {
|
|
181
|
+
const config = await response.json();
|
|
182
|
+
console.log(`✅ [loadLocalConfig] Loaded config from ${path}:`, {
|
|
183
|
+
configName: config.configName,
|
|
184
|
+
hasBranding: !!config.branding,
|
|
185
|
+
});
|
|
186
|
+
return config;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
console.warn(`⚠️ [loadLocalConfig] No config found for '${configName}'`);
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error('[loadLocalConfig] Error loading config:', error);
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Creates a RawPluginConfig object from provided options
|
|
203
|
+
* @param options - Configuration options including storeId, accountId, basePath, configName, or a direct config object
|
|
204
|
+
* @returns A RawPluginConfig object or undefined if required fields are missing
|
|
205
|
+
*/
|
|
206
|
+
export async function createRawPluginConfig(options) {
|
|
207
|
+
try {
|
|
208
|
+
const storeId = process.env.TAGADA_STORE_ID;
|
|
209
|
+
const accountId = process.env.TAGADA_ACCOUNT_ID;
|
|
210
|
+
const basePath = process.env.TAGADA_BASE_PATH;
|
|
211
|
+
const configName = process.env.TAGADA_CONFIG_NAME;
|
|
212
|
+
if (storeId) {
|
|
213
|
+
console.warn('[createRawPluginConfig] No storeId provided');
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const resolvedConfig = options?.config ?? await loadLocalConfig(configName);
|
|
217
|
+
const rawConfig = {
|
|
218
|
+
storeId: storeId,
|
|
219
|
+
accountId: accountId,
|
|
220
|
+
basePath: basePath || '/',
|
|
221
|
+
config: resolvedConfig,
|
|
222
|
+
};
|
|
223
|
+
console.log('[createRawPluginConfig] Created raw plugin config:', {
|
|
224
|
+
hasStoreId: !!rawConfig.storeId,
|
|
225
|
+
hasAccountId: !!rawConfig.accountId,
|
|
226
|
+
basePath: rawConfig.basePath,
|
|
227
|
+
hasConfig: !!rawConfig.config,
|
|
228
|
+
});
|
|
229
|
+
return rawConfig;
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
console.error('[createRawPluginConfig] Error creating config:', error);
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
169
236
|
export class PluginConfigUtils {
|
|
170
237
|
/**
|
|
171
238
|
* Get plugin configuration from various sources
|
package/dist/v2/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './core/isoData';
|
|
|
10
10
|
export * from './core/utils/currency';
|
|
11
11
|
export * from './core/utils/pluginConfig';
|
|
12
12
|
export * from './core/utils/products';
|
|
13
|
+
export * from './core/pathRemapping';
|
|
13
14
|
export type { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, Promotion } from './core/resources/checkout';
|
|
14
15
|
export type { Order, OrderLineItem } from './core/utils/order';
|
|
15
16
|
export type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferSummary } from './core/resources/postPurchases';
|
|
@@ -20,5 +21,13 @@ export type { ShippingRate, ShippingRatesResponse } from './core/resources/shipp
|
|
|
20
21
|
export type { ApplyDiscountResponse, Discount, DiscountCodeValidation, RemoveDiscountResponse } from './core/resources/discounts';
|
|
21
22
|
export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './core/resources/vipOffers';
|
|
22
23
|
export type { StoreConfig } from './core/resources/storeConfig';
|
|
23
|
-
export type {
|
|
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,
|
|
24
|
+
export type { FunnelContextUpdateRequest, FunnelContextUpdateResponse, FunnelEvent, FunnelInitializeRequest, FunnelInitializeResponse, FunnelNavigateRequest, FunnelNavigateResponse, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext } from './core/resources/funnel';
|
|
25
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
26
|
+
export type { TranslateFunction, UseTranslationOptions, UseTranslationResult } from './react/hooks/useTranslation';
|
|
27
|
+
export type { ClubOffer, ClubOfferItem, ClubOfferLineItem, ClubOfferSummary, UseClubOffersOptions, UseClubOffersResult } from './react/hooks/useClubOffers';
|
|
28
|
+
export type { UseLoginOptions, UseLoginResult } from './react/hooks/useLogin';
|
|
29
|
+
export type { CustomerAddress, CustomerInfos, CustomerOrderSummary, OrderWithRelations, Subscription, SubscriptionsResponse } from './core/resources/customer';
|
|
30
|
+
export type { UseCustomerResult } from './react/hooks/useCustomer';
|
|
31
|
+
export type { UseCustomerInfosOptions, UseCustomerInfosResult } from './react/hooks/useCustomerInfos';
|
|
32
|
+
export type { UseCustomerOrdersOptions, UseCustomerOrdersResult } from './react/hooks/useCustomerOrders';
|
|
33
|
+
export type { UseCustomerSubscriptionsOptions, UseCustomerSubscriptionsResult } from './react/hooks/useCustomerSubscriptions';
|
package/dist/v2/index.js
CHANGED
|
@@ -11,5 +11,7 @@ export * from './core/isoData';
|
|
|
11
11
|
export * from './core/utils/currency';
|
|
12
12
|
export * from './core/utils/pluginConfig';
|
|
13
13
|
export * from './core/utils/products';
|
|
14
|
+
// Path remapping helpers (framework-agnostic)
|
|
15
|
+
export * from './core/pathRemapping';
|
|
14
16
|
// 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,
|
|
17
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|