@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,46 @@
1
+ /**
2
+ * Site Config Metadata Types
3
+ *
4
+ * Defines the structure for versioned site configuration storage.
5
+ * Uses Stripe-style date-based versioning for configuration history.
6
+ * Stored in backend metadata (no separate database).
7
+ *
8
+ * @module admin/SiteConfigMetadata
9
+ */
10
+
11
+ import type { SiteConfig } from '../site-config';
12
+
13
+ /**
14
+ * Configuration History Entry
15
+ */
16
+ export interface ConfigHistoryEntry {
17
+ /** Version identifier (date-based: YYYY-MM-DD) */
18
+ version: string;
19
+
20
+ /** The site configuration at this version */
21
+ config: SiteConfig;
22
+
23
+ /** ISO 8601 timestamp when this version was created */
24
+ createdAt: string;
25
+
26
+ /** Admin ID who created this version (for future RBAC) */
27
+ createdBy?: string;
28
+ }
29
+
30
+ /**
31
+ * Site Configuration Metadata
32
+ *
33
+ * @remarks
34
+ * Stored in backend metadata field (e.g., sales_channel.metadata['site_config'])
35
+ * Uses date-based versioning inspired by Stripe API versioning
36
+ */
37
+ export interface SiteConfigMetadata {
38
+ /** Current version (date-based: YYYY-MM-DD) */
39
+ version: string;
40
+
41
+ /** The current active site configuration */
42
+ config: SiteConfig;
43
+
44
+ /** Configuration history (last 10 versions) */
45
+ history?: ConfigHistoryEntry[];
46
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Admin Types
3
+ *
4
+ * Central export point for all admin-related types.
5
+ *
6
+ * @module admin
7
+ */
8
+
9
+ export * from './AdminUser';
10
+ export * from './AuditLog';
11
+ export * from './DashboardConfig';
12
+ export * from './DashboardMetrics';
13
+ export * from './SiteConfigMetadata';
package/src/auth.ts ADDED
@@ -0,0 +1,267 @@
1
+ /**
2
+ * @fileoverview Authentication types for Thor Commerce adapters
3
+ * @module @thorprovider/adapters/types/auth
4
+ *
5
+ * Framework-agnostic authentication types that work across all commerce providers.
6
+ * Follows Thor Commerce principles: decoupling, agnostic configuration.
7
+ */
8
+
9
+ import type { Customer, Address } from './customer';
10
+
11
+ /**
12
+ * Authentication method configuration
13
+ */
14
+ export type AuthMethod = 'jwt' | 'session';
15
+
16
+ /**
17
+ * Authentication storage strategy
18
+ */
19
+ export type AuthStorage = 'cookie' | 'localStorage' | 'sessionStorage' | 'memory';
20
+
21
+ /**
22
+ * Authentication configuration
23
+ */
24
+ export interface AuthConfig {
25
+ /**
26
+ * Authentication method to use
27
+ * - 'jwt': JWT token in Authorization header (good for mobile, SPAs)
28
+ * - 'session': Cookie-based session (good for server-side rendering)
29
+ */
30
+ method: AuthMethod;
31
+
32
+ /**
33
+ * Where to store authentication tokens/session
34
+ * - 'cookie': Browser cookies (automatic with fetch)
35
+ * - 'localStorage': Browser localStorage (manual management)
36
+ * - 'sessionStorage': Browser sessionStorage (clears on tab close)
37
+ * - 'memory': In-memory only (for server-side or testing)
38
+ */
39
+ storage: AuthStorage;
40
+
41
+ /**
42
+ * Custom storage implementation (optional)
43
+ * Useful for React Native or non-browser environments
44
+ */
45
+ customStorage?: {
46
+ getItem: (key: string) => Promise<string | null> | string | null;
47
+ setItem: (key: string, value: string) => Promise<void> | void;
48
+ removeItem: (key: string) => Promise<void> | void;
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Login credentials for email/password authentication
54
+ */
55
+ export interface LoginCredentials {
56
+ email: string;
57
+ password: string;
58
+ }
59
+
60
+ /**
61
+ * Registration data for new customer
62
+ */
63
+ export interface RegisterData {
64
+ email: string;
65
+ password: string;
66
+ first_name: string;
67
+ last_name: string;
68
+ phone?: string;
69
+ }
70
+
71
+ /**
72
+ * Authentication response from login/register
73
+ */
74
+ export interface AuthResponse {
75
+ /**
76
+ * JWT token (if using JWT authentication)
77
+ */
78
+ token?: string;
79
+
80
+ /**
81
+ * Customer object (if registration was successful)
82
+ */
83
+ customer?: Customer;
84
+
85
+ /**
86
+ * Whether authentication requires additional steps (e.g., OAuth)
87
+ */
88
+ requiresAction?: boolean;
89
+
90
+ /**
91
+ * Redirect URL for OAuth flows
92
+ */
93
+ redirectUrl?: string;
94
+ }
95
+
96
+ /**
97
+ * Authentication response (used internally by providers)
98
+ */
99
+ export interface AuthResponse {
100
+ customer?: Customer;
101
+ token?: string;
102
+ }
103
+
104
+ // Re-export Customer type for convenience
105
+ export type { Customer };
106
+
107
+ /**
108
+ * Update customer data
109
+ */
110
+ export interface UpdateCustomerData {
111
+ first_name?: string;
112
+ last_name?: string;
113
+ phone?: string | null;
114
+ email?: string;
115
+ password?: string;
116
+ metadata?: Record<string, unknown>;
117
+ }
118
+
119
+ /**
120
+ * Create address data (camelCase for universal compatibility)
121
+ */
122
+ export interface CreateAddressData {
123
+ firstName: string;
124
+ lastName: string;
125
+ company?: string;
126
+ address1: string;
127
+ address2?: string;
128
+ city: string;
129
+ province?: string;
130
+ postalCode: string;
131
+ countryCode: string;
132
+ phone?: string;
133
+ metadata?: Record<string, unknown>;
134
+ }
135
+
136
+ /**
137
+ * Password reset request
138
+ */
139
+ export interface PasswordResetRequest {
140
+ email: string;
141
+ }
142
+
143
+ /**
144
+ * Password reset confirmation
145
+ */
146
+ export interface PasswordResetConfirm {
147
+ token: string;
148
+ password: string;
149
+ }
150
+
151
+ /**
152
+ * Authentication provider interface
153
+ *
154
+ * All commerce providers must implement this interface to support authentication.
155
+ * This enables framework-agnostic auth across Medusa, Shopify, WooCommerce, etc.
156
+ */
157
+ export interface AuthProvider {
158
+ // ========================================
159
+ // Authentication Methods
160
+ // ========================================
161
+
162
+ /**
163
+ * Login customer with email and password
164
+ * @param credentials - Email and password
165
+ * @returns Authentication response with token/customer
166
+ */
167
+ login(credentials: LoginCredentials): Promise<AuthResponse>;
168
+
169
+ /**
170
+ * Register new customer
171
+ * @param data - Registration data
172
+ * @returns Authentication response
173
+ */
174
+ register(data: RegisterData): Promise<AuthResponse>;
175
+
176
+ /**
177
+ * Logout current customer
178
+ * Clears authentication token/session
179
+ */
180
+ logout(): Promise<void>;
181
+
182
+ // ========================================
183
+ // Password Management
184
+ // ========================================
185
+
186
+ /**
187
+ * Request password reset email
188
+ * @param email - Customer email
189
+ */
190
+ requestPasswordReset(email: string): Promise<void>;
191
+
192
+ /**
193
+ * Reset password with token
194
+ * @param token - Password reset token from email (provider-specific format)
195
+ * @param password - New password
196
+ * @param metadata - Optional metadata for provider-specific requirements
197
+ */
198
+ resetPassword(token: string, password: string, metadata?: Record<string, unknown>): Promise<void>;
199
+
200
+ // ========================================
201
+ // Session Management
202
+ // ========================================
203
+
204
+ /**
205
+ * Get current authenticated customer
206
+ * @returns Customer object or null if not authenticated
207
+ */
208
+ getCurrentCustomer(): Promise<Customer | null>;
209
+
210
+ /**
211
+ * Update current customer profile
212
+ * @param data - Fields to update
213
+ * @returns Updated customer
214
+ */
215
+ updateCustomer(data: UpdateCustomerData): Promise<Customer>;
216
+
217
+ /**
218
+ * Check if customer is authenticated
219
+ * @returns true if authenticated, false otherwise
220
+ */
221
+ isAuthenticated(): Promise<boolean>;
222
+
223
+ /**
224
+ * Get current authentication token (if using JWT)
225
+ * @returns JWT token or null
226
+ */
227
+ getAuthToken(): string | null;
228
+
229
+ /**
230
+ * Delete current customer account
231
+ *
232
+ * WARNING: This is a permanent action and cannot be undone.
233
+ * Only implemented if capabilities.deleteAccount is true.
234
+ */
235
+ deleteCustomerAccount(): Promise<void>;
236
+
237
+ // ========================================
238
+ // Address Management
239
+ // ========================================
240
+
241
+ /**
242
+ * Get customer addresses
243
+ * @returns List of customer addresses
244
+ */
245
+ getAddresses(): Promise<Address[]>;
246
+
247
+ /**
248
+ * Create new address for current customer
249
+ * @param data - Address data
250
+ * @returns Created address
251
+ */
252
+ createAddress(data: CreateAddressData): Promise<Address>;
253
+
254
+ /**
255
+ * Update customer address
256
+ * @param addressId - Address ID
257
+ * @param data - Fields to update
258
+ * @returns Updated address
259
+ */
260
+ updateAddress(addressId: string, data: Partial<CreateAddressData>): Promise<Address>;
261
+
262
+ /**
263
+ * Delete customer address
264
+ * @param addressId - Address ID
265
+ */
266
+ deleteAddress(addressId: string): Promise<void>;
267
+ }
package/src/cart.ts ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @thorprovider/adapters v2.0
3
+ * Cart types - unified interface for all commerce providers
4
+ */
5
+
6
+ import type { Image, Money } from './common';
7
+ import type { SelectedOption } from './product';
8
+ import type { FulfillmentOption, StockStatus, StockValidation } from './stock-location';
9
+
10
+ /**
11
+ * Product reference in cart
12
+ */
13
+ export interface CartProduct {
14
+ id: string;
15
+ handle: string;
16
+ title: string;
17
+ featuredImage: Image;
18
+ }
19
+
20
+ /**
21
+ * Cart line item
22
+ */
23
+ export interface CartItem {
24
+ id: string | undefined;
25
+ quantity: number;
26
+ stockStatus?: StockStatus;
27
+ cost: {
28
+ totalAmount: Money;
29
+ };
30
+ merchandise: {
31
+ id: string;
32
+ title: string;
33
+ selectedOptions: SelectedOption[];
34
+ product: CartProduct;
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Cart cost breakdown
40
+ */
41
+ export interface CartCost {
42
+ subtotalAmount: Money;
43
+ totalAmount: Money;
44
+ totalTaxAmount?: Money;
45
+ }
46
+
47
+ /**
48
+ * Shipping method option
49
+ * Used during checkout to display available shipping methods
50
+ */
51
+ export interface ShippingMethod {
52
+ /** Unique identifier for the shipping method */
53
+ id: string;
54
+
55
+ /** Display name (e.g., 'Standard Shipping', 'Express') */
56
+ name: string;
57
+
58
+ /** Price for this shipping method */
59
+ price: Money;
60
+
61
+ /** Optional description */
62
+ description?: string;
63
+
64
+ /** Estimated delivery time (e.g., '3-5 business days') */
65
+ estimatedDays?: string;
66
+ }
67
+
68
+ /**
69
+ * Main cart type - normalized across all providers
70
+ */
71
+ export interface Cart {
72
+ id: string | undefined;
73
+ checkoutUrl: string;
74
+ cost: CartCost;
75
+ lines: CartItem[];
76
+ totalQuantity: number;
77
+ fulfillmentOptions?: FulfillmentOption[];
78
+ stockValidation?: StockValidation;
79
+ /** ISO timestamp when cart was completed/converted to order (undefined if active) */
80
+ completedAt?: string;
81
+ }
82
+
83
+ /**
84
+ * Input for adding items to cart
85
+ */
86
+ export interface CartLineInput {
87
+ merchandiseId: string;
88
+ quantity: number;
89
+ }
90
+
91
+ /**
92
+ * Input for updating cart items
93
+ */
94
+ export interface CartLineUpdate {
95
+ id: string;
96
+ merchandiseId: string;
97
+ quantity: number;
98
+ }
99
+
100
+ /**
101
+ * Discount code applied to the cart
102
+ *
103
+ * Universal format for discount/promo codes across all providers.
104
+ * Adapters transform platform-specific discount formats to this interface.
105
+ */
106
+ export interface DiscountCode {
107
+ /** Discount code string (e.g., "SUMMER2024") */
108
+ code: string;
109
+
110
+ /** Discount value (amount or percentage) */
111
+ value: number;
112
+
113
+ /** Whether the value is a percentage (true) or fixed amount (false) */
114
+ isPercentage: boolean;
115
+
116
+ /** Human-readable description of the discount */
117
+ description?: string;
118
+
119
+ /** Minimum purchase amount required */
120
+ minimumAmount?: Money;
121
+
122
+ /** Expiration date */
123
+ expiresAt?: Date;
124
+
125
+ /** Maximum number of uses allowed */
126
+ maxUses?: number;
127
+
128
+ /** Current number of times this code has been used */
129
+ usageCount?: number;
130
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @thorprovider/types v2.0
3
+ * Product Category types - unified interface for all commerce providers
4
+ */
5
+
6
+ /**
7
+ * Product category (hierarchical taxonomy)
8
+ */
9
+ export interface ProductCategory {
10
+ /** Unique identifier */
11
+ id: string;
12
+ /** Category name */
13
+ name: string;
14
+ /** URL-safe handle/slug */
15
+ handle: string;
16
+ /** Category description */
17
+ description?: string;
18
+ /** Parent category ID (null for root categories) */
19
+ parentCategoryId?: string;
20
+ /** Number of products in category */
21
+ productCount?: number;
22
+ /** Category image URL */
23
+ image?: string;
24
+ /** Metadata */
25
+ metadata?: Record<string, any>;
26
+ }
27
+
28
+ /**
29
+ * Custom fetcher callback for advanced category queries.
30
+ *
31
+ * When provided, this callback replaces the default SDK logic entirely.
32
+ * Useful for: custom API endpoints, backend-specific filters, Module Link queries.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Custom endpoint that filters categories by channel server-side
37
+ * const customFetcher = async (options: GetCategoriesOptions) => {
38
+ * const response = await fetch(`/api/admin/sales-channels/${options.salesChannelId}/categories`);
39
+ * return response.json();
40
+ * };
41
+ *
42
+ * const categories = await provider.getCategories({
43
+ * salesChannelId: 'sc_123',
44
+ * customFetcher,
45
+ * });
46
+ * ```
47
+ */
48
+ export type GetCategoriesCallback = (options: GetCategoriesOptions) => Promise<ProductCategory[]>;
49
+
50
+ /**
51
+ * Options for fetching categories
52
+ */
53
+ export interface GetCategoriesOptions {
54
+ /** Include child categories */
55
+ includeDescendants?: boolean;
56
+ /** Parent category ID to filter by */
57
+ parentCategoryId?: string;
58
+ /** Maximum number of categories to return */
59
+ limit?: number;
60
+ /** Search query to filter categories by name/handle */
61
+ query?: string;
62
+ /**
63
+ * Scope results to a specific sales channel / storefront channel.
64
+ * When provided, only categories that contain at least one product available
65
+ * in the given channel will be returned.
66
+ *
67
+ * Maps to: Medusa `sales_channel_id`, Shopify Sales Channel, etc.
68
+ * Adapters that support native server-side filtering should prefer it;
69
+ * others may fall back to a client-side post-filter pass.
70
+ */
71
+ salesChannelId?: string;
72
+ /**
73
+ * Custom fetcher callback (optional).
74
+ *
75
+ * When provided, this callback is invoked instead of the default SDK logic.
76
+ * Allows backends to implement custom filters, Module Link queries, or
77
+ * call alternative endpoints (e.g., `/api/admin/sales-channels/{id}/categories`).
78
+ *
79
+ * This option enables:
80
+ * - **Medusa Module Link**: Query categories via custom module API
81
+ * - **Custom endpoints**: Call `/api/admin/sales-channels/{id}/categories` for server-side filtering
82
+ * - **Backend-specific optimizations**: Shopify/WooCommerce adapters can implement their own logic
83
+ *
84
+ * @default undefined (uses default SDK + in-memory filter)
85
+ * @see {@link GetCategoriesCallback} for callback signature
86
+ */
87
+ customFetcher?: GetCategoriesCallback;
88
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @thorprovider/adapters v2.0
3
+ * Collection types - unified interface for all commerce providers
4
+ */
5
+
6
+ import type { SEO } from './common';
7
+
8
+ /**
9
+ * Product collection/category
10
+ */
11
+ export interface Collection {
12
+ id: string;
13
+ handle: string;
14
+ title: string;
15
+ description: string;
16
+ seo?: SEO;
17
+ path: string;
18
+ updatedAt: string;
19
+ }
20
+
21
+ /**
22
+ * Options for fetching collections
23
+ */
24
+ export interface GetCollectionsOptions {
25
+ /** Maximum number of collections to return */
26
+ limit?: number;
27
+ /** Search query to filter collections by title */
28
+ query?: string;
29
+ }
30
+
31
+ /**
32
+ * Options for fetching collection products
33
+ */
34
+ export interface CollectionProductsOptions {
35
+ sortKey?: string;
36
+ reverse?: boolean;
37
+ first?: number;
38
+ after?: string;
39
+ }