@dyne/interfacer-client 0.5.0 → 0.6.1
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 +368 -349
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +367 -349
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -421,7 +421,7 @@ var FETCH_RESOURCES = gql`
|
|
|
421
421
|
$filter: EconomicResourceFilterParams
|
|
422
422
|
) {
|
|
423
423
|
economicResources(first: $first after: $after before: $before last: $last filter: $filter) {
|
|
424
|
-
pageInfo { startCursor endCursor hasPreviousPage hasNextPage totalCount pageLimit }
|
|
424
|
+
pageInfo { startCursor endCursor hasPreviousPage hasNextPage totalCount pageLimit distinctPrimaryAccountableCount }
|
|
425
425
|
edges {
|
|
426
426
|
cursor
|
|
427
427
|
node {
|
|
@@ -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,76 +1746,357 @@ function clearInstanceVariablesCache() {
|
|
|
1745
1746
|
cachedVars = null;
|
|
1746
1747
|
}
|
|
1747
1748
|
|
|
1748
|
-
// src/
|
|
1749
|
-
var
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
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);
|
|
1779
1899
|
}
|
|
1900
|
+
if (!value) continue;
|
|
1901
|
+
if (seen.has(value)) continue;
|
|
1902
|
+
seen.add(value);
|
|
1903
|
+
out.push(value);
|
|
1780
1904
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
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);
|
|
1789
1919
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
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)}`);
|
|
1800
1946
|
}
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
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
|
+
|
|
2030
|
+
// src/resources/ResourceClient.ts
|
|
2031
|
+
var ResourceClient = class {
|
|
2032
|
+
constructor(config, store, graphql) {
|
|
2033
|
+
this.config = config;
|
|
2034
|
+
this.store = store;
|
|
2035
|
+
this.graphql = graphql;
|
|
2036
|
+
}
|
|
2037
|
+
config;
|
|
2038
|
+
store;
|
|
2039
|
+
graphql;
|
|
2040
|
+
get userId() {
|
|
2041
|
+
const id = this.store.getItem("authId");
|
|
2042
|
+
if (!id) throw new Error("Not authenticated");
|
|
2043
|
+
return id;
|
|
2044
|
+
}
|
|
2045
|
+
async getInstanceVars() {
|
|
2046
|
+
return getInstanceVariables(this.graphql);
|
|
2047
|
+
}
|
|
2048
|
+
// ─── Helpers ───────────────────────────────────────────────────────
|
|
2049
|
+
specIdForType(vars, type) {
|
|
2050
|
+
switch (type) {
|
|
2051
|
+
case "Design" /* DESIGN */:
|
|
2052
|
+
return vars.projectDesign.id;
|
|
2053
|
+
case "Product" /* PRODUCT */:
|
|
2054
|
+
return vars.projectProduct?.id || this.config.specs?.product || "";
|
|
2055
|
+
case "Service" /* SERVICE */:
|
|
2056
|
+
return vars.projectService?.id || this.config.specs?.service || "";
|
|
2057
|
+
case "Machine" /* MACHINE */:
|
|
2058
|
+
return vars.machine?.id || this.config.specs?.machine || "";
|
|
2059
|
+
case "DPP" /* DPP */:
|
|
2060
|
+
return vars.dpp?.id || this.config.specs?.dpp || "";
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
// ─── Process ───────────────────────────────────────────────────────
|
|
2064
|
+
async createProcess(name) {
|
|
2065
|
+
const res = await this.graphql.request(
|
|
2066
|
+
CREATE_PROCESS,
|
|
2067
|
+
{ name }
|
|
2068
|
+
);
|
|
2069
|
+
if (res.errors?.length) throw new Error(`createProcess failed: ${res.errors[0].message}`);
|
|
2070
|
+
return res.data.createProcess.process.id;
|
|
2071
|
+
}
|
|
2072
|
+
// ─── Location ──────────────────────────────────────────────────────
|
|
2073
|
+
async createLocation(params) {
|
|
2074
|
+
const res = await this.graphql.request(CREATE_LOCATION, {
|
|
2075
|
+
name: params.name,
|
|
2076
|
+
addr: params.address || "",
|
|
2077
|
+
lat: params.lat || 0,
|
|
2078
|
+
lng: params.lng || 0
|
|
2079
|
+
});
|
|
2080
|
+
if (res.errors?.length) throw new Error(`createLocation failed: ${res.errors[0].message}`);
|
|
2081
|
+
return res.data.createSpatialThing.spatialThing;
|
|
2082
|
+
}
|
|
2083
|
+
// ─── Create Project (Design, Product, Service) ─────────────────────
|
|
2084
|
+
async createProject(params) {
|
|
2085
|
+
const vars = await this.getInstanceVars();
|
|
2086
|
+
const specId = this.specIdForType(vars, params.projectType);
|
|
2087
|
+
if (!specId) throw new Error(`${params.projectType} spec ID not found in instance variables or config`);
|
|
2088
|
+
const processId = params.processId || await this.createProcess(`creation of ${params.name} by owner`);
|
|
2089
|
+
let locationId = params.locationId;
|
|
2090
|
+
if (!locationId && params.location) {
|
|
2091
|
+
const loc = await this.createLocation(params.location);
|
|
2092
|
+
locationId = loc.id;
|
|
2093
|
+
}
|
|
2094
|
+
const variables = {
|
|
2095
|
+
name: params.name,
|
|
2096
|
+
note: params.note || "",
|
|
2097
|
+
metadata: JSON.stringify(params.metadata || {}),
|
|
2098
|
+
agent: this.userId,
|
|
2099
|
+
creationTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1818
2100
|
location: locationId,
|
|
1819
2101
|
resourceSpec: specId,
|
|
1820
2102
|
oneUnit: vars.unitOne,
|
|
@@ -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
|
|
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(
|
|
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
|
}
|
|
@@ -2130,284 +2425,6 @@ var SocialClient = class {
|
|
|
2130
2425
|
}
|
|
2131
2426
|
};
|
|
2132
2427
|
|
|
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";
|
|
2242
|
-
|
|
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);
|
|
2285
|
-
}
|
|
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);
|
|
2300
|
-
}
|
|
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)}`);
|
|
2327
|
-
}
|
|
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)}`);
|
|
2331
|
-
}
|
|
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);
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
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
|
-
};
|
|
2410
|
-
|
|
2411
2428
|
// src/wallet/WalletClient.ts
|
|
2412
2429
|
init_sign();
|
|
2413
2430
|
var WalletClient = class {
|
|
@@ -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,
|