@nextera.one/axis-server-sdk 2.1.2 → 2.1.4

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
@@ -1733,6 +1733,163 @@ var init_axis_error = __esm({
1733
1733
  }
1734
1734
  });
1735
1735
 
1736
+ // src/decorators/intent-policy.decorator.ts
1737
+ var intent_policy_decorator_exports = {};
1738
+ __export(intent_policy_decorator_exports, {
1739
+ AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
1740
+ AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
1741
+ AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
1742
+ AxisAnonymous: () => AxisAnonymous,
1743
+ AxisPublic: () => AxisPublic,
1744
+ AxisRateLimit: () => AxisRateLimit,
1745
+ CONTRACT_METADATA_KEY: () => CONTRACT_METADATA_KEY,
1746
+ Capsule: () => Capsule,
1747
+ Contract: () => Contract,
1748
+ REQUIRED_PROOF_METADATA_KEY: () => REQUIRED_PROOF_METADATA_KEY,
1749
+ RequiredProof: () => RequiredProof,
1750
+ SENSITIVITY_METADATA_KEY: () => SENSITIVITY_METADATA_KEY,
1751
+ Sensitivity: () => Sensitivity,
1752
+ Witness: () => Witness
1753
+ });
1754
+ function Sensitivity(level) {
1755
+ return ((target, propertyKey) => {
1756
+ if (propertyKey !== void 0) {
1757
+ Reflect.defineMetadata(
1758
+ SENSITIVITY_METADATA_KEY,
1759
+ level,
1760
+ target,
1761
+ propertyKey
1762
+ );
1763
+ return;
1764
+ }
1765
+ Reflect.defineMetadata(SENSITIVITY_METADATA_KEY, level, target);
1766
+ });
1767
+ }
1768
+ function Contract(options) {
1769
+ return ((target, propertyKey) => {
1770
+ if (propertyKey !== void 0) {
1771
+ Reflect.defineMetadata(
1772
+ CONTRACT_METADATA_KEY,
1773
+ options,
1774
+ target,
1775
+ propertyKey
1776
+ );
1777
+ return;
1778
+ }
1779
+ Reflect.defineMetadata(CONTRACT_METADATA_KEY, options, target);
1780
+ });
1781
+ }
1782
+ function RequiredProof(proofs) {
1783
+ return ((target, propertyKey) => {
1784
+ if (propertyKey !== void 0) {
1785
+ Reflect.defineMetadata(
1786
+ REQUIRED_PROOF_METADATA_KEY,
1787
+ proofs,
1788
+ target,
1789
+ propertyKey
1790
+ );
1791
+ return;
1792
+ }
1793
+ Reflect.defineMetadata(
1794
+ REQUIRED_PROOF_METADATA_KEY,
1795
+ proofs,
1796
+ target
1797
+ );
1798
+ });
1799
+ }
1800
+ function Capsule() {
1801
+ return ((target, propertyKey) => {
1802
+ const existing = propertyKey !== void 0 ? Reflect.getMetadata(
1803
+ REQUIRED_PROOF_METADATA_KEY,
1804
+ target,
1805
+ propertyKey
1806
+ ) ?? [] : Reflect.getMetadata(
1807
+ REQUIRED_PROOF_METADATA_KEY,
1808
+ target
1809
+ ) ?? [];
1810
+ const merged = existing.includes("CAPSULE") ? existing : [...existing, "CAPSULE"];
1811
+ if (propertyKey !== void 0) {
1812
+ Reflect.defineMetadata(
1813
+ REQUIRED_PROOF_METADATA_KEY,
1814
+ merged,
1815
+ target,
1816
+ propertyKey
1817
+ );
1818
+ } else {
1819
+ Reflect.defineMetadata(
1820
+ REQUIRED_PROOF_METADATA_KEY,
1821
+ merged,
1822
+ target
1823
+ );
1824
+ }
1825
+ });
1826
+ }
1827
+ function Witness() {
1828
+ return ((target, propertyKey) => {
1829
+ const existing = propertyKey !== void 0 ? Reflect.getMetadata(
1830
+ REQUIRED_PROOF_METADATA_KEY,
1831
+ target,
1832
+ propertyKey
1833
+ ) ?? [] : Reflect.getMetadata(
1834
+ REQUIRED_PROOF_METADATA_KEY,
1835
+ target
1836
+ ) ?? [];
1837
+ const merged = existing.includes("WITNESS") ? existing : [...existing, "WITNESS"];
1838
+ if (propertyKey !== void 0) {
1839
+ Reflect.defineMetadata(
1840
+ REQUIRED_PROOF_METADATA_KEY,
1841
+ merged,
1842
+ target,
1843
+ propertyKey
1844
+ );
1845
+ } else {
1846
+ Reflect.defineMetadata(
1847
+ REQUIRED_PROOF_METADATA_KEY,
1848
+ merged,
1849
+ target
1850
+ );
1851
+ }
1852
+ });
1853
+ }
1854
+ function AxisPublic() {
1855
+ return (target, propertyKey, descriptor) => {
1856
+ if (descriptor) {
1857
+ Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target, propertyKey);
1858
+ return descriptor;
1859
+ }
1860
+ Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target);
1861
+ return target;
1862
+ };
1863
+ }
1864
+ function AxisAnonymous() {
1865
+ return (target, propertyKey, descriptor) => {
1866
+ if (descriptor) {
1867
+ Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target, propertyKey);
1868
+ return descriptor;
1869
+ }
1870
+ Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target);
1871
+ return target;
1872
+ };
1873
+ }
1874
+ function AxisRateLimit(config) {
1875
+ return (target, propertyKey, descriptor) => {
1876
+ Reflect.defineMetadata(AXIS_RATE_LIMIT_KEY, config, target, propertyKey);
1877
+ return descriptor;
1878
+ };
1879
+ }
1880
+ var import_reflect_metadata10, SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_RATE_LIMIT_KEY;
1881
+ var init_intent_policy_decorator = __esm({
1882
+ "src/decorators/intent-policy.decorator.ts"() {
1883
+ import_reflect_metadata10 = require("reflect-metadata");
1884
+ SENSITIVITY_METADATA_KEY = "axis:sensitivity";
1885
+ CONTRACT_METADATA_KEY = "axis:contract";
1886
+ REQUIRED_PROOF_METADATA_KEY = "axis:required_proof";
1887
+ AXIS_PUBLIC_KEY = "axis:public";
1888
+ AXIS_ANONYMOUS_KEY = "axis:anonymous";
1889
+ AXIS_RATE_LIMIT_KEY = "axis:rateLimit";
1890
+ }
1891
+ });
1892
+
1736
1893
  // src/security/scopes.ts
1737
1894
  function hasScope(scopes, required) {
1738
1895
  if (!Array.isArray(scopes) || scopes.length === 0) {
@@ -1937,6 +2094,7 @@ var require_intent_router = __commonJS({
1937
2094
  var handler_sensors_decorator_1 = (init_handler_sensors_decorator(), __toCommonJS(handler_sensors_decorator_exports));
1938
2095
  var handler_decorator_1 = (init_handler_decorator(), __toCommonJS(handler_decorator_exports));
1939
2096
  var intent_body_decorator_1 = (init_intent_body_decorator(), __toCommonJS(intent_body_decorator_exports));
2097
+ var intent_policy_decorator_1 = (init_intent_policy_decorator(), __toCommonJS(intent_policy_decorator_exports));
1940
2098
  var intent_sensors_decorator_1 = (init_intent_sensors_decorator(), __toCommonJS(intent_sensors_decorator_exports));
1941
2099
  var intent_decorator_1 = (init_intent_decorator(), __toCommonJS(intent_decorator_exports));
1942
2100
  var observer_decorator_1 = (init_observer_decorator(), __toCommonJS(observer_decorator_exports));
@@ -1998,6 +2156,12 @@ var require_intent_router = __commonJS({
1998
2156
  this.intentChains = /* @__PURE__ */ new Map();
1999
2157
  this.intentObservers = /* @__PURE__ */ new Map();
2000
2158
  this.intentCapsulePolicies = /* @__PURE__ */ new Map();
2159
+ this.intentSensitivity = /* @__PURE__ */ new Map();
2160
+ this.intentContracts = /* @__PURE__ */ new Map();
2161
+ this.intentRequiredProof = /* @__PURE__ */ new Map();
2162
+ this.publicIntents = /* @__PURE__ */ new Set();
2163
+ this.anonymousIntents = /* @__PURE__ */ new Set();
2164
+ this.intentRateLimits = /* @__PURE__ */ new Map();
2001
2165
  this.cceHandlers = /* @__PURE__ */ new Map();
2002
2166
  this.ccePipelineConfig = null;
2003
2167
  }
@@ -2253,6 +2417,56 @@ var require_intent_router = __commonJS({
2253
2417
  this.intentChains.set(intent, chainConfig);
2254
2418
  }
2255
2419
  }
2420
+ const methodSensitivity = Reflect.getMetadata(intent_policy_decorator_1.SENSITIVITY_METADATA_KEY, proto, methodName);
2421
+ const classSensitivity = Reflect.getMetadata(intent_policy_decorator_1.SENSITIVITY_METADATA_KEY, proto.constructor);
2422
+ const sensitivity = methodSensitivity ?? classSensitivity;
2423
+ if (sensitivity) {
2424
+ this.intentSensitivity.set(intent, sensitivity);
2425
+ }
2426
+ const methodContract = Reflect.getMetadata(intent_policy_decorator_1.CONTRACT_METADATA_KEY, proto, methodName);
2427
+ const classContract = Reflect.getMetadata(intent_policy_decorator_1.CONTRACT_METADATA_KEY, proto.constructor);
2428
+ const contract = methodContract ?? classContract;
2429
+ if (contract) {
2430
+ this.intentContracts.set(intent, contract);
2431
+ }
2432
+ const methodProof = Reflect.getMetadata(intent_policy_decorator_1.REQUIRED_PROOF_METADATA_KEY, proto, methodName);
2433
+ const classProof = Reflect.getMetadata(intent_policy_decorator_1.REQUIRED_PROOF_METADATA_KEY, proto.constructor);
2434
+ const requiredProof = methodProof ?? classProof;
2435
+ if (requiredProof && requiredProof.length > 0) {
2436
+ this.intentRequiredProof.set(intent, requiredProof);
2437
+ }
2438
+ const isPublicMethod = Reflect.getMetadata(intent_policy_decorator_1.AXIS_PUBLIC_KEY, proto, methodName);
2439
+ const isPublicClass = Reflect.getMetadata(intent_policy_decorator_1.AXIS_PUBLIC_KEY, proto.constructor);
2440
+ if (isPublicMethod || isPublicClass) {
2441
+ this.publicIntents.add(intent);
2442
+ }
2443
+ const isAnonMethod = Reflect.getMetadata(intent_policy_decorator_1.AXIS_ANONYMOUS_KEY, proto, methodName);
2444
+ const isAnonClass = Reflect.getMetadata(intent_policy_decorator_1.AXIS_ANONYMOUS_KEY, proto.constructor);
2445
+ if (isAnonMethod || isAnonClass) {
2446
+ this.anonymousIntents.add(intent);
2447
+ }
2448
+ const rateLimit = Reflect.getMetadata(intent_policy_decorator_1.AXIS_RATE_LIMIT_KEY, proto, methodName);
2449
+ if (rateLimit) {
2450
+ this.intentRateLimits.set(intent, rateLimit);
2451
+ }
2452
+ }
2453
+ getSensitivity(intent) {
2454
+ return this.intentSensitivity.get(intent);
2455
+ }
2456
+ getContract(intent) {
2457
+ return this.intentContracts.get(intent);
2458
+ }
2459
+ getRequiredProof(intent) {
2460
+ return this.intentRequiredProof.get(intent);
2461
+ }
2462
+ isPublic(intent) {
2463
+ return this.publicIntents.has(intent);
2464
+ }
2465
+ isAnonymous(intent) {
2466
+ return this.anonymousIntents.has(intent);
2467
+ }
2468
+ getRateLimit(intent) {
2469
+ return this.intentRateLimits.get(intent);
2256
2470
  }
2257
2471
  async emitIntentObservers(bindings, context) {
2258
2472
  if (!this.observerDispatcher || bindings.length === 0)
@@ -2453,7 +2667,11 @@ var require_intent_router = __commonJS({
2453
2667
  envelope: (0, axis_protocol_1.decodeChainEnvelope)(bytes2)
2454
2668
  };
2455
2669
  } catch (envelopeError) {
2456
- const reason = [jsonError?.message, requestError.message, envelopeError.message].filter(Boolean).join(" | ");
2670
+ const reason = [
2671
+ jsonError?.message,
2672
+ requestError.message,
2673
+ envelopeError.message
2674
+ ].filter(Boolean).join(" | ");
2457
2675
  throw new Error(`CHAIN.EXEC decode failed: ${reason}`);
2458
2676
  }
2459
2677
  }
@@ -7072,10 +7290,19 @@ var init_crypto = __esm({
7072
7290
  // src/decorators/index.ts
7073
7291
  var decorators_exports = {};
7074
7292
  __export(decorators_exports, {
7293
+ AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
7294
+ AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
7295
+ AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
7296
+ AxisAnonymous: () => AxisAnonymous,
7297
+ AxisPublic: () => AxisPublic,
7298
+ AxisRateLimit: () => AxisRateLimit,
7075
7299
  CAPSULE_POLICY_METADATA_KEY: () => CAPSULE_POLICY_METADATA_KEY,
7076
7300
  CHAIN_METADATA_KEY: () => CHAIN_METADATA_KEY,
7301
+ CONTRACT_METADATA_KEY: () => CONTRACT_METADATA_KEY,
7302
+ Capsule: () => Capsule,
7077
7303
  CapsulePolicy: () => CapsulePolicy,
7078
7304
  Chain: () => Chain,
7305
+ Contract: () => Contract,
7079
7306
  HANDLER_METADATA_KEY: () => HANDLER_METADATA_KEY,
7080
7307
  Handler: () => Handler,
7081
7308
  INTENT_BODY_KEY: () => INTENT_BODY_KEY,
@@ -7088,7 +7315,11 @@ __export(decorators_exports, {
7088
7315
  OBSERVER_BINDINGS_KEY: () => OBSERVER_BINDINGS_KEY,
7089
7316
  OBSERVER_METADATA_KEY: () => OBSERVER_METADATA_KEY,
7090
7317
  Observer: () => Observer,
7318
+ REQUIRED_PROOF_METADATA_KEY: () => REQUIRED_PROOF_METADATA_KEY,
7319
+ RequiredProof: () => RequiredProof,
7320
+ SENSITIVITY_METADATA_KEY: () => SENSITIVITY_METADATA_KEY,
7091
7321
  SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
7322
+ Sensitivity: () => Sensitivity,
7092
7323
  Sensor: () => Sensor,
7093
7324
  TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
7094
7325
  TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
@@ -7098,6 +7329,7 @@ __export(decorators_exports, {
7098
7329
  TlvRange: () => TlvRange,
7099
7330
  TlvUtf8Pattern: () => TlvUtf8Pattern,
7100
7331
  TlvValidate: () => TlvValidate,
7332
+ Witness: () => Witness,
7101
7333
  mergeCapsulePolicyOptions: () => mergeCapsulePolicyOptions,
7102
7334
  normalizeCapsulePolicyOptions: () => normalizeCapsulePolicyOptions
7103
7335
  });
@@ -7105,6 +7337,7 @@ var init_decorators = __esm({
7105
7337
  "src/decorators/index.ts"() {
7106
7338
  __reExport(decorators_exports, __toESM(require_axis_request_decorator()));
7107
7339
  init_capsule_policy_decorator();
7340
+ init_intent_policy_decorator();
7108
7341
  init_chain_decorator();
7109
7342
  __reExport(decorators_exports, __toESM(require_dto_schema_util()));
7110
7343
  init_handler_decorator();