@borrowbetter/amlassdk
v0.1.0
Published
Alleviate MLAS SDK
Readme
@borrowbetter/amlassdk
TypeScript SDK for the Alleviate MLAS platform. Wraps the GraphQL API for the lead service with automatic Azure AD authentication and full type safety.
Installation
npm install @borrowbetter/amlassdkRequirements
- Node.js >= 18
- Azure AD client credentials (provided by your Alleviate account manager)
Quick Start
import { AlleviateMLAS } from "@borrowbetter/amlassdk";
const client = new AlleviateMLAS({
environment: "sandbox", // or "production"
auth: {
clientId: process.env.AZURE_CLIENT_ID,
clientSecret: process.env.AZURE_CLIENT_SECRET,
},
});Services
The lead service is accessed as a property on the client instance:
client.leadServiceLead Service
Manages lead creation, submission, status lookup, and referrals.
Create Lead
const result = await client.leadService.CreateLead({
input: {
firstName: "John",
lastName: "Doe",
email: "[email protected]",
homePhone: "5551234567",
address1: "123 Main St",
city: "Atlanta",
state: "GA",
zipCode: "30301",
estimatedDebt: 25000,
loanPurposeId: 1,
termsConsent: true,
},
});
const { id, resultCode, note, bidValue } = result.createLead;Submit Lead
After receiving a qualified result code (1013-1017) from createLead:
const submitResult = await client.leadService.SubmitLead({
input: { leadId: id },
});
const { statusCode, crmRecordId, crm } = submitResult.submitLead;Get Lead Status
const status = await client.leadService.GetLeadStatus({ id });
const { resultCode, updatedAt, bidValue } = status.getLeadStatus;Create Referral
const referral = await client.leadService.CreateReferral({
input: {
firstName: "Jane",
lastName: "Doe",
email: "[email protected]",
homePhone: "5559876543",
state: "CA",
dashboardId: 123,
referralType: "ACCELERATOR_LOAN",
payload: { customField: "value" },
},
});
if (referral.createReferral.errors?.length) {
console.error(referral.createReferral.errors);
} else {
console.log(referral.createReferral.data);
}Configuration
const client = new AlleviateMLAS({
// Required
environment: "sandbox" | "production",
auth: {
clientId: string,
clientSecret: string,
},
// Optional
headers?: Record<string, string>, // Static headers added to every request
timeout?: number, // Request timeout in ms (default: 30_000)
});Custom Token Cache
By default tokens are cached in memory. For multi-process deployments (e.g. serverless, multiple workers) provide a shared cache implementation:
import { AlleviateMLAS, type TokenCache } from "@borrowbetter/amlassdk";
class RedisTokenCache implements TokenCache {
async get() {
return redis.get("mlas:token");
}
async set(token: string, expiresAt: Date) {
const ttl = Math.max(0, Math.floor((expiresAt.getTime() - Date.now()) / 1000));
await redis.set("mlas:token", token, { EX: ttl });
}
}
const client = new AlleviateMLAS({
environment: "production",
auth: { clientId, clientSecret, cache: new RedisTokenCache() },
});Raw Client Access
If you need direct access to the underlying graphql-request client:
client.rawLeadServiceClientType Exports
The service's generated types are available as a namespace export:
import {
AlleviateMLAS,
LeadService,
type MLASConfig,
type TokenCache,
} from "@borrowbetter/amlassdk";Development
Setup
npm install
npm run dev # codegen + tsup watchGenerated files (__generated__/sdk.ts) are excluded from source control and regenerated at build time.
Scripts
| Script | Description |
|--------|-------------|
| npm run build | Codegen + compile to dist/ |
| npm run dev | Watch mode (codegen + tsup) |
| npm run codegen | Regenerate TypeScript from GraphQL schemas |
| npm run smoke | Run end-to-end smoke test against sandbox |
| npm run lint | Biome lint check |
| npm run format | Biome format + auto-fix |
| npm run format:check | Biome CI check (no writes) |
| npm run typecheck | TypeScript type check |
Smoke Test
cp .env.example .env.local # add AZURE_CLIENT_ID and AZURE_CLIENT_SECRET
npm run smokeAdding a New Service
- Place the SDL schema at
src/schemas/{service-name}/schema.graphql - Add operations under
src/schemas/{service-name}/operations/ - Add the service name to the
SERVICESarray incodegen.ts - Wire up the new client in
AlleviateMLAS.ts - Export the namespace from
src/index.ts - Run
npm run codegen
