@shopkit/data-layer 1.1.0 → 1.3.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/adapters/index.js +43 -20
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +43 -20
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +35 -2
- package/dist/index.d.ts +35 -2
- package/dist/index.js +181 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -22
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/constants.mjs
|
|
1
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/constants.mjs
|
|
2
2
|
var CLIENT = "GraphQL Client";
|
|
3
3
|
var MIN_RETRIES = 0;
|
|
4
4
|
var MAX_RETRIES = 3;
|
|
@@ -12,7 +12,7 @@ var CONTENT_TYPES = {
|
|
|
12
12
|
var SDK_VARIANT_HEADER = "X-SDK-Variant";
|
|
13
13
|
var SDK_VERSION_HEADER = "X-SDK-Version";
|
|
14
14
|
var DEFAULT_SDK_VARIANT = "shopify-graphql-client";
|
|
15
|
-
var DEFAULT_CLIENT_VERSION = "1.4.
|
|
15
|
+
var DEFAULT_CLIENT_VERSION = "1.4.2";
|
|
16
16
|
var RETRY_WAIT_TIME = 1e3;
|
|
17
17
|
var RETRIABLE_STATUS_CODES = [429, 503];
|
|
18
18
|
var DEFER_OPERATION_REGEX = /@(defer)\b/i;
|
|
@@ -20,7 +20,7 @@ var NEWLINE_SEPARATOR = "\r\n";
|
|
|
20
20
|
var BOUNDARY_HEADER_REGEX = /boundary="?([^=";]+)"?/i;
|
|
21
21
|
var HEADER_SEPARATOR = NEWLINE_SEPARATOR + NEWLINE_SEPARATOR;
|
|
22
22
|
|
|
23
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/utilities.mjs
|
|
23
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/utilities.mjs
|
|
24
24
|
function formatErrorMessage(message, client = CLIENT) {
|
|
25
25
|
return message.startsWith(`${client}`) ? message : `${client}: ${message}`;
|
|
26
26
|
}
|
|
@@ -70,7 +70,7 @@ function buildCombinedDataObject([initialDatum, ...remainingData]) {
|
|
|
70
70
|
return remainingData.reduce(combineObjects, { ...initialDatum });
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/http-fetch.mjs
|
|
73
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/http-fetch.mjs
|
|
74
74
|
function generateHttpFetch({ clientLogger, customFetchApi = fetch, client = CLIENT, defaultRetryWaitTime = RETRY_WAIT_TIME, retriableCodes = RETRIABLE_STATUS_CODES }) {
|
|
75
75
|
const httpFetch = async (requestParams, count, maxRetries) => {
|
|
76
76
|
const nextCount = count + 1;
|
|
@@ -123,7 +123,7 @@ async function sleep(waitTime) {
|
|
|
123
123
|
return new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/graphql-client.mjs
|
|
126
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/graphql-client.mjs
|
|
127
127
|
function createGraphQLClient({ headers, url, customFetchApi = fetch, retries = 0, logger: logger2 }) {
|
|
128
128
|
validateRetries({ client: CLIENT, retries });
|
|
129
129
|
const config = {
|
|
@@ -294,11 +294,22 @@ function readStreamChunk(streamBodyIterator, boundary) {
|
|
|
294
294
|
function createJsonResponseAsyncIterator(response) {
|
|
295
295
|
return {
|
|
296
296
|
async *[Symbol.asyncIterator]() {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
try {
|
|
298
|
+
const processedResponse = await processJSONResponse(response);
|
|
299
|
+
yield {
|
|
300
|
+
...processedResponse,
|
|
301
|
+
hasNext: false
|
|
302
|
+
};
|
|
303
|
+
} catch (error) {
|
|
304
|
+
yield {
|
|
305
|
+
errors: {
|
|
306
|
+
message: formatErrorMessage(getErrorMessage(error)),
|
|
307
|
+
networkStatusCode: response.status,
|
|
308
|
+
response
|
|
309
|
+
},
|
|
310
|
+
hasNext: false
|
|
311
|
+
};
|
|
312
|
+
}
|
|
302
313
|
}
|
|
303
314
|
};
|
|
304
315
|
}
|
|
@@ -435,7 +446,7 @@ function generateRequestStream(fetchFn) {
|
|
|
435
446
|
};
|
|
436
447
|
}
|
|
437
448
|
|
|
438
|
-
// ../../node_modules/@shopify/graphql-client/dist/api-client-utilities/validations.mjs
|
|
449
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/api-client-utilities/validations.mjs
|
|
439
450
|
function validateDomainAndGetStoreUrl({ client, storeDomain }) {
|
|
440
451
|
try {
|
|
441
452
|
if (!storeDomain || typeof storeDomain !== "string") {
|
|
@@ -472,7 +483,7 @@ function validateApiVersion({ client, currentSupportedApiVersions, apiVersion, l
|
|
|
472
483
|
}
|
|
473
484
|
}
|
|
474
485
|
|
|
475
|
-
// ../../node_modules/@shopify/graphql-client/dist/api-client-utilities/api-versions.mjs
|
|
486
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/api-client-utilities/api-versions.mjs
|
|
476
487
|
function getQuarterMonth(quarter) {
|
|
477
488
|
const month = quarter * 3 - 2;
|
|
478
489
|
return month === 10 ? month : `0${month}`;
|
|
@@ -508,7 +519,7 @@ function getCurrentSupportedApiVersions() {
|
|
|
508
519
|
];
|
|
509
520
|
}
|
|
510
521
|
|
|
511
|
-
// ../../node_modules/@shopify/graphql-client/dist/api-client-utilities/utilities.mjs
|
|
522
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/api-client-utilities/utilities.mjs
|
|
512
523
|
function generateGetHeaders(config) {
|
|
513
524
|
return (customHeaders) => {
|
|
514
525
|
return { ...customHeaders ?? {}, ...config.headers };
|
|
@@ -531,10 +542,10 @@ function generateGetGQLClientParams({ getHeaders, getApiUrl }) {
|
|
|
531
542
|
};
|
|
532
543
|
}
|
|
533
544
|
|
|
534
|
-
// ../../node_modules/@shopify/storefront-api-client/dist/constants.mjs
|
|
545
|
+
// ../../node_modules/.bun/@shopify+storefront-api-client@1.0.10/node_modules/@shopify/storefront-api-client/dist/constants.mjs
|
|
535
546
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
536
547
|
var DEFAULT_SDK_VARIANT2 = "storefront-api-client";
|
|
537
|
-
var DEFAULT_CLIENT_VERSION2 = "1.0.
|
|
548
|
+
var DEFAULT_CLIENT_VERSION2 = "1.0.10";
|
|
538
549
|
var PUBLIC_ACCESS_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
|
|
539
550
|
var PRIVATE_ACCESS_TOKEN_HEADER = "Shopify-Storefront-Private-Token";
|
|
540
551
|
var SDK_VARIANT_HEADER2 = "X-SDK-Variant";
|
|
@@ -542,7 +553,7 @@ var SDK_VERSION_HEADER2 = "X-SDK-Version";
|
|
|
542
553
|
var SDK_VARIANT_SOURCE_HEADER = "X-SDK-Variant-Source";
|
|
543
554
|
var CLIENT2 = "Storefront API Client";
|
|
544
555
|
|
|
545
|
-
// ../../node_modules/@shopify/storefront-api-client/dist/validations.mjs
|
|
556
|
+
// ../../node_modules/.bun/@shopify+storefront-api-client@1.0.10/node_modules/@shopify/storefront-api-client/dist/validations.mjs
|
|
546
557
|
function validatePrivateAccessTokenUsage(privateAccessToken) {
|
|
547
558
|
if (privateAccessToken && typeof window !== "undefined") {
|
|
548
559
|
throw new Error(`${CLIENT2}: private access tokens and headers should only be used in a server-to-server implementation. Use the public API access token in nonserver environments.`);
|
|
@@ -557,7 +568,7 @@ function validateRequiredAccessTokens(publicAccessToken, privateAccessToken) {
|
|
|
557
568
|
}
|
|
558
569
|
}
|
|
559
570
|
|
|
560
|
-
// ../../node_modules/@shopify/storefront-api-client/dist/storefront-api-client.mjs
|
|
571
|
+
// ../../node_modules/.bun/@shopify+storefront-api-client@1.0.10/node_modules/@shopify/storefront-api-client/dist/storefront-api-client.mjs
|
|
561
572
|
function createStorefrontApiClient({ storeDomain, apiVersion, publicAccessToken, privateAccessToken, clientName, retries = 0, customFetchApi, logger: logger2 }) {
|
|
562
573
|
const currentSupportedApiVersions = getCurrentSupportedApiVersions();
|
|
563
574
|
const storeUrl = validateDomainAndGetStoreUrl({
|
|
@@ -782,7 +793,7 @@ function createLogger(config = {}) {
|
|
|
782
793
|
}
|
|
783
794
|
return new UniversalLogger(fullConfig);
|
|
784
795
|
}
|
|
785
|
-
createLogger({
|
|
796
|
+
var logger = createLogger({
|
|
786
797
|
enabled: false,
|
|
787
798
|
level: "info",
|
|
788
799
|
prettyPrint: false
|
|
@@ -804,6 +815,12 @@ function formatResponse(params) {
|
|
|
804
815
|
};
|
|
805
816
|
}
|
|
806
817
|
|
|
818
|
+
// src/core/request-timeout.ts
|
|
819
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
|
|
820
|
+
function resolveRequestSignal(options, defaultMs = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
821
|
+
return options?.signal ?? AbortSignal.timeout(options?.timeoutMs ?? defaultMs);
|
|
822
|
+
}
|
|
823
|
+
|
|
807
824
|
// src/core/client.ts
|
|
808
825
|
var NotImplementedError = class extends Error {
|
|
809
826
|
constructor(adapterName, methodName) {
|
|
@@ -1155,7 +1172,10 @@ var BaseCommerceClient = class {
|
|
|
1155
1172
|
async fetchRequest(params) {
|
|
1156
1173
|
try {
|
|
1157
1174
|
const { url, ...fetchOptions } = params;
|
|
1158
|
-
const response = await fetch(url,
|
|
1175
|
+
const response = await fetch(url, {
|
|
1176
|
+
...fetchOptions,
|
|
1177
|
+
signal: resolveRequestSignal(fetchOptions)
|
|
1178
|
+
});
|
|
1159
1179
|
const data = await response.json();
|
|
1160
1180
|
if (response.ok) {
|
|
1161
1181
|
return formatResponse({
|
|
@@ -4282,7 +4302,7 @@ var getCommonHeaders = (config) => {
|
|
|
4282
4302
|
// src/adapters/custom/services/base.ts
|
|
4283
4303
|
var BaseCustomService = class {
|
|
4284
4304
|
constructor(baseUrl, config, logger2) {
|
|
4285
|
-
this.timeout =
|
|
4305
|
+
this.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
4286
4306
|
this.baseUrl = baseUrl;
|
|
4287
4307
|
this.config = config;
|
|
4288
4308
|
this.logger = logger2 || createDomainLogger("custom", "custom", { enabled: false });
|
|
@@ -4319,7 +4339,10 @@ var BaseCustomService = class {
|
|
|
4319
4339
|
}
|
|
4320
4340
|
const requestOptions = {
|
|
4321
4341
|
method,
|
|
4322
|
-
headers
|
|
4342
|
+
headers,
|
|
4343
|
+
// Bound the upstream wait — see core/request-timeout.ts for the policy and
|
|
4344
|
+
// rationale (Bblunt prod memory-leak postmortem, Jun 2026).
|
|
4345
|
+
signal: resolveRequestSignal(options, this.timeout)
|
|
4323
4346
|
};
|
|
4324
4347
|
if (data && method !== "GET") {
|
|
4325
4348
|
requestOptions.body = JSON.stringify(data);
|
|
@@ -5528,6 +5551,137 @@ var EFulfillmentStatus = /* @__PURE__ */ ((EFulfillmentStatus2) => {
|
|
|
5528
5551
|
return EFulfillmentStatus2;
|
|
5529
5552
|
})(EFulfillmentStatus || {});
|
|
5530
5553
|
|
|
5531
|
-
|
|
5554
|
+
// src/static-params/index.ts
|
|
5555
|
+
var log = logger.child({ module: "static-params" });
|
|
5556
|
+
async function withConcurrency(thunks, limit) {
|
|
5557
|
+
const results = new Array(thunks.length);
|
|
5558
|
+
let next = 0;
|
|
5559
|
+
async function worker() {
|
|
5560
|
+
while (next < thunks.length) {
|
|
5561
|
+
const i = next++;
|
|
5562
|
+
results[i] = await thunks[i]().catch(() => []);
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5565
|
+
await Promise.all(Array.from({ length: Math.min(limit, thunks.length) }, worker));
|
|
5566
|
+
return results;
|
|
5567
|
+
}
|
|
5568
|
+
async function traverseCollectionProducts(client, collectionsLimit, productsPerCollection, concurrency) {
|
|
5569
|
+
const collectionsResult = await client.getCollections({ first: collectionsLimit });
|
|
5570
|
+
const collections = Array.isArray(collectionsResult?.data) ? collectionsResult.data : [];
|
|
5571
|
+
if (collections.length === 0) return [];
|
|
5572
|
+
if (collections.length >= collectionsLimit) {
|
|
5573
|
+
log.warn(
|
|
5574
|
+
"getCollections hit the collections limit \u2014 some collections may be missing from static build; increase options.collectionsLimit if needed",
|
|
5575
|
+
{ count: collections.length, limit: collectionsLimit }
|
|
5576
|
+
);
|
|
5577
|
+
}
|
|
5578
|
+
const thunks = collections.map((collection) => async () => {
|
|
5579
|
+
const collectionname = collection?.handle;
|
|
5580
|
+
if (!collectionname) return [];
|
|
5581
|
+
try {
|
|
5582
|
+
const result = await client.getCollection({
|
|
5583
|
+
handle: collectionname,
|
|
5584
|
+
productLimit: productsPerCollection
|
|
5585
|
+
});
|
|
5586
|
+
const col = result?.data;
|
|
5587
|
+
const products = Array.isArray(col?.products) ? col.products : [];
|
|
5588
|
+
return products.map((p) => p?.handle).filter((h) => Boolean(h)).map((productHandle) => ({ collectionname, productHandle }));
|
|
5589
|
+
} catch (err) {
|
|
5590
|
+
log.warn(
|
|
5591
|
+
"Skipping collection during static generation \u2014 getCollection failed",
|
|
5592
|
+
{ collection: collectionname, err: err instanceof Error ? err.message : String(err) }
|
|
5593
|
+
);
|
|
5594
|
+
return [];
|
|
5595
|
+
}
|
|
5596
|
+
});
|
|
5597
|
+
const pairsNested = await withConcurrency(thunks, concurrency);
|
|
5598
|
+
return pairsNested.flat();
|
|
5599
|
+
}
|
|
5600
|
+
function createCollectionStaticParams(getClient, options) {
|
|
5601
|
+
return async function generateStaticParams() {
|
|
5602
|
+
const limit = options?.limit ?? 250;
|
|
5603
|
+
try {
|
|
5604
|
+
const result = await getClient().getCollections({ first: limit });
|
|
5605
|
+
const collections = Array.isArray(result?.data) ? result.data : [];
|
|
5606
|
+
if (collections.length >= limit) {
|
|
5607
|
+
log.warn(
|
|
5608
|
+
"getCollections returned max limit \u2014 some collections may be missing from static build; increase options.limit if needed",
|
|
5609
|
+
{ count: collections.length, limit }
|
|
5610
|
+
);
|
|
5611
|
+
}
|
|
5612
|
+
return collections.map((c) => c?.handle).filter((h) => Boolean(h)).map((handle) => ({ collectionname: handle }));
|
|
5613
|
+
} catch (error) {
|
|
5614
|
+
log.error("getCollections failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5615
|
+
return [];
|
|
5616
|
+
}
|
|
5617
|
+
};
|
|
5618
|
+
}
|
|
5619
|
+
function createProductStaticParams(getClient, options) {
|
|
5620
|
+
return async function generateStaticParams() {
|
|
5621
|
+
const limit = options?.limit ?? 250;
|
|
5622
|
+
try {
|
|
5623
|
+
const result = await getClient().getProducts({ first: limit });
|
|
5624
|
+
const products = Array.isArray(result?.data) ? result.data : [];
|
|
5625
|
+
if (products.length >= limit) {
|
|
5626
|
+
log.warn(
|
|
5627
|
+
"getProducts returned max limit \u2014 some products may be missing from static build; increase options.limit if needed",
|
|
5628
|
+
{ count: products.length, limit }
|
|
5629
|
+
);
|
|
5630
|
+
}
|
|
5631
|
+
return products.map((p) => p?.handle).filter((h) => Boolean(h)).map((handle) => ({ handle }));
|
|
5632
|
+
} catch (error) {
|
|
5633
|
+
log.error("getProducts failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5634
|
+
return [];
|
|
5635
|
+
}
|
|
5636
|
+
};
|
|
5637
|
+
}
|
|
5638
|
+
function createProductViaCollectionsStaticParams(getClient, options) {
|
|
5639
|
+
return async function generateStaticParams() {
|
|
5640
|
+
try {
|
|
5641
|
+
const pairs = await traverseCollectionProducts(
|
|
5642
|
+
getClient(),
|
|
5643
|
+
options?.collectionsLimit ?? 250,
|
|
5644
|
+
options?.productsPerCollection ?? 100,
|
|
5645
|
+
options?.concurrency ?? 10
|
|
5646
|
+
);
|
|
5647
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5648
|
+
return pairs.filter(({ productHandle }) => {
|
|
5649
|
+
if (seen.has(productHandle)) return false;
|
|
5650
|
+
seen.add(productHandle);
|
|
5651
|
+
return true;
|
|
5652
|
+
}).map(({ productHandle }) => ({ handle: productHandle }));
|
|
5653
|
+
} catch (error) {
|
|
5654
|
+
log.error("getProductHandlesViaCollections failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5655
|
+
return [];
|
|
5656
|
+
}
|
|
5657
|
+
};
|
|
5658
|
+
}
|
|
5659
|
+
function createCollectionProductStaticParams(getClient, options) {
|
|
5660
|
+
return async function generateStaticParams() {
|
|
5661
|
+
try {
|
|
5662
|
+
const pairs = await traverseCollectionProducts(
|
|
5663
|
+
getClient(),
|
|
5664
|
+
options?.collectionsLimit ?? 50,
|
|
5665
|
+
options?.productsPerCollection ?? 20,
|
|
5666
|
+
options?.concurrency ?? 10
|
|
5667
|
+
);
|
|
5668
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5669
|
+
return pairs.filter(({ collectionname, productHandle }) => {
|
|
5670
|
+
const key = `${collectionname}:${productHandle}`;
|
|
5671
|
+
if (seen.has(key)) return false;
|
|
5672
|
+
seen.add(key);
|
|
5673
|
+
return true;
|
|
5674
|
+
}).map(({ collectionname, productHandle }) => ({
|
|
5675
|
+
collectionname,
|
|
5676
|
+
handle: productHandle
|
|
5677
|
+
}));
|
|
5678
|
+
} catch (error) {
|
|
5679
|
+
log.error("getCollectionProducts failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5680
|
+
return [];
|
|
5681
|
+
}
|
|
5682
|
+
};
|
|
5683
|
+
}
|
|
5684
|
+
|
|
5685
|
+
export { DEFAULT_REQUEST_TIMEOUT_MS, EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, createCollectionProductStaticParams, createCollectionStaticParams, createCommerceClient, createCustomClient, createProductStaticParams, createProductViaCollectionsStaticParams, createShopifyClient, resolveRequestSignal };
|
|
5532
5686
|
//# sourceMappingURL=index.mjs.map
|
|
5533
5687
|
//# sourceMappingURL=index.mjs.map
|