@shopkit/data-layer 1.2.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { I as ICommerceClient } from './interface-NJcjuqaL.mjs';
2
- import { I as IShopifyConfig, L as LoggerConfig, S as ShopifyCommerceClient, a as ICustomConfig, C as CustomBackendClient } from './service-DBKEK2oS.mjs';
2
+ import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-DBKEK2oS.mjs';
3
3
  export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest } from './models/index.mjs';
4
4
  export { createCollectionProductStaticParams, createCollectionStaticParams, createProductStaticParams, createProductViaCollectionsStaticParams } from './static-params/index.mjs';
5
5
 
@@ -91,4 +91,35 @@ type IClientConfig = {
91
91
  */
92
92
  declare function createCommerceClient(clientConfig: IClientConfig): ICommerceClient;
93
93
 
94
- export { type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, createCommerceClient, createCustomClient, createShopifyClient };
94
+ /**
95
+ * Centralized HTTP request deadline policy.
96
+ *
97
+ * Every upstream fetch made by this package MUST carry an AbortSignal.
98
+ * An unbounded fetch against a hung upstream never settles, which pins
99
+ * the awaiting caller (e.g. a Next.js SSR render and all its data) in
100
+ * memory indefinitely — root cause of the Bblunt prod memory leak
101
+ * (Jun 2026). See __tests__/adapters/custom/services/base.test.ts for
102
+ * the regression tests.
103
+ *
104
+ * Chosen default: 10s. Render-path APIs (products/collections) measure
105
+ * P99 well under 1s, while checkout-flow operations have P99s of 9–12s;
106
+ * 10s bounds the leak without failing legitimate slow checkout calls.
107
+ * Callers can tighten or loosen per request via options.timeoutMs, or
108
+ * take full control with options.signal.
109
+ */
110
+ /** Single source of truth for the default upstream request deadline. */
111
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
112
+ /**
113
+ * Resolve the AbortSignal for an upstream request.
114
+ *
115
+ * Precedence: caller-provided signal > caller timeoutMs > defaultMs.
116
+ *
117
+ * @param options - Request options possibly carrying signal/timeoutMs
118
+ * @param defaultMs - Fallback deadline (defaults to DEFAULT_REQUEST_TIMEOUT_MS)
119
+ */
120
+ declare function resolveRequestSignal(options?: {
121
+ signal?: AbortSignal | null;
122
+ timeoutMs?: number;
123
+ }, defaultMs?: number): AbortSignal;
124
+
125
+ export { DEFAULT_REQUEST_TIMEOUT_MS, type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, createCommerceClient, createCustomClient, createShopifyClient, resolveRequestSignal };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { I as ICommerceClient } from './interface-dqoKc63z.js';
2
- import { I as IShopifyConfig, L as LoggerConfig, S as ShopifyCommerceClient, a as ICustomConfig, C as CustomBackendClient } from './service-BHCLUEim.js';
2
+ import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-BHCLUEim.js';
3
3
  export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest } from './models/index.js';
4
4
  export { createCollectionProductStaticParams, createCollectionStaticParams, createProductStaticParams, createProductViaCollectionsStaticParams } from './static-params/index.js';
5
5
 
@@ -91,4 +91,35 @@ type IClientConfig = {
91
91
  */
92
92
  declare function createCommerceClient(clientConfig: IClientConfig): ICommerceClient;
93
93
 
94
- export { type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, createCommerceClient, createCustomClient, createShopifyClient };
94
+ /**
95
+ * Centralized HTTP request deadline policy.
96
+ *
97
+ * Every upstream fetch made by this package MUST carry an AbortSignal.
98
+ * An unbounded fetch against a hung upstream never settles, which pins
99
+ * the awaiting caller (e.g. a Next.js SSR render and all its data) in
100
+ * memory indefinitely — root cause of the Bblunt prod memory leak
101
+ * (Jun 2026). See __tests__/adapters/custom/services/base.test.ts for
102
+ * the regression tests.
103
+ *
104
+ * Chosen default: 10s. Render-path APIs (products/collections) measure
105
+ * P99 well under 1s, while checkout-flow operations have P99s of 9–12s;
106
+ * 10s bounds the leak without failing legitimate slow checkout calls.
107
+ * Callers can tighten or loosen per request via options.timeoutMs, or
108
+ * take full control with options.signal.
109
+ */
110
+ /** Single source of truth for the default upstream request deadline. */
111
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
112
+ /**
113
+ * Resolve the AbortSignal for an upstream request.
114
+ *
115
+ * Precedence: caller-provided signal > caller timeoutMs > defaultMs.
116
+ *
117
+ * @param options - Request options possibly carrying signal/timeoutMs
118
+ * @param defaultMs - Fallback deadline (defaults to DEFAULT_REQUEST_TIMEOUT_MS)
119
+ */
120
+ declare function resolveRequestSignal(options?: {
121
+ signal?: AbortSignal | null;
122
+ timeoutMs?: number;
123
+ }, defaultMs?: number): AbortSignal;
124
+
125
+ export { DEFAULT_REQUEST_TIMEOUT_MS, type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, createCommerceClient, createCustomClient, createShopifyClient, resolveRequestSignal };
package/dist/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.1";
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
- const processedResponse = await processJSONResponse(response);
300
- yield {
301
- ...processedResponse,
302
- hasNext: false
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.9";
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, fetchOptions);
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({
@@ -4284,7 +4304,7 @@ var getCommonHeaders = (config) => {
4284
4304
  // src/adapters/custom/services/base.ts
4285
4305
  var BaseCustomService = class {
4286
4306
  constructor(baseUrl, config, logger2) {
4287
- this.timeout = 5e3;
4307
+ this.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
4288
4308
  this.baseUrl = baseUrl;
4289
4309
  this.config = config;
4290
4310
  this.logger = logger2 || createDomainLogger("custom", "custom", { enabled: false });
@@ -4321,7 +4341,10 @@ var BaseCustomService = class {
4321
4341
  }
4322
4342
  const requestOptions = {
4323
4343
  method,
4324
- headers
4344
+ headers,
4345
+ // Bound the upstream wait — see core/request-timeout.ts for the policy and
4346
+ // rationale (Bblunt prod memory-leak postmortem, Jun 2026).
4347
+ signal: resolveRequestSignal(options, this.timeout)
4325
4348
  };
4326
4349
  if (data && method !== "GET") {
4327
4350
  requestOptions.body = JSON.stringify(data);
@@ -5661,6 +5684,7 @@ function createCollectionProductStaticParams(getClient, options) {
5661
5684
  };
5662
5685
  }
5663
5686
 
5687
+ exports.DEFAULT_REQUEST_TIMEOUT_MS = DEFAULT_REQUEST_TIMEOUT_MS;
5664
5688
  exports.EAvailability = EAvailability;
5665
5689
  exports.ECollectionSortKey = ECollectionSortKey;
5666
5690
  exports.EFulfillmentStatus = EFulfillmentStatus;
@@ -5675,5 +5699,6 @@ exports.createCustomClient = createCustomClient;
5675
5699
  exports.createProductStaticParams = createProductStaticParams;
5676
5700
  exports.createProductViaCollectionsStaticParams = createProductViaCollectionsStaticParams;
5677
5701
  exports.createShopifyClient = createShopifyClient;
5702
+ exports.resolveRequestSignal = resolveRequestSignal;
5678
5703
  //# sourceMappingURL=index.js.map
5679
5704
  //# sourceMappingURL=index.js.map