@styleflow.app/flowpress-astro-core 1.0.0-beta.34 → 1.0.0-beta.35

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0-beta.35 — 2026-10-26
4
+
5
+ - Add a fresh CMS content revision API and an optional request store; HTTP remains the default.
6
+ - Export a separate Node build store for private, revision-bound data shared across processes. Authenticated queries, mutations and failed responses bypass storage.
7
+ - [Canonical report](https://github.com/StyleFlow-App/styleflow-docs/blob/main/dev/rapporti/2026-10-26-prestazioni-oauth-dmo.md).
8
+
3
9
  ## 1.0.0-beta.34 — 2026-10-20
4
10
 
5
11
  - Make page loading composition-only and retire content-loader and conventional Astro template APIs.
@@ -0,0 +1,8 @@
1
+ import type { FlowpressRequestStore } from "./client.js";
2
+ export interface FlowpressBuildStoreOptions {
3
+ directory: string;
4
+ endpoint: string;
5
+ revision: string;
6
+ }
7
+ export declare function createBuildRequestStore(options: FlowpressBuildStoreOptions): Promise<FlowpressRequestStore>;
8
+ //# sourceMappingURL=build-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-cache.d.ts","sourceRoot":"","sources":["../src/build-cache.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIzD,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAsDjH"}
@@ -0,0 +1,81 @@
1
+ /** Node-only, private store shared by the safelist and Astro build processes. */
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { lstat, readFile, rename, writeFile, unlink, mkdir, rmdir } from "node:fs/promises";
4
+ import { setTimeout as delay } from "node:timers/promises";
5
+ import { isAbsolute, join } from "node:path";
6
+ const inFlight = new Map();
7
+ export async function createBuildRequestStore(options) {
8
+ const { directory, endpoint, revision } = options;
9
+ if (!isAbsolute(directory) || !/^[a-f0-9]{32}$/.test(revision)) {
10
+ throw new Error("A build request store requires a private absolute directory and content revision.");
11
+ }
12
+ const stat = await lstat(directory);
13
+ if (!stat.isDirectory() || stat.isSymbolicLink() || (stat.mode & 0o077)) {
14
+ throw new Error("The build request directory must be private and cannot be a symlink.");
15
+ }
16
+ const metadata = JSON.parse(await readFile(join(directory, "session.json"), "utf8"));
17
+ if (metadata.schemaVersion !== 1 || metadata.endpoint !== endpoint || metadata.revision !== revision) {
18
+ throw new Error("The build request store belongs to another backend or revision.");
19
+ }
20
+ return {
21
+ async getOrCreate(key, load) {
22
+ const identity = JSON.parse(key);
23
+ if (identity.endpoint !== endpoint)
24
+ throw new Error("Cross-backend build cache access refused.");
25
+ const digest = createHash("sha256").update(key).digest("hex");
26
+ const file = join(directory, digest + ".json");
27
+ const pending = inFlight.get(file);
28
+ if (pending)
29
+ return pending;
30
+ const result = (async () => {
31
+ const lock = file + ".lock";
32
+ const deadline = Date.now() + 120000;
33
+ while (true) {
34
+ try {
35
+ await mkdir(lock, { mode: 0o700 });
36
+ break;
37
+ }
38
+ catch (error) {
39
+ if (error.code !== "EEXIST")
40
+ throw error;
41
+ if (Date.now() > deadline)
42
+ throw new Error("Timed out waiting for another build process. Discard this attempt.");
43
+ await delay(20);
44
+ }
45
+ }
46
+ try {
47
+ try {
48
+ const cached = JSON.parse(await readFile(file, "utf8"));
49
+ if (cached.key === key && Object.hasOwn(cached, "value"))
50
+ return cached.value;
51
+ }
52
+ catch (error) {
53
+ if (!(error instanceof SyntaxError) && error.code !== "ENOENT")
54
+ throw error;
55
+ }
56
+ const value = await load();
57
+ const temporary = file + "." + randomUUID() + ".tmp";
58
+ try {
59
+ await writeFile(temporary, JSON.stringify({ key, value }), { mode: 0o600, flag: "wx" });
60
+ await rename(temporary, file);
61
+ }
62
+ finally {
63
+ await unlink(temporary).catch(() => { });
64
+ }
65
+ return value;
66
+ }
67
+ finally {
68
+ await rmdir(lock);
69
+ }
70
+ })();
71
+ inFlight.set(file, result);
72
+ try {
73
+ return await result;
74
+ }
75
+ finally {
76
+ inFlight.delete(file);
77
+ }
78
+ }
79
+ };
80
+ }
81
+ //# sourceMappingURL=build-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-cache.js","sourceRoot":"","sources":["../src/build-cache.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;AAQrD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAAmC;IAC/E,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAClD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;IACvG,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM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BACD,OAAO,KAAK,CAAC;gBACb,CAAC;wBAAS,CAAC;oBAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;gBAAC,CAAC;YAClC,CAAC,CAAC,EAAE,CAAC;YACL,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC3B,IAAI,CAAC;gBAAC,OAAO,MAAM,MAAM,CAAC;YAAC,CAAC;oBAAS,CAAC;gBAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAAC,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** Node-only, private store shared by the safelist and Astro build processes. */\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { lstat, readFile, rename, writeFile, unlink, mkdir, rmdir } from \"node:fs/promises\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { isAbsolute, join } from \"node:path\";\nimport type { FlowpressRequestStore } from \"./client.js\";\n\nconst inFlight = new Map<string, Promise<unknown>>();\n\nexport interface FlowpressBuildStoreOptions {\n directory: string;\n endpoint: string;\n revision: string;\n}\n\nexport async function createBuildRequestStore(options: FlowpressBuildStoreOptions): Promise<FlowpressRequestStore> {\n const { directory, endpoint, revision } = options;\n if (!isAbsolute(directory) || !/^[a-f0-9]{32}$/.test(revision)) {\n throw new Error(\"A build request store requires a private absolute directory and content revision.\");\n }\n const stat = await lstat(directory);\n if (!stat.isDirectory() || stat.isSymbolicLink() || (stat.mode & 0o077)) {\n throw new Error(\"The build request directory must be private and cannot be a symlink.\");\n }\n const metadata = JSON.parse(await readFile(join(directory, \"session.json\"), \"utf8\"));\n if (metadata.schemaVersion !== 1 || metadata.endpoint !== endpoint || metadata.revision !== revision) {\n throw new Error(\"The build request store belongs to another backend or revision.\");\n }\n return {\n async getOrCreate<T>(key: string, load: () => Promise<T>): Promise<T> {\n const identity = JSON.parse(key) as { endpoint?: string };\n if (identity.endpoint !== endpoint) throw new Error(\"Cross-backend build cache access refused.\");\n const digest = createHash(\"sha256\").update(key).digest(\"hex\");\n const file = join(directory, digest + \".json\");\n const pending = inFlight.get(file);\n if (pending) return pending as Promise<T>;\n const result = (async (): Promise<T> => {\n const lock = file + \".lock\";\n const deadline = Date.now() + 120000;\n while (true) {\n try { await mkdir(lock, { mode: 0o700 }); break; }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n if (Date.now() > deadline) throw new Error(\"Timed out waiting for another build process. Discard this attempt.\");\n await delay(20);\n }\n }\n try {\n try {\n const cached = JSON.parse(await readFile(file, \"utf8\"));\n if (cached.key === key && Object.hasOwn(cached, \"value\")) return cached.value as T;\n } catch (error) {\n if (!(error instanceof SyntaxError) && (error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n const value = await load();\n const temporary = file + \".\" + randomUUID() + \".tmp\";\n try {\n await writeFile(temporary, JSON.stringify({ key, value }), { mode: 0o600, flag: \"wx\" });\n await rename(temporary, file);\n } finally {\n await unlink(temporary).catch(() => {});\n }\n return value;\n } finally { await rmdir(lock); }\n })();\n inFlight.set(file, result);\n try { return await result; } finally { inFlight.delete(file); }\n }\n };\n}\n"]}
package/dist/client.d.ts CHANGED
@@ -7,11 +7,16 @@ export interface FlowpressGraphqlIssue {
7
7
  [key: string]: unknown;
8
8
  };
9
9
  }
10
+ /** Store only successful anonymous query data; implementations may deduplicate in flight. */
11
+ export interface FlowpressRequestStore {
12
+ getOrCreate<T>(key: string, load: () => Promise<T>): Promise<T>;
13
+ }
10
14
  export interface FlowpressClientOptions {
11
15
  endpoint: string;
12
16
  timeoutMs?: number;
13
17
  headers?: Record<string, string>;
14
18
  debug?: boolean;
19
+ requestStore?: FlowpressRequestStore;
15
20
  }
16
21
  export declare class FlowpressGraphqlError extends Error {
17
22
  readonly status?: number | undefined;
@@ -25,8 +30,11 @@ export declare class FlowpressClient {
25
30
  readonly timeoutMs: number;
26
31
  readonly headers: Record<string, string>;
27
32
  readonly debug: boolean;
33
+ readonly requestStore: FlowpressRequestStore | undefined;
28
34
  constructor(options: FlowpressClientOptions);
29
35
  request<T>(query: string, variables?: Record<string, unknown>): Promise<T>;
36
+ getContentRevision(): Promise<string>;
37
+ private requestUncached;
30
38
  getCapabilities(): Promise<FlowpressCapabilities>;
31
39
  getRoute(uri: string, locale?: string): Promise<FlowpressRoute | null>;
32
40
  getRoutes(locale?: string): Promise<FlowpressRoute[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE;QACX,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAOD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAG5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,EAAE;IACzC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM;gBAJ1B,OAAO,EAAE,MAAM,EACN,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,MAAM,CAAC,EAAE,qBAAqB,EAAE,YAAA,EAChC,aAAa,CAAC,EAAE,MAAM,YAAA,EACtB,QAAQ,CAAC,EAAE,MA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ug;
20
+ requestStore;
20
21
  constructor(options) {
21
22
  const endpoint = options.endpoint.trim();
22
23
  if (!endpoint) {
@@ -27,8 +28,30 @@ export class FlowpressClient {
27
28
  this.timeoutMs = options.timeoutMs ?? 15_000;
28
29
  this.headers = { ...options.headers };
29
30
  this.debug = options.debug ?? false;
31
+ this.requestStore = options.requestStore;
30
32
  }
31
33
  async request(query, variables = {}) {
34
+ const url = new URL(this.endpoint);
35
+ const anonymousQuery = Object.keys(this.headers).length === 0
36
+ && !url.username && !url.password
37
+ && /^(?:query\b|\{)/.test(query.trim())
38
+ && !/\b(?:mutation|subscription|sfContentRevision)\b/.test(query);
39
+ if (this.requestStore && anonymousQuery) {
40
+ return this.requestStore.getOrCreate(JSON.stringify({
41
+ endpoint: this.endpoint, query, variables: canonicalVariables(variables)
42
+ }), () => this.requestUncached(query, variables));
43
+ }
44
+ return this.requestUncached(query, variables);
45
+ }
46
+ async getContentRevision() {
47
+ // This read must never come from the build store it is validating.
48
+ const data = await this.requestUncached("query FlowpressContentRevision { sfContentRevision }", {});
49
+ if (!/^[a-f0-9]{32}$/.test(data.sfContentRevision || "")) {
50
+ throw new Error("WordPress returned no valid FlowPress content revision.");
51
+ }
52
+ return data.sfContentRevision;
53
+ }
54
+ async requestUncached(query, variables) {
32
55
  const controller = new AbortController();
33
56
  const timer = setTimeout(() => controller.abort(), this.timeoutMs);
34
57
  const operationName = getOperationName(query);
@@ -262,4 +285,13 @@ function parseRequiredJson(value, field) {
262
285
  throw new FlowpressGraphqlError(`FlowPress composition field ${field} is not valid JSON.`, undefined, undefined, "FlowpressComposition", undefined, error);
263
286
  }
264
287
  }
288
+ function canonicalVariables(value) {
289
+ const normalized = JSON.parse(JSON.stringify(value));
290
+ const sort = (item) => Array.isArray(item)
291
+ ? item.map(sort)
292
+ : item && typeof item === "object"
293
+ ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)).map(([key, child]) => [key, sort(child)]))
294
+ : item;
295
+ return sort(normalized);
296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["import type {\n FlowpressCapabilities,\n FlowpressCompositionV1,\n FlowpressContent,\n FlowpressRoute,\n SfSeo\n} from \"./types.js\";\n\nexport interface FlowpressGraphqlIssue {\n message?: string;\n extensions?: {\n debugMessage?: string;\n category?: string;\n [key: string]: unknown;\n };\n}\n\ninterface GraphqlResponse<T> {\n data?: T;\n errors?: FlowpressGraphqlIssue[];\n}\n\nexport interface FlowpressClientOptions {\n endpoint: string;\n timeoutMs?: number;\n headers?: Record<string, string>;\n debug?: boolean;\n}\n\nexport class FlowpressGraphqlError extends Error {\n constructor(\n message: string,\n readonly status?: number,\n readonly errors?: FlowpressGraphqlIssue[],\n readonly operationName?: string,\n readonly endpoint?: string,\n cause?: unknown\n ) {\n super(message, cause === undefined ? undefined : { cause });\n this.name = \"FlowpressGraphqlError\";\n }\n}\n\nexport class FlowpressClient {\n readonly endpoint: string;\n readonly timeoutMs: number;\n readonly headers: Record<string, string>;\n readonly debug: boolean;\n\n constructor(options: FlowpressClientOptions) {\n const endpoint = options.endpoint.trim();\n if (!endpoint) {\n throw new Error(\"FlowPress GraphQL endpoint is required.\");\n }\n\n new URL(endpoint);\n this.endpoint = endpoint;\n this.timeoutMs = options.timeoutMs ?? 15_000;\n this.headers = { ...options.headers };\n this.debug = options.debug ?? false;\n }\n\n async request<T>(\n query: string,\n variables: Record<string, unknown> = {}\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n const operationName = getOperationName(query);\n const safeEndpoint = sanitizeEndpoint(this.endpoint);\n\n try {\n let response: Response;\n try {\n response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...this.headers\n },\n body: JSON.stringify({ query, variables }),\n signal: controller.signal\n });\n } catch (error) {\n const timedOut = controller.signal.aborted;\n const detail = error instanceof Error && error.message\n ? ` ${error.message}`\n : \"\";\n throw new FlowpressGraphqlError(\n timedOut\n ? `FlowPress GraphQL ${operationName} timed out after ${this.timeoutMs}ms at ${safeEndpoint}.`\n : `FlowPress GraphQL ${operationName} could not reach ${safeEndpoint}.${detail}`,\n undefined,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n const body = await response.text();\n let payload: GraphqlResponse<T>;\n try {\n payload = JSON.parse(body) as GraphqlResponse<T>;\n } catch (error) {\n const contentType = response.headers.get(\"content-type\") || \"unknown content type\";\n throw new FlowpressGraphqlError(\n `FlowPress GraphQL ${operationName} returned ${response.status} `\n + `with ${contentType}, not JSON, from ${safeEndpoint}.`,\n response.status,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n if (!response.ok || payload.errors?.length || payload.data === undefined) {\n const errors: FlowpressGraphqlIssue[] | undefined = payload.errors?.map(\n (error) => {\n if (this.debug) {\n return error;\n }\n return error.message ? { message: error.message } : {};\n }\n );\n const messages = errors\n ?.flatMap((error) => [\n error.message,\n this.debug ? error.extensions?.debugMessage : undefined\n ])\n .filter((message): message is string => Boolean(message));\n throw new FlowpressGraphqlError(\n messages?.join(\"; \")\n || `FlowPress GraphQL ${operationName} failed with ${response.status} at ${safeEndpoint}.`,\n response.status,\n errors,\n operationName,\n safeEndpoint\n );\n }\n\n return payload.data;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async getCapabilities(): Promise<FlowpressCapabilities> {\n const data = await this.request<{ styleflowCapabilities: FlowpressCapabilities }>(\n `query FlowpressCapabilities {\n styleflowCapabilities {\n schemaVersion\n wpGraphql\n acfPro\n wpGraphqlAcf\n rankMath\n wpml\n woocommerce\n contactForm7\n defaultLocale\n locales { code slug homeUrl }\n features { id version enabled capabilities configJson }\n }\n }`\n );\n return {\n ...data.styleflowCapabilities,\n features: (data.styleflowCapabilities.features ?? []).map((feature) => {\n const wire = feature as typeof feature & { configJson?: string | null };\n let config: Record<string, unknown> = {};\n if (wire.configJson) {\n try {\n const parsed = JSON.parse(wire.configJson);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n config = parsed as Record<string, unknown>;\n }\n } catch {\n config = {};\n }\n }\n return {\n id: feature.id,\n version: feature.version ?? null,\n enabled: feature.enabled,\n capabilities: feature.capabilities ?? [],\n config\n };\n })\n };\n }\n\n async getRoute(uri: string, locale?: string): Promise<FlowpressRoute | null> {\n const data = await this.request<{\n sfRouteByUri: (Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }) | null;\n }>(\n `query FlowpressRoute($uri: String!, $locale: String) {\n sfRouteByUri(uri: $uri, locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { uri, locale: locale ?? null }\n );\n if (!data.sfRouteByUri) {\n return null;\n }\n return {\n ...data.sfRouteByUri,\n seo: normalizeGraphqlSeo(data.sfRouteByUri.seo)\n };\n }\n\n async getRoutes(locale?: string): Promise<FlowpressRoute[]> {\n const data = await this.request<{\n sfRoutes: Array<Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }>;\n }>(\n `query FlowpressRoutes($locale: String) {\n sfRoutes(locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { locale: locale ?? null }\n );\n return data.sfRoutes.map((route) => ({\n ...route,\n seo: normalizeGraphqlSeo(route.seo)\n }));\n }\n\n async getComposition(uri: string, locale?: string, options: { includeContent?: boolean } = {}): Promise<FlowpressCompositionV1 | null> {\n const data = await this.request<{\n sfCompositionByUri: null | {\n version: \"1\";\n sourceDigest: string;\n locale?: string | null;\n templateJson: string;\n blocksJson: string;\n stylesheetsJson: string;\n blockTypesJson: string;\n diagnosticsJson: string;\n routeJson: string;\n contentJson?: string | null;\n };\n }>(\n `query FlowpressComposition($uri: String!, $locale: String${options.includeContent === false ? \", $includeContent: Boolean\" : \"\"}) {\n sfCompositionByUri(uri: $uri, locale: $locale${options.includeContent === false ? \", includeContent: $includeContent\" : \"\"}) {\n version sourceDigest locale templateJson blocksJson stylesheetsJson blockTypesJson\n diagnosticsJson routeJson contentJson\n }\n }`,\n { uri, locale: locale ?? null, ...(options.includeContent === false ? { includeContent: false } : {}) }\n );\n const wire = data.sfCompositionByUri;\n if (!wire) return null;\n const route = parseRequiredJson<Omit<FlowpressRoute, \"seo\"> & { seo?: GraphqlSeo | SfSeo | null }>(wire.routeJson, \"routeJson\");\n return {\n version: wire.version,\n sourceDigest: wire.sourceDigest,\n locale: wire.locale ?? null,\n template: parseRequiredJson(wire.templateJson, \"templateJson\"),\n blocks: parseRequiredJson(wire.blocksJson, \"blocksJson\"),\n stylesheets: parseRequiredJson(wire.stylesheetsJson, \"stylesheetsJson\"),\n blockTypes: parseRequiredJson(wire.blockTypesJson, \"blockTypesJson\"),\n diagnostics: parseRequiredJson(wire.diagnosticsJson, \"diagnosticsJson\"),\n route: { ...route, seo: normalizeGraphqlSeo(route.seo) },\n content: parseJson(wire.contentJson, null)\n };\n }\n\n /** Site Editor already returns route and content in its composition. No\n * route preflight, retries or cross-request cache are needed for previews.\n */\n async getPage(uri: string, options: { locale?: string; includeContent?: boolean } = {}): Promise<{ route: FlowpressRoute; content: FlowpressContent | null; composition: FlowpressCompositionV1 } | null> {\n const composition = await this.getComposition(uri, options.locale, options);\n return composition ? { route: composition.route, content: composition.content ?? null, composition } : null;\n }\n\n}\n\nfunction getOperationName(query: string): string {\n return query.match(\n /\\b(?:query|mutation|subscription)\\s+([_A-Za-z][_0-9A-Za-z]*)/\n )?.[1] || \"AnonymousOperation\";\n}\n\nfunction sanitizeEndpoint(endpoint: string): string {\n const url = new URL(endpoint);\n url.username = \"\";\n url.password = \"\";\n url.search = \"\";\n url.hash = \"\";\n return url.toString();\n}\n\ninterface GraphqlSeo {\n title?: string | null;\n description?: string | null;\n canonicalUrl?: string | null;\n robots?: string[] | null;\n headHtml?: string | null;\n jsonLd?: { raw?: string | null } | null;\n openGraph?: GraphqlSocial | null;\n twitterMeta?: GraphqlSocial | null;\n hreflang?: Array<{ locale: string; url: string }> | null;\n}\n\ninterface GraphqlSocial {\n title?: string | null;\n description?: string | null;\n image?: { url: string; altText?: string | null } | null;\n}\n\nfunction normalizeGraphqlSeo(seo?: GraphqlSeo | SfSeo | null) {\n if (!seo) return null;\n const social = (value?: GraphqlSocial | SfSeo[\"openGraph\"] | null) => {\n if (!value) return null;\n const source = value.image as (NonNullable<NonNullable<SfSeo[\"openGraph\"]>[\"image\"]> & { altText?: string | null }) | null | undefined;\n const { altText, ...image } = source ?? {};\n return {\n title: value.title ?? null,\n description: value.description ?? null,\n image: source ? { ...image, url: source.url, alt: altText ?? source.alt ?? null } : null\n };\n };\n\n return {\n title: seo.title ?? null,\n description: seo.description ?? null,\n canonicalUrl: seo.canonicalUrl ?? null,\n robots: seo.robots ?? null,\n headHtml: seo.headHtml ?? null,\n jsonLd: seo.jsonLd && typeof seo.jsonLd === \"object\" && \"raw\" in seo.jsonLd\n ? parseJson((seo.jsonLd as { raw?: string | null }).raw, null) : seo.jsonLd ?? null,\n hreflang: seo.hreflang ?? null,\n openGraph: social(seo.openGraph),\n twitter: social(\"twitterMeta\" in seo ? seo.twitterMeta : (seo as SfSeo).twitter)\n };\n}\n\nfunction parseJson<T>(value: string | null | undefined, fallback: T): T {\n if (!value) return fallback;\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction parseRequiredJson<T>(value: string, field: string): T {\n try {\n return JSON.parse(value) as T;\n } catch (error) {\n throw new FlowpressGraphqlError(\n `FlowPress composition field ${field} is not valid JSON.`,\n undefined,\n undefined,\n \"FlowpressComposition\",\n undefined,\n error\n );\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAmCA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAGnC;IACA;IACA;IACA;IALX,YACE,OAAe,EACN,MAAe,EACf,MAAgC,EAChC,aAAsB,EACtB,QAAiB,EAC1B,KAAe;QAEf,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QANnD,WAAM,GAAN,MAAM,CAAS;QACf,WAAM,GAAN,MAAM,CAA0B;QAChC,kBAAa,GAAb,aAAa,CAAS;QACtB,aAAQ,GAAR,QAAQ,CAAS;QAI1B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IACjB,QAAQ,CAAS;IACjB,SAAS,CAAS;IAClB,OAAO,CAAyB;IAChC,KAAK,CAAU;IACf,YAAY,CAAoC;IAEzD,YAAY,OAA+B;QACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAA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c;IACxC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAY,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,IAAa,EAAW,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAC1D,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAChB,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;YAChC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC3H,CAAC,CAAC,IAAI,CAAC;IACX,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import type {\n FlowpressCapabilities,\n FlowpressCompositionV1,\n FlowpressContent,\n FlowpressRoute,\n SfSeo\n} from \"./types.js\";\n\nexport interface FlowpressGraphqlIssue {\n message?: string;\n extensions?: {\n debugMessage?: string;\n category?: string;\n [key: string]: unknown;\n };\n}\n\ninterface GraphqlResponse<T> {\n data?: T;\n errors?: FlowpressGraphqlIssue[];\n}\n\n/** Store only successful anonymous query data; implementations may deduplicate in flight. */\nexport interface FlowpressRequestStore {\n getOrCreate<T>(key: string, load: () => Promise<T>): Promise<T>;\n}\n\nexport interface FlowpressClientOptions {\n endpoint: string;\n timeoutMs?: number;\n headers?: Record<string, string>;\n debug?: boolean;\n requestStore?: FlowpressRequestStore;\n}\n\nexport class FlowpressGraphqlError extends Error {\n constructor(\n message: string,\n readonly status?: number,\n readonly errors?: FlowpressGraphqlIssue[],\n readonly operationName?: string,\n readonly endpoint?: string,\n cause?: unknown\n ) {\n super(message, cause === undefined ? undefined : { cause });\n this.name = \"FlowpressGraphqlError\";\n }\n}\n\nexport class FlowpressClient {\n readonly endpoint: string;\n readonly timeoutMs: number;\n readonly headers: Record<string, string>;\n readonly debug: boolean;\n readonly requestStore: FlowpressRequestStore | undefined;\n\n constructor(options: FlowpressClientOptions) {\n const endpoint = options.endpoint.trim();\n if (!endpoint) {\n throw new Error(\"FlowPress GraphQL endpoint is required.\");\n }\n\n new URL(endpoint);\n this.endpoint = endpoint;\n this.timeoutMs = options.timeoutMs ?? 15_000;\n this.headers = { ...options.headers };\n this.debug = options.debug ?? false;\n this.requestStore = options.requestStore;\n }\n\n async request<T>(\n query: string,\n variables: Record<string, unknown> = {}\n ): Promise<T> {\n const url = new URL(this.endpoint);\n const anonymousQuery = Object.keys(this.headers).length === 0\n && !url.username && !url.password\n && /^(?:query\\b|\\{)/.test(query.trim())\n && !/\\b(?:mutation|subscription|sfContentRevision)\\b/.test(query);\n if (this.requestStore && anonymousQuery) {\n return this.requestStore.getOrCreate<T>(JSON.stringify({\n endpoint: this.endpoint, query, variables: canonicalVariables(variables)\n }), () => this.requestUncached<T>(query, variables));\n }\n return this.requestUncached<T>(query, variables);\n }\n\n async getContentRevision(): Promise<string> {\n // This read must never come from the build store it is validating.\n const data = await this.requestUncached<{ sfContentRevision: string }>(\n \"query FlowpressContentRevision { sfContentRevision }\", {}\n );\n if (!/^[a-f0-9]{32}$/.test(data.sfContentRevision || \"\")) {\n throw new Error(\"WordPress returned no valid FlowPress content revision.\");\n }\n return data.sfContentRevision;\n }\n\n private async requestUncached<T>(query: string, variables: Record<string, unknown>): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n const operationName = getOperationName(query);\n const safeEndpoint = sanitizeEndpoint(this.endpoint);\n\n try {\n let response: Response;\n try {\n response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...this.headers\n },\n body: JSON.stringify({ query, variables }),\n signal: controller.signal\n });\n } catch (error) {\n const timedOut = controller.signal.aborted;\n const detail = error instanceof Error && error.message\n ? ` ${error.message}`\n : \"\";\n throw new FlowpressGraphqlError(\n timedOut\n ? `FlowPress GraphQL ${operationName} timed out after ${this.timeoutMs}ms at ${safeEndpoint}.`\n : `FlowPress GraphQL ${operationName} could not reach ${safeEndpoint}.${detail}`,\n undefined,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n const body = await response.text();\n let payload: GraphqlResponse<T>;\n try {\n payload = JSON.parse(body) as GraphqlResponse<T>;\n } catch (error) {\n const contentType = response.headers.get(\"content-type\") || \"unknown content type\";\n throw new FlowpressGraphqlError(\n `FlowPress GraphQL ${operationName} returned ${response.status} `\n + `with ${contentType}, not JSON, from ${safeEndpoint}.`,\n response.status,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n if (!response.ok || payload.errors?.length || payload.data === undefined) {\n const errors: FlowpressGraphqlIssue[] | undefined = payload.errors?.map(\n (error) => {\n if (this.debug) {\n return error;\n }\n return error.message ? { message: error.message } : {};\n }\n );\n const messages = errors\n ?.flatMap((error) => [\n error.message,\n this.debug ? error.extensions?.debugMessage : undefined\n ])\n .filter((message): message is string => Boolean(message));\n throw new FlowpressGraphqlError(\n messages?.join(\"; \")\n || `FlowPress GraphQL ${operationName} failed with ${response.status} at ${safeEndpoint}.`,\n response.status,\n errors,\n operationName,\n safeEndpoint\n );\n }\n\n return payload.data;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async getCapabilities(): Promise<FlowpressCapabilities> {\n const data = await this.request<{ styleflowCapabilities: FlowpressCapabilities }>(\n `query FlowpressCapabilities {\n styleflowCapabilities {\n schemaVersion\n wpGraphql\n acfPro\n wpGraphqlAcf\n rankMath\n wpml\n woocommerce\n contactForm7\n defaultLocale\n locales { code slug homeUrl }\n features { id version enabled capabilities configJson }\n }\n }`\n );\n return {\n ...data.styleflowCapabilities,\n features: (data.styleflowCapabilities.features ?? []).map((feature) => {\n const wire = feature as typeof feature & { configJson?: string | null };\n let config: Record<string, unknown> = {};\n if (wire.configJson) {\n try {\n const parsed = JSON.parse(wire.configJson);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n config = parsed as Record<string, unknown>;\n }\n } catch {\n config = {};\n }\n }\n return {\n id: feature.id,\n version: feature.version ?? null,\n enabled: feature.enabled,\n capabilities: feature.capabilities ?? [],\n config\n };\n })\n };\n }\n\n async getRoute(uri: string, locale?: string): Promise<FlowpressRoute | null> {\n const data = await this.request<{\n sfRouteByUri: (Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }) | null;\n }>(\n `query FlowpressRoute($uri: String!, $locale: String) {\n sfRouteByUri(uri: $uri, locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { uri, locale: locale ?? null }\n );\n if (!data.sfRouteByUri) {\n return null;\n }\n return {\n ...data.sfRouteByUri,\n seo: normalizeGraphqlSeo(data.sfRouteByUri.seo)\n };\n }\n\n async getRoutes(locale?: string): Promise<FlowpressRoute[]> {\n const data = await this.request<{\n sfRoutes: Array<Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }>;\n }>(\n `query FlowpressRoutes($locale: String) {\n sfRoutes(locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { locale: locale ?? null }\n );\n return data.sfRoutes.map((route) => ({\n ...route,\n seo: normalizeGraphqlSeo(route.seo)\n }));\n }\n\n async getComposition(uri: string, locale?: string, options: { includeContent?: boolean } = {}): Promise<FlowpressCompositionV1 | null> {\n const data = await this.request<{\n sfCompositionByUri: null | {\n version: \"1\";\n sourceDigest: string;\n locale?: string | null;\n templateJson: string;\n blocksJson: string;\n stylesheetsJson: string;\n blockTypesJson: string;\n diagnosticsJson: string;\n routeJson: string;\n contentJson?: string | null;\n };\n }>(\n `query FlowpressComposition($uri: String!, $locale: String${options.includeContent === false ? \", $includeContent: Boolean\" : \"\"}) {\n sfCompositionByUri(uri: $uri, locale: $locale${options.includeContent === false ? \", includeContent: $includeContent\" : \"\"}) {\n version sourceDigest locale templateJson blocksJson stylesheetsJson blockTypesJson\n diagnosticsJson routeJson contentJson\n }\n }`,\n { uri, locale: locale ?? null, ...(options.includeContent === false ? { includeContent: false } : {}) }\n );\n const wire = data.sfCompositionByUri;\n if (!wire) return null;\n const route = parseRequiredJson<Omit<FlowpressRoute, \"seo\"> & { seo?: GraphqlSeo | SfSeo | null }>(wire.routeJson, \"routeJson\");\n return {\n version: wire.version,\n sourceDigest: wire.sourceDigest,\n locale: wire.locale ?? null,\n template: parseRequiredJson(wire.templateJson, \"templateJson\"),\n blocks: parseRequiredJson(wire.blocksJson, \"blocksJson\"),\n stylesheets: parseRequiredJson(wire.stylesheetsJson, \"stylesheetsJson\"),\n blockTypes: parseRequiredJson(wire.blockTypesJson, \"blockTypesJson\"),\n diagnostics: parseRequiredJson(wire.diagnosticsJson, \"diagnosticsJson\"),\n route: { ...route, seo: normalizeGraphqlSeo(route.seo) },\n content: parseJson(wire.contentJson, null)\n };\n }\n\n /** Site Editor already returns route and content in its composition. No\n * route preflight, retries or cross-request cache are needed for previews.\n */\n async getPage(uri: string, options: { locale?: string; includeContent?: boolean } = {}): Promise<{ route: FlowpressRoute; content: FlowpressContent | null; composition: FlowpressCompositionV1 } | null> {\n const composition = await this.getComposition(uri, options.locale, options);\n return composition ? { route: composition.route, content: composition.content ?? null, composition } : null;\n }\n\n}\n\nfunction getOperationName(query: string): string {\n return query.match(\n /\\b(?:query|mutation|subscription)\\s+([_A-Za-z][_0-9A-Za-z]*)/\n )?.[1] || \"AnonymousOperation\";\n}\n\nfunction sanitizeEndpoint(endpoint: string): string {\n const url = new URL(endpoint);\n url.username = \"\";\n url.password = \"\";\n url.search = \"\";\n url.hash = \"\";\n return url.toString();\n}\n\ninterface GraphqlSeo {\n title?: string | null;\n description?: string | null;\n canonicalUrl?: string | null;\n robots?: string[] | null;\n headHtml?: string | null;\n jsonLd?: { raw?: string | null } | null;\n openGraph?: GraphqlSocial | null;\n twitterMeta?: GraphqlSocial | null;\n hreflang?: Array<{ locale: string; url: string }> | null;\n}\n\ninterface GraphqlSocial {\n title?: string | null;\n description?: string | null;\n image?: { url: string; altText?: string | null } | null;\n}\n\nfunction normalizeGraphqlSeo(seo?: GraphqlSeo | SfSeo | null) {\n if (!seo) return null;\n const social = (value?: GraphqlSocial | SfSeo[\"openGraph\"] | null) => {\n if (!value) return null;\n const source = value.image as (NonNullable<NonNullable<SfSeo[\"openGraph\"]>[\"image\"]> & { altText?: string | null }) | null | undefined;\n const { altText, ...image } = source ?? {};\n return {\n title: value.title ?? null,\n description: value.description ?? null,\n image: source ? { ...image, url: source.url, alt: altText ?? source.alt ?? null } : null\n };\n };\n\n return {\n title: seo.title ?? null,\n description: seo.description ?? null,\n canonicalUrl: seo.canonicalUrl ?? null,\n robots: seo.robots ?? null,\n headHtml: seo.headHtml ?? null,\n jsonLd: seo.jsonLd && typeof seo.jsonLd === \"object\" && \"raw\" in seo.jsonLd\n ? parseJson((seo.jsonLd as { raw?: string | null }).raw, null) : seo.jsonLd ?? null,\n hreflang: seo.hreflang ?? null,\n openGraph: social(seo.openGraph),\n twitter: social(\"twitterMeta\" in seo ? seo.twitterMeta : (seo as SfSeo).twitter)\n };\n}\n\nfunction parseJson<T>(value: string | null | undefined, fallback: T): T {\n if (!value) return fallback;\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction parseRequiredJson<T>(value: string, field: string): T {\n try {\n return JSON.parse(value) as T;\n } catch (error) {\n throw new FlowpressGraphqlError(\n `FlowPress composition field ${field} is not valid JSON.`,\n undefined,\n undefined,\n \"FlowpressComposition\",\n undefined,\n error\n );\n }\n}\n\nfunction canonicalVariables(value: unknown): unknown {\n const normalized = JSON.parse(JSON.stringify(value)) as unknown;\n const sort = (item: unknown): unknown => Array.isArray(item)\n ? item.map(sort)\n : item && typeof item === \"object\"\n ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)).map(([key, child]) => [key, sort(child)]))\n : item;\n return sort(normalized);\n}\n"]}
@@ -1 +1 @@
1
- {"root":["../src/accessibility-panel.ts","../src/astro.d.ts","../src/block-renderers.ts","../src/carousel.ts","../src/client.ts","../src/composition.ts","../src/default-blocks.ts","../src/env.ts","../src/index.ts","../src/links.ts","../src/media.ts","../src/motion-preference.ts","../src/number-spinner.ts","../src/preferences-runtime.ts","../src/preferences-styleflow.ts","../src/preferences.ts","../src/reserved-area.ts","../src/style-classes.ts","../src/styleflow.ts","../src/svg-media-types.ts","../src/svg-media.ts","../src/template-hierarchy.ts","../src/text.ts","../src/theme-runtime.ts","../src/types.ts","../src/vivid-colors-preference.ts","../src/astro/blocks/cover.ts","../src/astro/blocks/helpers.ts","../src/astro/motion/accordion.ts","../src/astro/motion/motion-controller.ts","../src/astro/motion/motion.ts","../src/astro/native/button-template.ts","../src/astro/native/button.ts","../src/astro/native/flowpress-navigation-controller.ts","../src/astro/native/grid.ts","../src/astro/native/group.ts","../src/astro/native/html.ts","../src/astro/native/icon.ts","../src/astro/native/map.ts","../src/astro/native/motion-preference.ts","../src/astro/native/motion.ts","../src/astro/native/query-carousel.ts","../src/astro/native/query-loop.ts","../src/astro/native/registry.ts","../src/astro/native/timeline.ts","../src/astro/native/blob/blob-shapes.generated.ts","../src/astro/native/blob/config.ts","../src/astro/native/blob/controller.ts","../src/astro/native/blob/geometry.ts","../src/astro/native/blob/ids.ts","../src/svg-media-runtime.js","../src/astro/native/grid-bleed.js"],"version":"5.9.3"}
1
+ {"root":["../src/accessibility-panel.ts","../src/astro.d.ts","../src/block-renderers.ts","../src/build-cache.ts","../src/carousel.ts","../src/client.ts","../src/composition.ts","../src/default-blocks.ts","../src/env.ts","../src/index.ts","../src/links.ts","../src/media.ts","../src/motion-preference.ts","../src/number-spinner.ts","../src/preferences-runtime.ts","../src/preferences-styleflow.ts","../src/preferences.ts","../src/reserved-area.ts","../src/style-classes.ts","../src/styleflow.ts","../src/svg-media-types.ts","../src/svg-media.ts","../src/template-hierarchy.ts","../src/text.ts","../src/theme-runtime.ts","../src/types.ts","../src/vivid-colors-preference.ts","../src/astro/blocks/cover.ts","../src/astro/blocks/helpers.ts","../src/astro/motion/accordion.ts","../src/astro/motion/motion-controller.ts","../src/astro/motion/motion.ts","../src/astro/native/button-template.ts","../src/astro/native/button.ts","../src/astro/native/flowpress-navigation-controller.ts","../src/astro/native/grid.ts","../src/astro/native/group.ts","../src/astro/native/html.ts","../src/astro/native/icon.ts","../src/astro/native/map.ts","../src/astro/native/motion-preference.ts","../src/astro/native/motion.ts","../src/astro/native/query-carousel.ts","../src/astro/native/query-loop.ts","../src/astro/native/registry.ts","../src/astro/native/timeline.ts","../src/astro/native/blob/blob-shapes.generated.ts","../src/astro/native/blob/config.ts","../src/astro/native/blob/controller.ts","../src/astro/native/blob/geometry.ts","../src/astro/native/blob/ids.ts","../src/svg-media-runtime.js","../src/astro/native/grid-bleed.js"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleflow.app/flowpress-astro-core",
3
- "version": "1.0.0-beta.34",
3
+ "version": "1.0.0-beta.35",
4
4
  "description": "Project-agnostic WordPress routing, templates, SEO and GraphQL runtime for FlowPress Astro apps.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -71,7 +71,11 @@
71
71
  "import": "./dist/astro/motion/motion-controller.js",
72
72
  "default": "./dist/astro/motion/motion-controller.js"
73
73
  },
74
- "./motion.css": "./dist/astro/motion/motion.css"
74
+ "./motion.css": "./dist/astro/motion/motion.css",
75
+ "./build-cache": {
76
+ "types": "./dist/build-cache.d.ts",
77
+ "import": "./dist/build-cache.js"
78
+ }
75
79
  },
76
80
  "files": [
77
81
  "dist",