@thorprovider/types 2.0.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.
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Header Configuration Types
3
+ *
4
+ * Type definitions for configurable header navigation system.
5
+ * Supports static links, mega menus, preset components (cart, account),
6
+ * dynamic data injection, and hybrid icon system.
7
+ */
8
+
9
+ /**
10
+ * Icon configuration with hybrid support
11
+ * - Lucide: Reference by string name for lucide-react icons
12
+ * - Custom: Provide React component/element directly
13
+ */
14
+ export type IconConfig =
15
+ | { type: 'lucide'; name: string }
16
+ | { type: 'custom'; component: React.ReactNode };
17
+
18
+ /**
19
+ * Navigation callout item (featured content in dropdown)
20
+ */
21
+ export interface NavigationCalloutItem {
22
+ logo?: string;
23
+ image?: string;
24
+ heading: string;
25
+ description: string;
26
+ href: string;
27
+ }
28
+
29
+ /**
30
+ * Navigation link item
31
+ */
32
+ export interface NavigationLinkItem {
33
+ title: string;
34
+ description?: string;
35
+ href: string;
36
+ badge?: {
37
+ content: number | string;
38
+ variant?: 'solid' | 'soft';
39
+ color?: string;
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Dynamic data source for navigation content
45
+ * - 'categories': Fetch and inject categories from backend
46
+ * - 'collections': Fetch and inject collections from backend
47
+ */
48
+ export type DynamicSource = 'categories' | 'collections';
49
+
50
+ /**
51
+ * Header link item - extends NavigationMenuItem with additional features
52
+ */
53
+ export type HeaderLinkItem =
54
+ | {
55
+ /** Simple direct link */
56
+ type: 'link';
57
+ label: string;
58
+ href: string;
59
+ icon?: IconConfig;
60
+ badge?: {
61
+ content: number | string;
62
+ variant?: 'solid' | 'soft';
63
+ color?: string;
64
+ };
65
+ }
66
+ | {
67
+ /** Dropdown menu with content */
68
+ type: 'dropdown';
69
+ label: string;
70
+ icon?: IconConfig;
71
+ badge?: {
72
+ content: number | string;
73
+ variant?: 'solid' | 'soft';
74
+ color?: string;
75
+ };
76
+ /** Optional dynamic data injection */
77
+ dynamicSource?: DynamicSource;
78
+ content: {
79
+ callout?: NavigationCalloutItem;
80
+ links: NavigationLinkItem[];
81
+ sideBanner?: NavigationCalloutItem;
82
+ columns?: number;
83
+ layout?: 'one' | 'two';
84
+ };
85
+ }
86
+ | {
87
+ /** Preset component (cart, account) */
88
+ type: 'preset';
89
+ preset: 'cart' | 'account';
90
+ /** Override default config for preset */
91
+ config?: Record<string, any>;
92
+ };
93
+
94
+ /**
95
+ * Account dropdown menu item
96
+ */
97
+ export type AccountMenuItem =
98
+ | {
99
+ /** Menu item label */
100
+ label: string;
101
+ /** Navigation href */
102
+ href?: string;
103
+ /** Icon configuration */
104
+ icon?: IconConfig;
105
+ /** Click handler (for actions like logout) */
106
+ onClick?: () => void;
107
+ /** Destructive action styling (e.g., logout, delete) */
108
+ destructive?: boolean;
109
+ divider?: never;
110
+ }
111
+ | {
112
+ /** Render as divider */
113
+ divider: true;
114
+ label?: never;
115
+ href?: never;
116
+ icon?: never;
117
+ onClick?: never;
118
+ destructive?: never;
119
+ };
120
+
121
+ /**
122
+ * Account dropdown configuration
123
+ */
124
+ export interface AccountDropdownConfig {
125
+ /** Enable account dropdown */
126
+ enabled: boolean;
127
+ /** Trigger label (e.g., "Mi cuenta") */
128
+ label?: string;
129
+ /** Trigger icon */
130
+ icon?: IconConfig;
131
+ /** Dropdown menu items */
132
+ items: AccountMenuItem[];
133
+ /** Logout handler */
134
+ onLogout?: () => void;
135
+ }
136
+
137
+ /**
138
+ * Search bar configuration
139
+ */
140
+ export interface SearchBarConfig {
141
+ /** Enable search bar */
142
+ enabled?: boolean;
143
+ /** Fixed width in pixels */
144
+ width?: number;
145
+ /** Placeholder text */
146
+ placeholder?: string;
147
+ /** Minimum characters to trigger search */
148
+ minChars?: number;
149
+ }
150
+
151
+
152
+ /**
153
+ * Main header navigation configuration
154
+ */
155
+ export interface HeaderNavigationConfig {
156
+ /** Logo configuration */
157
+ logo?: {
158
+ /** Logo image path */
159
+ src: string;
160
+ /** Logo alt text */
161
+ alt: string;
162
+ /** Logo width (px) */
163
+ width?: number;
164
+ /** Logo height (px) */
165
+ height?: number;
166
+ /** Logo link href */
167
+ href?: string;
168
+ };
169
+
170
+ /** Left navigation group (before search bar) */
171
+ leftLinks?: HeaderLinkItem[];
172
+
173
+ /** Right navigation group (after search bar) */
174
+ rightLinks?: HeaderLinkItem[];
175
+
176
+ /** Search bar configuration */
177
+ search?: SearchBarConfig;
178
+
179
+ /** Account dropdown configuration (if not using preset in rightLinks) */
180
+ account?: AccountDropdownConfig;
181
+
182
+ /** Cart configuration (if not using preset in rightLinks) */
183
+ cart?: {
184
+ /** Optional label rendered next to the cart icon in header (e.g., "Carrito") */
185
+ label?: string;
186
+ variant?: 'mini' | 'drawer';
187
+ composition?: 'compact' | 'detailed';
188
+ showBadge?: boolean;
189
+ };
190
+
191
+ /** Maximum container width (px) */
192
+ maxWidth?: number;
193
+
194
+ /** Enable overflow menu for excess links */
195
+ enableOverflow?: boolean;
196
+ }
197
+
package/src/index.ts ADDED
@@ -0,0 +1,249 @@
1
+ /**
2
+ * @thorprovider/types v1.0
3
+ * Shared TypeScript types for Thor Commerce ecosystem
4
+ *
5
+ * Pure type definitions with zero runtime dependencies.
6
+ * Foundation for type-safe commerce operations following SOLID principles.
7
+ */
8
+
9
+ // ============================================
10
+ // Common Types
11
+ // ============================================
12
+ export type {
13
+ Money,
14
+ Image,
15
+ SEO,
16
+ Connection,
17
+ Edge,
18
+ PaginationOptions,
19
+ SortOptions,
20
+ Country,
21
+ } from './common';
22
+
23
+ export type {
24
+ AuthorConfig,
25
+ BrandConfig,
26
+ ModulesConfig,
27
+ NavigationItem,
28
+ SiteConfig,
29
+ SocialConfig,
30
+ } from './site-config';
31
+
32
+ export type { SiteConfigLabels } from './site-config-labels';
33
+
34
+ // ============================================
35
+ // Product Types
36
+ // ============================================
37
+ export type {
38
+ Product,
39
+ ProductOption,
40
+ ProductVariant,
41
+ SelectedOption,
42
+ PriceRange,
43
+ GetProductsOptions,
44
+ ActiveFilter,
45
+ SortOption,
46
+ FilterSection,
47
+ FilterOption,
48
+ ProductPreview,
49
+ Review,
50
+ CompareProduct,
51
+ AdminProductVariant,
52
+ AdminProduct,
53
+ AdvancedSearchProductsOptions,
54
+ SearchResultMeta,
55
+ FilterConfig,
56
+ } from './product';
57
+
58
+ // ============================================
59
+ // Cart Types
60
+ // ============================================
61
+ export type {
62
+ Cart,
63
+ CartItem,
64
+ CartProduct,
65
+ CartCost,
66
+ CartLineInput,
67
+ CartLineUpdate,
68
+ ShippingMethod,
69
+ DiscountCode,
70
+ } from './cart';
71
+
72
+ // ============================================
73
+ // Inventory & Fulfillment Types
74
+ // ============================================
75
+ export type {
76
+ StockLocation,
77
+ InventoryLevel,
78
+ FulfillmentSet,
79
+ FulfillmentOption,
80
+ StockStatus,
81
+ StockValidation,
82
+ } from './stock-location';
83
+
84
+ // ============================================
85
+ // Collection Types
86
+ // ============================================
87
+ export type {
88
+ Collection,
89
+ CollectionProductsOptions,
90
+ GetCollectionsOptions,
91
+ } from './collection';
92
+
93
+ // ============================================
94
+ // Category Types
95
+ // ============================================
96
+ export type {
97
+ ProductCategory,
98
+ GetCategoriesOptions,
99
+ GetCategoriesCallback,
100
+ } from './category';
101
+
102
+ // ============================================
103
+ // Customer Types
104
+ // ============================================
105
+ export type {
106
+ Customer,
107
+ Address,
108
+ GetCustomersOptions,
109
+ GetCustomersCallback,
110
+ } from './customer';
111
+
112
+ // ============================================
113
+ // Region Types
114
+ // ============================================
115
+ export type {
116
+ Region,
117
+ } from './region';
118
+
119
+ // ============================================
120
+ // Order Types
121
+ // ============================================
122
+ export type {
123
+ Order,
124
+ OrderItem,
125
+ OrderStatus,
126
+ PaymentStatus,
127
+ FulfillmentStatus,
128
+ GetOrdersOptions,
129
+ GetOrdersCallback,
130
+ } from './order';
131
+
132
+ // ============================================
133
+ // Provider Types (L1 - Source of Truth)
134
+ // ============================================
135
+ export enum SupportedProviderType {
136
+ Medusa = 'medusa',
137
+ }
138
+
139
+ // Re-export provider types directly
140
+ export { type ProviderTypeString } from './provider';
141
+
142
+ export {
143
+ isSupportedProviderType,
144
+ getProviderMetadata,
145
+ PROVIDER_METADATA,
146
+ } from './provider';
147
+
148
+ // ============================================
149
+ // Storefront Types
150
+ // ============================================
151
+ export type {
152
+ StorefrontContext,
153
+ StorefrontPlatformType,
154
+ } from './storefront';
155
+
156
+ export {
157
+ StorefrontConfigError,
158
+ } from './storefront';
159
+
160
+ // ============================================
161
+ // Storefront Configuration Types
162
+ // ============================================
163
+ export type {
164
+ StorefrontConfig,
165
+ StorefrontSeoDefaults,
166
+ } from './storefront-config';
167
+
168
+ // ============================================
169
+ // Designer Configuration Types
170
+ // ============================================
171
+ export type {
172
+ DesignerConfig,
173
+ DesignerThemeConfig,
174
+ DesignerThemePreset,
175
+ DesignerNavItem,
176
+ DesignerHistoryEntry,
177
+ } from './designer-config';
178
+
179
+ // ============================================
180
+ // Auth Types
181
+ // ============================================
182
+ export type {
183
+ AuthProvider,
184
+ AuthConfig,
185
+ AuthMethod,
186
+ AuthStorage,
187
+ LoginCredentials,
188
+ RegisterData,
189
+ AuthResponse,
190
+ UpdateCustomerData,
191
+ CreateAddressData,
192
+ PasswordResetRequest,
193
+ PasswordResetConfirm,
194
+ } from './auth';
195
+
196
+ // ============================================
197
+ // Payment Types
198
+ // ============================================
199
+ export type {
200
+ PaymentMethod,
201
+ PaymentMethodType,
202
+ PaymentMethodFeatures,
203
+ PaymentMethodsOptions,
204
+ CachedPaymentMethods,
205
+ } from './payment';
206
+
207
+ // ============================================
208
+ // Commerce Provider Interface
209
+ // ============================================
210
+ export type {
211
+ CommerceProvider,
212
+ BackendCapabilities,
213
+ ProviderConfig,
214
+ } from './commerce-provider';
215
+
216
+ // ============================================
217
+ // Admin Types
218
+ // ============================================
219
+ export type {
220
+ AdminUser,
221
+ AuditLog,
222
+ DashboardConfig,
223
+ DashboardMetrics,
224
+ SalesMetrics,
225
+ OrdersMetrics,
226
+ ProductsMetrics,
227
+ ChartDataPoint,
228
+ DashboardMetricsAdapter,
229
+ DashboardOrdersAdapter,
230
+ DashboardProductsAdapter,
231
+ AuditLogAdapter,
232
+ SiteConfigMetadata,
233
+ ConfigHistoryEntry,
234
+ } from './admin';
235
+
236
+ // ============================================
237
+ // Header Configuration Types
238
+ // ============================================
239
+ export type {
240
+ IconConfig,
241
+ NavigationCalloutItem,
242
+ NavigationLinkItem,
243
+ DynamicSource,
244
+ HeaderLinkItem,
245
+ AccountMenuItem,
246
+ AccountDropdownConfig,
247
+ SearchBarConfig,
248
+ HeaderNavigationConfig,
249
+ } from './header-config';
package/src/order.ts ADDED
@@ -0,0 +1,188 @@
1
+ /**
2
+ * @thorprovider/types v3.0
3
+ * Order types - unified interface for all commerce providers
4
+ * Universal interfaces compatible with: Shopify, Medusa.js, WooCommerce, Magento, BigCommerce
5
+ */
6
+
7
+ import type { Money, Image } from './common';
8
+ import type { Address, Customer } from './customer';
9
+
10
+ /**
11
+ * Order status (overall)
12
+ *
13
+ * Platform mapping:
14
+ * - Shopify: Derived from financialStatus + fulfillmentStatus
15
+ * - Medusa: status field
16
+ * - WooCommerce: status (pending/processing/completed/cancelled/refunded)
17
+ * - Magento: status
18
+ */
19
+ export type OrderStatus =
20
+ | 'pending'
21
+ | 'processing'
22
+ | 'completed'
23
+ | 'cancelled'
24
+ | 'refunded';
25
+
26
+ /**
27
+ * Payment status (separate from order status)
28
+ *
29
+ * Platform mapping:
30
+ * - Shopify: financialStatus (PENDING, AUTHORIZED, PAID, REFUNDED, etc.)
31
+ * - Medusa: payment_status
32
+ * - WooCommerce: Derived from order status
33
+ * - Magento: payment status
34
+ */
35
+ export type PaymentStatus =
36
+ | 'pending'
37
+ | 'authorized'
38
+ | 'paid'
39
+ | 'partially_refunded'
40
+ | 'refunded';
41
+
42
+ /**
43
+ * Fulfillment status
44
+ *
45
+ * Platform mapping:
46
+ * - Shopify: fulfillmentStatus (FULFILLED, UNFULFILLED, etc.)
47
+ * - Medusa: fulfillment_status
48
+ * - WooCommerce: Derived from order status
49
+ * - Magento: shipping_status
50
+ */
51
+ export type FulfillmentStatus =
52
+ | 'unfulfilled'
53
+ | 'partially_fulfilled'
54
+ | 'fulfilled'
55
+ | 'returned';
56
+
57
+ /**
58
+ * Order line item
59
+ *
60
+ * Universal format for order items across platforms.
61
+ */
62
+ export interface OrderItem {
63
+ id: string;
64
+ title: string; // Product title
65
+ variantTitle?: string; // Variant title (e.g., "Large / Red")
66
+ quantity: number;
67
+ price: Money; // Unit price
68
+ total: Money; // Line total (quantity * price)
69
+ sku?: string;
70
+ image?: Image;
71
+
72
+ // Product references
73
+ productId?: string;
74
+ variantId?: string;
75
+ }
76
+
77
+ /**
78
+ * Order
79
+ *
80
+ * Universal format compatible with:
81
+ * - Shopify: Order (Storefront API)
82
+ * - Medusa: StoreOrder (v2)
83
+ * - WooCommerce: Order (REST API)
84
+ * - Magento: Order (GraphQL)
85
+ */
86
+ export interface Order {
87
+ id: string;
88
+ orderNumber: string; // Human-readable order number (e.g., "#1000", "727")
89
+ email: string;
90
+
91
+ // Status (3 separate statuses for granular control)
92
+ status: OrderStatus;
93
+ paymentStatus: PaymentStatus;
94
+ fulfillmentStatus: FulfillmentStatus;
95
+
96
+ // Customer
97
+ customerId?: string;
98
+ customer?: Customer;
99
+
100
+ // Items
101
+ items: OrderItem[];
102
+
103
+ // Pricing
104
+ subtotal: Money;
105
+ total: Money;
106
+ tax?: Money;
107
+ shipping?: Money;
108
+ discount?: Money; // Total discount applied
109
+
110
+ // Addresses
111
+ shippingAddress?: Address;
112
+ billingAddress?: Address;
113
+
114
+ // Dates
115
+ createdAt: string; // ISO 8601 timestamp
116
+ updatedAt: string;
117
+ completedAt?: string; // When order was completed/fulfilled
118
+ cancelledAt?: string; // When order was cancelled
119
+
120
+ // Draft status
121
+ isDraft?: boolean; // True if this is a draft order (not yet completed or placed)
122
+
123
+ // Platform-specific extensions
124
+ metadata?: Record<string, unknown>;
125
+ }
126
+
127
+ /**
128
+ * Custom fetcher callback for advanced order queries.
129
+ *
130
+ * When provided, this callback replaces the default SDK logic entirely.
131
+ * Useful for: custom API endpoints, backend-specific filters, Module Link queries.
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Custom endpoint that filters orders by channel server-side
136
+ * const customFetcher = async (options: GetOrdersOptions) => {
137
+ * const response = await fetch(
138
+ * `/api/admin/sales-channels/${options.salesChannelId}/orders`
139
+ * );
140
+ * return response.json();
141
+ * };
142
+ *
143
+ * const orders = await provider.getOrders({
144
+ * salesChannelId: 'sc_123',
145
+ * customFetcher,
146
+ * });
147
+ * ```
148
+ */
149
+ export type GetOrdersCallback = (options: GetOrdersOptions) => Promise<Order[]>;
150
+
151
+ /**
152
+ * Options for querying a list of orders.
153
+ *
154
+ * Used by CommerceProvider.getOrders() and admin list endpoints.
155
+ */
156
+ export interface GetOrdersOptions {
157
+ /** Customer ID to filter orders by */
158
+ customerId?: string;
159
+ /** Maximum number of results */
160
+ limit?: number;
161
+ /** Zero-based offset for pagination */
162
+ offset?: number;
163
+ /**
164
+ * Filter orders to a specific sales channel.
165
+ *
166
+ * When set, only orders whose `metadata.sales_channel_id` matches
167
+ * this value are returned. Enables multi-tenant isolation.
168
+ *
169
+ * If omitted, orders are returned unfiltered (admin view).
170
+ */
171
+ salesChannelId?: string;
172
+ /**
173
+ * Custom fetcher callback (optional).
174
+ *
175
+ * When provided, this callback is invoked instead of the default SDK logic.
176
+ * Allows backends to implement custom filters, Module Link queries, or
177
+ * call alternative endpoints (e.g., `/api/admin/sales-channels/{id}/orders`).
178
+ *
179
+ * This option enables:
180
+ * - **Medusa Module Link**: Query orders via custom module API
181
+ * - **Custom endpoints**: Call `/api/admin/sales-channels/{id}/orders` for server-side filtering
182
+ * - **Backend-specific optimizations**: Shopify/WooCommerce adapters can implement their own logic
183
+ *
184
+ * @default undefined (uses default SDK + in-memory filter)
185
+ * @see {@link GetOrdersCallback} for callback signature
186
+ */
187
+ customFetcher?: GetOrdersCallback;
188
+ }