@insureco/bio 0.3.0 → 0.5.0
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/chunk-NK5VXXWF.mjs +43 -0
- package/dist/chunk-PLN6QPED.mjs +169 -0
- package/dist/graph.d.mts +204 -0
- package/dist/graph.d.ts +204 -0
- package/dist/graph.js +225 -0
- package/dist/graph.mjs +7 -0
- package/dist/index.d.mts +4 -265
- package/dist/index.d.ts +4 -265
- package/dist/index.js +161 -0
- package/dist/index.mjs +11 -37
- package/dist/types-Dkb-drHZ.d.mts +302 -0
- package/dist/types-Dkb-drHZ.d.ts +302 -0
- package/dist/users.d.mts +45 -0
- package/dist/users.d.ts +45 -0
- package/dist/users.js +185 -0
- package/dist/users.mjs +128 -0
- package/package.json +12 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var BioError = class extends Error {
|
|
3
|
+
/** HTTP status code (if from an API response) */
|
|
4
|
+
statusCode;
|
|
5
|
+
/** Machine-readable error code (e.g. 'invalid_grant', 'token_expired') */
|
|
6
|
+
code;
|
|
7
|
+
/** Additional error details from the API */
|
|
8
|
+
details;
|
|
9
|
+
constructor(message, code, statusCode, details) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "BioError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/utils.ts
|
|
19
|
+
function retryDelay(attempt) {
|
|
20
|
+
const baseDelay = Math.min(1e3 * 2 ** attempt, 5e3);
|
|
21
|
+
return baseDelay * (0.5 + Math.random() * 0.5);
|
|
22
|
+
}
|
|
23
|
+
function sleep(ms) {
|
|
24
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
25
|
+
}
|
|
26
|
+
async function parseJsonResponse(response) {
|
|
27
|
+
try {
|
|
28
|
+
return await response.json();
|
|
29
|
+
} catch {
|
|
30
|
+
throw new BioError(
|
|
31
|
+
`Bio-ID returned ${response.status} with non-JSON body`,
|
|
32
|
+
"parse_error",
|
|
33
|
+
response.status
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
BioError,
|
|
40
|
+
retryDelay,
|
|
41
|
+
sleep,
|
|
42
|
+
parseJsonResponse
|
|
43
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BioError,
|
|
3
|
+
parseJsonResponse,
|
|
4
|
+
retryDelay,
|
|
5
|
+
sleep
|
|
6
|
+
} from "./chunk-NK5VXXWF.mjs";
|
|
7
|
+
|
|
8
|
+
// src/graph.ts
|
|
9
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
10
|
+
var BIO_GRAPH_URL = "https://bio-graph.tawa.pro";
|
|
11
|
+
var GraphClient = class _GraphClient {
|
|
12
|
+
graphUrl;
|
|
13
|
+
accessToken;
|
|
14
|
+
timeoutMs;
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
this.graphUrl = (config.graphUrl ?? process.env.BIO_GRAPH_URL ?? BIO_GRAPH_URL).replace(/\/$/, "");
|
|
17
|
+
this.accessToken = config.accessToken;
|
|
18
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a GraphClient from environment variables.
|
|
22
|
+
* BIO_GRAPH_URL defaults to https://bio-graph.tawa.pro if not set.
|
|
23
|
+
*/
|
|
24
|
+
static fromEnv(overrides) {
|
|
25
|
+
return new _GraphClient({
|
|
26
|
+
graphUrl: overrides?.graphUrl ?? process.env.BIO_GRAPH_URL,
|
|
27
|
+
accessToken: overrides?.accessToken,
|
|
28
|
+
timeoutMs: overrides?.timeoutMs
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// ─── Public Profile Routes ────────────────────────────────────────────────
|
|
32
|
+
/** Look up an agent by NPN. Returns agent properties + employment chain. */
|
|
33
|
+
async getAgent(npn) {
|
|
34
|
+
return this.get(`/api/graph/agent/${encodeURIComponent(npn)}`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Look up an agency by iecHash, raterspotId, or orgSlug.
|
|
38
|
+
* Returns agency properties + staff list + accessible programs.
|
|
39
|
+
*/
|
|
40
|
+
async getAgency(iecHash) {
|
|
41
|
+
return this.get(`/api/graph/agency/${encodeURIComponent(iecHash)}`);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Look up a carrier by NAIC code, iecHash, raterspotId, or orgSlug.
|
|
45
|
+
* Returns carrier properties + managed programs.
|
|
46
|
+
*/
|
|
47
|
+
async getCarrier(naic) {
|
|
48
|
+
return this.get(`/api/graph/carrier/${encodeURIComponent(naic)}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Look up a program by iecHash or raterspotId.
|
|
52
|
+
* Returns program properties + managing carrier or MGA.
|
|
53
|
+
*/
|
|
54
|
+
async getProgram(iecHash) {
|
|
55
|
+
return this.get(`/api/graph/program/${encodeURIComponent(iecHash)}`);
|
|
56
|
+
}
|
|
57
|
+
// ─── Authenticated Routes ─────────────────────────────────────────────────
|
|
58
|
+
/**
|
|
59
|
+
* Find programs whose appetite covers a given risk.
|
|
60
|
+
* Requires an accessToken (auth: required).
|
|
61
|
+
*
|
|
62
|
+
* @param input - Risk criteria: NAICS code, state, line of business, optional limits
|
|
63
|
+
*/
|
|
64
|
+
async matchAppetite(input) {
|
|
65
|
+
return this.post("/api/graph/appetite/match", input, { requiresAuth: true });
|
|
66
|
+
}
|
|
67
|
+
// ─── Internal ─────────────────────────────────────────────────────────────
|
|
68
|
+
async get(path, attempt = 0) {
|
|
69
|
+
const url = `${this.graphUrl}${path}`;
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
72
|
+
let response;
|
|
73
|
+
try {
|
|
74
|
+
response = await fetch(url, {
|
|
75
|
+
headers: this.buildHeaders(),
|
|
76
|
+
signal: controller.signal
|
|
77
|
+
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
81
|
+
if (!isTimeout && attempt < 2) {
|
|
82
|
+
await sleep(retryDelay(attempt));
|
|
83
|
+
return this.get(path, attempt + 1);
|
|
84
|
+
}
|
|
85
|
+
throw new BioError(
|
|
86
|
+
isTimeout ? "bio-graph request timed out" : `bio-graph request failed: ${String(err)}`,
|
|
87
|
+
isTimeout ? "timeout" : "network_error"
|
|
88
|
+
);
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
return this.handleResponse(response, path);
|
|
93
|
+
}
|
|
94
|
+
async post(path, body, opts = {}, attempt = 0) {
|
|
95
|
+
if (opts.requiresAuth && !this.accessToken) {
|
|
96
|
+
throw new BioError(
|
|
97
|
+
`bio-graph ${path} requires an accessToken \u2014 pass it in the GraphClient constructor`,
|
|
98
|
+
"config_error"
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const url = `${this.graphUrl}${path}`;
|
|
102
|
+
const controller = new AbortController();
|
|
103
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await fetch(url, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: { ...this.buildHeaders(), "Content-Type": "application/json" },
|
|
109
|
+
body: JSON.stringify(body),
|
|
110
|
+
signal: controller.signal
|
|
111
|
+
});
|
|
112
|
+
} catch (err) {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
115
|
+
if (!isTimeout && attempt < 2) {
|
|
116
|
+
await sleep(retryDelay(attempt));
|
|
117
|
+
return this.post(path, body, opts, attempt + 1);
|
|
118
|
+
}
|
|
119
|
+
throw new BioError(
|
|
120
|
+
isTimeout ? "bio-graph request timed out" : `bio-graph request failed: ${String(err)}`,
|
|
121
|
+
isTimeout ? "timeout" : "network_error"
|
|
122
|
+
);
|
|
123
|
+
} finally {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
}
|
|
126
|
+
return this.handleResponse(response, path);
|
|
127
|
+
}
|
|
128
|
+
buildHeaders() {
|
|
129
|
+
const headers = {};
|
|
130
|
+
if (this.accessToken) {
|
|
131
|
+
headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
132
|
+
}
|
|
133
|
+
return headers;
|
|
134
|
+
}
|
|
135
|
+
async handleResponse(response, path) {
|
|
136
|
+
if (response.status === 404) {
|
|
137
|
+
throw new BioError(`bio-graph entity not found: ${path}`, "not_found", 404);
|
|
138
|
+
}
|
|
139
|
+
if (response.status === 401) {
|
|
140
|
+
throw new BioError(
|
|
141
|
+
"bio-graph authentication failed \u2014 provide a valid accessToken",
|
|
142
|
+
"unauthorized",
|
|
143
|
+
401
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (response.status === 402) {
|
|
147
|
+
throw new BioError(
|
|
148
|
+
"bio-graph call failed \u2014 insufficient gas tokens. Top up at tawa.insureco.io/wallet",
|
|
149
|
+
"insufficient_gas",
|
|
150
|
+
402
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
const body2 = await parseJsonResponse(response).catch(() => ({}));
|
|
155
|
+
throw new BioError(
|
|
156
|
+
`bio-graph returned ${response.status} for ${path}`,
|
|
157
|
+
"api_error",
|
|
158
|
+
response.status,
|
|
159
|
+
body2
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
const body = await parseJsonResponse(response);
|
|
163
|
+
return body;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export {
|
|
168
|
+
GraphClient
|
|
169
|
+
};
|
package/dist/graph.d.mts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
interface GraphClientConfig {
|
|
2
|
+
/** Base URL for bio-graph service. Defaults to BIO_GRAPH_URL env var or https://bio-graph.tawa.pro */
|
|
3
|
+
graphUrl?: string;
|
|
4
|
+
/** Bearer token for authenticated routes (appetite/match, same-as-queue, etc.) */
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
/** Request timeout in ms. Default: 10_000 */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
interface AgentEmployer {
|
|
10
|
+
agencyName: string | null;
|
|
11
|
+
agencyIecHash: string | null;
|
|
12
|
+
agencyOrgSlug: string | null;
|
|
13
|
+
agencyRaterspotId: string | null;
|
|
14
|
+
current: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface AgentProfile {
|
|
17
|
+
iecHash: string | null;
|
|
18
|
+
name: string | null;
|
|
19
|
+
npn: string | null;
|
|
20
|
+
bioId: string | null;
|
|
21
|
+
role: string | null;
|
|
22
|
+
email: string | null;
|
|
23
|
+
phone: string | null;
|
|
24
|
+
address: string | null;
|
|
25
|
+
city: string | null;
|
|
26
|
+
state: string | null;
|
|
27
|
+
zip: string | null;
|
|
28
|
+
licenseNo: string | null;
|
|
29
|
+
status: string | null;
|
|
30
|
+
linesOfAuthority: string[];
|
|
31
|
+
territories: string[];
|
|
32
|
+
linesOfBusiness: string[];
|
|
33
|
+
isPublic: boolean;
|
|
34
|
+
claimedAt: string | null;
|
|
35
|
+
employment: AgentEmployer[];
|
|
36
|
+
}
|
|
37
|
+
interface AgencyStaffMember {
|
|
38
|
+
name: string | null;
|
|
39
|
+
npn: string | null;
|
|
40
|
+
iecHash: string | null;
|
|
41
|
+
role: string | null;
|
|
42
|
+
email: string | null;
|
|
43
|
+
}
|
|
44
|
+
interface AgencyProgram {
|
|
45
|
+
name: string | null;
|
|
46
|
+
raterspotId: string | null;
|
|
47
|
+
iecHash: string | null;
|
|
48
|
+
states: string[];
|
|
49
|
+
carrierName: string | null;
|
|
50
|
+
isActive: boolean;
|
|
51
|
+
}
|
|
52
|
+
interface AgencyProfile {
|
|
53
|
+
iecHash: string | null;
|
|
54
|
+
raterspotId: string | null;
|
|
55
|
+
name: string | null;
|
|
56
|
+
orgSlug: string | null;
|
|
57
|
+
orgId: string | null;
|
|
58
|
+
type: string | null;
|
|
59
|
+
email: string | null;
|
|
60
|
+
phone: string | null;
|
|
61
|
+
website: string | null;
|
|
62
|
+
address: string | null;
|
|
63
|
+
city: string | null;
|
|
64
|
+
state: string | null;
|
|
65
|
+
zip: string | null;
|
|
66
|
+
dba: string | null;
|
|
67
|
+
licenseNo: string | null;
|
|
68
|
+
linesOfAuthority: string | null;
|
|
69
|
+
territories: string[];
|
|
70
|
+
linesOfBusiness: string[];
|
|
71
|
+
isPublic: boolean;
|
|
72
|
+
claimedAt: string | null;
|
|
73
|
+
staff: AgencyStaffMember[];
|
|
74
|
+
programs: AgencyProgram[];
|
|
75
|
+
}
|
|
76
|
+
interface CarrierProgram {
|
|
77
|
+
name: string | null;
|
|
78
|
+
iecHash: string | null;
|
|
79
|
+
raterspotId: string | null;
|
|
80
|
+
states: string[];
|
|
81
|
+
isActive: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface CarrierProfile {
|
|
84
|
+
iecHash: string | null;
|
|
85
|
+
raterspotId: string | null;
|
|
86
|
+
name: string | null;
|
|
87
|
+
naic: string | null;
|
|
88
|
+
orgId: string | null;
|
|
89
|
+
orgSlug: string | null;
|
|
90
|
+
email: string | null;
|
|
91
|
+
phone: string | null;
|
|
92
|
+
website: string | null;
|
|
93
|
+
address: string | null;
|
|
94
|
+
city: string | null;
|
|
95
|
+
state: string | null;
|
|
96
|
+
isPublic: boolean;
|
|
97
|
+
claimedAt: string | null;
|
|
98
|
+
programs: CarrierProgram[];
|
|
99
|
+
}
|
|
100
|
+
interface ProgramProfile {
|
|
101
|
+
iecHash: string | null;
|
|
102
|
+
raterspotId: string | null;
|
|
103
|
+
name: string | null;
|
|
104
|
+
abrv: string | null;
|
|
105
|
+
states: string[];
|
|
106
|
+
isActive: boolean;
|
|
107
|
+
ratingEngine: string | null;
|
|
108
|
+
carrierName: string | null;
|
|
109
|
+
carrierNaic: string | null;
|
|
110
|
+
mgaName: string | null;
|
|
111
|
+
managerIecHash: string | null;
|
|
112
|
+
managerRaterspotId: string | null;
|
|
113
|
+
}
|
|
114
|
+
interface AppetiteMatchInput {
|
|
115
|
+
naicsCode: string;
|
|
116
|
+
state: string;
|
|
117
|
+
lineOfBusiness: string;
|
|
118
|
+
limits?: {
|
|
119
|
+
perOccurrence?: number;
|
|
120
|
+
aggregate?: number;
|
|
121
|
+
};
|
|
122
|
+
reason?: string;
|
|
123
|
+
}
|
|
124
|
+
interface AppetiteMatchProgram {
|
|
125
|
+
name: string | null;
|
|
126
|
+
iecHash: string | null;
|
|
127
|
+
raterspotId: string | null;
|
|
128
|
+
states: string[];
|
|
129
|
+
isActive: boolean;
|
|
130
|
+
carrierName: string | null;
|
|
131
|
+
carrierNaic: string | null;
|
|
132
|
+
mgaName: string | null;
|
|
133
|
+
ratingEngine: string | null;
|
|
134
|
+
}
|
|
135
|
+
interface AppetiteMatchResult {
|
|
136
|
+
programs: AppetiteMatchProgram[];
|
|
137
|
+
total: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Client for bio-graph InsureBio distribution graph endpoints.
|
|
141
|
+
*
|
|
142
|
+
* Public profile routes (agent, agency, carrier, program) require no auth.
|
|
143
|
+
* Authenticated routes (appetite match, same-as queue) require an accessToken.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* import { GraphClient } from '@insureco/bio/graph'
|
|
147
|
+
*
|
|
148
|
+
* // Public profile lookups — no auth needed
|
|
149
|
+
* const graph = new GraphClient()
|
|
150
|
+
* const { agent } = await graph.getAgent('1234567')
|
|
151
|
+
*
|
|
152
|
+
* // Authenticated routes — pass a user or service token
|
|
153
|
+
* const graph = new GraphClient({ accessToken: req.headers.authorization?.slice(7) })
|
|
154
|
+
* const result = await graph.matchAppetite({ naicsCode: '2361', state: 'TX', lineOfBusiness: 'GL' })
|
|
155
|
+
*/
|
|
156
|
+
declare class GraphClient {
|
|
157
|
+
private readonly graphUrl;
|
|
158
|
+
private readonly accessToken;
|
|
159
|
+
private readonly timeoutMs;
|
|
160
|
+
constructor(config?: GraphClientConfig);
|
|
161
|
+
/**
|
|
162
|
+
* Create a GraphClient from environment variables.
|
|
163
|
+
* BIO_GRAPH_URL defaults to https://bio-graph.tawa.pro if not set.
|
|
164
|
+
*/
|
|
165
|
+
static fromEnv(overrides?: GraphClientConfig): GraphClient;
|
|
166
|
+
/** Look up an agent by NPN. Returns agent properties + employment chain. */
|
|
167
|
+
getAgent(npn: string): Promise<{
|
|
168
|
+
agent: AgentProfile;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Look up an agency by iecHash, raterspotId, or orgSlug.
|
|
172
|
+
* Returns agency properties + staff list + accessible programs.
|
|
173
|
+
*/
|
|
174
|
+
getAgency(iecHash: string): Promise<{
|
|
175
|
+
agency: AgencyProfile;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Look up a carrier by NAIC code, iecHash, raterspotId, or orgSlug.
|
|
179
|
+
* Returns carrier properties + managed programs.
|
|
180
|
+
*/
|
|
181
|
+
getCarrier(naic: string): Promise<{
|
|
182
|
+
carrier: CarrierProfile;
|
|
183
|
+
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Look up a program by iecHash or raterspotId.
|
|
186
|
+
* Returns program properties + managing carrier or MGA.
|
|
187
|
+
*/
|
|
188
|
+
getProgram(iecHash: string): Promise<{
|
|
189
|
+
program: ProgramProfile;
|
|
190
|
+
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Find programs whose appetite covers a given risk.
|
|
193
|
+
* Requires an accessToken (auth: required).
|
|
194
|
+
*
|
|
195
|
+
* @param input - Risk criteria: NAICS code, state, line of business, optional limits
|
|
196
|
+
*/
|
|
197
|
+
matchAppetite(input: AppetiteMatchInput): Promise<AppetiteMatchResult>;
|
|
198
|
+
private get;
|
|
199
|
+
private post;
|
|
200
|
+
private buildHeaders;
|
|
201
|
+
private handleResponse;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { type AgencyProfile, type AgencyProgram, type AgencyStaffMember, type AgentEmployer, type AgentProfile, type AppetiteMatchInput, type AppetiteMatchProgram, type AppetiteMatchResult, type CarrierProfile, type CarrierProgram, GraphClient, type GraphClientConfig, type ProgramProfile };
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
interface GraphClientConfig {
|
|
2
|
+
/** Base URL for bio-graph service. Defaults to BIO_GRAPH_URL env var or https://bio-graph.tawa.pro */
|
|
3
|
+
graphUrl?: string;
|
|
4
|
+
/** Bearer token for authenticated routes (appetite/match, same-as-queue, etc.) */
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
/** Request timeout in ms. Default: 10_000 */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
interface AgentEmployer {
|
|
10
|
+
agencyName: string | null;
|
|
11
|
+
agencyIecHash: string | null;
|
|
12
|
+
agencyOrgSlug: string | null;
|
|
13
|
+
agencyRaterspotId: string | null;
|
|
14
|
+
current: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface AgentProfile {
|
|
17
|
+
iecHash: string | null;
|
|
18
|
+
name: string | null;
|
|
19
|
+
npn: string | null;
|
|
20
|
+
bioId: string | null;
|
|
21
|
+
role: string | null;
|
|
22
|
+
email: string | null;
|
|
23
|
+
phone: string | null;
|
|
24
|
+
address: string | null;
|
|
25
|
+
city: string | null;
|
|
26
|
+
state: string | null;
|
|
27
|
+
zip: string | null;
|
|
28
|
+
licenseNo: string | null;
|
|
29
|
+
status: string | null;
|
|
30
|
+
linesOfAuthority: string[];
|
|
31
|
+
territories: string[];
|
|
32
|
+
linesOfBusiness: string[];
|
|
33
|
+
isPublic: boolean;
|
|
34
|
+
claimedAt: string | null;
|
|
35
|
+
employment: AgentEmployer[];
|
|
36
|
+
}
|
|
37
|
+
interface AgencyStaffMember {
|
|
38
|
+
name: string | null;
|
|
39
|
+
npn: string | null;
|
|
40
|
+
iecHash: string | null;
|
|
41
|
+
role: string | null;
|
|
42
|
+
email: string | null;
|
|
43
|
+
}
|
|
44
|
+
interface AgencyProgram {
|
|
45
|
+
name: string | null;
|
|
46
|
+
raterspotId: string | null;
|
|
47
|
+
iecHash: string | null;
|
|
48
|
+
states: string[];
|
|
49
|
+
carrierName: string | null;
|
|
50
|
+
isActive: boolean;
|
|
51
|
+
}
|
|
52
|
+
interface AgencyProfile {
|
|
53
|
+
iecHash: string | null;
|
|
54
|
+
raterspotId: string | null;
|
|
55
|
+
name: string | null;
|
|
56
|
+
orgSlug: string | null;
|
|
57
|
+
orgId: string | null;
|
|
58
|
+
type: string | null;
|
|
59
|
+
email: string | null;
|
|
60
|
+
phone: string | null;
|
|
61
|
+
website: string | null;
|
|
62
|
+
address: string | null;
|
|
63
|
+
city: string | null;
|
|
64
|
+
state: string | null;
|
|
65
|
+
zip: string | null;
|
|
66
|
+
dba: string | null;
|
|
67
|
+
licenseNo: string | null;
|
|
68
|
+
linesOfAuthority: string | null;
|
|
69
|
+
territories: string[];
|
|
70
|
+
linesOfBusiness: string[];
|
|
71
|
+
isPublic: boolean;
|
|
72
|
+
claimedAt: string | null;
|
|
73
|
+
staff: AgencyStaffMember[];
|
|
74
|
+
programs: AgencyProgram[];
|
|
75
|
+
}
|
|
76
|
+
interface CarrierProgram {
|
|
77
|
+
name: string | null;
|
|
78
|
+
iecHash: string | null;
|
|
79
|
+
raterspotId: string | null;
|
|
80
|
+
states: string[];
|
|
81
|
+
isActive: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface CarrierProfile {
|
|
84
|
+
iecHash: string | null;
|
|
85
|
+
raterspotId: string | null;
|
|
86
|
+
name: string | null;
|
|
87
|
+
naic: string | null;
|
|
88
|
+
orgId: string | null;
|
|
89
|
+
orgSlug: string | null;
|
|
90
|
+
email: string | null;
|
|
91
|
+
phone: string | null;
|
|
92
|
+
website: string | null;
|
|
93
|
+
address: string | null;
|
|
94
|
+
city: string | null;
|
|
95
|
+
state: string | null;
|
|
96
|
+
isPublic: boolean;
|
|
97
|
+
claimedAt: string | null;
|
|
98
|
+
programs: CarrierProgram[];
|
|
99
|
+
}
|
|
100
|
+
interface ProgramProfile {
|
|
101
|
+
iecHash: string | null;
|
|
102
|
+
raterspotId: string | null;
|
|
103
|
+
name: string | null;
|
|
104
|
+
abrv: string | null;
|
|
105
|
+
states: string[];
|
|
106
|
+
isActive: boolean;
|
|
107
|
+
ratingEngine: string | null;
|
|
108
|
+
carrierName: string | null;
|
|
109
|
+
carrierNaic: string | null;
|
|
110
|
+
mgaName: string | null;
|
|
111
|
+
managerIecHash: string | null;
|
|
112
|
+
managerRaterspotId: string | null;
|
|
113
|
+
}
|
|
114
|
+
interface AppetiteMatchInput {
|
|
115
|
+
naicsCode: string;
|
|
116
|
+
state: string;
|
|
117
|
+
lineOfBusiness: string;
|
|
118
|
+
limits?: {
|
|
119
|
+
perOccurrence?: number;
|
|
120
|
+
aggregate?: number;
|
|
121
|
+
};
|
|
122
|
+
reason?: string;
|
|
123
|
+
}
|
|
124
|
+
interface AppetiteMatchProgram {
|
|
125
|
+
name: string | null;
|
|
126
|
+
iecHash: string | null;
|
|
127
|
+
raterspotId: string | null;
|
|
128
|
+
states: string[];
|
|
129
|
+
isActive: boolean;
|
|
130
|
+
carrierName: string | null;
|
|
131
|
+
carrierNaic: string | null;
|
|
132
|
+
mgaName: string | null;
|
|
133
|
+
ratingEngine: string | null;
|
|
134
|
+
}
|
|
135
|
+
interface AppetiteMatchResult {
|
|
136
|
+
programs: AppetiteMatchProgram[];
|
|
137
|
+
total: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Client for bio-graph InsureBio distribution graph endpoints.
|
|
141
|
+
*
|
|
142
|
+
* Public profile routes (agent, agency, carrier, program) require no auth.
|
|
143
|
+
* Authenticated routes (appetite match, same-as queue) require an accessToken.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* import { GraphClient } from '@insureco/bio/graph'
|
|
147
|
+
*
|
|
148
|
+
* // Public profile lookups — no auth needed
|
|
149
|
+
* const graph = new GraphClient()
|
|
150
|
+
* const { agent } = await graph.getAgent('1234567')
|
|
151
|
+
*
|
|
152
|
+
* // Authenticated routes — pass a user or service token
|
|
153
|
+
* const graph = new GraphClient({ accessToken: req.headers.authorization?.slice(7) })
|
|
154
|
+
* const result = await graph.matchAppetite({ naicsCode: '2361', state: 'TX', lineOfBusiness: 'GL' })
|
|
155
|
+
*/
|
|
156
|
+
declare class GraphClient {
|
|
157
|
+
private readonly graphUrl;
|
|
158
|
+
private readonly accessToken;
|
|
159
|
+
private readonly timeoutMs;
|
|
160
|
+
constructor(config?: GraphClientConfig);
|
|
161
|
+
/**
|
|
162
|
+
* Create a GraphClient from environment variables.
|
|
163
|
+
* BIO_GRAPH_URL defaults to https://bio-graph.tawa.pro if not set.
|
|
164
|
+
*/
|
|
165
|
+
static fromEnv(overrides?: GraphClientConfig): GraphClient;
|
|
166
|
+
/** Look up an agent by NPN. Returns agent properties + employment chain. */
|
|
167
|
+
getAgent(npn: string): Promise<{
|
|
168
|
+
agent: AgentProfile;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Look up an agency by iecHash, raterspotId, or orgSlug.
|
|
172
|
+
* Returns agency properties + staff list + accessible programs.
|
|
173
|
+
*/
|
|
174
|
+
getAgency(iecHash: string): Promise<{
|
|
175
|
+
agency: AgencyProfile;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Look up a carrier by NAIC code, iecHash, raterspotId, or orgSlug.
|
|
179
|
+
* Returns carrier properties + managed programs.
|
|
180
|
+
*/
|
|
181
|
+
getCarrier(naic: string): Promise<{
|
|
182
|
+
carrier: CarrierProfile;
|
|
183
|
+
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Look up a program by iecHash or raterspotId.
|
|
186
|
+
* Returns program properties + managing carrier or MGA.
|
|
187
|
+
*/
|
|
188
|
+
getProgram(iecHash: string): Promise<{
|
|
189
|
+
program: ProgramProfile;
|
|
190
|
+
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Find programs whose appetite covers a given risk.
|
|
193
|
+
* Requires an accessToken (auth: required).
|
|
194
|
+
*
|
|
195
|
+
* @param input - Risk criteria: NAICS code, state, line of business, optional limits
|
|
196
|
+
*/
|
|
197
|
+
matchAppetite(input: AppetiteMatchInput): Promise<AppetiteMatchResult>;
|
|
198
|
+
private get;
|
|
199
|
+
private post;
|
|
200
|
+
private buildHeaders;
|
|
201
|
+
private handleResponse;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { type AgencyProfile, type AgencyProgram, type AgencyStaffMember, type AgentEmployer, type AgentProfile, type AppetiteMatchInput, type AppetiteMatchProgram, type AppetiteMatchResult, type CarrierProfile, type CarrierProgram, GraphClient, type GraphClientConfig, type ProgramProfile };
|