@thorprovider/types 5.7.10 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +8 -0
- package/dist/index.d.mts +425 -144
- package/dist/index.d.ts +425 -144
- package/dist/index.js +0 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +0 -125
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/admin/DropshippingAdmin.ts +0 -57
- package/src/cart.ts +40 -0
- package/src/catalog.ts +210 -0
- package/src/collection.ts +10 -0
- package/src/commerce-provider.ts +58 -1
- package/src/commerce.ts +88 -0
- package/src/index.ts +32 -18
- package/src/order.ts +33 -0
- package/src/product.ts +1 -0
- package/src/provider.ts +14 -178
- package/src/storefront.ts +5 -32
package/src/provider.ts
CHANGED
|
@@ -1,47 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @thorprovider/types — Supported Providers
|
|
2
|
+
* @thorprovider/types — Supported Providers (type-only)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* This is the single source of truth for provider types across the monorepo.
|
|
4
|
+
* Defines the provider-type union contract shared across the monorepo.
|
|
6
5
|
*
|
|
7
6
|
* @remarks
|
|
8
|
-
* - L1 (Foundation):
|
|
9
|
-
* - L2 (@thorprovider/adapters)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* All supported commerce platform providers.
|
|
22
|
-
* `mock` is the backend-optional runtime provider used for layout/design mode.
|
|
23
|
-
* `medusa` is fully implemented for real backend usage; others are placeholders for future expansion.
|
|
24
|
-
*
|
|
25
|
-
* @remarks Implementation status:
|
|
26
|
-
* - ✅ mock: Fixture-backed provider for backend-optional storefronts
|
|
27
|
-
* - ✅ medusa: Fully implemented
|
|
28
|
-
* - 🟡 stelorder: In progress (ERP adapter v1)
|
|
29
|
-
* - 🟡 shopify: Planned (Phase 2)
|
|
30
|
-
* - 🟡 bigcommerce: Planned (Phase 2)
|
|
31
|
-
* - 🟡 woocommerce: Planned (Phase 3)
|
|
32
|
-
* - 🟡 spree: Planned (Phase 3)
|
|
33
|
-
* - 🟡 magento: Planned (Phase 3)
|
|
7
|
+
* - L1 (Foundation): owns the `ProviderTypeString` union type only.
|
|
8
|
+
* - L2 (@thorprovider/adapters) owns the runtime provider registry
|
|
9
|
+
* (`SupportedProviderType`, `PROVIDER_METADATA`, `isSupportedProviderType`,
|
|
10
|
+
* `getProviderMetadata`) in `@thorprovider/adapters`.
|
|
11
|
+
*
|
|
12
|
+
* When adding a new provider:
|
|
13
|
+
* 1. Add the string to `ProviderTypeString` below.
|
|
14
|
+
* 2. Add it to `SupportedProviderType` + `PROVIDER_METADATA` in
|
|
15
|
+
* packages/adapters/src/factory/provider-types.ts.
|
|
16
|
+
* 3. Create packages/adapters/src/providers/[platform]/ and implement the
|
|
17
|
+
* `CommerceProvider` interface.
|
|
18
|
+
* 4. Update `StorefrontPlatformType` in storefront.ts.
|
|
34
19
|
*/
|
|
35
|
-
export enum SupportedProviderType {
|
|
36
|
-
Mock = 'mock',
|
|
37
|
-
Medusa = 'medusa',
|
|
38
|
-
StelOrder = 'stelorder',
|
|
39
|
-
Shopify = 'shopify',
|
|
40
|
-
BigCommerce = 'bigcommerce',
|
|
41
|
-
WooCommerce = 'woocommerce',
|
|
42
|
-
Spree = 'spree',
|
|
43
|
-
Magento = 'magento',
|
|
44
|
-
}
|
|
45
20
|
|
|
46
21
|
/**
|
|
47
22
|
* Union type of all supported provider string values.
|
|
@@ -55,142 +30,3 @@ export enum SupportedProviderType {
|
|
|
55
30
|
* ```
|
|
56
31
|
*/
|
|
57
32
|
export type ProviderTypeString = 'mock' | 'medusa' | 'stelorder' | 'shopify' | 'bigcommerce' | 'woocommerce' | 'spree' | 'magento';
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Metadata about each provider.
|
|
61
|
-
* Useful for UI, error messages, validation, and documentation.
|
|
62
|
-
*
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
export const PROVIDER_METADATA: Record<
|
|
66
|
-
ProviderTypeString,
|
|
67
|
-
{
|
|
68
|
-
name: string;
|
|
69
|
-
description: string;
|
|
70
|
-
requiresStorefront: boolean;
|
|
71
|
-
requiredEnvVars: string[];
|
|
72
|
-
maxRetries: number;
|
|
73
|
-
}
|
|
74
|
-
> = {
|
|
75
|
-
mock: {
|
|
76
|
-
name: 'Mock',
|
|
77
|
-
description: 'Fixture-backed runtime provider for layout/design mode without a real backend',
|
|
78
|
-
requiresStorefront: false,
|
|
79
|
-
requiredEnvVars: [],
|
|
80
|
-
maxRetries: 0,
|
|
81
|
-
},
|
|
82
|
-
medusa: {
|
|
83
|
-
name: 'Medusa JS',
|
|
84
|
-
description: 'Medusa v2 commerce engine',
|
|
85
|
-
requiresStorefront: true,
|
|
86
|
-
requiredEnvVars: [
|
|
87
|
-
'NEXT_PUBLIC_COMMERCE_API_URL',
|
|
88
|
-
'NEXT_PUBLIC_COMMERCE_API_KEY',
|
|
89
|
-
'NEXT_PUBLIC_SALES_CHANNEL_ID',
|
|
90
|
-
],
|
|
91
|
-
maxRetries: 3,
|
|
92
|
-
},
|
|
93
|
-
stelorder: {
|
|
94
|
-
name: 'Stel Order',
|
|
95
|
-
description: 'Stel Order ERP and sales document API',
|
|
96
|
-
requiresStorefront: false,
|
|
97
|
-
requiredEnvVars: [
|
|
98
|
-
'NEXT_PUBLIC_COMMERCE_API_URL',
|
|
99
|
-
'NEXT_PUBLIC_COMMERCE_API_KEY',
|
|
100
|
-
],
|
|
101
|
-
maxRetries: 2,
|
|
102
|
-
},
|
|
103
|
-
shopify: {
|
|
104
|
-
name: 'Shopify',
|
|
105
|
-
description: 'Shopify Storefront API (GraphQL)',
|
|
106
|
-
requiresStorefront: false,
|
|
107
|
-
requiredEnvVars: [
|
|
108
|
-
'NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN',
|
|
109
|
-
'NEXT_PUBLIC_SHOPIFY_STOREFRONT_TOKEN',
|
|
110
|
-
],
|
|
111
|
-
maxRetries: 3,
|
|
112
|
-
},
|
|
113
|
-
bigcommerce: {
|
|
114
|
-
name: 'BigCommerce',
|
|
115
|
-
description: 'BigCommerce REST Storefront API',
|
|
116
|
-
requiresStorefront: false,
|
|
117
|
-
requiredEnvVars: [
|
|
118
|
-
'BIGCOMMERCE_STORE_HASH',
|
|
119
|
-
'BIGCOMMERCE_STOREFRONT_API_TOKEN',
|
|
120
|
-
'BIGCOMMERCE_CHANNEL_ID',
|
|
121
|
-
],
|
|
122
|
-
maxRetries: 3,
|
|
123
|
-
},
|
|
124
|
-
woocommerce: {
|
|
125
|
-
name: 'WooCommerce',
|
|
126
|
-
description: 'WooCommerce Store API + REST API v3',
|
|
127
|
-
requiresStorefront: false,
|
|
128
|
-
requiredEnvVars: [
|
|
129
|
-
'WOOCOMMERCE_URL',
|
|
130
|
-
'WOOCOMMERCE_CONSUMER_KEY',
|
|
131
|
-
'WOOCOMMERCE_CONSUMER_SECRET',
|
|
132
|
-
],
|
|
133
|
-
maxRetries: 3,
|
|
134
|
-
},
|
|
135
|
-
spree: {
|
|
136
|
-
name: 'Spree Commerce',
|
|
137
|
-
description: 'Spree API v2 Storefront (JSON:API)',
|
|
138
|
-
requiresStorefront: false,
|
|
139
|
-
requiredEnvVars: [
|
|
140
|
-
'SPREE_API_URL',
|
|
141
|
-
],
|
|
142
|
-
maxRetries: 3,
|
|
143
|
-
},
|
|
144
|
-
magento: {
|
|
145
|
-
name: 'Adobe Commerce (Magento)',
|
|
146
|
-
description: 'Adobe Commerce GraphQL + REST API',
|
|
147
|
-
requiresStorefront: true,
|
|
148
|
-
requiredEnvVars: [
|
|
149
|
-
'MAGENTO_URL',
|
|
150
|
-
'MAGENTO_STORE_CODE',
|
|
151
|
-
],
|
|
152
|
-
maxRetries: 3,
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Check if a string is a valid provider type.
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* if (isSupportedProviderType(process.env.COMMERCE_PROVIDER)) {
|
|
162
|
-
* // type is narrowed to ProviderTypeString
|
|
163
|
-
* }
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
export function isSupportedProviderType(
|
|
167
|
-
value: unknown
|
|
168
|
-
): value is ProviderTypeString {
|
|
169
|
-
return (
|
|
170
|
-
typeof value === 'string' &&
|
|
171
|
-
Object.values(SupportedProviderType).includes(value as SupportedProviderType)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Get metadata for a provider type.
|
|
177
|
-
* Useful for validation, error messages, and logging.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* const meta = getProviderMetadata('medusa');
|
|
182
|
-
* console.log(`Using ${meta.name} with max ${meta.maxRetries} retries`);
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export function getProviderMetadata(
|
|
186
|
-
type: ProviderTypeString
|
|
187
|
-
): (typeof PROVIDER_METADATA)[ProviderTypeString] {
|
|
188
|
-
if (!isSupportedProviderType(type)) {
|
|
189
|
-
throw new Error(
|
|
190
|
-
`Unsupported provider: ${type}. Supported: ${Object.values(
|
|
191
|
-
SupportedProviderType
|
|
192
|
-
).join(', ')}`
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
return PROVIDER_METADATA[type];
|
|
196
|
-
}
|
package/src/storefront.ts
CHANGED
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
* Supported commerce platform types for storefront identification.
|
|
16
16
|
*
|
|
17
17
|
* @remarks
|
|
18
|
-
* Keep this type in sync with
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Keep this type in sync with ProviderTypeString from provider.ts and the
|
|
19
|
+
* runtime registry in @thorprovider/adapters
|
|
20
|
+
* (packages/adapters/src/factory/provider-types.ts).
|
|
21
|
+
* When adding a new provider, update packages/types/src/provider.ts, this
|
|
22
|
+
* type, and the adapters registry.
|
|
21
23
|
*
|
|
22
24
|
* Currently supported:
|
|
23
25
|
* - ✅ 'mock': Backend-optional layout/design mode using fixture data
|
|
@@ -98,32 +100,3 @@ export interface StorefrontContext {
|
|
|
98
100
|
*/
|
|
99
101
|
metadata?: Record<string, unknown>;
|
|
100
102
|
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Storefront validation error.
|
|
104
|
-
* Thrown when storefront configuration is invalid or missing.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* throw new StorefrontConfigError(
|
|
109
|
-
* 'Medusa requires NEXT_PUBLIC_SALES_CHANNEL_ID',
|
|
110
|
-
* 'medusa',
|
|
111
|
-
* 'NEXT_PUBLIC_SALES_CHANNEL_ID',
|
|
112
|
-
* );
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
export class StorefrontConfigError extends Error {
|
|
116
|
-
public readonly platformType: string;
|
|
117
|
-
public readonly requiredEnvVar?: string;
|
|
118
|
-
|
|
119
|
-
constructor(
|
|
120
|
-
message: string,
|
|
121
|
-
platformType: string,
|
|
122
|
-
requiredEnvVar?: string,
|
|
123
|
-
) {
|
|
124
|
-
super(message);
|
|
125
|
-
this.name = 'StorefrontConfigError';
|
|
126
|
-
this.platformType = platformType;
|
|
127
|
-
this.requiredEnvVar = requiredEnvVar;
|
|
128
|
-
}
|
|
129
|
-
}
|