@claritylabs/cl-sdk 3.1.4 → 3.1.5

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
@@ -458,53 +458,70 @@ function sanitizeNulls(obj) {
458
458
 
459
459
  // src/core/strict-schema.ts
460
460
  var import_zod = require("zod");
461
+ function schemaDef(schema) {
462
+ return schema._zod?.def ?? schema._def ?? {};
463
+ }
464
+ function schemaKind(schema) {
465
+ const def = schemaDef(schema);
466
+ const raw = typeof def.type === "string" ? def.type : typeof def.typeName === "string" ? def.typeName : typeof schema.type === "string" ? schema.type : void 0;
467
+ return raw?.replace(/^Zod/, "").toLowerCase();
468
+ }
469
+ function schemaDescription(schema) {
470
+ const def = schemaDef(schema);
471
+ return schema.description ?? def.description;
472
+ }
473
+ function objectShape(schema) {
474
+ const def = schemaDef(schema);
475
+ const shape = schema.shape ?? def.shape;
476
+ return typeof shape === "function" ? shape() : shape;
477
+ }
478
+ function withDescription(schema, description) {
479
+ return description ? schema.describe(description) : schema;
480
+ }
461
481
  function toStrictSchema(schema) {
462
- const def = schema._zod?.def;
463
- const typeName = def?.type ?? schema.type;
464
- if (typeName === "object") {
465
- const shape = schema.shape;
482
+ const kind = schemaKind(schema);
483
+ const def = schemaDef(schema);
484
+ if (kind === "object") {
485
+ const shape = objectShape(schema);
466
486
  if (!shape) return schema;
467
487
  const newShape = {};
468
488
  for (const [key, value] of Object.entries(shape)) {
469
489
  const field = value;
470
- const fieldDef = field._zod?.def;
471
- const fieldType = fieldDef?.type ?? field.type;
472
- if (fieldType === "optional") {
490
+ const fieldDef = schemaDef(field);
491
+ const fieldKind = schemaKind(field);
492
+ if (fieldKind === "optional") {
473
493
  const innerType = fieldDef?.innerType;
474
- const description = field.description ?? fieldDef?.description ?? field._zod?.def?.description;
494
+ const description = schemaDescription(field);
475
495
  if (innerType) {
476
496
  const transformed = toStrictSchema(innerType);
477
- let nullable = import_zod.z.nullable(transformed);
478
- if (description) nullable = nullable.describe(description);
479
- newShape[key] = nullable;
497
+ newShape[key] = withDescription(import_zod.z.nullable(transformed), description);
480
498
  } else {
481
- let nullable = import_zod.z.nullable(field);
482
- if (description) nullable = nullable.describe(description);
483
- newShape[key] = nullable;
499
+ newShape[key] = withDescription(import_zod.z.nullable(field), description);
484
500
  }
485
501
  } else {
486
502
  newShape[key] = toStrictSchema(field);
487
503
  }
488
504
  }
489
- const objDesc = schema.description ?? def?.description ?? schema._zod?.def?.description;
490
- const result = import_zod.z.object(newShape);
491
- return objDesc ? result.describe(objDesc) : result;
505
+ return withDescription(import_zod.z.object(newShape), schemaDescription(schema));
492
506
  }
493
- if (typeName === "array") {
494
- const element = def?.element ?? schema.element;
507
+ if (kind === "array") {
508
+ const element = def.element ?? def.type ?? schema.element;
495
509
  if (element) {
496
- const arrDesc = schema.description ?? def?.description ?? schema._zod?.def?.description;
497
- const result = import_zod.z.array(toStrictSchema(element));
498
- return arrDesc ? result.describe(arrDesc) : result;
510
+ return withDescription(import_zod.z.array(toStrictSchema(element)), schemaDescription(schema));
499
511
  }
500
512
  return schema;
501
513
  }
502
- if (typeName === "nullable") {
514
+ if (kind === "nullable") {
503
515
  const innerType = def?.innerType;
504
516
  if (innerType) {
505
- const nullDesc = schema.description ?? def?.description ?? schema._zod?.def?.description;
506
- const result = import_zod.z.nullable(toStrictSchema(innerType));
507
- return nullDesc ? result.describe(nullDesc) : result;
517
+ return withDescription(import_zod.z.nullable(toStrictSchema(innerType)), schemaDescription(schema));
518
+ }
519
+ return schema;
520
+ }
521
+ if (kind === "default") {
522
+ const innerType = def?.innerType;
523
+ if (innerType) {
524
+ return withDescription(import_zod.z.nullable(toStrictSchema(innerType)), schemaDescription(schema));
508
525
  }
509
526
  return schema;
510
527
  }
@@ -10219,6 +10236,8 @@ Rules:
10219
10236
  - Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
10220
10237
  - When changing a term's semantic meaning, set kind to the corrected normalized term kind.
10221
10238
  - Do not add new coverage rows or new terms; this pass cleans the existing projection.
10239
+ - Include every JSON key in each decision. Use null for scalar fields you are not changing and [] for source ID lists you are not changing.
10240
+ - For each coverage decision, always include termDecisions. Use [] when no terms need cleanup.
10222
10241
  - Keep reasons concise and factual.
10223
10242
 
10224
10243
  Candidate projection:
@@ -10229,9 +10248,6 @@ ${JSON.stringify(nodes, null, 2)}
10229
10248
 
10230
10249
  Return JSON with coverageDecisions and warnings only.`;
10231
10250
  }
10232
- function hasOwn(object, key) {
10233
- return Object.prototype.hasOwnProperty.call(object, key);
10234
- }
10235
10251
  function uniqueStrings(values) {
10236
10252
  return [...new Set(values.filter((value) => value.length > 0))];
10237
10253
  }
@@ -10306,18 +10322,16 @@ function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
10306
10322
  sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, term.sourceSpanIds)
10307
10323
  };
10308
10324
  if (next.sourceNodeIds.length === 0 && next.sourceSpanIds.length === 0) return term;
10309
- if (hasOwn(decision, "amount")) {
10310
- if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) next.amount = decision.amount;
10311
- else delete next.amount;
10325
+ if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) {
10326
+ next.amount = decision.amount;
10312
10327
  } else if (decision.value || decision.kind) {
10313
10328
  const amount = next.kind === "retroactive_date" ? void 0 : amountFromOperationalValue(next.value);
10314
10329
  if (amount === void 0) delete next.amount;
10315
10330
  else next.amount = amount;
10316
10331
  }
10317
- if (hasOwn(decision, "appliesTo")) {
10332
+ if (decision.appliesTo != null) {
10318
10333
  const appliesTo = cleanProfileValue(decision.appliesTo);
10319
10334
  if (appliesTo) next.appliesTo = appliesTo;
10320
- else delete next.appliesTo;
10321
10335
  }
10322
10336
  return next;
10323
10337
  }
@@ -10336,46 +10350,42 @@ function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpa
10336
10350
  const name = cleanProfileValue(decision.name);
10337
10351
  if (name) next.name = name;
10338
10352
  if (decision.coverageOrigin) next.coverageOrigin = decision.coverageOrigin;
10339
- if (hasOwn(decision, "limit")) {
10353
+ if (decision.limit != null) {
10340
10354
  const value = cleanProfileValue(decision.limit);
10341
10355
  if (value) next.limit = value;
10342
- else delete next.limit;
10343
10356
  }
10344
- if (hasOwn(decision, "deductible")) {
10357
+ if (decision.deductible != null) {
10345
10358
  const value = cleanProfileValue(decision.deductible);
10346
10359
  if (value) next.deductible = value;
10347
- else delete next.deductible;
10348
10360
  }
10349
- if (hasOwn(decision, "premium")) {
10361
+ if (decision.premium != null) {
10350
10362
  const value = cleanProfileValue(decision.premium);
10351
10363
  if (value) next.premium = value;
10352
- else delete next.premium;
10353
10364
  }
10354
- if (hasOwn(decision, "retroactiveDate")) {
10365
+ if (decision.retroactiveDate != null) {
10355
10366
  const value = cleanProfileValue(decision.retroactiveDate);
10356
10367
  if (value) next.retroactiveDate = value;
10357
- else delete next.retroactiveDate;
10358
10368
  }
10359
10369
  const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
10360
10370
  const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
10361
10371
  next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
10362
10372
  if (termDecisions.length > 0) {
10363
- if (!hasOwn(decision, "limit") && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
10373
+ if (decision.limit == null && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
10364
10374
  const value = primaryLimitFromTerms(next.limits);
10365
10375
  if (value) next.limit = value;
10366
10376
  else delete next.limit;
10367
10377
  }
10368
- if (!hasOwn(decision, "deductible") && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
10378
+ if (decision.deductible == null && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
10369
10379
  const value = deductibleFromTerms(next.limits);
10370
10380
  if (value) next.deductible = value;
10371
10381
  else delete next.deductible;
10372
10382
  }
10373
- if (!hasOwn(decision, "premium") && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
10383
+ if (decision.premium == null && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
10374
10384
  const value = premiumFromTerms(next.limits);
10375
10385
  if (value) next.premium = value;
10376
10386
  else delete next.premium;
10377
10387
  }
10378
- if (!hasOwn(decision, "retroactiveDate") && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
10388
+ if (decision.retroactiveDate == null && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
10379
10389
  const value = retroactiveDateFromTerms(next.limits);
10380
10390
  if (value) next.retroactiveDate = value;
10381
10391
  else delete next.retroactiveDate;