@borrowbetter/arpcsdk 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/README.md +49 -9
- package/dist/index.d.mts +26 -16
- package/dist/index.d.ts +26 -16
- package/dist/index.js +51 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +64 -53
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@ const sdk = new ArpcSDK({
|
|
|
25
25
|
password: process.env.FDR_OAUTH_PASSWORD!,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// The first api call authenticates automatically — it exchanges your
|
|
29
|
+
// credentials for a bearer JWT (~900s TTL), caches it, and reuses it.
|
|
30
30
|
const elig = await sdk.api.checkEligibility({ /* … */ });
|
|
31
31
|
const faid = elig.data.application?.applicant?.fdr_applicant_id;
|
|
32
32
|
|
|
@@ -42,7 +42,7 @@ Four things to hold in your head:
|
|
|
42
42
|
|
|
43
43
|
- **Two hosts.** Auth happens on the **OAuth host** (`POST /v1/token`, HTTP Basic). Everything else goes to the **API gateway**. The SDK routes each call to the right one.
|
|
44
44
|
- **The passport.** `fdr_applicant_id` is minted once at eligibility and threads through *every* subsequent call. You carry it between operations.
|
|
45
|
-
- **
|
|
45
|
+
- **Automatic token lifecycle.** Every `api` call carries a bearer JWT (**~900s / 15 min TTL**) that the SDK manages for you: it exchanges your credentials on the first call, caches the token, attaches it to every request, and re-exchanges ~30s before expiry. Concurrent calls share a single exchange. See [Token caching](#token-caching) to persist or share the token.
|
|
46
46
|
- **No-throw responses.** Operations return `{ status, data, headers }`. Branch on `status` — don't wrap every call in try/catch.
|
|
47
47
|
|
|
48
48
|
## The enrollment workflow
|
|
@@ -56,7 +56,7 @@ sequenceDiagram
|
|
|
56
56
|
participant GW as FDR API gateway
|
|
57
57
|
participant DS as DocuSign
|
|
58
58
|
|
|
59
|
-
App->>OAuth:
|
|
59
|
+
App->>OAuth: (lazy, on first api call) client_credentials
|
|
60
60
|
OAuth-->>App: bearer JWT (~900s)
|
|
61
61
|
|
|
62
62
|
Note over App,GW: Phase 1 — identity
|
|
@@ -89,7 +89,7 @@ sequenceDiagram
|
|
|
89
89
|
|
|
90
90
|
### Step by step
|
|
91
91
|
|
|
92
|
-
**Auth** —
|
|
92
|
+
**Auth** — handled for you. The SDK authenticates on the first `api` call, caches the token, and refreshes it automatically. See [Token caching](#token-caching) to control where the token lives.
|
|
93
93
|
|
|
94
94
|
**Phase 1 — identity**
|
|
95
95
|
- `checkEligibility()` — stateless quote (no PII). Its critical job: it **mints `fdr_applicant_id`**. Registration doesn't return the id yet, so call eligibility first. *(FDR is working on making registerV2 return the id — not shipped yet.)*
|
|
@@ -141,6 +141,41 @@ sequenceDiagram
|
|
|
141
141
|
|
|
142
142
|
Key property: **no inactivation.** Transferring does *not* close the digital lead — both stay active, and whichever path enrolls first wins. If retail enrolls first, a later digital enroll returns a duplicate / "already enrolled" error (expected). So calling it early is safe.
|
|
143
143
|
|
|
144
|
+
## Token caching
|
|
145
|
+
|
|
146
|
+
By default the bearer token lives in-memory, per-process — good enough for a single long-running service. Pass a `cache` in the config to change where it lives: persist it across restarts, or share one token across workers/instances instead of each exchanging its own.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
interface TokenCache {
|
|
150
|
+
get(): Promise<string | null>; // valid token, or null if absent/expired
|
|
151
|
+
set(token: string, expiresAt: Date): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The contract:
|
|
156
|
+
|
|
157
|
+
- **The cache owns expiry.** `get()` returns `null` once the token is stale; that `null` is what triggers a re-exchange. `expiresAt` is passed to `set()` already carrying the SDK's ~30s refresh skew, so honor it as-is.
|
|
158
|
+
- **The SDK single-flights the exchange** within a process, so a cold burst does one `/v1/token` call. Across processes, a brief overlap where two workers each exchange is possible and harmless — FDR issues independent tokens.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Example: share the token across a fleet via Redis.
|
|
162
|
+
const cache: TokenCache = {
|
|
163
|
+
async get() {
|
|
164
|
+
const [token, exp] = await redis.mget("arpc:token", "arpc:exp");
|
|
165
|
+
return token && exp && Date.now() < Number(exp) ? token : null;
|
|
166
|
+
},
|
|
167
|
+
async set(token, expiresAt) {
|
|
168
|
+
await redis
|
|
169
|
+
.multi()
|
|
170
|
+
.set("arpc:token", token)
|
|
171
|
+
.set("arpc:exp", String(expiresAt.getTime()))
|
|
172
|
+
.exec();
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const sdk = new ArpcSDK({ /* …hosts + creds… */, cache });
|
|
177
|
+
```
|
|
178
|
+
|
|
144
179
|
## Development
|
|
145
180
|
|
|
146
181
|
```bash
|
|
@@ -156,8 +191,13 @@ The typed client (`src/generated/`) is generated from the committed spec (`opena
|
|
|
156
191
|
|
|
157
192
|
## Releasing
|
|
158
193
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
194
|
+
Releases are automated via [Changesets](https://github.com/changesets/changesets) + GitHub Actions — no manual publish.
|
|
195
|
+
|
|
196
|
+
1. With your change, add a changeset describing it:
|
|
197
|
+
```bash
|
|
198
|
+
pnpm changeset
|
|
199
|
+
```
|
|
200
|
+
Pick the bump (patch/minor/major) and write a summary. Commit the generated `.changeset/*.md` alongside your code.
|
|
201
|
+
2. Merge to `main`. The **Release** workflow (`.github/workflows/release.yml`) then runs `changeset version` (bumps `package.json` + updates `CHANGELOG.md`, consuming the changeset), commits `chore: version packages`, and publishes to npm.
|
|
162
202
|
|
|
163
|
-
|
|
203
|
+
Publishing uses **npm OIDC trusted publishing** — no `NPM_TOKEN` secret. The trusted-publisher policy on npm is scoped to this repo + the `release.yml` workflow.
|
package/dist/index.d.mts
CHANGED
|
@@ -13,12 +13,6 @@ interface HttpResponse<T> {
|
|
|
13
13
|
headers: Headers;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface TokenResponse {
|
|
17
|
-
access_token: string;
|
|
18
|
-
token_type?: string;
|
|
19
|
-
expires_in?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
/**
|
|
23
17
|
* SDK configuration.
|
|
24
18
|
*
|
|
@@ -27,6 +21,20 @@ interface TokenResponse {
|
|
|
27
21
|
* is a convenience for the dev scripts (smoke / server), which load `.env` via
|
|
28
22
|
* dotenv-flow and pass the result in.
|
|
29
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* Bearer-token store. The SDK authenticates lazily on the first gateway call:
|
|
26
|
+
* it asks `get()` for a still-valid token and, on `null`, exchanges credentials
|
|
27
|
+
* and hands the fresh token to `set()`. Owning expiry is the cache's job —
|
|
28
|
+
* `get()` returns `null` once the token is stale (or near-stale). The default
|
|
29
|
+
* store is in-memory and per-process; supply one to persist across restarts or
|
|
30
|
+
* share across workers.
|
|
31
|
+
*/
|
|
32
|
+
interface TokenCache {
|
|
33
|
+
/** Return a valid bearer token, or `null` if absent/expired. */
|
|
34
|
+
get(): Promise<string | null>;
|
|
35
|
+
/** Persist a freshly exchanged token. `expiresAt` already includes the SDK's refresh skew. */
|
|
36
|
+
set(token: string, expiresAt: Date): Promise<void>;
|
|
37
|
+
}
|
|
30
38
|
interface ArpcConfig {
|
|
31
39
|
/** OAuth host — token exchange only (`POST /v1/token`). */
|
|
32
40
|
oauthUrl: string;
|
|
@@ -39,6 +47,8 @@ interface ArpcConfig {
|
|
|
39
47
|
username: string;
|
|
40
48
|
/** OAuth client_secret (HTTP Basic password). */
|
|
41
49
|
password: string;
|
|
50
|
+
/** Bearer-token store. Defaults to an in-memory, per-process cache. */
|
|
51
|
+
cache?: TokenCache;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
/**
|
|
@@ -2802,13 +2812,18 @@ interface UwSubmissionV2Response {
|
|
|
2802
2812
|
* `scripts/smoke.ts` for a full end-to-end reference sequence (incl. the program
|
|
2803
2813
|
* poll loop).
|
|
2804
2814
|
*
|
|
2815
|
+
* Auth is lazy: the first `api` call exchanges credentials for a bearer JWT and
|
|
2816
|
+
* caches it (~900s TTL), then re-exchanges shortly before it expires. There's no
|
|
2817
|
+
* explicit login step. Supply a `cache` in the config to persist the token
|
|
2818
|
+
* across restarts or share it across workers; otherwise it's held in-process.
|
|
2819
|
+
*
|
|
2805
2820
|
* Operations never throw on a non-2xx: each returns `{ status, data, headers }`,
|
|
2806
2821
|
* so a business gate (e.g. a UW/DRA readiness failure) comes back as a normal
|
|
2807
2822
|
* response you inspect via `status`/`data`. Only transport errors throw.
|
|
2808
2823
|
*
|
|
2809
|
-
* Note: config and the
|
|
2810
|
-
* per process. A second instance reconfigures the first; instances are
|
|
2811
|
-
* isolated (single-tenant by design).
|
|
2824
|
+
* Note: config and the default token cache are process-global — construct one
|
|
2825
|
+
* `ArpcSDK` per process. A second instance reconfigures the first; instances are
|
|
2826
|
+
* not isolated (single-tenant by design).
|
|
2812
2827
|
*
|
|
2813
2828
|
* @example
|
|
2814
2829
|
* ```typescript
|
|
@@ -2819,7 +2834,7 @@ interface UwSubmissionV2Response {
|
|
|
2819
2834
|
* password: process.env.FDR_OAUTH_PASSWORD!,
|
|
2820
2835
|
* });
|
|
2821
2836
|
*
|
|
2822
|
-
*
|
|
2837
|
+
* // The first call authenticates automatically and caches the token.
|
|
2823
2838
|
* const elig = await sdk.api.checkEligibility({ ... });
|
|
2824
2839
|
* const faid = elig.data.application?.applicant?.fdr_applicant_id;
|
|
2825
2840
|
* ```
|
|
@@ -2844,11 +2859,6 @@ declare class ArpcSDK {
|
|
|
2844
2859
|
createProgramSummaryTask: (id: string, programSummaryTaskRequest: ProgramSummaryTaskRequest, options?: Partial<RequestConfig> | undefined) => Promise<HttpResponse<ProgramSummaryTaskResponse>>;
|
|
2845
2860
|
};
|
|
2846
2861
|
constructor(config: ArpcConfig);
|
|
2847
|
-
/**
|
|
2848
|
-
* Exchange OAuth client credentials for a bearer JWT and store it for
|
|
2849
|
-
* subsequent `api` calls. Token TTL is ~900s — re-call to refresh.
|
|
2850
|
-
*/
|
|
2851
|
-
authenticate(): Promise<TokenResponse>;
|
|
2852
2862
|
}
|
|
2853
2863
|
|
|
2854
|
-
export { type ARPCErrorResponse, type Address, type Applicant, type ApplicationSendEmailResponse, type ArpcConfig, ArpcSDK, type AuditInfo, type BankDetails, type BankDetailsInput, type BankUpdateRequest, type Check, CheckType, type CoApplicant, type Consents, type CreateLeadRequest, type CreateLeadResponse, type CreditPullConsent, type DebtAccount, type DraApplicant, type DraApplicantInput, DraApplicantInputSigningType, type DraRequest, type DraResponse, type EligibilityAddress, type EligibilityApplicant, type EligibilityApplication, type EligibilityDebtAccount, type EligibilityRequest, type EligibilityResponse, type ErrorDetails, type FieldValidationError, FieldValidationErrorReasonCode, type HttpResponse, type IneligibleReason, type LeadApplicant, LeadApplicantEmploymentStatus, type LeadApplicantInput, LeadApplicantPayFrequency, type LeadApplication, LeadApplicationCreditPullSource, LeadApplicationFdrOrCss, LeadApplicationFixedIncome, LeadApplicationOwnOrRent, type LeadCondition, LeadConditionActive, type LeadCreditor, type LeadDebtAccount, LeadDebtAccountOwnership, LeadDebtAccountResponsibility, type LeadDistribution, type LeadPatchRequest, type LeadReadiness, type LeadResponse, type LeadTransferRequest, type LeadTransferResponse, LeadTransferResponseResponse, type MailingAddress, type PatchAddress, type PatchApplicant, type PatchCoApplicant, type PatchCondition, type PatchDebtAccount, type PaymentOption, type ProgramRequest, type ProgramSummaryTaskRequest, type ProgramSummaryTaskResponse, type ReadinessCheck, ReadinessCheckType, type ReadinessErrorResponse, ReadinessErrorResponseErrorCode, type ReadinessResponse, type RegisterApplicantResponse, type RegisterApplicantV2Address, type RegisterApplicantV2Request, type SpinwheelNetworkUserRequest, type SpinwheelNetworkUserResponse, type StatelessReadinessRequest, type
|
|
2864
|
+
export { type ARPCErrorResponse, type Address, type Applicant, type ApplicationSendEmailResponse, type ArpcConfig, ArpcSDK, type AuditInfo, type BankDetails, type BankDetailsInput, type BankUpdateRequest, type Check, CheckType, type CoApplicant, type Consents, type CreateLeadRequest, type CreateLeadResponse, type CreditPullConsent, type DebtAccount, type DraApplicant, type DraApplicantInput, DraApplicantInputSigningType, type DraRequest, type DraResponse, type EligibilityAddress, type EligibilityApplicant, type EligibilityApplication, type EligibilityDebtAccount, type EligibilityRequest, type EligibilityResponse, type ErrorDetails, type FieldValidationError, FieldValidationErrorReasonCode, type HttpResponse, type IneligibleReason, type LeadApplicant, LeadApplicantEmploymentStatus, type LeadApplicantInput, LeadApplicantPayFrequency, type LeadApplication, LeadApplicationCreditPullSource, LeadApplicationFdrOrCss, LeadApplicationFixedIncome, LeadApplicationOwnOrRent, type LeadCondition, LeadConditionActive, type LeadCreditor, type LeadDebtAccount, LeadDebtAccountOwnership, LeadDebtAccountResponsibility, type LeadDistribution, type LeadPatchRequest, type LeadReadiness, type LeadResponse, type LeadTransferRequest, type LeadTransferResponse, LeadTransferResponseResponse, type MailingAddress, type PatchAddress, type PatchApplicant, type PatchCoApplicant, type PatchCondition, type PatchDebtAccount, type PaymentOption, type ProgramRequest, type ProgramSummaryTaskRequest, type ProgramSummaryTaskResponse, type ReadinessCheck, ReadinessCheckType, type ReadinessErrorResponse, ReadinessErrorResponseErrorCode, type ReadinessResponse, type RegisterApplicantResponse, type RegisterApplicantV2Address, type RegisterApplicantV2Request, type SpinwheelNetworkUserRequest, type SpinwheelNetworkUserResponse, type StatelessReadinessRequest, type TokenCache, type Tracking, type UwSubmissionV2Response };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,12 +13,6 @@ interface HttpResponse<T> {
|
|
|
13
13
|
headers: Headers;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface TokenResponse {
|
|
17
|
-
access_token: string;
|
|
18
|
-
token_type?: string;
|
|
19
|
-
expires_in?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
/**
|
|
23
17
|
* SDK configuration.
|
|
24
18
|
*
|
|
@@ -27,6 +21,20 @@ interface TokenResponse {
|
|
|
27
21
|
* is a convenience for the dev scripts (smoke / server), which load `.env` via
|
|
28
22
|
* dotenv-flow and pass the result in.
|
|
29
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* Bearer-token store. The SDK authenticates lazily on the first gateway call:
|
|
26
|
+
* it asks `get()` for a still-valid token and, on `null`, exchanges credentials
|
|
27
|
+
* and hands the fresh token to `set()`. Owning expiry is the cache's job —
|
|
28
|
+
* `get()` returns `null` once the token is stale (or near-stale). The default
|
|
29
|
+
* store is in-memory and per-process; supply one to persist across restarts or
|
|
30
|
+
* share across workers.
|
|
31
|
+
*/
|
|
32
|
+
interface TokenCache {
|
|
33
|
+
/** Return a valid bearer token, or `null` if absent/expired. */
|
|
34
|
+
get(): Promise<string | null>;
|
|
35
|
+
/** Persist a freshly exchanged token. `expiresAt` already includes the SDK's refresh skew. */
|
|
36
|
+
set(token: string, expiresAt: Date): Promise<void>;
|
|
37
|
+
}
|
|
30
38
|
interface ArpcConfig {
|
|
31
39
|
/** OAuth host — token exchange only (`POST /v1/token`). */
|
|
32
40
|
oauthUrl: string;
|
|
@@ -39,6 +47,8 @@ interface ArpcConfig {
|
|
|
39
47
|
username: string;
|
|
40
48
|
/** OAuth client_secret (HTTP Basic password). */
|
|
41
49
|
password: string;
|
|
50
|
+
/** Bearer-token store. Defaults to an in-memory, per-process cache. */
|
|
51
|
+
cache?: TokenCache;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
/**
|
|
@@ -2802,13 +2812,18 @@ interface UwSubmissionV2Response {
|
|
|
2802
2812
|
* `scripts/smoke.ts` for a full end-to-end reference sequence (incl. the program
|
|
2803
2813
|
* poll loop).
|
|
2804
2814
|
*
|
|
2815
|
+
* Auth is lazy: the first `api` call exchanges credentials for a bearer JWT and
|
|
2816
|
+
* caches it (~900s TTL), then re-exchanges shortly before it expires. There's no
|
|
2817
|
+
* explicit login step. Supply a `cache` in the config to persist the token
|
|
2818
|
+
* across restarts or share it across workers; otherwise it's held in-process.
|
|
2819
|
+
*
|
|
2805
2820
|
* Operations never throw on a non-2xx: each returns `{ status, data, headers }`,
|
|
2806
2821
|
* so a business gate (e.g. a UW/DRA readiness failure) comes back as a normal
|
|
2807
2822
|
* response you inspect via `status`/`data`. Only transport errors throw.
|
|
2808
2823
|
*
|
|
2809
|
-
* Note: config and the
|
|
2810
|
-
* per process. A second instance reconfigures the first; instances are
|
|
2811
|
-
* isolated (single-tenant by design).
|
|
2824
|
+
* Note: config and the default token cache are process-global — construct one
|
|
2825
|
+
* `ArpcSDK` per process. A second instance reconfigures the first; instances are
|
|
2826
|
+
* not isolated (single-tenant by design).
|
|
2812
2827
|
*
|
|
2813
2828
|
* @example
|
|
2814
2829
|
* ```typescript
|
|
@@ -2819,7 +2834,7 @@ interface UwSubmissionV2Response {
|
|
|
2819
2834
|
* password: process.env.FDR_OAUTH_PASSWORD!,
|
|
2820
2835
|
* });
|
|
2821
2836
|
*
|
|
2822
|
-
*
|
|
2837
|
+
* // The first call authenticates automatically and caches the token.
|
|
2823
2838
|
* const elig = await sdk.api.checkEligibility({ ... });
|
|
2824
2839
|
* const faid = elig.data.application?.applicant?.fdr_applicant_id;
|
|
2825
2840
|
* ```
|
|
@@ -2844,11 +2859,6 @@ declare class ArpcSDK {
|
|
|
2844
2859
|
createProgramSummaryTask: (id: string, programSummaryTaskRequest: ProgramSummaryTaskRequest, options?: Partial<RequestConfig> | undefined) => Promise<HttpResponse<ProgramSummaryTaskResponse>>;
|
|
2845
2860
|
};
|
|
2846
2861
|
constructor(config: ArpcConfig);
|
|
2847
|
-
/**
|
|
2848
|
-
* Exchange OAuth client credentials for a bearer JWT and store it for
|
|
2849
|
-
* subsequent `api` calls. Token TTL is ~900s — re-call to refresh.
|
|
2850
|
-
*/
|
|
2851
|
-
authenticate(): Promise<TokenResponse>;
|
|
2852
2862
|
}
|
|
2853
2863
|
|
|
2854
|
-
export { type ARPCErrorResponse, type Address, type Applicant, type ApplicationSendEmailResponse, type ArpcConfig, ArpcSDK, type AuditInfo, type BankDetails, type BankDetailsInput, type BankUpdateRequest, type Check, CheckType, type CoApplicant, type Consents, type CreateLeadRequest, type CreateLeadResponse, type CreditPullConsent, type DebtAccount, type DraApplicant, type DraApplicantInput, DraApplicantInputSigningType, type DraRequest, type DraResponse, type EligibilityAddress, type EligibilityApplicant, type EligibilityApplication, type EligibilityDebtAccount, type EligibilityRequest, type EligibilityResponse, type ErrorDetails, type FieldValidationError, FieldValidationErrorReasonCode, type HttpResponse, type IneligibleReason, type LeadApplicant, LeadApplicantEmploymentStatus, type LeadApplicantInput, LeadApplicantPayFrequency, type LeadApplication, LeadApplicationCreditPullSource, LeadApplicationFdrOrCss, LeadApplicationFixedIncome, LeadApplicationOwnOrRent, type LeadCondition, LeadConditionActive, type LeadCreditor, type LeadDebtAccount, LeadDebtAccountOwnership, LeadDebtAccountResponsibility, type LeadDistribution, type LeadPatchRequest, type LeadReadiness, type LeadResponse, type LeadTransferRequest, type LeadTransferResponse, LeadTransferResponseResponse, type MailingAddress, type PatchAddress, type PatchApplicant, type PatchCoApplicant, type PatchCondition, type PatchDebtAccount, type PaymentOption, type ProgramRequest, type ProgramSummaryTaskRequest, type ProgramSummaryTaskResponse, type ReadinessCheck, ReadinessCheckType, type ReadinessErrorResponse, ReadinessErrorResponseErrorCode, type ReadinessResponse, type RegisterApplicantResponse, type RegisterApplicantV2Address, type RegisterApplicantV2Request, type SpinwheelNetworkUserRequest, type SpinwheelNetworkUserResponse, type StatelessReadinessRequest, type
|
|
2864
|
+
export { type ARPCErrorResponse, type Address, type Applicant, type ApplicationSendEmailResponse, type ArpcConfig, ArpcSDK, type AuditInfo, type BankDetails, type BankDetailsInput, type BankUpdateRequest, type Check, CheckType, type CoApplicant, type Consents, type CreateLeadRequest, type CreateLeadResponse, type CreditPullConsent, type DebtAccount, type DraApplicant, type DraApplicantInput, DraApplicantInputSigningType, type DraRequest, type DraResponse, type EligibilityAddress, type EligibilityApplicant, type EligibilityApplication, type EligibilityDebtAccount, type EligibilityRequest, type EligibilityResponse, type ErrorDetails, type FieldValidationError, FieldValidationErrorReasonCode, type HttpResponse, type IneligibleReason, type LeadApplicant, LeadApplicantEmploymentStatus, type LeadApplicantInput, LeadApplicantPayFrequency, type LeadApplication, LeadApplicationCreditPullSource, LeadApplicationFdrOrCss, LeadApplicationFixedIncome, LeadApplicationOwnOrRent, type LeadCondition, LeadConditionActive, type LeadCreditor, type LeadDebtAccount, LeadDebtAccountOwnership, LeadDebtAccountResponsibility, type LeadDistribution, type LeadPatchRequest, type LeadReadiness, type LeadResponse, type LeadTransferRequest, type LeadTransferResponse, LeadTransferResponseResponse, type MailingAddress, type PatchAddress, type PatchApplicant, type PatchCoApplicant, type PatchCondition, type PatchDebtAccount, type PaymentOption, type ProgramRequest, type ProgramSummaryTaskRequest, type ProgramSummaryTaskResponse, type ReadinessCheck, ReadinessCheckType, type ReadinessErrorResponse, ReadinessErrorResponseErrorCode, type ReadinessResponse, type RegisterApplicantResponse, type RegisterApplicantV2Address, type RegisterApplicantV2Request, type SpinwheelNetworkUserRequest, type SpinwheelNetworkUserResponse, type StatelessReadinessRequest, type TokenCache, type Tracking, type UwSubmissionV2Response };
|
package/dist/index.js
CHANGED
|
@@ -6,8 +6,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
6
6
|
|
|
7
7
|
var ky__default = /*#__PURE__*/_interopDefault(ky);
|
|
8
8
|
|
|
9
|
-
// src/auth.ts
|
|
10
|
-
|
|
11
9
|
// src/config.ts
|
|
12
10
|
var current = null;
|
|
13
11
|
function configure(config) {
|
|
@@ -21,10 +19,48 @@ function getConfig() {
|
|
|
21
19
|
}
|
|
22
20
|
return current;
|
|
23
21
|
}
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
var TOKEN_SKEW_MS = 3e4;
|
|
23
|
+
var DEFAULT_TTL_S = 900;
|
|
24
|
+
async function exchangeToken() {
|
|
25
|
+
const { oauthUrl, username, password } = getConfig();
|
|
26
|
+
const basic = Buffer.from(`${username}:${password}`).toString("base64");
|
|
27
|
+
return ky__default.default.post(`${oauthUrl}/v1/token`, {
|
|
28
|
+
headers: { Authorization: `Basic ${basic}` },
|
|
29
|
+
body: new URLSearchParams({ grant_type: "client_credentials" })
|
|
30
|
+
}).json();
|
|
31
|
+
}
|
|
32
|
+
var memToken = null;
|
|
33
|
+
var memExpiresAt = 0;
|
|
34
|
+
var defaultCache = {
|
|
35
|
+
async get() {
|
|
36
|
+
return memToken && Date.now() < memExpiresAt ? memToken : null;
|
|
37
|
+
},
|
|
38
|
+
async set(token, expiresAt) {
|
|
39
|
+
memToken = token;
|
|
40
|
+
memExpiresAt = expiresAt.getTime();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var inflight = null;
|
|
44
|
+
function resolveToken() {
|
|
45
|
+
const store = getConfig().cache ?? defaultCache;
|
|
46
|
+
if (inflight) return inflight;
|
|
47
|
+
inflight = (async () => {
|
|
48
|
+
const cached = await store.get();
|
|
49
|
+
if (cached) return cached;
|
|
50
|
+
const res = await exchangeToken();
|
|
51
|
+
const ttl = (res.expires_in ?? DEFAULT_TTL_S) * 1e3;
|
|
52
|
+
await store.set(
|
|
53
|
+
res.access_token,
|
|
54
|
+
new Date(Date.now() + ttl - TOKEN_SKEW_MS)
|
|
55
|
+
);
|
|
56
|
+
return res.access_token;
|
|
57
|
+
})().finally(() => {
|
|
58
|
+
inflight = null;
|
|
59
|
+
});
|
|
60
|
+
return inflight;
|
|
27
61
|
}
|
|
62
|
+
|
|
63
|
+
// src/http/client.ts
|
|
28
64
|
var customInstance = async (request, options) => {
|
|
29
65
|
const { url, method, params, data, signal } = { ...request, ...options };
|
|
30
66
|
const headers = { ...request.headers, ...options?.headers };
|
|
@@ -37,9 +73,16 @@ var customInstance = async (request, options) => {
|
|
|
37
73
|
}
|
|
38
74
|
const response = await ky__default.default(target, {
|
|
39
75
|
method,
|
|
40
|
-
headers
|
|
41
|
-
|
|
42
|
-
|
|
76
|
+
headers,
|
|
77
|
+
hooks: {
|
|
78
|
+
// Lazy bearer injection: resolveToken() exchanges on the first call
|
|
79
|
+
// and refreshes once the cached token goes stale. The OAuth exchange
|
|
80
|
+
// itself runs on a bare ky.post (no hook), so there's no recursion.
|
|
81
|
+
beforeRequest: [
|
|
82
|
+
async (req) => {
|
|
83
|
+
req.headers.set("Authorization", `Bearer ${await resolveToken()}`);
|
|
84
|
+
}
|
|
85
|
+
]
|
|
43
86
|
},
|
|
44
87
|
...data !== void 0 ? { json: data } : {},
|
|
45
88
|
signal,
|
|
@@ -60,18 +103,6 @@ var customInstance = async (request, options) => {
|
|
|
60
103
|
return { status: response.status, data: body, headers: response.headers };
|
|
61
104
|
};
|
|
62
105
|
|
|
63
|
-
// src/auth.ts
|
|
64
|
-
async function exchangeToken() {
|
|
65
|
-
const { oauthUrl, username, password } = getConfig();
|
|
66
|
-
const basic = Buffer.from(`${username}:${password}`).toString("base64");
|
|
67
|
-
const token = await ky__default.default.post(`${oauthUrl}/v1/token`, {
|
|
68
|
-
headers: { Authorization: `Basic ${basic}` },
|
|
69
|
-
body: new URLSearchParams({ grant_type: "client_credentials" })
|
|
70
|
-
}).json();
|
|
71
|
-
setBearerToken(token.access_token);
|
|
72
|
-
return token;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
106
|
// src/generated/arpc.ts
|
|
76
107
|
var getARPCAchieveResolutionPartnerConnectAPI = () => {
|
|
77
108
|
const createLeadSync = (createLeadRequest, options) => {
|
|
@@ -241,13 +272,6 @@ var ArpcSDK = class {
|
|
|
241
272
|
this.api = getARPCAchieveResolutionPartnerConnectAPI();
|
|
242
273
|
configure(config);
|
|
243
274
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Exchange OAuth client credentials for a bearer JWT and store it for
|
|
246
|
-
* subsequent `api` calls. Token TTL is ~900s — re-call to refresh.
|
|
247
|
-
*/
|
|
248
|
-
authenticate() {
|
|
249
|
-
return exchangeToken();
|
|
250
|
-
}
|
|
251
275
|
};
|
|
252
276
|
|
|
253
277
|
exports.ArpcSDK = ArpcSDK;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/http/client.ts","../src/auth.ts","../src/generated/arpc.ts","../src/index.ts"],"names":["ky"],"mappings":";;;;;;;;;;;AAsBA,IAAI,OAAA,GAA6B,IAAA;AAG1B,SAAS,UAAU,MAAA,EAA0B;AACnD,EAAA,OAAA,GAAU,MAAA;AACX;AAGO,SAAS,SAAA,GAAwB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACT;AAAA,KACD;AAAA,EACD;AACA,EAAA,OAAO,OAAA;AACR;ACxBA,IAAI,WAAA,GAA6B,IAAA;AAC1B,SAAS,eAAe,KAAA,EAA4B;AAC1D,EAAA,WAAA,GAAc,KAAA;AACf;AAmBO,IAAM,cAAA,GAAiB,OAC7B,OAAA,EACA,OAAA,KAC8B;AAC9B,EAAA,MAAM,EAAE,GAAA,EAAK,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAO,GAAI,EAAE,GAAG,OAAA,EAAS,GAAG,OAAA,EAAQ;AAIvE,EAAA,MAAM,UAAU,EAAE,GAAG,QAAQ,OAAA,EAAS,GAAG,SAAS,OAAA,EAAQ;AAE1D,EAAA,MAAM,SAAS,IAAI,GAAA,CAAI,GAAA,EAAK,SAAA,GAAY,UAAU,CAAA;AAClD,EAAA,IAAI,MAAA,EAAQ;AACX,IAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AAClD,MAAA,IAAI,KAAA,KAAU,UAAa,KAAA,KAAU,IAAA;AACpC,QAAA,MAAA,CAAO,YAAA,CAAa,GAAA,CAAI,GAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,IAC5C;AAAA,EACD;AAEA,EAAA,M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CAAU,MAAM,CAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAA,GAAuC;AACtC,IAAA,OAAO,aAAA,EAAc;AAAA,EACtB;AACD","file":"index.js","sourcesContent":["/**\n * SDK configuration.\n *\n * The library never reads the environment itself — a consumer constructs\n * `new ArpcSDK(config)`, which calls `configure()`. The `configFromEnv()` helper\n * is a convenience for the dev scripts (smoke / server), which load `.env` via\n * dotenv-flow and pass the result in.\n */\nexport interface ArpcConfig {\n\t/** OAuth host — token exchange only (`POST /v1/token`). */\n\toauthUrl: string;\n\t/** API gateway host — every non-auth call. */\n\tgatewayUrl: string;\n\t/**\n\t * OAuth client_id (HTTP Basic username). Also used as the lead's\n\t * `seller_agent_email` — the OAuth identity is a registered DRA agent.\n\t */\n\tusername: string;\n\t/** OAuth client_secret (HTTP Basic password). */\n\tpassword: string;\n}\n\nlet current: ArpcConfig | null = null;\n\n/** Set the active config. Called by the `ArpcSDK` constructor. */\nexport function configure(config: ArpcConfig): void {\n\tcurrent = config;\n}\n\n/** Read the active config. Throws if the SDK hasn't been constructed yet. */\nexport function getConfig(): ArpcConfig {\n\tif (!current) {\n\t\tthrow new Error(\n\t\t\t\"ArpcSDK is not configured — construct `new ArpcSDK(config)` before making calls\",\n\t\t);\n\t}\n\treturn current;\n}\n\n/**\n * Build a config from environment variables. Not used by the library itself —\n * only the dev scripts call this after loading `.env`.\n */\nexport function configFromEnv(\n\tenv: NodeJS.ProcessEnv = process.env,\n): ArpcConfig {\n\tconst need = (key: string): string => {\n\t\tconst value = env[key];\n\t\tif (!value)\n\t\t\tthrow new Error(`Missing required env var: ${key} (set it in .env)`);\n\t\treturn value;\n\t};\n\treturn {\n\t\toauthUrl: need(\"FDR_OAUTH_URL\"),\n\t\tgatewayUrl: need(\"FDR_API_GATEWAY_URL\"),\n\t\tusername: need(\"FDR_OAUTH_USERNAME\"),\n\t\tpassword: need(\"FDR_OAUTH_PASSWORD\"),\n\t};\n}\n","import ky from \"ky\";\nimport { getConfig } from \"../config\";\n\n// ---------------------------------------------------------------------------\n// Orval custom mutator (ky-backed).\n//\n// Every generated operation calls `customInstance<T>(config, options)`. We\n// route all calls to the API gateway, inject the bearer token, and return a\n// small { status, data, headers } wrapper WITHOUT throwing on non-2xx — the\n// caller inspects status codes itself (202 + Retry-After on program, 400 on a\n// UW/DRA gate, etc.).\n// ---------------------------------------------------------------------------\n\nlet bearerToken: string | null = null;\nexport function setBearerToken(token: string | null): void {\n\tbearerToken = token;\n}\n\n// Shape Orval passes as the first arg (axios-style request config).\nexport interface RequestConfig {\n\turl: string;\n\tmethod: string;\n\tparams?: Record<string, unknown>;\n\tdata?: unknown;\n\theaders?: Record<string, string>;\n\tsignal?: AbortSignal;\n\tresponseType?: string;\n}\n\nexport interface HttpResponse<T> {\n\tstatus: number;\n\tdata: T;\n\theaders: Headers;\n}\n\nexport const customInstance = async <T>(\n\trequest: RequestConfig,\n\toptions?: Partial<RequestConfig>,\n): Promise<HttpResponse<T>> => {\n\tconst { url, method, params, data, signal } = { ...request, ...options };\n\t// Merge headers from both sides — a per-call override (e.g. an\n\t// x-correlation-id in `options.headers`) must not drop the operation's\n\t// Content-Type. The bearer token is layered on last, below.\n\tconst headers = { ...request.headers, ...options?.headers };\n\n\tconst target = new URL(url, getConfig().gatewayUrl);\n\tif (params) {\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tif (value !== undefined && value !== null)\n\t\t\t\ttarget.searchParams.set(key, String(value));\n\t\t}\n\t}\n\n\tconst response = await ky(target, {\n\t\tmethod,\n\t\theaders: {\n\t\t\t...headers,\n\t\t\t...(bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}),\n\t\t},\n\t\t...(data !== undefined ? { json: data } : {}),\n\t\tsignal,\n\t\tthrowHttpErrors: false,\n\t\tretry: 0,\n\t\t// Some gateway calls (program generation in particular) can take well over ky's\n\t\t// 10s default to respond. Raise the per-request ceiling; the program poll loop\n\t\t// handles 202/Retry-After on top of this.\n\t\ttimeout: 60_000,\n\t});\n\n\tconst text = await response.text();\n\tlet body: T;\n\ttry {\n\t\tbody = (text ? JSON.parse(text) : undefined) as T;\n\t} catch {\n\t\t// Non-JSON body (e.g. a gateway HTML error page on a transient 5xx). Don't throw —\n\t\t// hand back the raw text so callers can inspect status/body and retry as needed.\n\t\tbody = text as unknown as T;\n\t}\n\treturn { status: response.status, data: body, headers: response.headers };\n};\n","import ky from \"ky\";\nimport { getConfig } from \"./config\";\nimport { setBearerToken } from \"./http/client\";\n\n// Token exchange lives in the orchestration layer, not the generated client:\n// it targets the OAuth host (not the gateway), uses HTTP Basic, and is\n// form-encoded. We store the resulting JWT for the mutator to attach.\nexport interface TokenResponse {\n\taccess_token: string;\n\ttoken_type?: string;\n\texpires_in?: number;\n}\n\nexport async function exchangeToken(): Promise<TokenResponse> {\n\tconst { oauthUrl, username, password } = getConfig();\n\tconst basic = Buffer.from(`${username}:${password}`).toString(\"base64\");\n\n\tconst token = await ky\n\t\t.post(`${oauthUrl}/v1/token`, {\n\t\t\theaders: { Authorization: `Basic ${basic}` },\n\t\t\tbody: new URLSearchParams({ grant_type: \"client_credentials\" }),\n\t\t})\n\t\t.json<TokenResponse>();\n\n\tsetBearerToken(token.access_token);\n\treturn token;\n}\n","/**\n * Generated by orval v7.21.0 🍺\n * Do not edit manually.\n * ARPC — Achieve Resolution Partner Connect API\n * FDR Wholesale API — A Hybrid Integration Model designed to maximise partner velocity without compromising enterprise data standards. DEX (Digital Enrollment Experience) is the partner-facing integration layer that powers the full applicant lifecycle. The `fdr_applicant_id` acts as the applicant's passport across all systems, persisted from first eligibility check through enrollment. All endpoints require a valid Bearer JWT with the `arpc.all` role.\n * OpenAPI spec version: 2026.15.0\n */\nimport type {\n ARPCErrorResponse,\n ApplicationSendEmailResponse,\n BankUpdateRequest,\n CreateLeadRequest,\n CreateLeadResponse,\n DraRequest,\n DraResponse,\n EligibilityRequest,\n EligibilityResponse,\n LeadPatchRequest,\n LeadResponse,\n LeadTransferRequest,\n LeadTransferResponse,\n ProgramRequest,\n ProgramSummaryTaskRequest,\n ProgramSummaryTaskResponse,\n ReadinessResponse,\n RegisterApplicantResponse,\n RegisterApplicantV2Request,\n SpinwheelNetworkUserRequest,\n SpinwheelNetworkUserResponse,\n StatelessReadinessRequest,\n UwSubmissionV2Response\n} from './model';\n\nimport { customInstance } from '../http/client';\ntype SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n\n export const getARPCAchieveResolutionPartnerConnectAPI = () => {\n/**\n * Synchronous Orchestration: Handles both lead creation and income/expense data in one step, eliminating the async polling black box. Data authority shifts here — Achieve (SUIP SF) becomes the Source of Truth once the lead is formally promoted. Returns the full lead creation result including program options.\n * @summary Sync wholesale lead creation\n */\nconst createLeadSync = (\n createLeadRequest: CreateLeadRequest,\n options?: SecondParameter<typeof customInstance<CreateLeadResponse>>,) => {\n return customInstance<CreateLeadResponse>(\n {url: `/v3/application`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: createLeadRequest\n },\n options);\n }\n \n/**\n * Stateless Readiness Check: Pre-flight validation before initiating program calculations. Catches duplicate SSNs or emails early to prevent downstream failures. Requires a valid Authorization header.\n * @summary Check application readiness\n */\nconst checkApplicationReadiness = (\n statelessReadinessRequest: StatelessReadinessRequest,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/readiness`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: statelessReadinessRequest\n },\n options);\n }\n \n/**\n * Recovery endpoint — only required when the async Spinwheel user creation triggered by `POST /v1/applicant/register` fails due to a user error (e.g. invalid SSN or DOB). Not needed in the happy path. Authenticates the seller, resolves the law firm / program, creates an applicant ID when needed, and connects the applicant to the Spinwheel network. Requires a valid Authorization header.\n * @summary Create / connect Spinwheel network user\n */\nconst createSpinwheelNetworkUser = (\n spinwheelNetworkUserRequest: SpinwheelNetworkUserRequest,\n options?: SecondParameter<typeof customInstance<SpinwheelNetworkUserResponse>>,) => {\n return customInstance<SpinwheelNetworkUserResponse>(\n {url: `/v1/application/spinwheel-network-user`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: spinwheelNetworkUserRequest\n },\n options);\n }\n \n/**\n * Authenticates the seller, validates banking disclosure requirements, optionally validates the submitted account and routing numbers, patches the program, and returns the refreshed lead payload. Requires a valid Authorization header.\n * @summary Update applicant bank details\n */\nconst updateApplicationBankDetails = (\n applicantId: string,\n bankUpdateRequest: BankUpdateRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/bank-update/${applicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: bankUpdateRequest\n },\n options);\n }\n \n/**\n * Banking Disclosure: Manually triggers the banking disclosure email. **This endpoint is optional** — it is only needed when the disclosure was not already sent automatically by `POST /v2/application/uw-submission/{fdrApplicantId}` (which auto-sends on full UW approval). Use this endpoint for conditional approvals or when the v1 UW submission path is in use. A critical legal prerequisite that must be completed before enrollment can proceed. Requires a valid Authorization header.\n * @summary Send banking disclosure email (optional — only if not auto-sent by v2 UW submission)\n */\nconst sendEmail = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<ApplicationSendEmailResponse>>,) => {\n return customInstance<ApplicationSendEmailResponse>(\n {url: `/v1/application/send-email/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Submits a lead evaluation request. fdr_applicant_id is required in the request body. Requires a valid Authorization header with the arpc.all role.\n * @summary Transfer a lead to the debt-resolution program\n */\nconst leadTransfer = (\n leadTransferRequest: LeadTransferRequest,\n options?: SecondParameter<typeof customInstance<LeadTransferResponse>>,) => {\n return customInstance<LeadTransferResponse>(\n {url: `/v1/application/lead-transfer`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: leadTransferRequest\n },\n options);\n }\n \n/**\n * Fetches the current state of an application / lead record by FDR applicant ID. Requires a valid Authorization header.\n * @summary Read application / lead details\n */\nconst readLead = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'GET'\n },\n options);\n }\n \n/**\n * Applies a partial update to an existing wholesale lead record. Requires a valid Authorization header and an x-correlation-id header for request tracing.\n * @summary Partial update of application / lead record\n */\nconst patchLead = (\n fdrApplicantId: string,\n leadPatchRequest: LeadPatchRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: leadPatchRequest\n },\n options);\n }\n \n/**\n * DRA Readiness Check: Final pre-flight confirming the lead is approved and all prerequisites are met before initiating the embedded signing session. Requires a valid Authorization header.\n * @summary Get application readiness status\n */\nconst getApplicationReadiness = (\n applicantId: string,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/${applicantId}/readiness`, method: 'GET'\n },\n options);\n }\n \n/**\n * Embedded DRA Signing: Returns an Embedded Signing URL so the applicant signs the Debt Resolution Agreement via DocuSign directly within the Symple UI, preventing session breakage. Successful legal execution triggers automatic enrollment. Requires a valid Authorization header.\n * @summary Generate Debt Resolution Agreement (DRA)\n */\nconst generateDra = (\n applicantId: string,\n draRequest: DraRequest,\n options?: SecondParameter<typeof customInstance<DraResponse>>,) => {\n return customInstance<DraResponse>(\n {url: `/v2/application/${applicantId}/dra`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: draRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint.** `POST /v1/applicant/register` is deprecated and will be retired by end of July 2026 (deadline can be extended on request if your team needs more time). Identity Anchoring: Persists applicant PII to the Managed Package and generates the `fdr_applicant_id` — the applicant's passport across all systems. Routes to the correct Salesforce target (MP or WiB) based on seller identity, and triggers the async credit fetch. Requires a valid Authorization header.\n * @summary Seller-aware applicant registration (v2 — unified ARPCErrorResponse envelope) — recommended\n */\nconst registerApplicantV2 = (\n registerApplicantV2Request: RegisterApplicantV2Request,\n options?: SecondParameter<typeof customInstance<RegisterApplicantResponse>>,) => {\n return customInstance<RegisterApplicantResponse>(\n {url: `/v2/applicant/register`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: registerApplicantV2Request\n },\n options);\n }\n \n/**\n * Async Polling Loop: Call this single endpoint for both initial generation and refresh. Returns 202 Accepted with a Retry-After header while credit is still pending. Once ready, the Managed Package orchestrates the calculation and persists the program result. Requires a valid Authorization header.\n * @summary Generate application program (v1)\n */\nconst generateProgramV1 = (\n programRequest: ProgramRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/program`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programRequest\n },\n options);\n }\n \n/**\n * Eligibility Scout: A stateless, real-time quote based on anonymised data — no PII required. Returns estimated program options to anchor the conversation before any registration occurs. Requires a valid Authorization header.\n * @summary Check application eligibility\n */\nconst checkEligibility = (\n eligibilityRequest: EligibilityRequest,\n options?: SecondParameter<typeof customInstance<EligibilityResponse>>,) => {\n return customInstance<EligibilityResponse>(\n {url: `/v2/application/eligibility`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: eligibilityRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint — supersedes v1.** Submits a wholesale application to the underwriting system. On full UW approval (`sub_status = 'UW Approved'`) the banking disclosure email is sent automatically — no separate `send-email` call is needed in this path. Conditional approvals suppress the auto-send; in that case the manual `POST /v1/application/send-email/{fdrApplicantId}` endpoint can be used. Uses the SF Object API directly (no suip-proxy hop). Requires a valid Authorization header.\n * @summary Submit application to underwriting (v2 — auto banking disclosure) — recommended\n */\nconst uwSubmissionV2 = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<UwSubmissionV2Response>>,) => {\n return customInstance<UwSubmissionV2Response>(\n {url: `/v2/application/uw-submission/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Creates a SUIP Salesforce 'Program Summary Recording' task for the applicant identified by the {id} path variable. For DEX (or missing header), the parent SF opportunity is additionally PATCHed with the seller-config partner default PSC. For DC, the task is created and the parent SF opportunity is PATCHed only when ws_psc_code is provided in the request payload.\n * @summary Create program-summary recording task\n */\nconst createProgramSummaryTask = (\n id: string,\n programSummaryTaskRequest: ProgramSummaryTaskRequest,\n options?: SecondParameter<typeof customInstance<ProgramSummaryTaskResponse>>,) => {\n return customInstance<ProgramSummaryTaskResponse>(\n {url: `/v2/application/program-summary-task/${id}`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programSummaryTaskRequest\n },\n options);\n }\n \nreturn {createLeadSync,checkApplicationReadiness,createSpinwheelNetworkUser,updateApplicationBankDetails,sendEmail,leadTransfer,readLead,patchLead,getApplicationReadiness,generateDra,registerApplicantV2,generateProgramV1,checkEligibility,uwSubmissionV2,createProgramSummaryTask}};\nexport type CreateLeadSyncResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createLeadSync']>>>\nexport type CheckApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkApplicationReadiness']>>>\nexport type CreateSpinwheelNetworkUserResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createSpinwheelNetworkUser']>>>\nexport type UpdateApplicationBankDetailsResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['updateApplicationBankDetails']>>>\nexport type SendEmailResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['sendEmail']>>>\nexport type LeadTransferResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['leadTransfer']>>>\nexport type ReadLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['readLead']>>>\nexport type PatchLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['patchLead']>>>\nexport type GetApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['getApplicationReadiness']>>>\nexport type GenerateDraResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateDra']>>>\nexport type RegisterApplicantV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['registerApplicantV2']>>>\nexport type GenerateProgramV1Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateProgramV1']>>>\nexport type CheckEligibilityResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkEligibility']>>>\nexport type UwSubmissionV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['uwSubmissionV2']>>>\nexport type CreateProgramSummaryTaskResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createProgramSummaryTask']>>>\n","import { exchangeToken, type TokenResponse } from \"./auth\";\nimport { type ArpcConfig, configure } from \"./config\";\nimport { getARPCAchieveResolutionPartnerConnectAPI } from \"./generated/arpc\";\n\nexport type { TokenResponse } from \"./auth\";\nexport type { ArpcConfig } from \"./config\";\nexport type * from \"./generated/model\";\nexport type { HttpResponse } from \"./http/client\";\n\n/**\n * ARPC SDK — a typed, agnostic client for FDR's ARPC DEX API (Achieve\n * Resolution Partner Connect, Digital Enrollment Experience).\n *\n * Thin by design: it owns the two-host routing, the OAuth token lifecycle, and\n * bearer injection, and exposes the full endpoint surface as typed operations\n * on `sdk.api`. It does not orchestrate the enrollment sequence — the caller\n * assembles payloads and threads the `fdr_applicant_id` between calls. See\n * `scripts/smoke.ts` for a full end-to-end reference sequence (incl. the program\n * poll loop).\n *\n * Operations never throw on a non-2xx: each returns `{ status, data, headers }`,\n * so a business gate (e.g. a UW/DRA readiness failure) comes back as a normal\n * response you inspect via `status`/`data`. Only transport errors throw.\n *\n * Note: config and the bearer token are process-global — construct one `ArpcSDK`\n * per process. A second instance reconfigures the first; instances are not\n * isolated (single-tenant by design).\n *\n * @example\n * ```typescript\n * const sdk = new ArpcSDK({\n * oauthUrl: \"https://oauth.stg.ffngcp.com\",\n * gatewayUrl: \"https://apis-gateway-v2.stg.fdrgcp.com\",\n * username: \"borrowbetter@seller.com\",\n * password: process.env.FDR_OAUTH_PASSWORD!,\n * });\n *\n * await sdk.authenticate();\n * const elig = await sdk.api.checkEligibility({ ... });\n * const faid = elig.data.application?.applicant?.fdr_applicant_id;\n * ```\n */\nexport class ArpcSDK {\n\t/** The full typed endpoint surface — one method per gateway operation. */\n\treadonly api = getARPCAchieveResolutionPartnerConnectAPI();\n\n\tconstructor(config: ArpcConfig) {\n\t\tconfigure(config);\n\t}\n\n\t/**\n\t * Exchange OAuth client credentials for a bearer JWT and store it for\n\t * subsequent `api` calls. Token TTL is ~900s — re-call to refresh.\n\t */\n\tauthenticate(): Promise<TokenResponse> {\n\t\treturn exchangeToken();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/auth.ts","../src/http/client.ts","../src/generated/arpc.ts","../src/index.ts"],"names":["ky"],"mappings":";;;;;;;;;AAuCA,IAAI,OAAA,GAA6B,IAAA;AAG1B,SAAS,UAAU,MAAA,EAA0B;AACnD,EAAA,OAAA,GAAU,MAAA;AACX;AAGO,SAAS,SAAA,GAAwB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACT;AAAA,KACD;AAAA,EACD;AACA,EAAA,OAAO,OAAA;AACR;ACtCA,IAAM,aAAA,GAAgB,GAAA;AAEtB,IAAM,aAAA,GAAgB,GAAA;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ACP;AAAA,QAAC,GAAA,EAAK,wCAAwC,EAAE,CAAA,CAAA;AAAA,QAAI,MAAA,EAAQ,MAAA;AAAA,QAC5D,OAAA,EAAS,EAAC,cAAA,EAAgB,kBAAA,EAAoB;AAAA,QAC9C,IAAA,EAAM;AAAA,OACR;AAAA,MACE;AAAA,KAAO;AAAA,EACT,CAAA;AAEJ,EAAA,OAAO,EAAC,cAAA,EAAe,yBAAA,EAA0B,0BAAA,EAA2B,8BAA6B,SAAA,EAAU,YAAA,EAAa,QAAA,EAAS,SAAA,EAAU,yBAAwB,WAAA,EAAY,mBAAA,EAAoB,iBAAA,EAAkB,gBAAA,EAAiB,gBAAe,wBAAA,EAAwB;AAAC,CAAA;;;ACtN/Q,IAAM,UAAN,MAAc;AAAA,EAIpB,YAAY,MAAA,EAAoB;AAFhC;AAAA,IAAA,IAAA,CAAS,MAAM,yCAAA,EAA0C;AAGxD,IAAA,SAAA,CAAU,MAAM,CAAA;AAAA,EACjB;AACD","file":"index.js","sourcesContent":["/**\n * SDK configuration.\n *\n * The library never reads the environment itself — a consumer constructs\n * `new ArpcSDK(config)`, which calls `configure()`. The `configFromEnv()` helper\n * is a convenience for the dev scripts (smoke / server), which load `.env` via\n * dotenv-flow and pass the result in.\n */\n/**\n * Bearer-token store. The SDK authenticates lazily on the first gateway call:\n * it asks `get()` for a still-valid token and, on `null`, exchanges credentials\n * and hands the fresh token to `set()`. Owning expiry is the cache's job —\n * `get()` returns `null` once the token is stale (or near-stale). The default\n * store is in-memory and per-process; supply one to persist across restarts or\n * share across workers.\n */\nexport interface TokenCache {\n\t/** Return a valid bearer token, or `null` if absent/expired. */\n\tget(): Promise<string | null>;\n\t/** Persist a freshly exchanged token. `expiresAt` already includes the SDK's refresh skew. */\n\tset(token: string, expiresAt: Date): Promise<void>;\n}\n\nexport interface ArpcConfig {\n\t/** OAuth host — token exchange only (`POST /v1/token`). */\n\toauthUrl: string;\n\t/** API gateway host — every non-auth call. */\n\tgatewayUrl: string;\n\t/**\n\t * OAuth client_id (HTTP Basic username). Also used as the lead's\n\t * `seller_agent_email` — the OAuth identity is a registered DRA agent.\n\t */\n\tusername: string;\n\t/** OAuth client_secret (HTTP Basic password). */\n\tpassword: string;\n\t/** Bearer-token store. Defaults to an in-memory, per-process cache. */\n\tcache?: TokenCache;\n}\n\nlet current: ArpcConfig | null = null;\n\n/** Set the active config. Called by the `ArpcSDK` constructor. */\nexport function configure(config: ArpcConfig): void {\n\tcurrent = config;\n}\n\n/** Read the active config. Throws if the SDK hasn't been constructed yet. */\nexport function getConfig(): ArpcConfig {\n\tif (!current) {\n\t\tthrow new Error(\n\t\t\t\"ArpcSDK is not configured — construct `new ArpcSDK(config)` before making calls\",\n\t\t);\n\t}\n\treturn current;\n}\n\n/**\n * Build a config from environment variables. Not used by the library itself —\n * only the dev scripts call this after loading `.env`.\n */\nexport function configFromEnv(\n\tenv: NodeJS.ProcessEnv = process.env,\n): ArpcConfig {\n\tconst need = (key: string): string => {\n\t\tconst value = env[key];\n\t\tif (!value)\n\t\t\tthrow new Error(`Missing required env var: ${key} (set it in .env)`);\n\t\treturn value;\n\t};\n\treturn {\n\t\toauthUrl: need(\"FDR_OAUTH_URL\"),\n\t\tgatewayUrl: need(\"FDR_API_GATEWAY_URL\"),\n\t\tusername: need(\"FDR_OAUTH_USERNAME\"),\n\t\tpassword: need(\"FDR_OAUTH_PASSWORD\"),\n\t};\n}\n","import ky from \"ky\";\nimport { getConfig, type TokenCache } from \"./config\";\n\n// Token lifecycle lives in the orchestration layer, not the generated client:\n// the exchange targets the OAuth host (not the gateway), uses HTTP Basic, and is\n// form-encoded. Authentication is lazy — `resolveToken()` runs from the ky\n// beforeRequest hook on the first gateway call (and again once the token goes\n// stale), so callers never manage the token by hand.\nexport interface TokenResponse {\n\taccess_token: string;\n\ttoken_type?: string;\n\texpires_in?: number;\n}\n\n// Refresh this many ms before the server's stated expiry, so a token never\n// lapses mid-flight. Applied once, when we compute the stored `expiresAt`.\nconst TOKEN_SKEW_MS = 30_000;\n// FDR tokens are ~900s; fall back to that if the response omits expires_in.\nconst DEFAULT_TTL_S = 900;\n\n/** Raw credentials → bearer JWT. No storage; `resolveToken()` owns that. */\nexport async function exchangeToken(): Promise<TokenResponse> {\n\tconst { oauthUrl, username, password } = getConfig();\n\tconst basic = Buffer.from(`${username}:${password}`).toString(\"base64\");\n\n\treturn ky\n\t\t.post(`${oauthUrl}/v1/token`, {\n\t\t\theaders: { Authorization: `Basic ${basic}` },\n\t\t\tbody: new URLSearchParams({ grant_type: \"client_credentials\" }),\n\t\t})\n\t\t.json<TokenResponse>();\n}\n\n// Default store: in-memory, per-process. Used when config omits `cache`.\nlet memToken: string | null = null;\nlet memExpiresAt = 0;\nconst defaultCache: TokenCache = {\n\tasync get() {\n\t\treturn memToken && Date.now() < memExpiresAt ? memToken : null;\n\t},\n\tasync set(token, expiresAt) {\n\t\tmemToken = token;\n\t\tmemExpiresAt = expiresAt.getTime();\n\t},\n};\n\n// Single-flight guard: a cold burst of concurrent gateway calls performs one\n// exchange, not one per call.\nlet inflight: Promise<string> | null = null;\n\n/**\n * Return a valid bearer token, exchanging + caching on a miss. Called by the\n * gateway beforeRequest hook; not part of the public surface.\n */\nexport function resolveToken(): Promise<string> {\n\tconst store = getConfig().cache ?? defaultCache;\n\tif (inflight) return inflight;\n\n\tinflight = (async () => {\n\t\tconst cached = await store.get();\n\t\tif (cached) return cached;\n\t\tconst res = await exchangeToken();\n\t\tconst ttl = (res.expires_in ?? DEFAULT_TTL_S) * 1000;\n\t\tawait store.set(\n\t\t\tres.access_token,\n\t\t\tnew Date(Date.now() + ttl - TOKEN_SKEW_MS),\n\t\t);\n\t\treturn res.access_token;\n\t})().finally(() => {\n\t\tinflight = null;\n\t});\n\treturn inflight;\n}\n","import ky from \"ky\";\nimport { resolveToken } from \"../auth\";\nimport { getConfig } from \"../config\";\n\n// ---------------------------------------------------------------------------\n// Orval custom mutator (ky-backed).\n//\n// Every generated operation calls `customInstance<T>(config, options)`. We\n// route all calls to the API gateway, attach the bearer token via a\n// beforeRequest hook (lazy auth — `resolveToken()` exchanges/refreshes as\n// needed), and return a small { status, data, headers } wrapper WITHOUT\n// throwing on non-2xx — the caller inspects status codes itself (202 +\n// Retry-After on program, 400 on a UW/DRA gate, etc.).\n// ---------------------------------------------------------------------------\n\n// Shape Orval passes as the first arg (axios-style request config).\nexport interface RequestConfig {\n\turl: string;\n\tmethod: string;\n\tparams?: Record<string, unknown>;\n\tdata?: unknown;\n\theaders?: Record<string, string>;\n\tsignal?: AbortSignal;\n\tresponseType?: string;\n}\n\nexport interface HttpResponse<T> {\n\tstatus: number;\n\tdata: T;\n\theaders: Headers;\n}\n\nexport const customInstance = async <T>(\n\trequest: RequestConfig,\n\toptions?: Partial<RequestConfig>,\n): Promise<HttpResponse<T>> => {\n\tconst { url, method, params, data, signal } = { ...request, ...options };\n\t// Merge headers from both sides — a per-call override (e.g. an\n\t// x-correlation-id in `options.headers`) must not drop the operation's\n\t// Content-Type. The bearer token is layered on last, below.\n\tconst headers = { ...request.headers, ...options?.headers };\n\n\tconst target = new URL(url, getConfig().gatewayUrl);\n\tif (params) {\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tif (value !== undefined && value !== null)\n\t\t\t\ttarget.searchParams.set(key, String(value));\n\t\t}\n\t}\n\n\tconst response = await ky(target, {\n\t\tmethod,\n\t\theaders,\n\t\thooks: {\n\t\t\t// Lazy bearer injection: resolveToken() exchanges on the first call\n\t\t\t// and refreshes once the cached token goes stale. The OAuth exchange\n\t\t\t// itself runs on a bare ky.post (no hook), so there's no recursion.\n\t\t\tbeforeRequest: [\n\t\t\t\tasync (req) => {\n\t\t\t\t\treq.headers.set(\"Authorization\", `Bearer ${await resolveToken()}`);\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t...(data !== undefined ? { json: data } : {}),\n\t\tsignal,\n\t\tthrowHttpErrors: false,\n\t\tretry: 0,\n\t\t// Some gateway calls (program generation in particular) can take well over ky's\n\t\t// 10s default to respond. Raise the per-request ceiling; the program poll loop\n\t\t// handles 202/Retry-After on top of this.\n\t\ttimeout: 60_000,\n\t});\n\n\tconst text = await response.text();\n\tlet body: T;\n\ttry {\n\t\tbody = (text ? JSON.parse(text) : undefined) as T;\n\t} catch {\n\t\t// Non-JSON body (e.g. a gateway HTML error page on a transient 5xx). Don't throw —\n\t\t// hand back the raw text so callers can inspect status/body and retry as needed.\n\t\tbody = text as unknown as T;\n\t}\n\treturn { status: response.status, data: body, headers: response.headers };\n};\n","/**\n * Generated by orval v7.21.0 🍺\n * Do not edit manually.\n * ARPC — Achieve Resolution Partner Connect API\n * FDR Wholesale API — A Hybrid Integration Model designed to maximise partner velocity without compromising enterprise data standards. DEX (Digital Enrollment Experience) is the partner-facing integration layer that powers the full applicant lifecycle. The `fdr_applicant_id` acts as the applicant's passport across all systems, persisted from first eligibility check through enrollment. All endpoints require a valid Bearer JWT with the `arpc.all` role.\n * OpenAPI spec version: 2026.15.0\n */\nimport type {\n ARPCErrorResponse,\n ApplicationSendEmailResponse,\n BankUpdateRequest,\n CreateLeadRequest,\n CreateLeadResponse,\n DraRequest,\n DraResponse,\n EligibilityRequest,\n EligibilityResponse,\n LeadPatchRequest,\n LeadResponse,\n LeadTransferRequest,\n LeadTransferResponse,\n ProgramRequest,\n ProgramSummaryTaskRequest,\n ProgramSummaryTaskResponse,\n ReadinessResponse,\n RegisterApplicantResponse,\n RegisterApplicantV2Request,\n SpinwheelNetworkUserRequest,\n SpinwheelNetworkUserResponse,\n StatelessReadinessRequest,\n UwSubmissionV2Response\n} from './model';\n\nimport { customInstance } from '../http/client';\ntype SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n\n export const getARPCAchieveResolutionPartnerConnectAPI = () => {\n/**\n * Synchronous Orchestration: Handles both lead creation and income/expense data in one step, eliminating the async polling black box. Data authority shifts here — Achieve (SUIP SF) becomes the Source of Truth once the lead is formally promoted. Returns the full lead creation result including program options.\n * @summary Sync wholesale lead creation\n */\nconst createLeadSync = (\n createLeadRequest: CreateLeadRequest,\n options?: SecondParameter<typeof customInstance<CreateLeadResponse>>,) => {\n return customInstance<CreateLeadResponse>(\n {url: `/v3/application`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: createLeadRequest\n },\n options);\n }\n \n/**\n * Stateless Readiness Check: Pre-flight validation before initiating program calculations. Catches duplicate SSNs or emails early to prevent downstream failures. Requires a valid Authorization header.\n * @summary Check application readiness\n */\nconst checkApplicationReadiness = (\n statelessReadinessRequest: StatelessReadinessRequest,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/readiness`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: statelessReadinessRequest\n },\n options);\n }\n \n/**\n * Recovery endpoint — only required when the async Spinwheel user creation triggered by `POST /v1/applicant/register` fails due to a user error (e.g. invalid SSN or DOB). Not needed in the happy path. Authenticates the seller, resolves the law firm / program, creates an applicant ID when needed, and connects the applicant to the Spinwheel network. Requires a valid Authorization header.\n * @summary Create / connect Spinwheel network user\n */\nconst createSpinwheelNetworkUser = (\n spinwheelNetworkUserRequest: SpinwheelNetworkUserRequest,\n options?: SecondParameter<typeof customInstance<SpinwheelNetworkUserResponse>>,) => {\n return customInstance<SpinwheelNetworkUserResponse>(\n {url: `/v1/application/spinwheel-network-user`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: spinwheelNetworkUserRequest\n },\n options);\n }\n \n/**\n * Authenticates the seller, validates banking disclosure requirements, optionally validates the submitted account and routing numbers, patches the program, and returns the refreshed lead payload. Requires a valid Authorization header.\n * @summary Update applicant bank details\n */\nconst updateApplicationBankDetails = (\n applicantId: string,\n bankUpdateRequest: BankUpdateRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/bank-update/${applicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: bankUpdateRequest\n },\n options);\n }\n \n/**\n * Banking Disclosure: Manually triggers the banking disclosure email. **This endpoint is optional** — it is only needed when the disclosure was not already sent automatically by `POST /v2/application/uw-submission/{fdrApplicantId}` (which auto-sends on full UW approval). Use this endpoint for conditional approvals or when the v1 UW submission path is in use. A critical legal prerequisite that must be completed before enrollment can proceed. Requires a valid Authorization header.\n * @summary Send banking disclosure email (optional — only if not auto-sent by v2 UW submission)\n */\nconst sendEmail = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<ApplicationSendEmailResponse>>,) => {\n return customInstance<ApplicationSendEmailResponse>(\n {url: `/v1/application/send-email/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Submits a lead evaluation request. fdr_applicant_id is required in the request body. Requires a valid Authorization header with the arpc.all role.\n * @summary Transfer a lead to the debt-resolution program\n */\nconst leadTransfer = (\n leadTransferRequest: LeadTransferRequest,\n options?: SecondParameter<typeof customInstance<LeadTransferResponse>>,) => {\n return customInstance<LeadTransferResponse>(\n {url: `/v1/application/lead-transfer`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: leadTransferRequest\n },\n options);\n }\n \n/**\n * Fetches the current state of an application / lead record by FDR applicant ID. Requires a valid Authorization header.\n * @summary Read application / lead details\n */\nconst readLead = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'GET'\n },\n options);\n }\n \n/**\n * Applies a partial update to an existing wholesale lead record. Requires a valid Authorization header and an x-correlation-id header for request tracing.\n * @summary Partial update of application / lead record\n */\nconst patchLead = (\n fdrApplicantId: string,\n leadPatchRequest: LeadPatchRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: leadPatchRequest\n },\n options);\n }\n \n/**\n * DRA Readiness Check: Final pre-flight confirming the lead is approved and all prerequisites are met before initiating the embedded signing session. Requires a valid Authorization header.\n * @summary Get application readiness status\n */\nconst getApplicationReadiness = (\n applicantId: string,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/${applicantId}/readiness`, method: 'GET'\n },\n options);\n }\n \n/**\n * Embedded DRA Signing: Returns an Embedded Signing URL so the applicant signs the Debt Resolution Agreement via DocuSign directly within the Symple UI, preventing session breakage. Successful legal execution triggers automatic enrollment. Requires a valid Authorization header.\n * @summary Generate Debt Resolution Agreement (DRA)\n */\nconst generateDra = (\n applicantId: string,\n draRequest: DraRequest,\n options?: SecondParameter<typeof customInstance<DraResponse>>,) => {\n return customInstance<DraResponse>(\n {url: `/v2/application/${applicantId}/dra`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: draRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint.** `POST /v1/applicant/register` is deprecated and will be retired by end of July 2026 (deadline can be extended on request if your team needs more time). Identity Anchoring: Persists applicant PII to the Managed Package and generates the `fdr_applicant_id` — the applicant's passport across all systems. Routes to the correct Salesforce target (MP or WiB) based on seller identity, and triggers the async credit fetch. Requires a valid Authorization header.\n * @summary Seller-aware applicant registration (v2 — unified ARPCErrorResponse envelope) — recommended\n */\nconst registerApplicantV2 = (\n registerApplicantV2Request: RegisterApplicantV2Request,\n options?: SecondParameter<typeof customInstance<RegisterApplicantResponse>>,) => {\n return customInstance<RegisterApplicantResponse>(\n {url: `/v2/applicant/register`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: registerApplicantV2Request\n },\n options);\n }\n \n/**\n * Async Polling Loop: Call this single endpoint for both initial generation and refresh. Returns 202 Accepted with a Retry-After header while credit is still pending. Once ready, the Managed Package orchestrates the calculation and persists the program result. Requires a valid Authorization header.\n * @summary Generate application program (v1)\n */\nconst generateProgramV1 = (\n programRequest: ProgramRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/program`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programRequest\n },\n options);\n }\n \n/**\n * Eligibility Scout: A stateless, real-time quote based on anonymised data — no PII required. Returns estimated program options to anchor the conversation before any registration occurs. Requires a valid Authorization header.\n * @summary Check application eligibility\n */\nconst checkEligibility = (\n eligibilityRequest: EligibilityRequest,\n options?: SecondParameter<typeof customInstance<EligibilityResponse>>,) => {\n return customInstance<EligibilityResponse>(\n {url: `/v2/application/eligibility`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: eligibilityRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint — supersedes v1.** Submits a wholesale application to the underwriting system. On full UW approval (`sub_status = 'UW Approved'`) the banking disclosure email is sent automatically — no separate `send-email` call is needed in this path. Conditional approvals suppress the auto-send; in that case the manual `POST /v1/application/send-email/{fdrApplicantId}` endpoint can be used. Uses the SF Object API directly (no suip-proxy hop). Requires a valid Authorization header.\n * @summary Submit application to underwriting (v2 — auto banking disclosure) — recommended\n */\nconst uwSubmissionV2 = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<UwSubmissionV2Response>>,) => {\n return customInstance<UwSubmissionV2Response>(\n {url: `/v2/application/uw-submission/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Creates a SUIP Salesforce 'Program Summary Recording' task for the applicant identified by the {id} path variable. For DEX (or missing header), the parent SF opportunity is additionally PATCHed with the seller-config partner default PSC. For DC, the task is created and the parent SF opportunity is PATCHed only when ws_psc_code is provided in the request payload.\n * @summary Create program-summary recording task\n */\nconst createProgramSummaryTask = (\n id: string,\n programSummaryTaskRequest: ProgramSummaryTaskRequest,\n options?: SecondParameter<typeof customInstance<ProgramSummaryTaskResponse>>,) => {\n return customInstance<ProgramSummaryTaskResponse>(\n {url: `/v2/application/program-summary-task/${id}`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programSummaryTaskRequest\n },\n options);\n }\n \nreturn {createLeadSync,checkApplicationReadiness,createSpinwheelNetworkUser,updateApplicationBankDetails,sendEmail,leadTransfer,readLead,patchLead,getApplicationReadiness,generateDra,registerApplicantV2,generateProgramV1,checkEligibility,uwSubmissionV2,createProgramSummaryTask}};\nexport type CreateLeadSyncResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createLeadSync']>>>\nexport type CheckApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkApplicationReadiness']>>>\nexport type CreateSpinwheelNetworkUserResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createSpinwheelNetworkUser']>>>\nexport type UpdateApplicationBankDetailsResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['updateApplicationBankDetails']>>>\nexport type SendEmailResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['sendEmail']>>>\nexport type LeadTransferResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['leadTransfer']>>>\nexport type ReadLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['readLead']>>>\nexport type PatchLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['patchLead']>>>\nexport type GetApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['getApplicationReadiness']>>>\nexport type GenerateDraResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateDra']>>>\nexport type RegisterApplicantV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['registerApplicantV2']>>>\nexport type GenerateProgramV1Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateProgramV1']>>>\nexport type CheckEligibilityResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkEligibility']>>>\nexport type UwSubmissionV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['uwSubmissionV2']>>>\nexport type CreateProgramSummaryTaskResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createProgramSummaryTask']>>>\n","import { type ArpcConfig, configure } from \"./config\";\nimport { getARPCAchieveResolutionPartnerConnectAPI } from \"./generated/arpc\";\n\nexport type { ArpcConfig, TokenCache } from \"./config\";\nexport type * from \"./generated/model\";\nexport type { HttpResponse } from \"./http/client\";\n\n/**\n * ARPC SDK — a typed, agnostic client for FDR's ARPC DEX API (Achieve\n * Resolution Partner Connect, Digital Enrollment Experience).\n *\n * Thin by design: it owns the two-host routing, the OAuth token lifecycle, and\n * bearer injection, and exposes the full endpoint surface as typed operations\n * on `sdk.api`. It does not orchestrate the enrollment sequence — the caller\n * assembles payloads and threads the `fdr_applicant_id` between calls. See\n * `scripts/smoke.ts` for a full end-to-end reference sequence (incl. the program\n * poll loop).\n *\n * Auth is lazy: the first `api` call exchanges credentials for a bearer JWT and\n * caches it (~900s TTL), then re-exchanges shortly before it expires. There's no\n * explicit login step. Supply a `cache` in the config to persist the token\n * across restarts or share it across workers; otherwise it's held in-process.\n *\n * Operations never throw on a non-2xx: each returns `{ status, data, headers }`,\n * so a business gate (e.g. a UW/DRA readiness failure) comes back as a normal\n * response you inspect via `status`/`data`. Only transport errors throw.\n *\n * Note: config and the default token cache are process-global — construct one\n * `ArpcSDK` per process. A second instance reconfigures the first; instances are\n * not isolated (single-tenant by design).\n *\n * @example\n * ```typescript\n * const sdk = new ArpcSDK({\n * oauthUrl: \"https://oauth.stg.ffngcp.com\",\n * gatewayUrl: \"https://apis-gateway-v2.stg.fdrgcp.com\",\n * username: \"borrowbetter@seller.com\",\n * password: process.env.FDR_OAUTH_PASSWORD!,\n * });\n *\n * // The first call authenticates automatically and caches the token.\n * const elig = await sdk.api.checkEligibility({ ... });\n * const faid = elig.data.application?.applicant?.fdr_applicant_id;\n * ```\n */\nexport class ArpcSDK {\n\t/** The full typed endpoint surface — one method per gateway operation. */\n\treadonly api = getARPCAchieveResolutionPartnerConnectAPI();\n\n\tconstructor(config: ArpcConfig) {\n\t\tconfigure(config);\n\t}\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import ky from 'ky';
|
|
2
2
|
|
|
3
|
-
// src/auth.ts
|
|
4
|
-
|
|
5
3
|
// src/config.ts
|
|
6
4
|
var current = null;
|
|
7
5
|
function configure(config) {
|
|
@@ -15,10 +13,48 @@ function getConfig() {
|
|
|
15
13
|
}
|
|
16
14
|
return current;
|
|
17
15
|
}
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
var TOKEN_SKEW_MS = 3e4;
|
|
17
|
+
var DEFAULT_TTL_S = 900;
|
|
18
|
+
async function exchangeToken() {
|
|
19
|
+
const { oauthUrl, username, password } = getConfig();
|
|
20
|
+
const basic = Buffer.from(`${username}:${password}`).toString("base64");
|
|
21
|
+
return ky.post(`${oauthUrl}/v1/token`, {
|
|
22
|
+
headers: { Authorization: `Basic ${basic}` },
|
|
23
|
+
body: new URLSearchParams({ grant_type: "client_credentials" })
|
|
24
|
+
}).json();
|
|
25
|
+
}
|
|
26
|
+
var memToken = null;
|
|
27
|
+
var memExpiresAt = 0;
|
|
28
|
+
var defaultCache = {
|
|
29
|
+
async get() {
|
|
30
|
+
return memToken && Date.now() < memExpiresAt ? memToken : null;
|
|
31
|
+
},
|
|
32
|
+
async set(token, expiresAt) {
|
|
33
|
+
memToken = token;
|
|
34
|
+
memExpiresAt = expiresAt.getTime();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var inflight = null;
|
|
38
|
+
function resolveToken() {
|
|
39
|
+
const store = getConfig().cache ?? defaultCache;
|
|
40
|
+
if (inflight) return inflight;
|
|
41
|
+
inflight = (async () => {
|
|
42
|
+
const cached = await store.get();
|
|
43
|
+
if (cached) return cached;
|
|
44
|
+
const res = await exchangeToken();
|
|
45
|
+
const ttl = (res.expires_in ?? DEFAULT_TTL_S) * 1e3;
|
|
46
|
+
await store.set(
|
|
47
|
+
res.access_token,
|
|
48
|
+
new Date(Date.now() + ttl - TOKEN_SKEW_MS)
|
|
49
|
+
);
|
|
50
|
+
return res.access_token;
|
|
51
|
+
})().finally(() => {
|
|
52
|
+
inflight = null;
|
|
53
|
+
});
|
|
54
|
+
return inflight;
|
|
21
55
|
}
|
|
56
|
+
|
|
57
|
+
// src/http/client.ts
|
|
22
58
|
var customInstance = async (request, options) => {
|
|
23
59
|
const { url, method, params, data, signal } = { ...request, ...options };
|
|
24
60
|
const headers = { ...request.headers, ...options?.headers };
|
|
@@ -31,9 +67,16 @@ var customInstance = async (request, options) => {
|
|
|
31
67
|
}
|
|
32
68
|
const response = await ky(target, {
|
|
33
69
|
method,
|
|
34
|
-
headers
|
|
35
|
-
|
|
36
|
-
|
|
70
|
+
headers,
|
|
71
|
+
hooks: {
|
|
72
|
+
// Lazy bearer injection: resolveToken() exchanges on the first call
|
|
73
|
+
// and refreshes once the cached token goes stale. The OAuth exchange
|
|
74
|
+
// itself runs on a bare ky.post (no hook), so there's no recursion.
|
|
75
|
+
beforeRequest: [
|
|
76
|
+
async (req) => {
|
|
77
|
+
req.headers.set("Authorization", `Bearer ${await resolveToken()}`);
|
|
78
|
+
}
|
|
79
|
+
]
|
|
37
80
|
},
|
|
38
81
|
...data !== void 0 ? { json: data } : {},
|
|
39
82
|
signal,
|
|
@@ -54,18 +97,6 @@ var customInstance = async (request, options) => {
|
|
|
54
97
|
return { status: response.status, data: body, headers: response.headers };
|
|
55
98
|
};
|
|
56
99
|
|
|
57
|
-
// src/auth.ts
|
|
58
|
-
async function exchangeToken() {
|
|
59
|
-
const { oauthUrl, username, password } = getConfig();
|
|
60
|
-
const basic = Buffer.from(`${username}:${password}`).toString("base64");
|
|
61
|
-
const token = await ky.post(`${oauthUrl}/v1/token`, {
|
|
62
|
-
headers: { Authorization: `Basic ${basic}` },
|
|
63
|
-
body: new URLSearchParams({ grant_type: "client_credentials" })
|
|
64
|
-
}).json();
|
|
65
|
-
setBearerToken(token.access_token);
|
|
66
|
-
return token;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
100
|
// src/generated/arpc.ts
|
|
70
101
|
var getARPCAchieveResolutionPartnerConnectAPI = () => {
|
|
71
102
|
const createLeadSync = (createLeadRequest, options) => {
|
|
@@ -235,13 +266,6 @@ var ArpcSDK = class {
|
|
|
235
266
|
this.api = getARPCAchieveResolutionPartnerConnectAPI();
|
|
236
267
|
configure(config);
|
|
237
268
|
}
|
|
238
|
-
/**
|
|
239
|
-
* Exchange OAuth client credentials for a bearer JWT and store it for
|
|
240
|
-
* subsequent `api` calls. Token TTL is ~900s — re-call to refresh.
|
|
241
|
-
*/
|
|
242
|
-
authenticate() {
|
|
243
|
-
return exchangeToken();
|
|
244
|
-
}
|
|
245
269
|
};
|
|
246
270
|
|
|
247
271
|
export { ArpcSDK };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/http/client.ts","../src/auth.ts","../src/generated/arpc.ts","../src/index.ts"],"names":["ky"],"mappings":";;;;;AAsBA,IAAI,OAAA,GAA6B,IAAA;AAG1B,SAAS,UAAU,MAAA,EAA0B;AACnD,EAAA,OAAA,GAAU,MAAA;AACX;AAGO,SAAS,SAAA,GAAwB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACT;AAAA,KACD;AAAA,EACD;AACA,EAAA,OAAO,OAAA;AACR;ACxBA,IAAI,WAAA,GAA6B,IAAA;AAC1B,SAAS,eAAe,KAAA,EAA4B;AAC1D,E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CAAA;AAMJ,EAAA,MAAM,wBAAA,GAA2B,CAC7B,EAAA,EACA,yBAAA,EACH,OAAA,KAAkF;AAC7E,IAAA,OAAO,cAAA;AAAA,MACP;AAAA,QAAC,GAAA,EAAK,wCAAwC,EAAE,CAAA,CAAA;AAAA,QAAI,MAAA,EAAQ,MAAA;AAAA,QAC5D,OAAA,EAAS,EAAC,cAAA,EAAgB,kBAAA,EAAoB;AAAA,QAC9C,IAAA,EAAM;AAAA,OACR;AAAA,MACE;AAAA,KAAO;AAAA,EACT,CAAA;AAEJ,EAAA,OAAO,EAAC,cAAA,EAAe,yBAAA,EAA0B,0BAAA,EAA2B,8BAA6B,SAAA,EAAU,YAAA,EAAa,QAAA,EAAS,SAAA,EAAU,yBAAwB,WAAA,EAAY,mBAAA,EAAoB,iBAAA,EAAkB,gBAAA,EAAiB,gBAAe,wBAAA,EAAwB;AAAC,CAAA;;;ACzN/Q,IAAM,UAAN,MAAc;AAAA,EAIpB,YAAY,MAAA,EAAoB;AAFhC;AAAA,IAAA,IAAA,CAAS,MAAM,yCAAA,EAA0C;AAGxD,IAAA,SAAA,CAAU,MAAM,CAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAA,GAAuC;AACtC,IAAA,OAAO,aAAA,EAAc;AAAA,EACtB;AACD","file":"index.mjs","sourcesContent":["/**\n * SDK configuration.\n *\n * The library never reads the environment itself — a consumer constructs\n * `new ArpcSDK(config)`, which calls `configure()`. The `configFromEnv()` helper\n * is a convenience for the dev scripts (smoke / server), which load `.env` via\n * dotenv-flow and pass the result in.\n */\nexport interface ArpcConfig {\n\t/** OAuth host — token exchange only (`POST /v1/token`). */\n\toauthUrl: string;\n\t/** API gateway host — every non-auth call. */\n\tgatewayUrl: string;\n\t/**\n\t * OAuth client_id (HTTP Basic username). Also used as the lead's\n\t * `seller_agent_email` — the OAuth identity is a registered DRA agent.\n\t */\n\tusername: string;\n\t/** OAuth client_secret (HTTP Basic password). */\n\tpassword: string;\n}\n\nlet current: ArpcConfig | null = null;\n\n/** Set the active config. Called by the `ArpcSDK` constructor. */\nexport function configure(config: ArpcConfig): void {\n\tcurrent = config;\n}\n\n/** Read the active config. Throws if the SDK hasn't been constructed yet. */\nexport function getConfig(): ArpcConfig {\n\tif (!current) {\n\t\tthrow new Error(\n\t\t\t\"ArpcSDK is not configured — construct `new ArpcSDK(config)` before making calls\",\n\t\t);\n\t}\n\treturn current;\n}\n\n/**\n * Build a config from environment variables. Not used by the library itself —\n * only the dev scripts call this after loading `.env`.\n */\nexport function configFromEnv(\n\tenv: NodeJS.ProcessEnv = process.env,\n): ArpcConfig {\n\tconst need = (key: string): string => {\n\t\tconst value = env[key];\n\t\tif (!value)\n\t\t\tthrow new Error(`Missing required env var: ${key} (set it in .env)`);\n\t\treturn value;\n\t};\n\treturn {\n\t\toauthUrl: need(\"FDR_OAUTH_URL\"),\n\t\tgatewayUrl: need(\"FDR_API_GATEWAY_URL\"),\n\t\tusername: need(\"FDR_OAUTH_USERNAME\"),\n\t\tpassword: need(\"FDR_OAUTH_PASSWORD\"),\n\t};\n}\n","import ky from \"ky\";\nimport { getConfig } from \"../config\";\n\n// ---------------------------------------------------------------------------\n// Orval custom mutator (ky-backed).\n//\n// Every generated operation calls `customInstance<T>(config, options)`. We\n// route all calls to the API gateway, inject the bearer token, and return a\n// small { status, data, headers } wrapper WITHOUT throwing on non-2xx — the\n// caller inspects status codes itself (202 + Retry-After on program, 400 on a\n// UW/DRA gate, etc.).\n// ---------------------------------------------------------------------------\n\nlet bearerToken: string | null = null;\nexport function setBearerToken(token: string | null): void {\n\tbearerToken = token;\n}\n\n// Shape Orval passes as the first arg (axios-style request config).\nexport interface RequestConfig {\n\turl: string;\n\tmethod: string;\n\tparams?: Record<string, unknown>;\n\tdata?: unknown;\n\theaders?: Record<string, string>;\n\tsignal?: AbortSignal;\n\tresponseType?: string;\n}\n\nexport interface HttpResponse<T> {\n\tstatus: number;\n\tdata: T;\n\theaders: Headers;\n}\n\nexport const customInstance = async <T>(\n\trequest: RequestConfig,\n\toptions?: Partial<RequestConfig>,\n): Promise<HttpResponse<T>> => {\n\tconst { url, method, params, data, signal } = { ...request, ...options };\n\t// Merge headers from both sides — a per-call override (e.g. an\n\t// x-correlation-id in `options.headers`) must not drop the operation's\n\t// Content-Type. The bearer token is layered on last, below.\n\tconst headers = { ...request.headers, ...options?.headers };\n\n\tconst target = new URL(url, getConfig().gatewayUrl);\n\tif (params) {\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tif (value !== undefined && value !== null)\n\t\t\t\ttarget.searchParams.set(key, String(value));\n\t\t}\n\t}\n\n\tconst response = await ky(target, {\n\t\tmethod,\n\t\theaders: {\n\t\t\t...headers,\n\t\t\t...(bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}),\n\t\t},\n\t\t...(data !== undefined ? { json: data } : {}),\n\t\tsignal,\n\t\tthrowHttpErrors: false,\n\t\tretry: 0,\n\t\t// Some gateway calls (program generation in particular) can take well over ky's\n\t\t// 10s default to respond. Raise the per-request ceiling; the program poll loop\n\t\t// handles 202/Retry-After on top of this.\n\t\ttimeout: 60_000,\n\t});\n\n\tconst text = await response.text();\n\tlet body: T;\n\ttry {\n\t\tbody = (text ? JSON.parse(text) : undefined) as T;\n\t} catch {\n\t\t// Non-JSON body (e.g. a gateway HTML error page on a transient 5xx). Don't throw —\n\t\t// hand back the raw text so callers can inspect status/body and retry as needed.\n\t\tbody = text as unknown as T;\n\t}\n\treturn { status: response.status, data: body, headers: response.headers };\n};\n","import ky from \"ky\";\nimport { getConfig } from \"./config\";\nimport { setBearerToken } from \"./http/client\";\n\n// Token exchange lives in the orchestration layer, not the generated client:\n// it targets the OAuth host (not the gateway), uses HTTP Basic, and is\n// form-encoded. We store the resulting JWT for the mutator to attach.\nexport interface TokenResponse {\n\taccess_token: string;\n\ttoken_type?: string;\n\texpires_in?: number;\n}\n\nexport async function exchangeToken(): Promise<TokenResponse> {\n\tconst { oauthUrl, username, password } = getConfig();\n\tconst basic = Buffer.from(`${username}:${password}`).toString(\"base64\");\n\n\tconst token = await ky\n\t\t.post(`${oauthUrl}/v1/token`, {\n\t\t\theaders: { Authorization: `Basic ${basic}` },\n\t\t\tbody: new URLSearchParams({ grant_type: \"client_credentials\" }),\n\t\t})\n\t\t.json<TokenResponse>();\n\n\tsetBearerToken(token.access_token);\n\treturn token;\n}\n","/**\n * Generated by orval v7.21.0 🍺\n * Do not edit manually.\n * ARPC — Achieve Resolution Partner Connect API\n * FDR Wholesale API — A Hybrid Integration Model designed to maximise partner velocity without compromising enterprise data standards. DEX (Digital Enrollment Experience) is the partner-facing integration layer that powers the full applicant lifecycle. The `fdr_applicant_id` acts as the applicant's passport across all systems, persisted from first eligibility check through enrollment. All endpoints require a valid Bearer JWT with the `arpc.all` role.\n * OpenAPI spec version: 2026.15.0\n */\nimport type {\n ARPCErrorResponse,\n ApplicationSendEmailResponse,\n BankUpdateRequest,\n CreateLeadRequest,\n CreateLeadResponse,\n DraRequest,\n DraResponse,\n EligibilityRequest,\n EligibilityResponse,\n LeadPatchRequest,\n LeadResponse,\n LeadTransferRequest,\n LeadTransferResponse,\n ProgramRequest,\n ProgramSummaryTaskRequest,\n ProgramSummaryTaskResponse,\n ReadinessResponse,\n RegisterApplicantResponse,\n RegisterApplicantV2Request,\n SpinwheelNetworkUserRequest,\n SpinwheelNetworkUserResponse,\n StatelessReadinessRequest,\n UwSubmissionV2Response\n} from './model';\n\nimport { customInstance } from '../http/client';\ntype SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n\n export const getARPCAchieveResolutionPartnerConnectAPI = () => {\n/**\n * Synchronous Orchestration: Handles both lead creation and income/expense data in one step, eliminating the async polling black box. Data authority shifts here — Achieve (SUIP SF) becomes the Source of Truth once the lead is formally promoted. Returns the full lead creation result including program options.\n * @summary Sync wholesale lead creation\n */\nconst createLeadSync = (\n createLeadRequest: CreateLeadRequest,\n options?: SecondParameter<typeof customInstance<CreateLeadResponse>>,) => {\n return customInstance<CreateLeadResponse>(\n {url: `/v3/application`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: createLeadRequest\n },\n options);\n }\n \n/**\n * Stateless Readiness Check: Pre-flight validation before initiating program calculations. Catches duplicate SSNs or emails early to prevent downstream failures. Requires a valid Authorization header.\n * @summary Check application readiness\n */\nconst checkApplicationReadiness = (\n statelessReadinessRequest: StatelessReadinessRequest,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/readiness`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: statelessReadinessRequest\n },\n options);\n }\n \n/**\n * Recovery endpoint — only required when the async Spinwheel user creation triggered by `POST /v1/applicant/register` fails due to a user error (e.g. invalid SSN or DOB). Not needed in the happy path. Authenticates the seller, resolves the law firm / program, creates an applicant ID when needed, and connects the applicant to the Spinwheel network. Requires a valid Authorization header.\n * @summary Create / connect Spinwheel network user\n */\nconst createSpinwheelNetworkUser = (\n spinwheelNetworkUserRequest: SpinwheelNetworkUserRequest,\n options?: SecondParameter<typeof customInstance<SpinwheelNetworkUserResponse>>,) => {\n return customInstance<SpinwheelNetworkUserResponse>(\n {url: `/v1/application/spinwheel-network-user`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: spinwheelNetworkUserRequest\n },\n options);\n }\n \n/**\n * Authenticates the seller, validates banking disclosure requirements, optionally validates the submitted account and routing numbers, patches the program, and returns the refreshed lead payload. Requires a valid Authorization header.\n * @summary Update applicant bank details\n */\nconst updateApplicationBankDetails = (\n applicantId: string,\n bankUpdateRequest: BankUpdateRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/bank-update/${applicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: bankUpdateRequest\n },\n options);\n }\n \n/**\n * Banking Disclosure: Manually triggers the banking disclosure email. **This endpoint is optional** — it is only needed when the disclosure was not already sent automatically by `POST /v2/application/uw-submission/{fdrApplicantId}` (which auto-sends on full UW approval). Use this endpoint for conditional approvals or when the v1 UW submission path is in use. A critical legal prerequisite that must be completed before enrollment can proceed. Requires a valid Authorization header.\n * @summary Send banking disclosure email (optional — only if not auto-sent by v2 UW submission)\n */\nconst sendEmail = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<ApplicationSendEmailResponse>>,) => {\n return customInstance<ApplicationSendEmailResponse>(\n {url: `/v1/application/send-email/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Submits a lead evaluation request. fdr_applicant_id is required in the request body. Requires a valid Authorization header with the arpc.all role.\n * @summary Transfer a lead to the debt-resolution program\n */\nconst leadTransfer = (\n leadTransferRequest: LeadTransferRequest,\n options?: SecondParameter<typeof customInstance<LeadTransferResponse>>,) => {\n return customInstance<LeadTransferResponse>(\n {url: `/v1/application/lead-transfer`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: leadTransferRequest\n },\n options);\n }\n \n/**\n * Fetches the current state of an application / lead record by FDR applicant ID. Requires a valid Authorization header.\n * @summary Read application / lead details\n */\nconst readLead = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'GET'\n },\n options);\n }\n \n/**\n * Applies a partial update to an existing wholesale lead record. Requires a valid Authorization header and an x-correlation-id header for request tracing.\n * @summary Partial update of application / lead record\n */\nconst patchLead = (\n fdrApplicantId: string,\n leadPatchRequest: LeadPatchRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: leadPatchRequest\n },\n options);\n }\n \n/**\n * DRA Readiness Check: Final pre-flight confirming the lead is approved and all prerequisites are met before initiating the embedded signing session. Requires a valid Authorization header.\n * @summary Get application readiness status\n */\nconst getApplicationReadiness = (\n applicantId: string,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/${applicantId}/readiness`, method: 'GET'\n },\n options);\n }\n \n/**\n * Embedded DRA Signing: Returns an Embedded Signing URL so the applicant signs the Debt Resolution Agreement via DocuSign directly within the Symple UI, preventing session breakage. Successful legal execution triggers automatic enrollment. Requires a valid Authorization header.\n * @summary Generate Debt Resolution Agreement (DRA)\n */\nconst generateDra = (\n applicantId: string,\n draRequest: DraRequest,\n options?: SecondParameter<typeof customInstance<DraResponse>>,) => {\n return customInstance<DraResponse>(\n {url: `/v2/application/${applicantId}/dra`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: draRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint.** `POST /v1/applicant/register` is deprecated and will be retired by end of July 2026 (deadline can be extended on request if your team needs more time). Identity Anchoring: Persists applicant PII to the Managed Package and generates the `fdr_applicant_id` — the applicant's passport across all systems. Routes to the correct Salesforce target (MP or WiB) based on seller identity, and triggers the async credit fetch. Requires a valid Authorization header.\n * @summary Seller-aware applicant registration (v2 — unified ARPCErrorResponse envelope) — recommended\n */\nconst registerApplicantV2 = (\n registerApplicantV2Request: RegisterApplicantV2Request,\n options?: SecondParameter<typeof customInstance<RegisterApplicantResponse>>,) => {\n return customInstance<RegisterApplicantResponse>(\n {url: `/v2/applicant/register`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: registerApplicantV2Request\n },\n options);\n }\n \n/**\n * Async Polling Loop: Call this single endpoint for both initial generation and refresh. Returns 202 Accepted with a Retry-After header while credit is still pending. Once ready, the Managed Package orchestrates the calculation and persists the program result. Requires a valid Authorization header.\n * @summary Generate application program (v1)\n */\nconst generateProgramV1 = (\n programRequest: ProgramRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/program`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programRequest\n },\n options);\n }\n \n/**\n * Eligibility Scout: A stateless, real-time quote based on anonymised data — no PII required. Returns estimated program options to anchor the conversation before any registration occurs. Requires a valid Authorization header.\n * @summary Check application eligibility\n */\nconst checkEligibility = (\n eligibilityRequest: EligibilityRequest,\n options?: SecondParameter<typeof customInstance<EligibilityResponse>>,) => {\n return customInstance<EligibilityResponse>(\n {url: `/v2/application/eligibility`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: eligibilityRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint — supersedes v1.** Submits a wholesale application to the underwriting system. On full UW approval (`sub_status = 'UW Approved'`) the banking disclosure email is sent automatically — no separate `send-email` call is needed in this path. Conditional approvals suppress the auto-send; in that case the manual `POST /v1/application/send-email/{fdrApplicantId}` endpoint can be used. Uses the SF Object API directly (no suip-proxy hop). Requires a valid Authorization header.\n * @summary Submit application to underwriting (v2 — auto banking disclosure) — recommended\n */\nconst uwSubmissionV2 = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<UwSubmissionV2Response>>,) => {\n return customInstance<UwSubmissionV2Response>(\n {url: `/v2/application/uw-submission/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Creates a SUIP Salesforce 'Program Summary Recording' task for the applicant identified by the {id} path variable. For DEX (or missing header), the parent SF opportunity is additionally PATCHed with the seller-config partner default PSC. For DC, the task is created and the parent SF opportunity is PATCHed only when ws_psc_code is provided in the request payload.\n * @summary Create program-summary recording task\n */\nconst createProgramSummaryTask = (\n id: string,\n programSummaryTaskRequest: ProgramSummaryTaskRequest,\n options?: SecondParameter<typeof customInstance<ProgramSummaryTaskResponse>>,) => {\n return customInstance<ProgramSummaryTaskResponse>(\n {url: `/v2/application/program-summary-task/${id}`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programSummaryTaskRequest\n },\n options);\n }\n \nreturn {createLeadSync,checkApplicationReadiness,createSpinwheelNetworkUser,updateApplicationBankDetails,sendEmail,leadTransfer,readLead,patchLead,getApplicationReadiness,generateDra,registerApplicantV2,generateProgramV1,checkEligibility,uwSubmissionV2,createProgramSummaryTask}};\nexport type CreateLeadSyncResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createLeadSync']>>>\nexport type CheckApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkApplicationReadiness']>>>\nexport type CreateSpinwheelNetworkUserResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createSpinwheelNetworkUser']>>>\nexport type UpdateApplicationBankDetailsResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['updateApplicationBankDetails']>>>\nexport type SendEmailResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['sendEmail']>>>\nexport type LeadTransferResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['leadTransfer']>>>\nexport type ReadLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['readLead']>>>\nexport type PatchLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['patchLead']>>>\nexport type GetApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['getApplicationReadiness']>>>\nexport type GenerateDraResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateDra']>>>\nexport type RegisterApplicantV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['registerApplicantV2']>>>\nexport type GenerateProgramV1Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateProgramV1']>>>\nexport type CheckEligibilityResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkEligibility']>>>\nexport type UwSubmissionV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['uwSubmissionV2']>>>\nexport type CreateProgramSummaryTaskResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createProgramSummaryTask']>>>\n","import { exchangeToken, type TokenResponse } from \"./auth\";\nimport { type ArpcConfig, configure } from \"./config\";\nimport { getARPCAchieveResolutionPartnerConnectAPI } from \"./generated/arpc\";\n\nexport type { TokenResponse } from \"./auth\";\nexport type { ArpcConfig } from \"./config\";\nexport type * from \"./generated/model\";\nexport type { HttpResponse } from \"./http/client\";\n\n/**\n * ARPC SDK — a typed, agnostic client for FDR's ARPC DEX API (Achieve\n * Resolution Partner Connect, Digital Enrollment Experience).\n *\n * Thin by design: it owns the two-host routing, the OAuth token lifecycle, and\n * bearer injection, and exposes the full endpoint surface as typed operations\n * on `sdk.api`. It does not orchestrate the enrollment sequence — the caller\n * assembles payloads and threads the `fdr_applicant_id` between calls. See\n * `scripts/smoke.ts` for a full end-to-end reference sequence (incl. the program\n * poll loop).\n *\n * Operations never throw on a non-2xx: each returns `{ status, data, headers }`,\n * so a business gate (e.g. a UW/DRA readiness failure) comes back as a normal\n * response you inspect via `status`/`data`. Only transport errors throw.\n *\n * Note: config and the bearer token are process-global — construct one `ArpcSDK`\n * per process. A second instance reconfigures the first; instances are not\n * isolated (single-tenant by design).\n *\n * @example\n * ```typescript\n * const sdk = new ArpcSDK({\n * oauthUrl: \"https://oauth.stg.ffngcp.com\",\n * gatewayUrl: \"https://apis-gateway-v2.stg.fdrgcp.com\",\n * username: \"borrowbetter@seller.com\",\n * password: process.env.FDR_OAUTH_PASSWORD!,\n * });\n *\n * await sdk.authenticate();\n * const elig = await sdk.api.checkEligibility({ ... });\n * const faid = elig.data.application?.applicant?.fdr_applicant_id;\n * ```\n */\nexport class ArpcSDK {\n\t/** The full typed endpoint surface — one method per gateway operation. */\n\treadonly api = getARPCAchieveResolutionPartnerConnectAPI();\n\n\tconstructor(config: ArpcConfig) {\n\t\tconfigure(config);\n\t}\n\n\t/**\n\t * Exchange OAuth client credentials for a bearer JWT and store it for\n\t * subsequent `api` calls. Token TTL is ~900s — re-call to refresh.\n\t */\n\tauthenticate(): Promise<TokenResponse> {\n\t\treturn exchangeToken();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/auth.ts","../src/http/client.ts","../src/generated/arpc.ts","../src/index.ts"],"names":["ky"],"mappings":";;;AAuCA,IAAI,OAAA,GAA6B,IAAA;AAG1B,SAAS,UAAU,MAAA,EAA0B;AACnD,EAAA,OAAA,GAAU,MAAA;AACX;AAGO,SAAS,SAAA,GAAwB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACT;AAAA,KACD;AAAA,EACD;AACA,EAAA,OAAO,OAAA;AACR;ACtCA,IAAM,aAAA,GAAgB,GAAA;AAEtB,IAAM,aAAA,GAAgB,GAAA;AAGtB,eAAsB,aAAA,GAAwC;AAC7D,EAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAU,QAAA,KAAa,SAAA,EAAU;AACnD,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,QAAQ,IAAI,QAAQ,CAAA,CAAE,CAAA,CAAE,QAAA,CAAS,QAAQ,CAAA;AAEtE,EAAA,OAAO,EAAA,CACL,IAAA,CAAK,CAAA,EAAG,QAAQ,CAAA,SAAA,CAAA,EAAa;AAAA,IAC7B,OAAA,EAAS,EAAE,aAAA,EAAe,CAAA,MAAA,EAAS,KAAK,CAAA,CAAA,EAAG;AAAA,IAC3C,MAAM,IAAI,eAAA,CAAgB,EAAE,UAAA,EAAY,sBAAsB;AAAA,GAC9D,EACA,IAAA,EAAoB;AACvB;AAGA,IAAI,QAAA,GAA0B,IAAA;AAC9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0C;AAGxD,IAAA,SAAA,CAAU,MAAM,CAAA;AAAA,EACjB;AACD","file":"index.mjs","sourcesContent":["/**\n * SDK configuration.\n *\n * The library never reads the environment itself — a consumer constructs\n * `new ArpcSDK(config)`, which calls `configure()`. The `configFromEnv()` helper\n * is a convenience for the dev scripts (smoke / server), which load `.env` via\n * dotenv-flow and pass the result in.\n */\n/**\n * Bearer-token store. The SDK authenticates lazily on the first gateway call:\n * it asks `get()` for a still-valid token and, on `null`, exchanges credentials\n * and hands the fresh token to `set()`. Owning expiry is the cache's job —\n * `get()` returns `null` once the token is stale (or near-stale). The default\n * store is in-memory and per-process; supply one to persist across restarts or\n * share across workers.\n */\nexport interface TokenCache {\n\t/** Return a valid bearer token, or `null` if absent/expired. */\n\tget(): Promise<string | null>;\n\t/** Persist a freshly exchanged token. `expiresAt` already includes the SDK's refresh skew. */\n\tset(token: string, expiresAt: Date): Promise<void>;\n}\n\nexport interface ArpcConfig {\n\t/** OAuth host — token exchange only (`POST /v1/token`). */\n\toauthUrl: string;\n\t/** API gateway host — every non-auth call. */\n\tgatewayUrl: string;\n\t/**\n\t * OAuth client_id (HTTP Basic username). Also used as the lead's\n\t * `seller_agent_email` — the OAuth identity is a registered DRA agent.\n\t */\n\tusername: string;\n\t/** OAuth client_secret (HTTP Basic password). */\n\tpassword: string;\n\t/** Bearer-token store. Defaults to an in-memory, per-process cache. */\n\tcache?: TokenCache;\n}\n\nlet current: ArpcConfig | null = null;\n\n/** Set the active config. Called by the `ArpcSDK` constructor. */\nexport function configure(config: ArpcConfig): void {\n\tcurrent = config;\n}\n\n/** Read the active config. Throws if the SDK hasn't been constructed yet. */\nexport function getConfig(): ArpcConfig {\n\tif (!current) {\n\t\tthrow new Error(\n\t\t\t\"ArpcSDK is not configured — construct `new ArpcSDK(config)` before making calls\",\n\t\t);\n\t}\n\treturn current;\n}\n\n/**\n * Build a config from environment variables. Not used by the library itself —\n * only the dev scripts call this after loading `.env`.\n */\nexport function configFromEnv(\n\tenv: NodeJS.ProcessEnv = process.env,\n): ArpcConfig {\n\tconst need = (key: string): string => {\n\t\tconst value = env[key];\n\t\tif (!value)\n\t\t\tthrow new Error(`Missing required env var: ${key} (set it in .env)`);\n\t\treturn value;\n\t};\n\treturn {\n\t\toauthUrl: need(\"FDR_OAUTH_URL\"),\n\t\tgatewayUrl: need(\"FDR_API_GATEWAY_URL\"),\n\t\tusername: need(\"FDR_OAUTH_USERNAME\"),\n\t\tpassword: need(\"FDR_OAUTH_PASSWORD\"),\n\t};\n}\n","import ky from \"ky\";\nimport { getConfig, type TokenCache } from \"./config\";\n\n// Token lifecycle lives in the orchestration layer, not the generated client:\n// the exchange targets the OAuth host (not the gateway), uses HTTP Basic, and is\n// form-encoded. Authentication is lazy — `resolveToken()` runs from the ky\n// beforeRequest hook on the first gateway call (and again once the token goes\n// stale), so callers never manage the token by hand.\nexport interface TokenResponse {\n\taccess_token: string;\n\ttoken_type?: string;\n\texpires_in?: number;\n}\n\n// Refresh this many ms before the server's stated expiry, so a token never\n// lapses mid-flight. Applied once, when we compute the stored `expiresAt`.\nconst TOKEN_SKEW_MS = 30_000;\n// FDR tokens are ~900s; fall back to that if the response omits expires_in.\nconst DEFAULT_TTL_S = 900;\n\n/** Raw credentials → bearer JWT. No storage; `resolveToken()` owns that. */\nexport async function exchangeToken(): Promise<TokenResponse> {\n\tconst { oauthUrl, username, password } = getConfig();\n\tconst basic = Buffer.from(`${username}:${password}`).toString(\"base64\");\n\n\treturn ky\n\t\t.post(`${oauthUrl}/v1/token`, {\n\t\t\theaders: { Authorization: `Basic ${basic}` },\n\t\t\tbody: new URLSearchParams({ grant_type: \"client_credentials\" }),\n\t\t})\n\t\t.json<TokenResponse>();\n}\n\n// Default store: in-memory, per-process. Used when config omits `cache`.\nlet memToken: string | null = null;\nlet memExpiresAt = 0;\nconst defaultCache: TokenCache = {\n\tasync get() {\n\t\treturn memToken && Date.now() < memExpiresAt ? memToken : null;\n\t},\n\tasync set(token, expiresAt) {\n\t\tmemToken = token;\n\t\tmemExpiresAt = expiresAt.getTime();\n\t},\n};\n\n// Single-flight guard: a cold burst of concurrent gateway calls performs one\n// exchange, not one per call.\nlet inflight: Promise<string> | null = null;\n\n/**\n * Return a valid bearer token, exchanging + caching on a miss. Called by the\n * gateway beforeRequest hook; not part of the public surface.\n */\nexport function resolveToken(): Promise<string> {\n\tconst store = getConfig().cache ?? defaultCache;\n\tif (inflight) return inflight;\n\n\tinflight = (async () => {\n\t\tconst cached = await store.get();\n\t\tif (cached) return cached;\n\t\tconst res = await exchangeToken();\n\t\tconst ttl = (res.expires_in ?? DEFAULT_TTL_S) * 1000;\n\t\tawait store.set(\n\t\t\tres.access_token,\n\t\t\tnew Date(Date.now() + ttl - TOKEN_SKEW_MS),\n\t\t);\n\t\treturn res.access_token;\n\t})().finally(() => {\n\t\tinflight = null;\n\t});\n\treturn inflight;\n}\n","import ky from \"ky\";\nimport { resolveToken } from \"../auth\";\nimport { getConfig } from \"../config\";\n\n// ---------------------------------------------------------------------------\n// Orval custom mutator (ky-backed).\n//\n// Every generated operation calls `customInstance<T>(config, options)`. We\n// route all calls to the API gateway, attach the bearer token via a\n// beforeRequest hook (lazy auth — `resolveToken()` exchanges/refreshes as\n// needed), and return a small { status, data, headers } wrapper WITHOUT\n// throwing on non-2xx — the caller inspects status codes itself (202 +\n// Retry-After on program, 400 on a UW/DRA gate, etc.).\n// ---------------------------------------------------------------------------\n\n// Shape Orval passes as the first arg (axios-style request config).\nexport interface RequestConfig {\n\turl: string;\n\tmethod: string;\n\tparams?: Record<string, unknown>;\n\tdata?: unknown;\n\theaders?: Record<string, string>;\n\tsignal?: AbortSignal;\n\tresponseType?: string;\n}\n\nexport interface HttpResponse<T> {\n\tstatus: number;\n\tdata: T;\n\theaders: Headers;\n}\n\nexport const customInstance = async <T>(\n\trequest: RequestConfig,\n\toptions?: Partial<RequestConfig>,\n): Promise<HttpResponse<T>> => {\n\tconst { url, method, params, data, signal } = { ...request, ...options };\n\t// Merge headers from both sides — a per-call override (e.g. an\n\t// x-correlation-id in `options.headers`) must not drop the operation's\n\t// Content-Type. The bearer token is layered on last, below.\n\tconst headers = { ...request.headers, ...options?.headers };\n\n\tconst target = new URL(url, getConfig().gatewayUrl);\n\tif (params) {\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tif (value !== undefined && value !== null)\n\t\t\t\ttarget.searchParams.set(key, String(value));\n\t\t}\n\t}\n\n\tconst response = await ky(target, {\n\t\tmethod,\n\t\theaders,\n\t\thooks: {\n\t\t\t// Lazy bearer injection: resolveToken() exchanges on the first call\n\t\t\t// and refreshes once the cached token goes stale. The OAuth exchange\n\t\t\t// itself runs on a bare ky.post (no hook), so there's no recursion.\n\t\t\tbeforeRequest: [\n\t\t\t\tasync (req) => {\n\t\t\t\t\treq.headers.set(\"Authorization\", `Bearer ${await resolveToken()}`);\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t...(data !== undefined ? { json: data } : {}),\n\t\tsignal,\n\t\tthrowHttpErrors: false,\n\t\tretry: 0,\n\t\t// Some gateway calls (program generation in particular) can take well over ky's\n\t\t// 10s default to respond. Raise the per-request ceiling; the program poll loop\n\t\t// handles 202/Retry-After on top of this.\n\t\ttimeout: 60_000,\n\t});\n\n\tconst text = await response.text();\n\tlet body: T;\n\ttry {\n\t\tbody = (text ? JSON.parse(text) : undefined) as T;\n\t} catch {\n\t\t// Non-JSON body (e.g. a gateway HTML error page on a transient 5xx). Don't throw —\n\t\t// hand back the raw text so callers can inspect status/body and retry as needed.\n\t\tbody = text as unknown as T;\n\t}\n\treturn { status: response.status, data: body, headers: response.headers };\n};\n","/**\n * Generated by orval v7.21.0 🍺\n * Do not edit manually.\n * ARPC — Achieve Resolution Partner Connect API\n * FDR Wholesale API — A Hybrid Integration Model designed to maximise partner velocity without compromising enterprise data standards. DEX (Digital Enrollment Experience) is the partner-facing integration layer that powers the full applicant lifecycle. The `fdr_applicant_id` acts as the applicant's passport across all systems, persisted from first eligibility check through enrollment. All endpoints require a valid Bearer JWT with the `arpc.all` role.\n * OpenAPI spec version: 2026.15.0\n */\nimport type {\n ARPCErrorResponse,\n ApplicationSendEmailResponse,\n BankUpdateRequest,\n CreateLeadRequest,\n CreateLeadResponse,\n DraRequest,\n DraResponse,\n EligibilityRequest,\n EligibilityResponse,\n LeadPatchRequest,\n LeadResponse,\n LeadTransferRequest,\n LeadTransferResponse,\n ProgramRequest,\n ProgramSummaryTaskRequest,\n ProgramSummaryTaskResponse,\n ReadinessResponse,\n RegisterApplicantResponse,\n RegisterApplicantV2Request,\n SpinwheelNetworkUserRequest,\n SpinwheelNetworkUserResponse,\n StatelessReadinessRequest,\n UwSubmissionV2Response\n} from './model';\n\nimport { customInstance } from '../http/client';\ntype SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n\n export const getARPCAchieveResolutionPartnerConnectAPI = () => {\n/**\n * Synchronous Orchestration: Handles both lead creation and income/expense data in one step, eliminating the async polling black box. Data authority shifts here — Achieve (SUIP SF) becomes the Source of Truth once the lead is formally promoted. Returns the full lead creation result including program options.\n * @summary Sync wholesale lead creation\n */\nconst createLeadSync = (\n createLeadRequest: CreateLeadRequest,\n options?: SecondParameter<typeof customInstance<CreateLeadResponse>>,) => {\n return customInstance<CreateLeadResponse>(\n {url: `/v3/application`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: createLeadRequest\n },\n options);\n }\n \n/**\n * Stateless Readiness Check: Pre-flight validation before initiating program calculations. Catches duplicate SSNs or emails early to prevent downstream failures. Requires a valid Authorization header.\n * @summary Check application readiness\n */\nconst checkApplicationReadiness = (\n statelessReadinessRequest: StatelessReadinessRequest,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/readiness`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: statelessReadinessRequest\n },\n options);\n }\n \n/**\n * Recovery endpoint — only required when the async Spinwheel user creation triggered by `POST /v1/applicant/register` fails due to a user error (e.g. invalid SSN or DOB). Not needed in the happy path. Authenticates the seller, resolves the law firm / program, creates an applicant ID when needed, and connects the applicant to the Spinwheel network. Requires a valid Authorization header.\n * @summary Create / connect Spinwheel network user\n */\nconst createSpinwheelNetworkUser = (\n spinwheelNetworkUserRequest: SpinwheelNetworkUserRequest,\n options?: SecondParameter<typeof customInstance<SpinwheelNetworkUserResponse>>,) => {\n return customInstance<SpinwheelNetworkUserResponse>(\n {url: `/v1/application/spinwheel-network-user`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: spinwheelNetworkUserRequest\n },\n options);\n }\n \n/**\n * Authenticates the seller, validates banking disclosure requirements, optionally validates the submitted account and routing numbers, patches the program, and returns the refreshed lead payload. Requires a valid Authorization header.\n * @summary Update applicant bank details\n */\nconst updateApplicationBankDetails = (\n applicantId: string,\n bankUpdateRequest: BankUpdateRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/bank-update/${applicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: bankUpdateRequest\n },\n options);\n }\n \n/**\n * Banking Disclosure: Manually triggers the banking disclosure email. **This endpoint is optional** — it is only needed when the disclosure was not already sent automatically by `POST /v2/application/uw-submission/{fdrApplicantId}` (which auto-sends on full UW approval). Use this endpoint for conditional approvals or when the v1 UW submission path is in use. A critical legal prerequisite that must be completed before enrollment can proceed. Requires a valid Authorization header.\n * @summary Send banking disclosure email (optional — only if not auto-sent by v2 UW submission)\n */\nconst sendEmail = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<ApplicationSendEmailResponse>>,) => {\n return customInstance<ApplicationSendEmailResponse>(\n {url: `/v1/application/send-email/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Submits a lead evaluation request. fdr_applicant_id is required in the request body. Requires a valid Authorization header with the arpc.all role.\n * @summary Transfer a lead to the debt-resolution program\n */\nconst leadTransfer = (\n leadTransferRequest: LeadTransferRequest,\n options?: SecondParameter<typeof customInstance<LeadTransferResponse>>,) => {\n return customInstance<LeadTransferResponse>(\n {url: `/v1/application/lead-transfer`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: leadTransferRequest\n },\n options);\n }\n \n/**\n * Fetches the current state of an application / lead record by FDR applicant ID. Requires a valid Authorization header.\n * @summary Read application / lead details\n */\nconst readLead = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'GET'\n },\n options);\n }\n \n/**\n * Applies a partial update to an existing wholesale lead record. Requires a valid Authorization header and an x-correlation-id header for request tracing.\n * @summary Partial update of application / lead record\n */\nconst patchLead = (\n fdrApplicantId: string,\n leadPatchRequest: LeadPatchRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/${fdrApplicantId}`, method: 'PATCH',\n headers: {'Content-Type': 'application/json', },\n data: leadPatchRequest\n },\n options);\n }\n \n/**\n * DRA Readiness Check: Final pre-flight confirming the lead is approved and all prerequisites are met before initiating the embedded signing session. Requires a valid Authorization header.\n * @summary Get application readiness status\n */\nconst getApplicationReadiness = (\n applicantId: string,\n options?: SecondParameter<typeof customInstance<ReadinessResponse>>,) => {\n return customInstance<ReadinessResponse>(\n {url: `/v1/application/${applicantId}/readiness`, method: 'GET'\n },\n options);\n }\n \n/**\n * Embedded DRA Signing: Returns an Embedded Signing URL so the applicant signs the Debt Resolution Agreement via DocuSign directly within the Symple UI, preventing session breakage. Successful legal execution triggers automatic enrollment. Requires a valid Authorization header.\n * @summary Generate Debt Resolution Agreement (DRA)\n */\nconst generateDra = (\n applicantId: string,\n draRequest: DraRequest,\n options?: SecondParameter<typeof customInstance<DraResponse>>,) => {\n return customInstance<DraResponse>(\n {url: `/v2/application/${applicantId}/dra`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: draRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint.** `POST /v1/applicant/register` is deprecated and will be retired by end of July 2026 (deadline can be extended on request if your team needs more time). Identity Anchoring: Persists applicant PII to the Managed Package and generates the `fdr_applicant_id` — the applicant's passport across all systems. Routes to the correct Salesforce target (MP or WiB) based on seller identity, and triggers the async credit fetch. Requires a valid Authorization header.\n * @summary Seller-aware applicant registration (v2 — unified ARPCErrorResponse envelope) — recommended\n */\nconst registerApplicantV2 = (\n registerApplicantV2Request: RegisterApplicantV2Request,\n options?: SecondParameter<typeof customInstance<RegisterApplicantResponse>>,) => {\n return customInstance<RegisterApplicantResponse>(\n {url: `/v2/applicant/register`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: registerApplicantV2Request\n },\n options);\n }\n \n/**\n * Async Polling Loop: Call this single endpoint for both initial generation and refresh. Returns 202 Accepted with a Retry-After header while credit is still pending. Once ready, the Managed Package orchestrates the calculation and persists the program result. Requires a valid Authorization header.\n * @summary Generate application program (v1)\n */\nconst generateProgramV1 = (\n programRequest: ProgramRequest,\n options?: SecondParameter<typeof customInstance<LeadResponse>>,) => {\n return customInstance<LeadResponse>(\n {url: `/v1/application/program`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programRequest\n },\n options);\n }\n \n/**\n * Eligibility Scout: A stateless, real-time quote based on anonymised data — no PII required. Returns estimated program options to anchor the conversation before any registration occurs. Requires a valid Authorization header.\n * @summary Check application eligibility\n */\nconst checkEligibility = (\n eligibilityRequest: EligibilityRequest,\n options?: SecondParameter<typeof customInstance<EligibilityResponse>>,) => {\n return customInstance<EligibilityResponse>(\n {url: `/v2/application/eligibility`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: eligibilityRequest\n },\n options);\n }\n \n/**\n * **Recommended endpoint — supersedes v1.** Submits a wholesale application to the underwriting system. On full UW approval (`sub_status = 'UW Approved'`) the banking disclosure email is sent automatically — no separate `send-email` call is needed in this path. Conditional approvals suppress the auto-send; in that case the manual `POST /v1/application/send-email/{fdrApplicantId}` endpoint can be used. Uses the SF Object API directly (no suip-proxy hop). Requires a valid Authorization header.\n * @summary Submit application to underwriting (v2 — auto banking disclosure) — recommended\n */\nconst uwSubmissionV2 = (\n fdrApplicantId: string,\n options?: SecondParameter<typeof customInstance<UwSubmissionV2Response>>,) => {\n return customInstance<UwSubmissionV2Response>(\n {url: `/v2/application/uw-submission/${fdrApplicantId}`, method: 'POST'\n },\n options);\n }\n \n/**\n * Creates a SUIP Salesforce 'Program Summary Recording' task for the applicant identified by the {id} path variable. For DEX (or missing header), the parent SF opportunity is additionally PATCHed with the seller-config partner default PSC. For DC, the task is created and the parent SF opportunity is PATCHed only when ws_psc_code is provided in the request payload.\n * @summary Create program-summary recording task\n */\nconst createProgramSummaryTask = (\n id: string,\n programSummaryTaskRequest: ProgramSummaryTaskRequest,\n options?: SecondParameter<typeof customInstance<ProgramSummaryTaskResponse>>,) => {\n return customInstance<ProgramSummaryTaskResponse>(\n {url: `/v2/application/program-summary-task/${id}`, method: 'POST',\n headers: {'Content-Type': 'application/json', },\n data: programSummaryTaskRequest\n },\n options);\n }\n \nreturn {createLeadSync,checkApplicationReadiness,createSpinwheelNetworkUser,updateApplicationBankDetails,sendEmail,leadTransfer,readLead,patchLead,getApplicationReadiness,generateDra,registerApplicantV2,generateProgramV1,checkEligibility,uwSubmissionV2,createProgramSummaryTask}};\nexport type CreateLeadSyncResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createLeadSync']>>>\nexport type CheckApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkApplicationReadiness']>>>\nexport type CreateSpinwheelNetworkUserResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createSpinwheelNetworkUser']>>>\nexport type UpdateApplicationBankDetailsResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['updateApplicationBankDetails']>>>\nexport type SendEmailResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['sendEmail']>>>\nexport type LeadTransferResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['leadTransfer']>>>\nexport type ReadLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['readLead']>>>\nexport type PatchLeadResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['patchLead']>>>\nexport type GetApplicationReadinessResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['getApplicationReadiness']>>>\nexport type GenerateDraResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateDra']>>>\nexport type RegisterApplicantV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['registerApplicantV2']>>>\nexport type GenerateProgramV1Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['generateProgramV1']>>>\nexport type CheckEligibilityResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['checkEligibility']>>>\nexport type UwSubmissionV2Result = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['uwSubmissionV2']>>>\nexport type CreateProgramSummaryTaskResult = NonNullable<Awaited<ReturnType<ReturnType<typeof getARPCAchieveResolutionPartnerConnectAPI>['createProgramSummaryTask']>>>\n","import { type ArpcConfig, configure } from \"./config\";\nimport { getARPCAchieveResolutionPartnerConnectAPI } from \"./generated/arpc\";\n\nexport type { ArpcConfig, TokenCache } from \"./config\";\nexport type * from \"./generated/model\";\nexport type { HttpResponse } from \"./http/client\";\n\n/**\n * ARPC SDK — a typed, agnostic client for FDR's ARPC DEX API (Achieve\n * Resolution Partner Connect, Digital Enrollment Experience).\n *\n * Thin by design: it owns the two-host routing, the OAuth token lifecycle, and\n * bearer injection, and exposes the full endpoint surface as typed operations\n * on `sdk.api`. It does not orchestrate the enrollment sequence — the caller\n * assembles payloads and threads the `fdr_applicant_id` between calls. See\n * `scripts/smoke.ts` for a full end-to-end reference sequence (incl. the program\n * poll loop).\n *\n * Auth is lazy: the first `api` call exchanges credentials for a bearer JWT and\n * caches it (~900s TTL), then re-exchanges shortly before it expires. There's no\n * explicit login step. Supply a `cache` in the config to persist the token\n * across restarts or share it across workers; otherwise it's held in-process.\n *\n * Operations never throw on a non-2xx: each returns `{ status, data, headers }`,\n * so a business gate (e.g. a UW/DRA readiness failure) comes back as a normal\n * response you inspect via `status`/`data`. Only transport errors throw.\n *\n * Note: config and the default token cache are process-global — construct one\n * `ArpcSDK` per process. A second instance reconfigures the first; instances are\n * not isolated (single-tenant by design).\n *\n * @example\n * ```typescript\n * const sdk = new ArpcSDK({\n * oauthUrl: \"https://oauth.stg.ffngcp.com\",\n * gatewayUrl: \"https://apis-gateway-v2.stg.fdrgcp.com\",\n * username: \"borrowbetter@seller.com\",\n * password: process.env.FDR_OAUTH_PASSWORD!,\n * });\n *\n * // The first call authenticates automatically and caches the token.\n * const elig = await sdk.api.checkEligibility({ ... });\n * const faid = elig.data.application?.applicant?.fdr_applicant_id;\n * ```\n */\nexport class ArpcSDK {\n\t/** The full typed endpoint surface — one method per gateway operation. */\n\treadonly api = getARPCAchieveResolutionPartnerConnectAPI();\n\n\tconstructor(config: ArpcConfig) {\n\t\tconfigure(config);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,54 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
2
|
+
"name": "@borrowbetter/arpcsdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Typed, agnostic client for FDR's ARPC DEX API — Achieve Resolution Partner Connect (Digital Enrollment Experience)",
|
|
5
|
+
"author": "BorrowBetter",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/BorrowBetter/arpcsdk.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/BorrowBetter/arpcsdk#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/BorrowBetter/arpcsdk/issues"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.mjs",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"require": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"packageManager": "pnpm@10.24.0",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "pnpm codegen && tsup",
|
|
34
|
+
"build:dist": "tsup",
|
|
35
|
+
"codegen": "orval --config codegen.ts",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"typecheck:scripts": "tsc --noEmit --project scripts/tsconfig.json",
|
|
39
|
+
"smoke": "tsx scripts/smoke.ts",
|
|
40
|
+
"prepublishOnly": "pnpm build",
|
|
41
|
+
"lint": "biome check",
|
|
42
|
+
"format": "biome check --write --unsafe",
|
|
43
|
+
"format:check": "biome ci",
|
|
44
|
+
"changeset": "changeset",
|
|
45
|
+
"version": "changeset version",
|
|
46
|
+
"release": "pnpm build && changeset publish"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"ky": "^1.7.4"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@biomejs/biome": "^2.4.4",
|
|
53
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
54
|
+
"@changesets/cli": "^2.27.0",
|
|
55
|
+
"@types/node": "^22.10.5",
|
|
56
|
+
"dotenv-flow": "^4.1.0",
|
|
57
|
+
"orval": "^7.13.0",
|
|
58
|
+
"tsup": "^8.0.0",
|
|
59
|
+
"tsx": "^4.21.0",
|
|
60
|
+
"typescript": "^5.7.3"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18"
|
|
64
|
+
}
|
|
65
|
+
}
|