@cmssy/core 19.34.1 → 19.35.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.
@@ -14,6 +14,7 @@ interface RetryPolicy {
14
14
  maxRetryAfterMs?: number;
15
15
  maxTotalWaitMs?: number;
16
16
  retryStatuses?: readonly number[];
17
+ paceBelowRemaining?: number;
17
18
  }
18
19
  type CmssyRetryMode = "build" | "interactive";
19
20
  type RetryOption = CmssyRetryMode | RetryPolicy | false;
@@ -71,5 +72,7 @@ declare function fetchPageById(config: CmssyClientConfig, pageId: string, option
71
72
  declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageSummary[]>;
72
73
  declare function fetchPageMeta(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageMeta | null>;
73
74
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
75
+ declare function fetchLayoutKey(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<string | null>;
76
+ declare function fetchLayoutsByKey(config: CmssyClientConfig, layoutKey: string, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyLayoutGroup[]>;
74
77
 
75
- export { type CmssyClientConfig as C, DEFAULT_CMSSY_API_URL as D, type FetchLike as F, type RetryOption as R, fetchPage as a, fetchPageById as b, fetchPageMeta as c, fetchPages as d, CMSSY_RATE_LIMIT_WINDOW_MS as e, fetchLayouts as f, CMSSY_RETRY_MODES as g, CmssyGraphqlError as h, type CmssyGraphqlErrorEntry as i, CmssyRequestError as j, type CmssyRetryMode as k, type FetchLikeResponse as l, type FetchPageOptions as m, type RetryPolicy as n, createRetryingFetch as o, isTransientRequestError as p, resolveApiUrl as r };
78
+ export { type CmssyClientConfig as C, DEFAULT_CMSSY_API_URL as D, type FetchLike as F, type RetryOption as R, fetchLayouts as a, fetchLayoutsByKey as b, fetchPage as c, fetchPageById as d, fetchPageMeta as e, fetchLayoutKey as f, fetchPages as g, CMSSY_RATE_LIMIT_WINDOW_MS as h, CMSSY_RETRY_MODES as i, CmssyGraphqlError as j, type CmssyGraphqlErrorEntry as k, CmssyRequestError as l, type CmssyRetryMode as m, type FetchLikeResponse as n, type FetchPageOptions as o, type RetryPolicy as p, createRetryingFetch as q, resolveApiUrl as r, isTransientRequestError as s };
@@ -14,6 +14,7 @@ interface RetryPolicy {
14
14
  maxRetryAfterMs?: number;
15
15
  maxTotalWaitMs?: number;
16
16
  retryStatuses?: readonly number[];
17
+ paceBelowRemaining?: number;
17
18
  }
18
19
  type CmssyRetryMode = "build" | "interactive";
19
20
  type RetryOption = CmssyRetryMode | RetryPolicy | false;
@@ -71,5 +72,7 @@ declare function fetchPageById(config: CmssyClientConfig, pageId: string, option
71
72
  declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageSummary[]>;
72
73
  declare function fetchPageMeta(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageMeta | null>;
73
74
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
75
+ declare function fetchLayoutKey(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<string | null>;
76
+ declare function fetchLayoutsByKey(config: CmssyClientConfig, layoutKey: string, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyLayoutGroup[]>;
74
77
 
75
- export { type CmssyClientConfig as C, DEFAULT_CMSSY_API_URL as D, type FetchLike as F, type RetryOption as R, fetchPage as a, fetchPageById as b, fetchPageMeta as c, fetchPages as d, CMSSY_RATE_LIMIT_WINDOW_MS as e, fetchLayouts as f, CMSSY_RETRY_MODES as g, CmssyGraphqlError as h, type CmssyGraphqlErrorEntry as i, CmssyRequestError as j, type CmssyRetryMode as k, type FetchLikeResponse as l, type FetchPageOptions as m, type RetryPolicy as n, createRetryingFetch as o, isTransientRequestError as p, resolveApiUrl as r };
78
+ export { type CmssyClientConfig as C, DEFAULT_CMSSY_API_URL as D, type FetchLike as F, type RetryOption as R, fetchLayouts as a, fetchLayoutsByKey as b, fetchPage as c, fetchPageById as d, fetchPageMeta as e, fetchLayoutKey as f, fetchPages as g, CMSSY_RATE_LIMIT_WINDOW_MS as h, CMSSY_RETRY_MODES as i, CmssyGraphqlError as j, type CmssyGraphqlErrorEntry as k, CmssyRequestError as l, type CmssyRetryMode as m, type FetchLikeResponse as n, type FetchPageOptions as o, type RetryPolicy as p, createRetryingFetch as q, resolveApiUrl as r, isTransientRequestError as s };
@@ -1,6 +1,6 @@
1
1
  import { LayoutRegion, BlockPropsSchema, InferBlockContent, CmssyFormDefinition, CmssyModelDefinition, CmssyRecordList, CmssySiteConfig, CmssyFormSubmitResponse, SubmitFormInput, BlockRect, BlockSchema, BlockMeta } from '@cmssy/types';
2
- import { C as CmssyClientConfig } from './content-client-EAeHiBv2.js';
3
- import { C as CmssyOperationInput, G as GraphqlRequestOptions, a as CmssyOperation } from './locale-Ds2uJX5V.js';
2
+ import { C as CmssyClientConfig } from './content-client-PGHzdYQn.js';
3
+ import { C as CmssyOperationInput, G as GraphqlRequestOptions, a as CmssyOperation } from './locale-Dvjh-aD8.js';
4
4
 
5
5
  interface CmssyLayout<R extends readonly LayoutRegion[] = readonly LayoutRegion[]> {
6
6
  readonly regions: R;
@@ -1,6 +1,6 @@
1
1
  import { LayoutRegion, BlockPropsSchema, InferBlockContent, CmssyFormDefinition, CmssyModelDefinition, CmssyRecordList, CmssySiteConfig, CmssyFormSubmitResponse, SubmitFormInput, BlockRect, BlockSchema, BlockMeta } from '@cmssy/types';
2
- import { C as CmssyClientConfig } from './content-client-EAeHiBv2.cjs';
3
- import { C as CmssyOperationInput, G as GraphqlRequestOptions, a as CmssyOperation } from './locale-CUk6dYTo.cjs';
2
+ import { C as CmssyClientConfig } from './content-client-PGHzdYQn.cjs';
3
+ import { C as CmssyOperationInput, G as GraphqlRequestOptions, a as CmssyOperation } from './locale-CjVdpRSB.cjs';
4
4
 
5
5
  interface CmssyLayout<R extends readonly LayoutRegion[] = readonly LayoutRegion[]> {
6
6
  readonly regions: R;
package/dist/index.cjs CHANGED
@@ -225,7 +225,7 @@ function documentText(document2) {
225
225
  }
226
226
 
227
227
  // src/version.ts
228
- var CMSSY_CORE_VERSION = "19.34.1" ;
228
+ var CMSSY_CORE_VERSION = "19.35.0" ;
229
229
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
230
230
 
231
231
  // src/data/http.ts
@@ -251,7 +251,8 @@ var CMSSY_RETRY_MODES = {
251
251
  maxDelayMs: 2e4,
252
252
  maxRetryAfterMs: CMSSY_RATE_LIMIT_WINDOW_MS,
253
253
  maxTotalWaitMs: 18e4,
254
- retryStatuses: Object.freeze([429, 503])
254
+ retryStatuses: Object.freeze([429, 503]),
255
+ paceBelowRemaining: 6
255
256
  },
256
257
  interactive: {
257
258
  maxRetries: 2,
@@ -260,7 +261,8 @@ var CMSSY_RETRY_MODES = {
260
261
  maxDelayMs: 1e3,
261
262
  maxRetryAfterMs: 1e3,
262
263
  maxTotalWaitMs: 2e3,
263
- retryStatuses: Object.freeze([429, 503])
264
+ retryStatuses: Object.freeze([429, 503]),
265
+ paceBelowRemaining: 0
264
266
  }
265
267
  };
266
268
  Object.freeze(CMSSY_RETRY_MODES.build);
@@ -290,9 +292,54 @@ function resolveRetryPolicy(retry) {
290
292
  maxDelayMs: retry.maxDelayMs ?? base.maxDelayMs,
291
293
  maxRetryAfterMs: retry.maxRetryAfterMs ?? base.maxRetryAfterMs,
292
294
  maxTotalWaitMs: retry.maxTotalWaitMs ?? base.maxTotalWaitMs,
293
- retryStatuses: retry.retryStatuses ?? base.retryStatuses
295
+ retryStatuses: retry.retryStatuses ?? base.retryStatuses,
296
+ paceBelowRemaining: retry.paceBelowRemaining ?? 0
294
297
  };
295
298
  }
299
+ var buildThrottle = /* @__PURE__ */ new Map();
300
+ function pacedBy(policy) {
301
+ return policy.paceBelowRemaining > 0 && typeof globalThis.window === "undefined";
302
+ }
303
+ function holdEndpoint(url, until) {
304
+ if (until > (buildThrottle.get(url) ?? 0)) buildThrottle.set(url, until);
305
+ }
306
+ function heldUntilMs(url) {
307
+ const until = buildThrottle.get(url);
308
+ if (until === void 0) return 0;
309
+ const left = until - Date.now();
310
+ if (left <= 0) {
311
+ buildThrottle.delete(url);
312
+ return 0;
313
+ }
314
+ return left;
315
+ }
316
+ function lowRemainingResetAt(response, threshold) {
317
+ const remainingRaw = response.headers?.get("x-ratelimit-remaining");
318
+ const resetRaw = response.headers?.get("x-ratelimit-reset");
319
+ if (!remainingRaw || !resetRaw) return null;
320
+ const remaining = Number(remainingRaw);
321
+ const reset = Number(resetRaw);
322
+ if (!Number.isFinite(remaining) || !Number.isFinite(reset)) return null;
323
+ return remaining <= threshold ? reset * 1e3 : null;
324
+ }
325
+ function observeRateLimit(url, response, policy) {
326
+ if (response.status === THROTTLE_STATUS) {
327
+ const asked = retryAfterMs(response);
328
+ if (asked !== null && asked <= policy.maxRetryAfterMs) {
329
+ holdEndpoint(url, Date.now() + asked);
330
+ }
331
+ return;
332
+ }
333
+ if (!response.ok) return;
334
+ const resetAt = lowRemainingResetAt(response, policy.paceBelowRemaining);
335
+ if (resetAt === null) return;
336
+ holdEndpoint(url, Math.min(resetAt, Date.now() + policy.maxRetryAfterMs));
337
+ }
338
+ function holdToWait(url, policy) {
339
+ const left = heldUntilMs(url);
340
+ if (left <= 0) return 0;
341
+ return Math.round(left + Math.random() * policy.throttleBaseDelayMs);
342
+ }
296
343
  function retryAfterMs(response) {
297
344
  const raw = response.headers?.get("retry-after");
298
345
  if (!raw) return null;
@@ -324,8 +371,24 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
324
371
  if (policy === null) {
325
372
  return { response: await doFetch(url, init), waitedMs: 0 };
326
373
  }
327
- let response = await doFetch(url, init);
374
+ const paced = pacedBy(policy);
328
375
  let waitedMs = 0;
376
+ const send = async () => {
377
+ if (paced) {
378
+ const hold = Math.min(
379
+ holdToWait(url, policy),
380
+ Math.max(0, policy.maxTotalWaitMs - waitedMs)
381
+ );
382
+ if (hold > 0) {
383
+ await sleep(hold, init?.signal);
384
+ waitedMs += hold;
385
+ }
386
+ }
387
+ const sent = await doFetch(url, init);
388
+ if (paced) observeRateLimit(url, sent, policy);
389
+ return sent;
390
+ };
391
+ let response = await send();
329
392
  for (let attempt = 0; attempt < policy.maxRetries; attempt++) {
330
393
  if (response.ok || !policy.retryStatuses.includes(response.status)) {
331
394
  return { response, waitedMs };
@@ -350,7 +413,7 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
350
413
  );
351
414
  await sleep(wait, init?.signal);
352
415
  waitedMs += wait;
353
- response = await doFetch(url, init);
416
+ response = await send();
354
417
  }
355
418
  return { response, waitedMs };
356
419
  }
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as CmssyRecordSort } from './csp-BI4BNbR8.cjs';
2
- export { A as AppToEditorMessage, B as BoundsMessage, d as ClickMessage, e as CmssyClient, f as CmssyConfig, g as CmssyCspOptions, h as CmssyEnvConfig, j as CmssyLayout, k as CmssyRegion, m as CmssyRegionOf, n as CmssyRegionSettings, o as CmssyRegionSettingsOf, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, I as InvisibleBlock, p as InvisibleBlocksMessage, q as InvisibleReason, P as PROTOCOL_VERSION, s as ParentReadyMessage, u as PatchMessage, v as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, w as SHORTCUT_ACTIONS, x as ScopedVariables, y as SelectMessage, z as ShortcutAction, G as ShortcutMessage, V as VariablesParameter, H as ViewportMessage, J as applyCmssyCsp, K as createCmssyClient, L as defineCmssyConfig, N as defineCmssyLayout, O as isProtocolCompatible, T as normalizeOrigin, U as parseEditorMessage, W as postToEditor, X as resolveEditorOrigin } from './csp-BI4BNbR8.cjs';
3
- import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-CUk6dYTo.cjs';
4
- export { b as CMSSY_LOCALE_HEADER, C as CmssyOperationInput, f as CmssyTypedDocument, g as graphqlRequest, d as localizeHref, h as resolveCmssyLocale, t as typedOperation } from './locale-CUk6dYTo.cjs';
5
- import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-EAeHiBv2.cjs';
6
- export { e as CMSSY_RATE_LIMIT_WINDOW_MS, g as CMSSY_RETRY_MODES, h as CmssyGraphqlError, i as CmssyGraphqlErrorEntry, j as CmssyRequestError, k as CmssyRetryMode, D as DEFAULT_CMSSY_API_URL, l as FetchLikeResponse, m as FetchPageOptions, n as RetryPolicy, o as createRetryingFetch, p as isTransientRequestError } from './content-client-EAeHiBv2.cjs';
1
+ import { C as CmssyRecordSort } from './csp-os_zXaDL.cjs';
2
+ export { A as AppToEditorMessage, B as BoundsMessage, d as ClickMessage, e as CmssyClient, f as CmssyConfig, g as CmssyCspOptions, h as CmssyEnvConfig, j as CmssyLayout, k as CmssyRegion, m as CmssyRegionOf, n as CmssyRegionSettings, o as CmssyRegionSettingsOf, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, I as InvisibleBlock, p as InvisibleBlocksMessage, q as InvisibleReason, P as PROTOCOL_VERSION, s as ParentReadyMessage, u as PatchMessage, v as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, w as SHORTCUT_ACTIONS, x as ScopedVariables, y as SelectMessage, z as ShortcutAction, G as ShortcutMessage, V as VariablesParameter, H as ViewportMessage, J as applyCmssyCsp, K as createCmssyClient, L as defineCmssyConfig, N as defineCmssyLayout, O as isProtocolCompatible, T as normalizeOrigin, U as parseEditorMessage, W as postToEditor, X as resolveEditorOrigin } from './csp-os_zXaDL.cjs';
3
+ import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-CjVdpRSB.cjs';
4
+ export { b as CMSSY_LOCALE_HEADER, C as CmssyOperationInput, f as CmssyTypedDocument, g as graphqlRequest, d as localizeHref, h as resolveCmssyLocale, t as typedOperation } from './locale-CjVdpRSB.cjs';
5
+ import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-PGHzdYQn.cjs';
6
+ export { h as CMSSY_RATE_LIMIT_WINDOW_MS, i as CMSSY_RETRY_MODES, j as CmssyGraphqlError, k as CmssyGraphqlErrorEntry, l as CmssyRequestError, m as CmssyRetryMode, D as DEFAULT_CMSSY_API_URL, n as FetchLikeResponse, o as FetchPageOptions, p as RetryPolicy, q as createRetryingFetch, s as isTransientRequestError } from './content-client-PGHzdYQn.cjs';
7
7
  import * as _cmssy_types from '@cmssy/types';
8
8
  import { CmssyPriceSource, CmssyTaxTreatmentKind, FieldOptions, FieldValidation, TypedField, FieldTypeValueMap, ResolvedMediaValue, PageRef, BlockPropsSchema, InferBlockContent, RelationMode, CmssyModelRecord, ResolvedMedia, MediaType, BlockSchema, LayoutRegion, FieldDefinition, BlockMeta, CmssyFormField, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
9
9
  export { API_TOKEN_HEADER_NAME, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BuildBlockContextExtra, CLIENT_IP_HEADER_NAME, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssySiteConfig, CmssyTaxTreatmentKind, CmssyWebhookAccountEvent, CmssyWebhookAccountRequest, CmssyWebhookAuthoringEvent, CmssyWebhookContentChange, CmssyWebhookContentEvent, CmssyWebhookEvent, CmssyWebhookEventName, CmssyWebhookOrder, CmssyWebhookOrderEvent, CmssyWebhookOrderPayload, CmssyWebhookPricingEvent, CmssyWebhookReturn, CmssyWebhookReturnEvent, CmssyWebhookReturnPayload, CmssyWebhookShipment, CmssyWebhookShipmentEvent, CmssyWebhookShipmentPayload, CmssyWebhookSubject, CmssyWebhookTaxTreatment, FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldControl, FieldDefinition, FieldOptions, FieldType, FileFieldValue, InferBlockContent, LayoutRegion, LayoutRegionId, MediaTransform, MediaType, RawBlock, RawLayoutBlock, ResolvedMedia, SubmitFormInput, TypedField, VerifyCmssyWebhookOptions, evaluateFieldConditionGroup, mediaTypeValues, taxTreatmentKindValues } from '@cmssy/types';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as CmssyRecordSort } from './csp-DVzAKOYz.js';
2
- export { A as AppToEditorMessage, B as BoundsMessage, d as ClickMessage, e as CmssyClient, f as CmssyConfig, g as CmssyCspOptions, h as CmssyEnvConfig, j as CmssyLayout, k as CmssyRegion, m as CmssyRegionOf, n as CmssyRegionSettings, o as CmssyRegionSettingsOf, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, I as InvisibleBlock, p as InvisibleBlocksMessage, q as InvisibleReason, P as PROTOCOL_VERSION, s as ParentReadyMessage, u as PatchMessage, v as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, w as SHORTCUT_ACTIONS, x as ScopedVariables, y as SelectMessage, z as ShortcutAction, G as ShortcutMessage, V as VariablesParameter, H as ViewportMessage, J as applyCmssyCsp, K as createCmssyClient, L as defineCmssyConfig, N as defineCmssyLayout, O as isProtocolCompatible, T as normalizeOrigin, U as parseEditorMessage, W as postToEditor, X as resolveEditorOrigin } from './csp-DVzAKOYz.js';
3
- import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-Ds2uJX5V.js';
4
- export { b as CMSSY_LOCALE_HEADER, C as CmssyOperationInput, f as CmssyTypedDocument, g as graphqlRequest, d as localizeHref, h as resolveCmssyLocale, t as typedOperation } from './locale-Ds2uJX5V.js';
5
- import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-EAeHiBv2.js';
6
- export { e as CMSSY_RATE_LIMIT_WINDOW_MS, g as CMSSY_RETRY_MODES, h as CmssyGraphqlError, i as CmssyGraphqlErrorEntry, j as CmssyRequestError, k as CmssyRetryMode, D as DEFAULT_CMSSY_API_URL, l as FetchLikeResponse, m as FetchPageOptions, n as RetryPolicy, o as createRetryingFetch, p as isTransientRequestError } from './content-client-EAeHiBv2.js';
1
+ import { C as CmssyRecordSort } from './csp-BluOdkER.js';
2
+ export { A as AppToEditorMessage, B as BoundsMessage, d as ClickMessage, e as CmssyClient, f as CmssyConfig, g as CmssyCspOptions, h as CmssyEnvConfig, j as CmssyLayout, k as CmssyRegion, m as CmssyRegionOf, n as CmssyRegionSettings, o as CmssyRegionSettingsOf, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, I as InvisibleBlock, p as InvisibleBlocksMessage, q as InvisibleReason, P as PROTOCOL_VERSION, s as ParentReadyMessage, u as PatchMessage, v as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, w as SHORTCUT_ACTIONS, x as ScopedVariables, y as SelectMessage, z as ShortcutAction, G as ShortcutMessage, V as VariablesParameter, H as ViewportMessage, J as applyCmssyCsp, K as createCmssyClient, L as defineCmssyConfig, N as defineCmssyLayout, O as isProtocolCompatible, T as normalizeOrigin, U as parseEditorMessage, W as postToEditor, X as resolveEditorOrigin } from './csp-BluOdkER.js';
3
+ import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-Dvjh-aD8.js';
4
+ export { b as CMSSY_LOCALE_HEADER, C as CmssyOperationInput, f as CmssyTypedDocument, g as graphqlRequest, d as localizeHref, h as resolveCmssyLocale, t as typedOperation } from './locale-Dvjh-aD8.js';
5
+ import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-PGHzdYQn.js';
6
+ export { h as CMSSY_RATE_LIMIT_WINDOW_MS, i as CMSSY_RETRY_MODES, j as CmssyGraphqlError, k as CmssyGraphqlErrorEntry, l as CmssyRequestError, m as CmssyRetryMode, D as DEFAULT_CMSSY_API_URL, n as FetchLikeResponse, o as FetchPageOptions, p as RetryPolicy, q as createRetryingFetch, s as isTransientRequestError } from './content-client-PGHzdYQn.js';
7
7
  import * as _cmssy_types from '@cmssy/types';
8
8
  import { CmssyPriceSource, CmssyTaxTreatmentKind, FieldOptions, FieldValidation, TypedField, FieldTypeValueMap, ResolvedMediaValue, PageRef, BlockPropsSchema, InferBlockContent, RelationMode, CmssyModelRecord, ResolvedMedia, MediaType, BlockSchema, LayoutRegion, FieldDefinition, BlockMeta, CmssyFormField, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
9
9
  export { API_TOKEN_HEADER_NAME, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BuildBlockContextExtra, CLIENT_IP_HEADER_NAME, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssySiteConfig, CmssyTaxTreatmentKind, CmssyWebhookAccountEvent, CmssyWebhookAccountRequest, CmssyWebhookAuthoringEvent, CmssyWebhookContentChange, CmssyWebhookContentEvent, CmssyWebhookEvent, CmssyWebhookEventName, CmssyWebhookOrder, CmssyWebhookOrderEvent, CmssyWebhookOrderPayload, CmssyWebhookPricingEvent, CmssyWebhookReturn, CmssyWebhookReturnEvent, CmssyWebhookReturnPayload, CmssyWebhookShipment, CmssyWebhookShipmentEvent, CmssyWebhookShipmentPayload, CmssyWebhookSubject, CmssyWebhookTaxTreatment, FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldControl, FieldDefinition, FieldOptions, FieldType, FileFieldValue, InferBlockContent, LayoutRegion, LayoutRegionId, MediaTransform, MediaType, RawBlock, RawLayoutBlock, ResolvedMedia, SubmitFormInput, TypedField, VerifyCmssyWebhookOptions, evaluateFieldConditionGroup, mediaTypeValues, taxTreatmentKindValues } from '@cmssy/types';
package/dist/index.js CHANGED
@@ -224,7 +224,7 @@ function documentText(document2) {
224
224
  }
225
225
 
226
226
  // src/version.ts
227
- var CMSSY_CORE_VERSION = "19.34.1" ;
227
+ var CMSSY_CORE_VERSION = "19.35.0" ;
228
228
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
229
229
 
230
230
  // src/data/http.ts
@@ -250,7 +250,8 @@ var CMSSY_RETRY_MODES = {
250
250
  maxDelayMs: 2e4,
251
251
  maxRetryAfterMs: CMSSY_RATE_LIMIT_WINDOW_MS,
252
252
  maxTotalWaitMs: 18e4,
253
- retryStatuses: Object.freeze([429, 503])
253
+ retryStatuses: Object.freeze([429, 503]),
254
+ paceBelowRemaining: 6
254
255
  },
255
256
  interactive: {
256
257
  maxRetries: 2,
@@ -259,7 +260,8 @@ var CMSSY_RETRY_MODES = {
259
260
  maxDelayMs: 1e3,
260
261
  maxRetryAfterMs: 1e3,
261
262
  maxTotalWaitMs: 2e3,
262
- retryStatuses: Object.freeze([429, 503])
263
+ retryStatuses: Object.freeze([429, 503]),
264
+ paceBelowRemaining: 0
263
265
  }
264
266
  };
265
267
  Object.freeze(CMSSY_RETRY_MODES.build);
@@ -289,9 +291,54 @@ function resolveRetryPolicy(retry) {
289
291
  maxDelayMs: retry.maxDelayMs ?? base.maxDelayMs,
290
292
  maxRetryAfterMs: retry.maxRetryAfterMs ?? base.maxRetryAfterMs,
291
293
  maxTotalWaitMs: retry.maxTotalWaitMs ?? base.maxTotalWaitMs,
292
- retryStatuses: retry.retryStatuses ?? base.retryStatuses
294
+ retryStatuses: retry.retryStatuses ?? base.retryStatuses,
295
+ paceBelowRemaining: retry.paceBelowRemaining ?? 0
293
296
  };
294
297
  }
298
+ var buildThrottle = /* @__PURE__ */ new Map();
299
+ function pacedBy(policy) {
300
+ return policy.paceBelowRemaining > 0 && typeof globalThis.window === "undefined";
301
+ }
302
+ function holdEndpoint(url, until) {
303
+ if (until > (buildThrottle.get(url) ?? 0)) buildThrottle.set(url, until);
304
+ }
305
+ function heldUntilMs(url) {
306
+ const until = buildThrottle.get(url);
307
+ if (until === void 0) return 0;
308
+ const left = until - Date.now();
309
+ if (left <= 0) {
310
+ buildThrottle.delete(url);
311
+ return 0;
312
+ }
313
+ return left;
314
+ }
315
+ function lowRemainingResetAt(response, threshold) {
316
+ const remainingRaw = response.headers?.get("x-ratelimit-remaining");
317
+ const resetRaw = response.headers?.get("x-ratelimit-reset");
318
+ if (!remainingRaw || !resetRaw) return null;
319
+ const remaining = Number(remainingRaw);
320
+ const reset = Number(resetRaw);
321
+ if (!Number.isFinite(remaining) || !Number.isFinite(reset)) return null;
322
+ return remaining <= threshold ? reset * 1e3 : null;
323
+ }
324
+ function observeRateLimit(url, response, policy) {
325
+ if (response.status === THROTTLE_STATUS) {
326
+ const asked = retryAfterMs(response);
327
+ if (asked !== null && asked <= policy.maxRetryAfterMs) {
328
+ holdEndpoint(url, Date.now() + asked);
329
+ }
330
+ return;
331
+ }
332
+ if (!response.ok) return;
333
+ const resetAt = lowRemainingResetAt(response, policy.paceBelowRemaining);
334
+ if (resetAt === null) return;
335
+ holdEndpoint(url, Math.min(resetAt, Date.now() + policy.maxRetryAfterMs));
336
+ }
337
+ function holdToWait(url, policy) {
338
+ const left = heldUntilMs(url);
339
+ if (left <= 0) return 0;
340
+ return Math.round(left + Math.random() * policy.throttleBaseDelayMs);
341
+ }
295
342
  function retryAfterMs(response) {
296
343
  const raw = response.headers?.get("retry-after");
297
344
  if (!raw) return null;
@@ -323,8 +370,24 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
323
370
  if (policy === null) {
324
371
  return { response: await doFetch(url, init), waitedMs: 0 };
325
372
  }
326
- let response = await doFetch(url, init);
373
+ const paced = pacedBy(policy);
327
374
  let waitedMs = 0;
375
+ const send = async () => {
376
+ if (paced) {
377
+ const hold = Math.min(
378
+ holdToWait(url, policy),
379
+ Math.max(0, policy.maxTotalWaitMs - waitedMs)
380
+ );
381
+ if (hold > 0) {
382
+ await sleep(hold, init?.signal);
383
+ waitedMs += hold;
384
+ }
385
+ }
386
+ const sent = await doFetch(url, init);
387
+ if (paced) observeRateLimit(url, sent, policy);
388
+ return sent;
389
+ };
390
+ let response = await send();
328
391
  for (let attempt = 0; attempt < policy.maxRetries; attempt++) {
329
392
  if (response.ok || !policy.retryStatuses.includes(response.status)) {
330
393
  return { response, waitedMs };
@@ -349,7 +412,7 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
349
412
  );
350
413
  await sleep(wait, init?.signal);
351
414
  waitedMs += wait;
352
- response = await doFetch(url, init);
415
+ response = await send();
353
416
  }
354
417
  return { response, waitedMs };
355
418
  }
@@ -154,7 +154,7 @@ function documentText(document) {
154
154
  }
155
155
 
156
156
  // src/version.ts
157
- var CMSSY_CORE_VERSION = "19.34.1" ;
157
+ var CMSSY_CORE_VERSION = "19.35.0" ;
158
158
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
159
159
 
160
160
  // src/data/http.ts
@@ -180,7 +180,8 @@ var CMSSY_RETRY_MODES = {
180
180
  maxDelayMs: 2e4,
181
181
  maxRetryAfterMs: CMSSY_RATE_LIMIT_WINDOW_MS,
182
182
  maxTotalWaitMs: 18e4,
183
- retryStatuses: Object.freeze([429, 503])
183
+ retryStatuses: Object.freeze([429, 503]),
184
+ paceBelowRemaining: 6
184
185
  },
185
186
  interactive: {
186
187
  maxRetries: 2,
@@ -189,7 +190,8 @@ var CMSSY_RETRY_MODES = {
189
190
  maxDelayMs: 1e3,
190
191
  maxRetryAfterMs: 1e3,
191
192
  maxTotalWaitMs: 2e3,
192
- retryStatuses: Object.freeze([429, 503])
193
+ retryStatuses: Object.freeze([429, 503]),
194
+ paceBelowRemaining: 0
193
195
  }
194
196
  };
195
197
  Object.freeze(CMSSY_RETRY_MODES.build);
@@ -216,9 +218,54 @@ function resolveRetryPolicy(retry) {
216
218
  maxDelayMs: retry.maxDelayMs ?? base.maxDelayMs,
217
219
  maxRetryAfterMs: retry.maxRetryAfterMs ?? base.maxRetryAfterMs,
218
220
  maxTotalWaitMs: retry.maxTotalWaitMs ?? base.maxTotalWaitMs,
219
- retryStatuses: retry.retryStatuses ?? base.retryStatuses
221
+ retryStatuses: retry.retryStatuses ?? base.retryStatuses,
222
+ paceBelowRemaining: retry.paceBelowRemaining ?? 0
220
223
  };
221
224
  }
225
+ var buildThrottle = /* @__PURE__ */ new Map();
226
+ function pacedBy(policy) {
227
+ return policy.paceBelowRemaining > 0 && typeof globalThis.window === "undefined";
228
+ }
229
+ function holdEndpoint(url, until) {
230
+ if (until > (buildThrottle.get(url) ?? 0)) buildThrottle.set(url, until);
231
+ }
232
+ function heldUntilMs(url) {
233
+ const until = buildThrottle.get(url);
234
+ if (until === void 0) return 0;
235
+ const left = until - Date.now();
236
+ if (left <= 0) {
237
+ buildThrottle.delete(url);
238
+ return 0;
239
+ }
240
+ return left;
241
+ }
242
+ function lowRemainingResetAt(response, threshold) {
243
+ const remainingRaw = response.headers?.get("x-ratelimit-remaining");
244
+ const resetRaw = response.headers?.get("x-ratelimit-reset");
245
+ if (!remainingRaw || !resetRaw) return null;
246
+ const remaining = Number(remainingRaw);
247
+ const reset = Number(resetRaw);
248
+ if (!Number.isFinite(remaining) || !Number.isFinite(reset)) return null;
249
+ return remaining <= threshold ? reset * 1e3 : null;
250
+ }
251
+ function observeRateLimit(url, response, policy) {
252
+ if (response.status === THROTTLE_STATUS) {
253
+ const asked = retryAfterMs(response);
254
+ if (asked !== null && asked <= policy.maxRetryAfterMs) {
255
+ holdEndpoint(url, Date.now() + asked);
256
+ }
257
+ return;
258
+ }
259
+ if (!response.ok) return;
260
+ const resetAt = lowRemainingResetAt(response, policy.paceBelowRemaining);
261
+ if (resetAt === null) return;
262
+ holdEndpoint(url, Math.min(resetAt, Date.now() + policy.maxRetryAfterMs));
263
+ }
264
+ function holdToWait(url, policy) {
265
+ const left = heldUntilMs(url);
266
+ if (left <= 0) return 0;
267
+ return Math.round(left + Math.random() * policy.throttleBaseDelayMs);
268
+ }
222
269
  function retryAfterMs(response) {
223
270
  const raw = response.headers?.get("retry-after");
224
271
  if (!raw) return null;
@@ -250,8 +297,24 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
250
297
  if (policy === null) {
251
298
  return { response: await doFetch(url, init), waitedMs: 0 };
252
299
  }
253
- let response = await doFetch(url, init);
300
+ const paced = pacedBy(policy);
254
301
  let waitedMs = 0;
302
+ const send = async () => {
303
+ if (paced) {
304
+ const hold = Math.min(
305
+ holdToWait(url, policy),
306
+ Math.max(0, policy.maxTotalWaitMs - waitedMs)
307
+ );
308
+ if (hold > 0) {
309
+ await sleep(hold, init?.signal);
310
+ waitedMs += hold;
311
+ }
312
+ }
313
+ const sent = await doFetch(url, init);
314
+ if (paced) observeRateLimit(url, sent, policy);
315
+ return sent;
316
+ };
317
+ let response = await send();
255
318
  for (let attempt = 0; attempt < policy.maxRetries; attempt++) {
256
319
  if (response.ok || !policy.retryStatuses.includes(response.status)) {
257
320
  return { response, waitedMs };
@@ -276,7 +339,7 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
276
339
  );
277
340
  await sleep(wait, init?.signal);
278
341
  waitedMs += wait;
279
- response = await doFetch(url, init);
342
+ response = await send();
280
343
  }
281
344
  return { response, waitedMs };
282
345
  }
@@ -1,6 +1,6 @@
1
- export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from '../locale-CUk6dYTo.cjs';
1
+ export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from '../locale-CjVdpRSB.cjs';
2
2
  export { CmssySiteLocales } from '@cmssy/types';
3
- import '../content-client-EAeHiBv2.cjs';
3
+ import '../content-client-PGHzdYQn.cjs';
4
4
 
5
5
  declare function localizedPath(slug: string, locale: string, defaultLocale: string): string;
6
6
 
@@ -1,6 +1,6 @@
1
- export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from '../locale-Ds2uJX5V.js';
1
+ export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from '../locale-Dvjh-aD8.js';
2
2
  export { CmssySiteLocales } from '@cmssy/types';
3
- import '../content-client-EAeHiBv2.js';
3
+ import '../content-client-PGHzdYQn.js';
4
4
 
5
5
  declare function localizedPath(slug: string, locale: string, defaultLocale: string): string;
6
6
 
@@ -152,7 +152,7 @@ function documentText(document) {
152
152
  }
153
153
 
154
154
  // src/version.ts
155
- var CMSSY_CORE_VERSION = "19.34.1" ;
155
+ var CMSSY_CORE_VERSION = "19.35.0" ;
156
156
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
157
157
 
158
158
  // src/data/http.ts
@@ -178,7 +178,8 @@ var CMSSY_RETRY_MODES = {
178
178
  maxDelayMs: 2e4,
179
179
  maxRetryAfterMs: CMSSY_RATE_LIMIT_WINDOW_MS,
180
180
  maxTotalWaitMs: 18e4,
181
- retryStatuses: Object.freeze([429, 503])
181
+ retryStatuses: Object.freeze([429, 503]),
182
+ paceBelowRemaining: 6
182
183
  },
183
184
  interactive: {
184
185
  maxRetries: 2,
@@ -187,7 +188,8 @@ var CMSSY_RETRY_MODES = {
187
188
  maxDelayMs: 1e3,
188
189
  maxRetryAfterMs: 1e3,
189
190
  maxTotalWaitMs: 2e3,
190
- retryStatuses: Object.freeze([429, 503])
191
+ retryStatuses: Object.freeze([429, 503]),
192
+ paceBelowRemaining: 0
191
193
  }
192
194
  };
193
195
  Object.freeze(CMSSY_RETRY_MODES.build);
@@ -214,9 +216,54 @@ function resolveRetryPolicy(retry) {
214
216
  maxDelayMs: retry.maxDelayMs ?? base.maxDelayMs,
215
217
  maxRetryAfterMs: retry.maxRetryAfterMs ?? base.maxRetryAfterMs,
216
218
  maxTotalWaitMs: retry.maxTotalWaitMs ?? base.maxTotalWaitMs,
217
- retryStatuses: retry.retryStatuses ?? base.retryStatuses
219
+ retryStatuses: retry.retryStatuses ?? base.retryStatuses,
220
+ paceBelowRemaining: retry.paceBelowRemaining ?? 0
218
221
  };
219
222
  }
223
+ var buildThrottle = /* @__PURE__ */ new Map();
224
+ function pacedBy(policy) {
225
+ return policy.paceBelowRemaining > 0 && typeof globalThis.window === "undefined";
226
+ }
227
+ function holdEndpoint(url, until) {
228
+ if (until > (buildThrottle.get(url) ?? 0)) buildThrottle.set(url, until);
229
+ }
230
+ function heldUntilMs(url) {
231
+ const until = buildThrottle.get(url);
232
+ if (until === void 0) return 0;
233
+ const left = until - Date.now();
234
+ if (left <= 0) {
235
+ buildThrottle.delete(url);
236
+ return 0;
237
+ }
238
+ return left;
239
+ }
240
+ function lowRemainingResetAt(response, threshold) {
241
+ const remainingRaw = response.headers?.get("x-ratelimit-remaining");
242
+ const resetRaw = response.headers?.get("x-ratelimit-reset");
243
+ if (!remainingRaw || !resetRaw) return null;
244
+ const remaining = Number(remainingRaw);
245
+ const reset = Number(resetRaw);
246
+ if (!Number.isFinite(remaining) || !Number.isFinite(reset)) return null;
247
+ return remaining <= threshold ? reset * 1e3 : null;
248
+ }
249
+ function observeRateLimit(url, response, policy) {
250
+ if (response.status === THROTTLE_STATUS) {
251
+ const asked = retryAfterMs(response);
252
+ if (asked !== null && asked <= policy.maxRetryAfterMs) {
253
+ holdEndpoint(url, Date.now() + asked);
254
+ }
255
+ return;
256
+ }
257
+ if (!response.ok) return;
258
+ const resetAt = lowRemainingResetAt(response, policy.paceBelowRemaining);
259
+ if (resetAt === null) return;
260
+ holdEndpoint(url, Math.min(resetAt, Date.now() + policy.maxRetryAfterMs));
261
+ }
262
+ function holdToWait(url, policy) {
263
+ const left = heldUntilMs(url);
264
+ if (left <= 0) return 0;
265
+ return Math.round(left + Math.random() * policy.throttleBaseDelayMs);
266
+ }
220
267
  function retryAfterMs(response) {
221
268
  const raw = response.headers?.get("retry-after");
222
269
  if (!raw) return null;
@@ -248,8 +295,24 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
248
295
  if (policy === null) {
249
296
  return { response: await doFetch(url, init), waitedMs: 0 };
250
297
  }
251
- let response = await doFetch(url, init);
298
+ const paced = pacedBy(policy);
252
299
  let waitedMs = 0;
300
+ const send = async () => {
301
+ if (paced) {
302
+ const hold = Math.min(
303
+ holdToWait(url, policy),
304
+ Math.max(0, policy.maxTotalWaitMs - waitedMs)
305
+ );
306
+ if (hold > 0) {
307
+ await sleep(hold, init?.signal);
308
+ waitedMs += hold;
309
+ }
310
+ }
311
+ const sent = await doFetch(url, init);
312
+ if (paced) observeRateLimit(url, sent, policy);
313
+ return sent;
314
+ };
315
+ let response = await send();
253
316
  for (let attempt = 0; attempt < policy.maxRetries; attempt++) {
254
317
  if (response.ok || !policy.retryStatuses.includes(response.status)) {
255
318
  return { response, waitedMs };
@@ -274,7 +337,7 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
274
337
  );
275
338
  await sleep(wait, init?.signal);
276
339
  waitedMs += wait;
277
- response = await doFetch(url, init);
340
+ response = await send();
278
341
  }
279
342
  return { response, waitedMs };
280
343
  }
package/dist/internal.cjs CHANGED
@@ -154,7 +154,7 @@ function documentText(document2) {
154
154
  }
155
155
 
156
156
  // src/version.ts
157
- var CMSSY_CORE_VERSION = "19.34.1" ;
157
+ var CMSSY_CORE_VERSION = "19.35.0" ;
158
158
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
159
159
 
160
160
  // src/data/http.ts
@@ -180,7 +180,8 @@ var CMSSY_RETRY_MODES = {
180
180
  maxDelayMs: 2e4,
181
181
  maxRetryAfterMs: CMSSY_RATE_LIMIT_WINDOW_MS,
182
182
  maxTotalWaitMs: 18e4,
183
- retryStatuses: Object.freeze([429, 503])
183
+ retryStatuses: Object.freeze([429, 503]),
184
+ paceBelowRemaining: 6
184
185
  },
185
186
  interactive: {
186
187
  maxRetries: 2,
@@ -189,7 +190,8 @@ var CMSSY_RETRY_MODES = {
189
190
  maxDelayMs: 1e3,
190
191
  maxRetryAfterMs: 1e3,
191
192
  maxTotalWaitMs: 2e3,
192
- retryStatuses: Object.freeze([429, 503])
193
+ retryStatuses: Object.freeze([429, 503]),
194
+ paceBelowRemaining: 0
193
195
  }
194
196
  };
195
197
  Object.freeze(CMSSY_RETRY_MODES.build);
@@ -216,9 +218,54 @@ function resolveRetryPolicy(retry) {
216
218
  maxDelayMs: retry.maxDelayMs ?? base.maxDelayMs,
217
219
  maxRetryAfterMs: retry.maxRetryAfterMs ?? base.maxRetryAfterMs,
218
220
  maxTotalWaitMs: retry.maxTotalWaitMs ?? base.maxTotalWaitMs,
219
- retryStatuses: retry.retryStatuses ?? base.retryStatuses
221
+ retryStatuses: retry.retryStatuses ?? base.retryStatuses,
222
+ paceBelowRemaining: retry.paceBelowRemaining ?? 0
220
223
  };
221
224
  }
225
+ var buildThrottle = /* @__PURE__ */ new Map();
226
+ function pacedBy(policy) {
227
+ return policy.paceBelowRemaining > 0 && typeof globalThis.window === "undefined";
228
+ }
229
+ function holdEndpoint(url, until) {
230
+ if (until > (buildThrottle.get(url) ?? 0)) buildThrottle.set(url, until);
231
+ }
232
+ function heldUntilMs(url) {
233
+ const until = buildThrottle.get(url);
234
+ if (until === void 0) return 0;
235
+ const left = until - Date.now();
236
+ if (left <= 0) {
237
+ buildThrottle.delete(url);
238
+ return 0;
239
+ }
240
+ return left;
241
+ }
242
+ function lowRemainingResetAt(response, threshold) {
243
+ const remainingRaw = response.headers?.get("x-ratelimit-remaining");
244
+ const resetRaw = response.headers?.get("x-ratelimit-reset");
245
+ if (!remainingRaw || !resetRaw) return null;
246
+ const remaining = Number(remainingRaw);
247
+ const reset = Number(resetRaw);
248
+ if (!Number.isFinite(remaining) || !Number.isFinite(reset)) return null;
249
+ return remaining <= threshold ? reset * 1e3 : null;
250
+ }
251
+ function observeRateLimit(url, response, policy) {
252
+ if (response.status === THROTTLE_STATUS) {
253
+ const asked = retryAfterMs(response);
254
+ if (asked !== null && asked <= policy.maxRetryAfterMs) {
255
+ holdEndpoint(url, Date.now() + asked);
256
+ }
257
+ return;
258
+ }
259
+ if (!response.ok) return;
260
+ const resetAt = lowRemainingResetAt(response, policy.paceBelowRemaining);
261
+ if (resetAt === null) return;
262
+ holdEndpoint(url, Math.min(resetAt, Date.now() + policy.maxRetryAfterMs));
263
+ }
264
+ function holdToWait(url, policy) {
265
+ const left = heldUntilMs(url);
266
+ if (left <= 0) return 0;
267
+ return Math.round(left + Math.random() * policy.throttleBaseDelayMs);
268
+ }
222
269
  function retryAfterMs(response) {
223
270
  const raw = response.headers?.get("retry-after");
224
271
  if (!raw) return null;
@@ -250,8 +297,24 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
250
297
  if (policy === null) {
251
298
  return { response: await doFetch(url, init), waitedMs: 0 };
252
299
  }
253
- let response = await doFetch(url, init);
300
+ const paced = pacedBy(policy);
254
301
  let waitedMs = 0;
302
+ const send = async () => {
303
+ if (paced) {
304
+ const hold = Math.min(
305
+ holdToWait(url, policy),
306
+ Math.max(0, policy.maxTotalWaitMs - waitedMs)
307
+ );
308
+ if (hold > 0) {
309
+ await sleep(hold, init?.signal);
310
+ waitedMs += hold;
311
+ }
312
+ }
313
+ const sent = await doFetch(url, init);
314
+ if (paced) observeRateLimit(url, sent, policy);
315
+ return sent;
316
+ };
317
+ let response = await send();
255
318
  for (let attempt = 0; attempt < policy.maxRetries; attempt++) {
256
319
  if (response.ok || !policy.retryStatuses.includes(response.status)) {
257
320
  return { response, waitedMs };
@@ -276,7 +339,7 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
276
339
  );
277
340
  await sleep(wait, init?.signal);
278
341
  waitedMs += wait;
279
- response = await doFetch(url, init);
342
+ response = await send();
280
343
  }
281
344
  return { response, waitedMs };
282
345
  }
@@ -439,6 +502,24 @@ var PUBLIC_PAGE_LAYOUTS_QUERY = typedOperation(`query PublicPageLayouts($workspa
439
502
  }
440
503
  }
441
504
  }`);
505
+ var PUBLIC_PAGE_LAYOUT_KEY_QUERY = typedOperation(`query PublicPageLayoutKey($workspaceSlug: String!, $pageSlug: String!) {
506
+ public {
507
+ page {
508
+ layoutKey(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug)
509
+ }
510
+ }
511
+ }`);
512
+ var PUBLIC_PAGE_LAYOUTS_BY_KEY_QUERY = typedOperation(`query PublicPageLayoutsByKey($workspaceSlug: String!, $layoutKey: String!) {
513
+ public {
514
+ page {
515
+ layoutsByKey(workspaceSlug: $workspaceSlug, layoutKey: $layoutKey) {
516
+ region
517
+ blocks { id type content style advanced order isActive }
518
+ settings
519
+ }
520
+ }
521
+ }
522
+ }`);
442
523
  function normalizeSlug(path) {
443
524
  if (Array.isArray(path)) {
444
525
  const joined = path.filter(Boolean).join("/");
@@ -573,6 +654,34 @@ async function fetchLayouts(config, path, options = {}) {
573
654
  );
574
655
  return data?.public?.page?.layouts ?? [];
575
656
  }
657
+ async function fetchLayoutKey(config, path, options = {}) {
658
+ const data = await postGraphql(
659
+ resolvePublicUrl(config),
660
+ PUBLIC_PAGE_LAYOUT_KEY_QUERY,
661
+ { workspaceSlug: config.workspaceSlug, pageSlug: normalizeSlug(path) },
662
+ {
663
+ fetch: options.fetch,
664
+ signal: options.signal,
665
+ retry: options.retry ?? "build",
666
+ label: "layout key fetch"
667
+ }
668
+ );
669
+ return data?.public?.page?.layoutKey ?? null;
670
+ }
671
+ async function fetchLayoutsByKey(config, layoutKey, options = {}) {
672
+ const data = await postGraphql(
673
+ resolvePublicUrl(config),
674
+ PUBLIC_PAGE_LAYOUTS_BY_KEY_QUERY,
675
+ { workspaceSlug: config.workspaceSlug, layoutKey },
676
+ {
677
+ fetch: options.fetch,
678
+ signal: options.signal,
679
+ retry: options.retry ?? "build",
680
+ label: "layouts by key fetch"
681
+ }
682
+ );
683
+ return data?.public?.page?.layoutsByKey ?? [];
684
+ }
576
685
 
577
686
  // src/content/get-block-content.ts
578
687
  function isPlainObject(value) {
@@ -1212,14 +1321,18 @@ function localizeHref(href, locale) {
1212
1321
  function createCmssyLayoutStore() {
1213
1322
  return /* @__PURE__ */ new Map();
1214
1323
  }
1215
- function layoutStoreKey(config, pageSlug, previewSecret) {
1216
- return [
1324
+ function layoutStoreKey(config, source) {
1325
+ const scope = [
1217
1326
  resolveApiUrl(config.apiUrl),
1218
1327
  config.org ?? "",
1219
- config.workspaceSlug,
1220
- pageSlug,
1221
- previewSecret ? "draft" : "published"
1222
- ].join("\0");
1328
+ config.workspaceSlug
1329
+ ];
1330
+ const tail = "layoutKey" in source ? ["key", source.layoutKey] : [
1331
+ "page",
1332
+ source.pageSlug,
1333
+ source.previewSecret ? "draft" : "published"
1334
+ ];
1335
+ return [...scope, ...tail].join("\0");
1223
1336
  }
1224
1337
  function readThroughLayoutStore(store, key, load) {
1225
1338
  if (!store) return load();
@@ -1490,6 +1603,14 @@ var CMSSY_DELIVERY_OPERATIONS = [
1490
1603
  purpose: "Header, footer and the other layout regions for a page.",
1491
1604
  document: PUBLIC_PAGE_LAYOUTS_QUERY
1492
1605
  },
1606
+ {
1607
+ purpose: "The layout key of a page - pages that inherit one layout share it.",
1608
+ document: PUBLIC_PAGE_LAYOUT_KEY_QUERY
1609
+ },
1610
+ {
1611
+ purpose: "Layout regions by that key - one cached read for every page sharing it.",
1612
+ document: PUBLIC_PAGE_LAYOUTS_BY_KEY_QUERY
1613
+ },
1493
1614
  {
1494
1615
  purpose: "Records of one model - the typed half of `cmssy types`.",
1495
1616
  document: MODEL_RECORDS_QUERY
@@ -1529,7 +1650,9 @@ exports.cmssyCspHeaders = cmssyCspHeaders;
1529
1650
  exports.cmssySecretsMatch = cmssySecretsMatch;
1530
1651
  exports.collectFormIds = collectFormIds;
1531
1652
  exports.createCmssyLayoutStore = createCmssyLayoutStore;
1653
+ exports.fetchLayoutKey = fetchLayoutKey;
1532
1654
  exports.fetchLayouts = fetchLayouts;
1655
+ exports.fetchLayoutsByKey = fetchLayoutsByKey;
1533
1656
  exports.fetchPage = fetchPage;
1534
1657
  exports.fetchPageById = fetchPageById;
1535
1658
  exports.fetchPageMeta = fetchPageMeta;
@@ -1,11 +1,11 @@
1
- import { C as CmssyClientConfig } from './content-client-EAeHiBv2.cjs';
2
- export { f as fetchLayouts, a as fetchPage, b as fetchPageById, c as fetchPageMeta, d as fetchPages, r as resolveApiUrl } from './content-client-EAeHiBv2.cjs';
3
- import { G as GraphqlRequestOptions } from './locale-CUk6dYTo.cjs';
4
- export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from './locale-CUk6dYTo.cjs';
1
+ import { C as CmssyClientConfig } from './content-client-PGHzdYQn.cjs';
2
+ export { f as fetchLayoutKey, a as fetchLayouts, b as fetchLayoutsByKey, c as fetchPage, d as fetchPageById, e as fetchPageMeta, g as fetchPages, r as resolveApiUrl } from './content-client-PGHzdYQn.cjs';
3
+ import { G as GraphqlRequestOptions } from './locale-CjVdpRSB.cjs';
4
+ export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from './locale-CjVdpRSB.cjs';
5
5
  import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssySiteConfig, FieldDefinition, RawBlock, CmssyLayoutGroup } from '@cmssy/types';
6
6
  export { CmssySiteLocales } from '@cmssy/types';
7
- import { Q as QueryScopedOptions } from './csp-BI4BNbR8.cjs';
8
- export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-BI4BNbR8.cjs';
7
+ import { Q as QueryScopedOptions } from './csp-os_zXaDL.cjs';
8
+ export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-os_zXaDL.cjs';
9
9
  export { localizedPath } from './internal/locale.cjs';
10
10
 
11
11
  declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
@@ -43,7 +43,13 @@ declare function resolveForms(config: CmssyClientConfig, blocks: RawBlock[], sch
43
43
 
44
44
  type CmssyLayoutStore = Map<string, Promise<CmssyLayoutGroup[]>>;
45
45
  declare function createCmssyLayoutStore(): CmssyLayoutStore;
46
- declare function layoutStoreKey(config: CmssyClientConfig, pageSlug: string, previewSecret: string | undefined): string;
46
+ type CmssyLayoutStoreSource = {
47
+ pageSlug: string;
48
+ previewSecret: string | undefined;
49
+ } | {
50
+ layoutKey: string;
51
+ };
52
+ declare function layoutStoreKey(config: CmssyClientConfig, source: CmssyLayoutStoreSource): string;
47
53
  declare function readThroughLayoutStore(store: CmssyLayoutStore | undefined, key: string, load: () => Promise<CmssyLayoutGroup[]>): Promise<CmssyLayoutGroup[]>;
48
54
 
49
55
  declare function unreachableShowWhenTargets(blockType: string, schema: Record<string, FieldDefinition>, path?: readonly string[]): string[];
@@ -56,4 +62,4 @@ interface CmssyDeliveryOperation {
56
62
  }
57
63
  declare const CMSSY_DELIVERY_OPERATIONS: readonly CmssyDeliveryOperation[];
58
64
 
59
- export { type BlockSchemaMap, CMSSY_DELIVERY_OPERATIONS, type CmssyLayoutStore, type RelationContentEntry, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchSiteConfig, getBlockContentForLanguage, layoutStoreKey, normalizeBlockContent, readThroughLayoutStore, resolveForms, resolveRelationContent, resolveWorkspaceId, unreachableShowWhenTargets };
65
+ export { type BlockSchemaMap, CMSSY_DELIVERY_OPERATIONS, type CmssyLayoutStore, type CmssyLayoutStoreSource, type RelationContentEntry, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchSiteConfig, getBlockContentForLanguage, layoutStoreKey, normalizeBlockContent, readThroughLayoutStore, resolveForms, resolveRelationContent, resolveWorkspaceId, unreachableShowWhenTargets };
@@ -1,11 +1,11 @@
1
- import { C as CmssyClientConfig } from './content-client-EAeHiBv2.js';
2
- export { f as fetchLayouts, a as fetchPage, b as fetchPageById, c as fetchPageMeta, d as fetchPages, r as resolveApiUrl } from './content-client-EAeHiBv2.js';
3
- import { G as GraphqlRequestOptions } from './locale-Ds2uJX5V.js';
4
- export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from './locale-Ds2uJX5V.js';
1
+ import { C as CmssyClientConfig } from './content-client-PGHzdYQn.js';
2
+ export { f as fetchLayoutKey, a as fetchLayouts, b as fetchLayoutsByKey, c as fetchPage, d as fetchPageById, e as fetchPageMeta, g as fetchPages, r as resolveApiUrl } from './content-client-PGHzdYQn.js';
3
+ import { G as GraphqlRequestOptions } from './locale-Dvjh-aD8.js';
4
+ export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from './locale-Dvjh-aD8.js';
5
5
  import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssySiteConfig, FieldDefinition, RawBlock, CmssyLayoutGroup } from '@cmssy/types';
6
6
  export { CmssySiteLocales } from '@cmssy/types';
7
- import { Q as QueryScopedOptions } from './csp-DVzAKOYz.js';
8
- export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-DVzAKOYz.js';
7
+ import { Q as QueryScopedOptions } from './csp-BluOdkER.js';
8
+ export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-BluOdkER.js';
9
9
  export { localizedPath } from './internal/locale.js';
10
10
 
11
11
  declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
@@ -43,7 +43,13 @@ declare function resolveForms(config: CmssyClientConfig, blocks: RawBlock[], sch
43
43
 
44
44
  type CmssyLayoutStore = Map<string, Promise<CmssyLayoutGroup[]>>;
45
45
  declare function createCmssyLayoutStore(): CmssyLayoutStore;
46
- declare function layoutStoreKey(config: CmssyClientConfig, pageSlug: string, previewSecret: string | undefined): string;
46
+ type CmssyLayoutStoreSource = {
47
+ pageSlug: string;
48
+ previewSecret: string | undefined;
49
+ } | {
50
+ layoutKey: string;
51
+ };
52
+ declare function layoutStoreKey(config: CmssyClientConfig, source: CmssyLayoutStoreSource): string;
47
53
  declare function readThroughLayoutStore(store: CmssyLayoutStore | undefined, key: string, load: () => Promise<CmssyLayoutGroup[]>): Promise<CmssyLayoutGroup[]>;
48
54
 
49
55
  declare function unreachableShowWhenTargets(blockType: string, schema: Record<string, FieldDefinition>, path?: readonly string[]): string[];
@@ -56,4 +62,4 @@ interface CmssyDeliveryOperation {
56
62
  }
57
63
  declare const CMSSY_DELIVERY_OPERATIONS: readonly CmssyDeliveryOperation[];
58
64
 
59
- export { type BlockSchemaMap, CMSSY_DELIVERY_OPERATIONS, type CmssyLayoutStore, type RelationContentEntry, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchSiteConfig, getBlockContentForLanguage, layoutStoreKey, normalizeBlockContent, readThroughLayoutStore, resolveForms, resolveRelationContent, resolveWorkspaceId, unreachableShowWhenTargets };
65
+ export { type BlockSchemaMap, CMSSY_DELIVERY_OPERATIONS, type CmssyLayoutStore, type CmssyLayoutStoreSource, type RelationContentEntry, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchSiteConfig, getBlockContentForLanguage, layoutStoreKey, normalizeBlockContent, readThroughLayoutStore, resolveForms, resolveRelationContent, resolveWorkspaceId, unreachableShowWhenTargets };
package/dist/internal.js CHANGED
@@ -152,7 +152,7 @@ function documentText(document2) {
152
152
  }
153
153
 
154
154
  // src/version.ts
155
- var CMSSY_CORE_VERSION = "19.34.1" ;
155
+ var CMSSY_CORE_VERSION = "19.35.0" ;
156
156
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
157
157
 
158
158
  // src/data/http.ts
@@ -178,7 +178,8 @@ var CMSSY_RETRY_MODES = {
178
178
  maxDelayMs: 2e4,
179
179
  maxRetryAfterMs: CMSSY_RATE_LIMIT_WINDOW_MS,
180
180
  maxTotalWaitMs: 18e4,
181
- retryStatuses: Object.freeze([429, 503])
181
+ retryStatuses: Object.freeze([429, 503]),
182
+ paceBelowRemaining: 6
182
183
  },
183
184
  interactive: {
184
185
  maxRetries: 2,
@@ -187,7 +188,8 @@ var CMSSY_RETRY_MODES = {
187
188
  maxDelayMs: 1e3,
188
189
  maxRetryAfterMs: 1e3,
189
190
  maxTotalWaitMs: 2e3,
190
- retryStatuses: Object.freeze([429, 503])
191
+ retryStatuses: Object.freeze([429, 503]),
192
+ paceBelowRemaining: 0
191
193
  }
192
194
  };
193
195
  Object.freeze(CMSSY_RETRY_MODES.build);
@@ -214,9 +216,54 @@ function resolveRetryPolicy(retry) {
214
216
  maxDelayMs: retry.maxDelayMs ?? base.maxDelayMs,
215
217
  maxRetryAfterMs: retry.maxRetryAfterMs ?? base.maxRetryAfterMs,
216
218
  maxTotalWaitMs: retry.maxTotalWaitMs ?? base.maxTotalWaitMs,
217
- retryStatuses: retry.retryStatuses ?? base.retryStatuses
219
+ retryStatuses: retry.retryStatuses ?? base.retryStatuses,
220
+ paceBelowRemaining: retry.paceBelowRemaining ?? 0
218
221
  };
219
222
  }
223
+ var buildThrottle = /* @__PURE__ */ new Map();
224
+ function pacedBy(policy) {
225
+ return policy.paceBelowRemaining > 0 && typeof globalThis.window === "undefined";
226
+ }
227
+ function holdEndpoint(url, until) {
228
+ if (until > (buildThrottle.get(url) ?? 0)) buildThrottle.set(url, until);
229
+ }
230
+ function heldUntilMs(url) {
231
+ const until = buildThrottle.get(url);
232
+ if (until === void 0) return 0;
233
+ const left = until - Date.now();
234
+ if (left <= 0) {
235
+ buildThrottle.delete(url);
236
+ return 0;
237
+ }
238
+ return left;
239
+ }
240
+ function lowRemainingResetAt(response, threshold) {
241
+ const remainingRaw = response.headers?.get("x-ratelimit-remaining");
242
+ const resetRaw = response.headers?.get("x-ratelimit-reset");
243
+ if (!remainingRaw || !resetRaw) return null;
244
+ const remaining = Number(remainingRaw);
245
+ const reset = Number(resetRaw);
246
+ if (!Number.isFinite(remaining) || !Number.isFinite(reset)) return null;
247
+ return remaining <= threshold ? reset * 1e3 : null;
248
+ }
249
+ function observeRateLimit(url, response, policy) {
250
+ if (response.status === THROTTLE_STATUS) {
251
+ const asked = retryAfterMs(response);
252
+ if (asked !== null && asked <= policy.maxRetryAfterMs) {
253
+ holdEndpoint(url, Date.now() + asked);
254
+ }
255
+ return;
256
+ }
257
+ if (!response.ok) return;
258
+ const resetAt = lowRemainingResetAt(response, policy.paceBelowRemaining);
259
+ if (resetAt === null) return;
260
+ holdEndpoint(url, Math.min(resetAt, Date.now() + policy.maxRetryAfterMs));
261
+ }
262
+ function holdToWait(url, policy) {
263
+ const left = heldUntilMs(url);
264
+ if (left <= 0) return 0;
265
+ return Math.round(left + Math.random() * policy.throttleBaseDelayMs);
266
+ }
220
267
  function retryAfterMs(response) {
221
268
  const raw = response.headers?.get("retry-after");
222
269
  if (!raw) return null;
@@ -248,8 +295,24 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
248
295
  if (policy === null) {
249
296
  return { response: await doFetch(url, init), waitedMs: 0 };
250
297
  }
251
- let response = await doFetch(url, init);
298
+ const paced = pacedBy(policy);
252
299
  let waitedMs = 0;
300
+ const send = async () => {
301
+ if (paced) {
302
+ const hold = Math.min(
303
+ holdToWait(url, policy),
304
+ Math.max(0, policy.maxTotalWaitMs - waitedMs)
305
+ );
306
+ if (hold > 0) {
307
+ await sleep(hold, init?.signal);
308
+ waitedMs += hold;
309
+ }
310
+ }
311
+ const sent = await doFetch(url, init);
312
+ if (paced) observeRateLimit(url, sent, policy);
313
+ return sent;
314
+ };
315
+ let response = await send();
253
316
  for (let attempt = 0; attempt < policy.maxRetries; attempt++) {
254
317
  if (response.ok || !policy.retryStatuses.includes(response.status)) {
255
318
  return { response, waitedMs };
@@ -274,7 +337,7 @@ async function fetchWithRetry(doFetch, url, init, retry, label) {
274
337
  );
275
338
  await sleep(wait, init?.signal);
276
339
  waitedMs += wait;
277
- response = await doFetch(url, init);
340
+ response = await send();
278
341
  }
279
342
  return { response, waitedMs };
280
343
  }
@@ -437,6 +500,24 @@ var PUBLIC_PAGE_LAYOUTS_QUERY = typedOperation(`query PublicPageLayouts($workspa
437
500
  }
438
501
  }
439
502
  }`);
503
+ var PUBLIC_PAGE_LAYOUT_KEY_QUERY = typedOperation(`query PublicPageLayoutKey($workspaceSlug: String!, $pageSlug: String!) {
504
+ public {
505
+ page {
506
+ layoutKey(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug)
507
+ }
508
+ }
509
+ }`);
510
+ var PUBLIC_PAGE_LAYOUTS_BY_KEY_QUERY = typedOperation(`query PublicPageLayoutsByKey($workspaceSlug: String!, $layoutKey: String!) {
511
+ public {
512
+ page {
513
+ layoutsByKey(workspaceSlug: $workspaceSlug, layoutKey: $layoutKey) {
514
+ region
515
+ blocks { id type content style advanced order isActive }
516
+ settings
517
+ }
518
+ }
519
+ }
520
+ }`);
440
521
  function normalizeSlug(path) {
441
522
  if (Array.isArray(path)) {
442
523
  const joined = path.filter(Boolean).join("/");
@@ -571,6 +652,34 @@ async function fetchLayouts(config, path, options = {}) {
571
652
  );
572
653
  return data?.public?.page?.layouts ?? [];
573
654
  }
655
+ async function fetchLayoutKey(config, path, options = {}) {
656
+ const data = await postGraphql(
657
+ resolvePublicUrl(config),
658
+ PUBLIC_PAGE_LAYOUT_KEY_QUERY,
659
+ { workspaceSlug: config.workspaceSlug, pageSlug: normalizeSlug(path) },
660
+ {
661
+ fetch: options.fetch,
662
+ signal: options.signal,
663
+ retry: options.retry ?? "build",
664
+ label: "layout key fetch"
665
+ }
666
+ );
667
+ return data?.public?.page?.layoutKey ?? null;
668
+ }
669
+ async function fetchLayoutsByKey(config, layoutKey, options = {}) {
670
+ const data = await postGraphql(
671
+ resolvePublicUrl(config),
672
+ PUBLIC_PAGE_LAYOUTS_BY_KEY_QUERY,
673
+ { workspaceSlug: config.workspaceSlug, layoutKey },
674
+ {
675
+ fetch: options.fetch,
676
+ signal: options.signal,
677
+ retry: options.retry ?? "build",
678
+ label: "layouts by key fetch"
679
+ }
680
+ );
681
+ return data?.public?.page?.layoutsByKey ?? [];
682
+ }
574
683
 
575
684
  // src/content/get-block-content.ts
576
685
  function isPlainObject(value) {
@@ -1210,14 +1319,18 @@ function localizeHref(href, locale) {
1210
1319
  function createCmssyLayoutStore() {
1211
1320
  return /* @__PURE__ */ new Map();
1212
1321
  }
1213
- function layoutStoreKey(config, pageSlug, previewSecret) {
1214
- return [
1322
+ function layoutStoreKey(config, source) {
1323
+ const scope = [
1215
1324
  resolveApiUrl(config.apiUrl),
1216
1325
  config.org ?? "",
1217
- config.workspaceSlug,
1218
- pageSlug,
1219
- previewSecret ? "draft" : "published"
1220
- ].join("\0");
1326
+ config.workspaceSlug
1327
+ ];
1328
+ const tail = "layoutKey" in source ? ["key", source.layoutKey] : [
1329
+ "page",
1330
+ source.pageSlug,
1331
+ source.previewSecret ? "draft" : "published"
1332
+ ];
1333
+ return [...scope, ...tail].join("\0");
1221
1334
  }
1222
1335
  function readThroughLayoutStore(store, key, load) {
1223
1336
  if (!store) return load();
@@ -1488,6 +1601,14 @@ var CMSSY_DELIVERY_OPERATIONS = [
1488
1601
  purpose: "Header, footer and the other layout regions for a page.",
1489
1602
  document: PUBLIC_PAGE_LAYOUTS_QUERY
1490
1603
  },
1604
+ {
1605
+ purpose: "The layout key of a page - pages that inherit one layout share it.",
1606
+ document: PUBLIC_PAGE_LAYOUT_KEY_QUERY
1607
+ },
1608
+ {
1609
+ purpose: "Layout regions by that key - one cached read for every page sharing it.",
1610
+ document: PUBLIC_PAGE_LAYOUTS_BY_KEY_QUERY
1611
+ },
1491
1612
  {
1492
1613
  purpose: "Records of one model - the typed half of `cmssy types`.",
1493
1614
  document: MODEL_RECORDS_QUERY
@@ -1513,4 +1634,4 @@ function layoutRegionIds(layout) {
1513
1634
  return (layout?.regions ?? DEFAULT_LAYOUT_REGIONS).map((region) => region.id);
1514
1635
  }
1515
1636
 
1516
- export { CMSSY_DELIVERY_OPERATIONS, CMSSY_LOCALE_HEADER, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssyCspHeaders, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchLayouts, fetchPage, fetchPageById, fetchPageMeta, fetchPages, fetchSiteConfig, getBlockContentForLanguage, isDevelopment, layoutRegionIds, layoutStoreKey, localeForPath, localeForPathname, localizeHref, localizedPath, normalizeBlockContent, readThroughLayoutStore, resolveApiUrl, resolveForms, resolveInitialTarget, resolveRelationContent, resolveSiteLocales, resolveWorkspaceId, splitCmssyLocale, splitLocaleFromPath, toCspOrigin, unreachableShowWhenTargets };
1637
+ export { CMSSY_DELIVERY_OPERATIONS, CMSSY_LOCALE_HEADER, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssyCspHeaders, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchLayoutKey, fetchLayouts, fetchLayoutsByKey, fetchPage, fetchPageById, fetchPageMeta, fetchPages, fetchSiteConfig, getBlockContentForLanguage, isDevelopment, layoutRegionIds, layoutStoreKey, localeForPath, localeForPathname, localizeHref, localizedPath, normalizeBlockContent, readThroughLayoutStore, resolveApiUrl, resolveForms, resolveInitialTarget, resolveRelationContent, resolveSiteLocales, resolveWorkspaceId, splitCmssyLocale, splitLocaleFromPath, toCspOrigin, unreachableShowWhenTargets };
@@ -1,5 +1,5 @@
1
1
  import { CmssyLocaleContext, CmssySiteLocales } from '@cmssy/types';
2
- import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-EAeHiBv2.cjs';
2
+ import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-PGHzdYQn.cjs';
3
3
 
4
4
  interface CmssyTypedDocument<Result, Variables> {
5
5
  __apiType?: (variables: Variables) => Result;
@@ -1,5 +1,5 @@
1
1
  import { CmssyLocaleContext, CmssySiteLocales } from '@cmssy/types';
2
- import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-EAeHiBv2.js';
2
+ import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-PGHzdYQn.js';
3
3
 
4
4
  interface CmssyTypedDocument<Result, Variables> {
5
5
  __apiType?: (variables: Variables) => Result;
@@ -152,7 +152,7 @@ function documentText(document) {
152
152
  }
153
153
 
154
154
  // src/version.ts
155
- var CMSSY_CORE_VERSION = "19.34.1" ;
155
+ var CMSSY_CORE_VERSION = "19.35.0" ;
156
156
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
157
157
 
158
158
  // src/content/content-client.ts
@@ -1,4 +1,4 @@
1
- import { F as FetchLike, C as CmssyClientConfig } from './content-client-EAeHiBv2.cjs';
1
+ import { F as FetchLike, C as CmssyClientConfig } from './content-client-PGHzdYQn.cjs';
2
2
  import '@cmssy/types';
3
3
 
4
4
  interface EditDiagnosticsConfig {
@@ -1,4 +1,4 @@
1
- import { F as FetchLike, C as CmssyClientConfig } from './content-client-EAeHiBv2.js';
1
+ import { F as FetchLike, C as CmssyClientConfig } from './content-client-PGHzdYQn.js';
2
2
  import '@cmssy/types';
3
3
 
4
4
  interface EditDiagnosticsConfig {
package/dist/preflight.js CHANGED
@@ -150,7 +150,7 @@ function documentText(document) {
150
150
  }
151
151
 
152
152
  // src/version.ts
153
- var CMSSY_CORE_VERSION = "19.34.1" ;
153
+ var CMSSY_CORE_VERSION = "19.35.0" ;
154
154
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
155
155
 
156
156
  // src/content/content-client.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/core",
3
- "version": "19.34.1",
3
+ "version": "19.35.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },