@nextera.one/axis-server-sdk 2.1.3 → 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.mjs CHANGED
@@ -1805,6 +1805,163 @@ var init_axis_error = __esm({
1805
1805
  }
1806
1806
  });
1807
1807
 
1808
+ // src/decorators/intent-policy.decorator.ts
1809
+ var intent_policy_decorator_exports = {};
1810
+ __export(intent_policy_decorator_exports, {
1811
+ AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
1812
+ AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
1813
+ AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
1814
+ AxisAnonymous: () => AxisAnonymous,
1815
+ AxisPublic: () => AxisPublic,
1816
+ AxisRateLimit: () => AxisRateLimit,
1817
+ CONTRACT_METADATA_KEY: () => CONTRACT_METADATA_KEY,
1818
+ Capsule: () => Capsule,
1819
+ Contract: () => Contract,
1820
+ REQUIRED_PROOF_METADATA_KEY: () => REQUIRED_PROOF_METADATA_KEY,
1821
+ RequiredProof: () => RequiredProof,
1822
+ SENSITIVITY_METADATA_KEY: () => SENSITIVITY_METADATA_KEY,
1823
+ Sensitivity: () => Sensitivity,
1824
+ Witness: () => Witness
1825
+ });
1826
+ import "reflect-metadata";
1827
+ function Sensitivity(level) {
1828
+ return ((target, propertyKey) => {
1829
+ if (propertyKey !== void 0) {
1830
+ Reflect.defineMetadata(
1831
+ SENSITIVITY_METADATA_KEY,
1832
+ level,
1833
+ target,
1834
+ propertyKey
1835
+ );
1836
+ return;
1837
+ }
1838
+ Reflect.defineMetadata(SENSITIVITY_METADATA_KEY, level, target);
1839
+ });
1840
+ }
1841
+ function Contract(options) {
1842
+ return ((target, propertyKey) => {
1843
+ if (propertyKey !== void 0) {
1844
+ Reflect.defineMetadata(
1845
+ CONTRACT_METADATA_KEY,
1846
+ options,
1847
+ target,
1848
+ propertyKey
1849
+ );
1850
+ return;
1851
+ }
1852
+ Reflect.defineMetadata(CONTRACT_METADATA_KEY, options, target);
1853
+ });
1854
+ }
1855
+ function RequiredProof(proofs) {
1856
+ return ((target, propertyKey) => {
1857
+ if (propertyKey !== void 0) {
1858
+ Reflect.defineMetadata(
1859
+ REQUIRED_PROOF_METADATA_KEY,
1860
+ proofs,
1861
+ target,
1862
+ propertyKey
1863
+ );
1864
+ return;
1865
+ }
1866
+ Reflect.defineMetadata(
1867
+ REQUIRED_PROOF_METADATA_KEY,
1868
+ proofs,
1869
+ target
1870
+ );
1871
+ });
1872
+ }
1873
+ function Capsule() {
1874
+ return ((target, propertyKey) => {
1875
+ const existing = propertyKey !== void 0 ? Reflect.getMetadata(
1876
+ REQUIRED_PROOF_METADATA_KEY,
1877
+ target,
1878
+ propertyKey
1879
+ ) ?? [] : Reflect.getMetadata(
1880
+ REQUIRED_PROOF_METADATA_KEY,
1881
+ target
1882
+ ) ?? [];
1883
+ const merged = existing.includes("CAPSULE") ? existing : [...existing, "CAPSULE"];
1884
+ if (propertyKey !== void 0) {
1885
+ Reflect.defineMetadata(
1886
+ REQUIRED_PROOF_METADATA_KEY,
1887
+ merged,
1888
+ target,
1889
+ propertyKey
1890
+ );
1891
+ } else {
1892
+ Reflect.defineMetadata(
1893
+ REQUIRED_PROOF_METADATA_KEY,
1894
+ merged,
1895
+ target
1896
+ );
1897
+ }
1898
+ });
1899
+ }
1900
+ function Witness() {
1901
+ return ((target, propertyKey) => {
1902
+ const existing = propertyKey !== void 0 ? Reflect.getMetadata(
1903
+ REQUIRED_PROOF_METADATA_KEY,
1904
+ target,
1905
+ propertyKey
1906
+ ) ?? [] : Reflect.getMetadata(
1907
+ REQUIRED_PROOF_METADATA_KEY,
1908
+ target
1909
+ ) ?? [];
1910
+ const merged = existing.includes("WITNESS") ? existing : [...existing, "WITNESS"];
1911
+ if (propertyKey !== void 0) {
1912
+ Reflect.defineMetadata(
1913
+ REQUIRED_PROOF_METADATA_KEY,
1914
+ merged,
1915
+ target,
1916
+ propertyKey
1917
+ );
1918
+ } else {
1919
+ Reflect.defineMetadata(
1920
+ REQUIRED_PROOF_METADATA_KEY,
1921
+ merged,
1922
+ target
1923
+ );
1924
+ }
1925
+ });
1926
+ }
1927
+ function AxisPublic() {
1928
+ return (target, propertyKey, descriptor) => {
1929
+ if (descriptor) {
1930
+ Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target, propertyKey);
1931
+ return descriptor;
1932
+ }
1933
+ Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target);
1934
+ return target;
1935
+ };
1936
+ }
1937
+ function AxisAnonymous() {
1938
+ return (target, propertyKey, descriptor) => {
1939
+ if (descriptor) {
1940
+ Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target, propertyKey);
1941
+ return descriptor;
1942
+ }
1943
+ Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target);
1944
+ return target;
1945
+ };
1946
+ }
1947
+ function AxisRateLimit(config) {
1948
+ return (target, propertyKey, descriptor) => {
1949
+ Reflect.defineMetadata(AXIS_RATE_LIMIT_KEY, config, target, propertyKey);
1950
+ return descriptor;
1951
+ };
1952
+ }
1953
+ var SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_RATE_LIMIT_KEY;
1954
+ var init_intent_policy_decorator = __esm({
1955
+ "src/decorators/intent-policy.decorator.ts"() {
1956
+ SENSITIVITY_METADATA_KEY = "axis:sensitivity";
1957
+ CONTRACT_METADATA_KEY = "axis:contract";
1958
+ REQUIRED_PROOF_METADATA_KEY = "axis:required_proof";
1959
+ AXIS_PUBLIC_KEY = "axis:public";
1960
+ AXIS_ANONYMOUS_KEY = "axis:anonymous";
1961
+ AXIS_RATE_LIMIT_KEY = "axis:rateLimit";
1962
+ }
1963
+ });
1964
+
1808
1965
  // src/security/scopes.ts
1809
1966
  function hasScope(scopes, required) {
1810
1967
  if (!Array.isArray(scopes) || scopes.length === 0) {
@@ -2009,6 +2166,7 @@ var require_intent_router = __commonJS({
2009
2166
  var handler_sensors_decorator_1 = (init_handler_sensors_decorator(), __toCommonJS(handler_sensors_decorator_exports));
2010
2167
  var handler_decorator_1 = (init_handler_decorator(), __toCommonJS(handler_decorator_exports));
2011
2168
  var intent_body_decorator_1 = (init_intent_body_decorator(), __toCommonJS(intent_body_decorator_exports));
2169
+ var intent_policy_decorator_1 = (init_intent_policy_decorator(), __toCommonJS(intent_policy_decorator_exports));
2012
2170
  var intent_sensors_decorator_1 = (init_intent_sensors_decorator(), __toCommonJS(intent_sensors_decorator_exports));
2013
2171
  var intent_decorator_1 = (init_intent_decorator(), __toCommonJS(intent_decorator_exports));
2014
2172
  var observer_decorator_1 = (init_observer_decorator(), __toCommonJS(observer_decorator_exports));
@@ -2070,6 +2228,12 @@ var require_intent_router = __commonJS({
2070
2228
  this.intentChains = /* @__PURE__ */ new Map();
2071
2229
  this.intentObservers = /* @__PURE__ */ new Map();
2072
2230
  this.intentCapsulePolicies = /* @__PURE__ */ new Map();
2231
+ this.intentSensitivity = /* @__PURE__ */ new Map();
2232
+ this.intentContracts = /* @__PURE__ */ new Map();
2233
+ this.intentRequiredProof = /* @__PURE__ */ new Map();
2234
+ this.publicIntents = /* @__PURE__ */ new Set();
2235
+ this.anonymousIntents = /* @__PURE__ */ new Set();
2236
+ this.intentRateLimits = /* @__PURE__ */ new Map();
2073
2237
  this.cceHandlers = /* @__PURE__ */ new Map();
2074
2238
  this.ccePipelineConfig = null;
2075
2239
  }
@@ -2325,6 +2489,56 @@ var require_intent_router = __commonJS({
2325
2489
  this.intentChains.set(intent, chainConfig);
2326
2490
  }
2327
2491
  }
2492
+ const methodSensitivity = Reflect.getMetadata(intent_policy_decorator_1.SENSITIVITY_METADATA_KEY, proto, methodName);
2493
+ const classSensitivity = Reflect.getMetadata(intent_policy_decorator_1.SENSITIVITY_METADATA_KEY, proto.constructor);
2494
+ const sensitivity = methodSensitivity ?? classSensitivity;
2495
+ if (sensitivity) {
2496
+ this.intentSensitivity.set(intent, sensitivity);
2497
+ }
2498
+ const methodContract = Reflect.getMetadata(intent_policy_decorator_1.CONTRACT_METADATA_KEY, proto, methodName);
2499
+ const classContract = Reflect.getMetadata(intent_policy_decorator_1.CONTRACT_METADATA_KEY, proto.constructor);
2500
+ const contract = methodContract ?? classContract;
2501
+ if (contract) {
2502
+ this.intentContracts.set(intent, contract);
2503
+ }
2504
+ const methodProof = Reflect.getMetadata(intent_policy_decorator_1.REQUIRED_PROOF_METADATA_KEY, proto, methodName);
2505
+ const classProof = Reflect.getMetadata(intent_policy_decorator_1.REQUIRED_PROOF_METADATA_KEY, proto.constructor);
2506
+ const requiredProof = methodProof ?? classProof;
2507
+ if (requiredProof && requiredProof.length > 0) {
2508
+ this.intentRequiredProof.set(intent, requiredProof);
2509
+ }
2510
+ const isPublicMethod = Reflect.getMetadata(intent_policy_decorator_1.AXIS_PUBLIC_KEY, proto, methodName);
2511
+ const isPublicClass = Reflect.getMetadata(intent_policy_decorator_1.AXIS_PUBLIC_KEY, proto.constructor);
2512
+ if (isPublicMethod || isPublicClass) {
2513
+ this.publicIntents.add(intent);
2514
+ }
2515
+ const isAnonMethod = Reflect.getMetadata(intent_policy_decorator_1.AXIS_ANONYMOUS_KEY, proto, methodName);
2516
+ const isAnonClass = Reflect.getMetadata(intent_policy_decorator_1.AXIS_ANONYMOUS_KEY, proto.constructor);
2517
+ if (isAnonMethod || isAnonClass) {
2518
+ this.anonymousIntents.add(intent);
2519
+ }
2520
+ const rateLimit = Reflect.getMetadata(intent_policy_decorator_1.AXIS_RATE_LIMIT_KEY, proto, methodName);
2521
+ if (rateLimit) {
2522
+ this.intentRateLimits.set(intent, rateLimit);
2523
+ }
2524
+ }
2525
+ getSensitivity(intent) {
2526
+ return this.intentSensitivity.get(intent);
2527
+ }
2528
+ getContract(intent) {
2529
+ return this.intentContracts.get(intent);
2530
+ }
2531
+ getRequiredProof(intent) {
2532
+ return this.intentRequiredProof.get(intent);
2533
+ }
2534
+ isPublic(intent) {
2535
+ return this.publicIntents.has(intent);
2536
+ }
2537
+ isAnonymous(intent) {
2538
+ return this.anonymousIntents.has(intent);
2539
+ }
2540
+ getRateLimit(intent) {
2541
+ return this.intentRateLimits.get(intent);
2328
2542
  }
2329
2543
  async emitIntentObservers(bindings, context) {
2330
2544
  if (!this.observerDispatcher || bindings.length === 0)
@@ -2525,7 +2739,11 @@ var require_intent_router = __commonJS({
2525
2739
  envelope: (0, axis_protocol_1.decodeChainEnvelope)(bytes2)
2526
2740
  };
2527
2741
  } catch (envelopeError) {
2528
- const reason = [jsonError?.message, requestError.message, envelopeError.message].filter(Boolean).join(" | ");
2742
+ const reason = [
2743
+ jsonError?.message,
2744
+ requestError.message,
2745
+ envelopeError.message
2746
+ ].filter(Boolean).join(" | ");
2529
2747
  throw new Error(`CHAIN.EXEC decode failed: ${reason}`);
2530
2748
  }
2531
2749
  }
@@ -7135,120 +7353,15 @@ var init_crypto = __esm({
7135
7353
  }
7136
7354
  });
7137
7355
 
7138
- // src/decorators/intent-policy.decorator.ts
7139
- import "reflect-metadata";
7140
- function Sensitivity(level) {
7141
- return ((target, propertyKey) => {
7142
- if (propertyKey !== void 0) {
7143
- Reflect.defineMetadata(
7144
- SENSITIVITY_METADATA_KEY,
7145
- level,
7146
- target,
7147
- propertyKey
7148
- );
7149
- return;
7150
- }
7151
- Reflect.defineMetadata(SENSITIVITY_METADATA_KEY, level, target);
7152
- });
7153
- }
7154
- function Contract(options) {
7155
- return ((target, propertyKey) => {
7156
- if (propertyKey !== void 0) {
7157
- Reflect.defineMetadata(
7158
- CONTRACT_METADATA_KEY,
7159
- options,
7160
- target,
7161
- propertyKey
7162
- );
7163
- return;
7164
- }
7165
- Reflect.defineMetadata(CONTRACT_METADATA_KEY, options, target);
7166
- });
7167
- }
7168
- function RequiredProof(proofs) {
7169
- return ((target, propertyKey) => {
7170
- if (propertyKey !== void 0) {
7171
- Reflect.defineMetadata(
7172
- REQUIRED_PROOF_METADATA_KEY,
7173
- proofs,
7174
- target,
7175
- propertyKey
7176
- );
7177
- return;
7178
- }
7179
- Reflect.defineMetadata(
7180
- REQUIRED_PROOF_METADATA_KEY,
7181
- proofs,
7182
- target
7183
- );
7184
- });
7185
- }
7186
- function Capsule() {
7187
- return ((target, propertyKey) => {
7188
- const existing = propertyKey !== void 0 ? Reflect.getMetadata(
7189
- REQUIRED_PROOF_METADATA_KEY,
7190
- target,
7191
- propertyKey
7192
- ) ?? [] : Reflect.getMetadata(
7193
- REQUIRED_PROOF_METADATA_KEY,
7194
- target
7195
- ) ?? [];
7196
- const merged = existing.includes("CAPSULE") ? existing : [...existing, "CAPSULE"];
7197
- if (propertyKey !== void 0) {
7198
- Reflect.defineMetadata(
7199
- REQUIRED_PROOF_METADATA_KEY,
7200
- merged,
7201
- target,
7202
- propertyKey
7203
- );
7204
- } else {
7205
- Reflect.defineMetadata(
7206
- REQUIRED_PROOF_METADATA_KEY,
7207
- merged,
7208
- target
7209
- );
7210
- }
7211
- });
7212
- }
7213
- function Witness() {
7214
- return ((target, propertyKey) => {
7215
- const existing = propertyKey !== void 0 ? Reflect.getMetadata(
7216
- REQUIRED_PROOF_METADATA_KEY,
7217
- target,
7218
- propertyKey
7219
- ) ?? [] : Reflect.getMetadata(
7220
- REQUIRED_PROOF_METADATA_KEY,
7221
- target
7222
- ) ?? [];
7223
- const merged = existing.includes("WITNESS") ? existing : [...existing, "WITNESS"];
7224
- if (propertyKey !== void 0) {
7225
- Reflect.defineMetadata(
7226
- REQUIRED_PROOF_METADATA_KEY,
7227
- merged,
7228
- target,
7229
- propertyKey
7230
- );
7231
- } else {
7232
- Reflect.defineMetadata(
7233
- REQUIRED_PROOF_METADATA_KEY,
7234
- merged,
7235
- target
7236
- );
7237
- }
7238
- });
7239
- }
7240
- var SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY;
7241
- var init_intent_policy_decorator = __esm({
7242
- "src/decorators/intent-policy.decorator.ts"() {
7243
- SENSITIVITY_METADATA_KEY = "axis:sensitivity";
7244
- CONTRACT_METADATA_KEY = "axis:contract";
7245
- REQUIRED_PROOF_METADATA_KEY = "axis:required_proof";
7246
- }
7247
- });
7248
-
7249
7356
  // src/decorators/index.ts
7250
7357
  var decorators_exports = {};
7251
7358
  __export(decorators_exports, {
7359
+ AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
7360
+ AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
7361
+ AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
7362
+ AxisAnonymous: () => AxisAnonymous,
7363
+ AxisPublic: () => AxisPublic,
7364
+ AxisRateLimit: () => AxisRateLimit,
7252
7365
  CAPSULE_POLICY_METADATA_KEY: () => CAPSULE_POLICY_METADATA_KEY,
7253
7366
  CHAIN_METADATA_KEY: () => CHAIN_METADATA_KEY,
7254
7367
  CONTRACT_METADATA_KEY: () => CONTRACT_METADATA_KEY,