@thorprovider/adapters 4.2.1 → 5.0.0
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/PROVIDER_IMPLEMENTATION_ANALYSIS.md +659 -0
- package/dist/index.d.mts +225 -387
- package/dist/index.d.ts +225 -387
- package/dist/index.js +613 -3062
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +609 -3052
- package/dist/index.mjs.map +1 -1
- package/docs/RETRY_SOLUTION_SUMMARY.md +26 -11
- package/docs/authentication.md +115 -62
- package/docs/capabilities-system.md +4 -2
- package/docs/category-customization.md +37 -29
- package/docs/fetch-reliability-solution.md +127 -278
- package/docs/getting-started.md +43 -29
- package/docs/profile-management.md +68 -38
- package/docs/services-overview.md +4 -2
- package/package.json +1 -1
- package/quick-reference.md +33 -0
- package/src/backend/factory.ts +1 -11
- package/src/factory/index.ts +74 -52
- package/src/index.ts +5 -15
- package/src/providers/index.ts +1 -16
- package/src/providers/medusa/admin.test.ts +404 -0
- package/src/providers/medusa/admin.ts +442 -0
- package/src/providers/medusa/auth.test.ts +137 -0
- package/src/providers/medusa/auth.ts +96 -1
- package/src/providers/medusa/index.ts +21 -1
- package/src/resilience/README.md +70 -48
- package/src/types/capabilities.types.ts +0 -250
- package/src/core/errors.js +0 -161
- package/src/core/fetch-utils.js +0 -240
- package/src/core/logger.js +0 -63
- package/src/metadata/channel-scope-validation.js +0 -136
- package/src/metadata/channel-scope.js +0 -174
- package/src/metadata/index.js +0 -31
- package/src/providers/bigcommerce/bigcommerce.ts +0 -6
- package/src/providers/bigcommerce/index.ts +0 -315
- package/src/providers/bigcommerce/transforms.ts +0 -227
- package/src/providers/magento/index.ts +0 -387
- package/src/providers/magento/magento.ts +0 -5
- package/src/providers/magento/queries.ts +0 -267
- package/src/providers/magento/transforms.ts +0 -249
- package/src/providers/medusa/auth.js +0 -601
- package/src/providers/medusa/index.js +0 -2485
- package/src/providers/medusa/payment.js +0 -265
- package/src/providers/medusa/transforms.js +0 -505
- package/src/providers/shopify/auth.ts +0 -402
- package/src/providers/shopify/index.ts +0 -444
- package/src/providers/shopify/mutations.ts +0 -247
- package/src/providers/shopify/queries.ts +0 -324
- package/src/providers/shopify/shopify.ts +0 -7
- package/src/providers/shopify/transforms.ts +0 -275
- package/src/providers/spree/index.ts +0 -344
- package/src/providers/spree/spree.ts +0 -5
- package/src/providers/spree/transforms.ts +0 -254
- package/src/providers/woocommerce/index.ts +0 -310
- package/src/providers/woocommerce/transforms.ts +0 -254
- package/src/providers/woocommerce/woocommerce.ts +0 -5
- package/src/types/capabilities.types.js +0 -141
- package/src/types/provider.js +0 -9
- package/src/utils/payment-utils.js +0 -152
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
# Profile Management
|
|
2
|
-
|
|
3
1
|
---
|
|
2
|
+
title: Profile Management
|
|
3
|
+
purpose: Guide for managing customer profiles using capability-aware patterns for cross-backend compatibility
|
|
4
4
|
type: how-to
|
|
5
5
|
tags: [profile, account, customer, metadata, avatar]
|
|
6
6
|
related:
|
|
7
7
|
- authentication.md
|
|
8
8
|
- capabilities-system.md
|
|
9
9
|
- services-overview.md
|
|
10
|
-
updated: 2026-
|
|
10
|
+
updated: 2026-05-03
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
# Profile Management
|
|
14
|
+
|
|
13
15
|
Guide for managing customer profiles using capability-aware patterns for cross-backend compatibility.
|
|
14
16
|
|
|
15
17
|
## Prerequisites
|
|
16
18
|
|
|
17
19
|
- [Authentication set up](authentication.md)
|
|
18
|
-
- User logged in
|
|
20
|
+
- User logged in (`commerce.auth` available and `isAuthenticated()` returns `true`)
|
|
19
21
|
|
|
20
22
|
## Quick Example
|
|
21
23
|
|
|
22
24
|
```typescript
|
|
23
|
-
import {
|
|
25
|
+
import { createProvider } from '@thorprovider/adapters';
|
|
26
|
+
|
|
27
|
+
const commerce = createProvider({ provider: 'medusa', config: { ... } });
|
|
28
|
+
|
|
29
|
+
if (!commerce.auth) throw new Error('Auth not available');
|
|
24
30
|
|
|
25
31
|
// Simple profile update
|
|
26
32
|
const updated = await commerce.auth.updateCustomer({
|
|
@@ -41,6 +47,10 @@ const { updateEmail, updateProfile, deleteAccount } = commerce.capabilities;
|
|
|
41
47
|
if (updateEmail) {
|
|
42
48
|
// Render email update field
|
|
43
49
|
}
|
|
50
|
+
|
|
51
|
+
if (updateProfile) {
|
|
52
|
+
// Render name/phone fields
|
|
53
|
+
}
|
|
44
54
|
```
|
|
45
55
|
|
|
46
56
|
### Step 2: Retrieve Current Profile
|
|
@@ -48,6 +58,8 @@ if (updateEmail) {
|
|
|
48
58
|
Fetch the customer object to populate your forms.
|
|
49
59
|
|
|
50
60
|
```typescript
|
|
61
|
+
if (!commerce.auth) return;
|
|
62
|
+
|
|
51
63
|
const customer = await commerce.auth.getCurrentCustomer();
|
|
52
64
|
```
|
|
53
65
|
|
|
@@ -56,18 +68,24 @@ const customer = await commerce.auth.getCurrentCustomer();
|
|
|
56
68
|
Handle updates carefully, checking for specific field support.
|
|
57
69
|
|
|
58
70
|
```typescript
|
|
59
|
-
async function handleUpdate(formData
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
async function handleUpdate(formData: {
|
|
72
|
+
firstName: string;
|
|
73
|
+
lastName: string;
|
|
74
|
+
email?: string;
|
|
75
|
+
}) {
|
|
76
|
+
if (!commerce.auth) throw new Error('Auth not available');
|
|
77
|
+
|
|
78
|
+
const updateData: Record<string, unknown> = {};
|
|
79
|
+
|
|
62
80
|
if (commerce.capabilities.updateProfile) {
|
|
63
81
|
updateData.first_name = formData.firstName;
|
|
64
82
|
updateData.last_name = formData.lastName;
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
if (commerce.capabilities.updateEmail) {
|
|
84
|
+
|
|
85
|
+
if (commerce.capabilities.updateEmail && formData.email) {
|
|
68
86
|
updateData.email = formData.email;
|
|
69
87
|
}
|
|
70
|
-
|
|
88
|
+
|
|
71
89
|
return await commerce.auth.updateCustomer(updateData);
|
|
72
90
|
}
|
|
73
91
|
```
|
|
@@ -78,42 +96,54 @@ Handle password changes based on whether the backend supports direct or email-ba
|
|
|
78
96
|
|
|
79
97
|
```typescript
|
|
80
98
|
if (commerce.capabilities.changePasswordDirect) {
|
|
99
|
+
// Direct password change (Shopify, Spree, Magento)
|
|
81
100
|
await commerce.auth.updateCustomer({
|
|
82
|
-
|
|
83
|
-
password: 'new',
|
|
101
|
+
password: 'NewPassword123!',
|
|
84
102
|
});
|
|
103
|
+
} else if (commerce.capabilities.changePasswordViaEmail) {
|
|
104
|
+
// Email-based reset (Medusa v2)
|
|
105
|
+
await commerce.auth.requestPasswordReset(customer.email);
|
|
85
106
|
}
|
|
86
107
|
```
|
|
87
108
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
1. **Check Capabilities First:** Avoid rendering buttons for features the backend doesn't support.
|
|
91
|
-
2. **Use Metadata for Extensions:** Store extra info like `avatar_url` or `notifications` in `customer.metadata`.
|
|
92
|
-
3. **Handle Errors explicitly:** Distinguish between `EMAIL_TAKEN` and generic update errors.
|
|
93
|
-
4. **Validate on Client:** Use patterns/regex for phone and email before sending to the adapter.
|
|
94
|
-
5. **Protect UI with Loading States:** Backend operations can take time; show a spinner.
|
|
95
|
-
|
|
96
|
-
## ❌ DONT's
|
|
109
|
+
### Step 5: Account Deletion
|
|
97
110
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
```typescript
|
|
112
|
+
if (commerce.capabilities.deleteAccount && commerce.auth) {
|
|
113
|
+
await commerce.auth.deleteCustomerAccount();
|
|
114
|
+
}
|
|
115
|
+
```
|
|
103
116
|
|
|
104
|
-
##
|
|
117
|
+
## Avatar Management
|
|
105
118
|
|
|
106
|
-
|
|
107
|
-
Since many backends don't support native avatars, use an external service (S3/Cloudinary) and store the URL in metadata.
|
|
119
|
+
Most backends don't support native avatar uploads. Use an external service (S3, Cloudinary) and store the URL in metadata.
|
|
108
120
|
|
|
109
121
|
```typescript
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
// Check capability first
|
|
123
|
+
if (commerce.capabilities.avatarViaMetadata && commerce.auth) {
|
|
124
|
+
await commerce.auth.updateCustomer({
|
|
125
|
+
metadata: { avatar_url: 'https://cdn.example.com/avatars/user-123.jpg' },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
113
128
|
```
|
|
114
129
|
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
> ⚠️ **Backend Disparity:** `uploadAvatar` (native file upload) is `false` for all current providers. Use `avatarViaMetadata` instead.
|
|
131
|
+
|
|
132
|
+
## ✅ DO's
|
|
133
|
+
|
|
134
|
+
1. **Check `commerce.capabilities` first:** Avoid rendering buttons for features the backend doesn't support.
|
|
135
|
+
2. **Use metadata for extensions:** Store extra info like `avatar_url` or notification preferences in `customer.metadata`.
|
|
136
|
+
3. **Handle errors explicitly:** Distinguish between `EMAIL_TAKEN` and generic update errors.
|
|
137
|
+
4. **Validate on client:** Use patterns/regex for phone and email before sending to the adapter.
|
|
138
|
+
5. **Re-fetch after update:** After a successful update, refresh the local customer state.
|
|
139
|
+
|
|
140
|
+
## ❌ DONT's
|
|
141
|
+
|
|
142
|
+
1. **Don't assume all backends are equal:** Medusa v2 has different capabilities than Shopify or WooCommerce.
|
|
143
|
+
2. **Don't hardcode profile fields:** Use the `UpdateCustomerData` type from `@thorprovider/adapters`.
|
|
144
|
+
3. **Don't ignore account deletion:** Provide a way for users to delete their account if `deleteAccount` is `true`.
|
|
145
|
+
4. **Don't send sensitive data in metadata:** Metadata is often visible to the user and may be less secure.
|
|
146
|
+
5. **Don't call `commerce.auth.updateCustomer` without checking `commerce.auth`:** It may be undefined.
|
|
117
147
|
|
|
118
148
|
## Common Errors & Solutions
|
|
119
149
|
|
|
@@ -128,16 +158,16 @@ Render only the fields supported by the current provider.
|
|
|
128
158
|
## Common Pitfalls
|
|
129
159
|
|
|
130
160
|
> ⚠️ **Pitfall 1: Metadata Overwrites**
|
|
131
|
-
> Some backends overwrite the entire metadata object instead of merging. Always fetch the current
|
|
161
|
+
> Some backends overwrite the entire metadata object instead of merging. Always fetch the current metadata first if you want to preserve existing fields.
|
|
132
162
|
|
|
133
163
|
> ⚠️ **Pitfall 2: Password Complexity**
|
|
134
|
-
> Backends have different password requirements. Let the backend validate and
|
|
164
|
+
> Backends have different password requirements. Let the backend validate and surface the error message.
|
|
135
165
|
|
|
136
166
|
## Troubleshooting
|
|
137
167
|
|
|
138
168
|
| Issue | Solution |
|
|
139
169
|
|-------|----------|
|
|
140
|
-
| Profile data not saving | Check if the user session is still active |
|
|
170
|
+
| Profile data not saving | Check if the user session is still active (`isAuthenticated()`) |
|
|
141
171
|
| Metadata field missing | Ensure the key exists in the backend's allowed metadata list |
|
|
142
172
|
| 403 Forbidden | User might not have permission to update their own profile |
|
|
143
173
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Services Overview
|
|
2
|
-
|
|
3
1
|
---
|
|
2
|
+
title: Services Overview
|
|
3
|
+
purpose: Overview of adapter services and provider capabilities
|
|
4
4
|
type: guide
|
|
5
5
|
tags: [architecture, services, commerce, api, architecture]
|
|
6
6
|
related:
|
|
@@ -10,6 +10,8 @@ related:
|
|
|
10
10
|
updated: 2026-02-28
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
# Services Overview
|
|
14
|
+
|
|
13
15
|
Overview of the functional services provided by Thor adapters and how they interact to provide a unified e-commerce interface.
|
|
14
16
|
|
|
15
17
|
## Overview
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/adapters",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Framework-agnostic commerce adapters for Thor Commerce ecosystem - Multi-platform support with unified API",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org",
|
package/quick-reference.md
CHANGED
|
@@ -52,6 +52,39 @@ Framework-agnostic business logic SDK for e-commerce operations. Provides unifie
|
|
|
52
52
|
- **Collections**: Product collections/categories
|
|
53
53
|
- **Customer**: Authentication, profile management
|
|
54
54
|
- **Orders**: Order history, details, tracking
|
|
55
|
+
- **Auth — Multi-Tenant**: `linkCustomerToChannel()` — links authenticated customer to sales channel (Medusa only)
|
|
56
|
+
|
|
57
|
+
### Admin Client (Medusa only)
|
|
58
|
+
`provider.admin` — available when `adminConfig.apiKey` is set. Exposes 15 methods for the `/admin/thor/` endpoints:
|
|
59
|
+
```typescript
|
|
60
|
+
const commerce = createProvider({ provider: 'medusa', config: { ..., adminConfig: { apiKey: '...' } } })
|
|
61
|
+
if (!commerce.admin) throw new Error('Admin not configured')
|
|
62
|
+
|
|
63
|
+
// Sales Channel — Customers / API Keys / Categories
|
|
64
|
+
await commerce.admin.getChannelCustomers(salesChannelId, { limit, offset })
|
|
65
|
+
await commerce.admin.getChannelApiKeys(salesChannelId)
|
|
66
|
+
await commerce.admin.getChannelCategories(salesChannelId, { limit, offset, include_descendants })
|
|
67
|
+
|
|
68
|
+
// Category ↔ Sales Channel assignments
|
|
69
|
+
await commerce.admin.getCategorySalesChannels(categoryId)
|
|
70
|
+
await commerce.admin.assignCategoryToChannels(categoryId, { sales_channel_ids: [...] })
|
|
71
|
+
await commerce.admin.unassignCategoryFromChannels(categoryId, { sales_channel_ids: [...] })
|
|
72
|
+
|
|
73
|
+
// Collection ↔ Sales Channel assignments
|
|
74
|
+
await commerce.admin.getCollectionSalesChannels(collectionId)
|
|
75
|
+
await commerce.admin.assignCollectionToChannels(collectionId, { sales_channel_ids: [...] })
|
|
76
|
+
await commerce.admin.unassignCollectionFromChannels(collectionId, { sales_channel_ids: [...] })
|
|
77
|
+
|
|
78
|
+
// Storefront Config (visual theme, SEO defaults)
|
|
79
|
+
await commerce.admin.getStorefrontConfig(salesChannelId)
|
|
80
|
+
await commerce.admin.updateStorefrontConfig(salesChannelId, { theme_accent_color, logo_url, currency_code, seo_defaults })
|
|
81
|
+
|
|
82
|
+
// Site Designer Config (page builder config with history)
|
|
83
|
+
await commerce.admin.getSiteConfig(salesChannelId)
|
|
84
|
+
await commerce.admin.updateSiteConfig(salesChannelId, { config: { ... } })
|
|
85
|
+
await commerce.admin.getSiteConfigHistory(salesChannelId, { limit, offset })
|
|
86
|
+
await commerce.admin.restoreSiteConfig(salesChannelId, version)
|
|
87
|
+
```
|
|
55
88
|
|
|
56
89
|
### Provider Architecture
|
|
57
90
|
```
|
package/src/backend/factory.ts
CHANGED
|
@@ -93,15 +93,5 @@ export function createBackendMetadataAdapter(
|
|
|
93
93
|
return new MedusaMetadataAdapter(medusa);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
// TODO: Implement Shopify metadata adapter
|
|
98
|
-
throw new Error('Shopify metadata adapter not yet implemented');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (provider === 'woocommerce') {
|
|
102
|
-
// TODO: Implement WooCommerce metadata adapter
|
|
103
|
-
throw new Error('WooCommerce metadata adapter not yet implemented');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
throw new Error(`Unsupported provider: ${provider}`);
|
|
96
|
+
throw new Error(`Unsupported provider for metadata adapter: ${provider}. Only 'medusa' is currently supported.`);
|
|
107
97
|
}
|
package/src/factory/index.ts
CHANGED
|
@@ -1,57 +1,93 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @thorprovider/adapters
|
|
3
|
-
* Provider Factory -
|
|
2
|
+
* @thorprovider/adapters v5.0
|
|
3
|
+
* Provider Factory - Dynamic registry pattern
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 4. Implement CommerceProvider interface
|
|
5
|
+
* Providers register themselves at import time via `registerProvider()`.
|
|
6
|
+
* The factory no longer statically imports every backend — only the ones
|
|
7
|
+
* the consumer explicitly imports will be available.
|
|
8
|
+
*
|
|
9
|
+
* Built-in providers (medusa, stelorder, mock) are registered automatically.
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
12
|
import type { CommerceProvider } from '../types';
|
|
14
13
|
import { MedusaProvider, type MedusaProviderConfig } from '../providers/medusa';
|
|
15
|
-
import { ShopifyProvider, type ShopifyProviderConfig } from '../providers/shopify';
|
|
16
|
-
import { BigCommerceProvider, type BigCommerceProviderConfig } from '../providers/bigcommerce';
|
|
17
|
-
import { WooCommerceProvider, type WooCommerceProviderConfig } from '../providers/woocommerce';
|
|
18
|
-
import { SpreeProvider, type SpreeProviderConfig } from '../providers/spree';
|
|
19
|
-
import { MagentoProvider, type MagentoProviderConfig } from '../providers/magento';
|
|
20
14
|
import { StelOrderProvider, type StelOrderProviderConfig } from '../providers/stelorder';
|
|
21
15
|
import { MockProvider, type MockProviderConfig } from '../providers/mock';
|
|
22
16
|
import { ProviderNotFoundError, ConfigurationError } from '../core/errors';
|
|
23
17
|
import type { ProviderTypeString } from '@thorprovider/types';
|
|
24
18
|
|
|
19
|
+
// ============================================
|
|
20
|
+
// Registry
|
|
21
|
+
// ============================================
|
|
22
|
+
|
|
23
|
+
type ProviderFactory = (config: any) => CommerceProvider;
|
|
24
|
+
|
|
25
|
+
const registry = new Map<string, ProviderFactory>();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register a provider factory for a given type string.
|
|
29
|
+
* Call this to make a provider available to `createProvider()`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { registerProvider } from '@thorprovider/adapters';
|
|
34
|
+
* import { MyProvider } from './my-provider';
|
|
35
|
+
*
|
|
36
|
+
* registerProvider('my-provider', (config) => new MyProvider(config));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function registerProvider(type: string, factory: ProviderFactory): void {
|
|
40
|
+
registry.set(type, factory);
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
/**
|
|
26
|
-
*
|
|
27
|
-
* Kept for backward compatibility; prefer ProviderTypeString from @thorprovider/types
|
|
44
|
+
* Get all registered provider type strings.
|
|
28
45
|
*/
|
|
29
|
-
export
|
|
46
|
+
export function getRegisteredProviders(): string[] {
|
|
47
|
+
return Array.from(registry.keys());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ============================================
|
|
51
|
+
// Built-in registrations
|
|
52
|
+
// ============================================
|
|
53
|
+
|
|
54
|
+
registerProvider('mock', (config) => new MockProvider(config));
|
|
55
|
+
registerProvider('medusa', (config) => new MedusaProvider(config));
|
|
56
|
+
registerProvider('stelorder', (config) => new StelOrderProvider(config));
|
|
57
|
+
|
|
58
|
+
// ============================================
|
|
59
|
+
// Types
|
|
60
|
+
// ============================================
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Supported provider types
|
|
64
|
+
*/
|
|
65
|
+
export type ProviderType = ProviderTypeString | (string & {});
|
|
30
66
|
|
|
31
67
|
/**
|
|
32
|
-
* Provider configuration discriminated union
|
|
68
|
+
* Provider configuration discriminated union (built-in providers)
|
|
33
69
|
*/
|
|
34
70
|
export type ProviderFactoryConfig =
|
|
35
71
|
| { provider: 'mock'; config: MockProviderConfig }
|
|
36
72
|
| { provider: 'medusa'; config: MedusaProviderConfig }
|
|
37
73
|
| { provider: 'stelorder'; config: StelOrderProviderConfig }
|
|
38
|
-
| { provider:
|
|
39
|
-
| { provider: 'bigcommerce'; config: BigCommerceProviderConfig }
|
|
40
|
-
| { provider: 'woocommerce'; config: WooCommerceProviderConfig }
|
|
41
|
-
| { provider: 'spree'; config: SpreeProviderConfig }
|
|
42
|
-
| { provider: 'magento'; config: MagentoProviderConfig };
|
|
74
|
+
| { provider: string; config: Record<string, unknown> };
|
|
43
75
|
|
|
44
76
|
/**
|
|
45
|
-
* Runtime provider configuration (accepts any
|
|
77
|
+
* Runtime provider configuration (accepts any registered provider string)
|
|
46
78
|
*/
|
|
47
79
|
export type RuntimeProviderConfig = {
|
|
48
|
-
provider:
|
|
80
|
+
provider: string;
|
|
49
81
|
config: Record<string, unknown>;
|
|
50
82
|
};
|
|
51
83
|
|
|
84
|
+
// ============================================
|
|
85
|
+
// Factory
|
|
86
|
+
// ============================================
|
|
87
|
+
|
|
52
88
|
/**
|
|
53
|
-
* Create a commerce provider instance
|
|
54
|
-
*
|
|
89
|
+
* Create a commerce provider instance from the registry.
|
|
90
|
+
*
|
|
55
91
|
* @example
|
|
56
92
|
* ```ts
|
|
57
93
|
* const commerce = createProvider({
|
|
@@ -61,42 +97,28 @@ export type RuntimeProviderConfig = {
|
|
|
61
97
|
* publishableKey: process.env.MEDUSA_PUBLISHABLE_KEY,
|
|
62
98
|
* }
|
|
63
99
|
* });
|
|
64
|
-
*
|
|
65
|
-
* const products = await commerce.getProducts();
|
|
66
100
|
* ```
|
|
67
101
|
*/
|
|
68
102
|
export function createProvider(options: ProviderFactoryConfig | RuntimeProviderConfig): CommerceProvider {
|
|
69
103
|
if (!options || !options.provider) {
|
|
70
104
|
throw new ConfigurationError('Provider type is required');
|
|
71
105
|
}
|
|
72
|
-
|
|
106
|
+
|
|
73
107
|
if (!options.config) {
|
|
74
108
|
throw new ConfigurationError('Provider configuration is required');
|
|
75
109
|
}
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return new StelOrderProvider(config);
|
|
86
|
-
case 'shopify':
|
|
87
|
-
return new ShopifyProvider(config);
|
|
88
|
-
case 'bigcommerce':
|
|
89
|
-
return new BigCommerceProvider(config);
|
|
90
|
-
case 'woocommerce':
|
|
91
|
-
return new WooCommerceProvider(config);
|
|
92
|
-
case 'spree':
|
|
93
|
-
return new SpreeProvider(config);
|
|
94
|
-
case 'magento':
|
|
95
|
-
return new MagentoProvider(config);
|
|
96
|
-
|
|
97
|
-
default:
|
|
98
|
-
throw new ProviderNotFoundError(String((options as any).provider));
|
|
110
|
+
|
|
111
|
+
const factory = registry.get(options.provider);
|
|
112
|
+
|
|
113
|
+
if (!factory) {
|
|
114
|
+
const available = getRegisteredProviders().join(', ');
|
|
115
|
+
throw new ProviderNotFoundError(
|
|
116
|
+
`Provider "${options.provider}" is not registered. Available: ${available}. ` +
|
|
117
|
+
`Did you forget to import the provider package?`
|
|
118
|
+
);
|
|
99
119
|
}
|
|
120
|
+
|
|
121
|
+
return factory(options.config);
|
|
100
122
|
}
|
|
101
123
|
|
|
102
124
|
/**
|
package/src/index.ts
CHANGED
|
@@ -41,11 +41,6 @@ export {
|
|
|
41
41
|
MOCK_CAPABILITIES,
|
|
42
42
|
MEDUSA_CAPABILITIES,
|
|
43
43
|
STELORDER_CAPABILITIES,
|
|
44
|
-
SHOPIFY_CAPABILITIES,
|
|
45
|
-
BIGCOMMERCE_CAPABILITIES,
|
|
46
|
-
WOOCOMMERCE_CAPABILITIES,
|
|
47
|
-
SPREE_CAPABILITIES,
|
|
48
|
-
MAGENTO_CAPABILITIES,
|
|
49
44
|
isBackendCapabilities,
|
|
50
45
|
getCapabilityDescription,
|
|
51
46
|
} from './types/capabilities.types';
|
|
@@ -60,8 +55,11 @@ export {
|
|
|
60
55
|
ResourceNotFoundError,
|
|
61
56
|
ProviderAPIError,
|
|
62
57
|
createLogger,
|
|
58
|
+
fetchWithRetry,
|
|
59
|
+
extractErrorMessage,
|
|
63
60
|
type Logger,
|
|
64
61
|
type LogLevel,
|
|
62
|
+
type RetryConfig,
|
|
65
63
|
} from './core';
|
|
66
64
|
|
|
67
65
|
// ============================================
|
|
@@ -183,6 +181,8 @@ export type {
|
|
|
183
181
|
// ============================================
|
|
184
182
|
export {
|
|
185
183
|
createProvider,
|
|
184
|
+
registerProvider,
|
|
185
|
+
getRegisteredProviders,
|
|
186
186
|
isProviderType,
|
|
187
187
|
type ProviderType,
|
|
188
188
|
type ProviderFactoryConfig,
|
|
@@ -198,14 +198,4 @@ export {
|
|
|
198
198
|
type StelOrderProviderConfig,
|
|
199
199
|
MockProvider,
|
|
200
200
|
type MockProviderConfig,
|
|
201
|
-
ShopifyProvider,
|
|
202
|
-
type ShopifyProviderConfig,
|
|
203
|
-
BigCommerceProvider,
|
|
204
|
-
type BigCommerceProviderConfig,
|
|
205
|
-
WooCommerceProvider,
|
|
206
|
-
type WooCommerceProviderConfig,
|
|
207
|
-
SpreeProvider,
|
|
208
|
-
type SpreeProviderConfig,
|
|
209
|
-
MagentoProvider,
|
|
210
|
-
type MagentoProviderConfig,
|
|
211
201
|
} from './providers';
|
package/src/providers/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @thorprovider/adapters
|
|
2
|
+
* @thorprovider/adapters v5.0
|
|
3
3
|
* Providers index
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -9,20 +9,5 @@ export type { MedusaProviderConfig } from './medusa';
|
|
|
9
9
|
export { StelOrderProvider } from './stelorder';
|
|
10
10
|
export type { StelOrderProviderConfig } from './stelorder';
|
|
11
11
|
|
|
12
|
-
export { ShopifyProvider } from './shopify';
|
|
13
|
-
export type { ShopifyProviderConfig } from './shopify';
|
|
14
|
-
|
|
15
|
-
export { BigCommerceProvider } from './bigcommerce';
|
|
16
|
-
export type { BigCommerceProviderConfig } from './bigcommerce';
|
|
17
|
-
|
|
18
|
-
export { WooCommerceProvider } from './woocommerce';
|
|
19
|
-
export type { WooCommerceProviderConfig } from './woocommerce';
|
|
20
|
-
|
|
21
|
-
export { SpreeProvider } from './spree';
|
|
22
|
-
export type { SpreeProviderConfig } from './spree';
|
|
23
|
-
|
|
24
|
-
export { MagentoProvider } from './magento';
|
|
25
|
-
export type { MagentoProviderConfig } from './magento';
|
|
26
|
-
|
|
27
12
|
export { MockProvider } from './mock';
|
|
28
13
|
export type { MockProviderConfig } from './mock';
|