Skip to content

Commit 4b5c967

Browse files
feat(api): add retrieveSignals methods to accounts and cards
1 parent 7ea2203 commit 4b5c967

13 files changed

Lines changed: 401 additions & 7 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 191
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic/lithic-af9701d01abffc53ba2bf56c06415d893460e6b420f122e602cf4afe67bbf57b.yml
1+
configured_endpoints: 193
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic/lithic-00f07b0edcc0c3c5ef79920ced7f58dac2434df5e4c27ff6041783e8228315f9.yml
33
openapi_spec_hash: 963688b09480159a06865075c94a2577
4-
config_hash: 01dfc901bb6d54b0f582155d779bcbe0
4+
config_hash: 265a2b679964f4ad5706de101ad2a942

api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Methods:
3434
- <code title="get /v1/accounts/{account_token}">client.accounts.<a href="./src/resources/accounts.ts">retrieve</a>(accountToken) -> Account</code>
3535
- <code title="patch /v1/accounts/{account_token}">client.accounts.<a href="./src/resources/accounts.ts">update</a>(accountToken, { ...params }) -> Account</code>
3636
- <code title="get /v1/accounts">client.accounts.<a href="./src/resources/accounts.ts">list</a>({ ...params }) -> AccountsCursorPage</code>
37+
- <code title="get /v1/accounts/{account_token}/signals">client.accounts.<a href="./src/resources/accounts.ts">retrieveSignals</a>(accountToken) -> SignalsResponse</code>
3738
- <code title="get /v1/accounts/{account_token}/spend_limits">client.accounts.<a href="./src/resources/accounts.ts">retrieveSpendLimits</a>(accountToken) -> AccountSpendLimits</code>
3839

3940
# AccountHolders
@@ -78,6 +79,10 @@ Methods:
7879

7980
# AuthRules
8081

82+
Types:
83+
84+
- <code><a href="./src/resources/auth-rules/auth-rules.ts">SignalsResponse</a></code>
85+
8186
## V2
8287

8388
Types:
@@ -207,6 +212,7 @@ Methods:
207212
- <code title="post /v1/cards/{card_token}/provision">client.cards.<a href="./src/resources/cards/cards.ts">provision</a>(cardToken, { ...params }) -> CardProvisionResponse</code>
208213
- <code title="post /v1/cards/{card_token}/reissue">client.cards.<a href="./src/resources/cards/cards.ts">reissue</a>(cardToken, { ...params }) -> Card</code>
209214
- <code title="post /v1/cards/{card_token}/renew">client.cards.<a href="./src/resources/cards/cards.ts">renew</a>(cardToken, { ...params }) -> Card</code>
215+
- <code title="get /v1/cards/{card_token}/signals">client.cards.<a href="./src/resources/cards/cards.ts">retrieveSignals</a>(cardToken) -> SignalsResponse</code>
210216
- <code title="get /v1/cards/{card_token}/spend_limits">client.cards.<a href="./src/resources/cards/cards.ts">retrieveSpendLimits</a>(cardToken) -> CardSpendLimits</code>
211217
- <code title="post /v1/cards/search_by_pan">client.cards.<a href="./src/resources/cards/cards.ts">searchByPan</a>({ ...params }) -> Card</code>
212218
- <code title="post /v1/cards/{card_token}/web_provision">client.cards.<a href="./src/resources/cards/cards.ts">webProvision</a>(cardToken, { ...params }) -> CardWebProvisionResponse</code>

packages/mcp-server/src/code-tool-worker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const fuse = new Fuse(
111111
'client.apiStatus',
112112
'client.accounts.list',
113113
'client.accounts.retrieve',
114+
'client.accounts.retrieveSignals',
114115
'client.accounts.retrieveSpendLimits',
115116
'client.accounts.update',
116117
'client.accountHolders.create',
@@ -158,6 +159,7 @@ const fuse = new Fuse(
158159
'client.cards.reissue',
159160
'client.cards.renew',
160161
'client.cards.retrieve',
162+
'client.cards.retrieveSignals',
161163
'client.cards.retrieveSpendLimits',
162164
'client.cards.searchByPan',
163165
'client.cards.update',

packages/mcp-server/src/local-docs-search.ts

Lines changed: 102 additions & 0 deletions
Large diffs are not rendered by default.

packages/mcp-server/src/methods.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const sdkMethods: SdkMethod[] = [
3434
httpMethod: 'get',
3535
httpPath: '/v1/accounts',
3636
},
37+
{
38+
clientCallName: 'client.accounts.retrieveSignals',
39+
fullyQualifiedName: 'accounts.retrieveSignals',
40+
httpMethod: 'get',
41+
httpPath: '/v1/accounts/{account_token}/signals',
42+
},
3743
{
3844
clientCallName: 'client.accounts.retrieveSpendLimits',
3945
fullyQualifiedName: 'accounts.retrieveSpendLimits',
@@ -316,6 +322,12 @@ export const sdkMethods: SdkMethod[] = [
316322
httpMethod: 'post',
317323
httpPath: '/v1/cards/{card_token}/renew',
318324
},
325+
{
326+
clientCallName: 'client.cards.retrieveSignals',
327+
fullyQualifiedName: 'cards.retrieveSignals',
328+
httpMethod: 'get',
329+
httpPath: '/v1/cards/{card_token}/signals',
330+
},
319331
{
320332
clientCallName: 'client.cards.retrieveSpendLimits',
321333
fullyQualifiedName: 'cards.retrieveSpendLimits',

src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ import {
267267
KYCExempt,
268268
RequiredDocument,
269269
} from './resources/account-holders/account-holders';
270-
import { AuthRules } from './resources/auth-rules/auth-rules';
270+
import { AuthRules, SignalsResponse } from './resources/auth-rules/auth-rules';
271271
import {
272272
Card,
273273
CardConvertPhysicalParams,
@@ -1256,7 +1256,7 @@ export declare namespace Lithic {
12561256
type AccountHolderUploadDocumentParams as AccountHolderUploadDocumentParams,
12571257
};
12581258

1259-
export { AuthRules as AuthRules };
1259+
export { AuthRules as AuthRules, type SignalsResponse as SignalsResponse };
12601260

12611261
export { AuthStreamEnrollment as AuthStreamEnrollment, type AuthStreamSecret as AuthStreamSecret };
12621262

src/resources/accounts.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
import { APIResource } from '../core/resource';
4+
import * as AuthRulesAPI from './auth-rules/auth-rules';
45
import { APIPromise } from '../core/api-promise';
56
import { CursorPage, type CursorPageParams, PagePromise } from '../core/pagination';
67
import { RequestOptions } from '../internal/request-options';
@@ -56,6 +57,28 @@ export class Accounts extends APIResource {
5657
return this._client.getAPIList('/v1/accounts', CursorPage<Account>, { query, ...options });
5758
}
5859

60+
/**
61+
* Returns behavioral feature state derived from an account's transaction history.
62+
*
63+
* These signals expose the same data used by behavioral rule attributes (e.g.
64+
* `AMOUNT_Z_SCORE` with `scope: ACCOUNT`, `IS_NEW_COUNTRY` with `scope: ACCOUNT`)
65+
* and custom code `TRANSACTION_HISTORY_SIGNALS` features, allowing clients to
66+
* inspect feature values before writing rules and debug rule behavior.
67+
*
68+
* Note: 3DS fields are not available at the account scope and will be null.
69+
*
70+
* @example
71+
* ```ts
72+
* const signalsResponse =
73+
* await client.accounts.retrieveSignals(
74+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
75+
* );
76+
* ```
77+
*/
78+
retrieveSignals(accountToken: string, options?: RequestOptions): APIPromise<AuthRulesAPI.SignalsResponse> {
79+
return this._client.get(path`/v1/accounts/${accountToken}/signals`, options);
80+
}
81+
5982
/**
6083
* Get an Account's available spend limits, which is based on the spend limit
6184
* configured on the Account and the amount already spent over the spend limit's

src/resources/auth-rules/auth-rules.ts

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,216 @@ export class AuthRules extends APIResource {
4646
v2: V2API.V2 = new V2API.V2(this._client);
4747
}
4848

49+
/**
50+
* Behavioral feature state for a card or account derived from its transaction
51+
* history.
52+
*
53+
* Derived statistical features (averages, standard deviations, z-scores) are
54+
* computed using Welford's online algorithm over approved transactions. Average
55+
* fields are null when fewer than 5 approved transactions have been recorded.
56+
* Standard deviation fields are null when fewer than 30 approved transactions have
57+
* been recorded.
58+
*
59+
* 3DS fields (`three_ds_success_rate`, `three_ds_success_count`,
60+
* `three_ds_total_count`) are card-scoped and will be null for account responses.
61+
*
62+
* Raw fields (`seen_countries`, `seen_mccs`, `approved_txn_amount_m2`, etc.) are
63+
* included so clients can compute their own transaction-specific derivations, such
64+
* as checking whether a new transaction's country is in `seen_countries` to
65+
* determine `is_new_country`, or computing a z-score using the raw mean and M2
66+
* values.
67+
*/
68+
export interface SignalsResponse {
69+
/**
70+
* The Welford M2 accumulator for lifetime approved transaction amounts. Used
71+
* together with `avg_transaction_amount` and `approved_txn_count` to compute the
72+
* z-score of a new transaction amount (variance = M2 / (count - 1)).
73+
*/
74+
approved_txn_amount_m2: number | null;
75+
76+
/**
77+
* The Welford M2 accumulator for approved transaction amounts over the last 30
78+
* days.
79+
*/
80+
approved_txn_amount_m2_30d: number | null;
81+
82+
/**
83+
* The Welford M2 accumulator for approved transaction amounts over the last 7
84+
* days.
85+
*/
86+
approved_txn_amount_m2_7d: number | null;
87+
88+
/**
89+
* The Welford M2 accumulator for approved transaction amounts over the last 90
90+
* days.
91+
*/
92+
approved_txn_amount_m2_90d: number | null;
93+
94+
/**
95+
* The total number of approved transactions over the entity's lifetime.
96+
*/
97+
approved_txn_count: number | null;
98+
99+
/**
100+
* The number of approved transactions in the last 30 days.
101+
*/
102+
approved_txn_count_30d: number | null;
103+
104+
/**
105+
* The number of approved transactions in the last 7 days.
106+
*/
107+
approved_txn_count_7d: number | null;
108+
109+
/**
110+
* The number of approved transactions in the last 90 days.
111+
*/
112+
approved_txn_count_90d: number | null;
113+
114+
/**
115+
* The average approved transaction amount over the entity's lifetime, in cents.
116+
* Null if fewer than 5 approved transactions have been recorded.
117+
*/
118+
avg_transaction_amount: number | null;
119+
120+
/**
121+
* The average approved transaction amount over the last 30 days, in cents. Null if
122+
* fewer than 5 approved transactions in window.
123+
*/
124+
avg_transaction_amount_30d: number | null;
125+
126+
/**
127+
* The average approved transaction amount over the last 7 days, in cents. Null if
128+
* fewer than 5 approved transactions in window.
129+
*/
130+
avg_transaction_amount_7d: number | null;
131+
132+
/**
133+
* The average approved transaction amount over the last 90 days, in cents. Null if
134+
* fewer than 5 approved transactions in window.
135+
*/
136+
avg_transaction_amount_90d: number | null;
137+
138+
/**
139+
* The number of distinct merchant countries seen in the entity's transaction
140+
* history.
141+
*/
142+
distinct_country_count: number | null;
143+
144+
/**
145+
* The number of distinct MCCs seen in the entity's transaction history.
146+
*/
147+
distinct_mcc_count: number | null;
148+
149+
/**
150+
* The timestamp of the first approved transaction for the entity, in ISO 8601
151+
* format.
152+
*/
153+
first_txn_at: string | null;
154+
155+
/**
156+
* Whether the entity has no prior transaction history. Returns true if no history
157+
* is found. Null if transaction history exists but a first transaction timestamp
158+
* is unavailable.
159+
*/
160+
is_first_transaction: boolean | null;
161+
162+
/**
163+
* The merchant country of the last card-present transaction.
164+
*/
165+
last_cp_country: string | null;
166+
167+
/**
168+
* The merchant postal code of the last card-present transaction.
169+
*/
170+
last_cp_postal_code: string | null;
171+
172+
/**
173+
* The timestamp of the last card-present transaction, in ISO 8601 format.
174+
*/
175+
last_cp_timestamp: string | null;
176+
177+
/**
178+
* The timestamp of the most recent approved transaction for the entity, in ISO
179+
* 8601 format.
180+
*/
181+
last_txn_approved_at: string | null;
182+
183+
/**
184+
* The set of merchant countries seen in the entity's transaction history. Clients
185+
* can use this to determine whether a new transaction's country is novel (i.e.
186+
* compute `is_new_country`).
187+
*/
188+
seen_countries: Array<string> | null;
189+
190+
/**
191+
* The set of MCCs seen in the entity's transaction history. Clients can use this
192+
* to determine whether a new transaction's MCC is novel (i.e. compute
193+
* `is_new_mcc`).
194+
*/
195+
seen_mccs: Array<string> | null;
196+
197+
/**
198+
* The set of card acceptor IDs seen in the card's approved transaction history,
199+
* capped at the 1000 most recently seen. Null for account responses. Clients can
200+
* use this to determine whether a new transaction's merchant is novel (i.e.
201+
* compute `is_new_merchant`).
202+
*/
203+
seen_merchants: Array<string> | null;
204+
205+
/**
206+
* The standard deviation of approved transaction amounts over the entity's
207+
* lifetime, in cents. Null if fewer than 30 approved transactions have been
208+
* recorded.
209+
*/
210+
stdev_transaction_amount: number | null;
211+
212+
/**
213+
* The standard deviation of approved transaction amounts over the last 30 days, in
214+
* cents. Null if fewer than 30 approved transactions in window.
215+
*/
216+
stdev_transaction_amount_30d: number | null;
217+
218+
/**
219+
* The standard deviation of approved transaction amounts over the last 7 days, in
220+
* cents. Null if fewer than 30 approved transactions in window.
221+
*/
222+
stdev_transaction_amount_7d: number | null;
223+
224+
/**
225+
* The standard deviation of approved transaction amounts over the last 90 days, in
226+
* cents. Null if fewer than 30 approved transactions in window.
227+
*/
228+
stdev_transaction_amount_90d: number | null;
229+
230+
/**
231+
* The number of successful 3DS authentications for the card. Null for account
232+
* responses.
233+
*/
234+
three_ds_success_count: number | null;
235+
236+
/**
237+
* The 3DS authentication success rate for the card, as a percentage from 0.0 to
238+
* 100.0. Null for account responses.
239+
*/
240+
three_ds_success_rate: number | null;
241+
242+
/**
243+
* The total number of 3DS authentication attempts for the card. Null for account
244+
* responses.
245+
*/
246+
three_ds_total_count: number | null;
247+
248+
/**
249+
* The number of days since the last approved transaction on the entity.
250+
*/
251+
time_since_last_transaction_days: number | null;
252+
}
253+
49254
AuthRules.V2 = V2;
50255

51256
export declare namespace AuthRules {
257+
export { type SignalsResponse as SignalsResponse };
258+
52259
export {
53260
V2 as V2,
54261
type AuthRule as AuthRule,

src/resources/auth-rules/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
export { AuthRules } from './auth-rules';
3+
export { AuthRules, type SignalsResponse } from './auth-rules';
44
export {
55
V2,
66
type AuthRule,

src/resources/cards/cards.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { APIResource } from '../../core/resource';
44
import * as Shared from '../shared';
5+
import * as AuthRulesAPI from '../auth-rules/auth-rules';
56
import * as BalancesAPI from './balances';
67
import { BalanceListParams, Balances } from './balances';
78
import * as FinancialTransactionsAPI from './financial-transactions';
@@ -352,6 +353,25 @@ export class Cards extends APIResource {
352353
return this._client.post(path`/v1/cards/${cardToken}/renew`, { body, ...options });
353354
}
354355

356+
/**
357+
* Returns behavioral feature state derived from a card's transaction history.
358+
*
359+
* These signals expose the same data used by behavioral rule attributes (e.g.
360+
* `AMOUNT_Z_SCORE` with `scope: CARD`, `IS_NEW_COUNTRY` with `scope: CARD`) and
361+
* custom code `TRANSACTION_HISTORY_SIGNALS` features, allowing clients to inspect
362+
* feature values before writing rules and debug rule behavior.
363+
*
364+
* @example
365+
* ```ts
366+
* const signalsResponse = await client.cards.retrieveSignals(
367+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
368+
* );
369+
* ```
370+
*/
371+
retrieveSignals(cardToken: string, options?: RequestOptions): APIPromise<AuthRulesAPI.SignalsResponse> {
372+
return this._client.get(path`/v1/cards/${cardToken}/signals`, options);
373+
}
374+
355375
/**
356376
* Get a Card's available spend limit, which is based on the spend limit configured
357377
* on the Card and the amount already spent over the spend limit's duration. For

0 commit comments

Comments
 (0)