@fedify/vocab-tools 2.4.0-dev.2054 → 2.4.0-dev.2063

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.4.0-dev.2054+1756e190",
3
+ "version": "2.4.0-dev.2063+366c0362",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts"
package/dist/mod.cjs CHANGED
@@ -8,7 +8,7 @@ let yaml = require("yaml");
8
8
  let es_toolkit = require("es-toolkit");
9
9
  //#region deno.json
10
10
  var name = "@fedify/vocab-tools";
11
- var version = "2.4.0-dev.2054+1756e190";
11
+ var version = "2.4.0-dev.2063+366c0362";
12
12
  //#endregion
13
13
  //#region src/type.ts
14
14
  const HEURISTICS_CONTEXTS = [
@@ -1425,6 +1425,7 @@ async function* generateCloner(typeUri, types) {
1425
1425
  { id: values.id ?? this.id },
1426
1426
  options
1427
1427
  );
1428
+ copyPortableProvenance(this, clone);
1428
1429
  `;
1429
1430
  else yield `const clone = super.clone(values, options) as unknown as ${type.name};`;
1430
1431
  for (const property of type.properties) {
@@ -1680,6 +1681,10 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1680
1681
  tracerProvider,
1681
1682
  gateways: options.gateways,
1682
1683
  verifyPortableObject: options.verifyPortableObject,
1684
+ referrer: {
1685
+ object: this,
1686
+ property: ${JSON.stringify(property.uri)},
1687
+ },
1683
1688
  suppressError: options.suppressError,
1684
1689
  crossOrigin: options.crossOrigin,
1685
1690
  span,
@@ -1711,6 +1716,11 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1711
1716
  }
1712
1717
  }
1713
1718
  const lookupUrl = formatIri(url);
1719
+ const inPortableChain = isInPortableChain(this);
1720
+ if (inPortableChain && isCompatibleEf61Iri(url)) {
1721
+ span.end();
1722
+ return rejectPortableChainReference(lookupUrl, options.crossOrigin);
1723
+ }
1714
1724
  let fetchResult: RemoteDocument;
1715
1725
  try {
1716
1726
  fetchResult = await documentLoader(lookupUrl);
@@ -1736,6 +1746,17 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1736
1746
  document,
1737
1747
  { documentLoader, contextLoader, tracerProvider, baseUrl }
1738
1748
  );
1749
+ if (
1750
+ inPortableChain &&
1751
+ (isCompatibleEf61Iri(documentUrl) ||
1752
+ (obj.id != null &&
1753
+ (isPortableIri(obj.id) || isCompatibleEf61Iri(obj.id))))
1754
+ ) {
1755
+ return rejectPortableChainReference(
1756
+ documentUrl,
1757
+ options.crossOrigin,
1758
+ );
1759
+ }
1739
1760
  if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) {
1740
1761
  if (options.crossOrigin === "throw") {
1741
1762
  throw new Error(
@@ -1888,10 +1909,19 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1888
1909
  if (this.${await getFieldName(property.uri)}.length < 1) return null;
1889
1910
  let v = this.${await getFieldName(property.uri)}[0];
1890
1911
  if (!(v instanceof URL) &&
1891
- v.id != null &&
1892
- !isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
1893
1912
  !this.${await getFieldName(property.uri, "#_trust")}.has(0)) {
1894
- v = v.id;
1913
+ if (v.id == null) {
1914
+ if (isUnsecuredPortableObject(this)) {
1915
+ warnUnverifiableEmbeddedObject(this, ${JSON.stringify(property.uri)});
1916
+ return null;
1917
+ }
1918
+ } else if (
1919
+ !isTrustedIriOrigin(options, v.id, ${trustOwner}) ||
1920
+ isUnsecuredPortableObject(this) ||
1921
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))
1922
+ ) {
1923
+ v = v.id;
1924
+ }
1895
1925
  }
1896
1926
  if (v instanceof URL) {
1897
1927
  const fetched =
@@ -1900,6 +1930,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1900
1930
  this.${await getFieldName(property.uri)}[0] = fetched;
1901
1931
  this.${await getFieldName(property.uri, "#_trust")}.add(0);
1902
1932
  this._cachedJsonLd = undefined;
1933
+ recordPortableReferrer(this, fetched, ${JSON.stringify(property.uri)});
1903
1934
  return fetched;
1904
1935
  }
1905
1936
  `;
@@ -1929,12 +1960,14 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1929
1960
  }
1930
1961
  yield `
1931
1962
  if (v?.id != null &&
1932
- ${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
1963
+ ((${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner})) ||
1964
+ isUnsecuredPortableObject(this) ||
1965
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))) &&
1933
1966
  !this.${await getFieldName(property.uri, "#_trust")}.has(0)) {
1934
1967
  if (options.crossOrigin === "throw") {
1935
1968
  throw new Error(
1936
1969
  "The property object's @id (" + v.id.href + ") has a different " +
1937
- "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} + "); " +
1970
+ "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} + "); " +
1938
1971
  "refusing to return the object. If you want to bypass this " +
1939
1972
  "check and are aware of the security implications, set the " +
1940
1973
  'crossOrigin option to "trust".'
@@ -1946,10 +1979,11 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1946
1979
  "return the object. If you want to bypass this check and are " +
1947
1980
  "aware of the security implications, set the crossOrigin option " +
1948
1981
  'to "trust".',
1949
- { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} },
1982
+ { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} },
1950
1983
  );
1951
1984
  return null;
1952
1985
  }
1986
+ recordPortableReferrer(this, v, ${JSON.stringify(property.uri)});
1953
1987
  return v;
1954
1988
  }
1955
1989
  `;
@@ -1996,10 +2030,19 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1996
2030
  for (let i = 0; i < vs.length; i++) {
1997
2031
  let v = vs[i];
1998
2032
  if (!(v instanceof URL) &&
1999
- v.id != null &&
2000
- !isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
2001
2033
  !this.${await getFieldName(property.uri, "#_trust")}.has(i)) {
2002
- v = v.id;
2034
+ if (v.id == null) {
2035
+ if (isUnsecuredPortableObject(this)) {
2036
+ warnUnverifiableEmbeddedObject(this, ${JSON.stringify(property.uri)});
2037
+ continue;
2038
+ }
2039
+ } else if (
2040
+ !isTrustedIriOrigin(options, v.id, ${trustOwner}) ||
2041
+ isUnsecuredPortableObject(this) ||
2042
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))
2043
+ ) {
2044
+ v = v.id;
2045
+ }
2003
2046
  }
2004
2047
  if (v instanceof URL) {
2005
2048
  const fetched =
@@ -2008,6 +2051,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
2008
2051
  vs[i] = fetched;
2009
2052
  this.${await getFieldName(property.uri, "#_trust")}.add(i);
2010
2053
  this._cachedJsonLd = undefined;
2054
+ recordPortableReferrer(this, fetched, ${JSON.stringify(property.uri)});
2011
2055
  yield fetched;
2012
2056
  continue;
2013
2057
  }
@@ -2038,12 +2082,14 @@ async function* generateProperty(type, property, types, moduleVarNames) {
2038
2082
  }
2039
2083
  yield `
2040
2084
  if (v?.id != null &&
2041
- ${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
2085
+ ((${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner})) ||
2086
+ isUnsecuredPortableObject(this) ||
2087
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))) &&
2042
2088
  !this.${await getFieldName(property.uri, "#_trust")}.has(i)) {
2043
2089
  if (options.crossOrigin === "throw") {
2044
2090
  throw new Error(
2045
2091
  "The property object's @id (" + v.id.href + ") has a different " +
2046
- "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} + "); " +
2092
+ "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} + "); " +
2047
2093
  "refusing to return the object. If you want to bypass this " +
2048
2094
  "check and are aware of the security implications, set the " +
2049
2095
  'crossOrigin option to "trust".'
@@ -2055,10 +2101,11 @@ async function* generateProperty(type, property, types, moduleVarNames) {
2055
2101
  "return the object. If you want to bypass this check and are " +
2056
2102
  "aware of the security implications, set the crossOrigin " +
2057
2103
  'option to "trust".',
2058
- { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} },
2104
+ { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} },
2059
2105
  );
2060
2106
  continue;
2061
2107
  }
2108
+ recordPortableReferrer(this, v, ${JSON.stringify(property.uri)});
2062
2109
  yield v;
2063
2110
  }
2064
2111
  }
@@ -2080,7 +2127,17 @@ const INTERNAL_RUNTIME_IMPORTS = [
2080
2127
  "isTrustedIriOrigin",
2081
2128
  "normalizeJsonLdIris"
2082
2129
  ].join(",\n ");
2083
- const PORTABLE_DEREFERENCE_IMPORTS = ["dereferencePortableIri", "isPortableIri"].join(",\n ");
2130
+ const PORTABLE_DEREFERENCE_IMPORTS = [
2131
+ "copyPortableProvenance",
2132
+ "dereferencePortableIri",
2133
+ "isCompatibleEf61Iri",
2134
+ "isInPortableChain",
2135
+ "isPortableIri",
2136
+ "isUnsecuredPortableObject",
2137
+ "recordPortableReferrer",
2138
+ "rejectPortableChainReference",
2139
+ "warnUnverifiableEmbeddedObject"
2140
+ ].join(",\n ");
2084
2141
  const SIGNED_REPRESENTATION_IMPORTS = [
2085
2142
  "enterSignedValueScope",
2086
2143
  "resolveSignedValues",
package/dist/mod.js CHANGED
@@ -7,7 +7,7 @@ import { parse } from "yaml";
7
7
  import { pascalCase } from "es-toolkit";
8
8
  //#region deno.json
9
9
  var name = "@fedify/vocab-tools";
10
- var version = "2.4.0-dev.2054+1756e190";
10
+ var version = "2.4.0-dev.2063+366c0362";
11
11
  //#endregion
12
12
  //#region src/type.ts
13
13
  const HEURISTICS_CONTEXTS = [
@@ -1424,6 +1424,7 @@ async function* generateCloner(typeUri, types) {
1424
1424
  { id: values.id ?? this.id },
1425
1425
  options
1426
1426
  );
1427
+ copyPortableProvenance(this, clone);
1427
1428
  `;
1428
1429
  else yield `const clone = super.clone(values, options) as unknown as ${type.name};`;
1429
1430
  for (const property of type.properties) {
@@ -1679,6 +1680,10 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1679
1680
  tracerProvider,
1680
1681
  gateways: options.gateways,
1681
1682
  verifyPortableObject: options.verifyPortableObject,
1683
+ referrer: {
1684
+ object: this,
1685
+ property: ${JSON.stringify(property.uri)},
1686
+ },
1682
1687
  suppressError: options.suppressError,
1683
1688
  crossOrigin: options.crossOrigin,
1684
1689
  span,
@@ -1710,6 +1715,11 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1710
1715
  }
1711
1716
  }
1712
1717
  const lookupUrl = formatIri(url);
1718
+ const inPortableChain = isInPortableChain(this);
1719
+ if (inPortableChain && isCompatibleEf61Iri(url)) {
1720
+ span.end();
1721
+ return rejectPortableChainReference(lookupUrl, options.crossOrigin);
1722
+ }
1713
1723
  let fetchResult: RemoteDocument;
1714
1724
  try {
1715
1725
  fetchResult = await documentLoader(lookupUrl);
@@ -1735,6 +1745,17 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1735
1745
  document,
1736
1746
  { documentLoader, contextLoader, tracerProvider, baseUrl }
1737
1747
  );
1748
+ if (
1749
+ inPortableChain &&
1750
+ (isCompatibleEf61Iri(documentUrl) ||
1751
+ (obj.id != null &&
1752
+ (isPortableIri(obj.id) || isCompatibleEf61Iri(obj.id))))
1753
+ ) {
1754
+ return rejectPortableChainReference(
1755
+ documentUrl,
1756
+ options.crossOrigin,
1757
+ );
1758
+ }
1738
1759
  if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) {
1739
1760
  if (options.crossOrigin === "throw") {
1740
1761
  throw new Error(
@@ -1887,10 +1908,19 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1887
1908
  if (this.${await getFieldName(property.uri)}.length < 1) return null;
1888
1909
  let v = this.${await getFieldName(property.uri)}[0];
1889
1910
  if (!(v instanceof URL) &&
1890
- v.id != null &&
1891
- !isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
1892
1911
  !this.${await getFieldName(property.uri, "#_trust")}.has(0)) {
1893
- v = v.id;
1912
+ if (v.id == null) {
1913
+ if (isUnsecuredPortableObject(this)) {
1914
+ warnUnverifiableEmbeddedObject(this, ${JSON.stringify(property.uri)});
1915
+ return null;
1916
+ }
1917
+ } else if (
1918
+ !isTrustedIriOrigin(options, v.id, ${trustOwner}) ||
1919
+ isUnsecuredPortableObject(this) ||
1920
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))
1921
+ ) {
1922
+ v = v.id;
1923
+ }
1894
1924
  }
1895
1925
  if (v instanceof URL) {
1896
1926
  const fetched =
@@ -1899,6 +1929,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1899
1929
  this.${await getFieldName(property.uri)}[0] = fetched;
1900
1930
  this.${await getFieldName(property.uri, "#_trust")}.add(0);
1901
1931
  this._cachedJsonLd = undefined;
1932
+ recordPortableReferrer(this, fetched, ${JSON.stringify(property.uri)});
1902
1933
  return fetched;
1903
1934
  }
1904
1935
  `;
@@ -1928,12 +1959,14 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1928
1959
  }
1929
1960
  yield `
1930
1961
  if (v?.id != null &&
1931
- ${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
1962
+ ((${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner})) ||
1963
+ isUnsecuredPortableObject(this) ||
1964
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))) &&
1932
1965
  !this.${await getFieldName(property.uri, "#_trust")}.has(0)) {
1933
1966
  if (options.crossOrigin === "throw") {
1934
1967
  throw new Error(
1935
1968
  "The property object's @id (" + v.id.href + ") has a different " +
1936
- "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} + "); " +
1969
+ "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} + "); " +
1937
1970
  "refusing to return the object. If you want to bypass this " +
1938
1971
  "check and are aware of the security implications, set the " +
1939
1972
  'crossOrigin option to "trust".'
@@ -1945,10 +1978,11 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1945
1978
  "return the object. If you want to bypass this check and are " +
1946
1979
  "aware of the security implications, set the crossOrigin option " +
1947
1980
  'to "trust".',
1948
- { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} },
1981
+ { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} },
1949
1982
  );
1950
1983
  return null;
1951
1984
  }
1985
+ recordPortableReferrer(this, v, ${JSON.stringify(property.uri)});
1952
1986
  return v;
1953
1987
  }
1954
1988
  `;
@@ -1995,10 +2029,19 @@ async function* generateProperty(type, property, types, moduleVarNames) {
1995
2029
  for (let i = 0; i < vs.length; i++) {
1996
2030
  let v = vs[i];
1997
2031
  if (!(v instanceof URL) &&
1998
- v.id != null &&
1999
- !isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
2000
2032
  !this.${await getFieldName(property.uri, "#_trust")}.has(i)) {
2001
- v = v.id;
2033
+ if (v.id == null) {
2034
+ if (isUnsecuredPortableObject(this)) {
2035
+ warnUnverifiableEmbeddedObject(this, ${JSON.stringify(property.uri)});
2036
+ continue;
2037
+ }
2038
+ } else if (
2039
+ !isTrustedIriOrigin(options, v.id, ${trustOwner}) ||
2040
+ isUnsecuredPortableObject(this) ||
2041
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))
2042
+ ) {
2043
+ v = v.id;
2044
+ }
2002
2045
  }
2003
2046
  if (v instanceof URL) {
2004
2047
  const fetched =
@@ -2007,6 +2050,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
2007
2050
  vs[i] = fetched;
2008
2051
  this.${await getFieldName(property.uri, "#_trust")}.add(i);
2009
2052
  this._cachedJsonLd = undefined;
2053
+ recordPortableReferrer(this, fetched, ${JSON.stringify(property.uri)});
2010
2054
  yield fetched;
2011
2055
  continue;
2012
2056
  }
@@ -2037,12 +2081,14 @@ async function* generateProperty(type, property, types, moduleVarNames) {
2037
2081
  }
2038
2082
  yield `
2039
2083
  if (v?.id != null &&
2040
- ${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner}) &&
2084
+ ((${type.trustEmbeddedObjects === false ? "" : "this.id != null && "}!isTrustedIriOrigin(options, v.id, ${trustOwner})) ||
2085
+ isUnsecuredPortableObject(this) ||
2086
+ (isInPortableChain(this) && isCompatibleEf61Iri(v.id))) &&
2041
2087
  !this.${await getFieldName(property.uri, "#_trust")}.has(i)) {
2042
2088
  if (options.crossOrigin === "throw") {
2043
2089
  throw new Error(
2044
2090
  "The property object's @id (" + v.id.href + ") has a different " +
2045
- "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} + "); " +
2091
+ "origin than the property owner's @id (" + ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} + "); " +
2046
2092
  "refusing to return the object. If you want to bypass this " +
2047
2093
  "check and are aware of the security implications, set the " +
2048
2094
  'crossOrigin option to "trust".'
@@ -2054,10 +2100,11 @@ async function* generateProperty(type, property, types, moduleVarNames) {
2054
2100
  "return the object. If you want to bypass this check and are " +
2055
2101
  "aware of the security implications, set the crossOrigin " +
2056
2102
  'option to "trust".',
2057
- { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "this.id.href"} },
2103
+ { objectId: v.id.href, parentObjectId: ${type.trustEmbeddedObjects === false ? "\"untrusted metadata\"" : "(this.id?.href ?? null)"} },
2058
2104
  );
2059
2105
  continue;
2060
2106
  }
2107
+ recordPortableReferrer(this, v, ${JSON.stringify(property.uri)});
2061
2108
  yield v;
2062
2109
  }
2063
2110
  }
@@ -2079,7 +2126,17 @@ const INTERNAL_RUNTIME_IMPORTS = [
2079
2126
  "isTrustedIriOrigin",
2080
2127
  "normalizeJsonLdIris"
2081
2128
  ].join(",\n ");
2082
- const PORTABLE_DEREFERENCE_IMPORTS = ["dereferencePortableIri", "isPortableIri"].join(",\n ");
2129
+ const PORTABLE_DEREFERENCE_IMPORTS = [
2130
+ "copyPortableProvenance",
2131
+ "dereferencePortableIri",
2132
+ "isCompatibleEf61Iri",
2133
+ "isInPortableChain",
2134
+ "isPortableIri",
2135
+ "isUnsecuredPortableObject",
2136
+ "recordPortableReferrer",
2137
+ "rejectPortableChainReference",
2138
+ "warnUnverifiableEmbeddedObject"
2139
+ ].join(",\n ");
2083
2140
  const SIGNED_REPRESENTATION_IMPORTS = [
2084
2141
  "enterSignedValueScope",
2085
2142
  "resolveSignedValues",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.4.0-dev.2054+1756e190",
3
+ "version": "2.4.0-dev.2063+366c0362",
4
4
  "description": "Code generator for Activity Vocabulary APIs",
5
5
  "homepage": "https://fedify.dev/",
6
6
  "repository": {