@thorprovider/adapters 3.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.
- package/.turbo/turbo-build.log +18 -0
- package/.turbo/turbo-test.log +1 -0
- package/.turbo/turbo-type-check.log +0 -0
- package/AGENTS.md +1 -0
- package/CHANGELOG.md +271 -0
- package/README.md +634 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.mts +2524 -0
- package/dist/index.d.ts +2524 -0
- package/dist/index.js +8136 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8045 -0
- package/dist/index.mjs.map +1 -0
- package/docs/RETRY_SOLUTION_SUMMARY.md +55 -0
- package/docs/authentication.md +165 -0
- package/docs/capabilities-system.md +143 -0
- package/docs/category-customization.md +309 -0
- package/docs/fetch-reliability-solution.md +399 -0
- package/docs/getting-started.md +154 -0
- package/docs/multi-tenant-channel-scoping.md +225 -0
- package/docs/profile-management.md +147 -0
- package/docs/providers-overview.md +85 -0
- package/docs/services-overview.md +135 -0
- package/docs/update-documentation.md +113 -0
- package/package.json +43 -0
- package/publish.log +93 -0
- package/quick-reference.md +169 -0
- package/src/admin/AdminAuthService.ts +88 -0
- package/src/admin/AdminSessionService.ts +91 -0
- package/src/admin/MetricsService.ts +145 -0
- package/src/admin/index.ts +13 -0
- package/src/backend/BackendMetadataAdapter.ts +88 -0
- package/src/backend/factory.ts +107 -0
- package/src/backend/index.ts +12 -0
- package/src/backend/medusa/MedusaMetadataAdapter.ts +139 -0
- package/src/core/errors.js +161 -0
- package/src/core/errors.ts +132 -0
- package/src/core/fetch-utils.js +240 -0
- package/src/core/fetch-utils.ts +227 -0
- package/src/core/index.ts +8 -0
- package/src/core/logger.js +63 -0
- package/src/core/logger.ts +37 -0
- package/src/factory/index.ts +102 -0
- package/src/index.ts +205 -0
- package/src/lib/money-transform.ts +80 -0
- package/src/metadata/channel-scope-validation.js +136 -0
- package/src/metadata/channel-scope-validation.ts +151 -0
- package/src/metadata/channel-scope.js +174 -0
- package/src/metadata/channel-scope.ts +215 -0
- package/src/metadata/index.js +31 -0
- package/src/metadata/index.ts +37 -0
- package/src/providers/bigcommerce/bigcommerce.ts +6 -0
- package/src/providers/bigcommerce/index.ts +315 -0
- package/src/providers/bigcommerce/transforms.ts +227 -0
- package/src/providers/index.ts +22 -0
- package/src/providers/magento/index.ts +387 -0
- package/src/providers/magento/magento.ts +5 -0
- package/src/providers/magento/queries.ts +267 -0
- package/src/providers/magento/transforms.ts +249 -0
- package/src/providers/medusa/auth.js +601 -0
- package/src/providers/medusa/auth.ts +496 -0
- package/src/providers/medusa/fulfillment-planner.ts +225 -0
- package/src/providers/medusa/index.js +2485 -0
- package/src/providers/medusa/index.ts +4239 -0
- package/src/providers/medusa/medusa.ts +8 -0
- package/src/providers/medusa/payment.js +265 -0
- package/src/providers/medusa/payment.ts +269 -0
- package/src/providers/medusa/transforms.js +505 -0
- package/src/providers/medusa/transforms.ts +625 -0
- package/src/providers/shopify/index.ts +444 -0
- package/src/providers/shopify/mutations.ts +102 -0
- package/src/providers/shopify/queries.ts +324 -0
- package/src/providers/shopify/shopify.ts +7 -0
- package/src/providers/shopify/transforms.ts +270 -0
- package/src/providers/spree/index.ts +344 -0
- package/src/providers/spree/spree.ts +5 -0
- package/src/providers/spree/transforms.ts +254 -0
- package/src/providers/woocommerce/index.ts +310 -0
- package/src/providers/woocommerce/transforms.ts +254 -0
- package/src/providers/woocommerce/woocommerce.ts +5 -0
- package/src/resilience/README.md +299 -0
- package/src/resilience/circuit-breaker.ts +222 -0
- package/src/resilience/index.ts +10 -0
- package/src/types/capabilities.types.js +141 -0
- package/src/types/capabilities.types.ts +366 -0
- package/src/types/index.ts +24 -0
- package/src/types/provider.js +9 -0
- package/src/types/provider.ts +9 -0
- package/src/types/ui-responses.ts +261 -0
- package/src/utils/city-coordinates.ts +40 -0
- package/src/utils/geolocation.ts +52 -0
- package/src/utils/payment-utils.js +152 -0
- package/src/utils/payment-utils.ts +203 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +14 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
CLI Building entry: {"index":"src/index.ts"}
|
|
2
|
+
CLI Using tsconfig: tsconfig.json
|
|
3
|
+
CLI tsup v8.5.1
|
|
4
|
+
CLI Using tsup config: /home/nelson/dev/thorprovider/repos/thorcommerce/packages/adapters/tsup.config.ts
|
|
5
|
+
CLI Target: esnext
|
|
6
|
+
CLI Cleaning output folder
|
|
7
|
+
CJS Build start
|
|
8
|
+
ESM Build start
|
|
9
|
+
ESM dist/index.mjs 270.54 KB
|
|
10
|
+
ESM dist/index.mjs.map 550.94 KB
|
|
11
|
+
ESM ⚡️ Build success in 118ms
|
|
12
|
+
CJS dist/index.js 275.05 KB
|
|
13
|
+
CJS dist/index.js.map 551.29 KB
|
|
14
|
+
CJS ⚡️ Build success in 118ms
|
|
15
|
+
DTS Build start
|
|
16
|
+
DTS ⚡️ Build success in 3591ms
|
|
17
|
+
DTS dist/index.d.ts 88.39 KB
|
|
18
|
+
DTS dist/index.d.mts 88.39 KB
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
command not found: jest
|
|
File without changes
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!-- ADAPTERS-AGENTS-MD-START -->[@thorprovider/adapters Docs]|root: ./adapters|CRITICAL: Framework-agnostic business logic only. Never import Next.js or React. Check IMPORT_GUIDE.md for proper usage patterns.|To regenerate: yarn workspace @thorprovider/adapters generate:agent-index|.:{README.md,quick-reference.md}|docs:{RETRY_SOLUTION_SUMMARY.md,authentication.md,capabilities-system.md,category-customization.md,fetch-reliability-solution.md,getting-started.md,multi-tenant-channel-scoping.md,profile-management.md,providers-overview.md,services-overview.md,update-documentation.md}|src/resilience:{README.md}<!-- ADAPTERS-AGENTS-MD-END -->
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Automate package publishing with Changesets PR pattern and changeset-bot
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @thorprovider/types@2.0.2
|
|
10
|
+
|
|
11
|
+
## 3.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 377a7b4: Fix package publishing to GitHub Packages registry
|
|
16
|
+
- Updated dependencies [377a7b4]
|
|
17
|
+
- @thorprovider/types@2.0.1
|
|
18
|
+
|
|
19
|
+
## 3.0.0
|
|
20
|
+
|
|
21
|
+
### Major Changes
|
|
22
|
+
|
|
23
|
+
- c6ea482: Primera publicación de packages
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- d16d400: Initial publish of Thor Commerce packages to GitHub Packages registry.
|
|
28
|
+
- Updated dependencies [d16d400]
|
|
29
|
+
- Updated dependencies [c6ea482]
|
|
30
|
+
- @thorprovider/types@2.0.0
|
|
31
|
+
|
|
32
|
+
All notable changes to this project will be documented in this file.
|
|
33
|
+
|
|
34
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
35
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
36
|
+
|
|
37
|
+
## [Unreleased]
|
|
38
|
+
|
|
39
|
+
### Fixed - Completed Cart Detection
|
|
40
|
+
|
|
41
|
+
- **Cart type**: Added `completedAt?: string` field to Cart interface to track when a cart is converted to an order.
|
|
42
|
+
- **Medusa transform**: Updated `transformCart()` to include `completed_at` timestamp from Medusa backend.
|
|
43
|
+
- **Prevents errors**: Fixes "Cart already completed" errors when users attempt additional purchases after checkout.
|
|
44
|
+
|
|
45
|
+
### Fixed - Medusa v2 Cart Line Item Pricing
|
|
46
|
+
|
|
47
|
+
- **Cart line totals**: Fixed cart line item totals defaulting to `0` when Medusa doesn't return expanded totals fields.
|
|
48
|
+
- **Currency consistency**: Cart line items now inherit `currency_code` from the cart, preventing mixed-currency UI rendering.
|
|
49
|
+
- **Fallback behavior**: When line totals are missing, adapters compute line totals as `unit_price × quantity`.
|
|
50
|
+
|
|
51
|
+
### Fixed - Shipping Options Endpoint (Checkout)
|
|
52
|
+
|
|
53
|
+
- **Medusa v2 shipping methods**: Switched from the non-existent `/store/fulfillment/cart-options` call to the official `/store/shipping-options?cart_id=...` endpoint.
|
|
54
|
+
- **Compatibility**: Uses `sdk.store.shippingOption.list` when available, with an HTTP fallback for SDK versions that don't expose it.
|
|
55
|
+
|
|
56
|
+
### Added - Checkout Payment Session & Billing Address Support
|
|
57
|
+
|
|
58
|
+
**🎯 CRITICAL FIX:** Payment session creation now works correctly with Medusa v2
|
|
59
|
+
|
|
60
|
+
#### Payment Session Fix
|
|
61
|
+
|
|
62
|
+
- **Payment Collection Fields**: Added `payment_collection` fields to cart query to prevent HTTP 500 errors
|
|
63
|
+
- **Idempotent Session Creation**: Payment session creation now idempotent (no duplicate sessions)
|
|
64
|
+
- **Proper Error Handling**: Better error messages when payment session fails
|
|
65
|
+
- **Fields Added**: `payment_session.id`, `payment_session.status`, `payment_session.provider_id`, `payment_session.amount`
|
|
66
|
+
|
|
67
|
+
#### Billing Address Support
|
|
68
|
+
|
|
69
|
+
- **`updateBillingAddress(cartId, address)`**: New method in `CommerceProvider` interface
|
|
70
|
+
- **Medusa Implementation**: Updates cart billing address via Medusa SDK before payment session creation
|
|
71
|
+
- **Step 0.5**: Called automatically before payment session creation in checkout flow
|
|
72
|
+
- **Required by Medusa**: Billing address MUST be set before creating payment collection
|
|
73
|
+
|
|
74
|
+
#### CommerceProvider Interface Updates
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
interface CommerceProvider {
|
|
78
|
+
// ... existing methods
|
|
79
|
+
|
|
80
|
+
// NEW: Update billing address before payment session
|
|
81
|
+
updateBillingAddress(cartId: string, address: BillingAddress): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### Implementation Details
|
|
86
|
+
|
|
87
|
+
- `MedusaCartProvider.updateCart()`: Now includes payment_collection in query expansion
|
|
88
|
+
- `MedusaCommerceProvider.updateBillingAddress()`: Medusa SDK implementation
|
|
89
|
+
- **Architecture**: L2 (Adapters) - Framework-agnostic business logic
|
|
90
|
+
|
|
91
|
+
#### Impact
|
|
92
|
+
|
|
93
|
+
- Fixes HTTP 500 error when creating payment session without billing address
|
|
94
|
+
- Enables proper checkout flow with Medusa v2 backend
|
|
95
|
+
- Required for CheckoutModule payment step to work correctly
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## [2.0.0] - 2026-02-05
|
|
100
|
+
|
|
101
|
+
### Added - Backend Capability Detection System
|
|
102
|
+
|
|
103
|
+
**🎯 NEW:** Backend capability detection system for adaptive UI
|
|
104
|
+
|
|
105
|
+
#### Capabilities System
|
|
106
|
+
|
|
107
|
+
- **`BackendCapabilities` Interface**: 21 capability flags for profile, orders, cart, payments, etc.
|
|
108
|
+
- **Provider Capabilities**: Each provider declares its capabilities in `readonly capabilities` property
|
|
109
|
+
- **Type-Safe Checks**: Full TypeScript inference for capability checking
|
|
110
|
+
- **Constant Exports**: `MEDUSA_CAPABILITIES`, `SHOPIFY_CAPABILITIES` for direct import
|
|
111
|
+
|
|
112
|
+
#### Profile Management Capabilities
|
|
113
|
+
|
|
114
|
+
- `updateProfile`: Update name/phone (Medusa: ✅, Shopify: ✅)
|
|
115
|
+
- `updateEmail`: Change email address (Medusa: ❌, Shopify: ✅)
|
|
116
|
+
- `changePasswordDirect`: Direct password change (Medusa: ❌, Shopify: ✅)
|
|
117
|
+
- `changePasswordViaEmail`: Password reset via email (Medusa: ✅, Shopify: ✅)
|
|
118
|
+
- `deleteAccount`: Self-service account deletion (Medusa: ❌, Shopify: ❌)
|
|
119
|
+
- `uploadAvatar`: Native avatar upload API (Medusa: ❌, Shopify: ❌)
|
|
120
|
+
- `avatarViaMetadata`: Store avatar URL in metadata (Medusa: ✅, Shopify: ✅)
|
|
121
|
+
- `customAttributes`: Custom customer attributes (Medusa: ✅, Shopify: ✅)
|
|
122
|
+
|
|
123
|
+
#### Additional Capabilities (21 total)
|
|
124
|
+
|
|
125
|
+
- **Orders**: `fetchOrders`, `cancelOrder`
|
|
126
|
+
- **Addresses**: `manageAddresses`, `defaultAddress`
|
|
127
|
+
- **Cart**: `applyDiscounts`, `shippingCalculation`
|
|
128
|
+
- **Payment**: `guestCheckout`, `savedPaymentMethods`
|
|
129
|
+
- **Features**: `wishlist`, `advancedSearch`, `facetedFilters`, `productReviews`, `loyaltyProgram`
|
|
130
|
+
|
|
131
|
+
#### CommerceProvider Extension
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface CommerceProvider {
|
|
135
|
+
readonly name: string;
|
|
136
|
+
readonly version: string;
|
|
137
|
+
readonly capabilities: BackendCapabilities; // NEW!
|
|
138
|
+
// ... existing methods
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Utility Functions
|
|
143
|
+
|
|
144
|
+
- `isBackendCapabilities(obj)`: Type guard
|
|
145
|
+
- `getCapabilityDescription(capability)`: Human-readable descriptions
|
|
146
|
+
|
|
147
|
+
#### Documentation
|
|
148
|
+
|
|
149
|
+
- `types/capabilities.types.ts` - Complete capability definitions with JSDoc
|
|
150
|
+
- Backend comparison matrix (Medusa, Shopify)
|
|
151
|
+
- Usage examples for adaptive UI
|
|
152
|
+
|
|
153
|
+
### Changed
|
|
154
|
+
|
|
155
|
+
- **`CommerceProvider` interface**: Added `capabilities` property
|
|
156
|
+
- **`MedusaProvider`**: Now includes `MEDUSA_CAPABILITIES`
|
|
157
|
+
- **Exports**: Added capability types and constants to main index
|
|
158
|
+
|
|
159
|
+
### Use Cases
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Check capabilities at runtime
|
|
163
|
+
if (commerce.capabilities.updateEmail) {
|
|
164
|
+
return <EmailField />;
|
|
165
|
+
} else {
|
|
166
|
+
return <EmailField disabled />;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// React hook integration
|
|
170
|
+
const capabilities = useCapabilities();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## [2.0.0-beta] - 2026-02-03
|
|
176
|
+
|
|
177
|
+
### Added - Complete Rewrite
|
|
178
|
+
|
|
179
|
+
**@thorprovider/adapters v2.0** is a complete rewrite from scratch based on Vercel Commerce patterns.
|
|
180
|
+
|
|
181
|
+
#### Core Architecture
|
|
182
|
+
|
|
183
|
+
- **Provider Pattern**: Multi-platform commerce abstraction
|
|
184
|
+
- **Interface-First Design**: `CommerceProvider` interface defines contract
|
|
185
|
+
- **TypeScript Strict**: Full type safety across all operations
|
|
186
|
+
- **Framework Agnostic**: Zero dependencies on React/Next.js
|
|
187
|
+
|
|
188
|
+
#### Type System
|
|
189
|
+
|
|
190
|
+
- Unified types for Product, Cart, Collection, Customer, Order
|
|
191
|
+
- Shared types: Money, Image, SEO, Connection, Edge
|
|
192
|
+
- Provider-specific transforms to normalize responses
|
|
193
|
+
|
|
194
|
+
#### Medusa Provider (v2.11.3)
|
|
195
|
+
|
|
196
|
+
- Complete `CommerceProvider` implementation with 11 methods:
|
|
197
|
+
- **Products**: `getProduct()`, `getProducts()`, `getProductRecommendations()`
|
|
198
|
+
- **Collections**: `getCollection()`, `getCollections()`, `getCollectionProducts()`
|
|
199
|
+
- **Cart**: `createCart()`, `getCart()`, `addToCart()`, `removeFromCart()`, `updateCart()`
|
|
200
|
+
- Transform functions to convert Medusa types to unified types
|
|
201
|
+
- Support for @medusajs/js-sdk v2.11.3
|
|
202
|
+
|
|
203
|
+
#### Developer Experience
|
|
204
|
+
|
|
205
|
+
- Factory pattern: `createProvider({ provider: 'medusa', config: {...} })`
|
|
206
|
+
- Discriminated union types for type-safe configuration
|
|
207
|
+
- Custom error hierarchy: `ProviderAPIError`, `ResourceNotFoundError`, etc.
|
|
208
|
+
- Debug logging with `createLogger()`
|
|
209
|
+
|
|
210
|
+
#### Documentation
|
|
211
|
+
|
|
212
|
+
- Complete README with examples and API reference
|
|
213
|
+
- `examples/basic-usage.ts` - Full usage example
|
|
214
|
+
- `RESEARCH_V2.md` - Architecture decisions and research
|
|
215
|
+
|
|
216
|
+
### Build Output
|
|
217
|
+
|
|
218
|
+
- ✅ CommonJS (`dist/index.js`)
|
|
219
|
+
- ✅ ESM (`dist/index.mjs`)
|
|
220
|
+
- ✅ TypeScript declarations (`dist/index.d.ts`, `dist/index.d.mts`)
|
|
221
|
+
- ✅ Source maps for debugging
|
|
222
|
+
|
|
223
|
+
### Breaking Changes from v0.x
|
|
224
|
+
|
|
225
|
+
This is a **complete rewrite** and is not backwards compatible with v0.x:
|
|
226
|
+
|
|
227
|
+
- ❌ **Removed**: Context-aware exports (client/server splits)
|
|
228
|
+
- ❌ **Removed**: Direct SDK re-exports
|
|
229
|
+
- ✅ **New**: Unified provider interface
|
|
230
|
+
- ✅ **New**: Multi-platform support architecture
|
|
231
|
+
- ✅ **New**: Transform layer for type normalization
|
|
232
|
+
|
|
233
|
+
### Migration Guide
|
|
234
|
+
|
|
235
|
+
**v0.x → v2.0**
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// Before (v0.x)
|
|
239
|
+
import { sdk } from '@thorprovider/adapters/client';
|
|
240
|
+
const products = await sdk.store.product.list();
|
|
241
|
+
|
|
242
|
+
// After (v2.0)
|
|
243
|
+
import { createProvider } from '@thorprovider/adapters';
|
|
244
|
+
const commerce = createProvider({
|
|
245
|
+
provider: 'medusa',
|
|
246
|
+
config: { baseUrl, publishableKey },
|
|
247
|
+
});
|
|
248
|
+
const products = await commerce.getProducts();
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Dependencies
|
|
252
|
+
|
|
253
|
+
- `@medusajs/js-sdk`: ^2.11.3
|
|
254
|
+
- `@medusajs/types`: ^2.11.3
|
|
255
|
+
|
|
256
|
+
### Known Limitations
|
|
257
|
+
|
|
258
|
+
- Only Medusa provider implemented (Shopify, WooCommerce coming in future releases)
|
|
259
|
+
- No cache layer yet (planned for v2.1)
|
|
260
|
+
- No customer operations (login, register) - focus on storefront operations
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## [0.2.0] - Previous Version (Deprecated)
|
|
265
|
+
|
|
266
|
+
Legacy version with context-aware exports. See git history for details.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
[2.0.0]: https://github.com/thorprovider/thor-commerce/compare/v0.2.0...v2.0.0
|
|
271
|
+
[0.2.0]: https://github.com/thorprovider/thor-commerce/releases/tag/v0.2.0
|