@thorprovider/adapters 4.3.0 → 5.0.1
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/AGENTS.md +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +53 -631
- package/dist/index.d.mts +52 -161
- package/dist/index.d.ts +52 -161
- package/dist/index.js +52 -395
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -395
- package/dist/index.mjs.map +1 -1
- package/docs/RETRY_SOLUTION_SUMMARY.md +1 -1
- package/docs/authentication.md +0 -26
- package/docs/capabilities-system.md +66 -36
- package/docs/getting-started.md +1 -1
- package/docs/providers-overview.md +16 -13
- package/docs/update-documentation.md +10 -8
- package/package.json +6 -5
- package/quick-reference.md +0 -33
- package/src/index.ts +4 -0
- package/src/providers/medusa/auth.test.ts +94 -92
- package/src/providers/medusa/auth.ts +72 -123
- package/src/providers/medusa/index.test.ts +392 -0
- package/src/providers/medusa/index.ts +1 -21
- package/src/providers/medusa/live-smoke.test.ts +412 -0
- package/src/providers/shopify/auth.ts +0 -6
- package/vitest.live.config.ts +18 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _thorprovider_types from '@thorprovider/types';
|
|
2
|
-
import { BackendCapabilities, Money, PaymentMethod, FulfillmentOption, CartItem, StockLocation, InventoryLevel, StorefrontConfig, DashboardMetrics, ProviderTypeString,
|
|
2
|
+
import { BackendCapabilities, Money, PaymentMethod, FulfillmentOption, CartItem, StockLocation, InventoryLevel, StorefrontConfig, DashboardMetrics, ProviderTypeString, CommerceProvider, AuthProvider, ProviderConfig, AuthConfig, Product, GetProductsOptions, AdvancedSearchProductsOptions, SearchResultMeta, FilterConfig, Collection, GetCollectionsOptions, CollectionProductsOptions, ProductCategory, GetCategoriesOptions, Cart, CartLineInput, CartLineUpdate, GetOrdersOptions, Order, GetCustomersOptions, Customer, Address, Region, AdminProduct, PaymentMethodsOptions, StockValidation, StorefrontContext, DesignerConfig, DesignerHistoryEntry, ShippingMethod, Country } from '@thorprovider/types';
|
|
3
3
|
export * from '@thorprovider/types';
|
|
4
4
|
export { BackendCapabilities, CommerceProvider, DesignerConfig, DesignerHistoryEntry, DesignerNavItem, DesignerThemeConfig, DesignerThemePreset, ProviderConfig, StorefrontConfig, StorefrontConfigError, StorefrontContext, StorefrontPlatformType, StorefrontSeoDefaults } from '@thorprovider/types';
|
|
5
5
|
import Medusa from '@medusajs/js-sdk';
|
|
@@ -322,6 +322,11 @@ declare class ProviderAPIError extends CommerceError {
|
|
|
322
322
|
readonly provider: string;
|
|
323
323
|
constructor(message: string, provider: string, status?: number);
|
|
324
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Extract error message from various error types
|
|
327
|
+
* Handles standard Error objects, API responses, and unknown error types
|
|
328
|
+
*/
|
|
329
|
+
declare function extractErrorMessage(error: unknown): string;
|
|
325
330
|
|
|
326
331
|
/**
|
|
327
332
|
* @thorprovider/adapters v2.0
|
|
@@ -377,6 +382,51 @@ interface RetryConfig {
|
|
|
377
382
|
*/
|
|
378
383
|
retryableStatusCodes?: number[];
|
|
379
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Enhanced fetch with retry logic and timeout
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { fetchWithRetry } from '@thorprovider/adapters/core/fetch-utils';
|
|
391
|
+
*
|
|
392
|
+
* // Basic usage with defaults (3 retries, 10s timeout)
|
|
393
|
+
* const response = await fetchWithRetry('https://api.example.com/products');
|
|
394
|
+
*
|
|
395
|
+
* // Custom configuration
|
|
396
|
+
* const response = await fetchWithRetry(
|
|
397
|
+
* 'https://api.example.com/products',
|
|
398
|
+
* {
|
|
399
|
+
* method: 'POST',
|
|
400
|
+
* body: JSON.stringify({ name: 'Product' }),
|
|
401
|
+
* },
|
|
402
|
+
* {
|
|
403
|
+
* maxRetries: 5,
|
|
404
|
+
* timeoutMs: 15000, // 15 seconds
|
|
405
|
+
* initialDelayMs: 500,
|
|
406
|
+
* }
|
|
407
|
+
* );
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
declare function fetchWithRetry(url: string, init?: RequestInit, retryConfig?: RetryConfig): Promise<Response>;
|
|
411
|
+
/**
|
|
412
|
+
* Create a fetch function with custom retry configuration
|
|
413
|
+
* Useful for creating a configured fetch instance
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* import { createFetchWithRetry } from '@thorprovider/adapters/core/fetch-utils';
|
|
418
|
+
*
|
|
419
|
+
* // Create configured fetch
|
|
420
|
+
* const customFetch = createFetchWithRetry({
|
|
421
|
+
* maxRetries: 5,
|
|
422
|
+
* timeoutMs: 15000,
|
|
423
|
+
* });
|
|
424
|
+
*
|
|
425
|
+
* // Use it like regular fetch
|
|
426
|
+
* const response = await customFetch('https://api.example.com/products');
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
declare function createFetchWithRetry(retryConfig?: RetryConfig): (url: string, init?: RequestInit) => Promise<Response>;
|
|
380
430
|
|
|
381
431
|
/**
|
|
382
432
|
* Circuit Breaker Pattern Implementation
|
|
@@ -1368,153 +1418,6 @@ declare function validateChannelScopeAssignment(entityId: string, channelId: str
|
|
|
1368
1418
|
*/
|
|
1369
1419
|
declare function assertEntityBelongsToChannel(entity: ChannelScopeable, expectedChannelId: string): void;
|
|
1370
1420
|
|
|
1371
|
-
/**
|
|
1372
|
-
* @fileoverview Medusa Multi-Tenant Admin Client
|
|
1373
|
-
* @module @thorprovider/adapters/providers/medusa/admin
|
|
1374
|
-
*
|
|
1375
|
-
* Wrapper methods for all `/admin/thor/` endpoints defined in the Thor Commerce
|
|
1376
|
-
* multi-tenant API contract. Requires an admin API key (`adminConfig.apiKey`)
|
|
1377
|
-
* to be provided when creating the Medusa provider.
|
|
1378
|
-
*
|
|
1379
|
-
* Every method performs a raw `fetch` against the Medusa backend using the
|
|
1380
|
-
* admin API key (`x-medusa-access-token`) — the Medusa JS-SDK's admin client
|
|
1381
|
-
* does not expose these custom Thor plugin routes, so we use direct HTTP calls.
|
|
1382
|
-
*
|
|
1383
|
-
* Endpoint reference: `multitenant-api-contract.md`
|
|
1384
|
-
*/
|
|
1385
|
-
|
|
1386
|
-
/**
|
|
1387
|
-
* Configuration required to instantiate the admin client.
|
|
1388
|
-
*/
|
|
1389
|
-
interface MedusaAdminClientConfig {
|
|
1390
|
-
/** Medusa backend base URL */
|
|
1391
|
-
baseUrl: string;
|
|
1392
|
-
/** Secret admin API key (x-medusa-access-token) */
|
|
1393
|
-
apiKey: string;
|
|
1394
|
-
/** Enable debug logging */
|
|
1395
|
-
debug?: boolean;
|
|
1396
|
-
}
|
|
1397
|
-
/**
|
|
1398
|
-
* HTTP client for Thor Commerce multi-tenant admin endpoints (`/admin/thor/`).
|
|
1399
|
-
*
|
|
1400
|
-
* All methods throw `ProviderAPIError` on non-2xx responses.
|
|
1401
|
-
*
|
|
1402
|
-
* @example
|
|
1403
|
-
* ```typescript
|
|
1404
|
-
* const admin = new MedusaAdminClient({
|
|
1405
|
-
* baseUrl: process.env.MEDUSA_BACKEND_URL!,
|
|
1406
|
-
* apiKey: process.env.MEDUSA_ADMIN_API_KEY!,
|
|
1407
|
-
* });
|
|
1408
|
-
*
|
|
1409
|
-
* const { customers } = await admin.getChannelCustomers('sc_01JXXXXX');
|
|
1410
|
-
* ```
|
|
1411
|
-
*/
|
|
1412
|
-
declare class MedusaAdminClient {
|
|
1413
|
-
private baseUrl;
|
|
1414
|
-
private apiKey;
|
|
1415
|
-
private logger;
|
|
1416
|
-
constructor(config: MedusaAdminClientConfig);
|
|
1417
|
-
private request;
|
|
1418
|
-
/**
|
|
1419
|
-
* Paginated list of customers linked to a sales channel.
|
|
1420
|
-
*
|
|
1421
|
-
* `GET /admin/thor/sales-channels/:id/customers`
|
|
1422
|
-
*/
|
|
1423
|
-
getChannelCustomers(salesChannelId: string, options?: GetChannelCustomersOptions): Promise<GetChannelCustomersResponse>;
|
|
1424
|
-
/**
|
|
1425
|
-
* Publishable API keys associated with a sales channel.
|
|
1426
|
-
*
|
|
1427
|
-
* `GET /admin/thor/sales-channels/:id/api-keys`
|
|
1428
|
-
*/
|
|
1429
|
-
getChannelApiKeys(salesChannelId: string): Promise<GetChannelApiKeysResponse>;
|
|
1430
|
-
/**
|
|
1431
|
-
* Product categories assigned to a sales channel.
|
|
1432
|
-
*
|
|
1433
|
-
* `GET /admin/thor/sales-channels/:id/categories`
|
|
1434
|
-
*/
|
|
1435
|
-
getChannelCategories(salesChannelId: string, options?: GetChannelCategoriesOptions): Promise<GetChannelCategoriesResponse>;
|
|
1436
|
-
/**
|
|
1437
|
-
* Sales channels to which a category is assigned.
|
|
1438
|
-
*
|
|
1439
|
-
* `GET /admin/thor/categories/:id/sales-channels`
|
|
1440
|
-
*/
|
|
1441
|
-
getCategorySalesChannels(categoryId: string): Promise<GetCategorySalesChannelsResponse>;
|
|
1442
|
-
/**
|
|
1443
|
-
* Assign a category to one or more sales channels (idempotent).
|
|
1444
|
-
*
|
|
1445
|
-
* `POST /admin/thor/categories/:id/sales-channels`
|
|
1446
|
-
*/
|
|
1447
|
-
assignCategoryToChannels(categoryId: string, body: AssignCategoriesToChannelsBody): Promise<AssignCategoriesToChannelsResponse>;
|
|
1448
|
-
/**
|
|
1449
|
-
* Remove category assignment from one or more sales channels (idempotent).
|
|
1450
|
-
*
|
|
1451
|
-
* `DELETE /admin/thor/categories/:id/sales-channels`
|
|
1452
|
-
*/
|
|
1453
|
-
unassignCategoryFromChannels(categoryId: string, body: UnassignCategoriesFromChannelsBody): Promise<UnassignCategoriesFromChannelsResponse>;
|
|
1454
|
-
/**
|
|
1455
|
-
* Sales channels to which a collection is assigned.
|
|
1456
|
-
*
|
|
1457
|
-
* `GET /admin/thor/collections/:id/sales-channels`
|
|
1458
|
-
*/
|
|
1459
|
-
getCollectionSalesChannels(collectionId: string): Promise<GetCollectionSalesChannelsResponse>;
|
|
1460
|
-
/**
|
|
1461
|
-
* Assign a collection to one or more sales channels (idempotent).
|
|
1462
|
-
*
|
|
1463
|
-
* `POST /admin/thor/collections/:id/sales-channels`
|
|
1464
|
-
*/
|
|
1465
|
-
assignCollectionToChannels(collectionId: string, body: AssignCollectionsToChannelsBody): Promise<AssignCollectionsToChannelsResponse>;
|
|
1466
|
-
/**
|
|
1467
|
-
* Remove collection assignment from one or more sales channels (idempotent).
|
|
1468
|
-
*
|
|
1469
|
-
* `DELETE /admin/thor/collections/:id/sales-channels`
|
|
1470
|
-
*/
|
|
1471
|
-
unassignCollectionFromChannels(collectionId: string, body: UnassignCollectionsFromChannelsBody): Promise<UnassignCollectionsFromChannelsResponse>;
|
|
1472
|
-
/**
|
|
1473
|
-
* Read the visual storefront configuration for a channel.
|
|
1474
|
-
* `:id` is the `sales_channel_id`.
|
|
1475
|
-
*
|
|
1476
|
-
* `GET /admin/thor/storefront-config/:id`
|
|
1477
|
-
*/
|
|
1478
|
-
getStorefrontConfig(salesChannelId: string): Promise<GetAdminStorefrontConfigResponse>;
|
|
1479
|
-
/**
|
|
1480
|
-
* Update the visual storefront configuration for a channel.
|
|
1481
|
-
* Triggers the `storefront_config.updated` event → ISR webhook.
|
|
1482
|
-
*
|
|
1483
|
-
* `PUT /admin/thor/storefront-config/:id`
|
|
1484
|
-
*/
|
|
1485
|
-
updateStorefrontConfig(salesChannelId: string, body: UpdateStorefrontConfigBody): Promise<UpdateStorefrontConfigResponse>;
|
|
1486
|
-
/**
|
|
1487
|
-
* Read the active Site Designer configuration for a channel, including the
|
|
1488
|
-
* last 10 history entries.
|
|
1489
|
-
*
|
|
1490
|
-
* `GET /admin/thor/site-config/:sales_channel_id`
|
|
1491
|
-
*/
|
|
1492
|
-
getSiteConfig(salesChannelId: string): Promise<GetAdminSiteConfigResponse>;
|
|
1493
|
-
/**
|
|
1494
|
-
* Update the Site Designer configuration for a channel.
|
|
1495
|
-
* Creates a new history entry on every PUT.
|
|
1496
|
-
*
|
|
1497
|
-
* `PUT /admin/thor/site-config/:sales_channel_id`
|
|
1498
|
-
*/
|
|
1499
|
-
updateSiteConfig(salesChannelId: string, body: UpdateSiteConfigBody): Promise<UpdateSiteConfigResponse>;
|
|
1500
|
-
/**
|
|
1501
|
-
* Full paginated history of Site Designer versions for a channel.
|
|
1502
|
-
* Entries are immutable — they are never deleted.
|
|
1503
|
-
*
|
|
1504
|
-
* `GET /admin/thor/site-config/:sales_channel_id/history`
|
|
1505
|
-
*/
|
|
1506
|
-
getSiteConfigHistory(salesChannelId: string, options?: GetAdminSiteConfigHistoryOptions): Promise<GetAdminSiteConfigHistoryResponse>;
|
|
1507
|
-
/**
|
|
1508
|
-
* Restore a previous Site Designer version.
|
|
1509
|
-
* Internally runs the update workflow with the stored config of the target
|
|
1510
|
-
* version — this creates a **new** history entry and does NOT mutate past
|
|
1511
|
-
* entries.
|
|
1512
|
-
*
|
|
1513
|
-
* `POST /admin/thor/site-config/:sales_channel_id/restore/:version`
|
|
1514
|
-
*/
|
|
1515
|
-
restoreSiteConfig(salesChannelId: string, version: string): Promise<RestoreSiteConfigResponse>;
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
1421
|
/**
|
|
1519
1422
|
* Medusa provider configuration
|
|
1520
1423
|
*/
|
|
@@ -1606,18 +1509,6 @@ declare class MedusaProvider implements CommerceProvider {
|
|
|
1606
1509
|
* Only created when adminConfig.apiKey is provided.
|
|
1607
1510
|
*/
|
|
1608
1511
|
private sdkAdmin?;
|
|
1609
|
-
/**
|
|
1610
|
-
* Admin client for Thor multi-tenant endpoints (`/admin/thor/`).
|
|
1611
|
-
* Available when `adminConfig.apiKey` is provided.
|
|
1612
|
-
*
|
|
1613
|
-
* @example
|
|
1614
|
-
* ```typescript
|
|
1615
|
-
* const { customers } = await commerce.admin.getChannelCustomers('sc_01JXXXXX');
|
|
1616
|
-
* const { api_keys } = await commerce.admin.getChannelApiKeys('sc_01JXXXXX');
|
|
1617
|
-
* await commerce.admin.updateStorefrontConfig('sc_01JXXXXX', { theme_accent_color: '#EF4444', ... });
|
|
1618
|
-
* ```
|
|
1619
|
-
*/
|
|
1620
|
-
readonly admin?: MedusaAdminClient;
|
|
1621
1512
|
/** Cached distinct product status values — rarely changes, cached for process lifetime */
|
|
1622
1513
|
private _cachedProductStatuses;
|
|
1623
1514
|
/**
|
|
@@ -2849,4 +2740,4 @@ declare function createProvider(options: ProviderFactoryConfig | RuntimeProvider
|
|
|
2849
2740
|
*/
|
|
2850
2741
|
declare function isProviderType<T extends ProviderType>(provider: CommerceProvider, type: T): boolean;
|
|
2851
2742
|
|
|
2852
|
-
export { AdminAuthService, type AdminSession, AdminSessionService, BIGCOMMERCE_CAPABILITIES, type BackendMapping, type BackendMetadataAdapter, type BackendMetadataAdapterConfig, BigCommerceProvider, type BigCommerceProviderConfig, CHANNEL_ASSIGNED_AT_KEY, CHANNEL_ASSIGNED_BY_KEY, CHANNEL_SCOPE_KEY, type ChannelScopeMetadata, ChannelScopeValidationError, type ChannelScopeable, CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitBreakerStats, type CircuitState, CommerceError, ConfigurationError, type Coordinates, type FulfillmentGroup, type FulfillmentPlan, type LogLevel, type Logger, MAGENTO_CAPABILITIES, MEDUSA_CAPABILITIES, MOCK_CAPABILITIES, MagentoProvider, type MagentoProviderConfig, MedusaMetadataAdapter, MedusaProvider, type MedusaProviderConfig, type MetricsOrderInput, type MetricsProductInput, MetricsService, MockProvider, type MockProviderConfig, type PlanFulfillmentShippingAddress, ProviderAPIError, type ProviderFactoryConfig, ProviderNotFoundError, type ProviderType, ResourceNotFoundError, SHOPIFY_CAPABILITIES, SPREE_CAPABILITIES, STELORDER_CAPABILITIES, ShopifyProvider, type ShopifyProviderConfig, SpreeProvider, type SpreeProviderConfig, StelOrderProvider, type StelOrderProviderConfig, type UICartItem, type UICartTotals, type UIDiscountCode, type UIPaymentMethod, type UIShippingMethod, WOOCOMMERCE_CAPABILITIES, WooCommerceProvider, type WooCommerceProviderConfig, assertEntityBelongsToChannel, backendCircuitBreaker, buildChannelScopeMetadata, calculateDistance, createBackendMetadataAdapter, createLogger, createProvider, filterByChannel, filterGlobalOnly, geocodeAddress, getBackendProviderId, getCapabilityDescription, getChannelScope, isBackendCapabilities, isGlobalEntity, isProviderType, isScopedToChannel, moneyToNumber, moneyToNumberSafe, numberToMoney, partitionByChannel, planFulfillment, transformFulfillmentOption, transformInventoryLevel, transformStockLocation, transformStorefrontConfig, validateAssignedBy, validateChannelId, validateChannelScopeAssignment, validateEntityId, validatePaymentId };
|
|
2743
|
+
export { AdminAuthService, type AdminSession, AdminSessionService, BIGCOMMERCE_CAPABILITIES, type BackendMapping, type BackendMetadataAdapter, type BackendMetadataAdapterConfig, BigCommerceProvider, type BigCommerceProviderConfig, CHANNEL_ASSIGNED_AT_KEY, CHANNEL_ASSIGNED_BY_KEY, CHANNEL_SCOPE_KEY, type ChannelScopeMetadata, ChannelScopeValidationError, type ChannelScopeable, CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitBreakerStats, type CircuitState, CommerceError, ConfigurationError, type Coordinates, type FulfillmentGroup, type FulfillmentPlan, type LogLevel, type Logger, MAGENTO_CAPABILITIES, MEDUSA_CAPABILITIES, MOCK_CAPABILITIES, MagentoProvider, type MagentoProviderConfig, MedusaMetadataAdapter, MedusaProvider, type MedusaProviderConfig, type MetricsOrderInput, type MetricsProductInput, MetricsService, MockProvider, type MockProviderConfig, type PlanFulfillmentShippingAddress, ProviderAPIError, type ProviderFactoryConfig, ProviderNotFoundError, type ProviderType, ResourceNotFoundError, type RetryConfig, SHOPIFY_CAPABILITIES, SPREE_CAPABILITIES, STELORDER_CAPABILITIES, ShopifyProvider, type ShopifyProviderConfig, SpreeProvider, type SpreeProviderConfig, StelOrderProvider, type StelOrderProviderConfig, type UICartItem, type UICartTotals, type UIDiscountCode, type UIPaymentMethod, type UIShippingMethod, WOOCOMMERCE_CAPABILITIES, WooCommerceProvider, type WooCommerceProviderConfig, assertEntityBelongsToChannel, backendCircuitBreaker, buildChannelScopeMetadata, calculateDistance, createBackendMetadataAdapter, createFetchWithRetry, createLogger, createProvider, extractErrorMessage, fetchWithRetry, filterByChannel, filterGlobalOnly, geocodeAddress, getBackendProviderId, getCapabilityDescription, getChannelScope, isBackendCapabilities, isGlobalEntity, isProviderType, isScopedToChannel, moneyToNumber, moneyToNumberSafe, numberToMoney, partitionByChannel, planFulfillment, transformFulfillmentOption, transformInventoryLevel, transformStockLocation, transformStorefrontConfig, validateAssignedBy, validateChannelId, validateChannelScopeAssignment, validateEntityId, validatePaymentId };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _thorprovider_types from '@thorprovider/types';
|
|
2
|
-
import { BackendCapabilities, Money, PaymentMethod, FulfillmentOption, CartItem, StockLocation, InventoryLevel, StorefrontConfig, DashboardMetrics, ProviderTypeString,
|
|
2
|
+
import { BackendCapabilities, Money, PaymentMethod, FulfillmentOption, CartItem, StockLocation, InventoryLevel, StorefrontConfig, DashboardMetrics, ProviderTypeString, CommerceProvider, AuthProvider, ProviderConfig, AuthConfig, Product, GetProductsOptions, AdvancedSearchProductsOptions, SearchResultMeta, FilterConfig, Collection, GetCollectionsOptions, CollectionProductsOptions, ProductCategory, GetCategoriesOptions, Cart, CartLineInput, CartLineUpdate, GetOrdersOptions, Order, GetCustomersOptions, Customer, Address, Region, AdminProduct, PaymentMethodsOptions, StockValidation, StorefrontContext, DesignerConfig, DesignerHistoryEntry, ShippingMethod, Country } from '@thorprovider/types';
|
|
3
3
|
export * from '@thorprovider/types';
|
|
4
4
|
export { BackendCapabilities, CommerceProvider, DesignerConfig, DesignerHistoryEntry, DesignerNavItem, DesignerThemeConfig, DesignerThemePreset, ProviderConfig, StorefrontConfig, StorefrontConfigError, StorefrontContext, StorefrontPlatformType, StorefrontSeoDefaults } from '@thorprovider/types';
|
|
5
5
|
import Medusa from '@medusajs/js-sdk';
|
|
@@ -322,6 +322,11 @@ declare class ProviderAPIError extends CommerceError {
|
|
|
322
322
|
readonly provider: string;
|
|
323
323
|
constructor(message: string, provider: string, status?: number);
|
|
324
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Extract error message from various error types
|
|
327
|
+
* Handles standard Error objects, API responses, and unknown error types
|
|
328
|
+
*/
|
|
329
|
+
declare function extractErrorMessage(error: unknown): string;
|
|
325
330
|
|
|
326
331
|
/**
|
|
327
332
|
* @thorprovider/adapters v2.0
|
|
@@ -377,6 +382,51 @@ interface RetryConfig {
|
|
|
377
382
|
*/
|
|
378
383
|
retryableStatusCodes?: number[];
|
|
379
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Enhanced fetch with retry logic and timeout
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { fetchWithRetry } from '@thorprovider/adapters/core/fetch-utils';
|
|
391
|
+
*
|
|
392
|
+
* // Basic usage with defaults (3 retries, 10s timeout)
|
|
393
|
+
* const response = await fetchWithRetry('https://api.example.com/products');
|
|
394
|
+
*
|
|
395
|
+
* // Custom configuration
|
|
396
|
+
* const response = await fetchWithRetry(
|
|
397
|
+
* 'https://api.example.com/products',
|
|
398
|
+
* {
|
|
399
|
+
* method: 'POST',
|
|
400
|
+
* body: JSON.stringify({ name: 'Product' }),
|
|
401
|
+
* },
|
|
402
|
+
* {
|
|
403
|
+
* maxRetries: 5,
|
|
404
|
+
* timeoutMs: 15000, // 15 seconds
|
|
405
|
+
* initialDelayMs: 500,
|
|
406
|
+
* }
|
|
407
|
+
* );
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
declare function fetchWithRetry(url: string, init?: RequestInit, retryConfig?: RetryConfig): Promise<Response>;
|
|
411
|
+
/**
|
|
412
|
+
* Create a fetch function with custom retry configuration
|
|
413
|
+
* Useful for creating a configured fetch instance
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* import { createFetchWithRetry } from '@thorprovider/adapters/core/fetch-utils';
|
|
418
|
+
*
|
|
419
|
+
* // Create configured fetch
|
|
420
|
+
* const customFetch = createFetchWithRetry({
|
|
421
|
+
* maxRetries: 5,
|
|
422
|
+
* timeoutMs: 15000,
|
|
423
|
+
* });
|
|
424
|
+
*
|
|
425
|
+
* // Use it like regular fetch
|
|
426
|
+
* const response = await customFetch('https://api.example.com/products');
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
declare function createFetchWithRetry(retryConfig?: RetryConfig): (url: string, init?: RequestInit) => Promise<Response>;
|
|
380
430
|
|
|
381
431
|
/**
|
|
382
432
|
* Circuit Breaker Pattern Implementation
|
|
@@ -1368,153 +1418,6 @@ declare function validateChannelScopeAssignment(entityId: string, channelId: str
|
|
|
1368
1418
|
*/
|
|
1369
1419
|
declare function assertEntityBelongsToChannel(entity: ChannelScopeable, expectedChannelId: string): void;
|
|
1370
1420
|
|
|
1371
|
-
/**
|
|
1372
|
-
* @fileoverview Medusa Multi-Tenant Admin Client
|
|
1373
|
-
* @module @thorprovider/adapters/providers/medusa/admin
|
|
1374
|
-
*
|
|
1375
|
-
* Wrapper methods for all `/admin/thor/` endpoints defined in the Thor Commerce
|
|
1376
|
-
* multi-tenant API contract. Requires an admin API key (`adminConfig.apiKey`)
|
|
1377
|
-
* to be provided when creating the Medusa provider.
|
|
1378
|
-
*
|
|
1379
|
-
* Every method performs a raw `fetch` against the Medusa backend using the
|
|
1380
|
-
* admin API key (`x-medusa-access-token`) — the Medusa JS-SDK's admin client
|
|
1381
|
-
* does not expose these custom Thor plugin routes, so we use direct HTTP calls.
|
|
1382
|
-
*
|
|
1383
|
-
* Endpoint reference: `multitenant-api-contract.md`
|
|
1384
|
-
*/
|
|
1385
|
-
|
|
1386
|
-
/**
|
|
1387
|
-
* Configuration required to instantiate the admin client.
|
|
1388
|
-
*/
|
|
1389
|
-
interface MedusaAdminClientConfig {
|
|
1390
|
-
/** Medusa backend base URL */
|
|
1391
|
-
baseUrl: string;
|
|
1392
|
-
/** Secret admin API key (x-medusa-access-token) */
|
|
1393
|
-
apiKey: string;
|
|
1394
|
-
/** Enable debug logging */
|
|
1395
|
-
debug?: boolean;
|
|
1396
|
-
}
|
|
1397
|
-
/**
|
|
1398
|
-
* HTTP client for Thor Commerce multi-tenant admin endpoints (`/admin/thor/`).
|
|
1399
|
-
*
|
|
1400
|
-
* All methods throw `ProviderAPIError` on non-2xx responses.
|
|
1401
|
-
*
|
|
1402
|
-
* @example
|
|
1403
|
-
* ```typescript
|
|
1404
|
-
* const admin = new MedusaAdminClient({
|
|
1405
|
-
* baseUrl: process.env.MEDUSA_BACKEND_URL!,
|
|
1406
|
-
* apiKey: process.env.MEDUSA_ADMIN_API_KEY!,
|
|
1407
|
-
* });
|
|
1408
|
-
*
|
|
1409
|
-
* const { customers } = await admin.getChannelCustomers('sc_01JXXXXX');
|
|
1410
|
-
* ```
|
|
1411
|
-
*/
|
|
1412
|
-
declare class MedusaAdminClient {
|
|
1413
|
-
private baseUrl;
|
|
1414
|
-
private apiKey;
|
|
1415
|
-
private logger;
|
|
1416
|
-
constructor(config: MedusaAdminClientConfig);
|
|
1417
|
-
private request;
|
|
1418
|
-
/**
|
|
1419
|
-
* Paginated list of customers linked to a sales channel.
|
|
1420
|
-
*
|
|
1421
|
-
* `GET /admin/thor/sales-channels/:id/customers`
|
|
1422
|
-
*/
|
|
1423
|
-
getChannelCustomers(salesChannelId: string, options?: GetChannelCustomersOptions): Promise<GetChannelCustomersResponse>;
|
|
1424
|
-
/**
|
|
1425
|
-
* Publishable API keys associated with a sales channel.
|
|
1426
|
-
*
|
|
1427
|
-
* `GET /admin/thor/sales-channels/:id/api-keys`
|
|
1428
|
-
*/
|
|
1429
|
-
getChannelApiKeys(salesChannelId: string): Promise<GetChannelApiKeysResponse>;
|
|
1430
|
-
/**
|
|
1431
|
-
* Product categories assigned to a sales channel.
|
|
1432
|
-
*
|
|
1433
|
-
* `GET /admin/thor/sales-channels/:id/categories`
|
|
1434
|
-
*/
|
|
1435
|
-
getChannelCategories(salesChannelId: string, options?: GetChannelCategoriesOptions): Promise<GetChannelCategoriesResponse>;
|
|
1436
|
-
/**
|
|
1437
|
-
* Sales channels to which a category is assigned.
|
|
1438
|
-
*
|
|
1439
|
-
* `GET /admin/thor/categories/:id/sales-channels`
|
|
1440
|
-
*/
|
|
1441
|
-
getCategorySalesChannels(categoryId: string): Promise<GetCategorySalesChannelsResponse>;
|
|
1442
|
-
/**
|
|
1443
|
-
* Assign a category to one or more sales channels (idempotent).
|
|
1444
|
-
*
|
|
1445
|
-
* `POST /admin/thor/categories/:id/sales-channels`
|
|
1446
|
-
*/
|
|
1447
|
-
assignCategoryToChannels(categoryId: string, body: AssignCategoriesToChannelsBody): Promise<AssignCategoriesToChannelsResponse>;
|
|
1448
|
-
/**
|
|
1449
|
-
* Remove category assignment from one or more sales channels (idempotent).
|
|
1450
|
-
*
|
|
1451
|
-
* `DELETE /admin/thor/categories/:id/sales-channels`
|
|
1452
|
-
*/
|
|
1453
|
-
unassignCategoryFromChannels(categoryId: string, body: UnassignCategoriesFromChannelsBody): Promise<UnassignCategoriesFromChannelsResponse>;
|
|
1454
|
-
/**
|
|
1455
|
-
* Sales channels to which a collection is assigned.
|
|
1456
|
-
*
|
|
1457
|
-
* `GET /admin/thor/collections/:id/sales-channels`
|
|
1458
|
-
*/
|
|
1459
|
-
getCollectionSalesChannels(collectionId: string): Promise<GetCollectionSalesChannelsResponse>;
|
|
1460
|
-
/**
|
|
1461
|
-
* Assign a collection to one or more sales channels (idempotent).
|
|
1462
|
-
*
|
|
1463
|
-
* `POST /admin/thor/collections/:id/sales-channels`
|
|
1464
|
-
*/
|
|
1465
|
-
assignCollectionToChannels(collectionId: string, body: AssignCollectionsToChannelsBody): Promise<AssignCollectionsToChannelsResponse>;
|
|
1466
|
-
/**
|
|
1467
|
-
* Remove collection assignment from one or more sales channels (idempotent).
|
|
1468
|
-
*
|
|
1469
|
-
* `DELETE /admin/thor/collections/:id/sales-channels`
|
|
1470
|
-
*/
|
|
1471
|
-
unassignCollectionFromChannels(collectionId: string, body: UnassignCollectionsFromChannelsBody): Promise<UnassignCollectionsFromChannelsResponse>;
|
|
1472
|
-
/**
|
|
1473
|
-
* Read the visual storefront configuration for a channel.
|
|
1474
|
-
* `:id` is the `sales_channel_id`.
|
|
1475
|
-
*
|
|
1476
|
-
* `GET /admin/thor/storefront-config/:id`
|
|
1477
|
-
*/
|
|
1478
|
-
getStorefrontConfig(salesChannelId: string): Promise<GetAdminStorefrontConfigResponse>;
|
|
1479
|
-
/**
|
|
1480
|
-
* Update the visual storefront configuration for a channel.
|
|
1481
|
-
* Triggers the `storefront_config.updated` event → ISR webhook.
|
|
1482
|
-
*
|
|
1483
|
-
* `PUT /admin/thor/storefront-config/:id`
|
|
1484
|
-
*/
|
|
1485
|
-
updateStorefrontConfig(salesChannelId: string, body: UpdateStorefrontConfigBody): Promise<UpdateStorefrontConfigResponse>;
|
|
1486
|
-
/**
|
|
1487
|
-
* Read the active Site Designer configuration for a channel, including the
|
|
1488
|
-
* last 10 history entries.
|
|
1489
|
-
*
|
|
1490
|
-
* `GET /admin/thor/site-config/:sales_channel_id`
|
|
1491
|
-
*/
|
|
1492
|
-
getSiteConfig(salesChannelId: string): Promise<GetAdminSiteConfigResponse>;
|
|
1493
|
-
/**
|
|
1494
|
-
* Update the Site Designer configuration for a channel.
|
|
1495
|
-
* Creates a new history entry on every PUT.
|
|
1496
|
-
*
|
|
1497
|
-
* `PUT /admin/thor/site-config/:sales_channel_id`
|
|
1498
|
-
*/
|
|
1499
|
-
updateSiteConfig(salesChannelId: string, body: UpdateSiteConfigBody): Promise<UpdateSiteConfigResponse>;
|
|
1500
|
-
/**
|
|
1501
|
-
* Full paginated history of Site Designer versions for a channel.
|
|
1502
|
-
* Entries are immutable — they are never deleted.
|
|
1503
|
-
*
|
|
1504
|
-
* `GET /admin/thor/site-config/:sales_channel_id/history`
|
|
1505
|
-
*/
|
|
1506
|
-
getSiteConfigHistory(salesChannelId: string, options?: GetAdminSiteConfigHistoryOptions): Promise<GetAdminSiteConfigHistoryResponse>;
|
|
1507
|
-
/**
|
|
1508
|
-
* Restore a previous Site Designer version.
|
|
1509
|
-
* Internally runs the update workflow with the stored config of the target
|
|
1510
|
-
* version — this creates a **new** history entry and does NOT mutate past
|
|
1511
|
-
* entries.
|
|
1512
|
-
*
|
|
1513
|
-
* `POST /admin/thor/site-config/:sales_channel_id/restore/:version`
|
|
1514
|
-
*/
|
|
1515
|
-
restoreSiteConfig(salesChannelId: string, version: string): Promise<RestoreSiteConfigResponse>;
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
1421
|
/**
|
|
1519
1422
|
* Medusa provider configuration
|
|
1520
1423
|
*/
|
|
@@ -1606,18 +1509,6 @@ declare class MedusaProvider implements CommerceProvider {
|
|
|
1606
1509
|
* Only created when adminConfig.apiKey is provided.
|
|
1607
1510
|
*/
|
|
1608
1511
|
private sdkAdmin?;
|
|
1609
|
-
/**
|
|
1610
|
-
* Admin client for Thor multi-tenant endpoints (`/admin/thor/`).
|
|
1611
|
-
* Available when `adminConfig.apiKey` is provided.
|
|
1612
|
-
*
|
|
1613
|
-
* @example
|
|
1614
|
-
* ```typescript
|
|
1615
|
-
* const { customers } = await commerce.admin.getChannelCustomers('sc_01JXXXXX');
|
|
1616
|
-
* const { api_keys } = await commerce.admin.getChannelApiKeys('sc_01JXXXXX');
|
|
1617
|
-
* await commerce.admin.updateStorefrontConfig('sc_01JXXXXX', { theme_accent_color: '#EF4444', ... });
|
|
1618
|
-
* ```
|
|
1619
|
-
*/
|
|
1620
|
-
readonly admin?: MedusaAdminClient;
|
|
1621
1512
|
/** Cached distinct product status values — rarely changes, cached for process lifetime */
|
|
1622
1513
|
private _cachedProductStatuses;
|
|
1623
1514
|
/**
|
|
@@ -2849,4 +2740,4 @@ declare function createProvider(options: ProviderFactoryConfig | RuntimeProvider
|
|
|
2849
2740
|
*/
|
|
2850
2741
|
declare function isProviderType<T extends ProviderType>(provider: CommerceProvider, type: T): boolean;
|
|
2851
2742
|
|
|
2852
|
-
export { AdminAuthService, type AdminSession, AdminSessionService, BIGCOMMERCE_CAPABILITIES, type BackendMapping, type BackendMetadataAdapter, type BackendMetadataAdapterConfig, BigCommerceProvider, type BigCommerceProviderConfig, CHANNEL_ASSIGNED_AT_KEY, CHANNEL_ASSIGNED_BY_KEY, CHANNEL_SCOPE_KEY, type ChannelScopeMetadata, ChannelScopeValidationError, type ChannelScopeable, CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitBreakerStats, type CircuitState, CommerceError, ConfigurationError, type Coordinates, type FulfillmentGroup, type FulfillmentPlan, type LogLevel, type Logger, MAGENTO_CAPABILITIES, MEDUSA_CAPABILITIES, MOCK_CAPABILITIES, MagentoProvider, type MagentoProviderConfig, MedusaMetadataAdapter, MedusaProvider, type MedusaProviderConfig, type MetricsOrderInput, type MetricsProductInput, MetricsService, MockProvider, type MockProviderConfig, type PlanFulfillmentShippingAddress, ProviderAPIError, type ProviderFactoryConfig, ProviderNotFoundError, type ProviderType, ResourceNotFoundError, SHOPIFY_CAPABILITIES, SPREE_CAPABILITIES, STELORDER_CAPABILITIES, ShopifyProvider, type ShopifyProviderConfig, SpreeProvider, type SpreeProviderConfig, StelOrderProvider, type StelOrderProviderConfig, type UICartItem, type UICartTotals, type UIDiscountCode, type UIPaymentMethod, type UIShippingMethod, WOOCOMMERCE_CAPABILITIES, WooCommerceProvider, type WooCommerceProviderConfig, assertEntityBelongsToChannel, backendCircuitBreaker, buildChannelScopeMetadata, calculateDistance, createBackendMetadataAdapter, createLogger, createProvider, filterByChannel, filterGlobalOnly, geocodeAddress, getBackendProviderId, getCapabilityDescription, getChannelScope, isBackendCapabilities, isGlobalEntity, isProviderType, isScopedToChannel, moneyToNumber, moneyToNumberSafe, numberToMoney, partitionByChannel, planFulfillment, transformFulfillmentOption, transformInventoryLevel, transformStockLocation, transformStorefrontConfig, validateAssignedBy, validateChannelId, validateChannelScopeAssignment, validateEntityId, validatePaymentId };
|
|
2743
|
+
export { AdminAuthService, type AdminSession, AdminSessionService, BIGCOMMERCE_CAPABILITIES, type BackendMapping, type BackendMetadataAdapter, type BackendMetadataAdapterConfig, BigCommerceProvider, type BigCommerceProviderConfig, CHANNEL_ASSIGNED_AT_KEY, CHANNEL_ASSIGNED_BY_KEY, CHANNEL_SCOPE_KEY, type ChannelScopeMetadata, ChannelScopeValidationError, type ChannelScopeable, CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitBreakerStats, type CircuitState, CommerceError, ConfigurationError, type Coordinates, type FulfillmentGroup, type FulfillmentPlan, type LogLevel, type Logger, MAGENTO_CAPABILITIES, MEDUSA_CAPABILITIES, MOCK_CAPABILITIES, MagentoProvider, type MagentoProviderConfig, MedusaMetadataAdapter, MedusaProvider, type MedusaProviderConfig, type MetricsOrderInput, type MetricsProductInput, MetricsService, MockProvider, type MockProviderConfig, type PlanFulfillmentShippingAddress, ProviderAPIError, type ProviderFactoryConfig, ProviderNotFoundError, type ProviderType, ResourceNotFoundError, type RetryConfig, SHOPIFY_CAPABILITIES, SPREE_CAPABILITIES, STELORDER_CAPABILITIES, ShopifyProvider, type ShopifyProviderConfig, SpreeProvider, type SpreeProviderConfig, StelOrderProvider, type StelOrderProviderConfig, type UICartItem, type UICartTotals, type UIDiscountCode, type UIPaymentMethod, type UIShippingMethod, WOOCOMMERCE_CAPABILITIES, WooCommerceProvider, type WooCommerceProviderConfig, assertEntityBelongsToChannel, backendCircuitBreaker, buildChannelScopeMetadata, calculateDistance, createBackendMetadataAdapter, createFetchWithRetry, createLogger, createProvider, extractErrorMessage, fetchWithRetry, filterByChannel, filterGlobalOnly, geocodeAddress, getBackendProviderId, getCapabilityDescription, getChannelScope, isBackendCapabilities, isGlobalEntity, isProviderType, isScopedToChannel, moneyToNumber, moneyToNumberSafe, numberToMoney, partitionByChannel, planFulfillment, transformFulfillmentOption, transformInventoryLevel, transformStockLocation, transformStorefrontConfig, validateAssignedBy, validateChannelId, validateChannelScopeAssignment, validateEntityId, validatePaymentId };
|