@thorprovider/medusa-extended 1.11.0 → 1.11.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.
- package/README.md +0 -9
- package/dist/index.d.mts +1 -25
- package/dist/index.d.ts +1 -25
- package/dist/index.js +5 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/dropshipper.live-smoke.test.ts +1 -1
- package/src/dropshipper.test.ts +20 -110
- package/src/dropshipper.ts +4 -78
package/src/dropshipper.test.ts
CHANGED
|
@@ -66,109 +66,6 @@ describe('DropshipperClient.onboardDropshipper', () => {
|
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
// Variant Costs (Solo X)
|
|
71
|
-
// ---------------------------------------------------------------------------
|
|
72
|
-
|
|
73
|
-
describe('DropshipperClient.getVariantCosts', () => {
|
|
74
|
-
it('GET /admin/thor/dropshipper/variant-costs with defaults', async () => {
|
|
75
|
-
server.use(
|
|
76
|
-
http.get(`${BASE}/admin/thor/dropshipper/variant-costs`, ({ request }) => {
|
|
77
|
-
requireBearerToken(request)
|
|
78
|
-
const url = new URL(request.url)
|
|
79
|
-
expect(url.searchParams.get('limit')).toBe('20')
|
|
80
|
-
expect(url.searchParams.get('offset')).toBe('0')
|
|
81
|
-
return HttpResponse.json({ variant_costs: [], count: 0, offset: 0, limit: 20 })
|
|
82
|
-
}),
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
const result = await client().getVariantCosts()
|
|
86
|
-
expect(result.count).toBe(0)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('forwards account_id and currency_code filters', async () => {
|
|
90
|
-
server.use(
|
|
91
|
-
http.get(`${BASE}/admin/thor/dropshipper/variant-costs`, ({ request }) => {
|
|
92
|
-
const url = new URL(request.url)
|
|
93
|
-
expect(url.searchParams.get('account_id')).toBe('acc_01')
|
|
94
|
-
expect(url.searchParams.get('currency_code')).toBe('usd')
|
|
95
|
-
return HttpResponse.json({ variant_costs: [], count: 0, offset: 0, limit: 20 })
|
|
96
|
-
}),
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
await client().getVariantCosts({ account_id: 'acc_01', currency_code: 'usd' })
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
describe('DropshipperClient.createVariantCost', () => {
|
|
104
|
-
it('POST /admin/thor/dropshipper/variant-costs', async () => {
|
|
105
|
-
server.use(
|
|
106
|
-
http.post(`${BASE}/admin/thor/dropshipper/variant-costs`, async ({ request }) => {
|
|
107
|
-
requireBearerToken(request)
|
|
108
|
-
const body = await request.json() as any
|
|
109
|
-
expect(body.variant_id).toBe('var_1')
|
|
110
|
-
return HttpResponse.json({
|
|
111
|
-
variant_cost: {
|
|
112
|
-
id: 'vc_1',
|
|
113
|
-
account_id: 'acc_01',
|
|
114
|
-
variant_id: 'var_1',
|
|
115
|
-
cost_amount: 1000,
|
|
116
|
-
currency_code: 'usd',
|
|
117
|
-
updated_at: '2026-01-01T00:00:00Z',
|
|
118
|
-
},
|
|
119
|
-
})
|
|
120
|
-
}),
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
const result = await client().createVariantCost({
|
|
124
|
-
account_id: 'acc_01',
|
|
125
|
-
variant_id: 'var_1',
|
|
126
|
-
cost_amount: 1000,
|
|
127
|
-
currency_code: 'usd',
|
|
128
|
-
})
|
|
129
|
-
expect(result.variant_cost.id).toBe('vc_1')
|
|
130
|
-
})
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
describe('DropshipperClient.batchVariantCosts', () => {
|
|
134
|
-
it('POST /admin/thor/dropshipper/variant-costs/batch', async () => {
|
|
135
|
-
server.use(
|
|
136
|
-
http.post(`${BASE}/admin/thor/dropshipper/variant-costs/batch`, async ({ request }) => {
|
|
137
|
-
requireBearerToken(request)
|
|
138
|
-
const body = await request.json() as any
|
|
139
|
-
expect(body.costs).toHaveLength(2)
|
|
140
|
-
return HttpResponse.json({ updated: 2, errors: [] })
|
|
141
|
-
}),
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
const result = await client().batchVariantCosts({
|
|
145
|
-
account_id: 'acc_01',
|
|
146
|
-
currency_code: 'usd',
|
|
147
|
-
costs: [
|
|
148
|
-
{ variant_id: 'var_1', cost_amount: 1000 },
|
|
149
|
-
{ variant_id: 'var_2', cost_amount: 2000 },
|
|
150
|
-
],
|
|
151
|
-
})
|
|
152
|
-
expect(result.updated).toBe(2)
|
|
153
|
-
expect(result.errors).toHaveLength(0)
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
describe('DropshipperClient.deleteVariantCost', () => {
|
|
158
|
-
it('DELETE /admin/thor/dropshipper/variant-costs/:id', async () => {
|
|
159
|
-
server.use(
|
|
160
|
-
http.delete(`${BASE}/admin/thor/dropshipper/variant-costs/vc_1`, ({ request }) => {
|
|
161
|
-
requireBearerToken(request)
|
|
162
|
-
return HttpResponse.json({ deleted: true, id: 'vc_1' })
|
|
163
|
-
}),
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
const result = await client().deleteVariantCost('vc_1')
|
|
167
|
-
expect(result.deleted).toBe(true)
|
|
168
|
-
expect(result.id).toBe('vc_1')
|
|
169
|
-
})
|
|
170
|
-
})
|
|
171
|
-
|
|
172
69
|
// ---------------------------------------------------------------------------
|
|
173
70
|
// Products (Solo Y)
|
|
174
71
|
// ---------------------------------------------------------------------------
|
|
@@ -188,17 +85,18 @@ describe('DropshipperClient.getProducts', () => {
|
|
|
188
85
|
expect(result.products).toHaveLength(0)
|
|
189
86
|
})
|
|
190
87
|
|
|
191
|
-
it('forwards search and
|
|
88
|
+
it('forwards search, category, and collection filters', async () => {
|
|
192
89
|
server.use(
|
|
193
90
|
http.get(`${BASE}/admin/thor/dropshipper/products`, ({ request }) => {
|
|
194
91
|
const url = new URL(request.url)
|
|
195
92
|
expect(url.searchParams.get('q')).toBe('shirt')
|
|
196
93
|
expect(url.searchParams.get('category_id')).toBe('cat_1')
|
|
94
|
+
expect(url.searchParams.get('collection_id')).toBe('coll_1')
|
|
197
95
|
return HttpResponse.json({ products: [], count: 0, offset: 0, limit: 20 })
|
|
198
96
|
}),
|
|
199
97
|
)
|
|
200
98
|
|
|
201
|
-
await client().getProducts({ q: 'shirt', category_id: 'cat_1' })
|
|
99
|
+
await client().getProducts({ q: 'shirt', category_id: 'cat_1', collection_id: 'coll_1' })
|
|
202
100
|
})
|
|
203
101
|
})
|
|
204
102
|
|
|
@@ -266,7 +164,7 @@ describe('DropshipperClient.updatePrices', () => {
|
|
|
266
164
|
|
|
267
165
|
const result = await client().updatePrices({
|
|
268
166
|
currency_code: 'usd',
|
|
269
|
-
prices: [{ variant_id: 'var_1',
|
|
167
|
+
prices: [{ variant_id: 'var_1', margin_percent: 50 }],
|
|
270
168
|
})
|
|
271
169
|
expect(result.updated).toBe(1)
|
|
272
170
|
expect(result.account_id).toBe('acc_01')
|
|
@@ -280,7 +178,7 @@ describe('DropshipperClient.updatePrices', () => {
|
|
|
280
178
|
expect(body.currency_code).toBe('usd')
|
|
281
179
|
expect(body.prices).toHaveLength(1)
|
|
282
180
|
expect(body.prices[0].tiers).toHaveLength(2)
|
|
283
|
-
expect(body.prices[0].tiers[0].
|
|
181
|
+
expect(body.prices[0].tiers[0].margin_percent).toBe(30)
|
|
284
182
|
expect(body.prices[0].tiers[0].minQuantity).toBe(5)
|
|
285
183
|
return HttpResponse.json({ updated: 1, account_id: 'acc_01' })
|
|
286
184
|
}),
|
|
@@ -290,10 +188,10 @@ describe('DropshipperClient.updatePrices', () => {
|
|
|
290
188
|
currency_code: 'usd',
|
|
291
189
|
prices: [{
|
|
292
190
|
variant_id: 'var_1',
|
|
293
|
-
|
|
191
|
+
margin_percent: 50,
|
|
294
192
|
tiers: [
|
|
295
|
-
{
|
|
296
|
-
{
|
|
193
|
+
{ margin_percent: 30, minQuantity: 5, maxQuantity: 10 },
|
|
194
|
+
{ margin_percent: 20, minQuantity: 11 },
|
|
297
195
|
],
|
|
298
196
|
}],
|
|
299
197
|
})
|
|
@@ -331,6 +229,18 @@ describe('DropshipperClient.getOrders', () => {
|
|
|
331
229
|
|
|
332
230
|
await client().getOrders({ status: 'completed', settlement_status: 'unsettled' })
|
|
333
231
|
})
|
|
232
|
+
|
|
233
|
+
it('forwards customer_id filter', async () => {
|
|
234
|
+
server.use(
|
|
235
|
+
http.get(`${BASE}/admin/thor/dropshipper/orders`, ({ request }) => {
|
|
236
|
+
const url = new URL(request.url)
|
|
237
|
+
expect(url.searchParams.get('customer_id')).toBe('cus_1')
|
|
238
|
+
return HttpResponse.json({ orders: [], count: 0, offset: 0, limit: 20 })
|
|
239
|
+
}),
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
await client().getOrders({ customer_id: 'cus_1' })
|
|
243
|
+
})
|
|
334
244
|
})
|
|
335
245
|
|
|
336
246
|
describe('DropshipperClient.getOrder', () => {
|
package/src/dropshipper.ts
CHANGED
|
@@ -18,14 +18,6 @@ import type {
|
|
|
18
18
|
// Onboarding
|
|
19
19
|
OnboardDropshipperBody,
|
|
20
20
|
OnboardDropshipperResponse,
|
|
21
|
-
// Variant Costs
|
|
22
|
-
GetVariantCostsOptions,
|
|
23
|
-
GetVariantCostsResponse,
|
|
24
|
-
CreateVariantCostBody,
|
|
25
|
-
CreateVariantCostResponse,
|
|
26
|
-
BatchVariantCostsBody,
|
|
27
|
-
BatchVariantCostsResponse,
|
|
28
|
-
DeleteVariantCostResponse,
|
|
29
21
|
// Products & Prices
|
|
30
22
|
DropshipperCostTier,
|
|
31
23
|
DropshipperSaleTier,
|
|
@@ -380,74 +372,6 @@ export class DropshipperClient {
|
|
|
380
372
|
);
|
|
381
373
|
}
|
|
382
374
|
|
|
383
|
-
// -------------------------------------------------------------------------
|
|
384
|
-
// Variant Costs (Solo X)
|
|
385
|
-
// -------------------------------------------------------------------------
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* List variant cost records, optionally filtered by account/variant/currency.
|
|
389
|
-
*
|
|
390
|
-
* `GET /admin/thor/dropshipper/variant-costs`
|
|
391
|
-
*/
|
|
392
|
-
async getVariantCosts(
|
|
393
|
-
options: GetVariantCostsOptions = {},
|
|
394
|
-
): Promise<GetVariantCostsResponse> {
|
|
395
|
-
const { account_id, variant_id, currency_code, limit = 20, offset = 0 } = options;
|
|
396
|
-
const qs = new URLSearchParams({
|
|
397
|
-
limit: String(limit),
|
|
398
|
-
offset: String(offset),
|
|
399
|
-
...(account_id ? { account_id } : {}),
|
|
400
|
-
...(variant_id ? { variant_id } : {}),
|
|
401
|
-
...(currency_code ? { currency_code } : {}),
|
|
402
|
-
});
|
|
403
|
-
return this.request<GetVariantCostsResponse>(
|
|
404
|
-
'GET',
|
|
405
|
-
`/admin/thor/dropshipper/variant-costs?${qs}`,
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Upsert a single variant cost record.
|
|
411
|
-
*
|
|
412
|
-
* `POST /admin/thor/dropshipper/variant-costs`
|
|
413
|
-
*/
|
|
414
|
-
async createVariantCost(
|
|
415
|
-
body: CreateVariantCostBody,
|
|
416
|
-
): Promise<CreateVariantCostResponse> {
|
|
417
|
-
return this.request<CreateVariantCostResponse>(
|
|
418
|
-
'POST',
|
|
419
|
-
'/admin/thor/dropshipper/variant-costs',
|
|
420
|
-
body,
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* Batch-upsert variant costs for a given account and currency.
|
|
426
|
-
*
|
|
427
|
-
* `POST /admin/thor/dropshipper/variant-costs/batch`
|
|
428
|
-
*/
|
|
429
|
-
async batchVariantCosts(
|
|
430
|
-
body: BatchVariantCostsBody,
|
|
431
|
-
): Promise<BatchVariantCostsResponse> {
|
|
432
|
-
return this.request<BatchVariantCostsResponse>(
|
|
433
|
-
'POST',
|
|
434
|
-
'/admin/thor/dropshipper/variant-costs/batch',
|
|
435
|
-
body,
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Delete a variant cost record by ID.
|
|
441
|
-
*
|
|
442
|
-
* `DELETE /admin/thor/dropshipper/variant-costs/:id`
|
|
443
|
-
*/
|
|
444
|
-
async deleteVariantCost(id: string): Promise<DeleteVariantCostResponse> {
|
|
445
|
-
return this.request<DeleteVariantCostResponse>(
|
|
446
|
-
'DELETE',
|
|
447
|
-
`/admin/thor/dropshipper/variant-costs/${id}`,
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
375
|
// -------------------------------------------------------------------------
|
|
452
376
|
// Products (Solo Y)
|
|
453
377
|
// -------------------------------------------------------------------------
|
|
@@ -460,12 +384,13 @@ export class DropshipperClient {
|
|
|
460
384
|
async getProducts(
|
|
461
385
|
options: GetDropshipperProductsOptions = {},
|
|
462
386
|
): Promise<GetDropshipperProductsResponse> {
|
|
463
|
-
const { q, category_id, status, in_stock, limit = 20, offset = 0 } = options;
|
|
387
|
+
const { q, category_id, collection_id, status, in_stock, limit = 20, offset = 0 } = options;
|
|
464
388
|
const qs = new URLSearchParams({
|
|
465
389
|
limit: String(limit),
|
|
466
390
|
offset: String(offset),
|
|
467
391
|
...(q ? { q } : {}),
|
|
468
392
|
...(category_id ? { category_id } : {}),
|
|
393
|
+
...(collection_id ? { collection_id } : {}),
|
|
469
394
|
...(status ? { status } : {}),
|
|
470
395
|
...(in_stock !== undefined ? { in_stock: String(in_stock) } : {}),
|
|
471
396
|
});
|
|
@@ -608,7 +533,7 @@ export class DropshipperClient {
|
|
|
608
533
|
async getOrders(
|
|
609
534
|
options: GetDropshipperOrdersOptions = {},
|
|
610
535
|
): Promise<GetDropshipperOrdersResponse> {
|
|
611
|
-
const { status, payment_collector, settlement_status, from, to, q, limit = 20, offset = 0 } = options;
|
|
536
|
+
const { status, payment_collector, settlement_status, from, to, q, customer_id, limit = 20, offset = 0 } = options;
|
|
612
537
|
const qs = new URLSearchParams({
|
|
613
538
|
limit: String(limit),
|
|
614
539
|
offset: String(offset),
|
|
@@ -618,6 +543,7 @@ export class DropshipperClient {
|
|
|
618
543
|
...(from ? { from } : {}),
|
|
619
544
|
...(to ? { to } : {}),
|
|
620
545
|
...(q ? { q } : {}),
|
|
546
|
+
...(customer_id ? { customer_id } : {}),
|
|
621
547
|
});
|
|
622
548
|
return this.request<GetDropshipperOrdersResponse>(
|
|
623
549
|
'GET',
|