@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.
Files changed (60) hide show
  1. package/PROVIDER_IMPLEMENTATION_ANALYSIS.md +659 -0
  2. package/dist/index.d.mts +225 -387
  3. package/dist/index.d.ts +225 -387
  4. package/dist/index.js +613 -3062
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +609 -3052
  7. package/dist/index.mjs.map +1 -1
  8. package/docs/RETRY_SOLUTION_SUMMARY.md +26 -11
  9. package/docs/authentication.md +115 -62
  10. package/docs/capabilities-system.md +4 -2
  11. package/docs/category-customization.md +37 -29
  12. package/docs/fetch-reliability-solution.md +127 -278
  13. package/docs/getting-started.md +43 -29
  14. package/docs/profile-management.md +68 -38
  15. package/docs/services-overview.md +4 -2
  16. package/package.json +1 -1
  17. package/quick-reference.md +33 -0
  18. package/src/backend/factory.ts +1 -11
  19. package/src/factory/index.ts +74 -52
  20. package/src/index.ts +5 -15
  21. package/src/providers/index.ts +1 -16
  22. package/src/providers/medusa/admin.test.ts +404 -0
  23. package/src/providers/medusa/admin.ts +442 -0
  24. package/src/providers/medusa/auth.test.ts +137 -0
  25. package/src/providers/medusa/auth.ts +96 -1
  26. package/src/providers/medusa/index.ts +21 -1
  27. package/src/resilience/README.md +70 -48
  28. package/src/types/capabilities.types.ts +0 -250
  29. package/src/core/errors.js +0 -161
  30. package/src/core/fetch-utils.js +0 -240
  31. package/src/core/logger.js +0 -63
  32. package/src/metadata/channel-scope-validation.js +0 -136
  33. package/src/metadata/channel-scope.js +0 -174
  34. package/src/metadata/index.js +0 -31
  35. package/src/providers/bigcommerce/bigcommerce.ts +0 -6
  36. package/src/providers/bigcommerce/index.ts +0 -315
  37. package/src/providers/bigcommerce/transforms.ts +0 -227
  38. package/src/providers/magento/index.ts +0 -387
  39. package/src/providers/magento/magento.ts +0 -5
  40. package/src/providers/magento/queries.ts +0 -267
  41. package/src/providers/magento/transforms.ts +0 -249
  42. package/src/providers/medusa/auth.js +0 -601
  43. package/src/providers/medusa/index.js +0 -2485
  44. package/src/providers/medusa/payment.js +0 -265
  45. package/src/providers/medusa/transforms.js +0 -505
  46. package/src/providers/shopify/auth.ts +0 -402
  47. package/src/providers/shopify/index.ts +0 -444
  48. package/src/providers/shopify/mutations.ts +0 -247
  49. package/src/providers/shopify/queries.ts +0 -324
  50. package/src/providers/shopify/shopify.ts +0 -7
  51. package/src/providers/shopify/transforms.ts +0 -275
  52. package/src/providers/spree/index.ts +0 -344
  53. package/src/providers/spree/spree.ts +0 -5
  54. package/src/providers/spree/transforms.ts +0 -254
  55. package/src/providers/woocommerce/index.ts +0 -310
  56. package/src/providers/woocommerce/transforms.ts +0 -254
  57. package/src/providers/woocommerce/woocommerce.ts +0 -5
  58. package/src/types/capabilities.types.js +0 -141
  59. package/src/types/provider.js +0 -9
  60. package/src/utils/payment-utils.js +0 -152
@@ -1,141 +0,0 @@
1
- "use strict";
2
- /**
3
- * @thorprovider/adapters v2.0
4
- * Backend Capabilities System
5
- *
6
- * Defines what operations each backend platform supports.
7
- * This is a compile-time capability detection system, NOT runtime feature flags.
8
- *
9
- * NOTE: BackendCapabilities interface is defined in @thorprovider/types (L1: Foundation).
10
- * This file re-exports it and provides platform-specific implementations.
11
- *
12
- * @see packages/core/docs/BACKEND_CAPABILITIES_ANALYSIS.md
13
- * @see packages/core/docs/COMMERCE_PROVIDER_ARCHITECTURE.md
14
- */
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.SHOPIFY_CAPABILITIES = exports.MEDUSA_CAPABILITIES = void 0;
17
- exports.isBackendCapabilities = isBackendCapabilities;
18
- exports.getCapabilityDescription = getCapabilityDescription;
19
- /**
20
- * Medusa backend capabilities
21
- *
22
- * @see https://docs.medusajs.com/api/store
23
- */
24
- exports.MEDUSA_CAPABILITIES = {
25
- // Profile Management
26
- updateProfile: true,
27
- updateEmail: false, // Security restriction
28
- changePasswordDirect: false, // Email flow only
29
- changePasswordViaEmail: true,
30
- deleteAccount: true, // Implemented via ThorMedusaClient
31
- // Avatar
32
- uploadAvatar: false,
33
- avatarViaMetadata: true,
34
- // Custom Attributes
35
- customAttributes: true,
36
- // Orders
37
- fetchOrders: true,
38
- cancelOrder: true,
39
- // Addresses
40
- manageAddresses: true,
41
- defaultAddress: true,
42
- // Cart/Checkout
43
- applyDiscounts: true,
44
- shippingCalculation: true,
45
- guestCheckout: true,
46
- savedPaymentMethods: false, // Depends on payment provider
47
- listPaymentProviders: true,
48
- regionSpecificPayments: true,
49
- // Wishlist
50
- wishlist: false, // Requires custom implementation
51
- // Search
52
- advancedSearch: true,
53
- facetedFilters: true,
54
- // Reviews
55
- productReviews: false, // Requires custom implementation
56
- // Loyalty
57
- loyaltyProgram: false, // Requires custom implementation
58
- };
59
- /**
60
- * Shopify backend capabilities
61
- *
62
- * @see https://shopify.dev/docs/api/storefront
63
- */
64
- exports.SHOPIFY_CAPABILITIES = {
65
- // Profile Management
66
- updateProfile: true,
67
- updateEmail: true,
68
- changePasswordDirect: true,
69
- changePasswordViaEmail: true,
70
- deleteAccount: false, // Requires admin API
71
- // Avatar
72
- uploadAvatar: false,
73
- avatarViaMetadata: true,
74
- // Custom Attributes
75
- customAttributes: true,
76
- // Orders
77
- fetchOrders: true,
78
- cancelOrder: true,
79
- // Addresses
80
- manageAddresses: true,
81
- defaultAddress: true,
82
- // Cart/Checkout
83
- applyDiscounts: true,
84
- shippingCalculation: true,
85
- guestCheckout: true,
86
- savedPaymentMethods: true,
87
- listPaymentProviders: true,
88
- regionSpecificPayments: false, // Global payment methods
89
- // Wishlist
90
- wishlist: false, // Requires app
91
- // Search
92
- advancedSearch: true,
93
- facetedFilters: true,
94
- // Reviews
95
- productReviews: false, // Requires app
96
- // Loyalty
97
- loyaltyProgram: false, // Requires app
98
- };
99
- /**
100
- * Type guard to check if an object is a valid BackendCapabilities
101
- */
102
- function isBackendCapabilities(obj) {
103
- if (typeof obj !== 'object' || obj === null)
104
- return false;
105
- var capabilities = obj;
106
- // Check required profile management capabilities
107
- return (typeof capabilities.updateProfile === 'boolean' &&
108
- typeof capabilities.updateEmail === 'boolean' &&
109
- typeof capabilities.changePasswordDirect === 'boolean');
110
- }
111
- /**
112
- * Get capability description for UI display
113
- */
114
- function getCapabilityDescription(capability) {
115
- var descriptions = {
116
- updateProfile: 'Update profile information (name, phone)',
117
- updateEmail: 'Change email address',
118
- changePasswordDirect: 'Change password directly',
119
- changePasswordViaEmail: 'Request password reset via email',
120
- deleteAccount: 'Delete account (self-service)',
121
- uploadAvatar: 'Upload profile picture',
122
- avatarViaMetadata: 'Store avatar URL in metadata',
123
- customAttributes: 'Custom customer attributes',
124
- fetchOrders: 'View order history',
125
- cancelOrder: 'Cancel orders',
126
- manageAddresses: 'Add/update/delete addresses',
127
- defaultAddress: 'Set default address',
128
- applyDiscounts: 'Apply discount codes',
129
- shippingCalculation: 'Calculate shipping rates',
130
- guestCheckout: 'Checkout without account',
131
- savedPaymentMethods: 'Save payment methods',
132
- listPaymentProviders: 'List available payment providers',
133
- regionSpecificPayments: 'Region-specific payment methods',
134
- wishlist: 'Wishlist/favorites',
135
- advancedSearch: 'Advanced product search',
136
- facetedFilters: 'Filter by product attributes',
137
- productReviews: 'Product reviews and ratings',
138
- loyaltyProgram: 'Loyalty/rewards program',
139
- };
140
- return descriptions[capability] || capability;
141
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- /**
3
- * @thorprovider/adapters v2.0
4
- * Provider interface - unified commerce operations across all platforms
5
- *
6
- * NOTE: This file re-exports CommerceProvider from @thorprovider/types for backward compatibility.
7
- * The actual interface definition lives in @thorprovider/types (L1: Foundation).
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,152 +0,0 @@
1
- "use strict";
2
- /**
3
- * @thorprovider/adapters - Payment Utilities
4
- *
5
- * Backend-agnostic utilities for extracting backend provider IDs from
6
- * normalized PaymentMethod objects using metadata.
7
- *
8
- * This solves the problem of losing backend-specific provider IDs during
9
- * transformation to frontend-friendly formats.
10
- *
11
- * @module payment-utils
12
- * @since 2.0.0
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getBackendProviderId = getBackendProviderId;
16
- exports.validatePaymentId = validatePaymentId;
17
- /**
18
- * Extract backend provider ID from PaymentMethod
19
- *
20
- * Uses the `_backendMapping` metadata to retrieve the original
21
- * backend-specific provider ID that should be sent to API calls.
22
- *
23
- * **Why this exists:**
24
- * During transformation, we normalize backend IDs to friendly types:
25
- * - Backend: 'pp_stripe_stripe' → Frontend: type 'card'
26
- * - Backend: 'pp_system_default' → Frontend: type 'cash_on_delivery'
27
- *
28
- * But when making API calls, we need the ORIGINAL backend ID, not the type.
29
- * This function extracts it from metadata.
30
- *
31
- * @param method - PaymentMethod with _backendMapping metadata
32
- * @returns Backend provider ID (e.g., 'pp_stripe_stripe', 'pp_system_default')
33
- * @throws {Error} If _backendMapping metadata is missing or invalid
34
- *
35
- * @example
36
- * ```typescript
37
- * // PaymentMethod from backend with metadata
38
- * const method = {
39
- * id: 'pp_system_default',
40
- * type: 'cash_on_delivery',
41
- * name: 'Cash on Delivery',
42
- * metadata: {
43
- * _backendMapping: {
44
- * backend: 'medusa',
45
- * originalId: 'pp_system_default',
46
- * normalizedType: 'cash_on_delivery'
47
- * }
48
- * }
49
- * };
50
- *
51
- * const providerId = getBackendProviderId(method);
52
- * // Returns: 'pp_system_default'
53
- *
54
- * // Now safe to use with backend API:
55
- * await commerce.initiatePaymentSession(cartId, providerId);
56
- * ```
57
- *
58
- * @example
59
- * ```typescript
60
- * // Handling missing metadata
61
- * try {
62
- * const providerId = getBackendProviderId(methodWithoutMetadata);
63
- * } catch (error) {
64
- * console.error('Payment method missing backend mapping:', error.message);
65
- * // Error: PaymentMethod 'stripe' is missing _backendMapping metadata.
66
- * // This is required to extract the backend provider ID.
67
- * }
68
- * ```
69
- */
70
- function getBackendProviderId(method) {
71
- var _a;
72
- var mapping = (_a = method.metadata) === null || _a === void 0 ? void 0 : _a._backendMapping;
73
- if (!mapping) {
74
- throw new Error("PaymentMethod '".concat(method.id, "' is missing _backendMapping metadata. ") +
75
- "This is required to extract the backend provider ID. " +
76
- "Ensure the payment method was transformed with metadata preservation. " +
77
- "Check transformPaymentMethod() implementation in your provider adapter.");
78
- }
79
- if (!mapping.originalId) {
80
- throw new Error("PaymentMethod '".concat(method.id, "' has invalid _backendMapping metadata: ") +
81
- "'originalId' field is missing or empty. " +
82
- "Expected structure: { _backendMapping: { backend: 'medusa', originalId: 'pp_...', normalizedType: '...' } }");
83
- }
84
- return mapping.originalId;
85
- }
86
- /**
87
- * Validate payment provider ID format
88
- *
89
- * Checks if the provider ID is a valid backend-specific identifier,
90
- * not a normalized type like 'card', 'wallet', etc.
91
- *
92
- * **Why this exists:**
93
- * Common bug: Accidentally sending normalized types to backend APIs:
94
- * ❌ `initiatePaymentSession(cartId, 'card')` → Backend error
95
- * ✅ `initiatePaymentSession(cartId, 'pp_stripe_stripe')` → Success
96
- *
97
- * This validation catches the bug at runtime with a helpful error message.
98
- *
99
- * @param id - Provider ID to validate
100
- * @throws {Error} If ID appears to be a normalized type instead of backend ID
101
- *
102
- * @example
103
- * ```typescript
104
- * // Valid backend IDs - pass validation:
105
- * validatePaymentId('pp_stripe_stripe'); // ✅ OK (Medusa)
106
- * validatePaymentId('pp_system_default'); // ✅ OK (Medusa)
107
- * validatePaymentId('shopify_payments'); // ✅ OK (Shopify)
108
- * validatePaymentId('stripe'); // ✅ OK (WooCommerce)
109
- * validatePaymentId('paypal_express'); // ✅ OK (generic)
110
- *
111
- * // Invalid (normalized types) - throw error:
112
- * validatePaymentId('card'); // ❌ Throws error
113
- * validatePaymentId('wallet'); // ❌ Throws error
114
- * validatePaymentId('cash_on_delivery'); // ❌ Throws error
115
- * ```
116
- *
117
- * @example
118
- * ```typescript
119
- * // Use before API calls:
120
- * async function initiatePayment(cartId: string, providerId: string) {
121
- * // Validate before sending to backend
122
- * validatePaymentId(providerId);
123
- *
124
- * return await sdk.payment.initiatePaymentSession(cart, {
125
- * provider_id: providerId
126
- * });
127
- * }
128
- *
129
- * // Catches bugs early:
130
- * await initiatePayment(cartId, 'card');
131
- * // ❌ Error: Invalid payment provider ID: 'card'.
132
- * // This appears to be a normalized payment type, not a backend provider ID.
133
- * // Use getBackendProviderId() to extract the correct backend ID from PaymentMethod.
134
- * ```
135
- */
136
- function validatePaymentId(id) {
137
- var normalizedTypes = [
138
- 'card',
139
- 'wallet',
140
- 'bank_transfer',
141
- 'buy_now_pay_later',
142
- 'cash_on_delivery',
143
- 'crypto',
144
- 'other'
145
- ];
146
- if (normalizedTypes.includes(id)) {
147
- throw new Error("Invalid payment provider ID: '".concat(id, "'. ") +
148
- "This appears to be a normalized payment type, not a backend provider ID. " +
149
- "Use getBackendProviderId() to extract the correct backend ID from PaymentMethod. " +
150
- "Expected format examples: 'pp_stripe_stripe', 'pp_system_default', 'shopify_payments', 'stripe'");
151
- }
152
- }