@borrowbetter/arpcsdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,255 @@
1
+ 'use strict';
2
+
3
+ var ky = require('ky');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var ky__default = /*#__PURE__*/_interopDefault(ky);
8
+
9
+ // src/auth.ts
10
+
11
+ // src/config.ts
12
+ var current = null;
13
+ function configure(config) {
14
+ current = config;
15
+ }
16
+ function getConfig() {
17
+ if (!current) {
18
+ throw new Error(
19
+ "ArpcSDK is not configured \u2014 construct `new ArpcSDK(config)` before making calls"
20
+ );
21
+ }
22
+ return current;
23
+ }
24
+ var bearerToken = null;
25
+ function setBearerToken(token) {
26
+ bearerToken = token;
27
+ }
28
+ var customInstance = async (request, options) => {
29
+ const { url, method, params, data, signal } = { ...request, ...options };
30
+ const headers = { ...request.headers, ...options?.headers };
31
+ const target = new URL(url, getConfig().gatewayUrl);
32
+ if (params) {
33
+ for (const [key, value] of Object.entries(params)) {
34
+ if (value !== void 0 && value !== null)
35
+ target.searchParams.set(key, String(value));
36
+ }
37
+ }
38
+ const response = await ky__default.default(target, {
39
+ method,
40
+ headers: {
41
+ ...headers,
42
+ ...bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}
43
+ },
44
+ ...data !== void 0 ? { json: data } : {},
45
+ signal,
46
+ throwHttpErrors: false,
47
+ retry: 0,
48
+ // Some gateway calls (program generation in particular) can take well over ky's
49
+ // 10s default to respond. Raise the per-request ceiling; the program poll loop
50
+ // handles 202/Retry-After on top of this.
51
+ timeout: 6e4
52
+ });
53
+ const text = await response.text();
54
+ let body;
55
+ try {
56
+ body = text ? JSON.parse(text) : void 0;
57
+ } catch {
58
+ body = text;
59
+ }
60
+ return { status: response.status, data: body, headers: response.headers };
61
+ };
62
+
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
+ // src/generated/arpc.ts
76
+ var getARPCAchieveResolutionPartnerConnectAPI = () => {
77
+ const createLeadSync = (createLeadRequest, options) => {
78
+ return customInstance(
79
+ {
80
+ url: `/v3/application`,
81
+ method: "POST",
82
+ headers: { "Content-Type": "application/json" },
83
+ data: createLeadRequest
84
+ },
85
+ options
86
+ );
87
+ };
88
+ const checkApplicationReadiness = (statelessReadinessRequest, options) => {
89
+ return customInstance(
90
+ {
91
+ url: `/v1/application/readiness`,
92
+ method: "POST",
93
+ headers: { "Content-Type": "application/json" },
94
+ data: statelessReadinessRequest
95
+ },
96
+ options
97
+ );
98
+ };
99
+ const createSpinwheelNetworkUser = (spinwheelNetworkUserRequest, options) => {
100
+ return customInstance(
101
+ {
102
+ url: `/v1/application/spinwheel-network-user`,
103
+ method: "POST",
104
+ headers: { "Content-Type": "application/json" },
105
+ data: spinwheelNetworkUserRequest
106
+ },
107
+ options
108
+ );
109
+ };
110
+ const updateApplicationBankDetails = (applicantId, bankUpdateRequest, options) => {
111
+ return customInstance(
112
+ {
113
+ url: `/v1/application/bank-update/${applicantId}`,
114
+ method: "PATCH",
115
+ headers: { "Content-Type": "application/json" },
116
+ data: bankUpdateRequest
117
+ },
118
+ options
119
+ );
120
+ };
121
+ const sendEmail = (fdrApplicantId, options) => {
122
+ return customInstance(
123
+ {
124
+ url: `/v1/application/send-email/${fdrApplicantId}`,
125
+ method: "POST"
126
+ },
127
+ options
128
+ );
129
+ };
130
+ const leadTransfer = (leadTransferRequest, options) => {
131
+ return customInstance(
132
+ {
133
+ url: `/v1/application/lead-transfer`,
134
+ method: "POST",
135
+ headers: { "Content-Type": "application/json" },
136
+ data: leadTransferRequest
137
+ },
138
+ options
139
+ );
140
+ };
141
+ const readLead = (fdrApplicantId, options) => {
142
+ return customInstance(
143
+ {
144
+ url: `/v1/application/${fdrApplicantId}`,
145
+ method: "GET"
146
+ },
147
+ options
148
+ );
149
+ };
150
+ const patchLead = (fdrApplicantId, leadPatchRequest, options) => {
151
+ return customInstance(
152
+ {
153
+ url: `/v1/application/${fdrApplicantId}`,
154
+ method: "PATCH",
155
+ headers: { "Content-Type": "application/json" },
156
+ data: leadPatchRequest
157
+ },
158
+ options
159
+ );
160
+ };
161
+ const getApplicationReadiness = (applicantId, options) => {
162
+ return customInstance(
163
+ {
164
+ url: `/v1/application/${applicantId}/readiness`,
165
+ method: "GET"
166
+ },
167
+ options
168
+ );
169
+ };
170
+ const generateDra = (applicantId, draRequest, options) => {
171
+ return customInstance(
172
+ {
173
+ url: `/v2/application/${applicantId}/dra`,
174
+ method: "POST",
175
+ headers: { "Content-Type": "application/json" },
176
+ data: draRequest
177
+ },
178
+ options
179
+ );
180
+ };
181
+ const registerApplicantV2 = (registerApplicantV2Request, options) => {
182
+ return customInstance(
183
+ {
184
+ url: `/v2/applicant/register`,
185
+ method: "POST",
186
+ headers: { "Content-Type": "application/json" },
187
+ data: registerApplicantV2Request
188
+ },
189
+ options
190
+ );
191
+ };
192
+ const generateProgramV1 = (programRequest, options) => {
193
+ return customInstance(
194
+ {
195
+ url: `/v1/application/program`,
196
+ method: "POST",
197
+ headers: { "Content-Type": "application/json" },
198
+ data: programRequest
199
+ },
200
+ options
201
+ );
202
+ };
203
+ const checkEligibility = (eligibilityRequest, options) => {
204
+ return customInstance(
205
+ {
206
+ url: `/v2/application/eligibility`,
207
+ method: "POST",
208
+ headers: { "Content-Type": "application/json" },
209
+ data: eligibilityRequest
210
+ },
211
+ options
212
+ );
213
+ };
214
+ const uwSubmissionV2 = (fdrApplicantId, options) => {
215
+ return customInstance(
216
+ {
217
+ url: `/v2/application/uw-submission/${fdrApplicantId}`,
218
+ method: "POST"
219
+ },
220
+ options
221
+ );
222
+ };
223
+ const createProgramSummaryTask = (id, programSummaryTaskRequest, options) => {
224
+ return customInstance(
225
+ {
226
+ url: `/v2/application/program-summary-task/${id}`,
227
+ method: "POST",
228
+ headers: { "Content-Type": "application/json" },
229
+ data: programSummaryTaskRequest
230
+ },
231
+ options
232
+ );
233
+ };
234
+ return { createLeadSync, checkApplicationReadiness, createSpinwheelNetworkUser, updateApplicationBankDetails, sendEmail, leadTransfer, readLead, patchLead, getApplicationReadiness, generateDra, registerApplicantV2, generateProgramV1, checkEligibility, uwSubmissionV2, createProgramSummaryTask };
235
+ };
236
+
237
+ // src/index.ts
238
+ var ArpcSDK = class {
239
+ constructor(config) {
240
+ /** The full typed endpoint surface — one method per gateway operation. */
241
+ this.api = getARPCAchieveResolutionPartnerConnectAPI();
242
+ configure(config);
243
+ }
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
+ };
252
+
253
+ exports.ArpcSDK = ArpcSDK;
254
+ //# sourceMappingURL=index.js.map
255
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;A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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.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"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,249 @@
1
+ import ky from 'ky';
2
+
3
+ // src/auth.ts
4
+
5
+ // src/config.ts
6
+ var current = null;
7
+ function configure(config) {
8
+ current = config;
9
+ }
10
+ function getConfig() {
11
+ if (!current) {
12
+ throw new Error(
13
+ "ArpcSDK is not configured \u2014 construct `new ArpcSDK(config)` before making calls"
14
+ );
15
+ }
16
+ return current;
17
+ }
18
+ var bearerToken = null;
19
+ function setBearerToken(token) {
20
+ bearerToken = token;
21
+ }
22
+ var customInstance = async (request, options) => {
23
+ const { url, method, params, data, signal } = { ...request, ...options };
24
+ const headers = { ...request.headers, ...options?.headers };
25
+ const target = new URL(url, getConfig().gatewayUrl);
26
+ if (params) {
27
+ for (const [key, value] of Object.entries(params)) {
28
+ if (value !== void 0 && value !== null)
29
+ target.searchParams.set(key, String(value));
30
+ }
31
+ }
32
+ const response = await ky(target, {
33
+ method,
34
+ headers: {
35
+ ...headers,
36
+ ...bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}
37
+ },
38
+ ...data !== void 0 ? { json: data } : {},
39
+ signal,
40
+ throwHttpErrors: false,
41
+ retry: 0,
42
+ // Some gateway calls (program generation in particular) can take well over ky's
43
+ // 10s default to respond. Raise the per-request ceiling; the program poll loop
44
+ // handles 202/Retry-After on top of this.
45
+ timeout: 6e4
46
+ });
47
+ const text = await response.text();
48
+ let body;
49
+ try {
50
+ body = text ? JSON.parse(text) : void 0;
51
+ } catch {
52
+ body = text;
53
+ }
54
+ return { status: response.status, data: body, headers: response.headers };
55
+ };
56
+
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
+ // src/generated/arpc.ts
70
+ var getARPCAchieveResolutionPartnerConnectAPI = () => {
71
+ const createLeadSync = (createLeadRequest, options) => {
72
+ return customInstance(
73
+ {
74
+ url: `/v3/application`,
75
+ method: "POST",
76
+ headers: { "Content-Type": "application/json" },
77
+ data: createLeadRequest
78
+ },
79
+ options
80
+ );
81
+ };
82
+ const checkApplicationReadiness = (statelessReadinessRequest, options) => {
83
+ return customInstance(
84
+ {
85
+ url: `/v1/application/readiness`,
86
+ method: "POST",
87
+ headers: { "Content-Type": "application/json" },
88
+ data: statelessReadinessRequest
89
+ },
90
+ options
91
+ );
92
+ };
93
+ const createSpinwheelNetworkUser = (spinwheelNetworkUserRequest, options) => {
94
+ return customInstance(
95
+ {
96
+ url: `/v1/application/spinwheel-network-user`,
97
+ method: "POST",
98
+ headers: { "Content-Type": "application/json" },
99
+ data: spinwheelNetworkUserRequest
100
+ },
101
+ options
102
+ );
103
+ };
104
+ const updateApplicationBankDetails = (applicantId, bankUpdateRequest, options) => {
105
+ return customInstance(
106
+ {
107
+ url: `/v1/application/bank-update/${applicantId}`,
108
+ method: "PATCH",
109
+ headers: { "Content-Type": "application/json" },
110
+ data: bankUpdateRequest
111
+ },
112
+ options
113
+ );
114
+ };
115
+ const sendEmail = (fdrApplicantId, options) => {
116
+ return customInstance(
117
+ {
118
+ url: `/v1/application/send-email/${fdrApplicantId}`,
119
+ method: "POST"
120
+ },
121
+ options
122
+ );
123
+ };
124
+ const leadTransfer = (leadTransferRequest, options) => {
125
+ return customInstance(
126
+ {
127
+ url: `/v1/application/lead-transfer`,
128
+ method: "POST",
129
+ headers: { "Content-Type": "application/json" },
130
+ data: leadTransferRequest
131
+ },
132
+ options
133
+ );
134
+ };
135
+ const readLead = (fdrApplicantId, options) => {
136
+ return customInstance(
137
+ {
138
+ url: `/v1/application/${fdrApplicantId}`,
139
+ method: "GET"
140
+ },
141
+ options
142
+ );
143
+ };
144
+ const patchLead = (fdrApplicantId, leadPatchRequest, options) => {
145
+ return customInstance(
146
+ {
147
+ url: `/v1/application/${fdrApplicantId}`,
148
+ method: "PATCH",
149
+ headers: { "Content-Type": "application/json" },
150
+ data: leadPatchRequest
151
+ },
152
+ options
153
+ );
154
+ };
155
+ const getApplicationReadiness = (applicantId, options) => {
156
+ return customInstance(
157
+ {
158
+ url: `/v1/application/${applicantId}/readiness`,
159
+ method: "GET"
160
+ },
161
+ options
162
+ );
163
+ };
164
+ const generateDra = (applicantId, draRequest, options) => {
165
+ return customInstance(
166
+ {
167
+ url: `/v2/application/${applicantId}/dra`,
168
+ method: "POST",
169
+ headers: { "Content-Type": "application/json" },
170
+ data: draRequest
171
+ },
172
+ options
173
+ );
174
+ };
175
+ const registerApplicantV2 = (registerApplicantV2Request, options) => {
176
+ return customInstance(
177
+ {
178
+ url: `/v2/applicant/register`,
179
+ method: "POST",
180
+ headers: { "Content-Type": "application/json" },
181
+ data: registerApplicantV2Request
182
+ },
183
+ options
184
+ );
185
+ };
186
+ const generateProgramV1 = (programRequest, options) => {
187
+ return customInstance(
188
+ {
189
+ url: `/v1/application/program`,
190
+ method: "POST",
191
+ headers: { "Content-Type": "application/json" },
192
+ data: programRequest
193
+ },
194
+ options
195
+ );
196
+ };
197
+ const checkEligibility = (eligibilityRequest, options) => {
198
+ return customInstance(
199
+ {
200
+ url: `/v2/application/eligibility`,
201
+ method: "POST",
202
+ headers: { "Content-Type": "application/json" },
203
+ data: eligibilityRequest
204
+ },
205
+ options
206
+ );
207
+ };
208
+ const uwSubmissionV2 = (fdrApplicantId, options) => {
209
+ return customInstance(
210
+ {
211
+ url: `/v2/application/uw-submission/${fdrApplicantId}`,
212
+ method: "POST"
213
+ },
214
+ options
215
+ );
216
+ };
217
+ const createProgramSummaryTask = (id, programSummaryTaskRequest, options) => {
218
+ return customInstance(
219
+ {
220
+ url: `/v2/application/program-summary-task/${id}`,
221
+ method: "POST",
222
+ headers: { "Content-Type": "application/json" },
223
+ data: programSummaryTaskRequest
224
+ },
225
+ options
226
+ );
227
+ };
228
+ return { createLeadSync, checkApplicationReadiness, createSpinwheelNetworkUser, updateApplicationBankDetails, sendEmail, leadTransfer, readLead, patchLead, getApplicationReadiness, generateDra, registerApplicantV2, generateProgramV1, checkEligibility, uwSubmissionV2, createProgramSummaryTask };
229
+ };
230
+
231
+ // src/index.ts
232
+ var ArpcSDK = class {
233
+ constructor(config) {
234
+ /** The full typed endpoint surface — one method per gateway operation. */
235
+ this.api = getARPCAchieveResolutionPartnerConnectAPI();
236
+ configure(config);
237
+ }
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
+ };
246
+
247
+ export { ArpcSDK };
248
+ //# sourceMappingURL=index.mjs.map
249
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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;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AAA,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"]}