@dyne/interfacer-client 0.5.0 → 0.6.0

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.js CHANGED
@@ -717,13 +717,14 @@ var CREATE_PROJECT = gql`
717
717
  var CREATE_MACHINE_RESOURCE = gql`
718
718
  mutation createMachineResource(
719
719
  $agent: ID! $creationTime: DateTime! $process: ID! $resourceSpec: ID!
720
- $unitOne: ID! $name: String! $note: String $metadata: JSONObject
720
+ $unitOne: ID! $name: String! $note: String $metadata: JSONObject $tags: [URI!]
721
721
  ) {
722
722
  createEconomicEvent(
723
723
  event: {
724
724
  action: "produce" outputOf: $process provider: $agent receiver: $agent
725
725
  hasPointInTime: $creationTime resourceConformsTo: $resourceSpec
726
726
  resourceQuantity: { hasNumericalValue: 1 hasUnit: $unitOne } resourceMetadata: $metadata
727
+ resourceClassifiedAs: $tags
727
728
  }
728
729
  newInventoriedResource: { name: $name note: $note }
729
730
  ) {
@@ -1745,6 +1746,287 @@ function clearInstanceVariablesCache() {
1745
1746
  cachedVars = null;
1746
1747
  }
1747
1748
 
1749
+ // src/tagging/constants.ts
1750
+ var TAG_PREFIX = {
1751
+ USER: "tag",
1752
+ CATEGORY: "category",
1753
+ MACHINE: "machine",
1754
+ MATERIAL: "material",
1755
+ POWER_COMPAT: "powercompat",
1756
+ POWER_REQ: "powerreq",
1757
+ REPLICABILITY: "replicability",
1758
+ RECYCLABILITY: "recyclability",
1759
+ REPAIRABILITY: "repairability",
1760
+ ENV_ENERGY: "env-energy",
1761
+ ENV_CO2: "env-co2",
1762
+ SERVICE_TYPE: "servicetype",
1763
+ AVAILABILITY: "availability",
1764
+ LICENSE: "license",
1765
+ MANUFACTURABLE: "manufacturable",
1766
+ COMPLEXITY: "complexity"
1767
+ };
1768
+ var SYSTEM_TAG_PREFIXES = [
1769
+ TAG_PREFIX.CATEGORY,
1770
+ TAG_PREFIX.MACHINE,
1771
+ TAG_PREFIX.MATERIAL,
1772
+ TAG_PREFIX.POWER_COMPAT,
1773
+ TAG_PREFIX.POWER_REQ,
1774
+ TAG_PREFIX.REPLICABILITY,
1775
+ TAG_PREFIX.RECYCLABILITY,
1776
+ TAG_PREFIX.REPAIRABILITY,
1777
+ TAG_PREFIX.ENV_ENERGY,
1778
+ TAG_PREFIX.ENV_CO2,
1779
+ TAG_PREFIX.SERVICE_TYPE,
1780
+ TAG_PREFIX.AVAILABILITY,
1781
+ TAG_PREFIX.LICENSE,
1782
+ TAG_PREFIX.MANUFACTURABLE,
1783
+ TAG_PREFIX.COMPLEXITY
1784
+ ];
1785
+ var LEGACY_SYSTEM_TAG_PATTERNS = [
1786
+ "power_compat-",
1787
+ "power_",
1788
+ "env_",
1789
+ "mat:",
1790
+ "c:",
1791
+ "pc:",
1792
+ "env:",
1793
+ "pwr:",
1794
+ "rep:",
1795
+ "m:"
1796
+ ];
1797
+ var PRODUCT_CATEGORY_OPTIONS = [
1798
+ "Electronics",
1799
+ "Tools",
1800
+ "Furniture",
1801
+ "Home renovation",
1802
+ "Energy",
1803
+ "Wearables",
1804
+ "Medical",
1805
+ "Sustainability",
1806
+ "Education"
1807
+ ];
1808
+ var POWER_COMPATIBILITY_OPTIONS = [
1809
+ "120V AC",
1810
+ "220-240V AC",
1811
+ "12V DC",
1812
+ "24V DC",
1813
+ "Battery Powered",
1814
+ "USB-C"
1815
+ ];
1816
+ var REPLICABILITY_OPTIONS = ["High", "Medium", "Low"];
1817
+ var COMPLEXITY_OPTIONS = ["Beginner", "Intermediate", "Advanced"];
1818
+ var SERVICE_TYPE_OPTIONS = ["Fabrication", "Learning & Education", "Space Access"];
1819
+ var AVAILABILITY_OPTIONS = [
1820
+ "Available Now",
1821
+ "Booking Required",
1822
+ "Weekdays Only",
1823
+ "Weekends Available"
1824
+ ];
1825
+ var RECYCLABILITY_THRESHOLDS_PCT = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
1826
+ var POWER_REQUIREMENT_THRESHOLDS_W = [
1827
+ 0,
1828
+ 10,
1829
+ 25,
1830
+ 50,
1831
+ 75,
1832
+ 100,
1833
+ 150,
1834
+ 200,
1835
+ 250,
1836
+ 300,
1837
+ 500,
1838
+ 750,
1839
+ 1e3,
1840
+ 1500,
1841
+ 2e3
1842
+ ];
1843
+ var ENERGY_THRESHOLDS_KWH = [
1844
+ 0,
1845
+ 10,
1846
+ 20,
1847
+ 30,
1848
+ 50,
1849
+ 100,
1850
+ 200,
1851
+ 300,
1852
+ 500,
1853
+ 750,
1854
+ 1e3,
1855
+ 1500,
1856
+ 2e3
1857
+ ];
1858
+ var CO2_THRESHOLDS_KG = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 5, 7.5, 10, 15, 20];
1859
+ var REPAIRABILITY_AVAILABLE_TAG = "repairability-available";
1860
+ var MANUFACTURABLE_TRUE_TAG = "manufacturable-true";
1861
+
1862
+ // src/tagging/TaggingClient.ts
1863
+ function slugifyTagValue(value) {
1864
+ return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1865
+ }
1866
+ function prefixedTag(prefix, value) {
1867
+ const slug = slugifyTagValue(value);
1868
+ if (!slug) return void 0;
1869
+ return `${prefix}-${slug}`;
1870
+ }
1871
+ function userTag(raw) {
1872
+ const slug = slugifyTagValue(raw);
1873
+ if (!slug) return void 0;
1874
+ return `${TAG_PREFIX.USER}-${slug}`;
1875
+ }
1876
+ function isUserTag(tag) {
1877
+ return tag.startsWith(`${TAG_PREFIX.USER}-`);
1878
+ }
1879
+ function stripUserTagPrefix(tag) {
1880
+ return isUserTag(tag) ? tag.substring(TAG_PREFIX.USER.length + 1) : tag;
1881
+ }
1882
+ function isSystemTag(tag) {
1883
+ if (isUserTag(tag)) return false;
1884
+ if (SYSTEM_TAG_PREFIXES.some((p) => tag.startsWith(`${p}-`))) return true;
1885
+ if (LEGACY_SYSTEM_TAG_PATTERNS.some((p) => tag.startsWith(p))) return true;
1886
+ return false;
1887
+ }
1888
+ function extractUserTagValues(tags) {
1889
+ if (!tags || tags.length === 0) return [];
1890
+ const out = [];
1891
+ const seen = /* @__PURE__ */ new Set();
1892
+ for (const tag of tags) {
1893
+ if (!tag) continue;
1894
+ let value;
1895
+ if (isUserTag(tag)) {
1896
+ value = decodeURIComponent(stripUserTagPrefix(tag));
1897
+ } else if (!isSystemTag(tag)) {
1898
+ value = decodeURIComponent(tag);
1899
+ }
1900
+ if (!value) continue;
1901
+ if (seen.has(value)) continue;
1902
+ seen.add(value);
1903
+ out.push(value);
1904
+ }
1905
+ return out;
1906
+ }
1907
+ function normalizeUserTagsForSave(tags) {
1908
+ const out = [];
1909
+ const seen = /* @__PURE__ */ new Set();
1910
+ for (const raw of tags) {
1911
+ const trimmed = raw?.trim();
1912
+ if (!trimmed) continue;
1913
+ if (isSystemTag(trimmed)) continue;
1914
+ const canonical = isUserTag(trimmed) ? trimmed : userTag(trimmed);
1915
+ if (!canonical) continue;
1916
+ if (seen.has(canonical)) continue;
1917
+ seen.add(canonical);
1918
+ out.push(canonical);
1919
+ }
1920
+ return out;
1921
+ }
1922
+ function formatNumericTagValue(value) {
1923
+ if (!Number.isFinite(value)) return "";
1924
+ const normalized = Number.isInteger(value) ? String(value) : String(value).replace(/\./g, "p");
1925
+ return normalized.replace(/[^0-9p-]/g, "");
1926
+ }
1927
+ function asSortedNumericThresholds(thresholds) {
1928
+ return Array.from(new Set(thresholds.filter((n) => Number.isFinite(n)))).sort((a, b) => a - b);
1929
+ }
1930
+ function isPrefixedTag(tag, prefixes) {
1931
+ return prefixes.some((prefix) => tag.startsWith(`${prefix}-`));
1932
+ }
1933
+ function monotonicRangeTags(prefix, value, thresholds) {
1934
+ if (!Number.isFinite(value)) return [];
1935
+ const sorted = asSortedNumericThresholds(thresholds);
1936
+ const ge = sorted.filter((t) => t <= value).map((t) => `${prefix}-ge-${formatNumericTagValue(t)}`);
1937
+ const le = sorted.filter((t) => t >= value).map((t) => `${prefix}-le-${formatNumericTagValue(t)}`);
1938
+ return mergeTags(ge, le);
1939
+ }
1940
+ function rangeFilterTags(prefix, minValue, maxValue, thresholds) {
1941
+ const sorted = asSortedNumericThresholds(thresholds);
1942
+ const tags = [];
1943
+ if (typeof minValue === "number" && Number.isFinite(minValue)) {
1944
+ const lower = sorted.reduce((acc, t) => t <= minValue ? t : acc, void 0);
1945
+ if (typeof lower === "number") tags.push(`${prefix}-ge-${formatNumericTagValue(lower)}`);
1946
+ }
1947
+ if (typeof maxValue === "number" && Number.isFinite(maxValue)) {
1948
+ const upper = sorted.find((t) => t >= maxValue);
1949
+ if (typeof upper === "number") tags.push(`${prefix}-le-${formatNumericTagValue(upper)}`);
1950
+ }
1951
+ return mergeTags(tags);
1952
+ }
1953
+ function derivedProductFilterTags(filters) {
1954
+ const categories = (filters.categories || []).map((value) => prefixedTag(TAG_PREFIX.CATEGORY, value)).filter((t) => Boolean(t));
1955
+ const powerCompatibility = (filters.powerCompatibility || []).map((value) => prefixedTag(TAG_PREFIX.POWER_COMPAT, value)).filter((t) => Boolean(t));
1956
+ const replicability = (filters.replicability || []).map((value) => prefixedTag(TAG_PREFIX.REPLICABILITY, value)).filter((t) => Boolean(t));
1957
+ const recyclability = typeof filters.recyclabilityPct === "number" ? monotonicRangeTags(TAG_PREFIX.RECYCLABILITY, filters.recyclabilityPct, RECYCLABILITY_THRESHOLDS_PCT) : [];
1958
+ const repairability = filters.repairability ? [REPAIRABILITY_AVAILABLE_TAG] : [];
1959
+ const powerReq = typeof filters.powerRequirementW === "number" ? monotonicRangeTags(TAG_PREFIX.POWER_REQ, filters.powerRequirementW, POWER_REQUIREMENT_THRESHOLDS_W) : [];
1960
+ const energy = typeof filters.energyKwh === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_ENERGY, filters.energyKwh, ENERGY_THRESHOLDS_KWH) : [];
1961
+ const co2 = typeof filters.co2Kg === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_CO2, filters.co2Kg, CO2_THRESHOLDS_KG) : [];
1962
+ return mergeTags(
1963
+ categories,
1964
+ powerCompatibility,
1965
+ replicability,
1966
+ recyclability,
1967
+ repairability,
1968
+ powerReq,
1969
+ energy,
1970
+ co2
1971
+ );
1972
+ }
1973
+ function derivedServiceFilterTags(filters) {
1974
+ const serviceType = (filters.serviceType || []).map((value) => prefixedTag(TAG_PREFIX.SERVICE_TYPE, value)).filter((t) => Boolean(t));
1975
+ const availability = (filters.availability || []).map((value) => prefixedTag(TAG_PREFIX.AVAILABILITY, value)).filter((t) => Boolean(t));
1976
+ return mergeTags(serviceType, availability);
1977
+ }
1978
+ function removeTagsWithPrefixes(tags, prefixes) {
1979
+ return tags.filter((tag) => !isPrefixedTag(tag, prefixes));
1980
+ }
1981
+ function mergeTags(...tagLists) {
1982
+ const merged = [];
1983
+ const seen = /* @__PURE__ */ new Set();
1984
+ for (const list of tagLists) {
1985
+ if (!list) continue;
1986
+ for (const tag of list) {
1987
+ const trimmed = tag.trim();
1988
+ if (!trimmed) continue;
1989
+ if (seen.has(trimmed)) continue;
1990
+ seen.add(trimmed);
1991
+ merged.push(trimmed);
1992
+ }
1993
+ }
1994
+ return merged;
1995
+ }
1996
+ var TaggingClient = class {
1997
+ // User tag operations
1998
+ normalizeUserTags = normalizeUserTagsForSave;
1999
+ extractUserTagValues = extractUserTagValues;
2000
+ isSystemTag = isSystemTag;
2001
+ isUserTag = isUserTag;
2002
+ userTag = userTag;
2003
+ // Filter tag derivation
2004
+ derivedProductFilterTags = derivedProductFilterTags;
2005
+ derivedServiceFilterTags = derivedServiceFilterTags;
2006
+ // Numeric range helpers
2007
+ monotonicRangeTags = monotonicRangeTags;
2008
+ rangeFilterTags = rangeFilterTags;
2009
+ // Utilities
2010
+ slugifyTagValue = slugifyTagValue;
2011
+ prefixedTag = prefixedTag;
2012
+ mergeTags = mergeTags;
2013
+ removeTagsWithPrefixes = removeTagsWithPrefixes;
2014
+ // Constants
2015
+ TAG_PREFIX = TAG_PREFIX;
2016
+ SYSTEM_TAG_PREFIXES = SYSTEM_TAG_PREFIXES;
2017
+ PRODUCT_CATEGORY_OPTIONS = PRODUCT_CATEGORY_OPTIONS;
2018
+ POWER_COMPATIBILITY_OPTIONS = POWER_COMPATIBILITY_OPTIONS;
2019
+ REPLICABILITY_OPTIONS = REPLICABILITY_OPTIONS;
2020
+ SERVICE_TYPE_OPTIONS = SERVICE_TYPE_OPTIONS;
2021
+ AVAILABILITY_OPTIONS = AVAILABILITY_OPTIONS;
2022
+ RECYCLABILITY_THRESHOLDS_PCT = RECYCLABILITY_THRESHOLDS_PCT;
2023
+ POWER_REQUIREMENT_THRESHOLDS_W = POWER_REQUIREMENT_THRESHOLDS_W;
2024
+ ENERGY_THRESHOLDS_KWH = ENERGY_THRESHOLDS_KWH;
2025
+ CO2_THRESHOLDS_KG = CO2_THRESHOLDS_KG;
2026
+ REPAIRABILITY_AVAILABLE_TAG = REPAIRABILITY_AVAILABLE_TAG;
2027
+ MANUFACTURABLE_TRUE_TAG = MANUFACTURABLE_TRUE_TAG;
2028
+ };
2029
+
1748
2030
  // src/resources/ResourceClient.ts
1749
2031
  var ResourceClient = class {
1750
2032
  constructor(config, store, graphql) {
@@ -1836,7 +2118,18 @@ var ResourceClient = class {
1836
2118
  const machineSpecId = vars.machine?.id || this.config.specs?.machine;
1837
2119
  if (!machineSpecId) throw new Error("Machine spec ID not found in instance variables or config");
1838
2120
  const processId = await this.createProcess(`creation of machine ${params.name}`);
1839
- const res = await this.graphql.request(CREATE_MACHINE_RESOURCE, {
2121
+ const metadata = {
2122
+ ...params.type && { machineType: params.type },
2123
+ ...params.location && { location: params.location },
2124
+ ...params.image && { image: params.image },
2125
+ ...params.metadata || {}
2126
+ };
2127
+ const tags = [...params.tags || []];
2128
+ if (params.type) {
2129
+ const typeTag = prefixedTag(TAG_PREFIX.MACHINE, params.type);
2130
+ if (typeTag) tags.push(typeTag);
2131
+ }
2132
+ const variables = {
1840
2133
  agent: this.userId,
1841
2134
  creationTime: (/* @__PURE__ */ new Date()).toISOString(),
1842
2135
  process: processId,
@@ -1844,8 +2137,10 @@ var ResourceClient = class {
1844
2137
  unitOne: vars.unitOne,
1845
2138
  name: params.name,
1846
2139
  note: params.note || "",
1847
- metadata: JSON.stringify(params.metadata || {})
1848
- });
2140
+ metadata: JSON.stringify(metadata)
2141
+ };
2142
+ if (tags.length > 0) variables.tags = tags;
2143
+ const res = await this.graphql.request(CREATE_MACHINE_RESOURCE, variables);
1849
2144
  if (res.errors?.length) throw new Error(`createMachine failed: ${res.errors[0].message}`);
1850
2145
  return res.data.createEconomicEvent.economicEvent.resourceInventoriedAs;
1851
2146
  }
@@ -2025,387 +2320,109 @@ var ResourceClient = class {
2025
2320
  async getTraceDpp(id) {
2026
2321
  const res = await this.graphql.request(QUERY_RESOURCE_TRACE_DPP, { id });
2027
2322
  if (res.errors?.length) throw new Error(`getTraceDpp failed: ${res.errors[0].message}`);
2028
- const traceDpp = res.data?.economicResource?.traceDpp;
2029
- return Array.isArray(traceDpp) ? traceDpp : [];
2030
- }
2031
- async rejectProposal(intentCite, intentAccept, intentModify) {
2032
- const res = await this.graphql.request(REJECT_PROPOSAL, {
2033
- intentCite,
2034
- intentAccept,
2035
- intentModify
2036
- });
2037
- if (res.errors?.length) throw new Error(`rejectProposal failed: ${res.errors[0].message}`);
2038
- }
2039
- };
2040
-
2041
- // src/social/SocialClient.ts
2042
- init_sign();
2043
- var SocialClient = class {
2044
- constructor(config, store) {
2045
- this.config = config;
2046
- this.store = store;
2047
- }
2048
- config;
2049
- store;
2050
- get personBase() {
2051
- const base = this.config.social?.personBase;
2052
- if (!base) throw new Error("social.personBase URL not configured");
2053
- return base;
2054
- }
2055
- get erBase() {
2056
- const base = this.config.social?.economicResourceBase;
2057
- if (!base) throw new Error("social.economicResourceBase URL not configured");
2058
- return base;
2059
- }
2060
- get userId() {
2061
- const id = this.store.getItem("authId");
2062
- if (!id) throw new Error("Not authenticated");
2063
- return id;
2064
- }
2065
- /** Post an ActivityStreams activity to the user's outbox. */
2066
- async postActivity(activity) {
2067
- const body = JSON.stringify(activity);
2068
- const headers = await signGraphQLRequest(body, this.store);
2069
- const res = await fetch(`${this.personBase}/${this.userId}/outbox`, {
2070
- method: "POST",
2071
- headers: { ...headers, "Content-Type": "application/json" },
2072
- body
2073
- });
2074
- if (!res.ok) throw new Error(`ActivityPub post failed: ${res.statusText}`);
2075
- }
2076
- /** Like a resource. */
2077
- async likeResource(resourceId) {
2078
- await this.postActivity({
2079
- "@context": "https://www.w3.org/ns/activitystreams",
2080
- type: "Like",
2081
- actor: `${this.personBase}/${this.userId}`,
2082
- object: `${this.erBase}/${resourceId}`,
2083
- published: (/* @__PURE__ */ new Date()).toISOString()
2084
- });
2085
- }
2086
- /** Follow (watch) a resource. */
2087
- async followResource(resourceId) {
2088
- await this.postActivity({
2089
- "@context": "https://www.w3.org/ns/activitystreams",
2090
- type: "Follow",
2091
- actor: `${this.personBase}/${this.userId}`,
2092
- object: `${this.erBase}/${resourceId}`,
2093
- published: (/* @__PURE__ */ new Date()).toISOString()
2094
- });
2095
- }
2096
- /** Get the list of resource IDs the current user has liked. */
2097
- async getLikes() {
2098
- const res = await fetch(`${this.personBase}/${this.userId}/liked`);
2099
- const data = await res.json();
2100
- const likes = [];
2101
- for (const item of data.data?.items || []) {
2102
- const likeRes = await fetch(item);
2103
- const likeData = await likeRes.json();
2104
- const object = likeData.data?.object || "";
2105
- likes.push(object.split("economicresource/")[1] || object);
2106
- }
2107
- return likes.filter(Boolean);
2108
- }
2109
- /** Check if the current user liked a resource. */
2110
- async isLiked(resourceId) {
2111
- const likes = await this.getLikes();
2112
- return likes.includes(resourceId);
2113
- }
2114
- /** Get the list of follower IDs for a resource. */
2115
- async getFollowers(resourceId) {
2116
- const res = await fetch(`${this.erBase}/${resourceId}/follower`);
2117
- const data = await res.json();
2118
- return (data.data || []).map((f) => f.split("person/")[1] || f).filter(Boolean);
2119
- }
2120
- /** Get the list of resources the current user is following. */
2121
- async getFollowing() {
2122
- const res = await fetch(`${this.personBase}/${this.userId}/following`);
2123
- const data = await res.json();
2124
- return (data.data || []).map((f) => f.split("economicresource/")[1] || f).filter(Boolean);
2125
- }
2126
- /** Check if the current user is following a resource. */
2127
- async isFollowing(resourceId) {
2128
- const followers = await this.getFollowers(resourceId);
2129
- return followers.includes(this.userId);
2130
- }
2131
- };
2132
-
2133
- // src/tagging/constants.ts
2134
- var TAG_PREFIX = {
2135
- USER: "tag",
2136
- CATEGORY: "category",
2137
- MACHINE: "machine",
2138
- MATERIAL: "material",
2139
- POWER_COMPAT: "powercompat",
2140
- POWER_REQ: "powerreq",
2141
- REPLICABILITY: "replicability",
2142
- RECYCLABILITY: "recyclability",
2143
- REPAIRABILITY: "repairability",
2144
- ENV_ENERGY: "env-energy",
2145
- ENV_CO2: "env-co2",
2146
- SERVICE_TYPE: "servicetype",
2147
- AVAILABILITY: "availability",
2148
- LICENSE: "license",
2149
- MANUFACTURABLE: "manufacturable"
2150
- };
2151
- var SYSTEM_TAG_PREFIXES = [
2152
- TAG_PREFIX.CATEGORY,
2153
- TAG_PREFIX.MACHINE,
2154
- TAG_PREFIX.MATERIAL,
2155
- TAG_PREFIX.POWER_COMPAT,
2156
- TAG_PREFIX.POWER_REQ,
2157
- TAG_PREFIX.REPLICABILITY,
2158
- TAG_PREFIX.RECYCLABILITY,
2159
- TAG_PREFIX.REPAIRABILITY,
2160
- TAG_PREFIX.ENV_ENERGY,
2161
- TAG_PREFIX.ENV_CO2,
2162
- TAG_PREFIX.SERVICE_TYPE,
2163
- TAG_PREFIX.AVAILABILITY,
2164
- TAG_PREFIX.LICENSE,
2165
- TAG_PREFIX.MANUFACTURABLE
2166
- ];
2167
- var LEGACY_SYSTEM_TAG_PATTERNS = [
2168
- "power_compat-",
2169
- "power_",
2170
- "env_",
2171
- "mat:",
2172
- "c:",
2173
- "pc:",
2174
- "env:",
2175
- "pwr:",
2176
- "rep:",
2177
- "m:"
2178
- ];
2179
- var PRODUCT_CATEGORY_OPTIONS = [
2180
- "Electronics",
2181
- "Tools",
2182
- "Furniture",
2183
- "Home renovation",
2184
- "Energy",
2185
- "Wearables",
2186
- "Medical",
2187
- "Sustainability",
2188
- "Education"
2189
- ];
2190
- var POWER_COMPATIBILITY_OPTIONS = [
2191
- "120V AC",
2192
- "220-240V AC",
2193
- "12V DC",
2194
- "24V DC",
2195
- "Battery Powered",
2196
- "USB-C"
2197
- ];
2198
- var REPLICABILITY_OPTIONS = ["High", "Medium", "Low"];
2199
- var SERVICE_TYPE_OPTIONS = ["Fabrication", "Learning & Education", "Space Access"];
2200
- var AVAILABILITY_OPTIONS = [
2201
- "Available Now",
2202
- "Booking Required",
2203
- "Weekdays Only",
2204
- "Weekends Available"
2205
- ];
2206
- var RECYCLABILITY_THRESHOLDS_PCT = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
2207
- var POWER_REQUIREMENT_THRESHOLDS_W = [
2208
- 0,
2209
- 10,
2210
- 25,
2211
- 50,
2212
- 75,
2213
- 100,
2214
- 150,
2215
- 200,
2216
- 250,
2217
- 300,
2218
- 500,
2219
- 750,
2220
- 1e3,
2221
- 1500,
2222
- 2e3
2223
- ];
2224
- var ENERGY_THRESHOLDS_KWH = [
2225
- 0,
2226
- 10,
2227
- 20,
2228
- 30,
2229
- 50,
2230
- 100,
2231
- 200,
2232
- 300,
2233
- 500,
2234
- 750,
2235
- 1e3,
2236
- 1500,
2237
- 2e3
2238
- ];
2239
- var CO2_THRESHOLDS_KG = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 5, 7.5, 10, 15, 20];
2240
- var REPAIRABILITY_AVAILABLE_TAG = "repairability-available";
2241
- var MANUFACTURABLE_TRUE_TAG = "manufacturable-true";
2323
+ const traceDpp = res.data?.economicResource?.traceDpp;
2324
+ return Array.isArray(traceDpp) ? traceDpp : [];
2325
+ }
2326
+ async rejectProposal(intentCite, intentAccept, intentModify) {
2327
+ const res = await this.graphql.request(REJECT_PROPOSAL, {
2328
+ intentCite,
2329
+ intentAccept,
2330
+ intentModify
2331
+ });
2332
+ if (res.errors?.length) throw new Error(`rejectProposal failed: ${res.errors[0].message}`);
2333
+ }
2334
+ };
2242
2335
 
2243
- // src/tagging/TaggingClient.ts
2244
- function slugifyTagValue(value) {
2245
- return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
2246
- }
2247
- function prefixedTag(prefix, value) {
2248
- const slug = slugifyTagValue(value);
2249
- if (!slug) return void 0;
2250
- return `${prefix}-${slug}`;
2251
- }
2252
- function userTag(raw) {
2253
- const slug = slugifyTagValue(raw);
2254
- if (!slug) return void 0;
2255
- return `${TAG_PREFIX.USER}-${slug}`;
2256
- }
2257
- function isUserTag(tag) {
2258
- return tag.startsWith(`${TAG_PREFIX.USER}-`);
2259
- }
2260
- function stripUserTagPrefix(tag) {
2261
- return isUserTag(tag) ? tag.substring(TAG_PREFIX.USER.length + 1) : tag;
2262
- }
2263
- function isSystemTag(tag) {
2264
- if (isUserTag(tag)) return false;
2265
- if (SYSTEM_TAG_PREFIXES.some((p) => tag.startsWith(`${p}-`))) return true;
2266
- if (LEGACY_SYSTEM_TAG_PATTERNS.some((p) => tag.startsWith(p))) return true;
2267
- return false;
2268
- }
2269
- function extractUserTagValues(tags) {
2270
- if (!tags || tags.length === 0) return [];
2271
- const out = [];
2272
- const seen = /* @__PURE__ */ new Set();
2273
- for (const tag of tags) {
2274
- if (!tag) continue;
2275
- let value;
2276
- if (isUserTag(tag)) {
2277
- value = decodeURIComponent(stripUserTagPrefix(tag));
2278
- } else if (!isSystemTag(tag)) {
2279
- value = decodeURIComponent(tag);
2280
- }
2281
- if (!value) continue;
2282
- if (seen.has(value)) continue;
2283
- seen.add(value);
2284
- out.push(value);
2336
+ // src/social/SocialClient.ts
2337
+ init_sign();
2338
+ var SocialClient = class {
2339
+ constructor(config, store) {
2340
+ this.config = config;
2341
+ this.store = store;
2285
2342
  }
2286
- return out;
2287
- }
2288
- function normalizeUserTagsForSave(tags) {
2289
- const out = [];
2290
- const seen = /* @__PURE__ */ new Set();
2291
- for (const raw of tags) {
2292
- const trimmed = raw?.trim();
2293
- if (!trimmed) continue;
2294
- if (isSystemTag(trimmed)) continue;
2295
- const canonical = isUserTag(trimmed) ? trimmed : userTag(trimmed);
2296
- if (!canonical) continue;
2297
- if (seen.has(canonical)) continue;
2298
- seen.add(canonical);
2299
- out.push(canonical);
2343
+ config;
2344
+ store;
2345
+ get personBase() {
2346
+ const base = this.config.social?.personBase;
2347
+ if (!base) throw new Error("social.personBase URL not configured");
2348
+ return base;
2300
2349
  }
2301
- return out;
2302
- }
2303
- function formatNumericTagValue(value) {
2304
- if (!Number.isFinite(value)) return "";
2305
- const normalized = Number.isInteger(value) ? String(value) : String(value).replace(/\./g, "p");
2306
- return normalized.replace(/[^0-9p-]/g, "");
2307
- }
2308
- function asSortedNumericThresholds(thresholds) {
2309
- return Array.from(new Set(thresholds.filter((n) => Number.isFinite(n)))).sort((a, b) => a - b);
2310
- }
2311
- function isPrefixedTag(tag, prefixes) {
2312
- return prefixes.some((prefix) => tag.startsWith(`${prefix}-`));
2313
- }
2314
- function monotonicRangeTags(prefix, value, thresholds) {
2315
- if (!Number.isFinite(value)) return [];
2316
- const sorted = asSortedNumericThresholds(thresholds);
2317
- const ge = sorted.filter((t) => t <= value).map((t) => `${prefix}-ge-${formatNumericTagValue(t)}`);
2318
- const le = sorted.filter((t) => t >= value).map((t) => `${prefix}-le-${formatNumericTagValue(t)}`);
2319
- return mergeTags(ge, le);
2320
- }
2321
- function rangeFilterTags(prefix, minValue, maxValue, thresholds) {
2322
- const sorted = asSortedNumericThresholds(thresholds);
2323
- const tags = [];
2324
- if (typeof minValue === "number" && Number.isFinite(minValue)) {
2325
- const lower = sorted.reduce((acc, t) => t <= minValue ? t : acc, void 0);
2326
- if (typeof lower === "number") tags.push(`${prefix}-ge-${formatNumericTagValue(lower)}`);
2350
+ get erBase() {
2351
+ const base = this.config.social?.economicResourceBase;
2352
+ if (!base) throw new Error("social.economicResourceBase URL not configured");
2353
+ return base;
2327
2354
  }
2328
- if (typeof maxValue === "number" && Number.isFinite(maxValue)) {
2329
- const upper = sorted.find((t) => t >= maxValue);
2330
- if (typeof upper === "number") tags.push(`${prefix}-le-${formatNumericTagValue(upper)}`);
2355
+ get userId() {
2356
+ const id = this.store.getItem("authId");
2357
+ if (!id) throw new Error("Not authenticated");
2358
+ return id;
2331
2359
  }
2332
- return mergeTags(tags);
2333
- }
2334
- function derivedProductFilterTags(filters) {
2335
- const categories = (filters.categories || []).map((value) => prefixedTag(TAG_PREFIX.CATEGORY, value)).filter((t) => Boolean(t));
2336
- const powerCompatibility = (filters.powerCompatibility || []).map((value) => prefixedTag(TAG_PREFIX.POWER_COMPAT, value)).filter((t) => Boolean(t));
2337
- const replicability = (filters.replicability || []).map((value) => prefixedTag(TAG_PREFIX.REPLICABILITY, value)).filter((t) => Boolean(t));
2338
- const recyclability = typeof filters.recyclabilityPct === "number" ? monotonicRangeTags(TAG_PREFIX.RECYCLABILITY, filters.recyclabilityPct, RECYCLABILITY_THRESHOLDS_PCT) : [];
2339
- const repairability = filters.repairability ? [REPAIRABILITY_AVAILABLE_TAG] : [];
2340
- const powerReq = typeof filters.powerRequirementW === "number" ? monotonicRangeTags(TAG_PREFIX.POWER_REQ, filters.powerRequirementW, POWER_REQUIREMENT_THRESHOLDS_W) : [];
2341
- const energy = typeof filters.energyKwh === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_ENERGY, filters.energyKwh, ENERGY_THRESHOLDS_KWH) : [];
2342
- const co2 = typeof filters.co2Kg === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_CO2, filters.co2Kg, CO2_THRESHOLDS_KG) : [];
2343
- return mergeTags(
2344
- categories,
2345
- powerCompatibility,
2346
- replicability,
2347
- recyclability,
2348
- repairability,
2349
- powerReq,
2350
- energy,
2351
- co2
2352
- );
2353
- }
2354
- function derivedServiceFilterTags(filters) {
2355
- const serviceType = (filters.serviceType || []).map((value) => prefixedTag(TAG_PREFIX.SERVICE_TYPE, value)).filter((t) => Boolean(t));
2356
- const availability = (filters.availability || []).map((value) => prefixedTag(TAG_PREFIX.AVAILABILITY, value)).filter((t) => Boolean(t));
2357
- return mergeTags(serviceType, availability);
2358
- }
2359
- function removeTagsWithPrefixes(tags, prefixes) {
2360
- return tags.filter((tag) => !isPrefixedTag(tag, prefixes));
2361
- }
2362
- function mergeTags(...tagLists) {
2363
- const merged = [];
2364
- const seen = /* @__PURE__ */ new Set();
2365
- for (const list of tagLists) {
2366
- if (!list) continue;
2367
- for (const tag of list) {
2368
- const trimmed = tag.trim();
2369
- if (!trimmed) continue;
2370
- if (seen.has(trimmed)) continue;
2371
- seen.add(trimmed);
2372
- merged.push(trimmed);
2360
+ /** Post an ActivityStreams activity to the user's outbox. */
2361
+ async postActivity(activity) {
2362
+ const body = JSON.stringify(activity);
2363
+ const headers = await signGraphQLRequest(body, this.store);
2364
+ const res = await fetch(`${this.personBase}/${this.userId}/outbox`, {
2365
+ method: "POST",
2366
+ headers: { ...headers, "Content-Type": "application/json" },
2367
+ body
2368
+ });
2369
+ if (!res.ok) throw new Error(`ActivityPub post failed: ${res.statusText}`);
2370
+ }
2371
+ /** Like a resource. */
2372
+ async likeResource(resourceId) {
2373
+ await this.postActivity({
2374
+ "@context": "https://www.w3.org/ns/activitystreams",
2375
+ type: "Like",
2376
+ actor: `${this.personBase}/${this.userId}`,
2377
+ object: `${this.erBase}/${resourceId}`,
2378
+ published: (/* @__PURE__ */ new Date()).toISOString()
2379
+ });
2380
+ }
2381
+ /** Follow (watch) a resource. */
2382
+ async followResource(resourceId) {
2383
+ await this.postActivity({
2384
+ "@context": "https://www.w3.org/ns/activitystreams",
2385
+ type: "Follow",
2386
+ actor: `${this.personBase}/${this.userId}`,
2387
+ object: `${this.erBase}/${resourceId}`,
2388
+ published: (/* @__PURE__ */ new Date()).toISOString()
2389
+ });
2390
+ }
2391
+ /** Get the list of resource IDs the current user has liked. */
2392
+ async getLikes() {
2393
+ const res = await fetch(`${this.personBase}/${this.userId}/liked`);
2394
+ const data = await res.json();
2395
+ const likes = [];
2396
+ for (const item of data.data?.items || []) {
2397
+ const likeRes = await fetch(item);
2398
+ const likeData = await likeRes.json();
2399
+ const object = likeData.data?.object || "";
2400
+ likes.push(object.split("economicresource/")[1] || object);
2373
2401
  }
2402
+ return likes.filter(Boolean);
2403
+ }
2404
+ /** Check if the current user liked a resource. */
2405
+ async isLiked(resourceId) {
2406
+ const likes = await this.getLikes();
2407
+ return likes.includes(resourceId);
2408
+ }
2409
+ /** Get the list of follower IDs for a resource. */
2410
+ async getFollowers(resourceId) {
2411
+ const res = await fetch(`${this.erBase}/${resourceId}/follower`);
2412
+ const data = await res.json();
2413
+ return (data.data || []).map((f) => f.split("person/")[1] || f).filter(Boolean);
2414
+ }
2415
+ /** Get the list of resources the current user is following. */
2416
+ async getFollowing() {
2417
+ const res = await fetch(`${this.personBase}/${this.userId}/following`);
2418
+ const data = await res.json();
2419
+ return (data.data || []).map((f) => f.split("economicresource/")[1] || f).filter(Boolean);
2420
+ }
2421
+ /** Check if the current user is following a resource. */
2422
+ async isFollowing(resourceId) {
2423
+ const followers = await this.getFollowers(resourceId);
2424
+ return followers.includes(this.userId);
2374
2425
  }
2375
- return merged;
2376
- }
2377
- var TaggingClient = class {
2378
- // User tag operations
2379
- normalizeUserTags = normalizeUserTagsForSave;
2380
- extractUserTagValues = extractUserTagValues;
2381
- isSystemTag = isSystemTag;
2382
- isUserTag = isUserTag;
2383
- userTag = userTag;
2384
- // Filter tag derivation
2385
- derivedProductFilterTags = derivedProductFilterTags;
2386
- derivedServiceFilterTags = derivedServiceFilterTags;
2387
- // Numeric range helpers
2388
- monotonicRangeTags = monotonicRangeTags;
2389
- rangeFilterTags = rangeFilterTags;
2390
- // Utilities
2391
- slugifyTagValue = slugifyTagValue;
2392
- prefixedTag = prefixedTag;
2393
- mergeTags = mergeTags;
2394
- removeTagsWithPrefixes = removeTagsWithPrefixes;
2395
- // Constants
2396
- TAG_PREFIX = TAG_PREFIX;
2397
- SYSTEM_TAG_PREFIXES = SYSTEM_TAG_PREFIXES;
2398
- PRODUCT_CATEGORY_OPTIONS = PRODUCT_CATEGORY_OPTIONS;
2399
- POWER_COMPATIBILITY_OPTIONS = POWER_COMPATIBILITY_OPTIONS;
2400
- REPLICABILITY_OPTIONS = REPLICABILITY_OPTIONS;
2401
- SERVICE_TYPE_OPTIONS = SERVICE_TYPE_OPTIONS;
2402
- AVAILABILITY_OPTIONS = AVAILABILITY_OPTIONS;
2403
- RECYCLABILITY_THRESHOLDS_PCT = RECYCLABILITY_THRESHOLDS_PCT;
2404
- POWER_REQUIREMENT_THRESHOLDS_W = POWER_REQUIREMENT_THRESHOLDS_W;
2405
- ENERGY_THRESHOLDS_KWH = ENERGY_THRESHOLDS_KWH;
2406
- CO2_THRESHOLDS_KG = CO2_THRESHOLDS_KG;
2407
- REPAIRABILITY_AVAILABLE_TAG = REPAIRABILITY_AVAILABLE_TAG;
2408
- MANUFACTURABLE_TRUE_TAG = MANUFACTURABLE_TRUE_TAG;
2409
2426
  };
2410
2427
 
2411
2428
  // src/wallet/WalletClient.ts
@@ -2596,6 +2613,7 @@ export {
2596
2613
  CITE_PROJECT,
2597
2614
  CLAIM_DID,
2598
2615
  CO2_THRESHOLDS_KG,
2616
+ COMPLEXITY_OPTIONS,
2599
2617
  CONSUME_RESOURCE,
2600
2618
  CONTRIBUTE_TO_PROJECT,
2601
2619
  CREATE_DPP_RESOURCE,