@mondaydotcomorg/atp-provenance 0.19.21 → 0.21.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
@@ -366,7 +366,16 @@ var InMemoryProvenanceStore = class {
366
366
  // src/registry.ts
367
367
  var PROVENANCE_KEY = "__provenance__";
368
368
  var PROVENANCE_ID_KEY = "__prov_id__";
369
+ var PROVENANCE_META_KEY = "__prov_meta__";
369
370
  var provenanceStore = /* @__PURE__ */ new WeakMap();
371
+ var PROVENANCE_PROPERTY_NAMES = {
372
+ /** Symbol used for storing provenance data: __provenance__ */
373
+ PROVENANCE: PROVENANCE_KEY,
374
+ /** Symbol used for provenance ID: __prov_id__ */
375
+ PROVENANCE_ID: PROVENANCE_ID_KEY,
376
+ /** Symbol used for provenance metadata: __prov_meta__ */
377
+ PROVENANCE_META: PROVENANCE_META_KEY
378
+ };
370
379
  var provenanceRegistry = /* @__PURE__ */ new Map();
371
380
  var executionProvenanceIds = /* @__PURE__ */ new Map();
372
381
  var currentExecutionId = null;
@@ -689,7 +698,7 @@ function createProvenanceProxy(value, source, readers = {
689
698
  }
690
699
  } else if (typeof value === "object") {
691
700
  for (const key in value) {
692
- if (Object.prototype.hasOwnProperty.call(value, key) && key !== PROVENANCE_ID_KEY) {
701
+ if (Object.prototype.hasOwnProperty.call(value, key) && key !== PROVENANCE_ID_KEY && key !== PROVENANCE_META_KEY) {
693
702
  const nestedValue = value[key];
694
703
  if (typeof nestedValue === "object" && nestedValue !== null && !hasProvenance(nestedValue)) {
695
704
  createProvenanceProxy(nestedValue, source, readers, [
@@ -729,6 +738,24 @@ function getProvenance(value) {
729
738
  return metadata;
730
739
  }
731
740
  }
741
+ if (PROVENANCE_META_KEY in value) {
742
+ const embeddedMeta = value[PROVENANCE_META_KEY];
743
+ if (embeddedMeta && typeof embeddedMeta === "object") {
744
+ const metadata = {
745
+ id: embeddedMeta.id || id || crypto__default.default.randomUUID(),
746
+ source: embeddedMeta.source,
747
+ readers: embeddedMeta.readers || {
748
+ type: "public"
749
+ },
750
+ dependencies: embeddedMeta.dependencies || [],
751
+ context: {}
752
+ };
753
+ if (metadata.id) {
754
+ provenanceRegistry.set(metadata.id, metadata);
755
+ }
756
+ return metadata;
757
+ }
758
+ }
732
759
  if (PROVENANCE_KEY in value) {
733
760
  return value[PROVENANCE_KEY];
734
761
  }
@@ -744,6 +771,46 @@ function hasProvenance(value) {
744
771
  return getProvenance(value) !== null;
745
772
  }
746
773
  __name(hasProvenance, "hasProvenance");
774
+ function attachProvenanceMetaForCheckpoint(value, visited = /* @__PURE__ */ new WeakSet()) {
775
+ if (value === null || value === void 0 || typeof value !== "object") {
776
+ return;
777
+ }
778
+ if (visited.has(value)) {
779
+ return;
780
+ }
781
+ visited.add(value);
782
+ const metadata = getProvenance(value);
783
+ if (metadata) {
784
+ try {
785
+ if (!(PROVENANCE_META_KEY in value)) {
786
+ Object.defineProperty(value, PROVENANCE_META_KEY, {
787
+ value: {
788
+ id: metadata.id,
789
+ source: metadata.source,
790
+ readers: metadata.readers,
791
+ dependencies: metadata.dependencies
792
+ },
793
+ writable: false,
794
+ enumerable: true,
795
+ configurable: true
796
+ });
797
+ }
798
+ } catch (e) {
799
+ }
800
+ }
801
+ if (Array.isArray(value)) {
802
+ for (const item of value) {
803
+ attachProvenanceMetaForCheckpoint(item, visited);
804
+ }
805
+ } else {
806
+ for (const key in value) {
807
+ if (Object.prototype.hasOwnProperty.call(value, key) && key !== PROVENANCE_ID_KEY && key !== PROVENANCE_META_KEY) {
808
+ attachProvenanceMetaForCheckpoint(value[key], visited);
809
+ }
810
+ }
811
+ }
812
+ }
813
+ __name(attachProvenanceMetaForCheckpoint, "attachProvenanceMetaForCheckpoint");
747
814
  function getAllProvenance(value, visited = /* @__PURE__ */ new Set()) {
748
815
  if (value === null || value === void 0 || typeof value !== "object") {
749
816
  return [];
@@ -1931,11 +1998,228 @@ function createTrackingRuntime() {
1931
1998
  }
1932
1999
  __name(createTrackingRuntime, "createTrackingRuntime");
1933
2000
 
2001
+ // src/checkpoint-integration.ts
2002
+ function extractProvenanceRecursive(value, extractor, path = "", visited = /* @__PURE__ */ new WeakSet()) {
2003
+ const entries = [];
2004
+ const primitives = [];
2005
+ let hasRestrictedData = false;
2006
+ if (value === null || value === void 0) {
2007
+ return {
2008
+ entries,
2009
+ primitives,
2010
+ hasRestrictedData
2011
+ };
2012
+ }
2013
+ if (typeof value !== "object") {
2014
+ const primMeta = extractor(value);
2015
+ if (primMeta) {
2016
+ primitives.push([
2017
+ `${path}:${String(value)}`,
2018
+ primMeta
2019
+ ]);
2020
+ if (primMeta.readers?.type === "restricted") {
2021
+ hasRestrictedData = true;
2022
+ }
2023
+ }
2024
+ return {
2025
+ entries,
2026
+ primitives,
2027
+ hasRestrictedData
2028
+ };
2029
+ }
2030
+ if (visited.has(value)) {
2031
+ return {
2032
+ entries,
2033
+ primitives,
2034
+ hasRestrictedData
2035
+ };
2036
+ }
2037
+ visited.add(value);
2038
+ const metadata = extractor(value);
2039
+ if (metadata) {
2040
+ entries.push({
2041
+ path,
2042
+ metadata
2043
+ });
2044
+ if (metadata.readers?.type === "restricted") {
2045
+ hasRestrictedData = true;
2046
+ }
2047
+ }
2048
+ if (Array.isArray(value)) {
2049
+ for (let i = 0; i < value.length; i++) {
2050
+ const itemPath = `${path}[${i}]`;
2051
+ const itemResult = extractProvenanceRecursive(value[i], extractor, itemPath, visited);
2052
+ entries.push(...itemResult.entries);
2053
+ primitives.push(...itemResult.primitives);
2054
+ if (itemResult.hasRestrictedData) {
2055
+ hasRestrictedData = true;
2056
+ }
2057
+ }
2058
+ } else {
2059
+ for (const key of Object.keys(value)) {
2060
+ if (key === PROVENANCE_PROPERTY_NAMES.PROVENANCE_ID || key === PROVENANCE_PROPERTY_NAMES.PROVENANCE || key === PROVENANCE_PROPERTY_NAMES.PROVENANCE_META) {
2061
+ continue;
2062
+ }
2063
+ const propPath = path ? `${path}.${key}` : `.${key}`;
2064
+ const propResult = extractProvenanceRecursive(value[key], extractor, propPath, visited);
2065
+ entries.push(...propResult.entries);
2066
+ primitives.push(...propResult.primitives);
2067
+ if (propResult.hasRestrictedData) {
2068
+ hasRestrictedData = true;
2069
+ }
2070
+ }
2071
+ }
2072
+ return {
2073
+ entries,
2074
+ primitives,
2075
+ hasRestrictedData
2076
+ };
2077
+ }
2078
+ __name(extractProvenanceRecursive, "extractProvenanceRecursive");
2079
+ function restoreProvenanceFromSnapshot(value, snapshot, attacher) {
2080
+ if (!attacher) {
2081
+ return value;
2082
+ }
2083
+ if (snapshot.primitives) {
2084
+ for (const [key, primMeta] of snapshot.primitives) {
2085
+ attacher(null, primMeta, [
2086
+ [
2087
+ key,
2088
+ primMeta
2089
+ ]
2090
+ ]);
2091
+ }
2092
+ }
2093
+ if (snapshot.entries && snapshot.entries.length > 0) {
2094
+ return restoreProvenanceByPath(value, snapshot.entries, attacher);
2095
+ }
2096
+ if (snapshot.metadata) {
2097
+ return attacher(value, snapshot.metadata, snapshot.primitives);
2098
+ }
2099
+ return value;
2100
+ }
2101
+ __name(restoreProvenanceFromSnapshot, "restoreProvenanceFromSnapshot");
2102
+ function restoreProvenanceByPath(value, entries, attacher) {
2103
+ if (!entries || entries.length === 0) {
2104
+ return value;
2105
+ }
2106
+ const sortedEntries = [
2107
+ ...entries
2108
+ ].sort((a, b) => b.path.length - a.path.length);
2109
+ let result = deepClone(value);
2110
+ for (const entry of sortedEntries) {
2111
+ if (entry.path === "") {
2112
+ result = attacher(result, entry.metadata, void 0);
2113
+ } else {
2114
+ result = attachProvenanceAtPath(result, entry.path, entry.metadata, attacher);
2115
+ }
2116
+ }
2117
+ return result;
2118
+ }
2119
+ __name(restoreProvenanceByPath, "restoreProvenanceByPath");
2120
+ function attachProvenanceAtPath(root, path, metadata, attacher) {
2121
+ const segments = parsePath(path);
2122
+ if (segments.length === 0) {
2123
+ return attacher(root, metadata, void 0);
2124
+ }
2125
+ let current = root;
2126
+ const parentSegments = segments.slice(0, -1);
2127
+ const lastSegment = segments[segments.length - 1];
2128
+ for (const segment of parentSegments) {
2129
+ if (current === null || current === void 0) {
2130
+ return root;
2131
+ }
2132
+ current = current[segment];
2133
+ }
2134
+ if (current === null || current === void 0 || lastSegment === void 0) {
2135
+ return root;
2136
+ }
2137
+ const targetValue = current[lastSegment];
2138
+ const wrappedValue = attacher(targetValue, metadata, void 0);
2139
+ current[lastSegment] = wrappedValue;
2140
+ return root;
2141
+ }
2142
+ __name(attachProvenanceAtPath, "attachProvenanceAtPath");
2143
+ function parsePath(path) {
2144
+ const segments = [];
2145
+ let current = "";
2146
+ let inBracket = false;
2147
+ for (const char of path) {
2148
+ if (char === "[") {
2149
+ if (current) {
2150
+ segments.push(current);
2151
+ current = "";
2152
+ }
2153
+ inBracket = true;
2154
+ } else if (char === "]") {
2155
+ if (current) {
2156
+ segments.push(current);
2157
+ current = "";
2158
+ }
2159
+ inBracket = false;
2160
+ } else if (char === "." && !inBracket) {
2161
+ if (current) {
2162
+ segments.push(current);
2163
+ current = "";
2164
+ }
2165
+ } else {
2166
+ current += char;
2167
+ }
2168
+ }
2169
+ if (current) {
2170
+ segments.push(current);
2171
+ }
2172
+ return segments;
2173
+ }
2174
+ __name(parsePath, "parsePath");
2175
+ function deepClone(value) {
2176
+ if (value === null || value === void 0) {
2177
+ return value;
2178
+ }
2179
+ if (typeof value !== "object") {
2180
+ return value;
2181
+ }
2182
+ try {
2183
+ return JSON.parse(JSON.stringify(value));
2184
+ } catch {
2185
+ return value;
2186
+ }
2187
+ }
2188
+ __name(deepClone, "deepClone");
2189
+ function hasRestrictedProvenance(snapshot) {
2190
+ if (!snapshot) {
2191
+ return false;
2192
+ }
2193
+ if (snapshot.hasRestrictedData) {
2194
+ return true;
2195
+ }
2196
+ if (snapshot.metadata?.readers?.type === "restricted") {
2197
+ return true;
2198
+ }
2199
+ if (snapshot.entries) {
2200
+ for (const entry of snapshot.entries) {
2201
+ if (entry.metadata?.readers?.type === "restricted") {
2202
+ return true;
2203
+ }
2204
+ }
2205
+ }
2206
+ if (snapshot.primitives) {
2207
+ for (const [, primMeta] of snapshot.primitives) {
2208
+ if (primMeta.readers?.type === "restricted") {
2209
+ return true;
2210
+ }
2211
+ }
2212
+ }
2213
+ return false;
2214
+ }
2215
+ __name(hasRestrictedProvenance, "hasRestrictedProvenance");
2216
+
1934
2217
  exports.ConditionSchema = ConditionSchema;
1935
2218
  exports.DeclarativePolicyConfigSchema = DeclarativePolicyConfigSchema;
1936
2219
  exports.DynamicPolicyRegistry = DynamicPolicyRegistry;
1937
2220
  exports.InMemoryProvenanceStore = InMemoryProvenanceStore;
1938
2221
  exports.OperatorSchema = OperatorSchema;
2222
+ exports.PROVENANCE_PROPERTY_NAMES = PROVENANCE_PROPERTY_NAMES;
1939
2223
  exports.PolicyActionSchema = PolicyActionSchema;
1940
2224
  exports.PolicyBuilder = PolicyBuilder;
1941
2225
  exports.PolicyConfigurationSchema = PolicyConfigurationSchema;
@@ -1943,6 +2227,7 @@ exports.PolicyRuleSchema = PolicyRuleSchema;
1943
2227
  exports.ProvenanceSecurityError = ProvenanceSecurityError;
1944
2228
  exports.RuleBuilder = RuleBuilder;
1945
2229
  exports.SecurityPolicyEngine = SecurityPolicyEngine;
2230
+ exports.attachProvenanceMetaForCheckpoint = attachProvenanceMetaForCheckpoint;
1946
2231
  exports.auditSensitiveAccess = auditSensitiveAccess;
1947
2232
  exports.blockLLMRecipients = blockLLMRecipients;
1948
2233
  exports.blockLLMRecipientsWithApproval = blockLLMRecipientsWithApproval;
@@ -1956,6 +2241,8 @@ exports.createCustomPolicy = createCustomPolicy;
1956
2241
  exports.createDeclarativePolicy = createDeclarativePolicy;
1957
2242
  exports.createProvenanceProxy = createProvenanceProxy;
1958
2243
  exports.createTrackingRuntime = createTrackingRuntime;
2244
+ exports.deepClone = deepClone;
2245
+ exports.extractProvenanceRecursive = extractProvenanceRecursive;
1959
2246
  exports.getAllProvenance = getAllProvenance;
1960
2247
  exports.getBuiltInPolicies = getBuiltInPolicies;
1961
2248
  exports.getBuiltInPoliciesWithApproval = getBuiltInPoliciesWithApproval;
@@ -1963,6 +2250,7 @@ exports.getClientSecret = getClientSecret;
1963
2250
  exports.getProvenance = getProvenance;
1964
2251
  exports.getProvenanceForPrimitive = getProvenanceForPrimitive;
1965
2252
  exports.hasProvenance = hasProvenance;
2253
+ exports.hasRestrictedProvenance = hasRestrictedProvenance;
1966
2254
  exports.hydrateExecutionProvenance = hydrateExecutionProvenance;
1967
2255
  exports.hydrateProvenance = hydrateProvenance;
1968
2256
  exports.instrumentCode = instrumentCode;
@@ -1970,11 +2258,13 @@ exports.isPrimitiveTainted = isPrimitiveTainted;
1970
2258
  exports.issueProvenanceToken = issueProvenanceToken;
1971
2259
  exports.loadDeclarativePolicies = loadDeclarativePolicies;
1972
2260
  exports.markPrimitiveTainted = markPrimitiveTainted;
2261
+ exports.parsePath = parsePath;
1973
2262
  exports.preventDataExfiltration = preventDataExfiltration;
1974
2263
  exports.preventDataExfiltrationWithApproval = preventDataExfiltrationWithApproval;
1975
2264
  exports.registerProvenanceMetadata = registerProvenanceMetadata;
1976
2265
  exports.requireUserOrigin = requireUserOrigin;
1977
2266
  exports.requireUserOriginWithApproval = requireUserOriginWithApproval;
2267
+ exports.restoreProvenanceFromSnapshot = restoreProvenanceFromSnapshot;
1978
2268
  exports.restoreProvenanceSnapshot = restoreProvenanceSnapshot;
1979
2269
  exports.restoreProvenanceState = restoreProvenanceState;
1980
2270
  exports.setGlobalProvenanceStore = setGlobalProvenanceStore;