macbid-ts-api 1.0.0-beta.4 → 1.0.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/MacBid.d.ts +29 -16
- package/MacBid.d.ts.map +1 -1
- package/MacBid.js +177 -140
- package/MacBid.js.map +1 -1
- package/package.json +8 -27
- package/readme.md +83 -1
- package/MacBid.ts +0 -423
- package/index.ts +0 -2
package/MacBid.d.ts
CHANGED
|
@@ -10,6 +10,15 @@ export interface AuthInfo {
|
|
|
10
10
|
validation_code?: string;
|
|
11
11
|
device_id?: string;
|
|
12
12
|
}
|
|
13
|
+
/** JSON-serializable auth fields safe to persist (no credentials). */
|
|
14
|
+
export interface SerializableAuthState {
|
|
15
|
+
token?: string;
|
|
16
|
+
refresh_token?: string;
|
|
17
|
+
token_expiration?: string;
|
|
18
|
+
refresh_token_expiration?: string;
|
|
19
|
+
user_id?: string;
|
|
20
|
+
device_id?: string;
|
|
21
|
+
}
|
|
13
22
|
export interface WatchlistFull {
|
|
14
23
|
auction_lot_id: number;
|
|
15
24
|
watchlist_date_created: Date;
|
|
@@ -65,9 +74,20 @@ export declare class MacBid {
|
|
|
65
74
|
API_ROOT: string;
|
|
66
75
|
private macbid_session_headers;
|
|
67
76
|
private auth_info;
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
private mergeAuthInfo;
|
|
78
|
+
/** Returns persistable auth state (tokens and device_id). */
|
|
79
|
+
getAuthState: () => SerializableAuthState;
|
|
80
|
+
static serializeAuthState: (authInfo: Partial<AuthInfo>) => SerializableAuthState;
|
|
81
|
+
static parseAuthState: (data: string | SerializableAuthState) => Partial<AuthInfo>;
|
|
82
|
+
private clearLoginSession;
|
|
83
|
+
/** device_id saved without tokens means an SMS was sent and we're waiting for the code. */
|
|
84
|
+
private isAwaiting2FA;
|
|
85
|
+
/**
|
|
86
|
+
* Establish or refresh a session. Pass credentials and any saved tokens / device_id.
|
|
87
|
+
* Omit params on later calls to reuse the current session.
|
|
88
|
+
* Returns persistable auth state; use getAuthState() after API calls that may refresh tokens.
|
|
89
|
+
*/
|
|
90
|
+
authenticate: (params?: Partial<AuthInfo>) => Promise<SerializableAuthState>;
|
|
71
91
|
get: (path: string) => Promise<MacBidApiResponse>;
|
|
72
92
|
post: (path: string, options?: RequestInit) => Promise<MacBidApiResponse>;
|
|
73
93
|
/**
|
|
@@ -75,12 +95,13 @@ export declare class MacBid {
|
|
|
75
95
|
*/
|
|
76
96
|
private check_auth;
|
|
77
97
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param email - User email
|
|
80
|
-
* @param password - User password
|
|
81
|
-
* @param validation_code - Optional validation code. If not provided, will check auth_info.validation_code
|
|
98
|
+
* Validate the access code and get tokens
|
|
82
99
|
*/
|
|
83
|
-
|
|
100
|
+
private validateCode;
|
|
101
|
+
/**
|
|
102
|
+
* Do the login request using auth_info fields.
|
|
103
|
+
*/
|
|
104
|
+
private login;
|
|
84
105
|
get_refresh_token_expiration: () => Date;
|
|
85
106
|
/**
|
|
86
107
|
* Check if the access token is expired or about to expire (within 5 minutes)
|
|
@@ -102,14 +123,6 @@ export declare class MacBid {
|
|
|
102
123
|
* Returns the logged in user's favorites, and all of their (visible) attributes.
|
|
103
124
|
*/
|
|
104
125
|
get_watchlist: () => Promise<WatchlistFull[]>;
|
|
105
|
-
/**
|
|
106
|
-
* Save tokens to file for persistence across restarts
|
|
107
|
-
*/
|
|
108
|
-
private saveTokens;
|
|
109
|
-
/**
|
|
110
|
-
* Load tokens from file
|
|
111
|
-
*/
|
|
112
|
-
static loadTokens: (tokenFilePath: string) => Promise<Partial<AuthInfo> | null>;
|
|
113
126
|
}
|
|
114
127
|
export default MacBid;
|
|
115
128
|
//# sourceMappingURL=MacBid.d.ts.map
|
package/MacBid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MacBid.d.ts","sourceRoot":"","sources":["MacBid.ts"],"names":[],"mappings":"AAAA,OA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AEG;IACH,OAAO,CAAC,UAAU,CAKhB;IAEF;;OAEG;IACH,OAAO,CAAC,YAAY,CAyElB;IAEF;;OAEG;IACH,OAAO,CAAC,KAAK,CAwDX;IAEK,4BAA4B,QAAO,IAAI,CAM7C;IAED;;OAEG;IACH,OAAO,CAAC,cAAc,CAOrB;IAED;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAK5B;IAED;;OAEG;IACI,YAAY,QAAa,OAAO,CAAC,OAAO,CAAC,CA0D/C;IAED;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAIvB;IAED;;OAEG;IACI,aAAa,QAAa,OAAO,CAAC,aAAa,EAAE,CAAC,CAOvD;CACH;AAED,eAAe,MAAM,CAAC"}
|
package/MacBid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch from "node-fetch";
|
|
2
|
-
import {
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
3
|
export var AuctionType;
|
|
4
4
|
(function (AuctionType) {
|
|
5
5
|
AuctionType["Pallet"] = "pallet";
|
|
@@ -17,50 +17,109 @@ export class MacBid {
|
|
|
17
17
|
macbid_session_headers = {
|
|
18
18
|
"Content-Type": "application/json",
|
|
19
19
|
};
|
|
20
|
-
auth_info;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
auth_info = {};
|
|
21
|
+
mergeAuthInfo = (params) => {
|
|
22
|
+
Object.assign(this.auth_info, params);
|
|
23
|
+
};
|
|
24
|
+
/** Returns persistable auth state (tokens and device_id). */
|
|
25
|
+
getAuthState = () => {
|
|
26
|
+
return MacBid.serializeAuthState(this.auth_info);
|
|
27
|
+
};
|
|
28
|
+
static serializeAuthState = (authInfo) => ({
|
|
29
|
+
token: authInfo.token,
|
|
30
|
+
refresh_token: authInfo.refresh_token,
|
|
31
|
+
token_expiration: authInfo.token_expiration?.toISOString(),
|
|
32
|
+
refresh_token_expiration: authInfo.refresh_token_expiration?.toISOString(),
|
|
33
|
+
user_id: authInfo.user_id,
|
|
34
|
+
device_id: authInfo.device_id,
|
|
35
|
+
});
|
|
36
|
+
static parseAuthState = (data) => {
|
|
37
|
+
const parsed = typeof data === "string"
|
|
38
|
+
? JSON.parse(data)
|
|
39
|
+
: data;
|
|
40
|
+
return {
|
|
41
|
+
token: parsed.token,
|
|
42
|
+
refresh_token: parsed.refresh_token,
|
|
43
|
+
token_expiration: parsed.token_expiration
|
|
44
|
+
? new Date(parsed.token_expiration)
|
|
45
|
+
: undefined,
|
|
46
|
+
refresh_token_expiration: parsed.refresh_token_expiration
|
|
47
|
+
? new Date(parsed.refresh_token_expiration)
|
|
48
|
+
: undefined,
|
|
49
|
+
user_id: parsed.user_id,
|
|
50
|
+
device_id: parsed.device_id,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
clearLoginSession = () => {
|
|
54
|
+
delete this.auth_info.token;
|
|
55
|
+
delete this.auth_info.refresh_token;
|
|
56
|
+
delete this.auth_info.token_expiration;
|
|
57
|
+
delete this.auth_info.refresh_token_expiration;
|
|
58
|
+
delete this.auth_info.user_id;
|
|
59
|
+
delete this.auth_info.device_id;
|
|
60
|
+
delete this.auth_info.validation_code;
|
|
61
|
+
delete this.macbid_session_headers["Authorization"];
|
|
62
|
+
};
|
|
63
|
+
/** device_id saved without tokens means an SMS was sent and we're waiting for the code. */
|
|
64
|
+
isAwaiting2FA = () => {
|
|
65
|
+
return !!(this.auth_info.device_id &&
|
|
66
|
+
!this.auth_info.token &&
|
|
67
|
+
!this.auth_info.refresh_token);
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Establish or refresh a session. Pass credentials and any saved tokens / device_id.
|
|
71
|
+
* Omit params on later calls to reuse the current session.
|
|
72
|
+
* Returns persistable auth state; use getAuthState() after API calls that may refresh tokens.
|
|
73
|
+
*/
|
|
74
|
+
authenticate = async (params) => {
|
|
75
|
+
if (params) {
|
|
76
|
+
this.mergeAuthInfo(params);
|
|
77
|
+
}
|
|
78
|
+
if (this.auth_info.token) {
|
|
79
|
+
this.macbid_session_headers["Authorization"] = this.auth_info.token;
|
|
80
|
+
if (!this.isTokenExpired()) {
|
|
33
81
|
console.log("Using existing access token");
|
|
34
|
-
|
|
35
|
-
return;
|
|
82
|
+
return this.getAuthState();
|
|
36
83
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
84
|
+
if (this.auth_info.refresh_token && !this.isRefreshTokenExpired()) {
|
|
85
|
+
console.log("Access token expired, refreshing");
|
|
86
|
+
try {
|
|
87
|
+
await this.refreshToken();
|
|
88
|
+
return this.getAuthState();
|
|
41
89
|
}
|
|
42
|
-
|
|
43
|
-
console.
|
|
44
|
-
|
|
45
|
-
await this.refreshToken();
|
|
46
|
-
console.log("Successfully refreshed token");
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
// If refresh fails, fall through to login
|
|
51
|
-
console.warn("Failed to refresh token, attempting login:", error);
|
|
52
|
-
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.warn("Failed to refresh token, attempting login:", error);
|
|
92
|
+
this.clearLoginSession();
|
|
53
93
|
}
|
|
54
94
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
95
|
+
else {
|
|
96
|
+
this.clearLoginSession();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (this.auth_info.refresh_token) {
|
|
100
|
+
if (this.isRefreshTokenExpired()) {
|
|
101
|
+
console.log("Refresh token has expired, need to login");
|
|
102
|
+
this.clearLoginSession();
|
|
59
103
|
}
|
|
60
104
|
else {
|
|
61
|
-
|
|
105
|
+
console.log("No access token, attempting to refresh using refresh token");
|
|
106
|
+
try {
|
|
107
|
+
await this.refreshToken();
|
|
108
|
+
console.log("Successfully refreshed token");
|
|
109
|
+
return this.getAuthState();
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.warn("Failed to refresh token, attempting login:", error);
|
|
113
|
+
this.clearLoginSession();
|
|
114
|
+
}
|
|
62
115
|
}
|
|
63
116
|
}
|
|
117
|
+
if (this.auth_info.email && this.auth_info.password) {
|
|
118
|
+
console.log("No valid tokens found, attempting login");
|
|
119
|
+
await this.login();
|
|
120
|
+
return this.getAuthState();
|
|
121
|
+
}
|
|
122
|
+
throw new Error("email and password are required to log in");
|
|
64
123
|
};
|
|
65
124
|
get = async (path) => {
|
|
66
125
|
await this.ensureValidToken();
|
|
@@ -91,17 +150,86 @@ export class MacBid {
|
|
|
91
150
|
return true;
|
|
92
151
|
};
|
|
93
152
|
/**
|
|
94
|
-
*
|
|
95
|
-
* @param email - User email
|
|
96
|
-
* @param password - User password
|
|
97
|
-
* @param validation_code - Optional validation code. If not provided, will check auth_info.validation_code
|
|
153
|
+
* Validate the access code and get tokens
|
|
98
154
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
155
|
+
validateCode = async (code, device_id) => {
|
|
156
|
+
console.log("Validating code with device_id:", device_id);
|
|
157
|
+
const validation_params = {
|
|
158
|
+
code: code,
|
|
159
|
+
device_id: device_id,
|
|
160
|
+
new_password: "",
|
|
161
|
+
remember_me: false, // Match the browser behavior
|
|
162
|
+
};
|
|
163
|
+
console.log("Sending validation request to /auth/validate-access-code");
|
|
164
|
+
// Use PUT method like the browser does
|
|
165
|
+
const validation_res = await fetch(this.API_ROOT + "/auth/validate-access-code", {
|
|
166
|
+
method: "PUT",
|
|
167
|
+
body: JSON.stringify(validation_params),
|
|
168
|
+
headers: {
|
|
169
|
+
"Content-Type": "application/json",
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
const validation_resJson = (await validation_res.json());
|
|
173
|
+
console.log("Validation response status:", validation_res.status);
|
|
174
|
+
const errorMessage = validation_resJson["error"] || validation_resJson["message"] || "";
|
|
175
|
+
const hasError = validation_res.status !== 200 ||
|
|
176
|
+
!!validation_resJson["error"] ||
|
|
177
|
+
(typeof errorMessage === "string" && errorMessage.includes("Missing"));
|
|
178
|
+
if (hasError) {
|
|
179
|
+
console.error("Validation failed:", errorMessage || validation_res.status);
|
|
180
|
+
if (errorMessage.toLowerCase().includes("already verified")) {
|
|
181
|
+
this.clearLoginSession();
|
|
182
|
+
throw new Error("Validation code was already used. Clear saved auth state and authenticate again to request a new code.");
|
|
183
|
+
}
|
|
184
|
+
throw new Error(`Validation failed: ${errorMessage || "Unknown error"}`);
|
|
104
185
|
}
|
|
186
|
+
const access_token = validation_resJson["access_token"];
|
|
187
|
+
const refresh_token = validation_resJson["refresh_token"];
|
|
188
|
+
const user_id = validation_resJson["user_id"];
|
|
189
|
+
const expires = validation_resJson["expires"];
|
|
190
|
+
const expiration_refresh = validation_resJson["expiration_refresh"];
|
|
191
|
+
if (access_token) {
|
|
192
|
+
console.log("Access token received, saving tokens...");
|
|
193
|
+
this.auth_info.token = access_token;
|
|
194
|
+
this.auth_info.user_id = String(user_id);
|
|
195
|
+
this.macbid_session_headers["Authorization"] = this.auth_info.token;
|
|
196
|
+
this.auth_info.token_expiration = new Date(expires * 1000);
|
|
197
|
+
this.auth_info.refresh_token = refresh_token;
|
|
198
|
+
this.auth_info.refresh_token_expiration = new Date(expiration_refresh * 1000);
|
|
199
|
+
delete this.auth_info.validation_code;
|
|
200
|
+
console.log("✓ Login successful");
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
console.error("No access token in validation response");
|
|
205
|
+
throw new Error("Login failed: No access token received");
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Do the login request using auth_info fields.
|
|
210
|
+
*/
|
|
211
|
+
login = async () => {
|
|
212
|
+
const email = this.auth_info.email;
|
|
213
|
+
const password = this.auth_info.password;
|
|
214
|
+
if (!email || !password) {
|
|
215
|
+
throw new Error("email and password are required to log in");
|
|
216
|
+
}
|
|
217
|
+
const code = this.auth_info.validation_code;
|
|
218
|
+
if (code) {
|
|
219
|
+
const device_id = this.auth_info.device_id;
|
|
220
|
+
if (!device_id) {
|
|
221
|
+
throw new Error("device_id is required to validate a code");
|
|
222
|
+
}
|
|
223
|
+
console.log("Validation code present, attempting to validate...");
|
|
224
|
+
return await this.validateCode(code, device_id);
|
|
225
|
+
}
|
|
226
|
+
if (this.isAwaiting2FA()) {
|
|
227
|
+
throw new Error("A validation code was already sent for this device_id. Provide validation_code to continue.");
|
|
228
|
+
}
|
|
229
|
+
const device_id = randomUUID();
|
|
230
|
+
this.auth_info.device_id = device_id;
|
|
231
|
+
console.log("Generated new device_id:", device_id);
|
|
232
|
+
console.log("No validation code found, requesting new code...");
|
|
105
233
|
const login_params = {
|
|
106
234
|
device_id: device_id,
|
|
107
235
|
email: email,
|
|
@@ -113,57 +241,13 @@ export class MacBid {
|
|
|
113
241
|
utm_medium: null,
|
|
114
242
|
utm_source: null,
|
|
115
243
|
};
|
|
116
|
-
// https://api.macdiscount.com/auth/auth-validation
|
|
117
244
|
const res = await this.post("/auth/auth-validation", {
|
|
118
245
|
body: JSON.stringify(login_params),
|
|
119
246
|
});
|
|
120
247
|
const resJson = await res.json();
|
|
121
248
|
if (resJson["message"] === "Login validation code sent") {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.auth_info.validation_code ||
|
|
125
|
-
process.env.MACBID_VALIDATION_CODE;
|
|
126
|
-
if (!code) {
|
|
127
|
-
throw new Error("Validation code required. Provide it via:\n" +
|
|
128
|
-
" 1. login() method parameter: login(email, password, validation_code)\n" +
|
|
129
|
-
" 2. AuthInfo.validation_code when creating MacBid instance\n" +
|
|
130
|
-
" 3. MACBID_VALIDATION_CODE environment variable");
|
|
131
|
-
}
|
|
132
|
-
const validation_params = {
|
|
133
|
-
code: code,
|
|
134
|
-
device_id: login_params.device_id,
|
|
135
|
-
new_password: "",
|
|
136
|
-
remember_me: true,
|
|
137
|
-
};
|
|
138
|
-
const validation_res = await this.post("/auth/validate-access-code", {
|
|
139
|
-
body: JSON.stringify(validation_params),
|
|
140
|
-
});
|
|
141
|
-
const validation_resJson = await validation_res.json();
|
|
142
|
-
// Check if validation failed
|
|
143
|
-
if (validation_res.status !== 200 || validation_resJson["error"]) {
|
|
144
|
-
console.error("Validation failed:", JSON.stringify(validation_resJson, null, 2));
|
|
145
|
-
throw new Error(`Validation failed: ${validation_resJson["error"] || validation_resJson["message"] || "Unknown error"}`);
|
|
146
|
-
}
|
|
147
|
-
const access_token = validation_resJson["access_token"];
|
|
148
|
-
const refresh_token = validation_resJson["refresh_token"];
|
|
149
|
-
const user_id = validation_resJson["user_id"];
|
|
150
|
-
const expires = validation_resJson["expires"];
|
|
151
|
-
const expiration_refresh = validation_resJson["expiration_refresh"];
|
|
152
|
-
if (access_token) {
|
|
153
|
-
this.auth_info.token = access_token;
|
|
154
|
-
this.auth_info.user_id = user_id;
|
|
155
|
-
this.macbid_session_headers["Authorization"] = this.auth_info.token;
|
|
156
|
-
this.auth_info.token_expiration = new Date(expires * 1000);
|
|
157
|
-
this.auth_info.refresh_token = refresh_token;
|
|
158
|
-
this.auth_info.refresh_token_expiration = new Date(expiration_refresh * 1000);
|
|
159
|
-
await this.saveTokens();
|
|
160
|
-
console.log("Login successful, tokens saved");
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
console.error("No access token in validation response:", JSON.stringify(validation_resJson, null, 2));
|
|
165
|
-
throw new Error("Login failed: No access token received");
|
|
166
|
-
}
|
|
249
|
+
console.log("✓ Validation code sent");
|
|
250
|
+
throw new Error("Validation code sent. Provide validation_code and authenticate again.");
|
|
167
251
|
}
|
|
168
252
|
console.error("Unexpected login response:", JSON.stringify(resJson, null, 2));
|
|
169
253
|
throw new Error("Login failed");
|
|
@@ -218,9 +302,8 @@ export class MacBid {
|
|
|
218
302
|
},
|
|
219
303
|
});
|
|
220
304
|
const resJson = (await res.json());
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
throw new Error(`Failed to refresh token: ${resJson["error"]}`);
|
|
305
|
+
if (!res.ok || resJson.error) {
|
|
306
|
+
throw new Error(`Failed to refresh token: ${resJson.error || res.status}`);
|
|
224
307
|
}
|
|
225
308
|
const access_token = resJson["access_token"];
|
|
226
309
|
const refresh_token = resJson["refresh_token"];
|
|
@@ -237,7 +320,6 @@ export class MacBid {
|
|
|
237
320
|
if (expiration_refresh) {
|
|
238
321
|
this.auth_info.refresh_token_expiration = new Date(expiration_refresh * 1000);
|
|
239
322
|
}
|
|
240
|
-
await this.saveTokens();
|
|
241
323
|
return true;
|
|
242
324
|
}
|
|
243
325
|
else {
|
|
@@ -260,51 +342,6 @@ export class MacBid {
|
|
|
260
342
|
const res = await this.get(`/auctions/customer/${this.auth_info["user_id"]}/active-auctions`);
|
|
261
343
|
return (await res.json())["watchlist_full"];
|
|
262
344
|
};
|
|
263
|
-
/**
|
|
264
|
-
* Save tokens to file for persistence across restarts
|
|
265
|
-
*/
|
|
266
|
-
saveTokens = async () => {
|
|
267
|
-
if (!this.tokenFilePath) {
|
|
268
|
-
console.log("No token file path provided, skipping token save");
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
try {
|
|
272
|
-
const tokenData = {
|
|
273
|
-
token: this.auth_info.token,
|
|
274
|
-
refresh_token: this.auth_info.refresh_token,
|
|
275
|
-
token_expiration: this.auth_info.token_expiration?.toISOString(),
|
|
276
|
-
refresh_token_expiration: this.auth_info.refresh_token_expiration?.toISOString(),
|
|
277
|
-
user_id: this.auth_info.user_id,
|
|
278
|
-
device_id: this.auth_info.device_id,
|
|
279
|
-
};
|
|
280
|
-
await fs.writeFile(this.tokenFilePath, JSON.stringify(tokenData, null, 2), "utf-8");
|
|
281
|
-
console.log("Tokens saved to file:", this.tokenFilePath);
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
console.warn("Failed to save tokens:", error);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
/**
|
|
288
|
-
* Load tokens from file
|
|
289
|
-
*/
|
|
290
|
-
static loadTokens = async (tokenFilePath) => {
|
|
291
|
-
try {
|
|
292
|
-
const data = await fs.readFile(tokenFilePath, "utf-8");
|
|
293
|
-
const tokenData = JSON.parse(data);
|
|
294
|
-
return {
|
|
295
|
-
token: tokenData.token,
|
|
296
|
-
refresh_token: tokenData.refresh_token,
|
|
297
|
-
token_expiration: tokenData.token_expiration ? new Date(tokenData.token_expiration) : undefined,
|
|
298
|
-
refresh_token_expiration: tokenData.refresh_token_expiration ? new Date(tokenData.refresh_token_expiration) : undefined,
|
|
299
|
-
user_id: tokenData.user_id,
|
|
300
|
-
device_id: tokenData.device_id,
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
catch (error) {
|
|
304
|
-
// File doesn't exist or is invalid, return null
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
345
|
}
|
|
309
346
|
export default MacBid;
|
|
310
347
|
//# sourceMappingURL=MacBid.js.map
|
package/MacBid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MacBid.js","sourceRoot":"","sources":["MacBid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AAmDzC,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAED,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,qCAAoB,CAAA;IACpB,qCAAoB,CAAA;AACtB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAQD,MAAM,OAAO,MAAM;IACV,cAAc,GAAG,qBAAqB,CAAC;IACvC,QAAQ,GA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,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC,CAAA;IAED;;OAEG;IACK,gBAAgB,GAAG,KAAK,IAAmB,EAAE;QACnD,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC,CAAA;IAED;;OAEG;IACI,aAAa,GAAG,KAAK,IAA8B,EAAE;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CACxB,sBAAsB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,kBAAkB,CAClE,CAAC;QAEF,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,gBAAgB,CAAoB,CAAC;IACjE,CAAC,CAAC;;AAGJ,eAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "macbid-ts-api",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/pkmnct/macbid-ts-api.git"
|
|
@@ -17,35 +17,16 @@
|
|
|
17
17
|
"node": ">=16.0.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"eslint": "^
|
|
24
|
-
"
|
|
25
|
-
"eslint
|
|
26
|
-
"typescript": "^5.2.2"
|
|
27
|
-
},
|
|
28
|
-
"eslintConfig": {
|
|
29
|
-
"parser": "@typescript-eslint/parser",
|
|
30
|
-
"parserOptions": {
|
|
31
|
-
"ecmaVersion": 2021,
|
|
32
|
-
"sourceType": "module"
|
|
33
|
-
},
|
|
34
|
-
"extends": [
|
|
35
|
-
"eslint:recommended",
|
|
36
|
-
"plugin:@typescript-eslint/recommended",
|
|
37
|
-
"plugin:promise/recommended",
|
|
38
|
-
"plugin:import/recommended",
|
|
39
|
-
"plugin:import/typescript"
|
|
40
|
-
],
|
|
41
|
-
"plugins": [
|
|
42
|
-
"@typescript-eslint",
|
|
43
|
-
"promise",
|
|
44
|
-
"import"
|
|
45
|
-
]
|
|
20
|
+
"@eslint/js": "^10.0.1",
|
|
21
|
+
"@types/node-fetch": "^2.6.13",
|
|
22
|
+
"eslint": "^10.5.0",
|
|
23
|
+
"eslint-plugin-promise": "^7.3.0",
|
|
24
|
+
"typescript": "^6.0.3",
|
|
25
|
+
"typescript-eslint": "^8.61.1"
|
|
46
26
|
},
|
|
47
27
|
"scripts": {
|
|
48
28
|
"build": "tsc",
|
|
29
|
+
"lint": "eslint .",
|
|
49
30
|
"prepublish": "npm run build"
|
|
50
31
|
},
|
|
51
32
|
"type": "module",
|
package/readme.md
CHANGED
|
@@ -1 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# macbid-ts-api
|
|
2
|
+
|
|
3
|
+
Unofficial TypeScript client for the [Mac.Bid](https://www.mac.bid) API.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
Node.js **>= 16**
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install macbid-ts-api
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import MacBid, { type SerializableAuthState } from "macbid-ts-api";
|
|
19
|
+
|
|
20
|
+
const api = new MacBid();
|
|
21
|
+
let state: SerializableAuthState = {};
|
|
22
|
+
|
|
23
|
+
state = await api.authenticate({
|
|
24
|
+
email: "you@example.com",
|
|
25
|
+
password: "your-password",
|
|
26
|
+
...state,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const watchlist = await api.get_watchlist();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`authenticate()` returns persistable state (tokens and `device_id`, never credentials). Pass it back in on the next call with `...state`.
|
|
33
|
+
|
|
34
|
+
### Two-factor authentication
|
|
35
|
+
|
|
36
|
+
If SMS verification is required, the first call throws after sending a code. Set `state` from `api.getAuthState()` and call again with the code:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
let state: SerializableAuthState = {};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
state = await api.authenticate({ email, password, ...state });
|
|
43
|
+
} catch {
|
|
44
|
+
state = api.getAuthState();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// User receives SMS, then retry:
|
|
48
|
+
state = await api.authenticate({
|
|
49
|
+
email,
|
|
50
|
+
password,
|
|
51
|
+
validation_code: "123456",
|
|
52
|
+
...state,
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If `device_id` is set but there are no tokens and no `validation_code`, a code was already sent and a new SMS will not be requested.
|
|
57
|
+
|
|
58
|
+
For JSON storage, use `MacBid.serializeAuthState` / `MacBid.parseAuthState`.
|
|
59
|
+
|
|
60
|
+
`AuthInfo` is the type for `authenticate()` params (credentials, `validation_code`, etc.). `SerializableAuthState` is what comes back — safe to persist.
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
| Method | Description |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `authenticate(params?)` | Log in or refresh session; returns persistable state |
|
|
67
|
+
| `get_watchlist()` | Active watchlist items |
|
|
68
|
+
| `get(path)` / `post(path, options?)` | Authenticated API requests |
|
|
69
|
+
| `refreshToken()` | Refresh the access token |
|
|
70
|
+
| `getAuthState()` | Current persistable state |
|
|
71
|
+
| `get_refresh_token_expiration()` | Refresh token expiry |
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install
|
|
77
|
+
npm run build
|
|
78
|
+
npm run lint
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
package/MacBid.ts
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import fetch, { Response } from "node-fetch";
|
|
2
|
-
import { promises as fs } from "node:fs";
|
|
3
|
-
|
|
4
|
-
export interface AuthInfo {
|
|
5
|
-
email?: string;
|
|
6
|
-
password?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
token_expiration?: Date;
|
|
9
|
-
user_id?: string;
|
|
10
|
-
refresh_token?: string;
|
|
11
|
-
refresh_token_expiration?: Date;
|
|
12
|
-
validation_code?: string;
|
|
13
|
-
device_id?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface WatchlistFull {
|
|
17
|
-
auction_lot_id: number;
|
|
18
|
-
watchlist_date_created: Date;
|
|
19
|
-
id: number;
|
|
20
|
-
auction_id: number;
|
|
21
|
-
closed_date: null;
|
|
22
|
-
buyers_assurance_cost: number | null;
|
|
23
|
-
expected_close_date: Date;
|
|
24
|
-
inventory_id: number;
|
|
25
|
-
date_created: Date;
|
|
26
|
-
lot_number: string;
|
|
27
|
-
listing_url: null;
|
|
28
|
-
title: string;
|
|
29
|
-
is_open: number;
|
|
30
|
-
is_transferrable: number;
|
|
31
|
-
total_bids: number;
|
|
32
|
-
winning_customer_id: null;
|
|
33
|
-
winning_bid_id: null;
|
|
34
|
-
winning_bid_amount: number | null;
|
|
35
|
-
unique_bidders: number;
|
|
36
|
-
product_name: string;
|
|
37
|
-
quantity: number;
|
|
38
|
-
is_pallet: number;
|
|
39
|
-
shipping_height: number | null;
|
|
40
|
-
shipping_width: number | null;
|
|
41
|
-
shipping_length: number | null;
|
|
42
|
-
warehouse_location: string;
|
|
43
|
-
shipping_weight: number | null;
|
|
44
|
-
case_packed_qty: number | null;
|
|
45
|
-
auction_number: string;
|
|
46
|
-
retail_price: number;
|
|
47
|
-
condition_name: ConditionName;
|
|
48
|
-
category: null | string;
|
|
49
|
-
image_url: string;
|
|
50
|
-
auction_type: AuctionType;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export enum AuctionType {
|
|
54
|
-
Pallet = "pallet",
|
|
55
|
-
Standard = "standard",
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export enum ConditionName {
|
|
59
|
-
Damaged = "DAMAGED",
|
|
60
|
-
LikeNew = "LIKE NEW",
|
|
61
|
-
OpenBox = "OPEN BOX",
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface MacBidApiResponse extends Response {
|
|
65
|
-
json: () => Promise<{
|
|
66
|
-
[key: string]: unknown;
|
|
67
|
-
}>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export class MacBid {
|
|
71
|
-
public LOGIN_PAGE_URL = "https://www.mac.bid";
|
|
72
|
-
public API_ROOT = "https://api.macdiscount.com";
|
|
73
|
-
|
|
74
|
-
private macbid_session_headers: { [key: string]: string } = {
|
|
75
|
-
"Content-Type": "application/json",
|
|
76
|
-
};
|
|
77
|
-
private auth_info: AuthInfo;
|
|
78
|
-
private tokenFilePath?: string;
|
|
79
|
-
|
|
80
|
-
constructor(auth_info: AuthInfo, tokenFilePath?: string) {
|
|
81
|
-
this.auth_info = auth_info;
|
|
82
|
-
this.tokenFilePath = tokenFilePath;
|
|
83
|
-
// Don't authenticate in constructor - wait until actually needed
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public authenticate = async () => {
|
|
87
|
-
if (this.auth_info) {
|
|
88
|
-
// If we have a token, use it (will be auto-refreshed if expired)
|
|
89
|
-
if (this.auth_info.token) {
|
|
90
|
-
this.macbid_session_headers["Authorization"] = this.auth_info
|
|
91
|
-
.token as string;
|
|
92
|
-
console.log("Using existing access token");
|
|
93
|
-
// Token will be auto-refreshed by ensureValidToken if needed
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// If we have a refresh token but no access token, try to refresh first
|
|
98
|
-
if (this.auth_info.refresh_token) {
|
|
99
|
-
if (this.isRefreshTokenExpired()) {
|
|
100
|
-
console.log("Refresh token has expired, need to login");
|
|
101
|
-
} else {
|
|
102
|
-
console.log("No access token, attempting to refresh using refresh token");
|
|
103
|
-
try {
|
|
104
|
-
await this.refreshToken();
|
|
105
|
-
console.log("Successfully refreshed token");
|
|
106
|
-
return;
|
|
107
|
-
} catch (error) {
|
|
108
|
-
// If refresh fails, fall through to login
|
|
109
|
-
console.warn("Failed to refresh token, attempting login:", error);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// No valid tokens, need to login
|
|
115
|
-
if (this.auth_info.email && this.auth_info.password) {
|
|
116
|
-
console.log("No valid tokens found, attempting login");
|
|
117
|
-
await this.login(this.auth_info.email, this.auth_info.password);
|
|
118
|
-
} else {
|
|
119
|
-
throw new Error("Invalid auth_info");
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
public get = async (path: string): Promise<MacBidApiResponse> => {
|
|
125
|
-
await this.ensureValidToken();
|
|
126
|
-
return (await fetch(this.API_ROOT + path, {
|
|
127
|
-
headers: this.macbid_session_headers,
|
|
128
|
-
})) as MacBidApiResponse;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
public post = async (
|
|
132
|
-
path: string,
|
|
133
|
-
options?: RequestInit
|
|
134
|
-
): Promise<MacBidApiResponse> => {
|
|
135
|
-
// Don't refresh token for auth endpoints
|
|
136
|
-
if (!path.includes("/auth/")) {
|
|
137
|
-
await this.ensureValidToken();
|
|
138
|
-
}
|
|
139
|
-
return (await fetch(this.API_ROOT + path, {
|
|
140
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
141
|
-
// @ts-ignore
|
|
142
|
-
headers: this.macbid_session_headers,
|
|
143
|
-
method: "POST",
|
|
144
|
-
...options,
|
|
145
|
-
})) as MacBidApiResponse;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Raise an exception if an endpoint requiring login is called without valid auth
|
|
150
|
-
*/
|
|
151
|
-
private check_auth = (): boolean => {
|
|
152
|
-
if (!this.macbid_session_headers["Authorization"]) {
|
|
153
|
-
throw new Error("Not authenticated");
|
|
154
|
-
}
|
|
155
|
-
return true;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Do the login request
|
|
160
|
-
* @param email - User email
|
|
161
|
-
* @param password - User password
|
|
162
|
-
* @param validation_code - Optional validation code. If not provided, will check auth_info.validation_code
|
|
163
|
-
*/
|
|
164
|
-
public login = async (
|
|
165
|
-
email: string,
|
|
166
|
-
password: string,
|
|
167
|
-
validation_code?: string
|
|
168
|
-
): Promise<boolean> => {
|
|
169
|
-
// Use existing device_id if available, otherwise generate a new one
|
|
170
|
-
const device_id = this.auth_info.device_id || crypto.randomUUID();
|
|
171
|
-
if (!this.auth_info.device_id) {
|
|
172
|
-
this.auth_info.device_id = device_id;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const login_params = {
|
|
176
|
-
device_id: device_id,
|
|
177
|
-
email: email,
|
|
178
|
-
password: password,
|
|
179
|
-
ref_code: null,
|
|
180
|
-
ref_r: null,
|
|
181
|
-
remember_me: true,
|
|
182
|
-
utm_campaign: null,
|
|
183
|
-
utm_medium: null,
|
|
184
|
-
utm_source: null,
|
|
185
|
-
};
|
|
186
|
-
// https://api.macdiscount.com/auth/auth-validation
|
|
187
|
-
const res = await this.post("/auth/auth-validation", {
|
|
188
|
-
body: JSON.stringify(login_params),
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const resJson = await res.json();
|
|
192
|
-
|
|
193
|
-
if (resJson["message"] === "Login validation code sent") {
|
|
194
|
-
// Get validation code from parameter, auth_info, or throw error
|
|
195
|
-
const code =
|
|
196
|
-
validation_code ||
|
|
197
|
-
this.auth_info.validation_code ||
|
|
198
|
-
process.env.MACBID_VALIDATION_CODE;
|
|
199
|
-
|
|
200
|
-
if (!code) {
|
|
201
|
-
throw new Error(
|
|
202
|
-
"Validation code required. Provide it via:\n" +
|
|
203
|
-
" 1. login() method parameter: login(email, password, validation_code)\n" +
|
|
204
|
-
" 2. AuthInfo.validation_code when creating MacBid instance\n" +
|
|
205
|
-
" 3. MACBID_VALIDATION_CODE environment variable"
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const validation_params = {
|
|
210
|
-
code: code,
|
|
211
|
-
device_id: login_params.device_id,
|
|
212
|
-
new_password: "",
|
|
213
|
-
remember_me: true,
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const validation_res = await this.post("/auth/validate-access-code", {
|
|
217
|
-
body: JSON.stringify(validation_params),
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
const validation_resJson = await validation_res.json();
|
|
221
|
-
|
|
222
|
-
// Check if validation failed
|
|
223
|
-
if (validation_res.status !== 200 || validation_resJson["error"]) {
|
|
224
|
-
console.error("Validation failed:", JSON.stringify(validation_resJson, null, 2));
|
|
225
|
-
throw new Error(`Validation failed: ${validation_resJson["error"] || validation_resJson["message"] || "Unknown error"}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const access_token = validation_resJson["access_token"] as string;
|
|
229
|
-
const refresh_token = validation_resJson["refresh_token"] as string;
|
|
230
|
-
const user_id = validation_resJson["user_id"] as string;
|
|
231
|
-
const expires = validation_resJson["expires"] as number;
|
|
232
|
-
const expiration_refresh = validation_resJson["expiration_refresh"] as number;
|
|
233
|
-
|
|
234
|
-
if (access_token) {
|
|
235
|
-
this.auth_info.token = access_token as string;
|
|
236
|
-
this.auth_info.user_id = user_id as string;
|
|
237
|
-
this.macbid_session_headers["Authorization"] = this.auth_info.token;
|
|
238
|
-
this.auth_info.token_expiration = new Date(expires * 1000);
|
|
239
|
-
this.auth_info.refresh_token = refresh_token;
|
|
240
|
-
this.auth_info.refresh_token_expiration = new Date(expiration_refresh * 1000);
|
|
241
|
-
await this.saveTokens();
|
|
242
|
-
console.log("Login successful, tokens saved");
|
|
243
|
-
return true;
|
|
244
|
-
} else {
|
|
245
|
-
console.error("No access token in validation response:", JSON.stringify(validation_resJson, null, 2));
|
|
246
|
-
throw new Error("Login failed: No access token received");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
console.error("Unexpected login response:", JSON.stringify(resJson, null, 2));
|
|
250
|
-
throw new Error("Login failed");
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
public get_refresh_token_expiration = (): Date => {
|
|
254
|
-
if (this.auth_info.refresh_token_expiration) {
|
|
255
|
-
return this.auth_info.refresh_token_expiration;
|
|
256
|
-
} else {
|
|
257
|
-
throw new Error("Refresh token expiration not set, make sure to login first.");
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Check if the access token is expired or about to expire (within 5 minutes)
|
|
263
|
-
*/
|
|
264
|
-
private isTokenExpired = (): boolean => {
|
|
265
|
-
if (!this.auth_info.token_expiration) {
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
// Refresh if token expires within 5 minutes
|
|
269
|
-
const bufferTime = 5 * 60 * 1000; // 5 minutes in milliseconds
|
|
270
|
-
return Date.now() >= this.auth_info.token_expiration.getTime() - bufferTime;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Check if the refresh token is expired
|
|
275
|
-
*/
|
|
276
|
-
private isRefreshTokenExpired = (): boolean => {
|
|
277
|
-
if (!this.auth_info.refresh_token_expiration) {
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
return Date.now() >= this.auth_info.refresh_token_expiration.getTime();
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Refresh the access token using the refresh token
|
|
285
|
-
*/
|
|
286
|
-
public refreshToken = async (): Promise<boolean> => {
|
|
287
|
-
if (!this.auth_info.refresh_token) {
|
|
288
|
-
throw new Error("No refresh token available. Please login again.");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (this.isRefreshTokenExpired()) {
|
|
292
|
-
throw new Error("Refresh token has expired. Please login again.");
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const refresh_params = {
|
|
296
|
-
refresh_token: this.auth_info.refresh_token,
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// Use fetch directly to avoid triggering ensureValidToken and use PUT method
|
|
300
|
-
const res = await fetch(this.API_ROOT + "/auth/refresh-token", {
|
|
301
|
-
method: "PUT",
|
|
302
|
-
body: JSON.stringify(refresh_params),
|
|
303
|
-
headers: {
|
|
304
|
-
"Content-Type": "application/json",
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
const resJson = (await res.json()) as {
|
|
309
|
-
error?: string;
|
|
310
|
-
access_token?: string;
|
|
311
|
-
refresh_token?: string;
|
|
312
|
-
expires?: number;
|
|
313
|
-
expiration_refresh?: number;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// Check for error response
|
|
317
|
-
if (resJson["error"]) {
|
|
318
|
-
throw new Error(`Failed to refresh token: ${resJson["error"]}`);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const access_token = resJson["access_token"] as string;
|
|
322
|
-
const refresh_token = resJson["refresh_token"] as string | undefined;
|
|
323
|
-
const expires = resJson["expires"] as number;
|
|
324
|
-
const expiration_refresh = resJson["expiration_refresh"] as number | undefined;
|
|
325
|
-
|
|
326
|
-
if (access_token) {
|
|
327
|
-
this.auth_info.token = access_token;
|
|
328
|
-
this.macbid_session_headers["Authorization"] = this.auth_info.token;
|
|
329
|
-
this.auth_info.token_expiration = new Date(expires * 1000);
|
|
330
|
-
|
|
331
|
-
// Update refresh token if a new one is provided
|
|
332
|
-
if (refresh_token) {
|
|
333
|
-
this.auth_info.refresh_token = refresh_token;
|
|
334
|
-
}
|
|
335
|
-
if (expiration_refresh) {
|
|
336
|
-
this.auth_info.refresh_token_expiration = new Date(expiration_refresh * 1000);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
await this.saveTokens();
|
|
340
|
-
return true;
|
|
341
|
-
} else {
|
|
342
|
-
throw new Error("Failed to refresh token: no access token in response");
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Ensure the access token is valid, refreshing if necessary
|
|
348
|
-
*/
|
|
349
|
-
private ensureValidToken = async (): Promise<void> => {
|
|
350
|
-
if (this.isTokenExpired()) {
|
|
351
|
-
await this.refreshToken();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Returns the logged in user's favorites, and all of their (visible) attributes.
|
|
357
|
-
*/
|
|
358
|
-
public get_watchlist = async (): Promise<WatchlistFull[]> => {
|
|
359
|
-
this.check_auth();
|
|
360
|
-
const res = await this.get(
|
|
361
|
-
`/auctions/customer/${this.auth_info["user_id"]}/active-auctions`
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
return (await res.json())["watchlist_full"] as WatchlistFull[];
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Save tokens to file for persistence across restarts
|
|
369
|
-
*/
|
|
370
|
-
private saveTokens = async (): Promise<void> => {
|
|
371
|
-
if (!this.tokenFilePath) {
|
|
372
|
-
console.log("No token file path provided, skipping token save");
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
try {
|
|
377
|
-
const tokenData = {
|
|
378
|
-
token: this.auth_info.token,
|
|
379
|
-
refresh_token: this.auth_info.refresh_token,
|
|
380
|
-
token_expiration: this.auth_info.token_expiration?.toISOString(),
|
|
381
|
-
refresh_token_expiration: this.auth_info.refresh_token_expiration?.toISOString(),
|
|
382
|
-
user_id: this.auth_info.user_id,
|
|
383
|
-
device_id: this.auth_info.device_id,
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
await fs.writeFile(this.tokenFilePath, JSON.stringify(tokenData, null, 2), "utf-8");
|
|
387
|
-
console.log("Tokens saved to file:", this.tokenFilePath);
|
|
388
|
-
} catch (error) {
|
|
389
|
-
console.warn("Failed to save tokens:", error);
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Load tokens from file
|
|
395
|
-
*/
|
|
396
|
-
public static loadTokens = async (tokenFilePath: string): Promise<Partial<AuthInfo> | null> => {
|
|
397
|
-
try {
|
|
398
|
-
const data = await fs.readFile(tokenFilePath, "utf-8");
|
|
399
|
-
const tokenData = JSON.parse(data) as {
|
|
400
|
-
token?: string;
|
|
401
|
-
refresh_token?: string;
|
|
402
|
-
token_expiration?: string;
|
|
403
|
-
refresh_token_expiration?: string;
|
|
404
|
-
user_id?: string;
|
|
405
|
-
device_id?: string;
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
return {
|
|
409
|
-
token: tokenData.token,
|
|
410
|
-
refresh_token: tokenData.refresh_token,
|
|
411
|
-
token_expiration: tokenData.token_expiration ? new Date(tokenData.token_expiration) : undefined,
|
|
412
|
-
refresh_token_expiration: tokenData.refresh_token_expiration ? new Date(tokenData.refresh_token_expiration) : undefined,
|
|
413
|
-
user_id: tokenData.user_id,
|
|
414
|
-
device_id: tokenData.device_id,
|
|
415
|
-
};
|
|
416
|
-
} catch (error) {
|
|
417
|
-
// File doesn't exist or is invalid, return null
|
|
418
|
-
return null;
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export default MacBid;
|
package/index.ts
DELETED