@unchainedshop/cockpit-api 2.1.1 → 2.1.2

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.
@@ -12,20 +12,23 @@ export function createConfig(options = {}) {
12
12
  if (endpointStr === undefined || endpointStr === "") {
13
13
  throw new Error("Cockpit: endpoint is required (provide via options or COCKPIT_GRAPHQL_ENDPOINT env var)");
14
14
  }
15
+ // Normalize empty string tenant to undefined
16
+ const tenant = options.tenant === undefined || options.tenant === ""
17
+ ? undefined
18
+ : options.tenant;
15
19
  // Validate tenant format to prevent path traversal
16
- if (options.tenant !== undefined &&
17
- !VALID_TENANT_PATTERN.test(options.tenant)) {
20
+ if (tenant !== undefined && !VALID_TENANT_PATTERN.test(tenant)) {
18
21
  throw new Error("Cockpit: Invalid tenant format (only alphanumeric, hyphens, and underscores allowed)");
19
22
  }
20
23
  const endpoint = new URL(endpointStr);
21
- const apiKey = resolveApiKey(options.tenant, options);
24
+ const apiKey = resolveApiKey(tenant, options);
22
25
  // Build config object with all properties before freezing
23
26
  const config = Object.freeze({
24
27
  endpoint,
25
28
  useAdminAccess: options.useAdminAccess ?? false,
26
29
  defaultLanguage: options.defaultLanguage ?? null,
27
- cachePrefix: `${endpointStr}:${options.tenant ?? "default"}:`,
28
- ...(options.tenant !== undefined && { tenant: options.tenant }),
30
+ cachePrefix: `${endpointStr}:${tenant ?? "default"}:`,
31
+ ...(tenant !== undefined && { tenant }),
29
32
  ...(apiKey !== undefined && { apiKey }),
30
33
  });
31
34
  return config;
@@ -25,8 +25,8 @@ export interface MakeCockpitSchemaOptions {
25
25
  transforms?: unknown[];
26
26
  /** Custom tenant extractor function */
27
27
  extractTenant?: (context: CockpitExecutorContext | undefined) => string | undefined;
28
- /** CockpitAPI options to pass through (endpoint, apiKey, useAdminAccess) */
29
- cockpitOptions?: Pick<CockpitAPIOptions, "endpoint" | "apiKey" | "useAdminAccess">;
28
+ /** CockpitAPI options to pass through (endpoint, apiKey, useAdminAccess, preloadRoutes) */
29
+ cockpitOptions?: Pick<CockpitAPIOptions, "endpoint" | "apiKey" | "useAdminAccess" | "preloadRoutes">;
30
30
  /** Maximum number of clients to keep in the pool (default: 100) */
31
31
  maxClients?: number;
32
32
  }
@@ -54,7 +54,11 @@ export function createRemoteExecutor(options = {}) {
54
54
  if (pending)
55
55
  return pending;
56
56
  // Create new client and cache it
57
- const clientOpts = { ...cockpitOptions };
57
+ // Default preloadRoutes to true for page link resolution in GraphQL responses
58
+ const clientOpts = {
59
+ preloadRoutes: true,
60
+ ...cockpitOptions,
61
+ };
58
62
  if (tenant !== undefined)
59
63
  clientOpts.tenant = tenant;
60
64
  const clientPromise = CockpitAPI(clientOpts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/cockpit-api",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "A package to interact with the Cockpit CMS API, including functionalities to handle GraphQL requests and various CMS content manipulations.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://unchained.shop",