ochre-sdk 0.20.10 → 0.20.12

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 +32 -34
  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) {
@@ -823,26 +832,15 @@ const setQuerySchema = z.union([
823
832
  ]);
824
833
  const setQueriesSchema = z.array(setQuerySchema).default([]);
825
834
  function validateSetQueriesOperators(queries, ctx) {
826
- for (const [index, query] of queries.entries()) {
827
- if (index === 0 && query.operator != null) ctx.addIssue({
828
- code: "custom",
829
- path: [
830
- "queries",
831
- index,
832
- "operator"
833
- ],
834
- message: "The first query rule must not include an operator"
835
- });
836
- if (index > 0 && query.operator == null) ctx.addIssue({
837
- code: "custom",
838
- path: [
839
- "queries",
840
- index,
841
- "operator"
842
- ],
843
- message: "Query rules after the first must include an operator"
844
- });
845
- }
835
+ for (const [index, query] of queries.entries()) if (index > 0 && query.operator == null) ctx.addIssue({
836
+ code: "custom",
837
+ path: [
838
+ "queries",
839
+ index,
840
+ "operator"
841
+ ],
842
+ message: "Query rules after the first must include an operator"
843
+ });
846
844
  }
847
845
  /**
848
846
  * Schema for validating the parameters for the Set property values by property variables fetching function
@@ -1075,7 +1073,7 @@ function parseLink(linkRaw) {
1075
1073
  const returnLink = {
1076
1074
  category: categoryKey,
1077
1075
  content: "content" in link && link.content != null ? parseFakeString(link.content) : null,
1078
- href: "href" in link && link.href != null ? link.href : null,
1076
+ href: "href" in link && link.href != null ? transformPermanentIdentificationUrl(link.href) : null,
1079
1077
  fileFormat: "fileFormat" in link && link.fileFormat != null ? link.fileFormat : null,
1080
1078
  fileSize: "fileSize" in link && link.fileSize != null ? link.fileSize : null,
1081
1079
  uuid: link.uuid ?? null,
@@ -1132,9 +1130,9 @@ function parseImage(image) {
1132
1130
  return {
1133
1131
  publicationDateTime: parseOptionalDate(image.publicationDateTime),
1134
1132
  identification: image.identification ? parseIdentification(image.identification) : null,
1135
- url: image.href ?? (image.htmlImgSrcPrefix == null && image.content != null ? parseFakeString(image.content) : null),
1133
+ url: image.href != null ? transformPermanentIdentificationUrl(image.href) : image.htmlImgSrcPrefix == null && image.content != null ? transformPermanentIdentificationUrl(parseFakeString(image.content)) : null,
1136
1134
  htmlPrefix: image.htmlImgSrcPrefix ?? null,
1137
- content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null,
1135
+ content: image.htmlImgSrcPrefix != null && image.content != null ? transformPermanentIdentificationUrl(parseFakeString(image.content)) : null,
1138
1136
  widthPreview: image.widthPreview ?? null,
1139
1137
  heightPreview: image.heightPreview ?? null,
1140
1138
  width: image.width ?? null,
@@ -1369,7 +1367,7 @@ function parseProperty(property, language = "eng") {
1369
1367
  height: value.height ?? null,
1370
1368
  width: value.width ?? null,
1371
1369
  fileSize: value.fileSize ?? null,
1372
- href: value.href ?? null,
1370
+ href: value.href != null ? transformPermanentIdentificationUrl(value.href) : null,
1373
1371
  slug: value.slug ?? null
1374
1372
  };
1375
1373
  }
@@ -1471,7 +1469,7 @@ function parseBibliography(bibliography, metadata, persistentUrl, belongsTo) {
1471
1469
  publicationDateTime: parseISO(resource.publicationDateTime),
1472
1470
  type: resource.type,
1473
1471
  identification: parseIdentification(resource.identification),
1474
- href: resource.href ?? null
1472
+ href: resource.href != null ? transformPermanentIdentificationUrl(resource.href) : null
1475
1473
  })) : [];
1476
1474
  return {
1477
1475
  uuid: bibliography.uuid ?? null,
@@ -1850,7 +1848,7 @@ function parseResource(resource, metadata, persistentUrl, belongsTo) {
1850
1848
  description: resource.description ? parseFakeStringOrContent(resource.description) : "",
1851
1849
  coordinates: resource.coordinates ? parseCoordinates(resource.coordinates) : [],
1852
1850
  document: resource.document && "content" in resource.document ? parseDocument(resource.document.content) : null,
1853
- href: resource.href ?? null,
1851
+ href: resource.href != null ? transformPermanentIdentificationUrl(resource.href) : null,
1854
1852
  imageMap: resource.imagemap ? parseImageMap(resource.imagemap) : null,
1855
1853
  periods: resource.periods ? parsePeriods(ensureArray(resource.periods.period)) : [],
1856
1854
  links: resource.links ? parseLinks(ensureArray(resource.links)) : [],
@@ -2916,7 +2914,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2916
2914
  case "advanced-search": {
2917
2915
  const boundElementPropertyUuid = getPropertyByLabel(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
2918
2916
  const linkToProperty = getPropertyByLabel(componentProperty.properties, "link-to");
2919
- const href = linkToProperty?.values[0]?.href ?? linkToProperty?.values[0]?.slug ?? null;
2917
+ const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
2920
2918
  if (boundElementPropertyUuid == null && href == null) throw new Error(`Bound element or href not found for the following component: “${componentName}”`);
2921
2919
  properties = {
2922
2920
  component: "advanced-search",
@@ -2995,10 +2993,10 @@ function parseWebElementProperties(componentProperty, elementResource) {
2995
2993
  variant ??= "default";
2996
2994
  let isExternal = false;
2997
2995
  const navigateToProperty = getPropertyByLabel(componentProperty.properties, "navigate-to");
2998
- let href = navigateToProperty?.values[0]?.href ?? navigateToProperty?.values[0]?.slug ?? null;
2996
+ let href = navigateToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(navigateToProperty.values[0].href) : navigateToProperty?.values[0]?.slug ?? null;
2999
2997
  if (href === null) {
3000
2998
  const linkToProperty = getPropertyByLabel(componentProperty.properties, "link-to");
3001
- href = linkToProperty?.values[0]?.href ?? linkToProperty?.values[0]?.slug ?? null;
2999
+ href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
3002
3000
  if (href === null) throw new Error(`Properties “navigate-to” or “link-to” not found for the following component: “${componentName}”`);
3003
3001
  else isExternal = true;
3004
3002
  }
@@ -3139,7 +3137,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
3139
3137
  const width = getPropertyValueByLabel(componentProperty.properties, "width");
3140
3138
  properties = {
3141
3139
  component: "iframe",
3142
- href,
3140
+ href: transformPermanentIdentificationUrl(href),
3143
3141
  height: height?.toString() ?? null,
3144
3142
  width: width?.toString() ?? null
3145
3143
  };
@@ -3370,7 +3368,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
3370
3368
  queryVariant ??= "submit";
3371
3369
  const boundElementUuid = getPropertyByLabel(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
3372
3370
  const linkToProperty = getPropertyByLabel(componentProperty.properties, "link-to");
3373
- const href = linkToProperty?.values[0]?.href ?? linkToProperty?.values[0]?.slug ?? null;
3371
+ const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
3374
3372
  if (!boundElementUuid && !href) throw new Error(`Bound element or href not found for the following component: “${componentName}”`);
3375
3373
  let placeholder = getPropertyValueByLabel(componentProperty.properties, "placeholder-text");
3376
3374
  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.12",
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",