@thorprovider/adapters 4.2.1 → 4.2.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 -1
- package/CHANGELOG.md +6 -0
- package/PROVIDER_IMPLEMENTATION_ANALYSIS.md +659 -0
- package/README.md +3 -3
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.mts +51 -1
- package/dist/index.d.ts +51 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -1
- package/docs/RETRY_SOLUTION_SUMMARY.md +26 -11
- package/docs/authentication.md +89 -62
- package/docs/capabilities-system.md +70 -38
- 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/docs/update-documentation.md +10 -8
- package/package.json +3 -2
- package/publish.log +93 -0
- package/src/index.ts +4 -0
- package/src/providers/medusa/admin.test.ts +404 -0
- package/src/providers/medusa/admin.ts +442 -0
- package/src/providers/medusa/auth.test.ts +95 -0
- package/src/providers/medusa/index.test.ts +392 -0
- package/src/providers/medusa/live-smoke.test.ts +412 -0
- package/src/resilience/README.md +70 -48
- package/vitest.live.config.ts +18 -0
|
@@ -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
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
# Update Documentation
|
|
2
|
-
|
|
3
1
|
---
|
|
2
|
+
title: Update Documentation
|
|
3
|
+
purpose: Guidelines for updating @thorprovider/adapters documentation correctly
|
|
4
4
|
type: how-to
|
|
5
5
|
tags: [documentation, maintenance, adapters, standards, copilot]
|
|
6
6
|
related:
|
|
7
7
|
- ../../../docs/templates/README.md
|
|
8
|
-
- ../../../docs/
|
|
9
|
-
updated: 2026-
|
|
8
|
+
- ../../../docs/standards/documentation.md
|
|
9
|
+
updated: 2026-05-23
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
+
# Update Documentation
|
|
13
|
+
|
|
12
14
|
**Specific guidelines for updating @thorprovider/adapters documentation.**
|
|
13
15
|
|
|
14
|
-
Global guidelines: [docs/
|
|
16
|
+
Global guidelines: [docs/standards/documentation.md](../../../docs/standards/documentation.md)
|
|
15
17
|
|
|
16
18
|
## Prerequisites
|
|
17
19
|
|
|
18
|
-
- Read [global guidelines](../../../docs/
|
|
20
|
+
- Read [global guidelines](../../../docs/standards/documentation.md) for doc types and templates
|
|
19
21
|
- Understand the [Providers System](providers-overview.md) and [Capabilities System](capabilities-system.md)
|
|
20
|
-
- Ensure understanding of the [
|
|
22
|
+
- Ensure understanding of the [Architecture Overview](../../../docs/architecture/overview.md) (Strategy Pattern)
|
|
21
23
|
|
|
22
24
|
## Step-by-Step Process for Adapters
|
|
23
25
|
|
|
@@ -109,5 +111,5 @@ async function performTask() {
|
|
|
109
111
|
|
|
110
112
|
## Next Steps
|
|
111
113
|
|
|
112
|
-
- [global
|
|
114
|
+
- [global documentation standards](../../../docs/standards/documentation.md)
|
|
113
115
|
- [How-to: Getting Started](getting-started.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/adapters",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
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",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"dev": "tsup --watch",
|
|
23
23
|
"type-check": "tsc --noEmit",
|
|
24
24
|
"test": "vitest run --config vitest.config.ts",
|
|
25
|
-
"test:live": "vitest run --config vitest.config.ts src/providers/stelorder/live-smoke.test.ts",
|
|
25
|
+
"test:live": "vitest run --config vitest.live.config.ts src/providers/stelorder/live-smoke.test.ts",
|
|
26
|
+
"test:live:medusa": "vitest run --config vitest.live.config.ts src/providers/medusa/live-smoke.test.ts",
|
|
26
27
|
"generate:agent-index": "node ../../scripts/generate-package-agents-index.cjs packages/adapters @thorprovider/adapters"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
package/publish.log
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
npm warn Unknown project config "network-concurrency". This will stop working in the next major version of npm.
|
|
2
|
+
npm warn publish npm auto-corrected some errors in your package.json when publishing. Please run "npm pkg fix" to address these errors.
|
|
3
|
+
npm warn publish errors corrected:
|
|
4
|
+
npm warn publish "repository.url" was normalized to "git+https://github.com/thorprovider/thor-commerce.git"
|
|
5
|
+
npm notice
|
|
6
|
+
npm notice 📦 @thor/adapters@3.0.1
|
|
7
|
+
npm notice Tarball Contents
|
|
8
|
+
npm notice 629B AGENTS.md
|
|
9
|
+
npm notice 9.1kB CHANGELOG.md
|
|
10
|
+
npm notice 19.2kB README.md
|
|
11
|
+
npm notice 73.6kB dist/index.d.mts
|
|
12
|
+
npm notice 73.6kB dist/index.d.ts
|
|
13
|
+
npm notice 191.6kB dist/index.js
|
|
14
|
+
npm notice 377.7kB dist/index.js.map
|
|
15
|
+
npm notice 187.4kB dist/index.mjs
|
|
16
|
+
npm notice 377.4kB dist/index.mjs.map
|
|
17
|
+
npm notice 4.7kB docs/authentication.md
|
|
18
|
+
npm notice 4.3kB docs/capabilities-system.md
|
|
19
|
+
npm notice 9.9kB docs/category-customization.md
|
|
20
|
+
npm notice 11.0kB docs/fetch-reliability-solution.md
|
|
21
|
+
npm notice 4.4kB docs/getting-started.md
|
|
22
|
+
npm notice 7.8kB docs/multi-tenant-channel-scoping.md
|
|
23
|
+
npm notice 4.5kB docs/profile-management.md
|
|
24
|
+
npm notice 3.7kB docs/providers-overview.md
|
|
25
|
+
npm notice 2.1kB docs/RETRY_SOLUTION_SUMMARY.md
|
|
26
|
+
npm notice 5.2kB docs/services-overview.md
|
|
27
|
+
npm notice 4.0kB docs/update-documentation.md
|
|
28
|
+
npm notice 1.2kB package.json
|
|
29
|
+
npm notice 6.3kB quick-reference.md
|
|
30
|
+
npm notice 2.5kB src/admin/AdminAuthService.ts
|
|
31
|
+
npm notice 2.4kB src/admin/AdminSessionService.ts
|
|
32
|
+
npm notice 414B src/admin/index.ts
|
|
33
|
+
npm notice 4.2kB src/admin/MetricsService.ts
|
|
34
|
+
npm notice 2.5kB src/backend/BackendMetadataAdapter.ts
|
|
35
|
+
npm notice 3.5kB src/backend/factory.ts
|
|
36
|
+
npm notice 312B src/backend/index.ts
|
|
37
|
+
npm notice 3.9kB src/backend/medusa/MedusaMetadataAdapter.ts
|
|
38
|
+
npm notice 6.3kB src/core/errors.js
|
|
39
|
+
npm notice 3.5kB src/core/errors.ts
|
|
40
|
+
npm notice 11.3kB src/core/fetch-utils.js
|
|
41
|
+
npm notice 6.0kB src/core/fetch-utils.ts
|
|
42
|
+
npm notice 141B src/core/index.ts
|
|
43
|
+
npm notice 2.3kB src/core/logger.js
|
|
44
|
+
npm notice 1.1kB src/core/logger.ts
|
|
45
|
+
npm notice 2.0kB src/factory/index.ts
|
|
46
|
+
npm notice 4.5kB src/index.ts
|
|
47
|
+
npm notice 2.7kB src/lib/money-transform.ts
|
|
48
|
+
npm notice 6.2kB src/metadata/channel-scope-validation.js
|
|
49
|
+
npm notice 5.1kB src/metadata/channel-scope-validation.ts
|
|
50
|
+
npm notice 7.6kB src/metadata/channel-scope.js
|
|
51
|
+
npm notice 8.2kB src/metadata/channel-scope.ts
|
|
52
|
+
npm notice 3.3kB src/metadata/index.js
|
|
53
|
+
npm notice 810B src/metadata/index.ts
|
|
54
|
+
npm notice 148B src/providers/index.ts
|
|
55
|
+
npm notice 30.0kB src/providers/medusa/auth.js
|
|
56
|
+
npm notice 15.1kB src/providers/medusa/auth.ts
|
|
57
|
+
npm notice 6.2kB src/providers/medusa/fulfillment-planner.ts
|
|
58
|
+
npm notice 151.8kB src/providers/medusa/index.js
|
|
59
|
+
npm notice 147.6kB src/providers/medusa/index.ts
|
|
60
|
+
npm notice 184B src/providers/medusa/medusa.ts
|
|
61
|
+
npm notice 11.0kB src/providers/medusa/payment.js
|
|
62
|
+
npm notice 7.2kB src/providers/medusa/payment.ts
|
|
63
|
+
npm notice 25.8kB src/providers/medusa/transforms.js
|
|
64
|
+
npm notice 19.8kB src/providers/medusa/transforms.ts
|
|
65
|
+
npm notice 5.5kB src/resilience/circuit-breaker.ts
|
|
66
|
+
npm notice 238B src/resilience/index.ts
|
|
67
|
+
npm notice 7.6kB src/resilience/README.md
|
|
68
|
+
npm notice 4.8kB src/types/capabilities.types.js
|
|
69
|
+
npm notice 4.7kB src/types/capabilities.types.ts
|
|
70
|
+
npm notice 513B src/types/index.ts
|
|
71
|
+
npm notice 350B src/types/provider.js
|
|
72
|
+
npm notice 365B src/types/provider.ts
|
|
73
|
+
npm notice 6.5kB src/types/ui-responses.ts
|
|
74
|
+
npm notice 1.1kB src/utils/city-coordinates.ts
|
|
75
|
+
npm notice 1.3kB src/utils/geolocation.ts
|
|
76
|
+
npm notice 5.6kB src/utils/payment-utils.js
|
|
77
|
+
npm notice 6.5kB src/utils/payment-utils.ts
|
|
78
|
+
npm notice 357B tsconfig.json
|
|
79
|
+
npm notice 370B tsup.config.ts
|
|
80
|
+
npm notice Tarball Details
|
|
81
|
+
npm notice name: @thor/adapters
|
|
82
|
+
npm notice version: 3.0.1
|
|
83
|
+
npm notice filename: thor-adapters-3.0.1.tgz
|
|
84
|
+
npm notice package size: 413.9 kB
|
|
85
|
+
npm notice unpacked size: 1.9 MB
|
|
86
|
+
npm notice shasum: 696c58c4b5629ad1ec09336238ea157aad015e3d
|
|
87
|
+
npm notice integrity: sha512-tIweHlz73prg8[...]3KYkFTyNlUX4w==
|
|
88
|
+
npm notice total files: 72
|
|
89
|
+
npm notice
|
|
90
|
+
npm notice Publishing to https://npm.pkg.github.com with tag latest and restricted access
|
|
91
|
+
npm error code E401
|
|
92
|
+
npm error 401 Unauthorized - PUT https://npm.pkg.github.com/@thor%2fadapters - unauthenticated: User cannot be authenticated with the token provided.
|
|
93
|
+
npm error A complete log of this run can be found in: /home/nelson/.npm/_logs/2026-04-16T15_45_37_415Z-debug-0.log
|
package/src/index.ts
CHANGED
|
@@ -59,9 +59,13 @@ export {
|
|
|
59
59
|
ConfigurationError,
|
|
60
60
|
ResourceNotFoundError,
|
|
61
61
|
ProviderAPIError,
|
|
62
|
+
extractErrorMessage,
|
|
62
63
|
createLogger,
|
|
64
|
+
fetchWithRetry,
|
|
65
|
+
createFetchWithRetry,
|
|
63
66
|
type Logger,
|
|
64
67
|
type LogLevel,
|
|
68
|
+
type RetryConfig,
|
|
65
69
|
} from './core';
|
|
66
70
|
|
|
67
71
|
// ============================================
|