@digitalculture/ochre-sdk 0.11.29 → 0.12.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.
- package/dist/index.d.mts +37 -31
- package/dist/index.mjs +96 -66
- package/package.json +3 -3
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;
|
|
@@ -915,7 +910,10 @@ declare function fetchGallery(uuid: string, filter: string, page: number, perPag
|
|
|
915
910
|
*
|
|
916
911
|
* If the fetch/parse fails, the returned object will have an `error` property.
|
|
917
912
|
*/
|
|
918
|
-
declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid: string, category?: T, setCategory?: T extends "set" ? U : never,
|
|
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<{
|
|
919
917
|
error: null;
|
|
920
918
|
metadata: Metadata;
|
|
921
919
|
belongsTo: {
|
|
@@ -938,7 +936,9 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
|
|
|
938
936
|
*
|
|
939
937
|
* @param scopeUuids - The scope UUIDs to filter by
|
|
940
938
|
* @param propertyUuids - The property UUIDs to query by
|
|
941
|
-
* @param
|
|
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
|
|
942
942
|
* @returns The parsed property query or null if the fetch/parse fails
|
|
943
943
|
*
|
|
944
944
|
* @example
|
|
@@ -955,7 +955,10 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
|
|
|
955
955
|
* The returned property query includes:
|
|
956
956
|
* - Property items
|
|
957
957
|
*/
|
|
958
|
-
declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<string>,
|
|
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<{
|
|
959
962
|
items: Array<PropertyQueryItem> | null;
|
|
960
963
|
error: null;
|
|
961
964
|
} | {
|
|
@@ -1015,7 +1018,10 @@ declare function fetchByUuidMetadata(uuid: string, customFetch?: (input: string
|
|
|
1015
1018
|
*
|
|
1016
1019
|
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
1017
1020
|
*/
|
|
1018
|
-
declare function fetchWebsite(abbreviation: string,
|
|
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]>;
|
|
1019
1025
|
//#endregion
|
|
1020
1026
|
//#region src/utils/getters.d.ts
|
|
1021
1027
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from "zod";
|
|
2
2
|
|
|
3
3
|
//#region src/schemas.ts
|
|
4
4
|
/**
|
|
@@ -1801,6 +1801,47 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1801
1801
|
filterSort ??= "default";
|
|
1802
1802
|
let layout = getPropertyValueByLabel(componentProperty.properties, "layout");
|
|
1803
1803
|
layout ??= "image-start";
|
|
1804
|
+
const options = {
|
|
1805
|
+
attributeFilters: {
|
|
1806
|
+
bibliographies: elementResource.options?.filterBibliography ?? false,
|
|
1807
|
+
periods: elementResource.options?.filterPeriods ?? false
|
|
1808
|
+
},
|
|
1809
|
+
scopes: elementResource.options?.scopes != null ? (Array.isArray(elementResource.options.scopes.scope) ? elementResource.options.scopes.scope : [elementResource.options.scopes.scope]).map((scope) => ({
|
|
1810
|
+
uuid: scope.uuid.content,
|
|
1811
|
+
type: scope.uuid.type,
|
|
1812
|
+
identification: parseIdentification(scope.identification)
|
|
1813
|
+
})) : [],
|
|
1814
|
+
contexts: {
|
|
1815
|
+
flatten: [],
|
|
1816
|
+
filter: [],
|
|
1817
|
+
sort: [],
|
|
1818
|
+
detail: [],
|
|
1819
|
+
download: [],
|
|
1820
|
+
label: [],
|
|
1821
|
+
suppress: [],
|
|
1822
|
+
prominent: []
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
if ("options" in elementResource && elementResource.options) {
|
|
1826
|
+
const flattenContextsRaw = elementResource.options.flattenContexts != null ? Array.isArray(elementResource.options.flattenContexts) ? elementResource.options.flattenContexts : [elementResource.options.flattenContexts] : [];
|
|
1827
|
+
const suppressContextsRaw = elementResource.options.suppressContexts != null ? Array.isArray(elementResource.options.suppressContexts) ? elementResource.options.suppressContexts : [elementResource.options.suppressContexts] : [];
|
|
1828
|
+
const filterContextsRaw = elementResource.options.filterContexts != null ? Array.isArray(elementResource.options.filterContexts) ? elementResource.options.filterContexts : [elementResource.options.filterContexts] : [];
|
|
1829
|
+
const sortContextsRaw = elementResource.options.sortContexts != null ? Array.isArray(elementResource.options.sortContexts) ? elementResource.options.sortContexts : [elementResource.options.sortContexts] : [];
|
|
1830
|
+
const detailContextsRaw = elementResource.options.detailContexts != null ? Array.isArray(elementResource.options.detailContexts) ? elementResource.options.detailContexts : [elementResource.options.detailContexts] : [];
|
|
1831
|
+
const downloadContextsRaw = elementResource.options.downloadContexts != null ? Array.isArray(elementResource.options.downloadContexts) ? elementResource.options.downloadContexts : [elementResource.options.downloadContexts] : [];
|
|
1832
|
+
const labelContextsRaw = elementResource.options.labelContexts != null ? Array.isArray(elementResource.options.labelContexts) ? elementResource.options.labelContexts : [elementResource.options.labelContexts] : [];
|
|
1833
|
+
const prominentContextsRaw = elementResource.options.prominentContexts != null ? Array.isArray(elementResource.options.prominentContexts) ? elementResource.options.prominentContexts : [elementResource.options.prominentContexts] : [];
|
|
1834
|
+
options.contexts = {
|
|
1835
|
+
flatten: parseContexts(flattenContextsRaw),
|
|
1836
|
+
filter: parseContexts(filterContextsRaw),
|
|
1837
|
+
sort: parseContexts(sortContextsRaw),
|
|
1838
|
+
detail: parseContexts(detailContextsRaw),
|
|
1839
|
+
download: parseContexts(downloadContextsRaw),
|
|
1840
|
+
label: parseContexts(labelContextsRaw),
|
|
1841
|
+
suppress: parseContexts(suppressContextsRaw),
|
|
1842
|
+
prominent: parseContexts(prominentContextsRaw)
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1804
1845
|
properties.collectionId = collectionLink.uuid;
|
|
1805
1846
|
properties.variant = variant;
|
|
1806
1847
|
properties.itemVariant = itemVariant;
|
|
@@ -1809,6 +1850,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1809
1850
|
properties.isFilterDisplayed = isFilterDisplayed;
|
|
1810
1851
|
properties.filterSort = filterSort;
|
|
1811
1852
|
properties.layout = layout;
|
|
1853
|
+
properties.options = options;
|
|
1812
1854
|
break;
|
|
1813
1855
|
}
|
|
1814
1856
|
case "empty-space": {
|
|
@@ -2627,45 +2669,16 @@ function parseContexts(contexts) {
|
|
|
2627
2669
|
}
|
|
2628
2670
|
return contextsParsed;
|
|
2629
2671
|
}
|
|
2630
|
-
function parseWebsite(websiteTree, projectName, website) {
|
|
2672
|
+
function parseWebsite(websiteTree, projectName, website, { isVersion2 = false } = {}) {
|
|
2631
2673
|
if (!websiteTree.properties) throw new Error("Website properties not found");
|
|
2632
2674
|
const properties = parseWebsiteProperties(Array.isArray(websiteTree.properties.property) ? websiteTree.properties.property : [websiteTree.properties.property]);
|
|
2633
2675
|
if (typeof websiteTree.items === "string" || !("resource" in websiteTree.items)) throw new Error("Website pages not found");
|
|
2634
2676
|
const resources = Array.isArray(websiteTree.items.resource) ? websiteTree.items.resource : [websiteTree.items.resource];
|
|
2635
2677
|
const pages = parseWebpages(resources);
|
|
2636
2678
|
const sidebar = parseSidebar(resources);
|
|
2637
|
-
let globalOptions = { contexts: {
|
|
2638
|
-
flatten: [],
|
|
2639
|
-
filter: [],
|
|
2640
|
-
sort: [],
|
|
2641
|
-
detail: [],
|
|
2642
|
-
download: [],
|
|
2643
|
-
label: [],
|
|
2644
|
-
suppress: [],
|
|
2645
|
-
prominent: []
|
|
2646
|
-
} };
|
|
2647
|
-
if (websiteTree.websiteOptions) {
|
|
2648
|
-
const flattenContextsRaw = websiteTree.websiteOptions.flattenContexts != null ? Array.isArray(websiteTree.websiteOptions.flattenContexts) ? websiteTree.websiteOptions.flattenContexts : [websiteTree.websiteOptions.flattenContexts] : [];
|
|
2649
|
-
const suppressContextsRaw = websiteTree.websiteOptions.suppressContexts != null ? Array.isArray(websiteTree.websiteOptions.suppressContexts) ? websiteTree.websiteOptions.suppressContexts : [websiteTree.websiteOptions.suppressContexts] : [];
|
|
2650
|
-
const filterContextsRaw = websiteTree.websiteOptions.filterContexts != null ? Array.isArray(websiteTree.websiteOptions.filterContexts) ? websiteTree.websiteOptions.filterContexts : [websiteTree.websiteOptions.filterContexts] : [];
|
|
2651
|
-
const sortContextsRaw = websiteTree.websiteOptions.sortContexts != null ? Array.isArray(websiteTree.websiteOptions.sortContexts) ? websiteTree.websiteOptions.sortContexts : [websiteTree.websiteOptions.sortContexts] : [];
|
|
2652
|
-
const detailContextsRaw = websiteTree.websiteOptions.detailContexts != null ? Array.isArray(websiteTree.websiteOptions.detailContexts) ? websiteTree.websiteOptions.detailContexts : [websiteTree.websiteOptions.detailContexts] : [];
|
|
2653
|
-
const downloadContextsRaw = websiteTree.websiteOptions.downloadContexts != null ? Array.isArray(websiteTree.websiteOptions.downloadContexts) ? websiteTree.websiteOptions.downloadContexts : [websiteTree.websiteOptions.downloadContexts] : [];
|
|
2654
|
-
const labelContextsRaw = websiteTree.websiteOptions.labelContexts != null ? Array.isArray(websiteTree.websiteOptions.labelContexts) ? websiteTree.websiteOptions.labelContexts : [websiteTree.websiteOptions.labelContexts] : [];
|
|
2655
|
-
const prominentContextsRaw = websiteTree.websiteOptions.prominentContexts != null ? Array.isArray(websiteTree.websiteOptions.prominentContexts) ? websiteTree.websiteOptions.prominentContexts : [websiteTree.websiteOptions.prominentContexts] : [];
|
|
2656
|
-
globalOptions = { contexts: {
|
|
2657
|
-
flatten: parseContexts(flattenContextsRaw),
|
|
2658
|
-
filter: parseContexts(filterContextsRaw),
|
|
2659
|
-
sort: parseContexts(sortContextsRaw),
|
|
2660
|
-
detail: parseContexts(detailContextsRaw),
|
|
2661
|
-
download: parseContexts(downloadContextsRaw),
|
|
2662
|
-
label: parseContexts(labelContextsRaw),
|
|
2663
|
-
suppress: parseContexts(suppressContextsRaw),
|
|
2664
|
-
prominent: parseContexts(prominentContextsRaw)
|
|
2665
|
-
} };
|
|
2666
|
-
}
|
|
2667
2679
|
return {
|
|
2668
2680
|
uuid: websiteTree.uuid,
|
|
2681
|
+
version: isVersion2 ? 2 : 1,
|
|
2669
2682
|
publicationDateTime: websiteTree.publicationDateTime ? new Date(websiteTree.publicationDateTime) : null,
|
|
2670
2683
|
identification: parseIdentification(websiteTree.identification),
|
|
2671
2684
|
project: {
|
|
@@ -2676,23 +2689,7 @@ function parseWebsite(websiteTree, projectName, website) {
|
|
|
2676
2689
|
license: parseLicense(websiteTree.availability),
|
|
2677
2690
|
sidebar,
|
|
2678
2691
|
pages,
|
|
2679
|
-
properties
|
|
2680
|
-
searchOptions: {
|
|
2681
|
-
filters: websiteTree.searchOptions?.filterUuids != null ? (Array.isArray(websiteTree.searchOptions.filterUuids.uuid) ? websiteTree.searchOptions.filterUuids.uuid : [websiteTree.searchOptions.filterUuids.uuid]).map((uuid) => ({
|
|
2682
|
-
uuid: uuid.content,
|
|
2683
|
-
type: uuid.type
|
|
2684
|
-
})) : [],
|
|
2685
|
-
attributeFilters: {
|
|
2686
|
-
bibliographies: websiteTree.searchOptions?.filterUuids?.filterBibliography ?? false,
|
|
2687
|
-
periods: websiteTree.searchOptions?.filterUuids?.filterPeriods ?? false
|
|
2688
|
-
},
|
|
2689
|
-
scopes: websiteTree.searchOptions?.scopes != null ? (Array.isArray(websiteTree.searchOptions.scopes.scope) ? websiteTree.searchOptions.scopes.scope : [websiteTree.searchOptions.scopes.scope]).map((scope) => ({
|
|
2690
|
-
uuid: scope.uuid.content,
|
|
2691
|
-
type: scope.uuid.type,
|
|
2692
|
-
identification: parseIdentification(scope.identification)
|
|
2693
|
-
})) : []
|
|
2694
|
-
},
|
|
2695
|
-
globalOptions
|
|
2692
|
+
properties
|
|
2696
2693
|
};
|
|
2697
2694
|
}
|
|
2698
2695
|
|
|
@@ -2783,10 +2780,12 @@ async function fetchGallery(uuid, filter, page, perPage, customFetch) {
|
|
|
2783
2780
|
*
|
|
2784
2781
|
* @internal
|
|
2785
2782
|
*/
|
|
2786
|
-
async function fetchByUuid(uuid,
|
|
2783
|
+
async function fetchByUuid(uuid, options) {
|
|
2787
2784
|
try {
|
|
2785
|
+
const customFetch = options?.customFetch;
|
|
2786
|
+
const isVersion2 = options?.isVersion2 ?? false;
|
|
2788
2787
|
const parsedUuid = uuidSchema.parse(uuid);
|
|
2789
|
-
const response = await (customFetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`);
|
|
2788
|
+
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="*"`);
|
|
2790
2789
|
if (!response.ok) throw new Error("Failed to fetch OCHRE data");
|
|
2791
2790
|
const dataRaw = await response.json();
|
|
2792
2791
|
if (!("ochre" in dataRaw)) throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
@@ -2831,9 +2830,13 @@ async function fetchByUuid(uuid, customFetch) {
|
|
|
2831
2830
|
*
|
|
2832
2831
|
* If the fetch/parse fails, the returned object will have an `error` property.
|
|
2833
2832
|
*/
|
|
2834
|
-
async function fetchItem(uuid, category, setCategory,
|
|
2833
|
+
async function fetchItem(uuid, category, setCategory, options) {
|
|
2835
2834
|
try {
|
|
2836
|
-
const
|
|
2835
|
+
const customFetch = options?.customFetch;
|
|
2836
|
+
const [error, data] = await fetchByUuid(uuid, {
|
|
2837
|
+
customFetch,
|
|
2838
|
+
isVersion2: options?.isVersion2 ?? false
|
|
2839
|
+
});
|
|
2837
2840
|
if (error !== null) throw new Error(error);
|
|
2838
2841
|
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
2839
2842
|
let item;
|
|
@@ -2897,11 +2900,17 @@ async function fetchItem(uuid, category, setCategory, customFetch) {
|
|
|
2897
2900
|
}
|
|
2898
2901
|
}
|
|
2899
2902
|
|
|
2903
|
+
//#endregion
|
|
2904
|
+
//#region src/constants.ts
|
|
2905
|
+
/**
|
|
2906
|
+
* The UUID of the `<unassigned>` property value in OCHRE
|
|
2907
|
+
*/
|
|
2908
|
+
const UNASSIGNED_UUID = "e28e29af-b663-c0ac-ceb6-11a688fca0dd";
|
|
2909
|
+
|
|
2900
2910
|
//#endregion
|
|
2901
2911
|
//#region src/utils/fetchers/property-query.ts
|
|
2902
2912
|
const PROJECT_SCOPE = "0c0aae37-7246-495b-9547-e25dbf5b99a3";
|
|
2903
2913
|
const BELONG_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
|
|
2904
|
-
const UNASSIGNED_UUID = "e28e29af-b663-c0ac-ceb6-11a688fca0dd";
|
|
2905
2914
|
/**
|
|
2906
2915
|
* Check if a string is a valid UUID
|
|
2907
2916
|
* @param value - The string to check
|
|
@@ -2955,7 +2964,9 @@ return <item>
|
|
|
2955
2964
|
*
|
|
2956
2965
|
* @param scopeUuids - The scope UUIDs to filter by
|
|
2957
2966
|
* @param propertyUuids - The property UUIDs to query by
|
|
2958
|
-
* @param
|
|
2967
|
+
* @param options - Options for the fetch
|
|
2968
|
+
* @param options.customFetch - A custom fetch function to use instead of the default fetch
|
|
2969
|
+
* @param options.isVersion2 - Whether to use the v2 API
|
|
2959
2970
|
* @returns The parsed property query or null if the fetch/parse fails
|
|
2960
2971
|
*
|
|
2961
2972
|
* @example
|
|
@@ -2972,10 +2983,12 @@ return <item>
|
|
|
2972
2983
|
* The returned property query includes:
|
|
2973
2984
|
* - Property items
|
|
2974
2985
|
*/
|
|
2975
|
-
async function fetchPropertyQuery(scopeUuids, propertyUuids,
|
|
2986
|
+
async function fetchPropertyQuery(scopeUuids, propertyUuids, options) {
|
|
2976
2987
|
try {
|
|
2988
|
+
const customFetch = options?.customFetch;
|
|
2989
|
+
const isVersion2 = options?.isVersion2 ?? false;
|
|
2977
2990
|
const xquery = buildXQuery(scopeUuids, propertyUuids);
|
|
2978
|
-
const response = await (customFetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json`);
|
|
2991
|
+
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="*"`);
|
|
2979
2992
|
if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
|
|
2980
2993
|
const data = await response.json();
|
|
2981
2994
|
const parsedResultRaw = responseSchema.parse(data);
|
|
@@ -3078,6 +3091,7 @@ const KNOWN_ABBREVIATIONS = {
|
|
|
3078
3091
|
ssmc: "8ff977dd-d440-40f5-ad93-8ad7e2d39e74",
|
|
3079
3092
|
"sosc-core-at-smart": "db26c953-9b2a-4691-a909-5e8726b531d7"
|
|
3080
3093
|
};
|
|
3094
|
+
const V2_ABBREVIATIONS = new Set(["bengali-song"]);
|
|
3081
3095
|
/**
|
|
3082
3096
|
* Fetches and parses a website configuration from the OCHRE API
|
|
3083
3097
|
*
|
|
@@ -3107,16 +3121,32 @@ const KNOWN_ABBREVIATIONS = {
|
|
|
3107
3121
|
*
|
|
3108
3122
|
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
3109
3123
|
*/
|
|
3110
|
-
async function fetchWebsite(abbreviation,
|
|
3124
|
+
async function fetchWebsite(abbreviation, options) {
|
|
3111
3125
|
try {
|
|
3112
|
-
const
|
|
3113
|
-
const
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
if (
|
|
3118
|
-
|
|
3119
|
-
|
|
3126
|
+
const customFetch = options?.customFetch;
|
|
3127
|
+
const isVersion2 = options?.isVersion2 ?? false;
|
|
3128
|
+
const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
|
|
3129
|
+
let metadata = null;
|
|
3130
|
+
let tree = null;
|
|
3131
|
+
if (V2_ABBREVIATIONS.has(cleanAbbreviation) || isVersion2) {
|
|
3132
|
+
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="*"`);
|
|
3133
|
+
if (!response.ok) throw new Error("Failed to fetch website");
|
|
3134
|
+
const data = await response.json();
|
|
3135
|
+
if (Array.isArray(data.result) || !("tree" in data.result.ochre)) throw new Error("Failed to fetch website");
|
|
3136
|
+
metadata = data.result.ochre.metadata;
|
|
3137
|
+
tree = data.result.ochre.tree;
|
|
3138
|
+
} else {
|
|
3139
|
+
const uuid = KNOWN_ABBREVIATIONS[cleanAbbreviation];
|
|
3140
|
+
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`);
|
|
3141
|
+
if (!response.ok) throw new Error("Failed to fetch website");
|
|
3142
|
+
const data = await response.json();
|
|
3143
|
+
const result = "result" in data && !Array.isArray(data.result) ? data.result : !("result" in data) ? data : null;
|
|
3144
|
+
if (result == null || !("tree" in result.ochre)) throw new Error("Failed to fetch website");
|
|
3145
|
+
metadata = result.ochre.metadata;
|
|
3146
|
+
tree = result.ochre.tree;
|
|
3147
|
+
}
|
|
3148
|
+
const projectIdentification = metadata.project?.identification ? parseIdentification(metadata.project.identification) : null;
|
|
3149
|
+
return [null, parseWebsite(tree, projectIdentification?.label ?? "", metadata.project?.identification.website ?? null, { isVersion2: true })];
|
|
3120
3150
|
} catch (error) {
|
|
3121
3151
|
console.error(error);
|
|
3122
3152
|
return [error instanceof Error ? error.message : "Unknown error", null];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalculture/ochre-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.2",
|
|
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.
|
|
52
|
+
"tsdown": "^0.16.1",
|
|
53
53
|
"typescript": "^5.9.3",
|
|
54
|
-
"vitest": "^4.0.
|
|
54
|
+
"vitest": "^4.0.8"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"dev": "tsdown src/index.ts --watch",
|