@tallyui/connector-medusa 3.0.3 → 3.1.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/dist/index.d.ts +3 -3
- package/dist/index.js +21 -3
- package/package.json +3 -3
- package/src/pricing/calculated.ts +25 -5
- package/src/replication/products.ts +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -152,9 +152,9 @@ declare function getMedusaCustomer(baseUrl: string, headers: Record<string, stri
|
|
|
152
152
|
* amendment 8, D2b). A variant the store API does not list (a draft, or a
|
|
153
153
|
* product outside the key's sales channel) gets `null`: priced mode, not
|
|
154
154
|
* sellable here. Without a pricing context the documents come back
|
|
155
|
-
* unchanged (base-only mode, no `calculated_price` key).
|
|
156
|
-
*
|
|
157
|
-
* document.
|
|
155
|
+
* unchanged (base-only mode, no `calculated_price` key). Store-API chunk
|
|
156
|
+
* requests run up to `STORE_PRICE_CONCURRENCY` at a time; a failed store request throws,
|
|
157
|
+
* so the pull retries and never delivers a half-priced document.
|
|
158
158
|
*/
|
|
159
159
|
declare function withCalculatedPrices<Doc extends MedusaProductDocument>(docs: Doc[], context: SyncContext): Promise<Doc[]>;
|
|
160
160
|
|
package/dist/index.js
CHANGED
|
@@ -521,6 +521,7 @@ import { compareIds, ConnectorUnauthorizedError as ConnectorUnauthorizedError2 }
|
|
|
521
521
|
|
|
522
522
|
// src/pricing/calculated.ts
|
|
523
523
|
var STORE_PAGE_SIZE = 100;
|
|
524
|
+
var STORE_PRICE_CONCURRENCY = 3;
|
|
524
525
|
var STORE_PRICE_FIELDS = "id,*variants.calculated_price";
|
|
525
526
|
async function storeGet(path, context) {
|
|
526
527
|
const key = context.pricingContext?.publishable_key ?? "";
|
|
@@ -538,11 +539,28 @@ async function storeGet(path, context) {
|
|
|
538
539
|
async function withCalculatedPrices(docs, context) {
|
|
539
540
|
const pricing = context.pricingContext;
|
|
540
541
|
if (!pricing) return docs;
|
|
541
|
-
const
|
|
542
|
+
const urls = [];
|
|
542
543
|
for (let i = 0; i < docs.length; i += STORE_PAGE_SIZE) {
|
|
543
544
|
const params = new URLSearchParams({ region_id: pricing.region_id ?? "", limit: String(STORE_PAGE_SIZE), fields: STORE_PRICE_FIELDS });
|
|
544
545
|
for (const doc of docs.slice(i, i + STORE_PAGE_SIZE)) params.append("id[]", doc.id);
|
|
545
|
-
|
|
546
|
+
urls.push(`/store/products?${params}`);
|
|
547
|
+
}
|
|
548
|
+
const responses = [];
|
|
549
|
+
let next = 0;
|
|
550
|
+
let failed = false;
|
|
551
|
+
await Promise.all(Array.from({ length: Math.min(STORE_PRICE_CONCURRENCY, urls.length) }, async () => {
|
|
552
|
+
while (!failed && next < urls.length) {
|
|
553
|
+
const index = next++;
|
|
554
|
+
try {
|
|
555
|
+
responses[index] = await storeGet(urls[index], context);
|
|
556
|
+
} catch (error) {
|
|
557
|
+
failed = true;
|
|
558
|
+
throw error;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}));
|
|
562
|
+
const byVariant = /* @__PURE__ */ new Map();
|
|
563
|
+
for (const data of responses) {
|
|
546
564
|
for (const product of data.products ?? []) {
|
|
547
565
|
for (const variant of product.variants ?? []) byVariant.set(variant.id, variant.calculated_price ?? null);
|
|
548
566
|
}
|
|
@@ -574,7 +592,7 @@ var MEDUSA_PRODUCT_FIELDS = [
|
|
|
574
592
|
"*options",
|
|
575
593
|
"*options.values"
|
|
576
594
|
].join(",");
|
|
577
|
-
var MEDUSA_PULL_BATCH_SIZE =
|
|
595
|
+
var MEDUSA_PULL_BATCH_SIZE = 250;
|
|
578
596
|
var medusaProductReplication = {
|
|
579
597
|
pull: {
|
|
580
598
|
async handler(lastCheckpoint, batchSize, context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/connector-medusa",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MedusaJS v2 connector for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"directory": "connectors/medusa"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@tallyui/core": "^3.0
|
|
30
|
+
"@tallyui/core": "^3.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tallyui/database": "3.0
|
|
33
|
+
"@tallyui/database": "3.1.0",
|
|
34
34
|
"rxdb": "17.5.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
@@ -4,6 +4,9 @@ import type { MedusaCalculatedPrice, MedusaProductDocument } from '../schemas/pr
|
|
|
4
4
|
/** Store API list limit used here; also the most ids per enrichment request (as `fetchByIds`). */
|
|
5
5
|
export const STORE_PAGE_SIZE = 100;
|
|
6
6
|
|
|
7
|
+
/** Most store-API price requests in flight at once (ADR-074): the demo backend serialises heavier work, so more buys little. */
|
|
8
|
+
export const STORE_PRICE_CONCURRENCY = 3;
|
|
9
|
+
|
|
7
10
|
/** Only what pricing needs: the product id and each variant's calculated price. */
|
|
8
11
|
export const STORE_PRICE_FIELDS = 'id,*variants.calculated_price';
|
|
9
12
|
|
|
@@ -36,18 +39,35 @@ export async function storeGet(path: string, context: SyncContext): Promise<{ pr
|
|
|
36
39
|
* amendment 8, D2b). A variant the store API does not list (a draft, or a
|
|
37
40
|
* product outside the key's sales channel) gets `null`: priced mode, not
|
|
38
41
|
* sellable here. Without a pricing context the documents come back
|
|
39
|
-
* unchanged (base-only mode, no `calculated_price` key).
|
|
40
|
-
*
|
|
41
|
-
* document.
|
|
42
|
+
* unchanged (base-only mode, no `calculated_price` key). Store-API chunk
|
|
43
|
+
* requests run up to `STORE_PRICE_CONCURRENCY` at a time; a failed store request throws,
|
|
44
|
+
* so the pull retries and never delivers a half-priced document.
|
|
42
45
|
*/
|
|
43
46
|
export async function withCalculatedPrices<Doc extends MedusaProductDocument>(docs: Doc[], context: SyncContext): Promise<Doc[]> {
|
|
44
47
|
const pricing = context.pricingContext;
|
|
45
48
|
if (!pricing) return docs;
|
|
46
|
-
const
|
|
49
|
+
const urls: string[] = [];
|
|
47
50
|
for (let i = 0; i < docs.length; i += STORE_PAGE_SIZE) {
|
|
48
51
|
const params = new URLSearchParams({ region_id: pricing.region_id ?? '', limit: String(STORE_PAGE_SIZE), fields: STORE_PRICE_FIELDS });
|
|
49
52
|
for (const doc of docs.slice(i, i + STORE_PAGE_SIZE)) params.append('id[]', doc.id);
|
|
50
|
-
|
|
53
|
+
urls.push(`/store/products?${params}`);
|
|
54
|
+
}
|
|
55
|
+
const responses: Awaited<ReturnType<typeof storeGet>>[] = [];
|
|
56
|
+
let next = 0;
|
|
57
|
+
let failed = false;
|
|
58
|
+
await Promise.all(Array.from({ length: Math.min(STORE_PRICE_CONCURRENCY, urls.length) }, async () => {
|
|
59
|
+
while (!failed && next < urls.length) {
|
|
60
|
+
const index = next++;
|
|
61
|
+
try {
|
|
62
|
+
responses[index] = await storeGet(urls[index], context);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
failed = true;
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
const byVariant = new Map<string, MedusaCalculatedPrice | null>();
|
|
70
|
+
for (const data of responses) {
|
|
51
71
|
for (const product of data.products ?? []) {
|
|
52
72
|
for (const variant of product.variants ?? []) byVariant.set(variant.id, variant.calculated_price ?? null);
|
|
53
73
|
}
|
|
@@ -46,10 +46,9 @@ export const MEDUSA_PRODUCT_FIELDS = [
|
|
|
46
46
|
'*options.values',
|
|
47
47
|
].join(',');
|
|
48
48
|
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
export const MEDUSA_PULL_BATCH_SIZE = 500;
|
|
49
|
+
// ADR-074: 250 per page. On the live demo (2026-10-06, 1,956 products) the whole catalogue's admin pages took
|
|
50
|
+
// 8.05 s at 250, 8.37 s at 100 and 9.67 s at 500, and a 250-page answers in about 1 s, so the first tiles show sooner.
|
|
51
|
+
export const MEDUSA_PULL_BATCH_SIZE = 250;
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* Replication adapter for Medusa v2 products.
|