@iovdin/bunk 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/lib/auth.js +3 -65
  2. package/package.json +1 -1
package/lib/auth.js CHANGED
@@ -7,6 +7,7 @@ const crypto = require("crypto");
7
7
  const { Entry } = require("@napi-rs/keyring")
8
8
 
9
9
  const environment = 'production'
10
+ // const environment = 'sandbox'
10
11
 
11
12
  const domains = {
12
13
  sandbox: {
@@ -32,7 +33,7 @@ function getSecret(name) {
32
33
  }
33
34
 
34
35
  function setSecret(name, value) {
35
- new Entry(name, 'personal').setPassword(name, 'personal', value);
36
+ new Entry(name, 'personal').setPassword(value);
36
37
  }
37
38
 
38
39
 
@@ -104,66 +105,6 @@ function signBody(body, privateKey) {
104
105
  return signer.sign(privateKey, "base64");
105
106
  }
106
107
 
107
- /*
108
- async function createSession({ access_token }) {
109
- const res = await fetch(`https://${domains[environment].api}/v1/session-server`, {
110
- method: 'POST',
111
- headers: {
112
- 'Content-Type': 'application/json',
113
- 'X-Bunq-Client-Authentication': access_token,
114
- 'X-Bunq-Language': 'en_US',
115
- 'X-Bunq-Region': 'nl_NL',
116
- 'X-Bunq-Client-Request-Id': Date.now().toString(),
117
- 'Cache-Control': 'no-cache'
118
- // Authorization: `Bearer ${access_token}`,
119
- // Accept: 'application/json',
120
- // 'Content-Type': 'application/json',
121
- },
122
- body: JSON.stringify({}),
123
- });
124
-
125
- const text = await res.text();
126
- let json;
127
- try {
128
- json = text ? JSON.parse(text) : {};
129
- } catch {
130
- json = { raw: text };
131
- }
132
-
133
- if (!res.ok) {
134
- throw new Error(
135
- `bunq session-server error (${res.status}): ${typeof text === 'string' ? text : JSON.stringify(json)}`,
136
- );
137
- }
138
-
139
- const sessionToken = res.headers.get('x-bunq-client-authentication');
140
- if (!sessionToken) {
141
- throw new Error(
142
- `Missing x-bunq-client-authentication header from session-server response. Body: ${text}`,
143
- );
144
- }
145
-
146
- // Try to find user id in response payload.
147
- // bunq responses are typically arrays of objects like {UserPerson:{...}} wrapped in Response.
148
- let userId;
149
- try {
150
- const responses = Array.isArray(json.Response) ? json.Response : [];
151
- for (const item of responses) {
152
- if (!item || typeof item !== 'object') continue;
153
- const v = item.UserPerson || item.UserCompany || item.UserLight || item.UserApiKey;
154
- if (v && v.id) {
155
- userId = v.id;
156
- break;
157
- }
158
- }
159
- } catch {
160
- // ignore
161
- }
162
-
163
- return { sessionToken, session: json, userId };
164
- }
165
- */
166
-
167
108
  async function auth({ host = '127.0.0.1', port = 4589 }) {
168
109
  const redirectUri = `http://${host}:${port}/callback`;
169
110
 
@@ -206,8 +147,6 @@ async function auth({ host = '127.0.0.1', port = 4589 }) {
206
147
  authUrl.searchParams.set('response_type', 'code');
207
148
  authUrl.searchParams.set('client_id', clientId);
208
149
  authUrl.searchParams.set('redirect_uri', redirectUri);
209
- // Keep scope optional; bunq may allow empty or require specific.
210
- if (existing.scope) authUrl.searchParams.set('scope', existing.scope);
211
150
 
212
151
  const finalAuthUrl = authUrl.toString();
213
152
  console.log(`\nAuthorization URL (open in your browser):\n${finalAuthUrl}\n`);
@@ -309,7 +248,6 @@ async function auth({ host = '127.0.0.1', port = 4589 }) {
309
248
  throw new Error(`bunq installation token error (${res.status}): ${text}`);
310
249
  }
311
250
  res = await res.json();
312
- console.log(JSON.stringify(res, null, " "))
313
251
  installationToken = res.Response[1].Token.token;
314
252
 
315
253
 
@@ -364,7 +302,6 @@ async function auth({ host = '127.0.0.1', port = 4589 }) {
364
302
  throw new Error(`bunq device registration error (${res.status}): ${text}`);
365
303
  }
366
304
  res = await res.json()
367
- console.log(JSON.stringify(res, null, " "))
368
305
 
369
306
  const response = res?.Response ?? [];
370
307
 
@@ -383,6 +320,7 @@ async function auth({ host = '127.0.0.1', port = 4589 }) {
383
320
 
384
321
 
385
322
  console.log(`\nSaved tokens + session to keychain`);
323
+ process.exit(0)
386
324
  }
387
325
 
388
326
  module.exports = { auth, getSecret, setSecret };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iovdin/bunk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "homepage": "https://github.com/iovdin/bunk#readme",
5
5
  "description": "bunq CLI download and index transactions into sqlite database",
6
6
  "type": "commonjs",