lynkow 1.34.0 → 1.40.1

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 CHANGED
@@ -69,6 +69,12 @@ interface ClientConfig {
69
69
  // Optional: Enable SDK in-memory cache (default: false)
70
70
  // Set to true for browser SPAs that benefit from localStorage caching
71
71
  cache?: boolean
72
+
73
+ // Optional: Auto-retry transient failures on reads (default: true)
74
+ // Retries 429/503/network errors with exponential backoff, honoring the
75
+ // server's Retry-After header. Submissions (POST) are never retried.
76
+ // Set to false to disable, or tune with { retries, backoffMs, maxDelayMs }
77
+ retry?: RetryConfig | boolean
72
78
  }
73
79
  ```
74
80
 
package/dist/index.d.mts CHANGED
@@ -23,16 +23,27 @@ declare function createCache(config?: CacheConfig): {
23
23
  };
24
24
  type Cache = ReturnType<typeof createCache>;
25
25
 
26
+ /** Resolved (fully-defaulted) retry policy used by the fetch layer. */
27
+ interface ResolvedRetry {
28
+ retries: number;
29
+ backoffMs: number;
30
+ maxDelayMs: number;
31
+ }
32
+
26
33
  /**
27
34
  * Normalized internal configuration
28
35
  */
29
36
  interface InternalConfig {
30
37
  siteId: string;
31
38
  baseUrl: string;
39
+ /** Optional publishable key sent as the `X-Lynkow-Pk` header on every storefront API request. */
40
+ publishableKey?: string;
32
41
  locale?: string;
33
42
  fetchOptions: RequestInit;
34
43
  /** Optional cache manager for caching responses */
35
44
  cache?: Cache;
45
+ /** Optional retry policy for transient failures; normalized once in the service constructor. */
46
+ retry?: RetryConfig | boolean;
36
47
  }
37
48
  /**
38
49
  * Base service that all specific services inherit from
@@ -40,6 +51,7 @@ interface InternalConfig {
40
51
  declare abstract class BaseService {
41
52
  protected config: InternalConfig;
42
53
  protected cache?: Cache;
54
+ protected retry: ResolvedRetry;
43
55
  constructor(config: InternalConfig);
44
56
  /**
45
57
  * Builds the full URL for an endpoint
@@ -1782,6 +1794,56 @@ interface SearchProfilePublic {
1782
1794
  maxLimit: number;
1783
1795
  }
1784
1796
 
1797
+ /**
1798
+ * Automatic retry policy for transient failures.
1799
+ *
1800
+ * The SDK retries a request when it fails in a way that is likely to succeed on
1801
+ * a second attempt, using exponential backoff and honoring the server's
1802
+ * `Retry-After` header when present. Retries are enabled by default, which keeps
1803
+ * large static-site builds (SSG/ISR prerender fires many requests at once) from
1804
+ * failing the whole build on a short-lived rate limit.
1805
+ *
1806
+ * Only reads are retried: `GET` requests and text endpoints (sitemap, robots,
1807
+ * llms.txt, markdown) are retried on HTTP 429, HTTP 503, and network errors.
1808
+ * Submissions (`POST`, e.g. form and review submits) are never retried, so a
1809
+ * request that may have been processed is not sent twice.
1810
+ *
1811
+ * Pass `retry: false` to disable retries entirely.
1812
+ *
1813
+ * @example
1814
+ * ```typescript
1815
+ * // Tune the retry policy
1816
+ * createClient({ siteId, retry: { retries: 5, backoffMs: 250, maxDelayMs: 10000 } })
1817
+ *
1818
+ * // Disable retries
1819
+ * createClient({ siteId, retry: false })
1820
+ * ```
1821
+ */
1822
+ interface RetryConfig {
1823
+ /**
1824
+ * Maximum number of retry attempts after the initial request.
1825
+ * Set to `0` to disable retries (equivalent to `retry: false`).
1826
+ *
1827
+ * @default 3
1828
+ */
1829
+ retries?: number;
1830
+ /**
1831
+ * Base delay in milliseconds for exponential backoff, used when the response
1832
+ * carries no `Retry-After` header. The nth retry (0-indexed) waits about
1833
+ * `backoffMs * 2^n` plus a small random jitter, capped by `maxDelayMs`.
1834
+ *
1835
+ * @default 500
1836
+ */
1837
+ backoffMs?: number;
1838
+ /**
1839
+ * Upper bound in milliseconds for any single wait between attempts. Also caps
1840
+ * a large `Retry-After` value, so one rate-limited request can never stall a
1841
+ * build indefinitely.
1842
+ *
1843
+ * @default 20000
1844
+ */
1845
+ maxDelayMs?: number;
1846
+ }
1785
1847
  /**
1786
1848
  * Configuration for creating a Lynkow client instance.
1787
1849
  * Only `siteId` is required; all other options have sensible defaults.
@@ -1800,11 +1862,22 @@ interface LynkowConfig {
1800
1862
  * UUID of the Lynkow site to connect to.
1801
1863
  * Found in the admin dashboard under Site Settings.
1802
1864
  * Must be a valid UUID v4 format (lowercase hex with dashes).
1803
- * Sent as the `X-Site-Id` header on every API request.
1865
+ * Interpolated into the path of every request (`/storefront/:siteId/...`)
1866
+ * to identify the tenant. It is not sent as a header.
1804
1867
  *
1805
1868
  * @example '550e8400-e29b-41d4-a716-446655440000'
1806
1869
  */
1807
1870
  siteId: string;
1871
+ /**
1872
+ * Optional publishable key that identifies this client to the Lynkow
1873
+ * storefront API. Copied from the admin dashboard under Site Settings.
1874
+ * It has the form `lkw_pk_` followed by 24 characters.
1875
+ * When set, it is sent as the `X-Lynkow-Pk` header on every storefront API request the client makes.
1876
+ * Optional on CMS content routes; required on future commerce routes.
1877
+ *
1878
+ * @example 'lkw_pk_9f8g7h6j5k4w3m2n1p0qrstv'
1879
+ */
1880
+ publishableKey?: string;
1808
1881
  /**
1809
1882
  * Base URL of the Lynkow API.
1810
1883
  * Must not include a trailing slash.
@@ -1839,6 +1912,25 @@ interface LynkowConfig {
1839
1912
  * ```
1840
1913
  */
1841
1914
  fetchOptions?: RequestInit;
1915
+ /**
1916
+ * Automatic retry policy for transient failures (HTTP 429, HTTP 503, and
1917
+ * network errors on read requests). Enabled by default with sensible backoff
1918
+ * that honors the server's `Retry-After` header. Pass `false` to disable, or a
1919
+ * {@link RetryConfig} object to tune it. See {@link RetryConfig} for the full
1920
+ * behavior and defaults.
1921
+ *
1922
+ * @default true
1923
+ *
1924
+ * @example
1925
+ * ```typescript
1926
+ * // Disable retries
1927
+ * { retry: false }
1928
+ *
1929
+ * // Tune retries
1930
+ * { retry: { retries: 5, backoffMs: 250, maxDelayMs: 10000 } }
1931
+ * ```
1932
+ */
1933
+ retry?: RetryConfig | boolean;
1842
1934
  }
1843
1935
  /**
1844
1936
  * Lynkow Client interface -- the main SDK entry point.
@@ -2382,13 +2474,13 @@ interface Category {
2382
2474
  * - `'standard'`: articles use the TipTap rich text editor (stored in `Content.body`)
2383
2475
  * - `'structured'`: articles use custom fields defined by the category's schema (stored in `Content.customData`)
2384
2476
  *
2385
- * Only present in detail responses (`GET /public/categories/:id`), not in lightweight
2477
+ * Only present in detail responses (`GET /storefront/categories/:id`), not in lightweight
2386
2478
  * list projections (e.g. when categories are embedded in content responses).
2387
2479
  */
2388
2480
  contentMode?: 'standard' | 'structured';
2389
2481
  /**
2390
2482
  * Parent category in the hierarchy. Present when the API eagerly loads
2391
- * the parent relation (e.g. `GET /public/contents/slug/:slug` returns
2483
+ * the parent relation (e.g. `GET /storefront/contents/slug/:slug` returns
2392
2484
  * each category's parent so consumers can build a breadcrumb in a single
2393
2485
  * request). `null` for root-level categories. `undefined` when the
2394
2486
  * endpoint did not include parent data.
@@ -2401,7 +2493,7 @@ interface Category {
2401
2493
  }
2402
2494
  /**
2403
2495
  * Category with URL path, description, image, and content count.
2404
- * Returned by list endpoints (`GET /public/categories`).
2496
+ * Returned by list endpoints (`GET /storefront/categories`).
2405
2497
  *
2406
2498
  * Extends {@link Category} with display-oriented fields useful for rendering
2407
2499
  * category listing pages, navigation menus, and sidebar widgets.
@@ -2478,7 +2570,7 @@ interface CategoryWithCount extends Category {
2478
2570
  }
2479
2571
  /**
2480
2572
  * Full category detail with parent relationship.
2481
- * Returned by single-category endpoints (`GET /public/categories/:id`).
2573
+ * Returned by single-category endpoints (`GET /storefront/categories/:id`).
2482
2574
  *
2483
2575
  * Extends {@link CategoryWithCount} with the parent category reference,
2484
2576
  * enabling you to reconstruct the category hierarchy.
@@ -2505,7 +2597,7 @@ interface CategoryDetail extends CategoryWithCount {
2505
2597
  jsonLdExclusions?: string[];
2506
2598
  }
2507
2599
  /**
2508
- * Recursive category tree node, returned by the tree endpoint (`GET /public/categories/tree`).
2600
+ * Recursive category tree node, returned by the tree endpoint (`GET /storefront/categories/tree`).
2509
2601
  *
2510
2602
  * Each node contains its full {@link CategoryWithCount} data plus a `children` array
2511
2603
  * of nested sub-categories. The tree is pre-sorted by the API.
@@ -2838,15 +2930,15 @@ interface TipTapNode {
2838
2930
  type ContentBody = string;
2839
2931
  /**
2840
2932
  * Lightweight content representation returned in paginated list endpoints
2841
- * (`GET /public/contents`).
2933
+ * (`GET /storefront/contents`).
2842
2934
  *
2843
2935
  * Omits the full body, SEO fields, and relations to minimize payload size.
2844
- * Use `Content` (from `GET /public/contents/:idOrSlug`) for the complete data.
2936
+ * Use `Content` (from `GET /storefront/contents/:idOrSlug`) for the complete data.
2845
2937
  */
2846
2938
  interface ContentSummary {
2847
2939
  /**
2848
2940
  * Unique numeric content ID. Auto-incremented.
2849
- * Use this for API calls like `GET /public/contents/:id`.
2941
+ * Use this for API calls like `GET /storefront/contents/:id`.
2850
2942
  */
2851
2943
  id: number;
2852
2944
  /**
@@ -2857,7 +2949,7 @@ interface ContentSummary {
2857
2949
  /**
2858
2950
  * URL-friendly slug, unique within the site for this locale.
2859
2951
  * Lowercase, hyphenated (e.g. `'my-article-title'`). Max 500 characters.
2860
- * Can be used instead of `id` in API calls: `GET /public/contents/:slug`.
2952
+ * Can be used instead of `id` in API calls: `GET /storefront/contents/:slug`.
2861
2953
  */
2862
2954
  slug: string;
2863
2955
  /**
@@ -2917,7 +3009,7 @@ interface ContentSummary {
2917
3009
  }
2918
3010
  /**
2919
3011
  * Full content item with body, SEO metadata, structured data, and relations.
2920
- * Returned by single-content endpoints (`GET /public/contents/:idOrSlug`).
3012
+ * Returned by single-content endpoints (`GET /storefront/contents/:idOrSlug`).
2921
3013
  *
2922
3014
  * Extends {@link ContentSummary} with all the fields omitted from list responses.
2923
3015
  */
@@ -3187,19 +3279,19 @@ interface Alternate {
3187
3279
  * Lightweight page representation returned in list endpoints.
3188
3280
  * Contains basic identification and routing information.
3189
3281
  *
3190
- * Use {@link Page} (from `GET /public/pages/:idOrSlug`) for the full page
3282
+ * Use {@link Page} (from `GET /storefront/pages/:idOrSlug`) for the full page
3191
3283
  * including resolved data, SEO settings, and alternates.
3192
3284
  */
3193
3285
  interface PageSummary {
3194
3286
  /**
3195
3287
  * Unique numeric page ID. Auto-incremented.
3196
- * Use this for API calls like `GET /public/pages/:id`.
3288
+ * Use this for API calls like `GET /storefront/pages/:id`.
3197
3289
  */
3198
3290
  id: number;
3199
3291
  /**
3200
3292
  * URL-friendly slug, unique within the site for this locale.
3201
3293
  * Lowercase, hyphenated (e.g. `'about-us'`). Max 255 characters.
3202
- * Can be used instead of `id` in API calls: `GET /public/pages/:slug`.
3294
+ * Can be used instead of `id` in API calls: `GET /storefront/pages/:slug`.
3203
3295
  */
3204
3296
  slug: string;
3205
3297
  /**
@@ -3228,7 +3320,7 @@ interface PageSummary {
3228
3320
  }
3229
3321
  /**
3230
3322
  * Full page with resolved data sources, SEO settings, and locale alternates.
3231
- * Returned by single-page endpoints (`GET /public/pages/:idOrSlug`).
3323
+ * Returned by single-page endpoints (`GET /storefront/pages/:idOrSlug`).
3232
3324
  *
3233
3325
  * Pages are layout-driven containers whose content comes from **DataSources** —
3234
3326
  * configurable queries that fetch content, categories, forms, or other data.
@@ -3287,7 +3379,7 @@ interface Page extends PageSummary {
3287
3379
  *
3288
3380
  * `undefined` on responses from older API versions that do not populate
3289
3381
  * the cascade; in that case, fall back to the dedicated
3290
- * `/public/:siteId/pages/:slug/json-ld` endpoint which always returns
3382
+ * `/storefront/:siteId/pages/:slug/json-ld` endpoint which always returns
3291
3383
  * the array directly under `data`.
3292
3384
  */
3293
3385
  structuredData?: {
@@ -3704,7 +3796,7 @@ interface FormSchema {
3704
3796
  }
3705
3797
  /**
3706
3798
  * A public form available for submission.
3707
- * Returned by `GET /public/{siteId}/forms/{slug}` and unwrapped from the
3799
+ * Returned by `GET /storefront/{siteId}/forms/{slug}` and unwrapped from the
3708
3800
  * `{ data }` envelope by `forms.getBySlug()`.
3709
3801
  *
3710
3802
  * Use `schema.fields` to dynamically render the form fields, `schema.settings`
@@ -3726,8 +3818,8 @@ interface Form {
3726
3818
  /**
3727
3819
  * URL-friendly slug, unique within the site.
3728
3820
  * Lowercase, hyphenated (e.g. `'contact-us'`). Max 255 characters.
3729
- * Used to fetch the form: `GET /public/{siteId}/forms/{slug}`.
3730
- * Also used as the submission endpoint: `POST /public/{siteId}/forms/{slug}/submissions`.
3821
+ * Used to fetch the form: `GET /storefront/{siteId}/forms/{slug}`.
3822
+ * Also used as the submission endpoint: `POST /storefront/{siteId}/forms/{slug}/submissions`.
3731
3823
  */
3732
3824
  slug: string;
3733
3825
  /**
@@ -3847,7 +3939,7 @@ interface ReviewResponse {
3847
3939
  interface Review {
3848
3940
  /**
3849
3941
  * Unique numeric review ID. Auto-incremented.
3850
- * Use this for API calls like `GET /public/reviews/:id`.
3942
+ * Use this for API calls like `GET /storefront/reviews/:id`.
3851
3943
  */
3852
3944
  id: number;
3853
3945
  /**
@@ -3914,7 +4006,7 @@ interface Review {
3914
4006
  }
3915
4007
  /**
3916
4008
  * Public review settings for a site.
3917
- * Returned by `GET /public/reviews/settings`.
4009
+ * Returned by `GET /storefront/reviews/settings`.
3918
4010
  *
3919
4011
  * Use these settings to:
3920
4012
  * - Check if reviews are enabled before rendering a review form
@@ -3983,7 +4075,7 @@ interface ReviewSettings {
3983
4075
  };
3984
4076
  }
3985
4077
  /**
3986
- * Data payload for submitting a new review via `POST /public/reviews`.
4078
+ * Data payload for submitting a new review via `POST /storefront/reviews`.
3987
4079
  *
3988
4080
  * Required fields: `authorName`, `rating`, `content`.
3989
4081
  * Optional fields depend on `ReviewSettings.fields` configuration.
@@ -4796,7 +4888,7 @@ interface CategoryDetailResponse {
4796
4888
  * Response from `tags.list()`.
4797
4889
  * Paginated since SDK 1.32.2 (the wire was already returning `meta`; the SDK
4798
4890
  * type now exposes it). Server-side default is 20 items per page on
4799
- * `/v1/tags` and `/public/.../tags`, with `maxLimit=100` (ADR-0022 D3).
4891
+ * `/v1/tags` and `/storefront/.../tags`, with `maxLimit=100` (ADR-0022 D3).
4800
4892
  */
4801
4893
  interface TagsListResponse {
4802
4894
  /**
@@ -5087,9 +5179,9 @@ interface BaseRequestOptions {
5087
5179
  * Pagination options for list endpoints.
5088
5180
  *
5089
5181
  * All values are 1-based integers. The server default is 20 items per page
5090
- * on public-tier endpoints (`/public`, `/v1`) and 50 on admin-tier
5182
+ * on public-tier endpoints (`/storefront`, `/v1`) and 50 on admin-tier
5091
5183
  * endpoints (`/api`, `/admin`), per ADR-0022 D3. Documented exceptions:
5092
- * SSG endpoints like `/public/.../categories/:slug` default to 500.
5184
+ * SSG endpoints like `/storefront/.../categories/:slug` default to 500.
5093
5185
  */
5094
5186
  interface PaginationOptions {
5095
5187
  /**
@@ -5100,9 +5192,9 @@ interface PaginationOptions {
5100
5192
  page?: number;
5101
5193
  /**
5102
5194
  * Maximum number of items per page.
5103
- * Server default is 20 on public-tier endpoints (`/public`, `/v1`).
5195
+ * Server default is 20 on public-tier endpoints (`/storefront`, `/v1`).
5104
5196
  * Maximum allowed value is 100 (except documented SSG exceptions like
5105
- * `/public/.../categories/:slug` which permit up to 500).
5197
+ * `/storefront/.../categories/:slug` which permit up to 500).
5106
5198
  * Values above the per-endpoint maximum are silently capped by the API.
5107
5199
  */
5108
5200
  limit?: number;
@@ -5195,7 +5287,7 @@ interface CategoryOptions extends PaginationOptions {
5195
5287
  *
5196
5288
  * Pagination + locale. The public `/v1/tags` endpoint does not expose
5197
5289
  * search or sort on its public surface. `limit` defaults to 20 server-side
5198
- * on the public-tier mounts (`/public/.../tags`, `/v1/tags`) per
5290
+ * on the public-tier mounts (`/storefront/.../tags`, `/v1/tags`) per
5199
5291
  * ADR-0022 D3, with `maxLimit=100`.
5200
5292
  */
5201
5293
  interface TagsListFilters extends PaginationOptions {
@@ -6902,4 +6994,4 @@ declare function renderJsonLdGraph(nodes: object[] | null | undefined): string;
6902
6994
  */
6903
6995
  declare function mergeIntoGraph(server: object[] | null | undefined, custom: object[] | null | undefined): object[];
6904
6996
 
6905
- export { type Alternate, AnalyticsService, type ApiErrorDetail, type Author, type BaseRequestOptions, BlocksService, BrandingService, type CategoriesListResponse, CategoriesService, type Category, type CategoryDetail, type CategoryDetailResponse, type CategoryOptions, type CategoryResolveResponse, type CategoryTreeNode, type CategoryTreeResponse, type CategoryWithCount, type Client, type ClientConfig, type ConsentCategories, type ConsentLogResponse, ConsentService, type Content, type ContentBody, type ContentResolveResponse, type ContentSchema, type ContentSummary, type ContentsFilters, type ContentsListResponse, ContentsService, type CookieCategory, type CookieConfig, type CookiePreferences, type CookieTexts, CookiesService, type EnhancementsInitOptions, EnhancementsService, type ErrorCode, type EventData, type EventName, type Form, type FormCondition, type FormField, type FormFieldOption, type FormFieldPhoneOptions, type FormFieldType, type FormFieldValidation, type FormPage, type FormSchema, type FormSchemaSettings, type FormSettings, type FormSubmitData, type FormSubmitResponse, FormsService, type GlobalBlock, type GlobalBlockResponse, type ImageVariants, type JsonLdGraphConfig, type JsonLdNode, type JsonLdNodeSource, type LegalDocument, LegalService, type LynkowClient, type LynkowConfig, LynkowError, type LynkowEvents, MediaHelperService, type Page, type PageSeo, type PageSummary, type PagesListResponse, PagesService, type PageviewData, type PaginatedResponse, type PaginationMeta, type PaginationOptions, type Path, type PathsListResponse, PathsService, type Redirect, type ResolveResponse, type Review, type ReviewResponse, type ReviewSettings, type ReviewSubmitData, type ReviewSubmitResponse, type ReviewsFilters, type ReviewsListResponse, ReviewsService, type SchemaField, type SchemaFieldOption, type SchemaFieldType, type SchemaFieldValidation, type SearchConfig, type SearchHit, type SearchOptions, type SearchProfilePublic, type SearchResponse, SearchService, SeoService, type SiteConfig, type SiteConfigResponse, SiteService, type SortOptions, type SrcsetOptions, type SubmitOptions, type Tag, type TagsListFilters, type TagsListResponse, TagsService, type TipTapMark, type TipTapNode, type TransformOptions, browserOnly, browserOnlyAsync, createClient, createLynkowClient, detectSiteTheme, isBrowser, isCategoryResolve, isContentResolve, isLynkowError, isServer, mergeIntoGraph, onSiteThemeChange, renderJsonLdGraph };
6997
+ export { type Alternate, AnalyticsService, type ApiErrorDetail, type Author, type BaseRequestOptions, BlocksService, BrandingService, type CategoriesListResponse, CategoriesService, type Category, type CategoryDetail, type CategoryDetailResponse, type CategoryOptions, type CategoryResolveResponse, type CategoryTreeNode, type CategoryTreeResponse, type CategoryWithCount, type Client, type ClientConfig, type ConsentCategories, type ConsentLogResponse, ConsentService, type Content, type ContentBody, type ContentResolveResponse, type ContentSchema, type ContentSummary, type ContentsFilters, type ContentsListResponse, ContentsService, type CookieCategory, type CookieConfig, type CookiePreferences, type CookieTexts, CookiesService, type EnhancementsInitOptions, EnhancementsService, type ErrorCode, type EventData, type EventName, type Form, type FormCondition, type FormField, type FormFieldOption, type FormFieldPhoneOptions, type FormFieldType, type FormFieldValidation, type FormPage, type FormSchema, type FormSchemaSettings, type FormSettings, type FormSubmitData, type FormSubmitResponse, FormsService, type GlobalBlock, type GlobalBlockResponse, type ImageVariants, type JsonLdGraphConfig, type JsonLdNode, type JsonLdNodeSource, type LegalDocument, LegalService, type LynkowClient, type LynkowConfig, LynkowError, type LynkowEvents, MediaHelperService, type Page, type PageSeo, type PageSummary, type PagesListResponse, PagesService, type PageviewData, type PaginatedResponse, type PaginationMeta, type PaginationOptions, type Path, type PathsListResponse, PathsService, type Redirect, type ResolveResponse, type RetryConfig, type Review, type ReviewResponse, type ReviewSettings, type ReviewSubmitData, type ReviewSubmitResponse, type ReviewsFilters, type ReviewsListResponse, ReviewsService, type SchemaField, type SchemaFieldOption, type SchemaFieldType, type SchemaFieldValidation, type SearchConfig, type SearchHit, type SearchOptions, type SearchProfilePublic, type SearchResponse, SearchService, SeoService, type SiteConfig, type SiteConfigResponse, SiteService, type SortOptions, type SrcsetOptions, type SubmitOptions, type Tag, type TagsListFilters, type TagsListResponse, TagsService, type TipTapMark, type TipTapNode, type TransformOptions, browserOnly, browserOnlyAsync, createClient, createLynkowClient, detectSiteTheme, isBrowser, isCategoryResolve, isContentResolve, isLynkowError, isServer, mergeIntoGraph, onSiteThemeChange, renderJsonLdGraph };