@nextera.one/axis-server-sdk 2.3.9 → 2.3.12

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
@@ -129,6 +129,31 @@ var init_capsule_policy_decorator = __esm({
129
129
 
130
130
  // src/decorators/intent-policy.decorator.ts
131
131
  import "reflect-metadata";
132
+ function appendRequiredProof(target, propertyKey, proof) {
133
+ const existing = propertyKey !== void 0 ? Reflect.getMetadata(
134
+ REQUIRED_PROOF_METADATA_KEY,
135
+ target,
136
+ propertyKey
137
+ ) ?? [] : Reflect.getMetadata(
138
+ REQUIRED_PROOF_METADATA_KEY,
139
+ target
140
+ ) ?? [];
141
+ const merged = existing.includes(proof) ? existing : [...existing, proof];
142
+ if (propertyKey !== void 0) {
143
+ Reflect.defineMetadata(
144
+ REQUIRED_PROOF_METADATA_KEY,
145
+ merged,
146
+ target,
147
+ propertyKey
148
+ );
149
+ return;
150
+ }
151
+ Reflect.defineMetadata(
152
+ REQUIRED_PROOF_METADATA_KEY,
153
+ merged,
154
+ target
155
+ );
156
+ }
132
157
  function Sensitivity(level) {
133
158
  return ((target, propertyKey) => {
134
159
  if (propertyKey !== void 0) {
@@ -177,56 +202,12 @@ function RequiredProof(proofs) {
177
202
  }
178
203
  function Capsule() {
179
204
  return ((target, propertyKey) => {
180
- const existing = propertyKey !== void 0 ? Reflect.getMetadata(
181
- REQUIRED_PROOF_METADATA_KEY,
182
- target,
183
- propertyKey
184
- ) ?? [] : Reflect.getMetadata(
185
- REQUIRED_PROOF_METADATA_KEY,
186
- target
187
- ) ?? [];
188
- const merged = existing.includes("CAPSULE") ? existing : [...existing, "CAPSULE"];
189
- if (propertyKey !== void 0) {
190
- Reflect.defineMetadata(
191
- REQUIRED_PROOF_METADATA_KEY,
192
- merged,
193
- target,
194
- propertyKey
195
- );
196
- } else {
197
- Reflect.defineMetadata(
198
- REQUIRED_PROOF_METADATA_KEY,
199
- merged,
200
- target
201
- );
202
- }
205
+ appendRequiredProof(target, propertyKey, "CAPSULE");
203
206
  });
204
207
  }
205
208
  function Witness() {
206
209
  return ((target, propertyKey) => {
207
- const existing = propertyKey !== void 0 ? Reflect.getMetadata(
208
- REQUIRED_PROOF_METADATA_KEY,
209
- target,
210
- propertyKey
211
- ) ?? [] : Reflect.getMetadata(
212
- REQUIRED_PROOF_METADATA_KEY,
213
- target
214
- ) ?? [];
215
- const merged = existing.includes("WITNESS") ? existing : [...existing, "WITNESS"];
216
- if (propertyKey !== void 0) {
217
- Reflect.defineMetadata(
218
- REQUIRED_PROOF_METADATA_KEY,
219
- merged,
220
- target,
221
- propertyKey
222
- );
223
- } else {
224
- Reflect.defineMetadata(
225
- REQUIRED_PROOF_METADATA_KEY,
226
- merged,
227
- target
228
- );
229
- }
210
+ appendRequiredProof(target, propertyKey, "WITNESS");
230
211
  });
231
212
  }
232
213
  function Axis() {
@@ -236,31 +217,37 @@ function Axis() {
236
217
  }
237
218
  function AxisPublic() {
238
219
  return (target, propertyKey, descriptor) => {
239
- if (descriptor) {
220
+ if (propertyKey !== void 0) {
240
221
  Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target, propertyKey);
222
+ appendRequiredProof(target, propertyKey, "NONE");
241
223
  return descriptor;
242
224
  }
243
225
  Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target);
226
+ appendRequiredProof(target, void 0, "NONE");
244
227
  return target;
245
228
  };
246
229
  }
247
230
  function AxisAuthorized() {
248
231
  return (target, propertyKey, descriptor) => {
249
- if (descriptor) {
232
+ if (propertyKey !== void 0) {
250
233
  Reflect.defineMetadata(AXIS_AUTHORIZED_KEY, true, target, propertyKey);
234
+ appendRequiredProof(target, propertyKey, "AUTHORIZED");
251
235
  return descriptor;
252
236
  }
253
237
  Reflect.defineMetadata(AXIS_AUTHORIZED_KEY, true, target);
238
+ appendRequiredProof(target, void 0, "AUTHORIZED");
254
239
  return target;
255
240
  };
256
241
  }
257
242
  function AxisAnonymous() {
258
243
  return (target, propertyKey, descriptor) => {
259
- if (descriptor) {
244
+ if (propertyKey !== void 0) {
260
245
  Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target, propertyKey);
246
+ appendRequiredProof(target, propertyKey, "ANONYMOUS");
261
247
  return descriptor;
262
248
  }
263
249
  Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target);
250
+ appendRequiredProof(target, void 0, "ANONYMOUS");
264
251
  return target;
265
252
  };
266
253
  }
@@ -2392,6 +2379,22 @@ function sensorRefKey(ref) {
2392
2379
  function sensorBindingKey(binding) {
2393
2380
  return `${binding.when}:${sensorRefKey(binding.ref)}`;
2394
2381
  }
2382
+ function mergeProofKinds(...proofGroups) {
2383
+ const merged = /* @__PURE__ */ new Set();
2384
+ for (const proofs of proofGroups) {
2385
+ for (const proof of proofs ?? []) {
2386
+ merged.add(proof);
2387
+ }
2388
+ }
2389
+ return Array.from(merged);
2390
+ }
2391
+ function accessProofKinds(isPublic, isAnonymous, isAuthorized) {
2392
+ const proofs = [];
2393
+ if (isPublic) proofs.push("NONE");
2394
+ if (isAnonymous) proofs.push("ANONYMOUS");
2395
+ if (isAuthorized) proofs.push("AUTHORIZED");
2396
+ return proofs;
2397
+ }
2395
2398
  function mergeIntentSensorBindings(...sensorGroups) {
2396
2399
  const merged = /* @__PURE__ */ new Map();
2397
2400
  for (const group of sensorGroups) {
@@ -2926,10 +2929,6 @@ var init_intent_router = __esm({
2926
2929
  REQUIRED_PROOF_METADATA_KEY,
2927
2930
  proto.constructor
2928
2931
  );
2929
- const requiredProof = methodProof ?? classProof;
2930
- if (requiredProof && requiredProof.length > 0) {
2931
- this.intentRequiredProof.set(intent, requiredProof);
2932
- }
2933
2932
  const isPublicMethod = Reflect.getMetadata(
2934
2933
  AXIS_PUBLIC_KEY,
2935
2934
  proto,
@@ -2939,9 +2938,6 @@ var init_intent_router = __esm({
2939
2938
  AXIS_PUBLIC_KEY,
2940
2939
  proto.constructor
2941
2940
  );
2942
- if (isPublicMethod || isPublicClass) {
2943
- this.publicIntents.add(intent);
2944
- }
2945
2941
  const isAnonMethod = Reflect.getMetadata(
2946
2942
  AXIS_ANONYMOUS_KEY,
2947
2943
  proto,
@@ -2951,9 +2947,6 @@ var init_intent_router = __esm({
2951
2947
  AXIS_ANONYMOUS_KEY,
2952
2948
  proto.constructor
2953
2949
  );
2954
- if (isAnonMethod || isAnonClass) {
2955
- this.anonymousIntents.add(intent);
2956
- }
2957
2950
  const isAuthorizedMethod = Reflect.getMetadata(
2958
2951
  AXIS_AUTHORIZED_KEY,
2959
2952
  proto,
@@ -2963,7 +2956,25 @@ var init_intent_router = __esm({
2963
2956
  AXIS_AUTHORIZED_KEY,
2964
2957
  proto.constructor
2965
2958
  );
2966
- if (isAuthorizedMethod || isAuthorizedClass) {
2959
+ const methodPolicyProof = mergeProofKinds(
2960
+ methodProof,
2961
+ accessProofKinds(isPublicMethod, isAnonMethod, isAuthorizedMethod)
2962
+ );
2963
+ const classPolicyProof = mergeProofKinds(
2964
+ classProof,
2965
+ accessProofKinds(isPublicClass, isAnonClass, isAuthorizedClass)
2966
+ );
2967
+ const requiredProof = methodPolicyProof.length ? methodPolicyProof : classPolicyProof;
2968
+ if (requiredProof.length > 0) {
2969
+ this.intentRequiredProof.set(intent, requiredProof);
2970
+ }
2971
+ if (requiredProof.includes("NONE")) {
2972
+ this.publicIntents.add(intent);
2973
+ }
2974
+ if (requiredProof.includes("ANONYMOUS")) {
2975
+ this.anonymousIntents.add(intent);
2976
+ }
2977
+ if (requiredProof.includes("AUTHORIZED")) {
2967
2978
  this.authorizedIntents.add(intent);
2968
2979
  }
2969
2980
  const rateLimit = Reflect.getMetadata(
@@ -11423,6 +11434,80 @@ var require_intent_registry_sensor = __commonJS({
11423
11434
  }
11424
11435
  });
11425
11436
 
11437
+ // src/sensors/law-article-presence.sensor.ts
11438
+ var require_law_article_presence_sensor = __commonJS({
11439
+ "src/sensors/law-article-presence.sensor.ts"(exports) {
11440
+ "use strict";
11441
+ var __decorate = exports && exports.__decorate || function(decorators, target, key, desc) {
11442
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11443
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11444
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11445
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
11446
+ };
11447
+ var __metadata = exports && exports.__metadata || function(k, v) {
11448
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
11449
+ };
11450
+ Object.defineProperty(exports, "__esModule", { value: true });
11451
+ exports.LawArticlePresenceSensor = void 0;
11452
+ var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
11453
+ var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
11454
+ var LawArticlePresenceSensor = class LawArticlePresenceSensor {
11455
+ constructor(options) {
11456
+ this.options = options;
11457
+ this.name = "LawArticlePresenceSensor";
11458
+ this.order = sensor_bands_1.BAND.IDENTITY + 27;
11459
+ }
11460
+ supports(input) {
11461
+ if (this.mode() === "off")
11462
+ return false;
11463
+ if (!input.intent)
11464
+ return false;
11465
+ if (this.exemptIntents().includes(input.intent))
11466
+ return false;
11467
+ return true;
11468
+ }
11469
+ async run(input) {
11470
+ const intent = input.intent;
11471
+ const count = await this.options.getLawArticleCount(intent, input);
11472
+ if (count > 0) {
11473
+ return {
11474
+ action: "ALLOW",
11475
+ meta: { lawArticles: count }
11476
+ };
11477
+ }
11478
+ const reason = `Intent '${intent}' has no law article mapping`;
11479
+ if (this.mode() === "strict") {
11480
+ return {
11481
+ action: "DENY",
11482
+ code: this.options.missingCode ?? "CAPSULE_NOT_LAWFUL",
11483
+ reason
11484
+ };
11485
+ }
11486
+ return {
11487
+ action: "FLAG",
11488
+ scoreDelta: this.options.auditScoreDelta ?? 5,
11489
+ reasons: ["LAW_ARTICLE_MISSING", reason],
11490
+ meta: { lawArticles: 0 }
11491
+ };
11492
+ }
11493
+ mode() {
11494
+ const configured = this.options.mode;
11495
+ if (typeof configured === "function")
11496
+ return configured();
11497
+ return configured ?? "audit";
11498
+ }
11499
+ exemptIntents() {
11500
+ return this.options.exemptIntents ?? ["system.ping"];
11501
+ }
11502
+ };
11503
+ exports.LawArticlePresenceSensor = LawArticlePresenceSensor;
11504
+ exports.LawArticlePresenceSensor = LawArticlePresenceSensor = __decorate([
11505
+ (0, sensor_decorator_1.Sensor)({ phase: "POST_DECODE" }),
11506
+ __metadata("design:paramtypes", [Object])
11507
+ ], LawArticlePresenceSensor);
11508
+ }
11509
+ });
11510
+
11426
11511
  // src/sensors/law-evaluation.sensor.ts
11427
11512
  var require_law_evaluation_sensor = __commonJS({
11428
11513
  "src/sensors/law-evaluation.sensor.ts"(exports) {
@@ -12894,6 +12979,7 @@ var init_sensors = __esm({
12894
12979
  __reExport(sensors_exports, __toESM(require_header_tlv_limit_sensor()));
12895
12980
  __reExport(sensors_exports, __toESM(require_intent_allowlist_sensor()));
12896
12981
  __reExport(sensors_exports, __toESM(require_intent_registry_sensor()));
12982
+ __reExport(sensors_exports, __toESM(require_law_article_presence_sensor()));
12897
12983
  __reExport(sensors_exports, __toESM(require_law_evaluation_sensor()));
12898
12984
  __reExport(sensors_exports, __toESM(require_proof_presence_sensor()));
12899
12985
  __reExport(sensors_exports, __toESM(require_protocol_strict_sensor()));