@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.cjs CHANGED
@@ -261,6 +261,7 @@ __export(index_exports, {
261
261
  CITE_PROJECT: () => CITE_PROJECT,
262
262
  CLAIM_DID: () => CLAIM_DID,
263
263
  CO2_THRESHOLDS_KG: () => CO2_THRESHOLDS_KG,
264
+ COMPLEXITY_OPTIONS: () => COMPLEXITY_OPTIONS,
264
265
  CONSUME_RESOURCE: () => CONSUME_RESOURCE,
265
266
  CONTRIBUTE_TO_PROJECT: () => CONTRIBUTE_TO_PROJECT,
266
267
  CREATE_DPP_RESOURCE: () => CREATE_DPP_RESOURCE,
@@ -855,13 +856,14 @@ var CREATE_PROJECT = gql`
855
856
  var CREATE_MACHINE_RESOURCE = gql`
856
857
  mutation createMachineResource(
857
858
  $agent: ID! $creationTime: DateTime! $process: ID! $resourceSpec: ID!
858
- $unitOne: ID! $name: String! $note: String $metadata: JSONObject
859
+ $unitOne: ID! $name: String! $note: String $metadata: JSONObject $tags: [URI!]
859
860
  ) {
860
861
  createEconomicEvent(
861
862
  event: {
862
863
  action: "produce" outputOf: $process provider: $agent receiver: $agent
863
864
  hasPointInTime: $creationTime resourceConformsTo: $resourceSpec
864
865
  resourceQuantity: { hasNumericalValue: 1 hasUnit: $unitOne } resourceMetadata: $metadata
866
+ resourceClassifiedAs: $tags
865
867
  }
866
868
  newInventoriedResource: { name: $name note: $note }
867
869
  ) {
@@ -1883,6 +1885,287 @@ function clearInstanceVariablesCache() {
1883
1885
  cachedVars = null;
1884
1886
  }
1885
1887
 
1888
+ // src/tagging/constants.ts
1889
+ var TAG_PREFIX = {
1890
+ USER: "tag",
1891
+ CATEGORY: "category",
1892
+ MACHINE: "machine",
1893
+ MATERIAL: "material",
1894
+ POWER_COMPAT: "powercompat",
1895
+ POWER_REQ: "powerreq",
1896
+ REPLICABILITY: "replicability",
1897
+ RECYCLABILITY: "recyclability",
1898
+ REPAIRABILITY: "repairability",
1899
+ ENV_ENERGY: "env-energy",
1900
+ ENV_CO2: "env-co2",
1901
+ SERVICE_TYPE: "servicetype",
1902
+ AVAILABILITY: "availability",
1903
+ LICENSE: "license",
1904
+ MANUFACTURABLE: "manufacturable",
1905
+ COMPLEXITY: "complexity"
1906
+ };
1907
+ var SYSTEM_TAG_PREFIXES = [
1908
+ TAG_PREFIX.CATEGORY,
1909
+ TAG_PREFIX.MACHINE,
1910
+ TAG_PREFIX.MATERIAL,
1911
+ TAG_PREFIX.POWER_COMPAT,
1912
+ TAG_PREFIX.POWER_REQ,
1913
+ TAG_PREFIX.REPLICABILITY,
1914
+ TAG_PREFIX.RECYCLABILITY,
1915
+ TAG_PREFIX.REPAIRABILITY,
1916
+ TAG_PREFIX.ENV_ENERGY,
1917
+ TAG_PREFIX.ENV_CO2,
1918
+ TAG_PREFIX.SERVICE_TYPE,
1919
+ TAG_PREFIX.AVAILABILITY,
1920
+ TAG_PREFIX.LICENSE,
1921
+ TAG_PREFIX.MANUFACTURABLE,
1922
+ TAG_PREFIX.COMPLEXITY
1923
+ ];
1924
+ var LEGACY_SYSTEM_TAG_PATTERNS = [
1925
+ "power_compat-",
1926
+ "power_",
1927
+ "env_",
1928
+ "mat:",
1929
+ "c:",
1930
+ "pc:",
1931
+ "env:",
1932
+ "pwr:",
1933
+ "rep:",
1934
+ "m:"
1935
+ ];
1936
+ var PRODUCT_CATEGORY_OPTIONS = [
1937
+ "Electronics",
1938
+ "Tools",
1939
+ "Furniture",
1940
+ "Home renovation",
1941
+ "Energy",
1942
+ "Wearables",
1943
+ "Medical",
1944
+ "Sustainability",
1945
+ "Education"
1946
+ ];
1947
+ var POWER_COMPATIBILITY_OPTIONS = [
1948
+ "120V AC",
1949
+ "220-240V AC",
1950
+ "12V DC",
1951
+ "24V DC",
1952
+ "Battery Powered",
1953
+ "USB-C"
1954
+ ];
1955
+ var REPLICABILITY_OPTIONS = ["High", "Medium", "Low"];
1956
+ var COMPLEXITY_OPTIONS = ["Beginner", "Intermediate", "Advanced"];
1957
+ var SERVICE_TYPE_OPTIONS = ["Fabrication", "Learning & Education", "Space Access"];
1958
+ var AVAILABILITY_OPTIONS = [
1959
+ "Available Now",
1960
+ "Booking Required",
1961
+ "Weekdays Only",
1962
+ "Weekends Available"
1963
+ ];
1964
+ var RECYCLABILITY_THRESHOLDS_PCT = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
1965
+ var POWER_REQUIREMENT_THRESHOLDS_W = [
1966
+ 0,
1967
+ 10,
1968
+ 25,
1969
+ 50,
1970
+ 75,
1971
+ 100,
1972
+ 150,
1973
+ 200,
1974
+ 250,
1975
+ 300,
1976
+ 500,
1977
+ 750,
1978
+ 1e3,
1979
+ 1500,
1980
+ 2e3
1981
+ ];
1982
+ var ENERGY_THRESHOLDS_KWH = [
1983
+ 0,
1984
+ 10,
1985
+ 20,
1986
+ 30,
1987
+ 50,
1988
+ 100,
1989
+ 200,
1990
+ 300,
1991
+ 500,
1992
+ 750,
1993
+ 1e3,
1994
+ 1500,
1995
+ 2e3
1996
+ ];
1997
+ var CO2_THRESHOLDS_KG = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 5, 7.5, 10, 15, 20];
1998
+ var REPAIRABILITY_AVAILABLE_TAG = "repairability-available";
1999
+ var MANUFACTURABLE_TRUE_TAG = "manufacturable-true";
2000
+
2001
+ // src/tagging/TaggingClient.ts
2002
+ function slugifyTagValue(value) {
2003
+ return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
2004
+ }
2005
+ function prefixedTag(prefix, value) {
2006
+ const slug = slugifyTagValue(value);
2007
+ if (!slug) return void 0;
2008
+ return `${prefix}-${slug}`;
2009
+ }
2010
+ function userTag(raw) {
2011
+ const slug = slugifyTagValue(raw);
2012
+ if (!slug) return void 0;
2013
+ return `${TAG_PREFIX.USER}-${slug}`;
2014
+ }
2015
+ function isUserTag(tag) {
2016
+ return tag.startsWith(`${TAG_PREFIX.USER}-`);
2017
+ }
2018
+ function stripUserTagPrefix(tag) {
2019
+ return isUserTag(tag) ? tag.substring(TAG_PREFIX.USER.length + 1) : tag;
2020
+ }
2021
+ function isSystemTag(tag) {
2022
+ if (isUserTag(tag)) return false;
2023
+ if (SYSTEM_TAG_PREFIXES.some((p) => tag.startsWith(`${p}-`))) return true;
2024
+ if (LEGACY_SYSTEM_TAG_PATTERNS.some((p) => tag.startsWith(p))) return true;
2025
+ return false;
2026
+ }
2027
+ function extractUserTagValues(tags) {
2028
+ if (!tags || tags.length === 0) return [];
2029
+ const out = [];
2030
+ const seen = /* @__PURE__ */ new Set();
2031
+ for (const tag of tags) {
2032
+ if (!tag) continue;
2033
+ let value;
2034
+ if (isUserTag(tag)) {
2035
+ value = decodeURIComponent(stripUserTagPrefix(tag));
2036
+ } else if (!isSystemTag(tag)) {
2037
+ value = decodeURIComponent(tag);
2038
+ }
2039
+ if (!value) continue;
2040
+ if (seen.has(value)) continue;
2041
+ seen.add(value);
2042
+ out.push(value);
2043
+ }
2044
+ return out;
2045
+ }
2046
+ function normalizeUserTagsForSave(tags) {
2047
+ const out = [];
2048
+ const seen = /* @__PURE__ */ new Set();
2049
+ for (const raw of tags) {
2050
+ const trimmed = raw?.trim();
2051
+ if (!trimmed) continue;
2052
+ if (isSystemTag(trimmed)) continue;
2053
+ const canonical = isUserTag(trimmed) ? trimmed : userTag(trimmed);
2054
+ if (!canonical) continue;
2055
+ if (seen.has(canonical)) continue;
2056
+ seen.add(canonical);
2057
+ out.push(canonical);
2058
+ }
2059
+ return out;
2060
+ }
2061
+ function formatNumericTagValue(value) {
2062
+ if (!Number.isFinite(value)) return "";
2063
+ const normalized = Number.isInteger(value) ? String(value) : String(value).replace(/\./g, "p");
2064
+ return normalized.replace(/[^0-9p-]/g, "");
2065
+ }
2066
+ function asSortedNumericThresholds(thresholds) {
2067
+ return Array.from(new Set(thresholds.filter((n) => Number.isFinite(n)))).sort((a, b) => a - b);
2068
+ }
2069
+ function isPrefixedTag(tag, prefixes) {
2070
+ return prefixes.some((prefix) => tag.startsWith(`${prefix}-`));
2071
+ }
2072
+ function monotonicRangeTags(prefix, value, thresholds) {
2073
+ if (!Number.isFinite(value)) return [];
2074
+ const sorted = asSortedNumericThresholds(thresholds);
2075
+ const ge = sorted.filter((t) => t <= value).map((t) => `${prefix}-ge-${formatNumericTagValue(t)}`);
2076
+ const le = sorted.filter((t) => t >= value).map((t) => `${prefix}-le-${formatNumericTagValue(t)}`);
2077
+ return mergeTags(ge, le);
2078
+ }
2079
+ function rangeFilterTags(prefix, minValue, maxValue, thresholds) {
2080
+ const sorted = asSortedNumericThresholds(thresholds);
2081
+ const tags = [];
2082
+ if (typeof minValue === "number" && Number.isFinite(minValue)) {
2083
+ const lower = sorted.reduce((acc, t) => t <= minValue ? t : acc, void 0);
2084
+ if (typeof lower === "number") tags.push(`${prefix}-ge-${formatNumericTagValue(lower)}`);
2085
+ }
2086
+ if (typeof maxValue === "number" && Number.isFinite(maxValue)) {
2087
+ const upper = sorted.find((t) => t >= maxValue);
2088
+ if (typeof upper === "number") tags.push(`${prefix}-le-${formatNumericTagValue(upper)}`);
2089
+ }
2090
+ return mergeTags(tags);
2091
+ }
2092
+ function derivedProductFilterTags(filters) {
2093
+ const categories = (filters.categories || []).map((value) => prefixedTag(TAG_PREFIX.CATEGORY, value)).filter((t) => Boolean(t));
2094
+ const powerCompatibility = (filters.powerCompatibility || []).map((value) => prefixedTag(TAG_PREFIX.POWER_COMPAT, value)).filter((t) => Boolean(t));
2095
+ const replicability = (filters.replicability || []).map((value) => prefixedTag(TAG_PREFIX.REPLICABILITY, value)).filter((t) => Boolean(t));
2096
+ const recyclability = typeof filters.recyclabilityPct === "number" ? monotonicRangeTags(TAG_PREFIX.RECYCLABILITY, filters.recyclabilityPct, RECYCLABILITY_THRESHOLDS_PCT) : [];
2097
+ const repairability = filters.repairability ? [REPAIRABILITY_AVAILABLE_TAG] : [];
2098
+ const powerReq = typeof filters.powerRequirementW === "number" ? monotonicRangeTags(TAG_PREFIX.POWER_REQ, filters.powerRequirementW, POWER_REQUIREMENT_THRESHOLDS_W) : [];
2099
+ const energy = typeof filters.energyKwh === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_ENERGY, filters.energyKwh, ENERGY_THRESHOLDS_KWH) : [];
2100
+ const co2 = typeof filters.co2Kg === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_CO2, filters.co2Kg, CO2_THRESHOLDS_KG) : [];
2101
+ return mergeTags(
2102
+ categories,
2103
+ powerCompatibility,
2104
+ replicability,
2105
+ recyclability,
2106
+ repairability,
2107
+ powerReq,
2108
+ energy,
2109
+ co2
2110
+ );
2111
+ }
2112
+ function derivedServiceFilterTags(filters) {
2113
+ const serviceType = (filters.serviceType || []).map((value) => prefixedTag(TAG_PREFIX.SERVICE_TYPE, value)).filter((t) => Boolean(t));
2114
+ const availability = (filters.availability || []).map((value) => prefixedTag(TAG_PREFIX.AVAILABILITY, value)).filter((t) => Boolean(t));
2115
+ return mergeTags(serviceType, availability);
2116
+ }
2117
+ function removeTagsWithPrefixes(tags, prefixes) {
2118
+ return tags.filter((tag) => !isPrefixedTag(tag, prefixes));
2119
+ }
2120
+ function mergeTags(...tagLists) {
2121
+ const merged = [];
2122
+ const seen = /* @__PURE__ */ new Set();
2123
+ for (const list of tagLists) {
2124
+ if (!list) continue;
2125
+ for (const tag of list) {
2126
+ const trimmed = tag.trim();
2127
+ if (!trimmed) continue;
2128
+ if (seen.has(trimmed)) continue;
2129
+ seen.add(trimmed);
2130
+ merged.push(trimmed);
2131
+ }
2132
+ }
2133
+ return merged;
2134
+ }
2135
+ var TaggingClient = class {
2136
+ // User tag operations
2137
+ normalizeUserTags = normalizeUserTagsForSave;
2138
+ extractUserTagValues = extractUserTagValues;
2139
+ isSystemTag = isSystemTag;
2140
+ isUserTag = isUserTag;
2141
+ userTag = userTag;
2142
+ // Filter tag derivation
2143
+ derivedProductFilterTags = derivedProductFilterTags;
2144
+ derivedServiceFilterTags = derivedServiceFilterTags;
2145
+ // Numeric range helpers
2146
+ monotonicRangeTags = monotonicRangeTags;
2147
+ rangeFilterTags = rangeFilterTags;
2148
+ // Utilities
2149
+ slugifyTagValue = slugifyTagValue;
2150
+ prefixedTag = prefixedTag;
2151
+ mergeTags = mergeTags;
2152
+ removeTagsWithPrefixes = removeTagsWithPrefixes;
2153
+ // Constants
2154
+ TAG_PREFIX = TAG_PREFIX;
2155
+ SYSTEM_TAG_PREFIXES = SYSTEM_TAG_PREFIXES;
2156
+ PRODUCT_CATEGORY_OPTIONS = PRODUCT_CATEGORY_OPTIONS;
2157
+ POWER_COMPATIBILITY_OPTIONS = POWER_COMPATIBILITY_OPTIONS;
2158
+ REPLICABILITY_OPTIONS = REPLICABILITY_OPTIONS;
2159
+ SERVICE_TYPE_OPTIONS = SERVICE_TYPE_OPTIONS;
2160
+ AVAILABILITY_OPTIONS = AVAILABILITY_OPTIONS;
2161
+ RECYCLABILITY_THRESHOLDS_PCT = RECYCLABILITY_THRESHOLDS_PCT;
2162
+ POWER_REQUIREMENT_THRESHOLDS_W = POWER_REQUIREMENT_THRESHOLDS_W;
2163
+ ENERGY_THRESHOLDS_KWH = ENERGY_THRESHOLDS_KWH;
2164
+ CO2_THRESHOLDS_KG = CO2_THRESHOLDS_KG;
2165
+ REPAIRABILITY_AVAILABLE_TAG = REPAIRABILITY_AVAILABLE_TAG;
2166
+ MANUFACTURABLE_TRUE_TAG = MANUFACTURABLE_TRUE_TAG;
2167
+ };
2168
+
1886
2169
  // src/resources/ResourceClient.ts
1887
2170
  var ResourceClient = class {
1888
2171
  constructor(config, store, graphql) {
@@ -1974,7 +2257,18 @@ var ResourceClient = class {
1974
2257
  const machineSpecId = vars.machine?.id || this.config.specs?.machine;
1975
2258
  if (!machineSpecId) throw new Error("Machine spec ID not found in instance variables or config");
1976
2259
  const processId = await this.createProcess(`creation of machine ${params.name}`);
1977
- const res = await this.graphql.request(CREATE_MACHINE_RESOURCE, {
2260
+ const metadata = {
2261
+ ...params.type && { machineType: params.type },
2262
+ ...params.location && { location: params.location },
2263
+ ...params.image && { image: params.image },
2264
+ ...params.metadata || {}
2265
+ };
2266
+ const tags = [...params.tags || []];
2267
+ if (params.type) {
2268
+ const typeTag = prefixedTag(TAG_PREFIX.MACHINE, params.type);
2269
+ if (typeTag) tags.push(typeTag);
2270
+ }
2271
+ const variables = {
1978
2272
  agent: this.userId,
1979
2273
  creationTime: (/* @__PURE__ */ new Date()).toISOString(),
1980
2274
  process: processId,
@@ -1982,8 +2276,10 @@ var ResourceClient = class {
1982
2276
  unitOne: vars.unitOne,
1983
2277
  name: params.name,
1984
2278
  note: params.note || "",
1985
- metadata: JSON.stringify(params.metadata || {})
1986
- });
2279
+ metadata: JSON.stringify(metadata)
2280
+ };
2281
+ if (tags.length > 0) variables.tags = tags;
2282
+ const res = await this.graphql.request(CREATE_MACHINE_RESOURCE, variables);
1987
2283
  if (res.errors?.length) throw new Error(`createMachine failed: ${res.errors[0].message}`);
1988
2284
  return res.data.createEconomicEvent.economicEvent.resourceInventoriedAs;
1989
2285
  }
@@ -2163,387 +2459,109 @@ var ResourceClient = class {
2163
2459
  async getTraceDpp(id) {
2164
2460
  const res = await this.graphql.request(QUERY_RESOURCE_TRACE_DPP, { id });
2165
2461
  if (res.errors?.length) throw new Error(`getTraceDpp failed: ${res.errors[0].message}`);
2166
- const traceDpp = res.data?.economicResource?.traceDpp;
2167
- return Array.isArray(traceDpp) ? traceDpp : [];
2168
- }
2169
- async rejectProposal(intentCite, intentAccept, intentModify) {
2170
- const res = await this.graphql.request(REJECT_PROPOSAL, {
2171
- intentCite,
2172
- intentAccept,
2173
- intentModify
2174
- });
2175
- if (res.errors?.length) throw new Error(`rejectProposal failed: ${res.errors[0].message}`);
2176
- }
2177
- };
2178
-
2179
- // src/social/SocialClient.ts
2180
- init_sign();
2181
- var SocialClient = class {
2182
- constructor(config, store) {
2183
- this.config = config;
2184
- this.store = store;
2185
- }
2186
- config;
2187
- store;
2188
- get personBase() {
2189
- const base = this.config.social?.personBase;
2190
- if (!base) throw new Error("social.personBase URL not configured");
2191
- return base;
2192
- }
2193
- get erBase() {
2194
- const base = this.config.social?.economicResourceBase;
2195
- if (!base) throw new Error("social.economicResourceBase URL not configured");
2196
- return base;
2197
- }
2198
- get userId() {
2199
- const id = this.store.getItem("authId");
2200
- if (!id) throw new Error("Not authenticated");
2201
- return id;
2202
- }
2203
- /** Post an ActivityStreams activity to the user's outbox. */
2204
- async postActivity(activity) {
2205
- const body = JSON.stringify(activity);
2206
- const headers = await signGraphQLRequest(body, this.store);
2207
- const res = await fetch(`${this.personBase}/${this.userId}/outbox`, {
2208
- method: "POST",
2209
- headers: { ...headers, "Content-Type": "application/json" },
2210
- body
2211
- });
2212
- if (!res.ok) throw new Error(`ActivityPub post failed: ${res.statusText}`);
2213
- }
2214
- /** Like a resource. */
2215
- async likeResource(resourceId) {
2216
- await this.postActivity({
2217
- "@context": "https://www.w3.org/ns/activitystreams",
2218
- type: "Like",
2219
- actor: `${this.personBase}/${this.userId}`,
2220
- object: `${this.erBase}/${resourceId}`,
2221
- published: (/* @__PURE__ */ new Date()).toISOString()
2222
- });
2223
- }
2224
- /** Follow (watch) a resource. */
2225
- async followResource(resourceId) {
2226
- await this.postActivity({
2227
- "@context": "https://www.w3.org/ns/activitystreams",
2228
- type: "Follow",
2229
- actor: `${this.personBase}/${this.userId}`,
2230
- object: `${this.erBase}/${resourceId}`,
2231
- published: (/* @__PURE__ */ new Date()).toISOString()
2232
- });
2233
- }
2234
- /** Get the list of resource IDs the current user has liked. */
2235
- async getLikes() {
2236
- const res = await fetch(`${this.personBase}/${this.userId}/liked`);
2237
- const data = await res.json();
2238
- const likes = [];
2239
- for (const item of data.data?.items || []) {
2240
- const likeRes = await fetch(item);
2241
- const likeData = await likeRes.json();
2242
- const object = likeData.data?.object || "";
2243
- likes.push(object.split("economicresource/")[1] || object);
2244
- }
2245
- return likes.filter(Boolean);
2246
- }
2247
- /** Check if the current user liked a resource. */
2248
- async isLiked(resourceId) {
2249
- const likes = await this.getLikes();
2250
- return likes.includes(resourceId);
2251
- }
2252
- /** Get the list of follower IDs for a resource. */
2253
- async getFollowers(resourceId) {
2254
- const res = await fetch(`${this.erBase}/${resourceId}/follower`);
2255
- const data = await res.json();
2256
- return (data.data || []).map((f) => f.split("person/")[1] || f).filter(Boolean);
2257
- }
2258
- /** Get the list of resources the current user is following. */
2259
- async getFollowing() {
2260
- const res = await fetch(`${this.personBase}/${this.userId}/following`);
2261
- const data = await res.json();
2262
- return (data.data || []).map((f) => f.split("economicresource/")[1] || f).filter(Boolean);
2263
- }
2264
- /** Check if the current user is following a resource. */
2265
- async isFollowing(resourceId) {
2266
- const followers = await this.getFollowers(resourceId);
2267
- return followers.includes(this.userId);
2268
- }
2269
- };
2270
-
2271
- // src/tagging/constants.ts
2272
- var TAG_PREFIX = {
2273
- USER: "tag",
2274
- CATEGORY: "category",
2275
- MACHINE: "machine",
2276
- MATERIAL: "material",
2277
- POWER_COMPAT: "powercompat",
2278
- POWER_REQ: "powerreq",
2279
- REPLICABILITY: "replicability",
2280
- RECYCLABILITY: "recyclability",
2281
- REPAIRABILITY: "repairability",
2282
- ENV_ENERGY: "env-energy",
2283
- ENV_CO2: "env-co2",
2284
- SERVICE_TYPE: "servicetype",
2285
- AVAILABILITY: "availability",
2286
- LICENSE: "license",
2287
- MANUFACTURABLE: "manufacturable"
2288
- };
2289
- var SYSTEM_TAG_PREFIXES = [
2290
- TAG_PREFIX.CATEGORY,
2291
- TAG_PREFIX.MACHINE,
2292
- TAG_PREFIX.MATERIAL,
2293
- TAG_PREFIX.POWER_COMPAT,
2294
- TAG_PREFIX.POWER_REQ,
2295
- TAG_PREFIX.REPLICABILITY,
2296
- TAG_PREFIX.RECYCLABILITY,
2297
- TAG_PREFIX.REPAIRABILITY,
2298
- TAG_PREFIX.ENV_ENERGY,
2299
- TAG_PREFIX.ENV_CO2,
2300
- TAG_PREFIX.SERVICE_TYPE,
2301
- TAG_PREFIX.AVAILABILITY,
2302
- TAG_PREFIX.LICENSE,
2303
- TAG_PREFIX.MANUFACTURABLE
2304
- ];
2305
- var LEGACY_SYSTEM_TAG_PATTERNS = [
2306
- "power_compat-",
2307
- "power_",
2308
- "env_",
2309
- "mat:",
2310
- "c:",
2311
- "pc:",
2312
- "env:",
2313
- "pwr:",
2314
- "rep:",
2315
- "m:"
2316
- ];
2317
- var PRODUCT_CATEGORY_OPTIONS = [
2318
- "Electronics",
2319
- "Tools",
2320
- "Furniture",
2321
- "Home renovation",
2322
- "Energy",
2323
- "Wearables",
2324
- "Medical",
2325
- "Sustainability",
2326
- "Education"
2327
- ];
2328
- var POWER_COMPATIBILITY_OPTIONS = [
2329
- "120V AC",
2330
- "220-240V AC",
2331
- "12V DC",
2332
- "24V DC",
2333
- "Battery Powered",
2334
- "USB-C"
2335
- ];
2336
- var REPLICABILITY_OPTIONS = ["High", "Medium", "Low"];
2337
- var SERVICE_TYPE_OPTIONS = ["Fabrication", "Learning & Education", "Space Access"];
2338
- var AVAILABILITY_OPTIONS = [
2339
- "Available Now",
2340
- "Booking Required",
2341
- "Weekdays Only",
2342
- "Weekends Available"
2343
- ];
2344
- var RECYCLABILITY_THRESHOLDS_PCT = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
2345
- var POWER_REQUIREMENT_THRESHOLDS_W = [
2346
- 0,
2347
- 10,
2348
- 25,
2349
- 50,
2350
- 75,
2351
- 100,
2352
- 150,
2353
- 200,
2354
- 250,
2355
- 300,
2356
- 500,
2357
- 750,
2358
- 1e3,
2359
- 1500,
2360
- 2e3
2361
- ];
2362
- var ENERGY_THRESHOLDS_KWH = [
2363
- 0,
2364
- 10,
2365
- 20,
2366
- 30,
2367
- 50,
2368
- 100,
2369
- 200,
2370
- 300,
2371
- 500,
2372
- 750,
2373
- 1e3,
2374
- 1500,
2375
- 2e3
2376
- ];
2377
- var CO2_THRESHOLDS_KG = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 5, 7.5, 10, 15, 20];
2378
- var REPAIRABILITY_AVAILABLE_TAG = "repairability-available";
2379
- var MANUFACTURABLE_TRUE_TAG = "manufacturable-true";
2462
+ const traceDpp = res.data?.economicResource?.traceDpp;
2463
+ return Array.isArray(traceDpp) ? traceDpp : [];
2464
+ }
2465
+ async rejectProposal(intentCite, intentAccept, intentModify) {
2466
+ const res = await this.graphql.request(REJECT_PROPOSAL, {
2467
+ intentCite,
2468
+ intentAccept,
2469
+ intentModify
2470
+ });
2471
+ if (res.errors?.length) throw new Error(`rejectProposal failed: ${res.errors[0].message}`);
2472
+ }
2473
+ };
2380
2474
 
2381
- // src/tagging/TaggingClient.ts
2382
- function slugifyTagValue(value) {
2383
- return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
2384
- }
2385
- function prefixedTag(prefix, value) {
2386
- const slug = slugifyTagValue(value);
2387
- if (!slug) return void 0;
2388
- return `${prefix}-${slug}`;
2389
- }
2390
- function userTag(raw) {
2391
- const slug = slugifyTagValue(raw);
2392
- if (!slug) return void 0;
2393
- return `${TAG_PREFIX.USER}-${slug}`;
2394
- }
2395
- function isUserTag(tag) {
2396
- return tag.startsWith(`${TAG_PREFIX.USER}-`);
2397
- }
2398
- function stripUserTagPrefix(tag) {
2399
- return isUserTag(tag) ? tag.substring(TAG_PREFIX.USER.length + 1) : tag;
2400
- }
2401
- function isSystemTag(tag) {
2402
- if (isUserTag(tag)) return false;
2403
- if (SYSTEM_TAG_PREFIXES.some((p) => tag.startsWith(`${p}-`))) return true;
2404
- if (LEGACY_SYSTEM_TAG_PATTERNS.some((p) => tag.startsWith(p))) return true;
2405
- return false;
2406
- }
2407
- function extractUserTagValues(tags) {
2408
- if (!tags || tags.length === 0) return [];
2409
- const out = [];
2410
- const seen = /* @__PURE__ */ new Set();
2411
- for (const tag of tags) {
2412
- if (!tag) continue;
2413
- let value;
2414
- if (isUserTag(tag)) {
2415
- value = decodeURIComponent(stripUserTagPrefix(tag));
2416
- } else if (!isSystemTag(tag)) {
2417
- value = decodeURIComponent(tag);
2418
- }
2419
- if (!value) continue;
2420
- if (seen.has(value)) continue;
2421
- seen.add(value);
2422
- out.push(value);
2475
+ // src/social/SocialClient.ts
2476
+ init_sign();
2477
+ var SocialClient = class {
2478
+ constructor(config, store) {
2479
+ this.config = config;
2480
+ this.store = store;
2423
2481
  }
2424
- return out;
2425
- }
2426
- function normalizeUserTagsForSave(tags) {
2427
- const out = [];
2428
- const seen = /* @__PURE__ */ new Set();
2429
- for (const raw of tags) {
2430
- const trimmed = raw?.trim();
2431
- if (!trimmed) continue;
2432
- if (isSystemTag(trimmed)) continue;
2433
- const canonical = isUserTag(trimmed) ? trimmed : userTag(trimmed);
2434
- if (!canonical) continue;
2435
- if (seen.has(canonical)) continue;
2436
- seen.add(canonical);
2437
- out.push(canonical);
2482
+ config;
2483
+ store;
2484
+ get personBase() {
2485
+ const base = this.config.social?.personBase;
2486
+ if (!base) throw new Error("social.personBase URL not configured");
2487
+ return base;
2438
2488
  }
2439
- return out;
2440
- }
2441
- function formatNumericTagValue(value) {
2442
- if (!Number.isFinite(value)) return "";
2443
- const normalized = Number.isInteger(value) ? String(value) : String(value).replace(/\./g, "p");
2444
- return normalized.replace(/[^0-9p-]/g, "");
2445
- }
2446
- function asSortedNumericThresholds(thresholds) {
2447
- return Array.from(new Set(thresholds.filter((n) => Number.isFinite(n)))).sort((a, b) => a - b);
2448
- }
2449
- function isPrefixedTag(tag, prefixes) {
2450
- return prefixes.some((prefix) => tag.startsWith(`${prefix}-`));
2451
- }
2452
- function monotonicRangeTags(prefix, value, thresholds) {
2453
- if (!Number.isFinite(value)) return [];
2454
- const sorted = asSortedNumericThresholds(thresholds);
2455
- const ge = sorted.filter((t) => t <= value).map((t) => `${prefix}-ge-${formatNumericTagValue(t)}`);
2456
- const le = sorted.filter((t) => t >= value).map((t) => `${prefix}-le-${formatNumericTagValue(t)}`);
2457
- return mergeTags(ge, le);
2458
- }
2459
- function rangeFilterTags(prefix, minValue, maxValue, thresholds) {
2460
- const sorted = asSortedNumericThresholds(thresholds);
2461
- const tags = [];
2462
- if (typeof minValue === "number" && Number.isFinite(minValue)) {
2463
- const lower = sorted.reduce((acc, t) => t <= minValue ? t : acc, void 0);
2464
- if (typeof lower === "number") tags.push(`${prefix}-ge-${formatNumericTagValue(lower)}`);
2489
+ get erBase() {
2490
+ const base = this.config.social?.economicResourceBase;
2491
+ if (!base) throw new Error("social.economicResourceBase URL not configured");
2492
+ return base;
2465
2493
  }
2466
- if (typeof maxValue === "number" && Number.isFinite(maxValue)) {
2467
- const upper = sorted.find((t) => t >= maxValue);
2468
- if (typeof upper === "number") tags.push(`${prefix}-le-${formatNumericTagValue(upper)}`);
2494
+ get userId() {
2495
+ const id = this.store.getItem("authId");
2496
+ if (!id) throw new Error("Not authenticated");
2497
+ return id;
2469
2498
  }
2470
- return mergeTags(tags);
2471
- }
2472
- function derivedProductFilterTags(filters) {
2473
- const categories = (filters.categories || []).map((value) => prefixedTag(TAG_PREFIX.CATEGORY, value)).filter((t) => Boolean(t));
2474
- const powerCompatibility = (filters.powerCompatibility || []).map((value) => prefixedTag(TAG_PREFIX.POWER_COMPAT, value)).filter((t) => Boolean(t));
2475
- const replicability = (filters.replicability || []).map((value) => prefixedTag(TAG_PREFIX.REPLICABILITY, value)).filter((t) => Boolean(t));
2476
- const recyclability = typeof filters.recyclabilityPct === "number" ? monotonicRangeTags(TAG_PREFIX.RECYCLABILITY, filters.recyclabilityPct, RECYCLABILITY_THRESHOLDS_PCT) : [];
2477
- const repairability = filters.repairability ? [REPAIRABILITY_AVAILABLE_TAG] : [];
2478
- const powerReq = typeof filters.powerRequirementW === "number" ? monotonicRangeTags(TAG_PREFIX.POWER_REQ, filters.powerRequirementW, POWER_REQUIREMENT_THRESHOLDS_W) : [];
2479
- const energy = typeof filters.energyKwh === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_ENERGY, filters.energyKwh, ENERGY_THRESHOLDS_KWH) : [];
2480
- const co2 = typeof filters.co2Kg === "number" ? monotonicRangeTags(TAG_PREFIX.ENV_CO2, filters.co2Kg, CO2_THRESHOLDS_KG) : [];
2481
- return mergeTags(
2482
- categories,
2483
- powerCompatibility,
2484
- replicability,
2485
- recyclability,
2486
- repairability,
2487
- powerReq,
2488
- energy,
2489
- co2
2490
- );
2491
- }
2492
- function derivedServiceFilterTags(filters) {
2493
- const serviceType = (filters.serviceType || []).map((value) => prefixedTag(TAG_PREFIX.SERVICE_TYPE, value)).filter((t) => Boolean(t));
2494
- const availability = (filters.availability || []).map((value) => prefixedTag(TAG_PREFIX.AVAILABILITY, value)).filter((t) => Boolean(t));
2495
- return mergeTags(serviceType, availability);
2496
- }
2497
- function removeTagsWithPrefixes(tags, prefixes) {
2498
- return tags.filter((tag) => !isPrefixedTag(tag, prefixes));
2499
- }
2500
- function mergeTags(...tagLists) {
2501
- const merged = [];
2502
- const seen = /* @__PURE__ */ new Set();
2503
- for (const list of tagLists) {
2504
- if (!list) continue;
2505
- for (const tag of list) {
2506
- const trimmed = tag.trim();
2507
- if (!trimmed) continue;
2508
- if (seen.has(trimmed)) continue;
2509
- seen.add(trimmed);
2510
- merged.push(trimmed);
2499
+ /** Post an ActivityStreams activity to the user's outbox. */
2500
+ async postActivity(activity) {
2501
+ const body = JSON.stringify(activity);
2502
+ const headers = await signGraphQLRequest(body, this.store);
2503
+ const res = await fetch(`${this.personBase}/${this.userId}/outbox`, {
2504
+ method: "POST",
2505
+ headers: { ...headers, "Content-Type": "application/json" },
2506
+ body
2507
+ });
2508
+ if (!res.ok) throw new Error(`ActivityPub post failed: ${res.statusText}`);
2509
+ }
2510
+ /** Like a resource. */
2511
+ async likeResource(resourceId) {
2512
+ await this.postActivity({
2513
+ "@context": "https://www.w3.org/ns/activitystreams",
2514
+ type: "Like",
2515
+ actor: `${this.personBase}/${this.userId}`,
2516
+ object: `${this.erBase}/${resourceId}`,
2517
+ published: (/* @__PURE__ */ new Date()).toISOString()
2518
+ });
2519
+ }
2520
+ /** Follow (watch) a resource. */
2521
+ async followResource(resourceId) {
2522
+ await this.postActivity({
2523
+ "@context": "https://www.w3.org/ns/activitystreams",
2524
+ type: "Follow",
2525
+ actor: `${this.personBase}/${this.userId}`,
2526
+ object: `${this.erBase}/${resourceId}`,
2527
+ published: (/* @__PURE__ */ new Date()).toISOString()
2528
+ });
2529
+ }
2530
+ /** Get the list of resource IDs the current user has liked. */
2531
+ async getLikes() {
2532
+ const res = await fetch(`${this.personBase}/${this.userId}/liked`);
2533
+ const data = await res.json();
2534
+ const likes = [];
2535
+ for (const item of data.data?.items || []) {
2536
+ const likeRes = await fetch(item);
2537
+ const likeData = await likeRes.json();
2538
+ const object = likeData.data?.object || "";
2539
+ likes.push(object.split("economicresource/")[1] || object);
2511
2540
  }
2541
+ return likes.filter(Boolean);
2542
+ }
2543
+ /** Check if the current user liked a resource. */
2544
+ async isLiked(resourceId) {
2545
+ const likes = await this.getLikes();
2546
+ return likes.includes(resourceId);
2547
+ }
2548
+ /** Get the list of follower IDs for a resource. */
2549
+ async getFollowers(resourceId) {
2550
+ const res = await fetch(`${this.erBase}/${resourceId}/follower`);
2551
+ const data = await res.json();
2552
+ return (data.data || []).map((f) => f.split("person/")[1] || f).filter(Boolean);
2553
+ }
2554
+ /** Get the list of resources the current user is following. */
2555
+ async getFollowing() {
2556
+ const res = await fetch(`${this.personBase}/${this.userId}/following`);
2557
+ const data = await res.json();
2558
+ return (data.data || []).map((f) => f.split("economicresource/")[1] || f).filter(Boolean);
2559
+ }
2560
+ /** Check if the current user is following a resource. */
2561
+ async isFollowing(resourceId) {
2562
+ const followers = await this.getFollowers(resourceId);
2563
+ return followers.includes(this.userId);
2512
2564
  }
2513
- return merged;
2514
- }
2515
- var TaggingClient = class {
2516
- // User tag operations
2517
- normalizeUserTags = normalizeUserTagsForSave;
2518
- extractUserTagValues = extractUserTagValues;
2519
- isSystemTag = isSystemTag;
2520
- isUserTag = isUserTag;
2521
- userTag = userTag;
2522
- // Filter tag derivation
2523
- derivedProductFilterTags = derivedProductFilterTags;
2524
- derivedServiceFilterTags = derivedServiceFilterTags;
2525
- // Numeric range helpers
2526
- monotonicRangeTags = monotonicRangeTags;
2527
- rangeFilterTags = rangeFilterTags;
2528
- // Utilities
2529
- slugifyTagValue = slugifyTagValue;
2530
- prefixedTag = prefixedTag;
2531
- mergeTags = mergeTags;
2532
- removeTagsWithPrefixes = removeTagsWithPrefixes;
2533
- // Constants
2534
- TAG_PREFIX = TAG_PREFIX;
2535
- SYSTEM_TAG_PREFIXES = SYSTEM_TAG_PREFIXES;
2536
- PRODUCT_CATEGORY_OPTIONS = PRODUCT_CATEGORY_OPTIONS;
2537
- POWER_COMPATIBILITY_OPTIONS = POWER_COMPATIBILITY_OPTIONS;
2538
- REPLICABILITY_OPTIONS = REPLICABILITY_OPTIONS;
2539
- SERVICE_TYPE_OPTIONS = SERVICE_TYPE_OPTIONS;
2540
- AVAILABILITY_OPTIONS = AVAILABILITY_OPTIONS;
2541
- RECYCLABILITY_THRESHOLDS_PCT = RECYCLABILITY_THRESHOLDS_PCT;
2542
- POWER_REQUIREMENT_THRESHOLDS_W = POWER_REQUIREMENT_THRESHOLDS_W;
2543
- ENERGY_THRESHOLDS_KWH = ENERGY_THRESHOLDS_KWH;
2544
- CO2_THRESHOLDS_KG = CO2_THRESHOLDS_KG;
2545
- REPAIRABILITY_AVAILABLE_TAG = REPAIRABILITY_AVAILABLE_TAG;
2546
- MANUFACTURABLE_TRUE_TAG = MANUFACTURABLE_TRUE_TAG;
2547
2565
  };
2548
2566
 
2549
2567
  // src/wallet/WalletClient.ts
@@ -2735,6 +2753,7 @@ init_sign();
2735
2753
  CITE_PROJECT,
2736
2754
  CLAIM_DID,
2737
2755
  CO2_THRESHOLDS_KG,
2756
+ COMPLEXITY_OPTIONS,
2738
2757
  CONSUME_RESOURCE,
2739
2758
  CONTRIBUTE_TO_PROJECT,
2740
2759
  CREATE_DPP_RESOURCE,