@thorprovider/adapters 4.1.0 → 4.2.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/CHANGELOG.md +17 -0
- package/README.md +36 -2
- package/dist/index.d.mts +171 -2
- package/dist/index.d.ts +171 -2
- package/dist/index.js +2102 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2098 -0
- package/dist/index.mjs.map +1 -1
- package/docs/capabilities-system.md +30 -0
- package/docs/getting-started.md +32 -11
- package/docs/providers-overview.md +23 -3
- package/docs/services-overview.md +16 -0
- package/package.json +10 -6
- package/quick-reference.md +1 -0
- package/src/factory/index.ts +8 -0
- package/src/index.ts +6 -0
- package/src/providers/index.ts +6 -0
- package/src/providers/mock/index.ts +427 -0
- package/src/providers/mock/mock.ts +917 -0
- package/src/providers/stelorder/client.test-helpers.ts +3 -0
- package/src/providers/stelorder/client.test.ts +58 -0
- package/src/providers/stelorder/client.ts +326 -0
- package/src/providers/stelorder/index.test.ts +48 -0
- package/src/providers/stelorder/index.ts +685 -0
- package/src/providers/stelorder/live-smoke.test.ts +54 -0
- package/src/providers/stelorder/transforms.test.ts +103 -0
- package/src/providers/stelorder/transforms.ts +631 -0
- package/src/types/capabilities.types.ts +84 -0
- package/vitest.config.ts +13 -0
- package/vitest.setup.ts +6 -0
- package/.turbo/turbo-build.log +0 -18
- package/.turbo/turbo-test.log +0 -1
- package/.turbo/turbo-type-check.log +0 -0
- package/dist/.tsbuildinfo +0 -1
- package/publish.log +0 -93
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { StelOrderProvider } from './index'
|
|
3
|
+
|
|
4
|
+
const runLive = process.env.STEL_ORDER_SMOKE_TEST === '1'
|
|
5
|
+
|
|
6
|
+
function requiredEnv(name: string): string {
|
|
7
|
+
const value = process.env[name]
|
|
8
|
+
if (!value) {
|
|
9
|
+
throw new Error(`Missing required env var: ${name}`)
|
|
10
|
+
}
|
|
11
|
+
return value
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!runLive) {
|
|
15
|
+
describe('StelOrder live smoke', () => {
|
|
16
|
+
it.skip('disabled unless STEL_ORDER_SMOKE_TEST=1', () => {})
|
|
17
|
+
})
|
|
18
|
+
} else {
|
|
19
|
+
describe('StelOrder live smoke', () => {
|
|
20
|
+
const provider = new StelOrderProvider({
|
|
21
|
+
baseUrl: requiredEnv('STEL_ORDER_BASE_URL'),
|
|
22
|
+
apiKey: requiredEnv('STEL_ORDER_API_KEY'),
|
|
23
|
+
currencyCode: process.env.STEL_ORDER_CURRENCY_CODE ?? 'USD',
|
|
24
|
+
companyName: process.env.STEL_ORDER_COMPANY_NAME ?? 'Stel Smoke Test',
|
|
25
|
+
storefrontId: process.env.STEL_ORDER_STOREFRONT_ID ?? 'stel-smoke',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('fetches storefront context and read-only data', async () => {
|
|
29
|
+
await expect(provider.getStorefrontContext()).resolves.toMatchObject({
|
|
30
|
+
platformType: 'stelorder',
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
await expect(provider.getProducts({ first: 1 })).resolves.toBeInstanceOf(Array)
|
|
34
|
+
await expect(provider.getCategories({ limit: 1 })).resolves.toBeInstanceOf(Array)
|
|
35
|
+
await expect(provider.getPaymentMethods({})).resolves.toBeInstanceOf(Array)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('optionally updates a customer when a test customer id is provided', async () => {
|
|
39
|
+
const customerId = process.env.STEL_ORDER_TEST_CUSTOMER_ID
|
|
40
|
+
if (!customerId) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const customer = await provider.getCustomer(customerId)
|
|
45
|
+
expect(customer?.id).toBe(customerId)
|
|
46
|
+
|
|
47
|
+
const updated = await provider.updateCustomer(customerId, {
|
|
48
|
+
phone: process.env.STEL_ORDER_TEST_PHONE ?? customer?.phone ?? '+10000000000',
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
expect(updated.id).toBe(customerId)
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
buildStelHandle,
|
|
4
|
+
transformStelCategory,
|
|
5
|
+
transformStelClient,
|
|
6
|
+
transformStelDeliveryOption,
|
|
7
|
+
transformStelPaymentOption,
|
|
8
|
+
transformStelProduct,
|
|
9
|
+
transformStelSalesOrder,
|
|
10
|
+
transformStelWarehouseToStockLocation,
|
|
11
|
+
} from './transforms'
|
|
12
|
+
|
|
13
|
+
describe('stelorder transforms', () => {
|
|
14
|
+
it('transforms products into Thor products', () => {
|
|
15
|
+
const product = transformStelProduct(
|
|
16
|
+
{
|
|
17
|
+
id: 10,
|
|
18
|
+
name: 'Test Product',
|
|
19
|
+
description: 'Desc',
|
|
20
|
+
reference: 'TP-10',
|
|
21
|
+
'full-reference': 'TP-10',
|
|
22
|
+
'sales-price': 19.99,
|
|
23
|
+
'creation-date': '2026-01-01T10:00:00+00:00',
|
|
24
|
+
'utc-last-modification-date': '2026-01-02T10:00:00+00:00',
|
|
25
|
+
'stock-enabled': true,
|
|
26
|
+
'real-stock': 4,
|
|
27
|
+
'minimum-stock': 2,
|
|
28
|
+
},
|
|
29
|
+
'EUR',
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
expect(product.id).toBe('10')
|
|
33
|
+
expect(product.handle).toBe('tp-10')
|
|
34
|
+
expect(product.variants).toHaveLength(1)
|
|
35
|
+
expect(product.availableForSale).toBe(true)
|
|
36
|
+
expect(product.priceRange.minVariantPrice.amount).toBe('19.99')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('transforms category and collection shapes', () => {
|
|
40
|
+
const category = transformStelCategory({ id: 2, name: 'Hardware', slug: 'hardware' })
|
|
41
|
+
|
|
42
|
+
expect(category.id).toBe('2')
|
|
43
|
+
expect(category.handle).toBe('hardware')
|
|
44
|
+
expect(category.name).toBe('Hardware')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('transforms customer and order data', () => {
|
|
48
|
+
const customer = transformStelClient({
|
|
49
|
+
id: 7,
|
|
50
|
+
name: 'Ada Lovelace',
|
|
51
|
+
email: 'ada@example.com',
|
|
52
|
+
phone: '+1 555 0000',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
expect(customer.id).toBe('7')
|
|
56
|
+
expect(customer.firstName).toBe('Ada')
|
|
57
|
+
expect(customer.lastName).toBe('Lovelace')
|
|
58
|
+
|
|
59
|
+
const order = transformStelSalesOrder(
|
|
60
|
+
{
|
|
61
|
+
id: 99,
|
|
62
|
+
reference: 'SO-99',
|
|
63
|
+
email: 'ada@example.com',
|
|
64
|
+
status: 'settled',
|
|
65
|
+
'client-id': 7,
|
|
66
|
+
'creation-date': '2026-01-01T10:00:00+00:00',
|
|
67
|
+
'utc-last-modification-date': '2026-01-02T10:00:00+00:00',
|
|
68
|
+
'total-base': 50,
|
|
69
|
+
total: 59.5,
|
|
70
|
+
'document-lines': [
|
|
71
|
+
{
|
|
72
|
+
'item-id': 10,
|
|
73
|
+
'item-name': 'Test Product',
|
|
74
|
+
'item-base-price': 50,
|
|
75
|
+
units: 1,
|
|
76
|
+
'line-type': 'ITEM',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
'EUR',
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
expect(order.id).toBe('99')
|
|
84
|
+
expect(order.status).toBe('completed')
|
|
85
|
+
expect(order.paymentStatus).toBe('paid')
|
|
86
|
+
expect(order.items).toHaveLength(1)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('transforms payment and delivery options', () => {
|
|
90
|
+
expect(transformStelPaymentOption({ id: 1, name: 'Bank transfer' }).type).toBe('bank_transfer')
|
|
91
|
+
expect(transformStelDeliveryOption({ id: 2, name: 'Standard', description: '3-5 days' }, 'USD').price.amount).toBe('0.00')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('builds stable handles', () => {
|
|
95
|
+
expect(buildStelHandle('ABC 123')).toBe('abc-123')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('transforms stock location', () => {
|
|
99
|
+
const location = transformStelWarehouseToStockLocation({ id: 3, name: 'Main Warehouse' })
|
|
100
|
+
expect(location.id).toBe('3')
|
|
101
|
+
expect(location.name).toBe('Main Warehouse')
|
|
102
|
+
})
|
|
103
|
+
})
|