@borrowbetter/swsdk 0.1.1
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/README.md +189 -0
- package/dist/index.d.mts +611 -0
- package/dist/index.d.ts +611 -0
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +115 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# @borrowbetter/swsdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [Spinwheel](https://spinwheel.io) credit data and debt profile API. Provides type-safe access to user connection, debt profile fetching, and hydrated user data.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @borrowbetter/swsdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Node.js >= 18
|
|
14
|
+
- Spinwheel API key (provided by your Spinwheel account manager)
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { SpinwheelSDK } from "@borrowbetter/swsdk";
|
|
20
|
+
|
|
21
|
+
const spinwheel = new SpinwheelSDK({
|
|
22
|
+
apiKey: process.env.SPINWHEEL_API_KEY,
|
|
23
|
+
sandbox: process.env.NODE_ENV !== "production",
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
### Connect
|
|
30
|
+
|
|
31
|
+
Connect a user to Spinwheel via preverified phone or network token.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Preverified phone (requires Spinwheel support approval)
|
|
35
|
+
const result = await spinwheel.connect.preverifiedPhone({
|
|
36
|
+
phoneNumber: "+14155552671",
|
|
37
|
+
dateOfBirth: "1990-01-15",
|
|
38
|
+
extUserId: "your-internal-user-id",
|
|
39
|
+
audit: {
|
|
40
|
+
verificationDate: "2025-01-01",
|
|
41
|
+
userConsentDate: "2025-01-01",
|
|
42
|
+
verificationType: "SMS",
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { userId } = result.data;
|
|
47
|
+
|
|
48
|
+
// Network token
|
|
49
|
+
const result = await spinwheel.connect.networkToken({
|
|
50
|
+
extUserId: "your-internal-user-id",
|
|
51
|
+
networkToken: "token-from-verification",
|
|
52
|
+
ssnLastFourDigits: "1234",
|
|
53
|
+
dateOfBirth: "1990-01-15",
|
|
54
|
+
audit: { userConsentDate: "2025-01-01" },
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Debt Profile
|
|
59
|
+
|
|
60
|
+
Trigger an asynchronous credit pull. Results are retrieved via `userManagement.get()` once processing completes.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
await spinwheel.debtProfile.fetch(userId, {
|
|
64
|
+
creditReport: {
|
|
65
|
+
sourceBureau: "TransUnion",
|
|
66
|
+
type: "1_BUREAU.FULL",
|
|
67
|
+
},
|
|
68
|
+
creditScore: {
|
|
69
|
+
sourceBureau: "TransUnion",
|
|
70
|
+
model: "VANTAGE_SCORE_3_0",
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
> Note: Your implementation must display the Spinwheel End User Agreement before calling this method.
|
|
76
|
+
|
|
77
|
+
### User Management
|
|
78
|
+
|
|
79
|
+
Retrieve a user's full hydrated profile including all liabilities and credit reports. Always uses the secure endpoint with unmasked account number and SSN.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// By Spinwheel user ID
|
|
83
|
+
const { data } = await spinwheel.userManagement.get({ userId });
|
|
84
|
+
|
|
85
|
+
// By your external user ID
|
|
86
|
+
const { data } = await spinwheel.userManagement.get({ extUserId: "your-id" });
|
|
87
|
+
|
|
88
|
+
// Available on the hydrated user
|
|
89
|
+
data.profile?.creditScore;
|
|
90
|
+
data.creditCardSummary;
|
|
91
|
+
data.personalLoanSummary;
|
|
92
|
+
data.autoLoanSummary;
|
|
93
|
+
data.homeLoanSummary;
|
|
94
|
+
data.studentLoanSummary;
|
|
95
|
+
data.creditReports;
|
|
96
|
+
data.creditCards;
|
|
97
|
+
data.personalLoans;
|
|
98
|
+
data.autoLoans;
|
|
99
|
+
data.homeLoans;
|
|
100
|
+
data.studentLoans;
|
|
101
|
+
data.miscellaneousLiabilities;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
new SpinwheelSDK({
|
|
108
|
+
apiKey: string; // Required — your Spinwheel API key
|
|
109
|
+
sandbox?: boolean; // Optional — defaults to false (production)
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Response Shape
|
|
114
|
+
|
|
115
|
+
All methods return Spinwheel's standard response envelope:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
interface SpinwheelResponse<T> {
|
|
119
|
+
status: {
|
|
120
|
+
code: number;
|
|
121
|
+
desc: string;
|
|
122
|
+
messages?: Array<{ desc: string; type?: "ERROR" | "WARN" | "INFO" }>;
|
|
123
|
+
};
|
|
124
|
+
data: T;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const result = await spinwheel.connect.preverifiedPhone({ ... });
|
|
130
|
+
|
|
131
|
+
if (result.status.code >= 400) {
|
|
132
|
+
console.error(result.status.messages);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { userId } = result.data;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Type Exports
|
|
140
|
+
|
|
141
|
+
All types are exported directly from the package:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import type {
|
|
145
|
+
SpinwheelConfig,
|
|
146
|
+
HydratedUserData,
|
|
147
|
+
UserData,
|
|
148
|
+
CreditReport,
|
|
149
|
+
CreditCard,
|
|
150
|
+
PersonalLoan,
|
|
151
|
+
AutoLoan,
|
|
152
|
+
HomeLoan,
|
|
153
|
+
StudentLoan,
|
|
154
|
+
LiabilityType,
|
|
155
|
+
CreditBureau,
|
|
156
|
+
// ...and more
|
|
157
|
+
} from "@borrowbetter/swsdk";
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm install
|
|
164
|
+
npm run dev # tsup watch mode
|
|
165
|
+
npm run build # compile to dist/
|
|
166
|
+
npm run typecheck # TypeScript check
|
|
167
|
+
npm run lint # Biome lint
|
|
168
|
+
npm run format # Biome format + auto-fix
|
|
169
|
+
npm run smoke # Run smoke test against sandbox
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Smoke Test
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
cp .env.example .env.local
|
|
176
|
+
# Add SPINWHEEL_API_KEY to .env.local
|
|
177
|
+
npm run smoke
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Scripts
|
|
181
|
+
|
|
182
|
+
| Script | Description |
|
|
183
|
+
|--------|-------------|
|
|
184
|
+
| `npm run build` | Compile to `dist/` |
|
|
185
|
+
| `npm run dev` | Watch mode |
|
|
186
|
+
| `npm run smoke` | End-to-end test against sandbox |
|
|
187
|
+
| `npm run lint` | Biome lint check |
|
|
188
|
+
| `npm run format` | Biome format + auto-fix |
|
|
189
|
+
| `npm run typecheck` | TypeScript type check |
|