@digitalculture/ochre-sdk 0.11.28 → 0.12.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/dist/index.d.mts CHANGED
@@ -524,6 +524,7 @@ type LevelContext = {
524
524
  */
525
525
  type Website = {
526
526
  uuid: string;
527
+ version: 1 | 2;
527
528
  publicationDateTime: Date | null;
528
529
  identification: Identification;
529
530
  project: {
@@ -545,33 +546,6 @@ type Website = {
545
546
  };
546
547
  } | null;
547
548
  properties: WebsiteProperties;
548
- searchOptions: {
549
- filters: Array<{
550
- uuid: string;
551
- type: string;
552
- }>;
553
- attributeFilters: {
554
- bibliographies: boolean;
555
- periods: boolean;
556
- };
557
- scopes: Array<{
558
- uuid: string;
559
- type: string;
560
- identification: Identification;
561
- }>;
562
- };
563
- globalOptions: {
564
- contexts: {
565
- flatten: Array<LevelContext>;
566
- suppress: Array<LevelContext>;
567
- filter: Array<LevelContext>;
568
- sort: Array<LevelContext>;
569
- detail: Array<LevelContext>;
570
- download: Array<LevelContext>;
571
- label: Array<LevelContext>;
572
- prominent: Array<LevelContext>;
573
- };
574
- };
575
549
  };
576
550
  /**
577
551
  * Properties for configuring website display and styling
@@ -691,6 +665,27 @@ type WebElementComponent = {
691
665
  isFilterDisplayed: boolean;
692
666
  filterSort: "default" | "alphabetical";
693
667
  layout: "image-top" | "image-bottom" | "image-start" | "image-end";
668
+ options: {
669
+ attributeFilters: {
670
+ bibliographies: boolean;
671
+ periods: boolean;
672
+ };
673
+ scopes: Array<{
674
+ uuid: string;
675
+ type: string;
676
+ identification: Identification;
677
+ }>;
678
+ contexts: {
679
+ flatten: Array<LevelContext>;
680
+ suppress: Array<LevelContext>;
681
+ filter: Array<LevelContext>;
682
+ sort: Array<LevelContext>;
683
+ detail: Array<LevelContext>;
684
+ download: Array<LevelContext>;
685
+ label: Array<LevelContext>;
686
+ prominent: Array<LevelContext>;
687
+ };
688
+ };
694
689
  } | {
695
690
  component: "empty-space";
696
691
  height: string | null;
@@ -786,6 +781,7 @@ type WebElementComponent = {
786
781
  * Represents an image used in web elements
787
782
  */
788
783
  type WebImage = {
784
+ uuid: string | null;
789
785
  url: string;
790
786
  label: string | null;
791
787
  description: string | null;
@@ -914,7 +910,10 @@ declare function fetchGallery(uuid: string, filter: string, page: number, perPag
914
910
  *
915
911
  * If the fetch/parse fails, the returned object will have an `error` property.
916
912
  */
917
- declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid: string, category?: T, setCategory?: T extends "set" ? U : never, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<{
913
+ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid: string, category?: T, setCategory?: T extends "set" ? U : never, options?: {
914
+ customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
915
+ isVersion2: boolean;
916
+ }): Promise<{
918
917
  error: null;
919
918
  metadata: Metadata;
920
919
  belongsTo: {
@@ -937,7 +936,9 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
937
936
  *
938
937
  * @param scopeUuids - The scope UUIDs to filter by
939
938
  * @param propertyUuids - The property UUIDs to query by
940
- * @param customFetch - A custom fetch function to use instead of the default fetch
939
+ * @param options - Options for the fetch
940
+ * @param options.customFetch - A custom fetch function to use instead of the default fetch
941
+ * @param options.isVersion2 - Whether to use the v2 API
941
942
  * @returns The parsed property query or null if the fetch/parse fails
942
943
  *
943
944
  * @example
@@ -954,7 +955,10 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
954
955
  * The returned property query includes:
955
956
  * - Property items
956
957
  */
957
- declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<string>, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<{
958
+ declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<string>, options?: {
959
+ customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
960
+ isVersion2?: boolean;
961
+ }): Promise<{
958
962
  items: Array<PropertyQueryItem> | null;
959
963
  error: null;
960
964
  } | {
@@ -1014,7 +1018,10 @@ declare function fetchByUuidMetadata(uuid: string, customFetch?: (input: string
1014
1018
  *
1015
1019
  * The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
1016
1020
  */
1017
- declare function fetchWebsite(abbreviation: string, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<[null, Website] | [string, null]>;
1021
+ declare function fetchWebsite(abbreviation: string, options?: {
1022
+ customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1023
+ isVersion2?: boolean;
1024
+ }): Promise<[null, Website] | [string, null]>;
1018
1025
  //#endregion
1019
1026
  //#region src/utils/getters.d.ts
1020
1027
  /**
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { z } from "zod";
1
+ import * as z from "zod";
2
+ import { writeFileSync } from "node:fs";
2
3
 
3
4
  //#region src/schemas.ts
4
5
  /**
@@ -1766,6 +1767,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
1766
1767
  let image = null;
1767
1768
  const imageLink = links.find((link) => link.type === "image" || link.type === "IIIF");
1768
1769
  if (imageLink != null) image = {
1770
+ uuid: imageLink.uuid,
1769
1771
  url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load`,
1770
1772
  label: imageLink.identification?.label ?? null,
1771
1773
  width: imageLink.image?.width ?? 0,
@@ -1800,6 +1802,47 @@ function parseWebElementProperties(componentProperty, elementResource) {
1800
1802
  filterSort ??= "default";
1801
1803
  let layout = getPropertyValueByLabel(componentProperty.properties, "layout");
1802
1804
  layout ??= "image-start";
1805
+ const options = {
1806
+ attributeFilters: {
1807
+ bibliographies: elementResource.options?.filterBibliography ?? false,
1808
+ periods: elementResource.options?.filterPeriods ?? false
1809
+ },
1810
+ scopes: elementResource.options?.scopes != null ? (Array.isArray(elementResource.options.scopes.scope) ? elementResource.options.scopes.scope : [elementResource.options.scopes.scope]).map((scope) => ({
1811
+ uuid: scope.uuid.content,
1812
+ type: scope.uuid.type,
1813
+ identification: parseIdentification(scope.identification)
1814
+ })) : [],
1815
+ contexts: {
1816
+ flatten: [],
1817
+ filter: [],
1818
+ sort: [],
1819
+ detail: [],
1820
+ download: [],
1821
+ label: [],
1822
+ suppress: [],
1823
+ prominent: []
1824
+ }
1825
+ };
1826
+ if ("options" in elementResource && elementResource.options) {
1827
+ const flattenContextsRaw = elementResource.options.flattenContexts != null ? Array.isArray(elementResource.options.flattenContexts) ? elementResource.options.flattenContexts : [elementResource.options.flattenContexts] : [];
1828
+ const suppressContextsRaw = elementResource.options.suppressContexts != null ? Array.isArray(elementResource.options.suppressContexts) ? elementResource.options.suppressContexts : [elementResource.options.suppressContexts] : [];
1829
+ const filterContextsRaw = elementResource.options.filterContexts != null ? Array.isArray(elementResource.options.filterContexts) ? elementResource.options.filterContexts : [elementResource.options.filterContexts] : [];
1830
+ const sortContextsRaw = elementResource.options.sortContexts != null ? Array.isArray(elementResource.options.sortContexts) ? elementResource.options.sortContexts : [elementResource.options.sortContexts] : [];
1831
+ const detailContextsRaw = elementResource.options.detailContexts != null ? Array.isArray(elementResource.options.detailContexts) ? elementResource.options.detailContexts : [elementResource.options.detailContexts] : [];
1832
+ const downloadContextsRaw = elementResource.options.downloadContexts != null ? Array.isArray(elementResource.options.downloadContexts) ? elementResource.options.downloadContexts : [elementResource.options.downloadContexts] : [];
1833
+ const labelContextsRaw = elementResource.options.labelContexts != null ? Array.isArray(elementResource.options.labelContexts) ? elementResource.options.labelContexts : [elementResource.options.labelContexts] : [];
1834
+ const prominentContextsRaw = elementResource.options.prominentContexts != null ? Array.isArray(elementResource.options.prominentContexts) ? elementResource.options.prominentContexts : [elementResource.options.prominentContexts] : [];
1835
+ options.contexts = {
1836
+ flatten: parseContexts(flattenContextsRaw),
1837
+ filter: parseContexts(filterContextsRaw),
1838
+ sort: parseContexts(sortContextsRaw),
1839
+ detail: parseContexts(detailContextsRaw),
1840
+ download: parseContexts(downloadContextsRaw),
1841
+ label: parseContexts(labelContextsRaw),
1842
+ suppress: parseContexts(suppressContextsRaw),
1843
+ prominent: parseContexts(prominentContextsRaw)
1844
+ };
1845
+ }
1803
1846
  properties.collectionId = collectionLink.uuid;
1804
1847
  properties.variant = variant;
1805
1848
  properties.itemVariant = itemVariant;
@@ -1808,6 +1851,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
1808
1851
  properties.isFilterDisplayed = isFilterDisplayed;
1809
1852
  properties.filterSort = filterSort;
1810
1853
  properties.layout = layout;
1854
+ properties.options = options;
1811
1855
  break;
1812
1856
  }
1813
1857
  case "empty-space": {
@@ -1855,6 +1899,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
1855
1899
  imageQuality ??= "high";
1856
1900
  const images = [];
1857
1901
  for (const link of links) images.push({
1902
+ uuid: link.uuid,
1858
1903
  url: `https://ochre.lib.uchicago.edu/ochre?uuid=${link.uuid}${imageQuality === "high" && (link.type === "image" || link.type === "IIIF") ? "&load" : "&preview"}`,
1859
1904
  label: link.identification?.label ?? null,
1860
1905
  width: link.image?.width ?? 0,
@@ -2625,72 +2670,27 @@ function parseContexts(contexts) {
2625
2670
  }
2626
2671
  return contextsParsed;
2627
2672
  }
2628
- function parseWebsite(websiteTree, projectName, website) {
2673
+ function parseWebsite(websiteTree, projectName, website$1, { isVersion2 = false } = {}) {
2629
2674
  if (!websiteTree.properties) throw new Error("Website properties not found");
2630
2675
  const properties = parseWebsiteProperties(Array.isArray(websiteTree.properties.property) ? websiteTree.properties.property : [websiteTree.properties.property]);
2631
2676
  if (typeof websiteTree.items === "string" || !("resource" in websiteTree.items)) throw new Error("Website pages not found");
2632
2677
  const resources = Array.isArray(websiteTree.items.resource) ? websiteTree.items.resource : [websiteTree.items.resource];
2633
2678
  const pages = parseWebpages(resources);
2634
2679
  const sidebar = parseSidebar(resources);
2635
- let globalOptions = { contexts: {
2636
- flatten: [],
2637
- filter: [],
2638
- sort: [],
2639
- detail: [],
2640
- download: [],
2641
- label: [],
2642
- suppress: [],
2643
- prominent: []
2644
- } };
2645
- if (websiteTree.websiteOptions) {
2646
- const flattenContextsRaw = websiteTree.websiteOptions.flattenContexts != null ? Array.isArray(websiteTree.websiteOptions.flattenContexts) ? websiteTree.websiteOptions.flattenContexts : [websiteTree.websiteOptions.flattenContexts] : [];
2647
- const suppressContextsRaw = websiteTree.websiteOptions.suppressContexts != null ? Array.isArray(websiteTree.websiteOptions.suppressContexts) ? websiteTree.websiteOptions.suppressContexts : [websiteTree.websiteOptions.suppressContexts] : [];
2648
- const filterContextsRaw = websiteTree.websiteOptions.filterContexts != null ? Array.isArray(websiteTree.websiteOptions.filterContexts) ? websiteTree.websiteOptions.filterContexts : [websiteTree.websiteOptions.filterContexts] : [];
2649
- const sortContextsRaw = websiteTree.websiteOptions.sortContexts != null ? Array.isArray(websiteTree.websiteOptions.sortContexts) ? websiteTree.websiteOptions.sortContexts : [websiteTree.websiteOptions.sortContexts] : [];
2650
- const detailContextsRaw = websiteTree.websiteOptions.detailContexts != null ? Array.isArray(websiteTree.websiteOptions.detailContexts) ? websiteTree.websiteOptions.detailContexts : [websiteTree.websiteOptions.detailContexts] : [];
2651
- const downloadContextsRaw = websiteTree.websiteOptions.downloadContexts != null ? Array.isArray(websiteTree.websiteOptions.downloadContexts) ? websiteTree.websiteOptions.downloadContexts : [websiteTree.websiteOptions.downloadContexts] : [];
2652
- const labelContextsRaw = websiteTree.websiteOptions.labelContexts != null ? Array.isArray(websiteTree.websiteOptions.labelContexts) ? websiteTree.websiteOptions.labelContexts : [websiteTree.websiteOptions.labelContexts] : [];
2653
- const prominentContextsRaw = websiteTree.websiteOptions.prominentContexts != null ? Array.isArray(websiteTree.websiteOptions.prominentContexts) ? websiteTree.websiteOptions.prominentContexts : [websiteTree.websiteOptions.prominentContexts] : [];
2654
- globalOptions = { contexts: {
2655
- flatten: parseContexts(flattenContextsRaw),
2656
- filter: parseContexts(filterContextsRaw),
2657
- sort: parseContexts(sortContextsRaw),
2658
- detail: parseContexts(detailContextsRaw),
2659
- download: parseContexts(downloadContextsRaw),
2660
- label: parseContexts(labelContextsRaw),
2661
- suppress: parseContexts(suppressContextsRaw),
2662
- prominent: parseContexts(prominentContextsRaw)
2663
- } };
2664
- }
2665
2680
  return {
2666
2681
  uuid: websiteTree.uuid,
2682
+ version: isVersion2 ? 2 : 1,
2667
2683
  publicationDateTime: websiteTree.publicationDateTime ? new Date(websiteTree.publicationDateTime) : null,
2668
2684
  identification: parseIdentification(websiteTree.identification),
2669
2685
  project: {
2670
2686
  name: parseFakeString(projectName),
2671
- website: website !== null ? parseFakeString(website) : null
2687
+ website: website$1 !== null ? parseFakeString(website$1) : null
2672
2688
  },
2673
2689
  creators: websiteTree.creators ? parsePersons(Array.isArray(websiteTree.creators.creator) ? websiteTree.creators.creator : [websiteTree.creators.creator]) : [],
2674
2690
  license: parseLicense(websiteTree.availability),
2675
2691
  sidebar,
2676
2692
  pages,
2677
- properties,
2678
- searchOptions: {
2679
- filters: websiteTree.searchOptions?.filterUuids != null ? (Array.isArray(websiteTree.searchOptions.filterUuids.uuid) ? websiteTree.searchOptions.filterUuids.uuid : [websiteTree.searchOptions.filterUuids.uuid]).map((uuid) => ({
2680
- uuid: uuid.content,
2681
- type: uuid.type
2682
- })) : [],
2683
- attributeFilters: {
2684
- bibliographies: websiteTree.searchOptions?.filterUuids?.filterBibliography ?? false,
2685
- periods: websiteTree.searchOptions?.filterUuids?.filterPeriods ?? false
2686
- },
2687
- scopes: websiteTree.searchOptions?.scopes != null ? (Array.isArray(websiteTree.searchOptions.scopes.scope) ? websiteTree.searchOptions.scopes.scope : [websiteTree.searchOptions.scopes.scope]).map((scope) => ({
2688
- uuid: scope.uuid.content,
2689
- type: scope.uuid.type,
2690
- identification: parseIdentification(scope.identification)
2691
- })) : []
2692
- },
2693
- globalOptions
2693
+ properties
2694
2694
  };
2695
2695
  }
2696
2696
 
@@ -2781,10 +2781,12 @@ async function fetchGallery(uuid, filter, page, perPage, customFetch) {
2781
2781
  *
2782
2782
  * @internal
2783
2783
  */
2784
- async function fetchByUuid(uuid, customFetch) {
2784
+ async function fetchByUuid(uuid, options) {
2785
2785
  try {
2786
+ const customFetch = options?.customFetch;
2787
+ const isVersion2 = options?.isVersion2 ?? false;
2786
2788
  const parsedUuid = uuidSchema.parse(uuid);
2787
- const response = await (customFetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`);
2789
+ const response = await (customFetch ?? fetch)(isVersion2 ? `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${parsedUuid}&format=json&lang="*"` : `https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`);
2788
2790
  if (!response.ok) throw new Error("Failed to fetch OCHRE data");
2789
2791
  const dataRaw = await response.json();
2790
2792
  if (!("ochre" in dataRaw)) throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
@@ -2829,9 +2831,13 @@ async function fetchByUuid(uuid, customFetch) {
2829
2831
  *
2830
2832
  * If the fetch/parse fails, the returned object will have an `error` property.
2831
2833
  */
2832
- async function fetchItem(uuid, category, setCategory, customFetch) {
2834
+ async function fetchItem(uuid, category, setCategory, options) {
2833
2835
  try {
2834
- const [error, data] = await fetchByUuid(uuid, customFetch);
2836
+ const customFetch = options?.customFetch;
2837
+ const [error, data] = await fetchByUuid(uuid, {
2838
+ customFetch,
2839
+ isVersion2: options?.isVersion2 ?? false
2840
+ });
2835
2841
  if (error !== null) throw new Error(error);
2836
2842
  const categoryKey = getItemCategory(Object.keys(data.ochre));
2837
2843
  let item;
@@ -2895,11 +2901,17 @@ async function fetchItem(uuid, category, setCategory, customFetch) {
2895
2901
  }
2896
2902
  }
2897
2903
 
2904
+ //#endregion
2905
+ //#region src/constants.ts
2906
+ /**
2907
+ * The UUID of the `<unassigned>` property value in OCHRE
2908
+ */
2909
+ const UNASSIGNED_UUID = "e28e29af-b663-c0ac-ceb6-11a688fca0dd";
2910
+
2898
2911
  //#endregion
2899
2912
  //#region src/utils/fetchers/property-query.ts
2900
2913
  const PROJECT_SCOPE = "0c0aae37-7246-495b-9547-e25dbf5b99a3";
2901
2914
  const BELONG_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
2902
- const UNASSIGNED_UUID = "e28e29af-b663-c0ac-ceb6-11a688fca0dd";
2903
2915
  /**
2904
2916
  * Check if a string is a valid UUID
2905
2917
  * @param value - The string to check
@@ -2953,7 +2965,9 @@ return <item>
2953
2965
  *
2954
2966
  * @param scopeUuids - The scope UUIDs to filter by
2955
2967
  * @param propertyUuids - The property UUIDs to query by
2956
- * @param customFetch - A custom fetch function to use instead of the default fetch
2968
+ * @param options - Options for the fetch
2969
+ * @param options.customFetch - A custom fetch function to use instead of the default fetch
2970
+ * @param options.isVersion2 - Whether to use the v2 API
2957
2971
  * @returns The parsed property query or null if the fetch/parse fails
2958
2972
  *
2959
2973
  * @example
@@ -2970,10 +2984,12 @@ return <item>
2970
2984
  * The returned property query includes:
2971
2985
  * - Property items
2972
2986
  */
2973
- async function fetchPropertyQuery(scopeUuids, propertyUuids, customFetch) {
2987
+ async function fetchPropertyQuery(scopeUuids, propertyUuids, options) {
2974
2988
  try {
2989
+ const customFetch = options?.customFetch;
2990
+ const isVersion2 = options?.isVersion2 ?? false;
2975
2991
  const xquery = buildXQuery(scopeUuids, propertyUuids);
2976
- const response = await (customFetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json`);
2992
+ const response = await (customFetch ?? fetch)(isVersion2 ? `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"`);
2977
2993
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
2978
2994
  const data = await response.json();
2979
2995
  const parsedResultRaw = responseSchema.parse(data);
@@ -3076,6 +3092,7 @@ const KNOWN_ABBREVIATIONS = {
3076
3092
  ssmc: "8ff977dd-d440-40f5-ad93-8ad7e2d39e74",
3077
3093
  "sosc-core-at-smart": "db26c953-9b2a-4691-a909-5e8726b531d7"
3078
3094
  };
3095
+ const V2_ABBREVIATIONS = new Set(["bengali-song"]);
3079
3096
  /**
3080
3097
  * Fetches and parses a website configuration from the OCHRE API
3081
3098
  *
@@ -3105,21 +3122,39 @@ const KNOWN_ABBREVIATIONS = {
3105
3122
  *
3106
3123
  * The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
3107
3124
  */
3108
- async function fetchWebsite(abbreviation, customFetch) {
3125
+ async function fetchWebsite(abbreviation, options) {
3109
3126
  try {
3110
- const uuid = KNOWN_ABBREVIATIONS[abbreviation.toLocaleLowerCase("en-US")];
3111
- const response = await (customFetch ?? fetch)(uuid != null ? `https://ochre.lib.uchicago.edu/ochre?uuid=${uuid}&format=json` : `https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${abbreviation.toLocaleLowerCase("en-US")}']] return $q&format=json`);
3112
- if (!response.ok) throw new Error("Failed to fetch website");
3113
- const data = await response.json();
3114
- const result = "result" in data && !Array.isArray(data.result) ? data.result : !("result" in data) ? data : null;
3115
- if (result == null || !("tree" in result.ochre)) throw new Error("Failed to fetch website");
3116
- const projectIdentification = result.ochre.metadata.project?.identification ? parseIdentification(result.ochre.metadata.project.identification) : null;
3117
- return [null, parseWebsite(result.ochre.tree, projectIdentification?.label ?? "", result.ochre.metadata.project?.identification.website ?? null)];
3127
+ const customFetch = options?.customFetch;
3128
+ const isVersion2 = options?.isVersion2 ?? false;
3129
+ const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
3130
+ let metadata = null;
3131
+ let tree = null;
3132
+ if (V2_ABBREVIATIONS.has(cleanAbbreviation) || isVersion2) {
3133
+ 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
+ if (!response.ok) throw new Error("Failed to fetch website");
3135
+ const data = await response.json();
3136
+ if (Array.isArray(data.result) || !("tree" in data.result.ochre)) throw new Error("Failed to fetch website");
3137
+ metadata = data.result.ochre.metadata;
3138
+ tree = data.result.ochre.tree;
3139
+ } else {
3140
+ const uuid = KNOWN_ABBREVIATIONS[cleanAbbreviation];
3141
+ const response = await (customFetch ?? fetch)(uuid != null ? `https://ochre.lib.uchicago.edu/ochre?uuid=${uuid}&format=json` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${cleanAbbreviation}']] return $q`)}&format=json`);
3142
+ if (!response.ok) throw new Error("Failed to fetch website");
3143
+ const data = await response.json();
3144
+ const result = "result" in data && !Array.isArray(data.result) ? data.result : !("result" in data) ? data : null;
3145
+ if (result == null || !("tree" in result.ochre)) throw new Error("Failed to fetch website");
3146
+ metadata = result.ochre.metadata;
3147
+ tree = result.ochre.tree;
3148
+ }
3149
+ const projectIdentification = metadata.project?.identification ? parseIdentification(metadata.project.identification) : null;
3150
+ return [null, parseWebsite(tree, projectIdentification?.label ?? "", metadata.project?.identification.website ?? null, { isVersion2: true })];
3118
3151
  } catch (error) {
3119
3152
  console.error(error);
3120
3153
  return [error instanceof Error ? error.message : "Unknown error", null];
3121
3154
  }
3122
3155
  }
3156
+ const [_, website] = await fetchWebsite("bengali-song");
3157
+ writeFileSync("website.json", JSON.stringify(website, null, 2));
3123
3158
 
3124
3159
  //#endregion
3125
3160
  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.11.28",
3
+ "version": "0.12.1",
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",
@@ -49,9 +49,9 @@
49
49
  "eslint": "^9.39.1",
50
50
  "prettier": "^3.6.2",
51
51
  "terser": "^5.44.1",
52
- "tsdown": "^0.16.0",
52
+ "tsdown": "^0.16.1",
53
53
  "typescript": "^5.9.3",
54
- "vitest": "^4.0.7"
54
+ "vitest": "^4.0.8"
55
55
  },
56
56
  "scripts": {
57
57
  "dev": "tsdown src/index.ts --watch",