@shopkit/data-layer 1.1.0 → 1.2.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/README.md +53 -0
- package/dist/adapters/index.d.mts +2 -1
- package/dist/adapters/index.d.ts +2 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +136 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -2
- package/dist/index.mjs.map +1 -1
- package/dist/interface-NJcjuqaL.d.mts +236 -0
- package/dist/interface-dqoKc63z.d.ts +236 -0
- package/dist/{service-Dw9qj17-.d.ts → service-BHCLUEim.d.ts} +2 -234
- package/dist/{service-Cnm8tn7H.d.mts → service-DBKEK2oS.d.mts} +2 -234
- package/dist/static-params/index.d.mts +65 -0
- package/dist/static-params/index.d.ts +65 -0
- package/dist/static-params/index.js +275 -0
- package/dist/static-params/index.js.map +1 -0
- package/dist/static-params/index.mjs +270 -0
- package/dist/static-params/index.mjs.map +1 -0
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -782,7 +782,7 @@ function createLogger(config = {}) {
|
|
|
782
782
|
}
|
|
783
783
|
return new UniversalLogger(fullConfig);
|
|
784
784
|
}
|
|
785
|
-
createLogger({
|
|
785
|
+
var logger = createLogger({
|
|
786
786
|
enabled: false,
|
|
787
787
|
level: "info",
|
|
788
788
|
prettyPrint: false
|
|
@@ -5528,6 +5528,137 @@ var EFulfillmentStatus = /* @__PURE__ */ ((EFulfillmentStatus2) => {
|
|
|
5528
5528
|
return EFulfillmentStatus2;
|
|
5529
5529
|
})(EFulfillmentStatus || {});
|
|
5530
5530
|
|
|
5531
|
-
|
|
5531
|
+
// src/static-params/index.ts
|
|
5532
|
+
var log = logger.child({ module: "static-params" });
|
|
5533
|
+
async function withConcurrency(thunks, limit) {
|
|
5534
|
+
const results = new Array(thunks.length);
|
|
5535
|
+
let next = 0;
|
|
5536
|
+
async function worker() {
|
|
5537
|
+
while (next < thunks.length) {
|
|
5538
|
+
const i = next++;
|
|
5539
|
+
results[i] = await thunks[i]().catch(() => []);
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
5542
|
+
await Promise.all(Array.from({ length: Math.min(limit, thunks.length) }, worker));
|
|
5543
|
+
return results;
|
|
5544
|
+
}
|
|
5545
|
+
async function traverseCollectionProducts(client, collectionsLimit, productsPerCollection, concurrency) {
|
|
5546
|
+
const collectionsResult = await client.getCollections({ first: collectionsLimit });
|
|
5547
|
+
const collections = Array.isArray(collectionsResult?.data) ? collectionsResult.data : [];
|
|
5548
|
+
if (collections.length === 0) return [];
|
|
5549
|
+
if (collections.length >= collectionsLimit) {
|
|
5550
|
+
log.warn(
|
|
5551
|
+
"getCollections hit the collections limit \u2014 some collections may be missing from static build; increase options.collectionsLimit if needed",
|
|
5552
|
+
{ count: collections.length, limit: collectionsLimit }
|
|
5553
|
+
);
|
|
5554
|
+
}
|
|
5555
|
+
const thunks = collections.map((collection) => async () => {
|
|
5556
|
+
const collectionname = collection?.handle;
|
|
5557
|
+
if (!collectionname) return [];
|
|
5558
|
+
try {
|
|
5559
|
+
const result = await client.getCollection({
|
|
5560
|
+
handle: collectionname,
|
|
5561
|
+
productLimit: productsPerCollection
|
|
5562
|
+
});
|
|
5563
|
+
const col = result?.data;
|
|
5564
|
+
const products = Array.isArray(col?.products) ? col.products : [];
|
|
5565
|
+
return products.map((p) => p?.handle).filter((h) => Boolean(h)).map((productHandle) => ({ collectionname, productHandle }));
|
|
5566
|
+
} catch (err) {
|
|
5567
|
+
log.warn(
|
|
5568
|
+
"Skipping collection during static generation \u2014 getCollection failed",
|
|
5569
|
+
{ collection: collectionname, err: err instanceof Error ? err.message : String(err) }
|
|
5570
|
+
);
|
|
5571
|
+
return [];
|
|
5572
|
+
}
|
|
5573
|
+
});
|
|
5574
|
+
const pairsNested = await withConcurrency(thunks, concurrency);
|
|
5575
|
+
return pairsNested.flat();
|
|
5576
|
+
}
|
|
5577
|
+
function createCollectionStaticParams(getClient, options) {
|
|
5578
|
+
return async function generateStaticParams() {
|
|
5579
|
+
const limit = options?.limit ?? 250;
|
|
5580
|
+
try {
|
|
5581
|
+
const result = await getClient().getCollections({ first: limit });
|
|
5582
|
+
const collections = Array.isArray(result?.data) ? result.data : [];
|
|
5583
|
+
if (collections.length >= limit) {
|
|
5584
|
+
log.warn(
|
|
5585
|
+
"getCollections returned max limit \u2014 some collections may be missing from static build; increase options.limit if needed",
|
|
5586
|
+
{ count: collections.length, limit }
|
|
5587
|
+
);
|
|
5588
|
+
}
|
|
5589
|
+
return collections.map((c) => c?.handle).filter((h) => Boolean(h)).map((handle) => ({ collectionname: handle }));
|
|
5590
|
+
} catch (error) {
|
|
5591
|
+
log.error("getCollections failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5592
|
+
return [];
|
|
5593
|
+
}
|
|
5594
|
+
};
|
|
5595
|
+
}
|
|
5596
|
+
function createProductStaticParams(getClient, options) {
|
|
5597
|
+
return async function generateStaticParams() {
|
|
5598
|
+
const limit = options?.limit ?? 250;
|
|
5599
|
+
try {
|
|
5600
|
+
const result = await getClient().getProducts({ first: limit });
|
|
5601
|
+
const products = Array.isArray(result?.data) ? result.data : [];
|
|
5602
|
+
if (products.length >= limit) {
|
|
5603
|
+
log.warn(
|
|
5604
|
+
"getProducts returned max limit \u2014 some products may be missing from static build; increase options.limit if needed",
|
|
5605
|
+
{ count: products.length, limit }
|
|
5606
|
+
);
|
|
5607
|
+
}
|
|
5608
|
+
return products.map((p) => p?.handle).filter((h) => Boolean(h)).map((handle) => ({ handle }));
|
|
5609
|
+
} catch (error) {
|
|
5610
|
+
log.error("getProducts failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5611
|
+
return [];
|
|
5612
|
+
}
|
|
5613
|
+
};
|
|
5614
|
+
}
|
|
5615
|
+
function createProductViaCollectionsStaticParams(getClient, options) {
|
|
5616
|
+
return async function generateStaticParams() {
|
|
5617
|
+
try {
|
|
5618
|
+
const pairs = await traverseCollectionProducts(
|
|
5619
|
+
getClient(),
|
|
5620
|
+
options?.collectionsLimit ?? 250,
|
|
5621
|
+
options?.productsPerCollection ?? 100,
|
|
5622
|
+
options?.concurrency ?? 10
|
|
5623
|
+
);
|
|
5624
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5625
|
+
return pairs.filter(({ productHandle }) => {
|
|
5626
|
+
if (seen.has(productHandle)) return false;
|
|
5627
|
+
seen.add(productHandle);
|
|
5628
|
+
return true;
|
|
5629
|
+
}).map(({ productHandle }) => ({ handle: productHandle }));
|
|
5630
|
+
} catch (error) {
|
|
5631
|
+
log.error("getProductHandlesViaCollections failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5632
|
+
return [];
|
|
5633
|
+
}
|
|
5634
|
+
};
|
|
5635
|
+
}
|
|
5636
|
+
function createCollectionProductStaticParams(getClient, options) {
|
|
5637
|
+
return async function generateStaticParams() {
|
|
5638
|
+
try {
|
|
5639
|
+
const pairs = await traverseCollectionProducts(
|
|
5640
|
+
getClient(),
|
|
5641
|
+
options?.collectionsLimit ?? 50,
|
|
5642
|
+
options?.productsPerCollection ?? 20,
|
|
5643
|
+
options?.concurrency ?? 10
|
|
5644
|
+
);
|
|
5645
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5646
|
+
return pairs.filter(({ collectionname, productHandle }) => {
|
|
5647
|
+
const key = `${collectionname}:${productHandle}`;
|
|
5648
|
+
if (seen.has(key)) return false;
|
|
5649
|
+
seen.add(key);
|
|
5650
|
+
return true;
|
|
5651
|
+
}).map(({ collectionname, productHandle }) => ({
|
|
5652
|
+
collectionname,
|
|
5653
|
+
handle: productHandle
|
|
5654
|
+
}));
|
|
5655
|
+
} catch (error) {
|
|
5656
|
+
log.error("getCollectionProducts failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5657
|
+
return [];
|
|
5658
|
+
}
|
|
5659
|
+
};
|
|
5660
|
+
}
|
|
5661
|
+
|
|
5662
|
+
export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, createCollectionProductStaticParams, createCollectionStaticParams, createCommerceClient, createCustomClient, createProductStaticParams, createProductViaCollectionsStaticParams, createShopifyClient };
|
|
5532
5663
|
//# sourceMappingURL=index.mjs.map
|
|
5533
5664
|
//# sourceMappingURL=index.mjs.map
|