@thorprovider/adapters 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +6 -0
  3. package/README.md +53 -631
  4. package/dist/index.d.mts +406 -194
  5. package/dist/index.d.ts +406 -194
  6. package/dist/index.js +3092 -604
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +3081 -602
  9. package/dist/index.mjs.map +1 -1
  10. package/docs/RETRY_SOLUTION_SUMMARY.md +1 -1
  11. package/docs/authentication.md +0 -26
  12. package/docs/capabilities-system.md +66 -36
  13. package/docs/getting-started.md +1 -1
  14. package/docs/providers-overview.md +16 -13
  15. package/docs/update-documentation.md +10 -8
  16. package/package.json +6 -5
  17. package/quick-reference.md +0 -33
  18. package/src/backend/factory.ts +11 -1
  19. package/src/factory/index.ts +52 -74
  20. package/src/index.ts +17 -3
  21. package/src/providers/bigcommerce/bigcommerce.ts +6 -0
  22. package/src/providers/bigcommerce/index.ts +315 -0
  23. package/src/providers/bigcommerce/transforms.ts +227 -0
  24. package/src/providers/index.ts +16 -1
  25. package/src/providers/magento/index.ts +387 -0
  26. package/src/providers/magento/magento.ts +5 -0
  27. package/src/providers/magento/queries.ts +267 -0
  28. package/src/providers/magento/transforms.ts +249 -0
  29. package/src/providers/medusa/auth.test.ts +94 -92
  30. package/src/providers/medusa/auth.ts +72 -123
  31. package/src/providers/medusa/index.test.ts +392 -0
  32. package/src/providers/medusa/index.ts +1 -21
  33. package/src/providers/medusa/live-smoke.test.ts +412 -0
  34. package/src/providers/shopify/auth.ts +402 -0
  35. package/src/providers/shopify/index.ts +444 -0
  36. package/src/providers/shopify/mutations.ts +247 -0
  37. package/src/providers/shopify/queries.ts +324 -0
  38. package/src/providers/shopify/shopify.ts +7 -0
  39. package/src/providers/shopify/transforms.ts +275 -0
  40. package/src/providers/spree/index.ts +344 -0
  41. package/src/providers/spree/spree.ts +5 -0
  42. package/src/providers/spree/transforms.ts +254 -0
  43. package/src/providers/woocommerce/index.ts +310 -0
  44. package/src/providers/woocommerce/transforms.ts +254 -0
  45. package/src/providers/woocommerce/woocommerce.ts +5 -0
  46. package/src/types/capabilities.types.ts +250 -0
  47. 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, GetChannelCustomersOptions, GetChannelCustomersResponse, GetChannelApiKeysResponse, GetChannelCategoriesOptions, GetChannelCategoriesResponse, GetCategorySalesChannelsResponse, AssignCategoriesToChannelsBody, AssignCategoriesToChannelsResponse, UnassignCategoriesFromChannelsBody, UnassignCategoriesFromChannelsResponse, GetCollectionSalesChannelsResponse, AssignCollectionsToChannelsBody, AssignCollectionsToChannelsResponse, UnassignCollectionsFromChannelsBody, UnassignCollectionsFromChannelsResponse, GetAdminStorefrontConfigResponse, UpdateStorefrontConfigBody, UpdateStorefrontConfigResponse, GetAdminSiteConfigResponse, UpdateSiteConfigBody, UpdateSiteConfigResponse, GetAdminSiteConfigHistoryOptions, GetAdminSiteConfigHistoryResponse, RestoreSiteConfigResponse, 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, Country, ShippingMethod } from '@thorprovider/types';
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';
@@ -246,6 +246,36 @@ declare const MEDUSA_CAPABILITIES: Readonly<BackendCapabilities>;
246
246
  * but without cart, checkout, customer auth, or storefront-native payment flows.
247
247
  */
248
248
  declare const STELORDER_CAPABILITIES: Readonly<BackendCapabilities>;
249
+ /**
250
+ * Shopify backend capabilities
251
+ *
252
+ * @see https://shopify.dev/docs/api/storefront
253
+ */
254
+ declare const SHOPIFY_CAPABILITIES: Readonly<BackendCapabilities>;
255
+ /**
256
+ * BigCommerce backend capabilities
257
+ *
258
+ * @see https://developer.bigcommerce.com/docs/rest-storefront
259
+ */
260
+ declare const BIGCOMMERCE_CAPABILITIES: Readonly<BackendCapabilities>;
261
+ /**
262
+ * WooCommerce backend capabilities
263
+ *
264
+ * @see https://developer.woocommerce.com/docs/apis/store-api
265
+ */
266
+ declare const WOOCOMMERCE_CAPABILITIES: Readonly<BackendCapabilities>;
267
+ /**
268
+ * Spree Commerce backend capabilities
269
+ *
270
+ * @see https://docs.spreecommerce.org/api-reference
271
+ */
272
+ declare const SPREE_CAPABILITIES: Readonly<BackendCapabilities>;
273
+ /**
274
+ * Adobe Commerce / Magento backend capabilities
275
+ *
276
+ * @see https://developer.adobe.com/commerce/webapi/graphql/
277
+ */
278
+ declare const MAGENTO_CAPABILITIES: Readonly<BackendCapabilities>;
249
279
  /**
250
280
  * Type guard to check if an object is a valid BackendCapabilities
251
281
  */
@@ -378,6 +408,25 @@ interface RetryConfig {
378
408
  * ```
379
409
  */
380
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>;
381
430
 
382
431
  /**
383
432
  * Circuit Breaker Pattern Implementation
@@ -1369,153 +1418,6 @@ declare function validateChannelScopeAssignment(entityId: string, channelId: str
1369
1418
  */
1370
1419
  declare function assertEntityBelongsToChannel(entity: ChannelScopeable, expectedChannelId: string): void;
1371
1420
 
1372
- /**
1373
- * @fileoverview Medusa Multi-Tenant Admin Client
1374
- * @module @thorprovider/adapters/providers/medusa/admin
1375
- *
1376
- * Wrapper methods for all `/admin/thor/` endpoints defined in the Thor Commerce
1377
- * multi-tenant API contract. Requires an admin API key (`adminConfig.apiKey`)
1378
- * to be provided when creating the Medusa provider.
1379
- *
1380
- * Every method performs a raw `fetch` against the Medusa backend using the
1381
- * admin API key (`x-medusa-access-token`) — the Medusa JS-SDK's admin client
1382
- * does not expose these custom Thor plugin routes, so we use direct HTTP calls.
1383
- *
1384
- * Endpoint reference: `multitenant-api-contract.md`
1385
- */
1386
-
1387
- /**
1388
- * Configuration required to instantiate the admin client.
1389
- */
1390
- interface MedusaAdminClientConfig {
1391
- /** Medusa backend base URL */
1392
- baseUrl: string;
1393
- /** Secret admin API key (x-medusa-access-token) */
1394
- apiKey: string;
1395
- /** Enable debug logging */
1396
- debug?: boolean;
1397
- }
1398
- /**
1399
- * HTTP client for Thor Commerce multi-tenant admin endpoints (`/admin/thor/`).
1400
- *
1401
- * All methods throw `ProviderAPIError` on non-2xx responses.
1402
- *
1403
- * @example
1404
- * ```typescript
1405
- * const admin = new MedusaAdminClient({
1406
- * baseUrl: process.env.MEDUSA_BACKEND_URL!,
1407
- * apiKey: process.env.MEDUSA_ADMIN_API_KEY!,
1408
- * });
1409
- *
1410
- * const { customers } = await admin.getChannelCustomers('sc_01JXXXXX');
1411
- * ```
1412
- */
1413
- declare class MedusaAdminClient {
1414
- private baseUrl;
1415
- private apiKey;
1416
- private logger;
1417
- constructor(config: MedusaAdminClientConfig);
1418
- private request;
1419
- /**
1420
- * Paginated list of customers linked to a sales channel.
1421
- *
1422
- * `GET /admin/thor/sales-channels/:id/customers`
1423
- */
1424
- getChannelCustomers(salesChannelId: string, options?: GetChannelCustomersOptions): Promise<GetChannelCustomersResponse>;
1425
- /**
1426
- * Publishable API keys associated with a sales channel.
1427
- *
1428
- * `GET /admin/thor/sales-channels/:id/api-keys`
1429
- */
1430
- getChannelApiKeys(salesChannelId: string): Promise<GetChannelApiKeysResponse>;
1431
- /**
1432
- * Product categories assigned to a sales channel.
1433
- *
1434
- * `GET /admin/thor/sales-channels/:id/categories`
1435
- */
1436
- getChannelCategories(salesChannelId: string, options?: GetChannelCategoriesOptions): Promise<GetChannelCategoriesResponse>;
1437
- /**
1438
- * Sales channels to which a category is assigned.
1439
- *
1440
- * `GET /admin/thor/categories/:id/sales-channels`
1441
- */
1442
- getCategorySalesChannels(categoryId: string): Promise<GetCategorySalesChannelsResponse>;
1443
- /**
1444
- * Assign a category to one or more sales channels (idempotent).
1445
- *
1446
- * `POST /admin/thor/categories/:id/sales-channels`
1447
- */
1448
- assignCategoryToChannels(categoryId: string, body: AssignCategoriesToChannelsBody): Promise<AssignCategoriesToChannelsResponse>;
1449
- /**
1450
- * Remove category assignment from one or more sales channels (idempotent).
1451
- *
1452
- * `DELETE /admin/thor/categories/:id/sales-channels`
1453
- */
1454
- unassignCategoryFromChannels(categoryId: string, body: UnassignCategoriesFromChannelsBody): Promise<UnassignCategoriesFromChannelsResponse>;
1455
- /**
1456
- * Sales channels to which a collection is assigned.
1457
- *
1458
- * `GET /admin/thor/collections/:id/sales-channels`
1459
- */
1460
- getCollectionSalesChannels(collectionId: string): Promise<GetCollectionSalesChannelsResponse>;
1461
- /**
1462
- * Assign a collection to one or more sales channels (idempotent).
1463
- *
1464
- * `POST /admin/thor/collections/:id/sales-channels`
1465
- */
1466
- assignCollectionToChannels(collectionId: string, body: AssignCollectionsToChannelsBody): Promise<AssignCollectionsToChannelsResponse>;
1467
- /**
1468
- * Remove collection assignment from one or more sales channels (idempotent).
1469
- *
1470
- * `DELETE /admin/thor/collections/:id/sales-channels`
1471
- */
1472
- unassignCollectionFromChannels(collectionId: string, body: UnassignCollectionsFromChannelsBody): Promise<UnassignCollectionsFromChannelsResponse>;
1473
- /**
1474
- * Read the visual storefront configuration for a channel.
1475
- * `:id` is the `sales_channel_id`.
1476
- *
1477
- * `GET /admin/thor/storefront-config/:id`
1478
- */
1479
- getStorefrontConfig(salesChannelId: string): Promise<GetAdminStorefrontConfigResponse>;
1480
- /**
1481
- * Update the visual storefront configuration for a channel.
1482
- * Triggers the `storefront_config.updated` event → ISR webhook.
1483
- *
1484
- * `PUT /admin/thor/storefront-config/:id`
1485
- */
1486
- updateStorefrontConfig(salesChannelId: string, body: UpdateStorefrontConfigBody): Promise<UpdateStorefrontConfigResponse>;
1487
- /**
1488
- * Read the active Site Designer configuration for a channel, including the
1489
- * last 10 history entries.
1490
- *
1491
- * `GET /admin/thor/site-config/:sales_channel_id`
1492
- */
1493
- getSiteConfig(salesChannelId: string): Promise<GetAdminSiteConfigResponse>;
1494
- /**
1495
- * Update the Site Designer configuration for a channel.
1496
- * Creates a new history entry on every PUT.
1497
- *
1498
- * `PUT /admin/thor/site-config/:sales_channel_id`
1499
- */
1500
- updateSiteConfig(salesChannelId: string, body: UpdateSiteConfigBody): Promise<UpdateSiteConfigResponse>;
1501
- /**
1502
- * Full paginated history of Site Designer versions for a channel.
1503
- * Entries are immutable — they are never deleted.
1504
- *
1505
- * `GET /admin/thor/site-config/:sales_channel_id/history`
1506
- */
1507
- getSiteConfigHistory(salesChannelId: string, options?: GetAdminSiteConfigHistoryOptions): Promise<GetAdminSiteConfigHistoryResponse>;
1508
- /**
1509
- * Restore a previous Site Designer version.
1510
- * Internally runs the update workflow with the stored config of the target
1511
- * version — this creates a **new** history entry and does NOT mutate past
1512
- * entries.
1513
- *
1514
- * `POST /admin/thor/site-config/:sales_channel_id/restore/:version`
1515
- */
1516
- restoreSiteConfig(salesChannelId: string, version: string): Promise<RestoreSiteConfigResponse>;
1517
- }
1518
-
1519
1421
  /**
1520
1422
  * Medusa provider configuration
1521
1423
  */
@@ -1607,18 +1509,6 @@ declare class MedusaProvider implements CommerceProvider {
1607
1509
  * Only created when adminConfig.apiKey is provided.
1608
1510
  */
1609
1511
  private sdkAdmin?;
1610
- /**
1611
- * Admin client for Thor multi-tenant endpoints (`/admin/thor/`).
1612
- * Available when `adminConfig.apiKey` is provided.
1613
- *
1614
- * @example
1615
- * ```typescript
1616
- * const { customers } = await commerce.admin.getChannelCustomers('sc_01JXXXXX');
1617
- * const { api_keys } = await commerce.admin.getChannelApiKeys('sc_01JXXXXX');
1618
- * await commerce.admin.updateStorefrontConfig('sc_01JXXXXX', { theme_accent_color: '#EF4444', ... });
1619
- * ```
1620
- */
1621
- readonly admin?: MedusaAdminClient;
1622
1512
  /** Cached distinct product status values — rarely changes, cached for process lifetime */
1623
1513
  private _cachedProductStatuses;
1624
1514
  /**
@@ -2304,6 +2194,330 @@ declare class MedusaProvider implements CommerceProvider {
2304
2194
  }>;
2305
2195
  }
2306
2196
 
2197
+ /**
2198
+ * Shopify provider configuration
2199
+ */
2200
+ interface ShopifyProviderConfig extends ProviderConfig {
2201
+ /** Store domain (e.g., 'your-store.myshopify.com') */
2202
+ storeDomain: string;
2203
+ /** Public Storefront API access token */
2204
+ publicAccessToken: string;
2205
+ /** Private Storefront API access token (server-side only) */
2206
+ privateAccessToken?: string;
2207
+ /** API version (default: '2026-04') */
2208
+ apiVersion?: string;
2209
+ }
2210
+ /**
2211
+ * Shopify commerce provider
2212
+ *
2213
+ * Implements CommerceProvider for Shopify Storefront API.
2214
+ * Uses raw fetch + GraphQL queries (no SDK dependency to stay L2-pure).
2215
+ */
2216
+ declare class ShopifyProvider implements CommerceProvider {
2217
+ readonly name = "shopify";
2218
+ readonly version = "1.0.0";
2219
+ readonly capabilities: BackendCapabilities;
2220
+ private logger;
2221
+ private storeDomain;
2222
+ private apiVersion;
2223
+ private endpoint;
2224
+ private headers;
2225
+ constructor(config: ShopifyProviderConfig);
2226
+ private query;
2227
+ getProduct(handle: string): Promise<Product | undefined>;
2228
+ getProducts(options?: GetProductsOptions): Promise<Product[]>;
2229
+ getProductRecommendations(productId: string): Promise<Product[]>;
2230
+ getCollection(handle: string): Promise<Collection | undefined>;
2231
+ getCollections(options?: GetCollectionsOptions): Promise<Collection[]>;
2232
+ getCollectionProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2233
+ getCategory(): Promise<ProductCategory | undefined>;
2234
+ getCategories(): Promise<ProductCategory[]>;
2235
+ getCategoryProducts(): Promise<Product[]>;
2236
+ createCart(): Promise<Cart>;
2237
+ getCart(cartId: string): Promise<Cart | undefined>;
2238
+ addToCart(cartId: string, lines: CartLineInput[]): Promise<Cart>;
2239
+ removeFromCart(cartId: string, lineIds: string[]): Promise<Cart>;
2240
+ updateCart(cartId: string, lines: CartLineUpdate[]): Promise<Cart>;
2241
+ completeCheckout(_cartId: string): Promise<Order>;
2242
+ getShippingMethods(_cartId: string): Promise<ShippingMethod[]>;
2243
+ getRegionCountries(): Promise<_thorprovider_types.Country[]>;
2244
+ addShippingMethod(_cartId: string, _methodId: string): Promise<Cart>;
2245
+ initiatePaymentSession(_cartId: string, _providerId: string): Promise<void>;
2246
+ applyDiscountCode(cartId: string, code: string): Promise<Cart>;
2247
+ removeDiscountCode(cartId: string, _code: string): Promise<Cart>;
2248
+ getOrders(options: GetOrdersOptions): Promise<Order[]>;
2249
+ getPaymentMethods(_options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
2250
+ getStockLocations(): Promise<StockLocation[]>;
2251
+ checkInventoryLevels(): Promise<InventoryLevel[]>;
2252
+ validateCartStock(): Promise<StockValidation>;
2253
+ getFulfillmentOptions(): Promise<FulfillmentOption[]>;
2254
+ cancelOrder(_orderId: string): Promise<Order>;
2255
+ createFulfillment(_orderId: string): Promise<void>;
2256
+ createRefund(_orderId: string): Promise<void>;
2257
+ getAdminOrders(): Promise<{
2258
+ orders: Order[];
2259
+ count: number;
2260
+ }>;
2261
+ getStorefrontContext(): Promise<StorefrontContext>;
2262
+ isStorefrontRequired(): boolean;
2263
+ }
2264
+
2265
+ /**
2266
+ * BigCommerce provider configuration
2267
+ */
2268
+ interface BigCommerceProviderConfig extends ProviderConfig {
2269
+ /** BigCommerce store hash */
2270
+ storeHash: string;
2271
+ /** Storefront API token (JWT) */
2272
+ storefrontApiToken: string;
2273
+ /** Storefront API URL (usually https://store-{hash}.mybigcommerce.com) */
2274
+ storefrontApiUrl: string;
2275
+ /** Channel ID */
2276
+ channelId: string;
2277
+ /** Default currency code (default: 'USD') */
2278
+ currencyCode?: string;
2279
+ }
2280
+ declare class BigCommerceProvider implements CommerceProvider {
2281
+ readonly name = "bigcommerce";
2282
+ readonly version = "1.0.0";
2283
+ readonly capabilities: BackendCapabilities;
2284
+ private logger;
2285
+ private storefrontApiUrl;
2286
+ private storeHash;
2287
+ private channelId;
2288
+ private currencyCode;
2289
+ private headers;
2290
+ constructor(config: BigCommerceProviderConfig);
2291
+ private fetchApi;
2292
+ getProduct(handle: string): Promise<Product | undefined>;
2293
+ getProducts(options?: GetProductsOptions): Promise<Product[]>;
2294
+ getProductRecommendations(_productId: string): Promise<Product[]>;
2295
+ getCollection(handle: string): Promise<Collection | undefined>;
2296
+ getCollections(options?: GetCollectionsOptions): Promise<Collection[]>;
2297
+ getCollectionProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2298
+ getCategory(idOrHandle: string): Promise<ProductCategory | undefined>;
2299
+ getCategories(options?: GetCategoriesOptions): Promise<ProductCategory[]>;
2300
+ getCategoryProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2301
+ createCart(): Promise<Cart>;
2302
+ getCart(cartId: string): Promise<Cart | undefined>;
2303
+ addToCart(cartId: string, lines: CartLineInput[]): Promise<Cart>;
2304
+ removeFromCart(cartId: string, lineIds: string[]): Promise<Cart>;
2305
+ updateCart(cartId: string, lines: CartLineUpdate[]): Promise<Cart>;
2306
+ completeCheckout(_cartId: string): Promise<Order>;
2307
+ getShippingMethods(_cartId: string): Promise<ShippingMethod[]>;
2308
+ getRegionCountries(): Promise<_thorprovider_types.Country[]>;
2309
+ addShippingMethod(_cartId: string, _methodId: string): Promise<Cart>;
2310
+ initiatePaymentSession(_cartId: string, _providerId: string): Promise<void>;
2311
+ applyDiscountCode(cartId: string, code: string): Promise<Cart>;
2312
+ removeDiscountCode(cartId: string, code: string): Promise<Cart>;
2313
+ getOrders(_options: GetOrdersOptions): Promise<Order[]>;
2314
+ getPaymentMethods(_options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
2315
+ getStockLocations(): Promise<StockLocation[]>;
2316
+ checkInventoryLevels(): Promise<InventoryLevel[]>;
2317
+ validateCartStock(): Promise<StockValidation>;
2318
+ getFulfillmentOptions(): Promise<FulfillmentOption[]>;
2319
+ cancelOrder(_orderId: string): Promise<Order>;
2320
+ createFulfillment(_orderId: string): Promise<void>;
2321
+ createRefund(_orderId: string): Promise<void>;
2322
+ getAdminOrders(): Promise<{
2323
+ orders: Order[];
2324
+ count: number;
2325
+ }>;
2326
+ getStorefrontContext(): Promise<StorefrontContext>;
2327
+ isStorefrontRequired(): boolean;
2328
+ }
2329
+
2330
+ /**
2331
+ * WooCommerce provider configuration
2332
+ */
2333
+ interface WooCommerceProviderConfig extends ProviderConfig {
2334
+ /** WordPress site URL (e.g., 'https://mystore.com') */
2335
+ url: string;
2336
+ /** WooCommerce REST API consumer key (for authenticated operations) */
2337
+ consumerKey?: string;
2338
+ /** WooCommerce REST API consumer secret (for authenticated operations) */
2339
+ consumerSecret?: string;
2340
+ /** Default currency code (default: 'USD') */
2341
+ currencyCode?: string;
2342
+ }
2343
+ declare class WooCommerceProvider implements CommerceProvider {
2344
+ readonly name = "woocommerce";
2345
+ readonly version = "1.0.0";
2346
+ readonly capabilities: BackendCapabilities;
2347
+ private logger;
2348
+ private baseUrl;
2349
+ private storeApiBase;
2350
+ private restApiBase;
2351
+ private currencyCode;
2352
+ private authHeader?;
2353
+ constructor(config: WooCommerceProviderConfig);
2354
+ private storeApiFetch;
2355
+ private restApiFetch;
2356
+ getProduct(handle: string): Promise<Product | undefined>;
2357
+ getProducts(options?: GetProductsOptions): Promise<Product[]>;
2358
+ getProductRecommendations(_productId: string): Promise<Product[]>;
2359
+ getCollection(handle: string): Promise<Collection | undefined>;
2360
+ getCollections(options?: GetCollectionsOptions): Promise<Collection[]>;
2361
+ getCollectionProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2362
+ getCategory(idOrHandle: string): Promise<ProductCategory | undefined>;
2363
+ getCategories(options?: GetCategoriesOptions): Promise<ProductCategory[]>;
2364
+ getCategoryProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2365
+ createCart(): Promise<Cart>;
2366
+ getCart(_cartId: string): Promise<Cart | undefined>;
2367
+ addToCart(_cartId: string, lines: CartLineInput[]): Promise<Cart>;
2368
+ removeFromCart(_cartId: string, lineIds: string[]): Promise<Cart>;
2369
+ updateCart(_cartId: string, lines: CartLineUpdate[]): Promise<Cart>;
2370
+ completeCheckout(_cartId: string): Promise<Order>;
2371
+ getShippingMethods(_cartId: string): Promise<ShippingMethod[]>;
2372
+ getRegionCountries(): Promise<_thorprovider_types.Country[]>;
2373
+ addShippingMethod(_cartId: string, methodId: string): Promise<Cart>;
2374
+ initiatePaymentSession(_cartId: string, _providerId: string): Promise<void>;
2375
+ applyDiscountCode(_cartId: string, code: string): Promise<Cart>;
2376
+ removeDiscountCode(_cartId: string, code: string): Promise<Cart>;
2377
+ getOrders(_options: GetOrdersOptions): Promise<Order[]>;
2378
+ getPaymentMethods(_options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
2379
+ getStockLocations(): Promise<StockLocation[]>;
2380
+ checkInventoryLevels(): Promise<InventoryLevel[]>;
2381
+ validateCartStock(): Promise<StockValidation>;
2382
+ getFulfillmentOptions(): Promise<FulfillmentOption[]>;
2383
+ cancelOrder(_orderId: string): Promise<Order>;
2384
+ createFulfillment(_orderId: string): Promise<void>;
2385
+ createRefund(_orderId: string): Promise<void>;
2386
+ getAdminOrders(): Promise<{
2387
+ orders: Order[];
2388
+ count: number;
2389
+ }>;
2390
+ getStorefrontContext(): Promise<StorefrontContext>;
2391
+ isStorefrontRequired(): boolean;
2392
+ }
2393
+
2394
+ /**
2395
+ * Spree provider configuration
2396
+ */
2397
+ interface SpreeProviderConfig extends ProviderConfig {
2398
+ /** Spree store base URL (e.g., 'https://myspreestore.com') */
2399
+ baseUrl: string;
2400
+ /** Bearer token for authenticated operations (customer or OAuth) */
2401
+ bearerToken?: string;
2402
+ /** Default currency code (default: 'USD') */
2403
+ currencyCode?: string;
2404
+ }
2405
+ declare class SpreeProvider implements CommerceProvider {
2406
+ readonly name = "spree";
2407
+ readonly version = "1.0.0";
2408
+ readonly capabilities: BackendCapabilities;
2409
+ private logger;
2410
+ private baseUrl;
2411
+ private apiBase;
2412
+ private currencyCode;
2413
+ private bearerToken?;
2414
+ private orderToken?;
2415
+ constructor(config: SpreeProviderConfig);
2416
+ private apiFetch;
2417
+ getProduct(handle: string): Promise<Product | undefined>;
2418
+ getProducts(options?: GetProductsOptions): Promise<Product[]>;
2419
+ getProductRecommendations(_productId: string): Promise<Product[]>;
2420
+ getCollection(handle: string): Promise<Collection | undefined>;
2421
+ getCollections(options?: GetCollectionsOptions): Promise<Collection[]>;
2422
+ getCollectionProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2423
+ getCategory(handle: string): Promise<ProductCategory | undefined>;
2424
+ getCategories(options?: GetCategoriesOptions): Promise<ProductCategory[]>;
2425
+ getCategoryProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2426
+ createCart(): Promise<Cart>;
2427
+ getCart(_cartId: string): Promise<Cart | undefined>;
2428
+ addToCart(_cartId: string, lines: CartLineInput[]): Promise<Cart>;
2429
+ removeFromCart(_cartId: string, lineIds: string[]): Promise<Cart>;
2430
+ updateCart(_cartId: string, lines: CartLineUpdate[]): Promise<Cart>;
2431
+ completeCheckout(_cartId: string): Promise<Order>;
2432
+ getShippingMethods(_cartId: string): Promise<ShippingMethod[]>;
2433
+ getRegionCountries(): Promise<_thorprovider_types.Country[]>;
2434
+ addShippingMethod(_cartId: string, methodId: string): Promise<Cart>;
2435
+ initiatePaymentSession(_cartId: string, _providerId: string): Promise<void>;
2436
+ applyDiscountCode(_cartId: string, code: string): Promise<Cart>;
2437
+ removeDiscountCode(_cartId: string, code: string): Promise<Cart>;
2438
+ getOrders(_options: GetOrdersOptions): Promise<Order[]>;
2439
+ getPaymentMethods(_options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
2440
+ getStockLocations(): Promise<StockLocation[]>;
2441
+ checkInventoryLevels(): Promise<InventoryLevel[]>;
2442
+ validateCartStock(): Promise<StockValidation>;
2443
+ getFulfillmentOptions(): Promise<FulfillmentOption[]>;
2444
+ cancelOrder(_orderId: string): Promise<Order>;
2445
+ createFulfillment(_orderId: string): Promise<void>;
2446
+ createRefund(_orderId: string): Promise<void>;
2447
+ getAdminOrders(): Promise<{
2448
+ orders: Order[];
2449
+ count: number;
2450
+ }>;
2451
+ getStorefrontContext(): Promise<StorefrontContext>;
2452
+ isStorefrontRequired(): boolean;
2453
+ }
2454
+
2455
+ /**
2456
+ * Magento provider configuration
2457
+ */
2458
+ interface MagentoProviderConfig extends ProviderConfig {
2459
+ /** Magento base URL (e.g., 'https://mymagento.com') */
2460
+ baseUrl: string;
2461
+ /** Store code for multi-tenant (default: 'default') */
2462
+ storeCode?: string;
2463
+ /** Customer bearer token (for authenticated operations) */
2464
+ customerToken?: string;
2465
+ /** Integration access token (for admin-level operations) */
2466
+ accessToken?: string;
2467
+ /** Default currency code (default: 'USD') */
2468
+ currencyCode?: string;
2469
+ }
2470
+ declare class MagentoProvider implements CommerceProvider {
2471
+ readonly name = "magento";
2472
+ readonly version = "1.0.0";
2473
+ readonly capabilities: BackendCapabilities;
2474
+ private logger;
2475
+ private baseUrl;
2476
+ private storeCode;
2477
+ private currencyCode;
2478
+ private graphqlEndpoint;
2479
+ private customerToken?;
2480
+ private accessToken?;
2481
+ constructor(config: MagentoProviderConfig);
2482
+ private graphql;
2483
+ getProduct(handle: string): Promise<Product | undefined>;
2484
+ getProducts(options?: GetProductsOptions): Promise<Product[]>;
2485
+ getProductRecommendations(_productId: string): Promise<Product[]>;
2486
+ getCollection(handle: string): Promise<Collection | undefined>;
2487
+ getCollections(options?: GetCollectionsOptions): Promise<Collection[]>;
2488
+ getCollectionProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2489
+ getCategory(handle: string): Promise<ProductCategory | undefined>;
2490
+ getCategories(options?: GetCategoriesOptions): Promise<ProductCategory[]>;
2491
+ getCategoryProducts(handle: string, options?: CollectionProductsOptions): Promise<Product[]>;
2492
+ createCart(): Promise<Cart>;
2493
+ getCart(cartId: string): Promise<Cart | undefined>;
2494
+ addToCart(cartId: string, lines: CartLineInput[]): Promise<Cart>;
2495
+ removeFromCart(cartId: string, lineIds: string[]): Promise<Cart>;
2496
+ updateCart(cartId: string, lines: CartLineUpdate[]): Promise<Cart>;
2497
+ completeCheckout(_cartId: string): Promise<Order>;
2498
+ getShippingMethods(_cartId: string): Promise<ShippingMethod[]>;
2499
+ getRegionCountries(): Promise<_thorprovider_types.Country[]>;
2500
+ addShippingMethod(_cartId: string, _methodId: string): Promise<Cart>;
2501
+ initiatePaymentSession(_cartId: string, _providerId: string): Promise<void>;
2502
+ applyDiscountCode(cartId: string, code: string): Promise<Cart>;
2503
+ removeDiscountCode(cartId: string, _code: string): Promise<Cart>;
2504
+ getOrders(_options: GetOrdersOptions): Promise<Order[]>;
2505
+ getPaymentMethods(_options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
2506
+ getStockLocations(): Promise<StockLocation[]>;
2507
+ checkInventoryLevels(): Promise<InventoryLevel[]>;
2508
+ validateCartStock(): Promise<StockValidation>;
2509
+ getFulfillmentOptions(): Promise<FulfillmentOption[]>;
2510
+ cancelOrder(_orderId: string): Promise<Order>;
2511
+ createFulfillment(_orderId: string): Promise<void>;
2512
+ createRefund(_orderId: string): Promise<void>;
2513
+ getAdminOrders(): Promise<{
2514
+ orders: Order[];
2515
+ count: number;
2516
+ }>;
2517
+ getStorefrontContext(): Promise<StorefrontContext>;
2518
+ isStorefrontRequired(): boolean;
2519
+ }
2520
+
2307
2521
  interface StelOrderProviderConfig extends ProviderConfig {
2308
2522
  baseUrl: string;
2309
2523
  apiKey?: string;
@@ -2453,40 +2667,24 @@ declare class MockProvider implements CommerceProvider {
2453
2667
  }
2454
2668
 
2455
2669
  /**
2456
- * @thorprovider/adapters v5.0
2457
- * Provider Factory - Dynamic registry pattern
2458
- *
2459
- * Providers register themselves at import time via `registerProvider()`.
2460
- * The factory no longer statically imports every backend — only the ones
2461
- * the consumer explicitly imports will be available.
2670
+ * @thorprovider/adapters v2.0
2671
+ * Provider Factory - Create commerce providers dynamically
2462
2672
  *
2463
- * Built-in providers (medusa, stelorder, mock) are registered automatically.
2673
+ * This factory is bound to SupportedProviderType from @thorprovider/types (L1).
2674
+ * When adding a new provider:
2675
+ * 1. Update SupportedProviderType enum in packages/types/src/provider.ts
2676
+ * 2. Add new discriminated union case here
2677
+ * 3. Create packages/adapters/src/providers/[platform]/
2678
+ * 4. Implement CommerceProvider interface
2464
2679
  */
2465
2680
 
2466
- type ProviderFactory = (config: any) => CommerceProvider;
2467
- /**
2468
- * Register a provider factory for a given type string.
2469
- * Call this to make a provider available to `createProvider()`.
2470
- *
2471
- * @example
2472
- * ```ts
2473
- * import { registerProvider } from '@thorprovider/adapters';
2474
- * import { MyProvider } from './my-provider';
2475
- *
2476
- * registerProvider('my-provider', (config) => new MyProvider(config));
2477
- * ```
2478
- */
2479
- declare function registerProvider(type: string, factory: ProviderFactory): void;
2480
2681
  /**
2481
- * Get all registered provider type strings.
2682
+ * Supported provider types (imported from @thorprovider/types L1)
2683
+ * Kept for backward compatibility; prefer ProviderTypeString from @thorprovider/types
2482
2684
  */
2483
- declare function getRegisteredProviders(): string[];
2685
+ type ProviderType = ProviderTypeString;
2484
2686
  /**
2485
- * Supported provider types
2486
- */
2487
- type ProviderType = ProviderTypeString | (string & {});
2488
- /**
2489
- * Provider configuration discriminated union (built-in providers)
2687
+ * Provider configuration discriminated union
2490
2688
  */
2491
2689
  type ProviderFactoryConfig = {
2492
2690
  provider: 'mock';
@@ -2498,18 +2696,30 @@ type ProviderFactoryConfig = {
2498
2696
  provider: 'stelorder';
2499
2697
  config: StelOrderProviderConfig;
2500
2698
  } | {
2501
- provider: string;
2502
- config: Record<string, unknown>;
2699
+ provider: 'shopify';
2700
+ config: ShopifyProviderConfig;
2701
+ } | {
2702
+ provider: 'bigcommerce';
2703
+ config: BigCommerceProviderConfig;
2704
+ } | {
2705
+ provider: 'woocommerce';
2706
+ config: WooCommerceProviderConfig;
2707
+ } | {
2708
+ provider: 'spree';
2709
+ config: SpreeProviderConfig;
2710
+ } | {
2711
+ provider: 'magento';
2712
+ config: MagentoProviderConfig;
2503
2713
  };
2504
2714
  /**
2505
- * Runtime provider configuration (accepts any registered provider string)
2715
+ * Runtime provider configuration (accepts any ProviderTypeString from env vars)
2506
2716
  */
2507
2717
  type RuntimeProviderConfig = {
2508
- provider: string;
2718
+ provider: ProviderTypeString;
2509
2719
  config: Record<string, unknown>;
2510
2720
  };
2511
2721
  /**
2512
- * Create a commerce provider instance from the registry.
2722
+ * Create a commerce provider instance
2513
2723
  *
2514
2724
  * @example
2515
2725
  * ```ts
@@ -2520,6 +2730,8 @@ type RuntimeProviderConfig = {
2520
2730
  * publishableKey: process.env.MEDUSA_PUBLISHABLE_KEY,
2521
2731
  * }
2522
2732
  * });
2733
+ *
2734
+ * const products = await commerce.getProducts();
2523
2735
  * ```
2524
2736
  */
2525
2737
  declare function createProvider(options: ProviderFactoryConfig | RuntimeProviderConfig): CommerceProvider;
@@ -2528,4 +2740,4 @@ declare function createProvider(options: ProviderFactoryConfig | RuntimeProvider
2528
2740
  */
2529
2741
  declare function isProviderType<T extends ProviderType>(provider: CommerceProvider, type: T): boolean;
2530
2742
 
2531
- export { AdminAuthService, type AdminSession, AdminSessionService, type BackendMapping, type BackendMetadataAdapter, type BackendMetadataAdapterConfig, 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, MEDUSA_CAPABILITIES, MOCK_CAPABILITIES, MedusaMetadataAdapter, MedusaProvider, type MedusaProviderConfig, type MetricsOrderInput, type MetricsProductInput, MetricsService, MockProvider, type MockProviderConfig, type PlanFulfillmentShippingAddress, ProviderAPIError, type ProviderFactoryConfig, ProviderNotFoundError, type ProviderType, ResourceNotFoundError, type RetryConfig, STELORDER_CAPABILITIES, StelOrderProvider, type StelOrderProviderConfig, type UICartItem, type UICartTotals, type UIDiscountCode, type UIPaymentMethod, type UIShippingMethod, assertEntityBelongsToChannel, backendCircuitBreaker, buildChannelScopeMetadata, calculateDistance, createBackendMetadataAdapter, createLogger, createProvider, extractErrorMessage, fetchWithRetry, filterByChannel, filterGlobalOnly, geocodeAddress, getBackendProviderId, getCapabilityDescription, getChannelScope, getRegisteredProviders, isBackendCapabilities, isGlobalEntity, isProviderType, isScopedToChannel, moneyToNumber, moneyToNumberSafe, numberToMoney, partitionByChannel, planFulfillment, registerProvider, 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 };