@holoscript/plugin-insurance 2.0.1 → 2.0.2

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.
@@ -1,23 +1,77 @@
1
1
  /** @claim Trait — Insurance claim processing. @trait claim */
2
2
  import type { TraitHandler, HSPlusNode, TraitContext, TraitEvent } from './types';
3
3
 
4
- export type ClaimStatus = 'filed' | 'under_review' | 'approved' | 'denied' | 'paid' | 'appealed' | 'closed';
5
- export interface ClaimConfig { claimNumber: string; policyNumber: string; dateOfLoss: string; description: string; claimAmount: number; claimantName: string; }
6
- export interface ClaimState { status: ClaimStatus; approvedAmount: number; adjusterAssigned: string | null; filedAt: number; }
4
+ export type ClaimStatus =
5
+ | 'filed'
6
+ | 'under_review'
7
+ | 'approved'
8
+ | 'denied'
9
+ | 'paid'
10
+ | 'appealed'
11
+ | 'closed';
12
+ export interface ClaimConfig {
13
+ claimNumber: string;
14
+ policyNumber: string;
15
+ dateOfLoss: string;
16
+ description: string;
17
+ claimAmount: number;
18
+ claimantName: string;
19
+ }
20
+ export interface ClaimState {
21
+ status: ClaimStatus;
22
+ approvedAmount: number;
23
+ adjusterAssigned: string | null;
24
+ filedAt: number;
25
+ }
7
26
 
8
- const defaultConfig: ClaimConfig = { claimNumber: '', policyNumber: '', dateOfLoss: '', description: '', claimAmount: 0, claimantName: '' };
27
+ const defaultConfig: ClaimConfig = {
28
+ claimNumber: '',
29
+ policyNumber: '',
30
+ dateOfLoss: '',
31
+ description: '',
32
+ claimAmount: 0,
33
+ claimantName: '',
34
+ };
9
35
 
10
36
  export function createClaimHandler(): TraitHandler<ClaimConfig> {
11
- return { name: 'claim', defaultConfig,
12
- onAttach(n: HSPlusNode, _c: ClaimConfig, ctx: TraitContext) { n.__claimState = { status: 'filed' as ClaimStatus, approvedAmount: 0, adjusterAssigned: null, filedAt: Date.now() }; ctx.emit?.('claim:filed'); },
13
- onDetach(n: HSPlusNode, _c: ClaimConfig, ctx: TraitContext) { delete n.__claimState; ctx.emit?.('claim:removed'); },
37
+ return {
38
+ name: 'claim',
39
+ defaultConfig,
40
+ onAttach(n: HSPlusNode, _c: ClaimConfig, ctx: TraitContext) {
41
+ n.__claimState = {
42
+ status: 'filed' as ClaimStatus,
43
+ approvedAmount: 0,
44
+ adjusterAssigned: null,
45
+ filedAt: Date.now(),
46
+ };
47
+ ctx.emit?.('claim:filed');
48
+ },
49
+ onDetach(n: HSPlusNode, _c: ClaimConfig, ctx: TraitContext) {
50
+ delete n.__claimState;
51
+ ctx.emit?.('claim:removed');
52
+ },
14
53
  onUpdate() {},
15
54
  onEvent(n: HSPlusNode, c: ClaimConfig, ctx: TraitContext, e: TraitEvent) {
16
- const s = n.__claimState as ClaimState | undefined; if (!s) return;
17
- if (e.type === 'claim:assign_adjuster') { s.adjusterAssigned = (e.payload?.adjuster as string) ?? null; s.status = 'under_review'; ctx.emit?.('claim:reviewing', { adjuster: s.adjusterAssigned }); }
18
- if (e.type === 'claim:approve') { s.status = 'approved'; s.approvedAmount = (e.payload?.amount as number) ?? c.claimAmount; ctx.emit?.('claim:approved', { amount: s.approvedAmount }); }
19
- if (e.type === 'claim:deny') { s.status = 'denied'; ctx.emit?.('claim:denied', { reason: e.payload?.reason }); }
20
- if (e.type === 'claim:pay') { s.status = 'paid'; ctx.emit?.('claim:paid', { amount: s.approvedAmount }); }
55
+ const s = n.__claimState as ClaimState | undefined;
56
+ if (!s) return;
57
+ if (e.type === 'claim:assign_adjuster') {
58
+ s.adjusterAssigned = (e.payload?.adjuster as string) ?? null;
59
+ s.status = 'under_review';
60
+ ctx.emit?.('claim:reviewing', { adjuster: s.adjusterAssigned });
61
+ }
62
+ if (e.type === 'claim:approve') {
63
+ s.status = 'approved';
64
+ s.approvedAmount = (e.payload?.amount as number) ?? c.claimAmount;
65
+ ctx.emit?.('claim:approved', { amount: s.approvedAmount });
66
+ }
67
+ if (e.type === 'claim:deny') {
68
+ s.status = 'denied';
69
+ ctx.emit?.('claim:denied', { reason: e.payload?.reason });
70
+ }
71
+ if (e.type === 'claim:pay') {
72
+ s.status = 'paid';
73
+ ctx.emit?.('claim:paid', { amount: s.approvedAmount });
74
+ }
21
75
  },
22
76
  };
23
77
  }
@@ -3,20 +3,63 @@ import type { TraitHandler, HSPlusNode, TraitContext, TraitEvent } from './types
3
3
 
4
4
  export type PolicyType = 'life' | 'health' | 'auto' | 'home' | 'commercial' | 'liability' | 'cyber';
5
5
  export type PolicyStatus = 'quoted' | 'bound' | 'active' | 'lapsed' | 'cancelled' | 'expired';
6
- export interface PolicyConfig { policyNumber: string; type: PolicyType; insuredName: string; premium: number; coverageAmount: number; deductible: number; effectiveDate: string; expirationDate: string; }
7
- export interface PolicyState { status: PolicyStatus; claimCount: number; totalPaidClaims: number; remainingCoverage: number; }
6
+ export interface PolicyConfig {
7
+ policyNumber: string;
8
+ type: PolicyType;
9
+ insuredName: string;
10
+ premium: number;
11
+ coverageAmount: number;
12
+ deductible: number;
13
+ effectiveDate: string;
14
+ expirationDate: string;
15
+ }
16
+ export interface PolicyState {
17
+ status: PolicyStatus;
18
+ claimCount: number;
19
+ totalPaidClaims: number;
20
+ remainingCoverage: number;
21
+ }
8
22
 
9
- const defaultConfig: PolicyConfig = { policyNumber: '', type: 'auto', insuredName: '', premium: 0, coverageAmount: 0, deductible: 0, effectiveDate: '', expirationDate: '' };
23
+ const defaultConfig: PolicyConfig = {
24
+ policyNumber: '',
25
+ type: 'auto',
26
+ insuredName: '',
27
+ premium: 0,
28
+ coverageAmount: 0,
29
+ deductible: 0,
30
+ effectiveDate: '',
31
+ expirationDate: '',
32
+ };
10
33
 
11
34
  export function createPolicyHandler(): TraitHandler<PolicyConfig> {
12
- return { name: 'policy', defaultConfig,
13
- onAttach(n: HSPlusNode, c: PolicyConfig, ctx: TraitContext) { n.__policyState = { status: 'active' as PolicyStatus, claimCount: 0, totalPaidClaims: 0, remainingCoverage: c.coverageAmount }; ctx.emit?.('policy:bound', { type: c.type, coverage: c.coverageAmount }); },
14
- onDetach(n: HSPlusNode, _c: PolicyConfig, ctx: TraitContext) { delete n.__policyState; ctx.emit?.('policy:removed'); },
35
+ return {
36
+ name: 'policy',
37
+ defaultConfig,
38
+ onAttach(n: HSPlusNode, c: PolicyConfig, ctx: TraitContext) {
39
+ n.__policyState = {
40
+ status: 'active' as PolicyStatus,
41
+ claimCount: 0,
42
+ totalPaidClaims: 0,
43
+ remainingCoverage: c.coverageAmount,
44
+ };
45
+ ctx.emit?.('policy:bound', { type: c.type, coverage: c.coverageAmount });
46
+ },
47
+ onDetach(n: HSPlusNode, _c: PolicyConfig, ctx: TraitContext) {
48
+ delete n.__policyState;
49
+ ctx.emit?.('policy:removed');
50
+ },
15
51
  onUpdate() {},
16
52
  onEvent(n: HSPlusNode, _c: PolicyConfig, ctx: TraitContext, e: TraitEvent) {
17
- const s = n.__policyState as PolicyState | undefined; if (!s) return;
18
- if (e.type === 'policy:cancel') { s.status = 'cancelled'; ctx.emit?.('policy:cancelled'); }
19
- if (e.type === 'policy:renew') { s.status = 'active'; ctx.emit?.('policy:renewed'); }
53
+ const s = n.__policyState as PolicyState | undefined;
54
+ if (!s) return;
55
+ if (e.type === 'policy:cancel') {
56
+ s.status = 'cancelled';
57
+ ctx.emit?.('policy:cancelled');
58
+ }
59
+ if (e.type === 'policy:renew') {
60
+ s.status = 'active';
61
+ ctx.emit?.('policy:renewed');
62
+ }
20
63
  },
21
64
  };
22
65
  }
@@ -1,25 +1,51 @@
1
1
  /** @risk_assessment Trait — Actuarial risk scoring. @trait risk_assessment */
2
2
  import type { TraitHandler, HSPlusNode, TraitContext, TraitEvent } from './types';
3
3
 
4
- export interface RiskFactor { name: string; weight: number; value: number; maxValue: number; }
5
- export interface RiskAssessmentConfig { factors: RiskFactor[]; baseRate: number; riskClass: 'preferred' | 'standard' | 'substandard' | 'declined'; maxRiskScore: number; }
4
+ export interface RiskFactor {
5
+ name: string;
6
+ weight: number;
7
+ value: number;
8
+ maxValue: number;
9
+ }
10
+ export interface RiskAssessmentConfig {
11
+ factors: RiskFactor[];
12
+ baseRate: number;
13
+ riskClass: 'preferred' | 'standard' | 'substandard' | 'declined';
14
+ maxRiskScore: number;
15
+ }
6
16
 
7
- const defaultConfig: RiskAssessmentConfig = { factors: [], baseRate: 100, riskClass: 'standard', maxRiskScore: 100 };
17
+ const defaultConfig: RiskAssessmentConfig = {
18
+ factors: [],
19
+ baseRate: 100,
20
+ riskClass: 'standard',
21
+ maxRiskScore: 100,
22
+ };
8
23
 
9
24
  export function createRiskAssessmentHandler(): TraitHandler<RiskAssessmentConfig> {
10
- return { name: 'risk_assessment', defaultConfig,
25
+ return {
26
+ name: 'risk_assessment',
27
+ defaultConfig,
11
28
  onAttach(n: HSPlusNode, c: RiskAssessmentConfig, ctx: TraitContext) {
12
29
  const score = c.factors.reduce((s, f) => s + (f.value / f.maxValue) * f.weight, 0);
13
- n.__riskAssessState = { riskScore: Math.min(c.maxRiskScore, score), adjustedPremium: c.baseRate * (1 + score / 100), isAcceptable: c.riskClass !== 'declined' };
30
+ n.__riskAssessState = {
31
+ riskScore: Math.min(c.maxRiskScore, score),
32
+ adjustedPremium: c.baseRate * (1 + score / 100),
33
+ isAcceptable: c.riskClass !== 'declined',
34
+ };
14
35
  ctx.emit?.('risk_assessment:scored', { score, riskClass: c.riskClass });
15
36
  },
16
- onDetach(n: HSPlusNode, _c: RiskAssessmentConfig, ctx: TraitContext) { delete n.__riskAssessState; ctx.emit?.('risk_assessment:removed'); },
37
+ onDetach(n: HSPlusNode, _c: RiskAssessmentConfig, ctx: TraitContext) {
38
+ delete n.__riskAssessState;
39
+ ctx.emit?.('risk_assessment:removed');
40
+ },
17
41
  onUpdate() {},
18
42
  onEvent(n: HSPlusNode, c: RiskAssessmentConfig, ctx: TraitContext, e: TraitEvent) {
19
43
  if (e.type === 'risk_assessment:recalculate') {
20
- const s = n.__riskAssessState as Record<string, unknown> | undefined; if (!s) return;
44
+ const s = n.__riskAssessState as Record<string, unknown> | undefined;
45
+ if (!s) return;
21
46
  const score = c.factors.reduce((sum, f) => sum + (f.value / f.maxValue) * f.weight, 0);
22
- s.riskScore = Math.min(c.maxRiskScore, score); s.adjustedPremium = c.baseRate * (1 + score / 100);
47
+ s.riskScore = Math.min(c.maxRiskScore, score);
48
+ s.adjustedPremium = c.baseRate * (1 + score / 100);
23
49
  ctx.emit?.('risk_assessment:updated', { score, premium: s.adjustedPremium });
24
50
  }
25
51
  },
@@ -2,27 +2,62 @@
2
2
  import type { TraitHandler, HSPlusNode, TraitContext, TraitEvent } from './types';
3
3
 
4
4
  export type UnderwritingDecision = 'approve' | 'approve_with_conditions' | 'refer' | 'decline';
5
- export interface UnderwritingConfig { applicationId: string; riskScore: number; requestedCoverage: number; maxAutoCoverage: number; referralThreshold: number; declineThreshold: number; conditions: string[]; }
6
- export interface UnderwritingState { decision: UnderwritingDecision | null; reviewedAt: number | null; underwriterId: string | null; }
5
+ export interface UnderwritingConfig {
6
+ applicationId: string;
7
+ riskScore: number;
8
+ requestedCoverage: number;
9
+ maxAutoCoverage: number;
10
+ referralThreshold: number;
11
+ declineThreshold: number;
12
+ conditions: string[];
13
+ }
14
+ export interface UnderwritingState {
15
+ decision: UnderwritingDecision | null;
16
+ reviewedAt: number | null;
17
+ underwriterId: string | null;
18
+ }
7
19
 
8
- const defaultConfig: UnderwritingConfig = { applicationId: '', riskScore: 0, requestedCoverage: 0, maxAutoCoverage: 500000, referralThreshold: 70, declineThreshold: 90, conditions: [] };
20
+ const defaultConfig: UnderwritingConfig = {
21
+ applicationId: '',
22
+ riskScore: 0,
23
+ requestedCoverage: 0,
24
+ maxAutoCoverage: 500000,
25
+ referralThreshold: 70,
26
+ declineThreshold: 90,
27
+ conditions: [],
28
+ };
9
29
 
10
30
  export function createUnderwritingHandler(): TraitHandler<UnderwritingConfig> {
11
- return { name: 'underwriting', defaultConfig,
12
- onAttach(n: HSPlusNode, _c: UnderwritingConfig, ctx: TraitContext) { n.__uwState = { decision: null, reviewedAt: null, underwriterId: null }; ctx.emit?.('underwriting:submitted'); },
13
- onDetach(n: HSPlusNode, _c: UnderwritingConfig, ctx: TraitContext) { delete n.__uwState; ctx.emit?.('underwriting:removed'); },
31
+ return {
32
+ name: 'underwriting',
33
+ defaultConfig,
34
+ onAttach(n: HSPlusNode, _c: UnderwritingConfig, ctx: TraitContext) {
35
+ n.__uwState = { decision: null, reviewedAt: null, underwriterId: null };
36
+ ctx.emit?.('underwriting:submitted');
37
+ },
38
+ onDetach(n: HSPlusNode, _c: UnderwritingConfig, ctx: TraitContext) {
39
+ delete n.__uwState;
40
+ ctx.emit?.('underwriting:removed');
41
+ },
14
42
  onUpdate() {},
15
43
  onEvent(n: HSPlusNode, c: UnderwritingConfig, ctx: TraitContext, e: TraitEvent) {
16
- const s = n.__uwState as UnderwritingState | undefined; if (!s) return;
44
+ const s = n.__uwState as UnderwritingState | undefined;
45
+ if (!s) return;
17
46
  if (e.type === 'underwriting:auto_decide') {
18
47
  if (c.riskScore >= c.declineThreshold) s.decision = 'decline';
19
- else if (c.riskScore >= c.referralThreshold || c.requestedCoverage > c.maxAutoCoverage) s.decision = 'refer';
48
+ else if (c.riskScore >= c.referralThreshold || c.requestedCoverage > c.maxAutoCoverage)
49
+ s.decision = 'refer';
20
50
  else if (c.conditions.length > 0) s.decision = 'approve_with_conditions';
21
51
  else s.decision = 'approve';
22
52
  s.reviewedAt = Date.now();
23
53
  ctx.emit?.('underwriting:decided', { decision: s.decision, riskScore: c.riskScore });
24
54
  }
25
- if (e.type === 'underwriting:manual_decide') { s.decision = (e.payload?.decision as UnderwritingDecision) ?? 'refer'; s.underwriterId = (e.payload?.underwriterId as string) ?? null; s.reviewedAt = Date.now(); ctx.emit?.('underwriting:manual_decision', { decision: s.decision }); }
55
+ if (e.type === 'underwriting:manual_decide') {
56
+ s.decision = (e.payload?.decision as UnderwritingDecision) ?? 'refer';
57
+ s.underwriterId = (e.payload?.underwriterId as string) ?? null;
58
+ s.reviewedAt = Date.now();
59
+ ctx.emit?.('underwriting:manual_decision', { decision: s.decision });
60
+ }
26
61
  },
27
62
  };
28
63
  }
@@ -1,4 +1,22 @@
1
- export interface HSPlusNode { id?: string; properties?: Record<string, unknown>; [key: string]: unknown; }
2
- export interface TraitContext { emit?: (event: string, payload?: unknown) => void; [key: string]: unknown; }
3
- export interface TraitEvent { type: string; payload?: Record<string, unknown>; [key: string]: unknown; }
4
- export interface TraitHandler<T = unknown> { name: string; defaultConfig: T; onAttach(n: HSPlusNode, c: T, ctx: TraitContext): void; onDetach(n: HSPlusNode, c: T, ctx: TraitContext): void; onUpdate(n: HSPlusNode, c: T, ctx: TraitContext, d: number): void; onEvent(n: HSPlusNode, c: T, ctx: TraitContext, e: TraitEvent): void; }
1
+ export interface HSPlusNode {
2
+ id?: string;
3
+ properties?: Record<string, unknown>;
4
+ [key: string]: unknown;
5
+ }
6
+ export interface TraitContext {
7
+ emit?: (event: string, payload?: unknown) => void;
8
+ [key: string]: unknown;
9
+ }
10
+ export interface TraitEvent {
11
+ type: string;
12
+ payload?: Record<string, unknown>;
13
+ [key: string]: unknown;
14
+ }
15
+ export interface TraitHandler<T = unknown> {
16
+ name: string;
17
+ defaultConfig: T;
18
+ onAttach(n: HSPlusNode, c: T, ctx: TraitContext): void;
19
+ onDetach(n: HSPlusNode, c: T, ctx: TraitContext): void;
20
+ onUpdate(n: HSPlusNode, c: T, ctx: TraitContext, d: number): void;
21
+ onEvent(n: HSPlusNode, c: T, ctx: TraitContext, e: TraitEvent): void;
22
+ }
package/tsconfig.json CHANGED
@@ -1 +1,5 @@
1
- { "extends": "../../../tsconfig.json", "compilerOptions": { "outDir": "dist", "rootDir": "src", "declaration": true }, "include": ["src"] }
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": { "outDir": "dist", "rootDir": "src", "declaration": true },
4
+ "include": ["src"]
5
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025-2026 HoloScript Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.