ochre-sdk 0.20.10 → 0.20.11

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.
Files changed (2) hide show
  1. package/dist/index.mjs +23 -14
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -28,6 +28,15 @@ function getStringItemByLanguage(content, language) {
28
28
  return content.find((item) => item.lang === language) ?? null;
29
29
  }
30
30
  /**
31
+ * Transforms a permanent identification URL to a OCHRE API URL
32
+ *
33
+ * @param url - The permanent identification URL to transform
34
+ * @returns The OCHRE API URL
35
+ */
36
+ function transformPermanentIdentificationUrl(url) {
37
+ return url.replace("https://pi.lib.uchicago.edu/1001/org/ochre/", "https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=");
38
+ }
39
+ /**
31
40
  * Parses email addresses in a string into HTML links
32
41
  *
33
42
  * @param string - Input string to parse
@@ -37,7 +46,7 @@ function parseEmail(string) {
37
46
  const splitString = string.split(" ");
38
47
  const returnSplitString = [];
39
48
  for (const string of splitString) {
40
- const cleanString = string.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g, "").replaceAll(/[!),:;?\]]/g, "").replace(/\.$/, "");
49
+ const cleanString = transformPermanentIdentificationUrl(string).replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g, "").replaceAll(/[!),:;?\]]/g, "").replace(/\.$/, "");
41
50
  const index = string.indexOf(cleanString);
42
51
  const before = string.slice(0, index);
43
52
  const after = string.slice(index + cleanString.length);
@@ -321,9 +330,9 @@ function parseStringDocumentItem(item) {
321
330
  }
322
331
  return applyWhitespaceToResult(linkElement, itemWhitespace);
323
332
  }
324
- case "externalDocument": if (linkResource.publicationDateTime != null) return applyWhitespaceToResult(String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre?uuid=${linkResource.uuid}&load" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`, itemWhitespace);
333
+ case "externalDocument": if (linkResource.publicationDateTime != null) return applyWhitespaceToResult(String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${linkResource.uuid}&load" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`, itemWhitespace);
325
334
  else return applyWhitespaceToResult(`<TooltipSpan${linkContent !== null ? ` content="${linkContent}"` : ""}>${itemString}</TooltipSpan>`, itemWhitespace);
326
- case "webpage": return applyWhitespaceToResult(`<ExternalLink href="${linkResource.href}" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`, itemWhitespace);
335
+ case "webpage": return applyWhitespaceToResult(`<ExternalLink href="${linkResource.href != null ? transformPermanentIdentificationUrl(linkResource.href) : "#"}" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`, itemWhitespace);
327
336
  default: return "";
328
337
  }
329
338
  } else if ("spatialUnit" in link) {
@@ -1075,7 +1084,7 @@ function parseLink(linkRaw) {
1075
1084
  const returnLink = {
1076
1085
  category: categoryKey,
1077
1086
  content: "content" in link && link.content != null ? parseFakeString(link.content) : null,
1078
- href: "href" in link && link.href != null ? link.href : null,
1087
+ href: "href" in link && link.href != null ? transformPermanentIdentificationUrl(link.href) : null,
1079
1088
  fileFormat: "fileFormat" in link && link.fileFormat != null ? link.fileFormat : null,
1080
1089
  fileSize: "fileSize" in link && link.fileSize != null ? link.fileSize : null,
1081
1090
  uuid: link.uuid ?? null,
@@ -1132,9 +1141,9 @@ function parseImage(image) {
1132
1141
  return {
1133
1142
  publicationDateTime: parseOptionalDate(image.publicationDateTime),
1134
1143
  identification: image.identification ? parseIdentification(image.identification) : null,
1135
- url: image.href ?? (image.htmlImgSrcPrefix == null && image.content != null ? parseFakeString(image.content) : null),
1144
+ url: image.href != null ? transformPermanentIdentificationUrl(image.href) : image.htmlImgSrcPrefix == null && image.content != null ? transformPermanentIdentificationUrl(parseFakeString(image.content)) : null,
1136
1145
  htmlPrefix: image.htmlImgSrcPrefix ?? null,
1137
- content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null,
1146
+ content: image.htmlImgSrcPrefix != null && image.content != null ? transformPermanentIdentificationUrl(parseFakeString(image.content)) : null,
1138
1147
  widthPreview: image.widthPreview ?? null,
1139
1148
  heightPreview: image.heightPreview ?? null,
1140
1149
  width: image.width ?? null,
@@ -1369,7 +1378,7 @@ function parseProperty(property, language = "eng") {
1369
1378
  height: value.height ?? null,
1370
1379
  width: value.width ?? null,
1371
1380
  fileSize: value.fileSize ?? null,
1372
- href: value.href ?? null,
1381
+ href: value.href != null ? transformPermanentIdentificationUrl(value.href) : null,
1373
1382
  slug: value.slug ?? null
1374
1383
  };
1375
1384
  }
@@ -1471,7 +1480,7 @@ function parseBibliography(bibliography, metadata, persistentUrl, belongsTo) {
1471
1480
  publicationDateTime: parseISO(resource.publicationDateTime),
1472
1481
  type: resource.type,
1473
1482
  identification: parseIdentification(resource.identification),
1474
- href: resource.href ?? null
1483
+ href: resource.href != null ? transformPermanentIdentificationUrl(resource.href) : null
1475
1484
  })) : [];
1476
1485
  return {
1477
1486
  uuid: bibliography.uuid ?? null,
@@ -1850,7 +1859,7 @@ function parseResource(resource, metadata, persistentUrl, belongsTo) {
1850
1859
  description: resource.description ? parseFakeStringOrContent(resource.description) : "",
1851
1860
  coordinates: resource.coordinates ? parseCoordinates(resource.coordinates) : [],
1852
1861
  document: resource.document && "content" in resource.document ? parseDocument(resource.document.content) : null,
1853
- href: resource.href ?? null,
1862
+ href: resource.href != null ? transformPermanentIdentificationUrl(resource.href) : null,
1854
1863
  imageMap: resource.imagemap ? parseImageMap(resource.imagemap) : null,
1855
1864
  periods: resource.periods ? parsePeriods(ensureArray(resource.periods.period)) : [],
1856
1865
  links: resource.links ? parseLinks(ensureArray(resource.links)) : [],
@@ -2916,7 +2925,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2916
2925
  case "advanced-search": {
2917
2926
  const boundElementPropertyUuid = getPropertyByLabel(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
2918
2927
  const linkToProperty = getPropertyByLabel(componentProperty.properties, "link-to");
2919
- const href = linkToProperty?.values[0]?.href ?? linkToProperty?.values[0]?.slug ?? null;
2928
+ const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
2920
2929
  if (boundElementPropertyUuid == null && href == null) throw new Error(`Bound element or href not found for the following component: “${componentName}”`);
2921
2930
  properties = {
2922
2931
  component: "advanced-search",
@@ -2995,10 +3004,10 @@ function parseWebElementProperties(componentProperty, elementResource) {
2995
3004
  variant ??= "default";
2996
3005
  let isExternal = false;
2997
3006
  const navigateToProperty = getPropertyByLabel(componentProperty.properties, "navigate-to");
2998
- let href = navigateToProperty?.values[0]?.href ?? navigateToProperty?.values[0]?.slug ?? null;
3007
+ let href = navigateToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(navigateToProperty.values[0].href) : navigateToProperty?.values[0]?.slug ?? null;
2999
3008
  if (href === null) {
3000
3009
  const linkToProperty = getPropertyByLabel(componentProperty.properties, "link-to");
3001
- href = linkToProperty?.values[0]?.href ?? linkToProperty?.values[0]?.slug ?? null;
3010
+ href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
3002
3011
  if (href === null) throw new Error(`Properties “navigate-to” or “link-to” not found for the following component: “${componentName}”`);
3003
3012
  else isExternal = true;
3004
3013
  }
@@ -3139,7 +3148,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
3139
3148
  const width = getPropertyValueByLabel(componentProperty.properties, "width");
3140
3149
  properties = {
3141
3150
  component: "iframe",
3142
- href,
3151
+ href: transformPermanentIdentificationUrl(href),
3143
3152
  height: height?.toString() ?? null,
3144
3153
  width: width?.toString() ?? null
3145
3154
  };
@@ -3370,7 +3379,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
3370
3379
  queryVariant ??= "submit";
3371
3380
  const boundElementUuid = getPropertyByLabel(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
3372
3381
  const linkToProperty = getPropertyByLabel(componentProperty.properties, "link-to");
3373
- const href = linkToProperty?.values[0]?.href ?? linkToProperty?.values[0]?.slug ?? null;
3382
+ const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
3374
3383
  if (!boundElementUuid && !href) throw new Error(`Bound element or href not found for the following component: “${componentName}”`);
3375
3384
  let placeholder = getPropertyValueByLabel(componentProperty.properties, "placeholder-text");
3376
3385
  placeholder ??= null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.20.10",
3
+ "version": "0.20.11",
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",