@tagadapay/plugin-sdk 2.8.7 → 2.8.8
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.
|
@@ -33,13 +33,202 @@ export declare enum FunnelActionType {
|
|
|
33
33
|
export type NextAction<T> = T & {
|
|
34
34
|
[key: string]: any;
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Base resource data type - all resources must have an id and optional metadata
|
|
38
|
+
*/
|
|
39
|
+
export interface FunnelResourceData {
|
|
40
|
+
id: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resource metadata for tracking, versioning, and relationships
|
|
45
|
+
*/
|
|
46
|
+
export interface ResourceMetadata {
|
|
47
|
+
/** Plugin that created this resource */
|
|
48
|
+
source?: string;
|
|
49
|
+
/** Schema version for this resource */
|
|
50
|
+
version?: string;
|
|
51
|
+
/** Timestamp when resource was created */
|
|
52
|
+
timestamp?: number;
|
|
53
|
+
/** Scope: how long should this resource persist */
|
|
54
|
+
scope?: 'global' | 'session' | 'step' | 'ephemeral';
|
|
55
|
+
/** Tags for categorization and filtering */
|
|
56
|
+
tags?: string[];
|
|
57
|
+
/** Related resource IDs (for relationships) */
|
|
58
|
+
relatedTo?: string[];
|
|
59
|
+
/** Custom metadata */
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Wrapped resource with metadata
|
|
64
|
+
*/
|
|
65
|
+
export interface ResourceWithMetadata<T extends FunnelResourceData = FunnelResourceData> {
|
|
66
|
+
data: T;
|
|
67
|
+
meta: ResourceMetadata;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Standard resource types for e-commerce (provides IntelliSense)
|
|
71
|
+
* These are SUGGESTIONS, not limitations - any key is allowed via index signature
|
|
72
|
+
*/
|
|
73
|
+
export interface StandardResourceKeys {
|
|
74
|
+
order?: FunnelResourceData;
|
|
75
|
+
customer?: FunnelResourceData;
|
|
76
|
+
payment?: FunnelResourceData;
|
|
77
|
+
checkout?: FunnelResourceData;
|
|
78
|
+
cart?: FunnelResourceData;
|
|
79
|
+
subscription?: FunnelResourceData;
|
|
80
|
+
product?: FunnelResourceData;
|
|
81
|
+
variant?: FunnelResourceData;
|
|
82
|
+
mainOrder?: FunnelResourceData;
|
|
83
|
+
upsellOrder?: FunnelResourceData;
|
|
84
|
+
downsellOrder?: FunnelResourceData;
|
|
85
|
+
orders?: FunnelResourceData[];
|
|
86
|
+
customers?: FunnelResourceData[];
|
|
87
|
+
payments?: FunnelResourceData[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Flexible resource map supporting:
|
|
91
|
+
* 1. Single resources (order)
|
|
92
|
+
* 2. Collections (orders[])
|
|
93
|
+
* 3. Wrapped resources with metadata
|
|
94
|
+
* 4. Completely custom keys
|
|
95
|
+
*
|
|
96
|
+
* @example Simple usage (backward compatible)
|
|
97
|
+
* ```typescript
|
|
98
|
+
* resources: {
|
|
99
|
+
* order: { id: '123', amount: 100 }
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Multiple instances via collections
|
|
104
|
+
* ```typescript
|
|
105
|
+
* resources: {
|
|
106
|
+
* order: { id: 'main' }, // Hot context
|
|
107
|
+
* orders: [ // Full collection
|
|
108
|
+
* { id: 'main', type: 'initial' },
|
|
109
|
+
* { id: 'upsell1', type: 'addon' }
|
|
110
|
+
* ]
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example With metadata (opt-in)
|
|
115
|
+
* ```typescript
|
|
116
|
+
* resources: {
|
|
117
|
+
* order: {
|
|
118
|
+
* data: { id: '123', amount: 100 },
|
|
119
|
+
* meta: { source: 'checkout-plugin', version: '2.0' }
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example Typed resources (opt-in strict typing)
|
|
125
|
+
* ```typescript
|
|
126
|
+
* interface MyResources {
|
|
127
|
+
* order: Order; // Your typed Order interface
|
|
128
|
+
* customer: Customer;
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
* const result = await funnel.next<MyResources>({
|
|
132
|
+
* type: 'payment_success',
|
|
133
|
+
* data: {
|
|
134
|
+
* resources: {
|
|
135
|
+
* order: { id: '123', amount: 100 } // ✅ Type-checked!
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export type FunnelResourceMap<TCustom = {}> = StandardResourceKeys & {
|
|
142
|
+
/**
|
|
143
|
+
* Fully extensible - any key allowed
|
|
144
|
+
* Value can be:
|
|
145
|
+
* - Single resource: { id: '...' }
|
|
146
|
+
* - Collection: [{ id: '...' }, ...]
|
|
147
|
+
* - Wrapped: { data: {...}, meta: {...} }
|
|
148
|
+
*/
|
|
149
|
+
[key: string]: FunnelResourceData | FunnelResourceData[] | ResourceWithMetadata | ResourceWithMetadata[] | undefined;
|
|
150
|
+
} & TCustom;
|
|
151
|
+
/**
|
|
152
|
+
* Typed resources structure for funnel actions
|
|
153
|
+
*
|
|
154
|
+
* 💡 RESOURCE PROTOCOL: Flexible & Scalable
|
|
155
|
+
*
|
|
156
|
+
* The system supports multiple patterns for maximum flexibility:
|
|
157
|
+
*
|
|
158
|
+
* 1. **Simple Pattern** (Default - Backward Compatible):
|
|
159
|
+
* ```typescript
|
|
160
|
+
* resources: { order: { id: '123' } }
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* 2. **Aliasing Pattern** (For Hot + Named Context):
|
|
164
|
+
* ```typescript
|
|
165
|
+
* resources: {
|
|
166
|
+
* order: { id: '123' }, // Hot context (latest)
|
|
167
|
+
* mainOrder: { id: '123' } // Named (persistent)
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* 3. **Collection Pattern** (For Multiple Instances):
|
|
172
|
+
* ```typescript
|
|
173
|
+
* resources: {
|
|
174
|
+
* orders: [
|
|
175
|
+
* { id: 'main', label: 'Initial Order' },
|
|
176
|
+
* { id: 'upsell1', label: 'Upsell #1' }
|
|
177
|
+
* ]
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* 4. **Metadata Pattern** (For Versioning/Tracking):
|
|
182
|
+
* ```typescript
|
|
183
|
+
* resources: {
|
|
184
|
+
* order: {
|
|
185
|
+
* data: { id: '123', amount: 100 },
|
|
186
|
+
* meta: { version: '2.0', source: 'checkout' }
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* 5. **Namespaced Pattern** (For Collision Prevention):
|
|
192
|
+
* ```typescript
|
|
193
|
+
* resources: {
|
|
194
|
+
* 'checkout:order': { id: '123' },
|
|
195
|
+
* 'subscription:order': { id: '456' }
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* 6. **Typed Pattern** (For Strict Type Safety):
|
|
200
|
+
* ```typescript
|
|
201
|
+
* interface StrictResources {
|
|
202
|
+
* order: Order; // Your interface
|
|
203
|
+
* customer: Customer;
|
|
204
|
+
* }
|
|
205
|
+
* funnel.next<StrictResources>({ ... })
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* All patterns work together - choose what fits your use case!
|
|
209
|
+
*/
|
|
210
|
+
export interface FunnelActionResources<TCustom = {}> {
|
|
211
|
+
/**
|
|
212
|
+
* Resource map - infinitely extensible
|
|
213
|
+
* - Standard keys provide IntelliSense
|
|
214
|
+
* - Custom keys allowed via index signature
|
|
215
|
+
* - Supports single resources, collections, and metadata
|
|
216
|
+
* - Optional: pass generic for strict typing
|
|
217
|
+
*/
|
|
218
|
+
resources?: FunnelResourceMap<TCustom>;
|
|
219
|
+
/**
|
|
220
|
+
* Legacy top-level data (backward compatible)
|
|
221
|
+
* Will be automatically migrated to resources by orchestrator
|
|
222
|
+
*/
|
|
223
|
+
[key: string]: any;
|
|
224
|
+
}
|
|
225
|
+
export interface DirectNavigationActionData extends FunnelActionResources {
|
|
37
226
|
targetStepId: string;
|
|
38
227
|
}
|
|
39
|
-
export interface BackNavigationActionData {
|
|
228
|
+
export interface BackNavigationActionData extends FunnelActionResources {
|
|
40
229
|
targetStepId: string;
|
|
41
230
|
}
|
|
42
|
-
export interface PaymentSuccessActionData {
|
|
231
|
+
export interface PaymentSuccessActionData extends FunnelActionResources {
|
|
43
232
|
payment: {
|
|
44
233
|
id: string;
|
|
45
234
|
status: string;
|
|
@@ -53,34 +242,30 @@ export interface PaymentSuccessActionData {
|
|
|
53
242
|
currency: string;
|
|
54
243
|
[key: string]: any;
|
|
55
244
|
};
|
|
56
|
-
[key: string]: any;
|
|
57
245
|
}
|
|
58
|
-
export interface PaymentFailedActionData {
|
|
246
|
+
export interface PaymentFailedActionData extends FunnelActionResources {
|
|
59
247
|
payment: {
|
|
60
248
|
id: string;
|
|
61
249
|
status: string;
|
|
62
250
|
error?: string;
|
|
63
251
|
[key: string]: any;
|
|
64
252
|
};
|
|
65
|
-
[key: string]: any;
|
|
66
253
|
}
|
|
67
|
-
export interface OfferAcceptedActionData {
|
|
254
|
+
export interface OfferAcceptedActionData extends FunnelActionResources {
|
|
68
255
|
offer: {
|
|
69
256
|
accepted: boolean;
|
|
70
257
|
offerId?: string;
|
|
71
258
|
[key: string]: any;
|
|
72
259
|
};
|
|
73
|
-
[key: string]: any;
|
|
74
260
|
}
|
|
75
|
-
export interface OfferDeclinedActionData {
|
|
261
|
+
export interface OfferDeclinedActionData extends FunnelActionResources {
|
|
76
262
|
offer: {
|
|
77
263
|
declined: boolean;
|
|
78
264
|
offerId?: string;
|
|
79
265
|
[key: string]: any;
|
|
80
266
|
};
|
|
81
|
-
[key: string]: any;
|
|
82
267
|
}
|
|
83
|
-
export interface CartUpdatedActionData {
|
|
268
|
+
export interface CartUpdatedActionData extends FunnelActionResources {
|
|
84
269
|
cart: {
|
|
85
270
|
hasSpecificItem?: boolean;
|
|
86
271
|
itemIds?: string[];
|
|
@@ -88,13 +273,11 @@ export interface CartUpdatedActionData {
|
|
|
88
273
|
total?: number;
|
|
89
274
|
[key: string]: any;
|
|
90
275
|
};
|
|
91
|
-
[key: string]: any;
|
|
92
276
|
}
|
|
93
|
-
export interface FormSubmitActionData {
|
|
277
|
+
export interface FormSubmitActionData extends FunnelActionResources {
|
|
94
278
|
form?: {
|
|
95
279
|
[key: string]: any;
|
|
96
280
|
};
|
|
97
|
-
[key: string]: any;
|
|
98
281
|
}
|
|
99
282
|
/**
|
|
100
283
|
* Base properties shared by all FunnelAction types
|
|
@@ -149,7 +332,10 @@ export type FunnelAction = BaseFunnelAction & (({
|
|
|
149
332
|
data: NextAction<CartUpdatedActionData>;
|
|
150
333
|
}) | ({
|
|
151
334
|
type: FunnelActionType.CUSTOM;
|
|
152
|
-
data: NextAction<
|
|
335
|
+
data: NextAction<FunnelActionResources>;
|
|
336
|
+
}) | ({
|
|
337
|
+
type: string;
|
|
338
|
+
data?: NextAction<FunnelActionResources>;
|
|
153
339
|
}));
|
|
154
340
|
export interface FunnelNavigationAction {
|
|
155
341
|
type: 'redirect' | 'replace' | 'push' | 'external' | 'none';
|
|
@@ -167,7 +353,33 @@ export interface FunnelNavigationResult {
|
|
|
167
353
|
timestamp: string;
|
|
168
354
|
};
|
|
169
355
|
}
|
|
170
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Funnel context available to plugins
|
|
358
|
+
* Contains current state, resources, and metadata about the funnel session
|
|
359
|
+
*
|
|
360
|
+
* @example Basic usage
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const context = await funnel.getContext();
|
|
363
|
+
* const orderId = context.resources?.order?.id;
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* @example Typed usage (opt-in strict typing)
|
|
367
|
+
* ```typescript
|
|
368
|
+
* interface MyResources {
|
|
369
|
+
* order: Order;
|
|
370
|
+
* customer: Customer;
|
|
371
|
+
* }
|
|
372
|
+
* const context = await funnel.getContext<MyResources>();
|
|
373
|
+
* const total = context.resources?.order.amount; // ✅ Type-safe!
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @example Collection access
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const allOrders = context.resources?.orders; // FunnelResourceData[]
|
|
379
|
+
* const mainOrder = allOrders?.find(o => o.id === 'main');
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
export interface SimpleFunnelContext<TCustom = {}> {
|
|
171
383
|
customerId: string;
|
|
172
384
|
storeId: string;
|
|
173
385
|
sessionId: string;
|
|
@@ -181,6 +393,17 @@ export interface SimpleFunnelContext {
|
|
|
181
393
|
furthestStepId?: string;
|
|
182
394
|
startedAt: number;
|
|
183
395
|
lastActivityAt: number;
|
|
396
|
+
/**
|
|
397
|
+
* Typed resources map - infinitely extensible
|
|
398
|
+
* - Single resources, collections, or wrapped with metadata
|
|
399
|
+
* - Pass generic for strict typing: SimpleFunnelContext<MyResources>
|
|
400
|
+
* - Standard keys provide IntelliSense, custom keys always allowed
|
|
401
|
+
*/
|
|
402
|
+
resources?: FunnelResourceMap<TCustom>;
|
|
403
|
+
/**
|
|
404
|
+
* Legacy/Custom metadata
|
|
405
|
+
* For backward compatibility and flexible unstructured data
|
|
406
|
+
*/
|
|
184
407
|
metadata?: Record<string, any>;
|
|
185
408
|
}
|
|
186
409
|
export interface FunnelInitializeRequest {
|
package/dist/v2/index.d.ts
CHANGED
|
@@ -23,9 +23,10 @@ export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './co
|
|
|
23
23
|
export type { StoreConfig } from './core/resources/storeConfig';
|
|
24
24
|
export { FunnelActionType } from './core/resources/funnel';
|
|
25
25
|
export type { BackNavigationActionData, CartUpdatedActionData, DirectNavigationActionData, FormSubmitActionData, FunnelContextUpdateRequest, FunnelContextUpdateResponse, FunnelAction as FunnelEvent, FunnelInitializeRequest, FunnelInitializeResponse, FunnelNavigateRequest, FunnelNavigateResponse, FunnelNavigationAction, FunnelNavigationResult, NextAction, OfferAcceptedActionData, OfferDeclinedActionData, PaymentFailedActionData, PaymentSuccessActionData, SimpleFunnelContext } from './core/resources/funnel';
|
|
26
|
-
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, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
26
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
27
27
|
export type { TranslateFunction, TranslationText, UseTranslationOptions, UseTranslationResult } from './react/hooks/useTranslation';
|
|
28
28
|
export type { ClubOffer, ClubOfferItem, ClubOfferLineItem, ClubOfferSummary, UseClubOffersOptions, UseClubOffersResult } from './react/hooks/useClubOffers';
|
|
29
|
+
export type { UseCreditsOptions, UseCreditsResult } from './react/hooks/useCredits';
|
|
29
30
|
export type { UseLoginOptions, UseLoginResult } from './react/hooks/useLogin';
|
|
30
31
|
export type { CustomerAddress, CustomerInfos, CustomerOrderSummary, OrderWithRelations, Subscription, SubscriptionsResponse } from './core/resources/customer';
|
|
31
32
|
export type { UseCustomerResult } from './react/hooks/useCustomer';
|
package/dist/v2/index.js
CHANGED
|
@@ -15,4 +15,4 @@ export * from './core/utils/products';
|
|
|
15
15
|
export * from './core/pathRemapping';
|
|
16
16
|
export { FunnelActionType } from './core/resources/funnel';
|
|
17
17
|
// React exports (hooks and components only, types are exported above)
|
|
18
|
-
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, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
18
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
@@ -46,6 +46,6 @@ export declare function useSimpleFunnel(funnelId: string, initialStepId?: string
|
|
|
46
46
|
next: (event: FunnelAction) => Promise<any>;
|
|
47
47
|
goToStep: (stepId: string) => Promise<any>;
|
|
48
48
|
isLoading: boolean;
|
|
49
|
-
context: SimpleFunnelContext | null;
|
|
49
|
+
context: SimpleFunnelContext<{}> | null;
|
|
50
50
|
};
|
|
51
51
|
export type { FunnelAction as FunnelEvent, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext } from '../../core/resources/funnel';
|