@kvant-dev/nordnet 0.0.0-stage → 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/README.md +54 -2
- package/dist/accounts/accounts-client.d.ts +57 -0
- package/dist/accounts/accounts-client.d.ts.map +1 -0
- package/dist/accounts/accounts-client.js +28 -0
- package/dist/accounts/accounts-client.js.map +1 -0
- package/dist/alerts/alerts-client.d.ts +13 -0
- package/dist/alerts/alerts-client.d.ts.map +1 -0
- package/dist/alerts/alerts-client.js +16 -0
- package/dist/alerts/alerts-client.js.map +1 -0
- package/dist/auth/auth-client.d.ts +58 -0
- package/dist/auth/auth-client.d.ts.map +1 -0
- package/dist/auth/auth-client.js +154 -0
- package/dist/auth/auth-client.js.map +1 -0
- package/dist/auth/session.d.ts +24 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +2 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/client.d.ts +40 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +64 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +56 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/instruments/instruments-client.d.ts +41 -0
- package/dist/instruments/instruments-client.d.ts.map +1 -0
- package/dist/instruments/instruments-client.js +29 -0
- package/dist/instruments/instruments-client.js.map +1 -0
- package/dist/internal/amounts.d.ts +18 -0
- package/dist/internal/amounts.d.ts.map +1 -0
- package/dist/internal/amounts.js +2 -0
- package/dist/internal/amounts.js.map +1 -0
- package/dist/internal/client-context.d.ts +14 -0
- package/dist/internal/client-context.d.ts.map +1 -0
- package/dist/internal/client-context.js +6 -0
- package/dist/internal/client-context.js.map +1 -0
- package/dist/internal/cookie-store.d.ts +11 -0
- package/dist/internal/cookie-store.d.ts.map +1 -0
- package/dist/internal/cookie-store.js +47 -0
- package/dist/internal/cookie-store.js.map +1 -0
- package/dist/internal/http-client.d.ts +35 -0
- package/dist/internal/http-client.d.ts.map +1 -0
- package/dist/internal/http-client.js +159 -0
- package/dist/internal/http-client.js.map +1 -0
- package/dist/market/market-client.d.ts +264 -0
- package/dist/market/market-client.d.ts.map +1 -0
- package/dist/market/market-client.js +117 -0
- package/dist/market/market-client.js.map +1 -0
- package/dist/orders/orders-client.d.ts +15 -0
- package/dist/orders/orders-client.d.ts.map +1 -0
- package/dist/orders/orders-client.js +30 -0
- package/dist/orders/orders-client.js.map +1 -0
- package/dist/performance/performance-client.d.ts +74 -0
- package/dist/performance/performance-client.d.ts.map +1 -0
- package/dist/performance/performance-client.js +46 -0
- package/dist/performance/performance-client.js.map +1 -0
- package/dist/positions/positions-client.d.ts +68 -0
- package/dist/positions/positions-client.d.ts.map +1 -0
- package/dist/positions/positions-client.js +26 -0
- package/dist/positions/positions-client.js.map +1 -0
- package/dist/transactions/transactions-client.d.ts +51 -0
- package/dist/transactions/transactions-client.d.ts.map +1 -0
- package/dist/transactions/transactions-client.js +27 -0
- package/dist/transactions/transactions-client.js.map +1 -0
- package/dist/watchlists/watchlists-client.d.ts +23 -0
- package/dist/watchlists/watchlists-client.d.ts.map +1 -0
- package/dist/watchlists/watchlists-client.js +26 -0
- package/dist/watchlists/watchlists-client.js.map +1 -0
- package/package.json +37 -3
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kvant-dev/nordnet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unofficial, ESM-first TypeScript SDK for the web API behind nordnet.se: the same calls Nordnet's
|
|
4
|
+
own web app makes, not the official External API.
|
|
5
|
+
|
|
6
|
+
**Documentation:** [Getting started](https://antewall.github.io/kvant-tools/docs/nordnet/getting-started) · [Authentication](https://antewall.github.io/kvant-tools/docs/nordnet/authentication) · [API reference](https://antewall.github.io/kvant-tools/docs/nordnet/reference)
|
|
7
|
+
|
|
8
|
+
## Disclaimer
|
|
9
|
+
|
|
10
|
+
This SDK is not affiliated with Nordnet Bank AB. The API is undocumented and can change or
|
|
11
|
+
disappear without warning. The author is not responsible for any damages from using it.
|
|
12
|
+
|
|
13
|
+
## Login
|
|
14
|
+
|
|
15
|
+
Nordnet's web API sits on two hosts. `www.nordnet.se` (`/api/2`, `/nnxapi`) authenticates with
|
|
16
|
+
session cookies. `api.prod.nntech.io` takes short-lived bearer tokens that the client mints from
|
|
17
|
+
that session. A `NordnetSession` is just those cookies, so persist `client.session` after calls.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { NordnetClient } from '@kvant-dev/nordnet';
|
|
21
|
+
|
|
22
|
+
const client = new NordnetClient();
|
|
23
|
+
const attempt = await client.auth.startBankId();
|
|
24
|
+
for (;;) {
|
|
25
|
+
render(attempt.challenge.qrPayload); // a new QR code every poll
|
|
26
|
+
await new Promise((r) => setTimeout(r, attempt.challenge.refreshAfterMs));
|
|
27
|
+
const result = await attempt.poll();
|
|
28
|
+
if (result.status === 'pending') continue;
|
|
29
|
+
if (result.status !== 'complete') throw new Error(result.status);
|
|
30
|
+
save(result.session);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Later: `new NordnetClient({ session })`, then `await client.auth.validateSession()`.
|
|
36
|
+
|
|
37
|
+
## Calls
|
|
38
|
+
|
|
39
|
+
| Client | Calls |
|
|
40
|
+
| -------------- | -------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `accounts` | `list()`, `info(accids)` |
|
|
42
|
+
| `positions` | `list(accountIds)`, `ownCapital(accountIds)` |
|
|
43
|
+
| `performance` | `graph(accountIds, range)`, `development(accountIds, period)`, `riskMetrics`, `returnsByYear` |
|
|
44
|
+
| `transactions` | `page({ accountIds, fromDate, toDate, … })` |
|
|
45
|
+
| `watchlists` | `list()`, `get(id)` |
|
|
46
|
+
| `alerts` | `priceAlarms()` |
|
|
47
|
+
| `orders` | `list()`, `trades()` |
|
|
48
|
+
| `instruments` | `get(ids)`, `byIsin(isin, currency, marketId)` |
|
|
49
|
+
| `market` | `search(query)`, `prices(ids)`, `series(id, period)`, `news(id)`, `dividends(id)`, company data, … |
|
|
50
|
+
|
|
51
|
+
Legacy calls take an account's integer `accid`; cloud calls take its UUID `account_id`. Both
|
|
52
|
+
come from `accounts.list()`.
|
|
53
|
+
|
|
54
|
+
Not verified yet: the item shapes of positions, transactions, orders, trades, alarms and a
|
|
55
|
+
watchlist's contents. Their types come from nordnet.se's frontend code, not a recorded response.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NordnetLegacyAmount } from '../internal/amounts.js';
|
|
2
|
+
import type { ClientContext } from '../internal/client-context.js';
|
|
3
|
+
export interface NordnetAccount {
|
|
4
|
+
/** The integer id the legacy `/api/2` endpoints take. */
|
|
5
|
+
readonly accid: number;
|
|
6
|
+
/** The account number shown to the user. */
|
|
7
|
+
readonly accno: number;
|
|
8
|
+
/** The UUID the cloud endpoints take as `accountIds`. */
|
|
9
|
+
readonly account_id: string;
|
|
10
|
+
readonly account_code: string;
|
|
11
|
+
readonly alias?: string;
|
|
12
|
+
/** Nordnet's account type id. */
|
|
13
|
+
readonly atyid: number;
|
|
14
|
+
readonly bank_accno?: string;
|
|
15
|
+
readonly default?: boolean;
|
|
16
|
+
readonly role: string;
|
|
17
|
+
/** Short type code, e.g. `AF`, `ISK`, `KF`. */
|
|
18
|
+
readonly symbol: string;
|
|
19
|
+
/** Type name in the session's language, e.g. `Investeringssparkonto`. */
|
|
20
|
+
readonly type: string;
|
|
21
|
+
}
|
|
22
|
+
export interface NordnetAccountInfo {
|
|
23
|
+
readonly accid: number;
|
|
24
|
+
readonly accno: number;
|
|
25
|
+
readonly account_code: string;
|
|
26
|
+
readonly account_credit: NordnetLegacyAmount;
|
|
27
|
+
readonly account_currency: string;
|
|
28
|
+
/** Cash. */
|
|
29
|
+
readonly account_sum: NordnetLegacyAmount;
|
|
30
|
+
readonly bank_accno?: string;
|
|
31
|
+
readonly buy_orders_value: NordnetLegacyAmount;
|
|
32
|
+
readonly collateral: NordnetLegacyAmount;
|
|
33
|
+
readonly equity: NordnetLegacyAmount;
|
|
34
|
+
readonly forward_sum: NordnetLegacyAmount;
|
|
35
|
+
readonly full_marketvalue: NordnetLegacyAmount;
|
|
36
|
+
readonly future_sum: NordnetLegacyAmount;
|
|
37
|
+
readonly interest: NordnetLegacyAmount;
|
|
38
|
+
readonly interest_rate?: number;
|
|
39
|
+
readonly loan_limit: NordnetLegacyAmount;
|
|
40
|
+
readonly own_capital: NordnetLegacyAmount;
|
|
41
|
+
readonly own_capital_morning: NordnetLegacyAmount;
|
|
42
|
+
readonly pawn_value: NordnetLegacyAmount;
|
|
43
|
+
readonly registration_date?: string;
|
|
44
|
+
readonly reserved?: Readonly<Record<string, NordnetLegacyAmount>>;
|
|
45
|
+
readonly short_positions_margin: NordnetLegacyAmount;
|
|
46
|
+
/** Buying power. */
|
|
47
|
+
readonly trading_power: NordnetLegacyAmount;
|
|
48
|
+
readonly unrealized_future_profit_loss: NordnetLegacyAmount;
|
|
49
|
+
}
|
|
50
|
+
export declare class AccountsClient {
|
|
51
|
+
private readonly context;
|
|
52
|
+
constructor(context: ClientContext);
|
|
53
|
+
list(signal?: AbortSignal): Promise<readonly NordnetAccount[]>;
|
|
54
|
+
/** Cash, buying power and value for each account, by legacy `accid`. */
|
|
55
|
+
info(accids: readonly number[], signal?: AbortSignal): Promise<readonly NordnetAccountInfo[]>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=accounts-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts-client.d.ts","sourceRoot":"","sources":["../../src/accounts/accounts-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,M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C;IAC/C,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IACvC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAClD,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAClE,QAAQ,CAAC,sBAAsB,EAAE,mBAAmB,CAAC;IACrD,oBAAoB;IACpB,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAAC;IAC5C,QAAQ,CAAC,6BAA6B,EAAE,mBAAmB,CAAC;CAC7D;AAED,qBAAa,cAAc;IACN,OAAO,CAAC,QAAQ,CAAC,OAAO;IAA3C,YAAoC,OAAO,EAAE,aAAa,EAAI;IAEvD,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAQpE;IAED,wEAAwE;IACjE,IAAI,CACT,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,SAAS,kBAAkB,EAAE,CAAC,CASxC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class AccountsClient {
|
|
2
|
+
context;
|
|
3
|
+
constructor(context) {
|
|
4
|
+
this.context = context;
|
|
5
|
+
}
|
|
6
|
+
list(signal) {
|
|
7
|
+
return this.context.http.request({
|
|
8
|
+
access: 'required',
|
|
9
|
+
host: 'web',
|
|
10
|
+
method: 'GET',
|
|
11
|
+
path: '/api/2/accounts',
|
|
12
|
+
signal,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** Cash, buying power and value for each account, by legacy `accid`. */
|
|
16
|
+
info(accids, signal) {
|
|
17
|
+
if (accids.length === 0)
|
|
18
|
+
return Promise.resolve([]);
|
|
19
|
+
return this.context.http.request({
|
|
20
|
+
access: 'required',
|
|
21
|
+
host: 'web',
|
|
22
|
+
method: 'GET',
|
|
23
|
+
path: `/api/2/accounts/${accids.join(',')}/info`,
|
|
24
|
+
signal,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=accounts-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts-client.js","sourceRoot":"","sources":["../../src/accounts/accounts-client.ts"],"names":[],"mappings":"AAoDA,MAAM,OAAO,cAAc;IACW,OAAO;IAA3C,YAAoC,OAAsB;uBAAtB,OAAO;IAAkB,CAAC;IAEvD,IAAI,CAAC,MAAoB;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/B,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,iBAAiB;YACvB,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,wEAAwE;IACjE,IAAI,CACT,MAAyB,EACzB,MAAoB;QAEpB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/B,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,mBAAmB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO;YAChD,MAAM;SACP,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClientContext } from '../internal/client-context.js';
|
|
2
|
+
export interface NordnetPriceAlarms {
|
|
3
|
+
/** The alarm shape hasn't been captured yet, hence `unknown` values. */
|
|
4
|
+
readonly results: readonly Readonly<Record<string, unknown>>[];
|
|
5
|
+
readonly rows: number;
|
|
6
|
+
readonly total_hits: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class AlertsClient {
|
|
9
|
+
private readonly context;
|
|
10
|
+
constructor(context: ClientContext);
|
|
11
|
+
priceAlarms(signal?: AbortSignal): Promise<NordnetPriceAlarms>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=alerts-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alerts-client.d.ts","sourceRoot":"","sources":["../../src/alerts/alerts-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,qBAAa,YAAY;IACJ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAA3C,YAAoC,OAAO,EAAE,aAAa,EAAI;IAEvD,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAQpE;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class AlertsClient {
|
|
2
|
+
context;
|
|
3
|
+
constructor(context) {
|
|
4
|
+
this.context = context;
|
|
5
|
+
}
|
|
6
|
+
priceAlarms(signal) {
|
|
7
|
+
return this.context.http.request({
|
|
8
|
+
access: 'required',
|
|
9
|
+
host: 'web',
|
|
10
|
+
method: 'GET',
|
|
11
|
+
path: '/api/2/price_alarms/alarms',
|
|
12
|
+
signal,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=alerts-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alerts-client.js","sourceRoot":"","sources":["../../src/alerts/alerts-client.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,YAAY;IACa,OAAO;IAA3C,YAAoC,OAAsB;uBAAtB,OAAO;IAAkB,CAAC;IAEvD,WAAW,CAAC,MAAoB;QACrC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/B,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,4BAA4B;YAClC,MAAM;SACP,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ClientContext } from '../internal/client-context.js';
|
|
2
|
+
import type { NordnetSession } from './session.js';
|
|
3
|
+
export interface BankIdChallenge {
|
|
4
|
+
/** Render as a QR code; it changes every poll. */
|
|
5
|
+
readonly qrPayload: string;
|
|
6
|
+
readonly refreshAfterMs: number;
|
|
7
|
+
}
|
|
8
|
+
export type BankIdPollResult = {
|
|
9
|
+
readonly challenge: BankIdChallenge;
|
|
10
|
+
readonly status: 'pending';
|
|
11
|
+
} | {
|
|
12
|
+
readonly session: NordnetSession;
|
|
13
|
+
readonly status: 'complete';
|
|
14
|
+
} | {
|
|
15
|
+
readonly status: 'denied';
|
|
16
|
+
} | {
|
|
17
|
+
readonly status: 'expired';
|
|
18
|
+
};
|
|
19
|
+
export interface BankIdOrder {
|
|
20
|
+
readonly hintCode?: string;
|
|
21
|
+
readonly orderReference: string;
|
|
22
|
+
readonly qrData?: string;
|
|
23
|
+
/** `PENDING`, `COMPLETE` or `FAILED`. */
|
|
24
|
+
readonly status: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionCreated {
|
|
27
|
+
readonly authenticationMethod: string;
|
|
28
|
+
readonly countryCode: string;
|
|
29
|
+
readonly customerId: string;
|
|
30
|
+
readonly scopes: readonly string[];
|
|
31
|
+
readonly sessionReference: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SessionVerification {
|
|
34
|
+
readonly hasOnpremSession: boolean;
|
|
35
|
+
readonly onpremCsrfToken?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare class AuthClient {
|
|
38
|
+
private readonly context;
|
|
39
|
+
constructor(context: ClientContext);
|
|
40
|
+
/** Starts a BankID QR login. Show `attempt.challenge`, then `poll()` until it is no longer pending. */
|
|
41
|
+
startBankId(signal?: AbortSignal): Promise<BankIdAuthAttempt>;
|
|
42
|
+
/** Whether the stored session is still logged in. */
|
|
43
|
+
validateSession(signal?: AbortSignal): Promise<boolean>;
|
|
44
|
+
/** Ends the session at Nordnet, then drops it locally. */
|
|
45
|
+
logout(signal?: AbortSignal): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare class BankIdAuthAttempt {
|
|
48
|
+
#private;
|
|
49
|
+
private readonly context;
|
|
50
|
+
private readonly orderReference;
|
|
51
|
+
private readonly signal;
|
|
52
|
+
private constructor();
|
|
53
|
+
get challenge(): BankIdChallenge;
|
|
54
|
+
static start(context: ClientContext, signal?: AbortSignal): Promise<BankIdAuthAttempt>;
|
|
55
|
+
poll(): Promise<BankIdPollResult>;
|
|
56
|
+
cancel(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=auth-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-client.d.ts","sourceRoot":"","sources":["../../src/auth/auth-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AASnD,MAAM,WAAW,eAAe;IAC9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AO,CAAC,iBAAiB,CAAC,CAEnE;IAED,qDAAqD;IACxC,eAAe,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBnE;IAED,0DAA0D;IAC7C,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAavD;CACF;AAED,qBAAa,iBAAiB;;IAM1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAE/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,eAON;IAED,IAAW,SAAS,IAAI,eAAe,CAEtC;IAED,OAAoB,KAAK,CACvB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAiB5B;IAEY,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAoB7C;IAGM,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAG7B;CA6BF"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { NordnetAuthenticationError, NordnetHttpError } from '../errors.js';
|
|
2
|
+
const BANKID_ORDERS_PATH = '/authentication/v1/methods/swedish-bankid/authentication-orders';
|
|
3
|
+
const SESSIONS_PATH = '/nnxapi/authentication/v2/sessions';
|
|
4
|
+
const LEGACY_LOGIN_PATH = '/api/2/authentication/nnx-session/login';
|
|
5
|
+
const CURRENT_SESSION_PATH = '/nnxapi/authentication/v1/sessions/current';
|
|
6
|
+
/** nordnet.se polls the order about once a second; each poll carries the next animated QR code. */
|
|
7
|
+
const REFRESH_AFTER_MS = 1_000;
|
|
8
|
+
export class AuthClient {
|
|
9
|
+
context;
|
|
10
|
+
constructor(context) {
|
|
11
|
+
this.context = context;
|
|
12
|
+
}
|
|
13
|
+
/** Starts a BankID QR login. Show `attempt.challenge`, then `poll()` until it is no longer pending. */
|
|
14
|
+
startBankId(signal) {
|
|
15
|
+
return BankIdAuthAttempt.start(this.context, signal);
|
|
16
|
+
}
|
|
17
|
+
/** Whether the stored session is still logged in. */
|
|
18
|
+
async validateSession(signal) {
|
|
19
|
+
try {
|
|
20
|
+
const body = await this.context.http.request({
|
|
21
|
+
access: 'required',
|
|
22
|
+
host: 'web',
|
|
23
|
+
method: 'GET',
|
|
24
|
+
path: `${SESSIONS_PATH}/verify`,
|
|
25
|
+
signal,
|
|
26
|
+
});
|
|
27
|
+
return body.hasOnpremSession;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof NordnetHttpError && (error.status === 401 || error.status === 403)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Ends the session at Nordnet, then drops it locally. */
|
|
37
|
+
async logout(signal) {
|
|
38
|
+
try {
|
|
39
|
+
await this.context.http.request({
|
|
40
|
+
access: 'required',
|
|
41
|
+
host: 'web',
|
|
42
|
+
method: 'DELETE',
|
|
43
|
+
path: CURRENT_SESSION_PATH,
|
|
44
|
+
signal,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
this.context.session.clear();
|
|
49
|
+
this.context.http.resetCookies();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class BankIdAuthAttempt {
|
|
54
|
+
context;
|
|
55
|
+
orderReference;
|
|
56
|
+
signal;
|
|
57
|
+
#cancelled = false;
|
|
58
|
+
#challenge;
|
|
59
|
+
#terminal = false;
|
|
60
|
+
constructor(context, orderReference, challenge, signal) {
|
|
61
|
+
this.context = context;
|
|
62
|
+
this.orderReference = orderReference;
|
|
63
|
+
this.signal = signal;
|
|
64
|
+
this.#challenge = challenge;
|
|
65
|
+
}
|
|
66
|
+
get challenge() {
|
|
67
|
+
return this.#challenge;
|
|
68
|
+
}
|
|
69
|
+
static async start(context, signal) {
|
|
70
|
+
context.session.clear();
|
|
71
|
+
context.http.resetCookies();
|
|
72
|
+
const { orderReference } = await context.http.request({
|
|
73
|
+
access: 'anonymous',
|
|
74
|
+
host: 'api',
|
|
75
|
+
method: 'POST',
|
|
76
|
+
path: BANKID_ORDERS_PATH,
|
|
77
|
+
query: { useCase: 'QR' },
|
|
78
|
+
signal,
|
|
79
|
+
});
|
|
80
|
+
if (typeof orderReference !== 'string')
|
|
81
|
+
throw new NordnetAuthenticationError('malformed_response');
|
|
82
|
+
// The order only carries QR data once polled.
|
|
83
|
+
const order = await getOrder(context, orderReference, signal);
|
|
84
|
+
if (order.qrData === undefined)
|
|
85
|
+
throw new NordnetAuthenticationError('malformed_response');
|
|
86
|
+
return new BankIdAuthAttempt(context, orderReference, toChallenge(order.qrData), signal);
|
|
87
|
+
}
|
|
88
|
+
async poll() {
|
|
89
|
+
if (this.#cancelled)
|
|
90
|
+
throw new NordnetAuthenticationError('cancelled');
|
|
91
|
+
if (this.#terminal)
|
|
92
|
+
throw new NordnetAuthenticationError('protocol');
|
|
93
|
+
const order = await getOrder(this.context, this.orderReference, this.signal);
|
|
94
|
+
if (order.status === 'PENDING') {
|
|
95
|
+
// While the user signs in the app there is no QR code; keep showing the last one.
|
|
96
|
+
if (order.qrData !== undefined)
|
|
97
|
+
this.#challenge = toChallenge(order.qrData);
|
|
98
|
+
return { challenge: this.#challenge, status: 'pending' };
|
|
99
|
+
}
|
|
100
|
+
this.#terminal = true;
|
|
101
|
+
if (order.status === 'COMPLETE')
|
|
102
|
+
return { session: await this.#createSession(), status: 'complete' };
|
|
103
|
+
return {
|
|
104
|
+
status: order.hintCode === 'expiredTransaction' || order.hintCode === 'startFailed'
|
|
105
|
+
? 'expired'
|
|
106
|
+
: 'denied',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// ponytail: no cancel endpoint found in nordnet.se's bundle; the order simply expires at BankID.
|
|
110
|
+
cancel() {
|
|
111
|
+
this.#cancelled = true;
|
|
112
|
+
return Promise.resolve();
|
|
113
|
+
}
|
|
114
|
+
async #createSession() {
|
|
115
|
+
const { http } = this.context;
|
|
116
|
+
const created = await http.request({
|
|
117
|
+
access: 'anonymous',
|
|
118
|
+
body: {
|
|
119
|
+
authenticationProvider: 'SWEDISH_BANKID',
|
|
120
|
+
countryCode: 'SE',
|
|
121
|
+
swedishBankId: { orderReference: this.orderReference },
|
|
122
|
+
},
|
|
123
|
+
host: 'web',
|
|
124
|
+
method: 'POST',
|
|
125
|
+
path: SESSIONS_PATH,
|
|
126
|
+
signal: this.signal,
|
|
127
|
+
});
|
|
128
|
+
// The legacy /api/2 endpoints need their own session on top of the new one.
|
|
129
|
+
await http.request({
|
|
130
|
+
access: 'anonymous',
|
|
131
|
+
body: {},
|
|
132
|
+
host: 'web',
|
|
133
|
+
method: 'POST',
|
|
134
|
+
path: LEGACY_LOGIN_PATH,
|
|
135
|
+
signal: this.signal,
|
|
136
|
+
});
|
|
137
|
+
const session = { cookies: http.cookies, customerId: created.customerId };
|
|
138
|
+
this.context.session.set(session);
|
|
139
|
+
return session;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function getOrder(context, orderReference, signal) {
|
|
143
|
+
return context.http.request({
|
|
144
|
+
access: 'anonymous',
|
|
145
|
+
host: 'api',
|
|
146
|
+
method: 'GET',
|
|
147
|
+
path: `${BANKID_ORDERS_PATH}/${encodeURIComponent(orderReference)}`,
|
|
148
|
+
signal,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function toChallenge(qrPayload) {
|
|
152
|
+
return { qrPayload, refreshAfterMs: REFRESH_AFTER_MS };
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=auth-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-client.js","sourceRoot":"","sources":["../../src/auth/auth-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAI5E,MAAM,kBAAkB,GAAG,iEAAiE,CAAC;AA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CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A tough-cookie serialized cookie for www.nordnet.se. */
|
|
2
|
+
export interface NordnetCookie {
|
|
3
|
+
readonly creation?: string;
|
|
4
|
+
readonly domain?: string;
|
|
5
|
+
readonly expires?: string;
|
|
6
|
+
readonly extensions?: readonly string[];
|
|
7
|
+
readonly hostOnly?: boolean;
|
|
8
|
+
readonly httpOnly?: boolean;
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly lastAccessed?: string;
|
|
11
|
+
readonly maxAge?: number | string;
|
|
12
|
+
readonly path?: string;
|
|
13
|
+
readonly pathIsDefault?: boolean;
|
|
14
|
+
readonly sameSite?: string;
|
|
15
|
+
readonly secure?: boolean;
|
|
16
|
+
readonly value: string;
|
|
17
|
+
}
|
|
18
|
+
/** Everything needed to resume a login: the www.nordnet.se cookies. API tokens are fetched from them. */
|
|
19
|
+
export interface NordnetSession {
|
|
20
|
+
readonly cookies: readonly NordnetCookie[];
|
|
21
|
+
/** Nordnet's customer UUID, from the BankID login. */
|
|
22
|
+
readonly customerId?: string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/auth/session.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,yGAAyG;AACzG,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAC3C,sDAAsD;IACtD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/auth/session.ts"],"names":[],"mappings":""}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AccountsClient } from './accounts/accounts-client.js';
|
|
2
|
+
import { AlertsClient } from './alerts/alerts-client.js';
|
|
3
|
+
import { AuthClient } from './auth/auth-client.js';
|
|
4
|
+
import type { NordnetSession } from './auth/session.js';
|
|
5
|
+
import { InstrumentsClient } from './instruments/instruments-client.js';
|
|
6
|
+
import { MarketClient } from './market/market-client.js';
|
|
7
|
+
import { OrdersClient } from './orders/orders-client.js';
|
|
8
|
+
import { PerformanceClient } from './performance/performance-client.js';
|
|
9
|
+
import { PositionsClient } from './positions/positions-client.js';
|
|
10
|
+
import { TransactionsClient } from './transactions/transactions-client.js';
|
|
11
|
+
import { WatchlistsClient } from './watchlists/watchlists-client.js';
|
|
12
|
+
export interface NordnetClientOptions {
|
|
13
|
+
/** Nordnet's cloud API. Defaults to `https://api.prod.nntech.io`. */
|
|
14
|
+
readonly apiBaseUrl?: string;
|
|
15
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
16
|
+
/** Sent as `x-locale`; decides the language of type names. Defaults to `sv-SE`. */
|
|
17
|
+
readonly locale?: string;
|
|
18
|
+
readonly session?: NordnetSession;
|
|
19
|
+
/** Defaults to `https://www.nordnet.se`. */
|
|
20
|
+
readonly webBaseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class NordnetClient {
|
|
23
|
+
#private;
|
|
24
|
+
readonly accounts: AccountsClient;
|
|
25
|
+
readonly alerts: AlertsClient;
|
|
26
|
+
readonly auth: AuthClient;
|
|
27
|
+
readonly instruments: InstrumentsClient;
|
|
28
|
+
readonly market: MarketClient;
|
|
29
|
+
readonly orders: OrdersClient;
|
|
30
|
+
readonly performance: PerformanceClient;
|
|
31
|
+
readonly positions: PositionsClient;
|
|
32
|
+
readonly transactions: TransactionsClient;
|
|
33
|
+
readonly watchlists: WatchlistsClient;
|
|
34
|
+
constructor(options?: NordnetClientOptions);
|
|
35
|
+
/** The current session; changes as Nordnet refreshes its cookies, so persist it after calls. */
|
|
36
|
+
get session(): NordnetSession | undefined;
|
|
37
|
+
setSession(session: NordnetSession): void;
|
|
38
|
+
clearSession(): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAA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+
import { AccountsClient } from './accounts/accounts-client.js';
|
|
2
|
+
import { AlertsClient } from './alerts/alerts-client.js';
|
|
3
|
+
import { AuthClient } from './auth/auth-client.js';
|
|
4
|
+
import { InstrumentsClient } from './instruments/instruments-client.js';
|
|
5
|
+
import { HttpClient } from './internal/http-client.js';
|
|
6
|
+
import { MarketClient } from './market/market-client.js';
|
|
7
|
+
import { OrdersClient } from './orders/orders-client.js';
|
|
8
|
+
import { PerformanceClient } from './performance/performance-client.js';
|
|
9
|
+
import { PositionsClient } from './positions/positions-client.js';
|
|
10
|
+
import { TransactionsClient } from './transactions/transactions-client.js';
|
|
11
|
+
import { WatchlistsClient } from './watchlists/watchlists-client.js';
|
|
12
|
+
export class NordnetClient {
|
|
13
|
+
#session;
|
|
14
|
+
accounts;
|
|
15
|
+
alerts;
|
|
16
|
+
auth;
|
|
17
|
+
instruments;
|
|
18
|
+
market;
|
|
19
|
+
orders;
|
|
20
|
+
performance;
|
|
21
|
+
positions;
|
|
22
|
+
transactions;
|
|
23
|
+
watchlists;
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
this.#session = options.session;
|
|
26
|
+
const http = new HttpClient({
|
|
27
|
+
...(options.apiBaseUrl === undefined ? {} : { apiBaseUrl: options.apiBaseUrl }),
|
|
28
|
+
...(options.fetch === undefined ? {} : { fetch: options.fetch }),
|
|
29
|
+
...(options.locale === undefined ? {} : { locale: options.locale }),
|
|
30
|
+
...(options.webBaseUrl === undefined ? {} : { webBaseUrl: options.webBaseUrl }),
|
|
31
|
+
getSession: () => this.#session,
|
|
32
|
+
updateSession: (session) => this.setSession(session),
|
|
33
|
+
});
|
|
34
|
+
const context = {
|
|
35
|
+
http,
|
|
36
|
+
session: {
|
|
37
|
+
clear: () => this.clearSession(),
|
|
38
|
+
get: () => this.#session,
|
|
39
|
+
set: (session) => this.setSession(session),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
this.accounts = new AccountsClient(context);
|
|
43
|
+
this.alerts = new AlertsClient(context);
|
|
44
|
+
this.auth = new AuthClient(context);
|
|
45
|
+
this.instruments = new InstrumentsClient(context);
|
|
46
|
+
this.market = new MarketClient(context);
|
|
47
|
+
this.orders = new OrdersClient(context);
|
|
48
|
+
this.performance = new PerformanceClient(context);
|
|
49
|
+
this.positions = new PositionsClient(context);
|
|
50
|
+
this.transactions = new TransactionsClient(context);
|
|
51
|
+
this.watchlists = new WatchlistsClient(context);
|
|
52
|
+
}
|
|
53
|
+
/** The current session; changes as Nordnet refreshes its cookies, so persist it after calls. */
|
|
54
|
+
get session() {
|
|
55
|
+
return this.#session;
|
|
56
|
+
}
|
|
57
|
+
setSession(session) {
|
|
58
|
+
this.#session = session;
|
|
59
|
+
}
|
|
60
|
+
clearSession() {
|
|
61
|
+
this.#session = undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAarE,MAAM,OAAO,aAAa;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gBACxB,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;aAC3C;SACF,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,SAAS,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,gGAAgG;IAChG,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAEM,UAAU,CAAC,OAAuB;QACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,YAAY;QACjB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class NordnetError extends Error {
|
|
2
|
+
constructor(message: string, options?: ErrorOptions);
|
|
3
|
+
}
|
|
4
|
+
export declare class NordnetAuthenticationRequiredError extends NordnetError {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export type NordnetAuthenticationErrorCode = 'cancelled' | 'malformed_response' | 'protocol';
|
|
8
|
+
export declare class NordnetAuthenticationError extends NordnetError {
|
|
9
|
+
readonly code: NordnetAuthenticationErrorCode;
|
|
10
|
+
constructor(code: NordnetAuthenticationErrorCode, options?: ErrorOptions);
|
|
11
|
+
}
|
|
12
|
+
export interface NordnetHttpErrorOptions {
|
|
13
|
+
readonly body: unknown;
|
|
14
|
+
readonly method?: string;
|
|
15
|
+
readonly status: number;
|
|
16
|
+
readonly statusText: string;
|
|
17
|
+
readonly url: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class NordnetHttpError extends NordnetError {
|
|
20
|
+
readonly body: unknown;
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly statusText: string;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
constructor(options: NordnetHttpErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,YAAmB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAGzD;CACF;AAED,qBAAa,kCAAmC,SAAQ,YAAY;IAClE,cAEC;CACF;AAED,MAAM,MAAM,8BAA8B,GAAG,WAAW,GAAG,oBAAoB,GAAG,UAAU,CAAC;AAE7F,qBAAa,0BAA2B,SAAQ,YAAY;IAC1D,SAAgB,IAAI,EAAE,8BAA8B,CAAC;IAErD,YAAmB,IAAI,EAAE,8BAA8B,EAAE,OAAO,CAAC,EAAE,YAAY,EAG9E;CACF;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,SAAgB,IAAI,EAAE,OAAO,CAAC;IAC9B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,GAAG,EAAE,MAAM,CAAC;IAE5B,YAAmB,OAAO,EAAE,uBAAuB,EAalD;CACF"}
|