@digitalculture/ochre-sdk 0.12.1 → 0.12.3

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/dist/index.d.mts CHANGED
@@ -545,29 +545,26 @@ type Website = {
545
545
  mobile: Array<Style>;
546
546
  };
547
547
  } | null;
548
- properties: WebsiteProperties;
549
- };
550
- /**
551
- * Properties for configuring website display and styling
552
- */
553
- type WebsiteProperties = {
554
- type: "traditional" | "digital-collection" | "plum" | "cedar" | "elm" | "maple" | "oak" | "palm";
555
- privacy: "public" | "password" | "private";
556
- status: "development" | "preview" | "production";
557
- contact: {
558
- name: string;
559
- email: string | null;
560
- } | null;
561
- isHeaderDisplayed: boolean;
562
- headerVariant: "default" | "floating" | "inline";
563
- headerAlignment: "start" | "center" | "end";
564
- isHeaderProjectDisplayed: boolean;
565
- isFooterDisplayed: boolean;
566
- isSidebarDisplayed: boolean;
567
- iiifViewer: "universal-viewer" | "clover";
568
- supportsThemeToggle: boolean;
569
- defaultTheme: "light" | "dark" | null;
570
- logoUrl: string | null;
548
+ properties: {
549
+ type: "traditional" | "digital-collection" | "plum" | "cedar" | "elm" | "maple" | "oak" | "palm";
550
+ privacy: "public" | "password" | "private";
551
+ status: "development" | "preview" | "production";
552
+ contact: {
553
+ name: string;
554
+ email: string | null;
555
+ } | null;
556
+ isHeaderDisplayed: boolean;
557
+ headerVariant: "default" | "floating" | "inline";
558
+ headerAlignment: "start" | "center" | "end";
559
+ isHeaderProjectDisplayed: boolean;
560
+ isFooterDisplayed: boolean;
561
+ isSidebarDisplayed: boolean;
562
+ headerSearchButtonPageSlug: string | null;
563
+ iiifViewer: "universal-viewer" | "clover";
564
+ supportsThemeToggle: boolean;
565
+ defaultTheme: "light" | "dark" | null;
566
+ logoUrl: string | null;
567
+ };
571
568
  };
572
569
  type Webpage = {
573
570
  title: string;
@@ -661,6 +658,7 @@ type WebElementComponent = {
661
658
  variant: "full" | "highlights";
662
659
  itemVariant: "detailed" | "card" | "tile";
663
660
  paginationVariant: "default" | "numeric";
661
+ isSearchDisplayed: boolean;
664
662
  isSortDisplayed: boolean;
665
663
  isFilterDisplayed: boolean;
666
664
  filterSort: "default" | "alphabetical";
@@ -1191,4 +1189,4 @@ declare function filterProperties(property: Property, filter: {
1191
1189
  value: string | number | boolean | Date;
1192
1190
  }, options?: PropertyOptions): boolean;
1193
1191
  //#endregion
1194
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1192
+ export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, WebpageProperties, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as z from "zod";
2
- import { writeFileSync } from "node:fs";
3
2
 
4
3
  //#region src/schemas.ts
5
4
  /**
@@ -1792,6 +1791,9 @@ function parseWebElementProperties(componentProperty, elementResource) {
1792
1791
  itemVariant ??= "detailed";
1793
1792
  let paginationVariant = getPropertyValueByLabel(componentProperty.properties, "pagination-variant");
1794
1793
  paginationVariant ??= "default";
1794
+ let isSearchDisplayed = false;
1795
+ const isSearchDisplayedProperty = getPropertyValueByLabel(componentProperty.properties, "search-displayed");
1796
+ if (isSearchDisplayedProperty !== null) isSearchDisplayed = isSearchDisplayedProperty === true;
1795
1797
  let isSortDisplayed = false;
1796
1798
  const isSortDisplayedProperty = getPropertyValueByLabel(componentProperty.properties, "sort-displayed");
1797
1799
  if (isSortDisplayedProperty !== null) isSortDisplayed = isSortDisplayedProperty === true;
@@ -1847,6 +1849,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
1847
1849
  properties.variant = variant;
1848
1850
  properties.itemVariant = itemVariant;
1849
1851
  properties.paginationVariant = paginationVariant;
1852
+ properties.isSearchDisplayed = isSearchDisplayed;
1850
1853
  properties.isSortDisplayed = isSortDisplayed;
1851
1854
  properties.isFilterDisplayed = isFilterDisplayed;
1852
1855
  properties.filterSort = filterSort;
@@ -2561,7 +2564,7 @@ function parseWebBlock(blockResource) {
2561
2564
  return returnBlock;
2562
2565
  }
2563
2566
  /**
2564
- * Parses raw website properties into a standardized WebsiteProperties structure
2567
+ * Parses raw website properties into a standardized Website properties structure
2565
2568
  *
2566
2569
  * @param properties - Array of raw website properties in OCHRE format
2567
2570
  * @returns Parsed WebsiteProperties object
@@ -2612,6 +2615,7 @@ function parseWebsiteProperties(properties) {
2612
2615
  if (footerProperty) isFooterDisplayed = footerProperty.content === true;
2613
2616
  const sidebarProperty = websiteProperties.find((property) => property.label === "sidebar-visible")?.values[0];
2614
2617
  if (sidebarProperty) isSidebarDisplayed = sidebarProperty.content === true;
2618
+ const headerSearchButtonPageSlug = websiteProperties.find((property) => property.label === "navbar-search-button-page")?.values[0]?.content?.toString() ?? null;
2615
2619
  const iiifViewerProperty = websiteProperties.find((property) => property.label === "iiif-viewer")?.values[0];
2616
2620
  if (iiifViewerProperty) iiifViewer = iiifViewerProperty.content;
2617
2621
  const supportsThemeToggleProperty = websiteProperties.find((property) => property.label === "supports-theme-toggle")?.values[0];
@@ -2630,6 +2634,7 @@ function parseWebsiteProperties(properties) {
2630
2634
  isHeaderProjectDisplayed,
2631
2635
  isFooterDisplayed,
2632
2636
  isSidebarDisplayed,
2637
+ headerSearchButtonPageSlug,
2633
2638
  iiifViewer,
2634
2639
  supportsThemeToggle,
2635
2640
  defaultTheme,
@@ -2670,7 +2675,7 @@ function parseContexts(contexts) {
2670
2675
  }
2671
2676
  return contextsParsed;
2672
2677
  }
2673
- function parseWebsite(websiteTree, projectName, website$1, { isVersion2 = false } = {}) {
2678
+ function parseWebsite(websiteTree, projectName, website, { isVersion2 = false } = {}) {
2674
2679
  if (!websiteTree.properties) throw new Error("Website properties not found");
2675
2680
  const properties = parseWebsiteProperties(Array.isArray(websiteTree.properties.property) ? websiteTree.properties.property : [websiteTree.properties.property]);
2676
2681
  if (typeof websiteTree.items === "string" || !("resource" in websiteTree.items)) throw new Error("Website pages not found");
@@ -2684,7 +2689,7 @@ function parseWebsite(websiteTree, projectName, website$1, { isVersion2 = false
2684
2689
  identification: parseIdentification(websiteTree.identification),
2685
2690
  project: {
2686
2691
  name: parseFakeString(projectName),
2687
- website: website$1 !== null ? parseFakeString(website$1) : null
2692
+ website: website !== null ? parseFakeString(website) : null
2688
2693
  },
2689
2694
  creators: websiteTree.creators ? parsePersons(Array.isArray(websiteTree.creators.creator) ? websiteTree.creators.creator : [websiteTree.creators.creator]) : [],
2690
2695
  license: parseLicense(websiteTree.availability),
@@ -3124,12 +3129,12 @@ const V2_ABBREVIATIONS = new Set(["bengali-song"]);
3124
3129
  */
3125
3130
  async function fetchWebsite(abbreviation, options) {
3126
3131
  try {
3127
- const customFetch = options?.customFetch;
3128
- const isVersion2 = options?.isVersion2 ?? false;
3129
3132
  const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
3133
+ const customFetch = options?.customFetch;
3134
+ const isVersion2 = V2_ABBREVIATIONS.has(cleanAbbreviation) ? true : options?.isVersion2 ?? false;
3130
3135
  let metadata = null;
3131
3136
  let tree = null;
3132
- if (V2_ABBREVIATIONS.has(cleanAbbreviation) || isVersion2) {
3137
+ if (isVersion2) {
3133
3138
  const response = await (customFetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(`collection('ochre/tree')/ochre[tree/identification/abbreviation/content/string='${cleanAbbreviation}']`)}&format=json&lang="*"`);
3134
3139
  if (!response.ok) throw new Error("Failed to fetch website");
3135
3140
  const data = await response.json();
@@ -3147,14 +3152,12 @@ async function fetchWebsite(abbreviation, options) {
3147
3152
  tree = result.ochre.tree;
3148
3153
  }
3149
3154
  const projectIdentification = metadata.project?.identification ? parseIdentification(metadata.project.identification) : null;
3150
- return [null, parseWebsite(tree, projectIdentification?.label ?? "", metadata.project?.identification.website ?? null, { isVersion2: true })];
3155
+ return [null, parseWebsite(tree, projectIdentification?.label ?? "", metadata.project?.identification.website ?? null, { isVersion2 })];
3151
3156
  } catch (error) {
3152
3157
  console.error(error);
3153
3158
  return [error instanceof Error ? error.message : "Unknown error", null];
3154
3159
  }
3155
3160
  }
3156
- const [_, website] = await fetchWebsite("bengali-song");
3157
- writeFileSync("website.json", JSON.stringify(website, null, 2));
3158
3161
 
3159
3162
  //#endregion
3160
3163
  export { fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",