@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
package/dist/index.d.ts
CHANGED
|
@@ -1,267 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
clientId: string;
|
|
5
|
-
/** OAuth client secret (env: BIO_CLIENT_SECRET) */
|
|
6
|
-
clientSecret: string;
|
|
7
|
-
/** Bio-ID issuer URL (env: BIO_ID_URL, default: https://bio.tawa.pro) */
|
|
8
|
-
issuer?: string;
|
|
9
|
-
/** Number of retry attempts on transient failures (default: 2) */
|
|
10
|
-
retries?: number;
|
|
11
|
-
/** Request timeout in milliseconds (default: 10000) */
|
|
12
|
-
timeoutMs?: number;
|
|
13
|
-
}
|
|
14
|
-
/** Configuration for BioAdmin (admin API client) */
|
|
15
|
-
interface BioAdminConfig {
|
|
16
|
-
/** Bio-ID base URL (env: BIO_ID_URL, default: https://bio.tawa.pro) */
|
|
17
|
-
baseUrl?: string;
|
|
18
|
-
/** Internal API key for service-to-service auth (env: INTERNAL_API_KEY) */
|
|
19
|
-
internalKey?: string;
|
|
20
|
-
/** Async function returning a Bearer token (alternative to internalKey) */
|
|
21
|
-
accessTokenFn?: () => Promise<string>;
|
|
22
|
-
/** Number of retry attempts on transient failures (default: 2) */
|
|
23
|
-
retries?: number;
|
|
24
|
-
/** Request timeout in milliseconds (default: 10000) */
|
|
25
|
-
timeoutMs?: number;
|
|
26
|
-
}
|
|
27
|
-
/** Options for building an authorization URL */
|
|
28
|
-
interface AuthorizeOptions {
|
|
29
|
-
/** Callback URL where Bio-ID redirects after authorization */
|
|
30
|
-
redirectUri: string;
|
|
31
|
-
/** OAuth scopes to request (default: ['openid', 'profile', 'email']) */
|
|
32
|
-
scopes?: string[];
|
|
33
|
-
/** CSRF state parameter (auto-generated if not provided) */
|
|
34
|
-
state?: string;
|
|
35
|
-
/** Optional org slug to pre-select during authorization (for multi-org users) */
|
|
36
|
-
organization?: string;
|
|
37
|
-
}
|
|
38
|
-
/** Result from getAuthorizationUrl() */
|
|
39
|
-
interface AuthorizeResult {
|
|
40
|
-
/** Full authorization URL to redirect the user to */
|
|
41
|
-
url: string;
|
|
42
|
-
/** State parameter (for CSRF validation on callback) */
|
|
43
|
-
state: string;
|
|
44
|
-
/** PKCE code verifier (store securely, send during token exchange) */
|
|
45
|
-
codeVerifier: string;
|
|
46
|
-
/** PKCE code challenge (included in the URL) */
|
|
47
|
-
codeChallenge: string;
|
|
48
|
-
}
|
|
49
|
-
/** Response from the /api/oauth/token endpoint */
|
|
50
|
-
interface TokenResponse {
|
|
51
|
-
access_token: string;
|
|
52
|
-
token_type: 'Bearer';
|
|
53
|
-
expires_in: number;
|
|
54
|
-
refresh_token?: string;
|
|
55
|
-
scope: string;
|
|
56
|
-
id_token?: string;
|
|
57
|
-
}
|
|
58
|
-
/** Response from the /api/auth/introspect endpoint */
|
|
59
|
-
interface IntrospectResult {
|
|
60
|
-
active: boolean;
|
|
61
|
-
user?: {
|
|
62
|
-
id: string;
|
|
63
|
-
email: string;
|
|
64
|
-
name: string;
|
|
65
|
-
org: string;
|
|
66
|
-
roles: string[];
|
|
67
|
-
};
|
|
68
|
-
tokenType?: 'client_credentials';
|
|
69
|
-
clientId?: string;
|
|
70
|
-
scopes?: string[];
|
|
71
|
-
orgId?: string;
|
|
72
|
-
orgSlug?: string;
|
|
73
|
-
organizationName?: string;
|
|
74
|
-
}
|
|
75
|
-
/** Decoded access token payload (user auth) */
|
|
76
|
-
interface BioTokenPayload {
|
|
77
|
-
iss: string;
|
|
78
|
-
sub: string;
|
|
79
|
-
aud: string;
|
|
80
|
-
exp: number;
|
|
81
|
-
iat: number;
|
|
82
|
-
bioId: string;
|
|
83
|
-
email: string;
|
|
84
|
-
name: string;
|
|
85
|
-
userType: string;
|
|
86
|
-
roles: string[];
|
|
87
|
-
permissions: string[];
|
|
88
|
-
orgId?: string;
|
|
89
|
-
orgSlug?: string;
|
|
90
|
-
/** Org-specific role slugs within the user's active org (from OrgMembership) */
|
|
91
|
-
orgRoles?: string[];
|
|
92
|
-
/** Job title at the active org (from OrgMembership.jobTitle) */
|
|
93
|
-
orgTitle?: string;
|
|
94
|
-
/** Additional modules granted by the org specifically (from OrgMembership.enabled_modules) */
|
|
95
|
-
orgModules?: string[];
|
|
96
|
-
client_id: string;
|
|
97
|
-
scope: string;
|
|
98
|
-
enabled_modules?: string[];
|
|
99
|
-
onboarding?: {
|
|
100
|
-
platform: boolean;
|
|
101
|
-
modules: Record<string, {
|
|
102
|
-
completed: string[];
|
|
103
|
-
due: string[];
|
|
104
|
-
}>;
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** Decoded client credentials token payload (service-to-service) */
|
|
108
|
-
interface BioClientTokenPayload {
|
|
109
|
-
iss: string;
|
|
110
|
-
exp: number;
|
|
111
|
-
iat: number;
|
|
112
|
-
client_id: string;
|
|
113
|
-
scope: string;
|
|
114
|
-
token_type: 'client_credentials';
|
|
115
|
-
orgId?: string;
|
|
116
|
-
orgSlug?: string;
|
|
117
|
-
}
|
|
118
|
-
/** Options for local JWT verification (HS256) */
|
|
119
|
-
interface VerifyOptions {
|
|
120
|
-
/** Expected issuer (default: config issuer) */
|
|
121
|
-
issuer?: string;
|
|
122
|
-
/** Expected audience (client_id) */
|
|
123
|
-
audience?: string;
|
|
124
|
-
}
|
|
125
|
-
/** Options for JWKS-based JWT verification (RS256) */
|
|
126
|
-
interface JWKSVerifyOptions {
|
|
127
|
-
/** JWKS endpoint URL (default: https://bio.tawa.pro/.well-known/jwks.json) */
|
|
128
|
-
jwksUri?: string;
|
|
129
|
-
/** Expected issuer — defaults to accepting bio.insureco.io, bio.tawa.insureco.io, and bio.tawa.pro */
|
|
130
|
-
issuer?: string;
|
|
131
|
-
/** Expected audience (client_id) */
|
|
132
|
-
audience?: string;
|
|
133
|
-
}
|
|
134
|
-
/** User profile from /api/oauth/userinfo or admin API */
|
|
135
|
-
interface BioUser {
|
|
136
|
-
sub: string;
|
|
137
|
-
bioId: string;
|
|
138
|
-
email: string;
|
|
139
|
-
emailVerified: boolean;
|
|
140
|
-
name: string;
|
|
141
|
-
firstName?: string;
|
|
142
|
-
lastName?: string;
|
|
143
|
-
userType: string;
|
|
144
|
-
roles: string[];
|
|
145
|
-
permissions: string[];
|
|
146
|
-
status: string;
|
|
147
|
-
orgId?: string;
|
|
148
|
-
orgSlug?: string;
|
|
149
|
-
organizationId?: string;
|
|
150
|
-
organizationName?: string;
|
|
151
|
-
departmentId?: string;
|
|
152
|
-
departmentName?: string;
|
|
153
|
-
managerId?: string;
|
|
154
|
-
enabledModules?: string[];
|
|
155
|
-
jobTitle?: string;
|
|
156
|
-
phoneHome?: string;
|
|
157
|
-
phoneWork?: string;
|
|
158
|
-
phoneCell?: string;
|
|
159
|
-
phone?: string;
|
|
160
|
-
addressHome?: BioAddress;
|
|
161
|
-
addressWork?: BioAddress;
|
|
162
|
-
messaging?: BioMessaging;
|
|
163
|
-
preferences?: Record<string, unknown>;
|
|
164
|
-
lastLoginAt?: number;
|
|
165
|
-
}
|
|
166
|
-
interface BioAddress {
|
|
167
|
-
street?: string;
|
|
168
|
-
city?: string;
|
|
169
|
-
state?: string;
|
|
170
|
-
zip?: string;
|
|
171
|
-
country?: string;
|
|
172
|
-
}
|
|
173
|
-
interface BioMessaging {
|
|
174
|
-
slack?: string;
|
|
175
|
-
teams?: string;
|
|
176
|
-
skype?: string;
|
|
177
|
-
whatsapp?: string;
|
|
178
|
-
}
|
|
179
|
-
/** Filters for listing users */
|
|
180
|
-
interface UserFilters {
|
|
181
|
-
search?: string;
|
|
182
|
-
status?: string;
|
|
183
|
-
userType?: string;
|
|
184
|
-
organizationId?: string;
|
|
185
|
-
page?: number;
|
|
186
|
-
limit?: number;
|
|
187
|
-
}
|
|
188
|
-
/** Data for updating a user */
|
|
189
|
-
interface UpdateUserData {
|
|
190
|
-
firstName?: string;
|
|
191
|
-
lastName?: string;
|
|
192
|
-
displayName?: string;
|
|
193
|
-
roles?: string[];
|
|
194
|
-
status?: string;
|
|
195
|
-
userType?: string;
|
|
196
|
-
departmentId?: string;
|
|
197
|
-
jobTitle?: string;
|
|
198
|
-
permissions?: string[];
|
|
199
|
-
enabled_modules?: string[];
|
|
200
|
-
}
|
|
201
|
-
/** Department from admin API */
|
|
202
|
-
interface BioDepartment {
|
|
203
|
-
id: string;
|
|
204
|
-
name: string;
|
|
205
|
-
description?: string;
|
|
206
|
-
organizationId: string;
|
|
207
|
-
headId?: string;
|
|
208
|
-
parentId?: string;
|
|
209
|
-
memberCount?: number;
|
|
210
|
-
}
|
|
211
|
-
/** Data for creating a department */
|
|
212
|
-
interface CreateDepartmentData {
|
|
213
|
-
name: string;
|
|
214
|
-
description?: string;
|
|
215
|
-
headId?: string;
|
|
216
|
-
parentId?: string;
|
|
217
|
-
}
|
|
218
|
-
/** Role from admin API */
|
|
219
|
-
interface BioRole {
|
|
220
|
-
id: string;
|
|
221
|
-
name: string;
|
|
222
|
-
description?: string;
|
|
223
|
-
permissions: string[];
|
|
224
|
-
isSystem?: boolean;
|
|
225
|
-
}
|
|
226
|
-
/** Data for creating a role */
|
|
227
|
-
interface CreateRoleData {
|
|
228
|
-
name: string;
|
|
229
|
-
description?: string;
|
|
230
|
-
permissions: string[];
|
|
231
|
-
}
|
|
232
|
-
/** OAuth client from admin API */
|
|
233
|
-
interface BioOAuthClient {
|
|
234
|
-
clientId: string;
|
|
235
|
-
name: string;
|
|
236
|
-
description?: string;
|
|
237
|
-
redirectUris: string[];
|
|
238
|
-
allowedScopes: string[];
|
|
239
|
-
allowedGrantTypes: string[];
|
|
240
|
-
isActive: boolean;
|
|
241
|
-
orgId?: string;
|
|
242
|
-
orgSlug?: string;
|
|
243
|
-
accessTokenTtl?: number;
|
|
244
|
-
refreshTokenTtl?: number;
|
|
245
|
-
}
|
|
246
|
-
/** Data for creating an OAuth client */
|
|
247
|
-
interface CreateClientData {
|
|
248
|
-
name: string;
|
|
249
|
-
description?: string;
|
|
250
|
-
redirectUris: string[];
|
|
251
|
-
allowedScopes?: string[];
|
|
252
|
-
allowedGrantTypes?: string[];
|
|
253
|
-
}
|
|
254
|
-
/** Admin API response wrapper */
|
|
255
|
-
interface AdminResponse<T> {
|
|
256
|
-
success: boolean;
|
|
257
|
-
data?: T;
|
|
258
|
-
error?: string;
|
|
259
|
-
meta?: {
|
|
260
|
-
total: number;
|
|
261
|
-
page: number;
|
|
262
|
-
limit: number;
|
|
263
|
-
};
|
|
264
|
-
}
|
|
1
|
+
import { B as BioAuthConfig, A as AuthorizeOptions, a as AuthorizeResult, T as TokenResponse, b as BioUser, I as IntrospectResult, c as BioAdminConfig, U as UserFilters, d as UpdateUserData, e as BioDepartment, C as CreateDepartmentData, f as BioRole, g as CreateRoleData, h as BioOAuthClient, i as CreateClientData, j as BioTokenPayload, V as VerifyOptions, J as JWKSVerifyOptions } from './types-Dkb-drHZ.js';
|
|
2
|
+
export { k as AdminResponse, l as BioAddress, m as BioClientTokenPayload, n as BioMessaging, o as BioUsersConfig, O as OrgMember, p as OrgMemberFilters, q as OrgMembersResult } from './types-Dkb-drHZ.js';
|
|
3
|
+
export { AgencyProfile, AgencyProgram, AgencyStaffMember, AgentEmployer, AgentProfile, AppetiteMatchInput, AppetiteMatchProgram, AppetiteMatchResult, CarrierProfile, CarrierProgram, GraphClient, GraphClientConfig, ProgramProfile } from './graph.js';
|
|
265
4
|
|
|
266
5
|
/**
|
|
267
6
|
* OAuth flow client for Bio-ID SSO.
|
|
@@ -416,4 +155,4 @@ declare function isTokenExpired(token: string, bufferSeconds?: number): boolean;
|
|
|
416
155
|
*/
|
|
417
156
|
declare function verifyTokenJWKS(token: string, options?: JWKSVerifyOptions): Promise<BioTokenPayload>;
|
|
418
157
|
|
|
419
|
-
export {
|
|
158
|
+
export { AuthorizeOptions, AuthorizeResult, BioAdmin, BioAdminConfig, BioAuth, BioAuthConfig, BioDepartment, BioError, BioOAuthClient, BioRole, BioTokenPayload, BioUser, CreateClientData, CreateDepartmentData, CreateRoleData, IntrospectResult, JWKSVerifyOptions, TokenResponse, UpdateUserData, UserFilters, VerifyOptions, decodeToken, generatePKCE, isTokenExpired, verifyToken, verifyTokenJWKS };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
BioAdmin: () => BioAdmin,
|
|
34
34
|
BioAuth: () => BioAuth,
|
|
35
35
|
BioError: () => BioError,
|
|
36
|
+
GraphClient: () => GraphClient,
|
|
36
37
|
decodeToken: () => decodeToken,
|
|
37
38
|
generatePKCE: () => generatePKCE,
|
|
38
39
|
isTokenExpired: () => isTokenExpired,
|
|
@@ -737,11 +738,171 @@ async function verifyTokenJWKS(token, options) {
|
|
|
737
738
|
}
|
|
738
739
|
return payload;
|
|
739
740
|
}
|
|
741
|
+
|
|
742
|
+
// src/graph.ts
|
|
743
|
+
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
744
|
+
var BIO_GRAPH_URL = "https://bio-graph.tawa.pro";
|
|
745
|
+
var GraphClient = class _GraphClient {
|
|
746
|
+
graphUrl;
|
|
747
|
+
accessToken;
|
|
748
|
+
timeoutMs;
|
|
749
|
+
constructor(config = {}) {
|
|
750
|
+
this.graphUrl = (config.graphUrl ?? process.env.BIO_GRAPH_URL ?? BIO_GRAPH_URL).replace(/\/$/, "");
|
|
751
|
+
this.accessToken = config.accessToken;
|
|
752
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS3;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Create a GraphClient from environment variables.
|
|
756
|
+
* BIO_GRAPH_URL defaults to https://bio-graph.tawa.pro if not set.
|
|
757
|
+
*/
|
|
758
|
+
static fromEnv(overrides) {
|
|
759
|
+
return new _GraphClient({
|
|
760
|
+
graphUrl: overrides?.graphUrl ?? process.env.BIO_GRAPH_URL,
|
|
761
|
+
accessToken: overrides?.accessToken,
|
|
762
|
+
timeoutMs: overrides?.timeoutMs
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
// ─── Public Profile Routes ────────────────────────────────────────────────
|
|
766
|
+
/** Look up an agent by NPN. Returns agent properties + employment chain. */
|
|
767
|
+
async getAgent(npn) {
|
|
768
|
+
return this.get(`/api/graph/agent/${encodeURIComponent(npn)}`);
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Look up an agency by iecHash, raterspotId, or orgSlug.
|
|
772
|
+
* Returns agency properties + staff list + accessible programs.
|
|
773
|
+
*/
|
|
774
|
+
async getAgency(iecHash) {
|
|
775
|
+
return this.get(`/api/graph/agency/${encodeURIComponent(iecHash)}`);
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Look up a carrier by NAIC code, iecHash, raterspotId, or orgSlug.
|
|
779
|
+
* Returns carrier properties + managed programs.
|
|
780
|
+
*/
|
|
781
|
+
async getCarrier(naic) {
|
|
782
|
+
return this.get(`/api/graph/carrier/${encodeURIComponent(naic)}`);
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Look up a program by iecHash or raterspotId.
|
|
786
|
+
* Returns program properties + managing carrier or MGA.
|
|
787
|
+
*/
|
|
788
|
+
async getProgram(iecHash) {
|
|
789
|
+
return this.get(`/api/graph/program/${encodeURIComponent(iecHash)}`);
|
|
790
|
+
}
|
|
791
|
+
// ─── Authenticated Routes ─────────────────────────────────────────────────
|
|
792
|
+
/**
|
|
793
|
+
* Find programs whose appetite covers a given risk.
|
|
794
|
+
* Requires an accessToken (auth: required).
|
|
795
|
+
*
|
|
796
|
+
* @param input - Risk criteria: NAICS code, state, line of business, optional limits
|
|
797
|
+
*/
|
|
798
|
+
async matchAppetite(input) {
|
|
799
|
+
return this.post("/api/graph/appetite/match", input, { requiresAuth: true });
|
|
800
|
+
}
|
|
801
|
+
// ─── Internal ─────────────────────────────────────────────────────────────
|
|
802
|
+
async get(path, attempt = 0) {
|
|
803
|
+
const url = `${this.graphUrl}${path}`;
|
|
804
|
+
const controller = new AbortController();
|
|
805
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
806
|
+
let response;
|
|
807
|
+
try {
|
|
808
|
+
response = await fetch(url, {
|
|
809
|
+
headers: this.buildHeaders(),
|
|
810
|
+
signal: controller.signal
|
|
811
|
+
});
|
|
812
|
+
} catch (err) {
|
|
813
|
+
clearTimeout(timer);
|
|
814
|
+
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
815
|
+
if (!isTimeout && attempt < 2) {
|
|
816
|
+
await sleep(retryDelay(attempt));
|
|
817
|
+
return this.get(path, attempt + 1);
|
|
818
|
+
}
|
|
819
|
+
throw new BioError(
|
|
820
|
+
isTimeout ? "bio-graph request timed out" : `bio-graph request failed: ${String(err)}`,
|
|
821
|
+
isTimeout ? "timeout" : "network_error"
|
|
822
|
+
);
|
|
823
|
+
} finally {
|
|
824
|
+
clearTimeout(timer);
|
|
825
|
+
}
|
|
826
|
+
return this.handleResponse(response, path);
|
|
827
|
+
}
|
|
828
|
+
async post(path, body, opts = {}, attempt = 0) {
|
|
829
|
+
if (opts.requiresAuth && !this.accessToken) {
|
|
830
|
+
throw new BioError(
|
|
831
|
+
`bio-graph ${path} requires an accessToken \u2014 pass it in the GraphClient constructor`,
|
|
832
|
+
"config_error"
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
const url = `${this.graphUrl}${path}`;
|
|
836
|
+
const controller = new AbortController();
|
|
837
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
838
|
+
let response;
|
|
839
|
+
try {
|
|
840
|
+
response = await fetch(url, {
|
|
841
|
+
method: "POST",
|
|
842
|
+
headers: { ...this.buildHeaders(), "Content-Type": "application/json" },
|
|
843
|
+
body: JSON.stringify(body),
|
|
844
|
+
signal: controller.signal
|
|
845
|
+
});
|
|
846
|
+
} catch (err) {
|
|
847
|
+
clearTimeout(timer);
|
|
848
|
+
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
849
|
+
if (!isTimeout && attempt < 2) {
|
|
850
|
+
await sleep(retryDelay(attempt));
|
|
851
|
+
return this.post(path, body, opts, attempt + 1);
|
|
852
|
+
}
|
|
853
|
+
throw new BioError(
|
|
854
|
+
isTimeout ? "bio-graph request timed out" : `bio-graph request failed: ${String(err)}`,
|
|
855
|
+
isTimeout ? "timeout" : "network_error"
|
|
856
|
+
);
|
|
857
|
+
} finally {
|
|
858
|
+
clearTimeout(timer);
|
|
859
|
+
}
|
|
860
|
+
return this.handleResponse(response, path);
|
|
861
|
+
}
|
|
862
|
+
buildHeaders() {
|
|
863
|
+
const headers = {};
|
|
864
|
+
if (this.accessToken) {
|
|
865
|
+
headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
866
|
+
}
|
|
867
|
+
return headers;
|
|
868
|
+
}
|
|
869
|
+
async handleResponse(response, path) {
|
|
870
|
+
if (response.status === 404) {
|
|
871
|
+
throw new BioError(`bio-graph entity not found: ${path}`, "not_found", 404);
|
|
872
|
+
}
|
|
873
|
+
if (response.status === 401) {
|
|
874
|
+
throw new BioError(
|
|
875
|
+
"bio-graph authentication failed \u2014 provide a valid accessToken",
|
|
876
|
+
"unauthorized",
|
|
877
|
+
401
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
if (response.status === 402) {
|
|
881
|
+
throw new BioError(
|
|
882
|
+
"bio-graph call failed \u2014 insufficient gas tokens. Top up at tawa.insureco.io/wallet",
|
|
883
|
+
"insufficient_gas",
|
|
884
|
+
402
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
if (!response.ok) {
|
|
888
|
+
const body2 = await parseJsonResponse(response).catch(() => ({}));
|
|
889
|
+
throw new BioError(
|
|
890
|
+
`bio-graph returned ${response.status} for ${path}`,
|
|
891
|
+
"api_error",
|
|
892
|
+
response.status,
|
|
893
|
+
body2
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
const body = await parseJsonResponse(response);
|
|
897
|
+
return body;
|
|
898
|
+
}
|
|
899
|
+
};
|
|
740
900
|
// Annotate the CommonJS export names for ESM import in node:
|
|
741
901
|
0 && (module.exports = {
|
|
742
902
|
BioAdmin,
|
|
743
903
|
BioAuth,
|
|
744
904
|
BioError,
|
|
905
|
+
GraphClient,
|
|
745
906
|
decodeToken,
|
|
746
907
|
generatePKCE,
|
|
747
908
|
isTokenExpired,
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GraphClient
|
|
3
|
+
} from "./chunk-PLN6QPED.mjs";
|
|
4
|
+
import {
|
|
5
|
+
BioError,
|
|
6
|
+
parseJsonResponse,
|
|
7
|
+
retryDelay,
|
|
8
|
+
sleep
|
|
9
|
+
} from "./chunk-NK5VXXWF.mjs";
|
|
10
|
+
|
|
1
11
|
// src/auth.ts
|
|
2
12
|
import crypto2 from "crypto";
|
|
3
13
|
|
|
4
|
-
// src/errors.ts
|
|
5
|
-
var BioError = class extends Error {
|
|
6
|
-
/** HTTP status code (if from an API response) */
|
|
7
|
-
statusCode;
|
|
8
|
-
/** Machine-readable error code (e.g. 'invalid_grant', 'token_expired') */
|
|
9
|
-
code;
|
|
10
|
-
/** Additional error details from the API */
|
|
11
|
-
details;
|
|
12
|
-
constructor(message, code, statusCode, details) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.name = "BioError";
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.statusCode = statusCode;
|
|
17
|
-
this.details = details;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
14
|
// src/pkce.ts
|
|
22
15
|
import crypto from "crypto";
|
|
23
16
|
function generatePKCE() {
|
|
@@ -26,26 +19,6 @@ function generatePKCE() {
|
|
|
26
19
|
return { codeVerifier, codeChallenge };
|
|
27
20
|
}
|
|
28
21
|
|
|
29
|
-
// src/utils.ts
|
|
30
|
-
function retryDelay(attempt) {
|
|
31
|
-
const baseDelay = Math.min(1e3 * 2 ** attempt, 5e3);
|
|
32
|
-
return baseDelay * (0.5 + Math.random() * 0.5);
|
|
33
|
-
}
|
|
34
|
-
function sleep(ms) {
|
|
35
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
36
|
-
}
|
|
37
|
-
async function parseJsonResponse(response) {
|
|
38
|
-
try {
|
|
39
|
-
return await response.json();
|
|
40
|
-
} catch {
|
|
41
|
-
throw new BioError(
|
|
42
|
-
`Bio-ID returned ${response.status} with non-JSON body`,
|
|
43
|
-
"parse_error",
|
|
44
|
-
response.status
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
22
|
// src/auth.ts
|
|
50
23
|
var DEFAULT_ISSUER = "https://bio.tawa.pro";
|
|
51
24
|
var DEFAULT_SCOPES = ["openid", "profile", "email"];
|
|
@@ -698,6 +671,7 @@ export {
|
|
|
698
671
|
BioAdmin,
|
|
699
672
|
BioAuth,
|
|
700
673
|
BioError,
|
|
674
|
+
GraphClient,
|
|
701
675
|
decodeToken,
|
|
702
676
|
generatePKCE,
|
|
703
677
|
isTokenExpired,
|