@the-smithy/hearth 0.23.0 → 0.24.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.
@@ -73,7 +73,7 @@ function createCore(options) {
73
73
  throw new Error("Hearth: the API key is secret, so the client only runs on the server. Fetch content in server code, or pass allowBrowser: true if you understand the risk.");
74
74
  }
75
75
  const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
76
- const doFetch = options.fetch ?? globalThis.fetch;
76
+ const doFetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
77
77
  const timeoutMs = options.timeoutMs ?? 1e4;
78
78
  const retries = options.retries ?? 2;
79
79
  const hooks = options.hooks ?? {};
@@ -299,15 +299,13 @@ function createCore(options) {
299
299
  },
300
300
  globalBlocks: {
301
301
  /**
302
- * The site's global blocks (Global blocks in Hearth), resolved: pop-ups (`popup` set), menu dropdowns (a menu
303
- * item's `dropdown` names one) and any others the site's code places by key. Empty from Hearth versions without them.
302
+ * Every published global block on the site (Global blocks in Hearth), resolved, with what it is and where editors
303
+ * placed it: pop-ups (`popup` set), menu dropdowns (`usedOn.menuItems`), pages. Place any of them anywhere.
304
+ * Empty from Hearth versions without them.
304
305
  */
305
306
  list: async (o = {}) => await maybe("/global-blocks", { ...o, resource: "globalBlocks.list" }) ?? [],
306
- /** One global block by key, or null. */
307
- get: async (key, o = {}) => {
308
- const list = await maybe("/global-blocks", { ...o, resource: "globalBlocks.list" }) ?? [];
309
- return list.find((g) => g.key === key) ?? null;
310
- }
307
+ /** One global block by its key ("contact") or id, or null if there's none or it isn't published. */
308
+ get: (ref, o = {}) => maybe(`/global-blocks/${encodeURIComponent(ref)}`, { ...o, resource: "globalBlocks.get" })
311
309
  },
312
310
  customBlocks: {
313
311
  /** The site's own block types (Custom blocks in Hearth): each one's key, name and fields, for rendering `custom` blocks. */
@@ -229,12 +229,13 @@ declare function createCore(options: HearthClientOptions): {
229
229
  };
230
230
  globalBlocks: {
231
231
  /**
232
- * The site's global blocks (Global blocks in Hearth), resolved: pop-ups (`popup` set), menu dropdowns (a menu
233
- * item's `dropdown` names one) and any others the site's code places by key. Empty from Hearth versions without them.
232
+ * Every published global block on the site (Global blocks in Hearth), resolved, with what it is and where editors
233
+ * placed it: pop-ups (`popup` set), menu dropdowns (`usedOn.menuItems`), pages. Place any of them anywhere.
234
+ * Empty from Hearth versions without them.
234
235
  */
235
236
  list: (o?: CallOptions) => Promise<GlobalBlock[]>;
236
- /** One global block by key, or null. */
237
- get: (key: string, o?: CallOptions) => Promise<GlobalBlock | null>;
237
+ /** One global block by its key ("contact") or id, or null if there's none or it isn't published. */
238
+ get: (ref: string, o?: CallOptions) => Promise<GlobalBlock | null>;
238
239
  };
239
240
  customBlocks: {
240
241
  /** The site's own block types (Custom blocks in Hearth): each one's key, name and fields, for rendering `custom` blocks. */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HearthCore, a as HearthClientOptions } from './client-Deumm7No.js';
2
- export { C as CallOptions, b as CollectionPage, D as DEFAULT_BASE_URL, E as EventCollectionPage, F as FormResult, c as FormValues, d as HearthError, e as HearthErrorCode, f as HearthHooks, N as NextFetchOptions, P as PreviewSession, R as RequestContext, g as RequestOptions, h as findRedirect, i as isHearthError, n as normalizeSlug } from './client-Deumm7No.js';
1
+ import { H as HearthCore, a as HearthClientOptions } from './client-E1ie4g_L.js';
2
+ export { C as CallOptions, b as CollectionPage, D as DEFAULT_BASE_URL, E as EventCollectionPage, F as FormResult, c as FormValues, d as HearthError, e as HearthErrorCode, f as HearthHooks, N as NextFetchOptions, P as PreviewSession, R as RequestContext, g as RequestOptions, h as findRedirect, i as isHearthError, n as normalizeSlug } from './client-E1ie4g_L.js';
3
3
  export { AnalyticsReport, AnalyticsRow, Block, BlockOf, CategoryGroup, CategoryRef, Collection, CollectionEntry, CollectionRef, DonationCheckout, DonationInput, EntryDetails, EventCustomFields, EventRegistration, EventTicket, EventVolunteerShift, EventVolunteering, Fundraiser, FundraiserDetail, GlobalBlock, GlobalPopup, HearthEvent, HearthEventDetail, ImageRef, KnownBlock, Page, PageMeta, PageSummary, Position, Redirect, RegistrationInput, RegistrationResult, ResolvedBlock, SharedFrom, Site, SiteAnalytics, SiteSettings, SitemapEntry, UnknownBlock, VolunteerInput, VolunteerResult, WebhookPayload, directionsUrl, focalPosition, pinned, videoEmbedUrl } from '@the-smithy/hearth-schema';
4
4
 
5
5
  /** A plugin adds resources (and can use the core's `request`) under its own names. */
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  findRedirect,
6
6
  isHearthError,
7
7
  normalizeSlug
8
- } from "./chunk-QDCU7YWV.js";
8
+ } from "./chunk-3LZQGXTQ.js";
9
9
 
10
10
  // src/index.ts
11
11
  import { videoEmbedUrl } from "@the-smithy/hearth-schema";
package/dist/next.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { H as HearthCore, b as CollectionPage, E as EventCollectionPage, F as FormResult, c as FormValues } from './client-Deumm7No.js';
1
+ import { H as HearthCore, b as CollectionPage, E as EventCollectionPage, F as FormResult, c as FormValues } from './client-E1ie4g_L.js';
2
2
  import * as _the_smithy_hearth_schema from '@the-smithy/hearth-schema';
3
3
  import { Site, PageMeta } from '@the-smithy/hearth-schema';
4
4
  import { Metadata, MetadataRoute } from 'next';
@@ -170,8 +170,10 @@ declare function createHearthNext(client: HearthCore, { tag, revalidate }?: Hear
170
170
  optional?: boolean | undefined;
171
171
  })[];
172
172
  }[]>;
173
- /** Global blocks (pop-ups, menu dropdowns, ones the site places by key); drafts while previewing. */
173
+ /** Every global block (to place anywhere, and for pop-ups and menu dropdowns); drafts while previewing. */
174
174
  getGlobalBlocks: () => Promise<_the_smithy_hearth_schema.GlobalBlock[]>;
175
+ /** One global block by key or id, or null; its draft while previewing. */
176
+ getGlobalBlock: (ref: string) => Promise<_the_smithy_hearth_schema.GlobalBlock | null>;
175
177
  getCollections: () => Promise<_the_smithy_hearth_schema.Collection[]>;
176
178
  getCollection: (slug: string, opts?: {
177
179
  limit?: number;
package/dist/next.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  findRedirect,
3
3
  isHearthError,
4
4
  normalizeSlug
5
- } from "./chunk-QDCU7YWV.js";
5
+ } from "./chunk-3LZQGXTQ.js";
6
6
  import {
7
7
  parseWebhook,
8
8
  tagsForWebhook
@@ -60,8 +60,10 @@ function createHearthNext(client, { tag = "hearth", revalidate = 3600 } = {}) {
60
60
  getEvents: (opts) => client.events.list(opts, tags(`${tag}:events`)),
61
61
  getCategories: () => client.categories.list(tags(`${tag}:site`)),
62
62
  getCustomBlocks: () => client.customBlocks.list(tags(`${tag}:site`)),
63
- /** Global blocks (pop-ups, menu dropdowns, ones the site places by key); drafts while previewing. */
63
+ /** Every global block (to place anywhere, and for pop-ups and menu dropdowns); drafts while previewing. */
64
64
  getGlobalBlocks: async () => client.globalBlocks.list(await read(`${tag}:global`)),
65
+ /** One global block by key or id, or null; its draft while previewing. */
66
+ getGlobalBlock: async (ref) => client.globalBlocks.get(ref, await read(`${tag}:global`)),
65
67
  getCollections: () => client.collections.list(tags(`${tag}:site`, `${tag}:pages`)),
66
68
  getCollection: (slug, opts) => client.collections.get(slug, opts, tags(`${tag}:pages`, `${tag}:events`)),
67
69
  getEvent: async (slug) => client.events.get(slug, await read(`${tag}:events`)),
package/dist/testing.js CHANGED
@@ -49,6 +49,11 @@ function createMockHearth(data = {}) {
49
49
  if (rest === "/llms") return json({ data: data.llmsTxt ?? null });
50
50
  if (rest === "/redirects") return json({ data: data.redirects ?? [] });
51
51
  if (rest === "/global-blocks") return json({ data: data.globalBlocks ?? [] });
52
+ if (rest.startsWith("/global-blocks/")) {
53
+ const ref = decodeURIComponent(rest.slice(15));
54
+ const block = (data.globalBlocks ?? []).find((g) => g.key === ref || g.id === ref);
55
+ return block ? json({ data: block }) : notFound();
56
+ }
52
57
  if (rest === "/fundraisers" || rest.startsWith("/fundraisers?")) {
53
58
  const status = url.searchParams.get("status") ?? "active";
54
59
  return json({ data: (data.fundraisers ?? []).filter((f) => status === "all" || f.status === status) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-smithy/hearth",
3
- "version": "0.23.0",
3
+ "version": "0.24.1",
4
4
  "description": "Typed client for the Hearth Delivery API: content, SEO, forms and publish webhooks.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -49,7 +49,7 @@
49
49
  "llms.md"
50
50
  ],
51
51
  "dependencies": {
52
- "@the-smithy/hearth-schema": "^0.23.0"
52
+ "@the-smithy/hearth-schema": "^0.24.1"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "next": ">=15",