@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/README.md
CHANGED
|
@@ -26,6 +26,59 @@ A comprehensive, production-ready data layer package for e-commerce applications
|
|
|
26
26
|
- **📋 Consistent Response Format**: Standardized `IResponse` format across all operations
|
|
27
27
|
- **🪵 Advanced Logging**: Built-in logging with configurable levels and formatting
|
|
28
28
|
- **🎯 Standardized Interface**: All methods follow consistent signature patterns
|
|
29
|
+
- **⚡ Build-time Static Generation**: Factory functions that auto-generate `generateStaticParams` for all dynamic routes — no manual env var configuration needed
|
|
30
|
+
|
|
31
|
+
## Static Params (Build-time Route Generation)
|
|
32
|
+
|
|
33
|
+
Use the `static-params` subpath to automatically pre-build all collection and product pages at CI time. Replaces the manual `FEATURED_COLLECTIONS` env var pattern.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import {
|
|
37
|
+
createCollectionStaticParams,
|
|
38
|
+
createProductStaticParams,
|
|
39
|
+
createProductViaCollectionsStaticParams,
|
|
40
|
+
createCollectionProductStaticParams,
|
|
41
|
+
} from "@shopkit/data-layer";
|
|
42
|
+
import { getCommerceClient } from "@/config/commerce";
|
|
43
|
+
|
|
44
|
+
// /collections/[collectionname]/page.tsx
|
|
45
|
+
export const revalidate = 3600;
|
|
46
|
+
export const dynamicParams = true;
|
|
47
|
+
export const generateStaticParams = createCollectionStaticParams(getCommerceClient);
|
|
48
|
+
|
|
49
|
+
// /products/[handle]/page.tsx — backend supports getProducts directly
|
|
50
|
+
export const revalidate = 3600;
|
|
51
|
+
export const dynamicParams = true;
|
|
52
|
+
export const generateStaticParams = createProductStaticParams(getCommerceClient);
|
|
53
|
+
|
|
54
|
+
// /products/[handle]/page.tsx — backend has no products-list endpoint (derives handles from collections)
|
|
55
|
+
export const revalidate = 3600;
|
|
56
|
+
export const dynamicParams = true;
|
|
57
|
+
export const generateStaticParams = createProductViaCollectionsStaticParams(getCommerceClient);
|
|
58
|
+
|
|
59
|
+
// /collections/[collectionname]/products/[handle]/page.tsx
|
|
60
|
+
export const revalidate = 3600;
|
|
61
|
+
export const dynamicParams = true;
|
|
62
|
+
export const generateStaticParams = createCollectionProductStaticParams(getCommerceClient);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
All factories: catch API errors and return `[]` (build never fails), accept an optional `options` argument for custom limits and concurrency, and deduplicate product handles across collections.
|
|
66
|
+
|
|
67
|
+
`createProductViaCollectionsStaticParams` and `createCollectionProductStaticParams` also accept a `concurrency` option (default: `10`) that caps how many `getCollection` calls run simultaneously — prevents burst load on custom REST backends at build time:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Custom backend with strict rate limits — lower concurrency
|
|
71
|
+
export const generateStaticParams = createProductViaCollectionsStaticParams(
|
|
72
|
+
getCommerceClient,
|
|
73
|
+
{ collectionsLimit: 250, productsPerCollection: 100, concurrency: 5 }
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Fast internal backend — raise concurrency to build faster
|
|
77
|
+
export const generateStaticParams = createCollectionProductStaticParams(
|
|
78
|
+
getCommerceClient,
|
|
79
|
+
{ collectionsLimit: 50, productsPerCollection: 20, concurrency: 20 }
|
|
80
|
+
);
|
|
81
|
+
```
|
|
29
82
|
|
|
30
83
|
## Installation
|
|
31
84
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { I as IShopifyConfig, S as ShopifyCommerceClient, a as ICustomConfig, C as CustomBackendClient } from '../service-
|
|
1
|
+
import { I as IShopifyConfig, S as ShopifyCommerceClient, a as ICustomConfig, C as CustomBackendClient } from '../service-DBKEK2oS.mjs';
|
|
2
2
|
import '../models/index.mjs';
|
|
3
|
+
import '../interface-NJcjuqaL.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Shopify adapter for the commerce library
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { I as IShopifyConfig, S as ShopifyCommerceClient, a as ICustomConfig, C as CustomBackendClient } from '../service-
|
|
1
|
+
import { I as IShopifyConfig, S as ShopifyCommerceClient, a as ICustomConfig, C as CustomBackendClient } from '../service-BHCLUEim.js';
|
|
2
2
|
import '../models/index.js';
|
|
3
|
+
import '../interface-dqoKc63z.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Shopify adapter for the commerce library
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/constants.mjs
|
|
3
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/constants.mjs
|
|
4
4
|
var CLIENT = "GraphQL Client";
|
|
5
5
|
var MIN_RETRIES = 0;
|
|
6
6
|
var MAX_RETRIES = 3;
|
|
@@ -14,7 +14,7 @@ var CONTENT_TYPES = {
|
|
|
14
14
|
var SDK_VARIANT_HEADER = "X-SDK-Variant";
|
|
15
15
|
var SDK_VERSION_HEADER = "X-SDK-Version";
|
|
16
16
|
var DEFAULT_SDK_VARIANT = "shopify-graphql-client";
|
|
17
|
-
var DEFAULT_CLIENT_VERSION = "1.4.
|
|
17
|
+
var DEFAULT_CLIENT_VERSION = "1.4.2";
|
|
18
18
|
var RETRY_WAIT_TIME = 1e3;
|
|
19
19
|
var RETRIABLE_STATUS_CODES = [429, 503];
|
|
20
20
|
var DEFER_OPERATION_REGEX = /@(defer)\b/i;
|
|
@@ -22,7 +22,7 @@ var NEWLINE_SEPARATOR = "\r\n";
|
|
|
22
22
|
var BOUNDARY_HEADER_REGEX = /boundary="?([^=";]+)"?/i;
|
|
23
23
|
var HEADER_SEPARATOR = NEWLINE_SEPARATOR + NEWLINE_SEPARATOR;
|
|
24
24
|
|
|
25
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/utilities.mjs
|
|
25
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/utilities.mjs
|
|
26
26
|
function formatErrorMessage(message, client = CLIENT) {
|
|
27
27
|
return message.startsWith(`${client}`) ? message : `${client}: ${message}`;
|
|
28
28
|
}
|
|
@@ -72,7 +72,7 @@ function buildCombinedDataObject([initialDatum, ...remainingData]) {
|
|
|
72
72
|
return remainingData.reduce(combineObjects, { ...initialDatum });
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/http-fetch.mjs
|
|
75
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/http-fetch.mjs
|
|
76
76
|
function generateHttpFetch({ clientLogger, customFetchApi = fetch, client = CLIENT, defaultRetryWaitTime = RETRY_WAIT_TIME, retriableCodes = RETRIABLE_STATUS_CODES }) {
|
|
77
77
|
const httpFetch = async (requestParams, count, maxRetries) => {
|
|
78
78
|
const nextCount = count + 1;
|
|
@@ -125,7 +125,7 @@ async function sleep(waitTime) {
|
|
|
125
125
|
return new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
// ../../node_modules/@shopify/graphql-client/dist/graphql-client/graphql-client.mjs
|
|
128
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/graphql-client/graphql-client.mjs
|
|
129
129
|
function createGraphQLClient({ headers, url, customFetchApi = fetch, retries = 0, logger: logger2 }) {
|
|
130
130
|
validateRetries({ client: CLIENT, retries });
|
|
131
131
|
const config = {
|
|
@@ -296,11 +296,22 @@ function readStreamChunk(streamBodyIterator, boundary) {
|
|
|
296
296
|
function createJsonResponseAsyncIterator(response) {
|
|
297
297
|
return {
|
|
298
298
|
async *[Symbol.asyncIterator]() {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
299
|
+
try {
|
|
300
|
+
const processedResponse = await processJSONResponse(response);
|
|
301
|
+
yield {
|
|
302
|
+
...processedResponse,
|
|
303
|
+
hasNext: false
|
|
304
|
+
};
|
|
305
|
+
} catch (error) {
|
|
306
|
+
yield {
|
|
307
|
+
errors: {
|
|
308
|
+
message: formatErrorMessage(getErrorMessage(error)),
|
|
309
|
+
networkStatusCode: response.status,
|
|
310
|
+
response
|
|
311
|
+
},
|
|
312
|
+
hasNext: false
|
|
313
|
+
};
|
|
314
|
+
}
|
|
304
315
|
}
|
|
305
316
|
};
|
|
306
317
|
}
|
|
@@ -437,7 +448,7 @@ function generateRequestStream(fetchFn) {
|
|
|
437
448
|
};
|
|
438
449
|
}
|
|
439
450
|
|
|
440
|
-
// ../../node_modules/@shopify/graphql-client/dist/api-client-utilities/validations.mjs
|
|
451
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/api-client-utilities/validations.mjs
|
|
441
452
|
function validateDomainAndGetStoreUrl({ client, storeDomain }) {
|
|
442
453
|
try {
|
|
443
454
|
if (!storeDomain || typeof storeDomain !== "string") {
|
|
@@ -474,7 +485,7 @@ function validateApiVersion({ client, currentSupportedApiVersions, apiVersion, l
|
|
|
474
485
|
}
|
|
475
486
|
}
|
|
476
487
|
|
|
477
|
-
// ../../node_modules/@shopify/graphql-client/dist/api-client-utilities/api-versions.mjs
|
|
488
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/api-client-utilities/api-versions.mjs
|
|
478
489
|
function getQuarterMonth(quarter) {
|
|
479
490
|
const month = quarter * 3 - 2;
|
|
480
491
|
return month === 10 ? month : `0${month}`;
|
|
@@ -510,7 +521,7 @@ function getCurrentSupportedApiVersions() {
|
|
|
510
521
|
];
|
|
511
522
|
}
|
|
512
523
|
|
|
513
|
-
// ../../node_modules/@shopify/graphql-client/dist/api-client-utilities/utilities.mjs
|
|
524
|
+
// ../../node_modules/.bun/@shopify+graphql-client@1.4.2/node_modules/@shopify/graphql-client/dist/api-client-utilities/utilities.mjs
|
|
514
525
|
function generateGetHeaders(config) {
|
|
515
526
|
return (customHeaders) => {
|
|
516
527
|
return { ...customHeaders ?? {}, ...config.headers };
|
|
@@ -533,10 +544,10 @@ function generateGetGQLClientParams({ getHeaders, getApiUrl }) {
|
|
|
533
544
|
};
|
|
534
545
|
}
|
|
535
546
|
|
|
536
|
-
// ../../node_modules/@shopify/storefront-api-client/dist/constants.mjs
|
|
547
|
+
// ../../node_modules/.bun/@shopify+storefront-api-client@1.0.10/node_modules/@shopify/storefront-api-client/dist/constants.mjs
|
|
537
548
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
538
549
|
var DEFAULT_SDK_VARIANT2 = "storefront-api-client";
|
|
539
|
-
var DEFAULT_CLIENT_VERSION2 = "1.0.
|
|
550
|
+
var DEFAULT_CLIENT_VERSION2 = "1.0.10";
|
|
540
551
|
var PUBLIC_ACCESS_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
|
|
541
552
|
var PRIVATE_ACCESS_TOKEN_HEADER = "Shopify-Storefront-Private-Token";
|
|
542
553
|
var SDK_VARIANT_HEADER2 = "X-SDK-Variant";
|
|
@@ -544,7 +555,7 @@ var SDK_VERSION_HEADER2 = "X-SDK-Version";
|
|
|
544
555
|
var SDK_VARIANT_SOURCE_HEADER = "X-SDK-Variant-Source";
|
|
545
556
|
var CLIENT2 = "Storefront API Client";
|
|
546
557
|
|
|
547
|
-
// ../../node_modules/@shopify/storefront-api-client/dist/validations.mjs
|
|
558
|
+
// ../../node_modules/.bun/@shopify+storefront-api-client@1.0.10/node_modules/@shopify/storefront-api-client/dist/validations.mjs
|
|
548
559
|
function validatePrivateAccessTokenUsage(privateAccessToken) {
|
|
549
560
|
if (privateAccessToken && typeof window !== "undefined") {
|
|
550
561
|
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.`);
|
|
@@ -559,7 +570,7 @@ function validateRequiredAccessTokens(publicAccessToken, privateAccessToken) {
|
|
|
559
570
|
}
|
|
560
571
|
}
|
|
561
572
|
|
|
562
|
-
// ../../node_modules/@shopify/storefront-api-client/dist/storefront-api-client.mjs
|
|
573
|
+
// ../../node_modules/.bun/@shopify+storefront-api-client@1.0.10/node_modules/@shopify/storefront-api-client/dist/storefront-api-client.mjs
|
|
563
574
|
function createStorefrontApiClient({ storeDomain, apiVersion, publicAccessToken, privateAccessToken, clientName, retries = 0, customFetchApi, logger: logger2 }) {
|
|
564
575
|
const currentSupportedApiVersions = getCurrentSupportedApiVersions();
|
|
565
576
|
const storeUrl = validateDomainAndGetStoreUrl({
|
|
@@ -806,6 +817,12 @@ function formatResponse(params) {
|
|
|
806
817
|
};
|
|
807
818
|
}
|
|
808
819
|
|
|
820
|
+
// src/core/request-timeout.ts
|
|
821
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
|
|
822
|
+
function resolveRequestSignal(options, defaultMs = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
823
|
+
return options?.signal ?? AbortSignal.timeout(options?.timeoutMs ?? defaultMs);
|
|
824
|
+
}
|
|
825
|
+
|
|
809
826
|
// src/core/client.ts
|
|
810
827
|
var NotImplementedError = class extends Error {
|
|
811
828
|
constructor(adapterName, methodName) {
|
|
@@ -1157,7 +1174,10 @@ var BaseCommerceClient = class {
|
|
|
1157
1174
|
async fetchRequest(params) {
|
|
1158
1175
|
try {
|
|
1159
1176
|
const { url, ...fetchOptions } = params;
|
|
1160
|
-
const response = await fetch(url,
|
|
1177
|
+
const response = await fetch(url, {
|
|
1178
|
+
...fetchOptions,
|
|
1179
|
+
signal: resolveRequestSignal(fetchOptions)
|
|
1180
|
+
});
|
|
1161
1181
|
const data = await response.json();
|
|
1162
1182
|
if (response.ok) {
|
|
1163
1183
|
return formatResponse({
|
|
@@ -4289,7 +4309,7 @@ var getCommonHeaders = (config) => {
|
|
|
4289
4309
|
// src/adapters/custom/services/base.ts
|
|
4290
4310
|
var BaseCustomService = class {
|
|
4291
4311
|
constructor(baseUrl, config, logger2) {
|
|
4292
|
-
this.timeout =
|
|
4312
|
+
this.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
4293
4313
|
this.baseUrl = baseUrl;
|
|
4294
4314
|
this.config = config;
|
|
4295
4315
|
this.logger = logger2 || createDomainLogger("custom", "custom", { enabled: false });
|
|
@@ -4326,7 +4346,10 @@ var BaseCustomService = class {
|
|
|
4326
4346
|
}
|
|
4327
4347
|
const requestOptions = {
|
|
4328
4348
|
method,
|
|
4329
|
-
headers
|
|
4349
|
+
headers,
|
|
4350
|
+
// Bound the upstream wait — see core/request-timeout.ts for the policy and
|
|
4351
|
+
// rationale (Bblunt prod memory-leak postmortem, Jun 2026).
|
|
4352
|
+
signal: resolveRequestSignal(options, this.timeout)
|
|
4330
4353
|
};
|
|
4331
4354
|
if (data && method !== "GET") {
|
|
4332
4355
|
requestOptions.body = JSON.stringify(data);
|