@delegance/sdk 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +96 -8
- package/dist/index.d.mts +947 -68
- package/dist/index.d.ts +947 -68
- package/dist/index.js +658 -14
- package/dist/index.mjs +639 -13
- package/package.json +20 -19
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Delegance Inc.
|
|
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.
|
package/README.md
CHANGED
|
@@ -12,7 +12,55 @@ yarn add @delegance/sdk
|
|
|
12
12
|
pnpm add @delegance/sdk
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Requires Node 18 or newer. The package ships CommonJS, ESM, and TypeScript types.
|
|
16
|
+
|
|
17
|
+
## Availability
|
|
18
|
+
|
|
19
|
+
- **Quoting over the API is live for enrolled companies.** Delegance turns it on account by account today.
|
|
20
|
+
- **Public access opens on 2026-10-06.** From that date a new account created with `createSignup()` can quote.
|
|
21
|
+
- **Until an account has access,** the instant-quote, bind, and payment calls throw a `DeleganceError` with `statusCode` 503 and `reason` `'not_available'`. The SDK does not retry that answer.
|
|
22
|
+
- **A licensed Delegance broker reviews every bind.** `instantQuotes.bind()` creates a request. It never charges a card and never binds coverage by itself.
|
|
23
|
+
|
|
24
|
+
## Sign up and quote
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { createSignup, newDeviceSecret, DeleganceClient } from '@delegance/sdk';
|
|
28
|
+
|
|
29
|
+
// 1. Create the account. Keep `device.secret` on this machine only.
|
|
30
|
+
const signup = createSignup();
|
|
31
|
+
const account = await signup.createAccount({
|
|
32
|
+
name: 'Acme Bakery',
|
|
33
|
+
contactEmail: 'owner@acmebakery.com',
|
|
34
|
+
industry: 'commercial bakery',
|
|
35
|
+
companySize: '2-10',
|
|
36
|
+
});
|
|
37
|
+
const device = newDeviceSecret();
|
|
38
|
+
const { enrollmentId } = await signup.enroll(account.bootstrapKey, {
|
|
39
|
+
deviceSecretHash: device.hash,
|
|
40
|
+
firstName: 'Dana',
|
|
41
|
+
lastName: 'Owner',
|
|
42
|
+
});
|
|
43
|
+
await signup.requestVerification(account.bootstrapKey);
|
|
44
|
+
|
|
45
|
+
// 2. The owner clicks the emailed confirm link. Then collect the API key.
|
|
46
|
+
const result = await signup.waitForKey(enrollmentId, device.secret);
|
|
47
|
+
if (result.status !== 'ready') throw new Error('Confirm link not clicked yet');
|
|
48
|
+
|
|
49
|
+
// 3. Quote general liability.
|
|
50
|
+
const client = new DeleganceClient({ apiKey: result.apiKey });
|
|
51
|
+
const session = await client.instantQuotes.start(['general_liability']);
|
|
52
|
+
// Answer session.questions (keyed by question id), then submit.
|
|
53
|
+
const submitted = await client.instantQuotes.submit({
|
|
54
|
+
submissionId: session.submissionId,
|
|
55
|
+
sessionVersion: session.sessionVersion,
|
|
56
|
+
answers: {},
|
|
57
|
+
});
|
|
58
|
+
const status = await client.instantQuotes.waitForQuotes(session.submissionId);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The [`@delegance/cli`](https://www.npmjs.com/package/@delegance/cli) package runs the same flow from a terminal (`delegance signup`, `delegance quote start`).
|
|
62
|
+
|
|
63
|
+
## Quick Start (existing API key)
|
|
16
64
|
|
|
17
65
|
```typescript
|
|
18
66
|
import { DeleganceClient } from '@delegance/sdk';
|
|
@@ -70,8 +118,8 @@ const client = new DeleganceClient({
|
|
|
70
118
|
// Required: Your API key
|
|
71
119
|
apiKey: 'dlg_xxxxxxxx_sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
72
120
|
|
|
73
|
-
// Optional: API base URL (default: https://
|
|
74
|
-
baseUrl: 'https://
|
|
121
|
+
// Optional: API base URL (default: https://portal.delegancebrokerage.com)
|
|
122
|
+
baseUrl: 'https://portal.delegancebrokerage.com',
|
|
75
123
|
|
|
76
124
|
// Optional: Request timeout in ms (default: 30000)
|
|
77
125
|
timeout: 30000,
|
|
@@ -239,6 +287,39 @@ if (result.status === 'completed') {
|
|
|
239
287
|
}
|
|
240
288
|
```
|
|
241
289
|
|
|
290
|
+
### Appetite
|
|
291
|
+
|
|
292
|
+
Which carriers will write a risk. Needs an API key with the `appetite:read` scope, which `read` and `write` do not include. A warm cache hit returns the result at once; a cold match returns a job to poll.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
const start = await client.appetite.match({
|
|
296
|
+
state: 'CA',
|
|
297
|
+
industry: 'commercial bakery',
|
|
298
|
+
coverageTypes: ['general_liability', 'workers_comp'],
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const result = start.status === 'succeeded'
|
|
302
|
+
? start
|
|
303
|
+
: await client.appetite.waitForMatch(start.jobId);
|
|
304
|
+
|
|
305
|
+
for (const c of result.carrierResults) {
|
|
306
|
+
console.log(c.carrier, c.overallStatus, c.productsAvailable);
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Leads
|
|
311
|
+
|
|
312
|
+
Send a prospect business to Delegance. Idempotent on `externalId`, and a contact email that already belongs to a company returns that company.
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
const { companyId } = await client.leads.create({
|
|
316
|
+
name: 'Riverbend Bakery',
|
|
317
|
+
contactEmail: 'owner@riverbend.example',
|
|
318
|
+
state: 'TX',
|
|
319
|
+
externalId: 'crm-4411',
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
242
323
|
## Error Handling
|
|
243
324
|
|
|
244
325
|
The SDK throws typed errors for different scenarios:
|
|
@@ -246,8 +327,10 @@ The SDK throws typed errors for different scenarios:
|
|
|
246
327
|
```typescript
|
|
247
328
|
import {
|
|
248
329
|
AuthenticationError,
|
|
330
|
+
ForbiddenError,
|
|
249
331
|
ValidationError,
|
|
250
332
|
NotFoundError,
|
|
333
|
+
NotImplementedError,
|
|
251
334
|
RateLimitError,
|
|
252
335
|
DeleganceError
|
|
253
336
|
} from '@delegance/sdk';
|
|
@@ -257,8 +340,12 @@ try {
|
|
|
257
340
|
} catch (error) {
|
|
258
341
|
if (error instanceof AuthenticationError) {
|
|
259
342
|
console.error('Invalid API key');
|
|
343
|
+
} else if (error instanceof ForbiddenError) {
|
|
344
|
+
console.error('Key lacks the scope for this call');
|
|
260
345
|
} else if (error instanceof NotFoundError) {
|
|
261
346
|
console.error('Document not found');
|
|
347
|
+
} else if (error instanceof NotImplementedError) {
|
|
348
|
+
console.error('Not available over the API yet:', error.message);
|
|
262
349
|
} else if (error instanceof ValidationError) {
|
|
263
350
|
console.error('Invalid input:', error.details);
|
|
264
351
|
} else if (error instanceof RateLimitError) {
|
|
@@ -269,6 +356,8 @@ try {
|
|
|
269
356
|
}
|
|
270
357
|
```
|
|
271
358
|
|
|
359
|
+
The SDK retries network failures and 5xx responses other than 501. It never retries a 4xx or a 501.
|
|
360
|
+
|
|
272
361
|
## TypeScript Support
|
|
273
362
|
|
|
274
363
|
The SDK is written in TypeScript and includes full type definitions:
|
|
@@ -294,8 +383,8 @@ if (!result.success) {
|
|
|
294
383
|
|
|
295
384
|
## Getting an API Key
|
|
296
385
|
|
|
297
|
-
1. Log in to the
|
|
298
|
-
2.
|
|
386
|
+
1. Log in to the portal at https://portal.delegancebrokerage.com
|
|
387
|
+
2. Open Settings > API keys
|
|
299
388
|
3. Click "Create API Key"
|
|
300
389
|
4. Copy the key (it's only shown once!)
|
|
301
390
|
|
|
@@ -303,6 +392,5 @@ API keys have the format: `dlg_xxxxxxxx_sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|
|
|
303
392
|
|
|
304
393
|
## Support
|
|
305
394
|
|
|
306
|
-
- Documentation: https://
|
|
307
|
-
-
|
|
308
|
-
- Email: support@delegance.ai
|
|
395
|
+
- Documentation: https://portal.delegancebrokerage.com/docs/sdk
|
|
396
|
+
- Email: support@delegancebrokerage.com
|