ebag 0.1.0 → 0.1.2
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 +30 -7
- package/dist/cli/format.d.ts +1 -1
- package/dist/cli/format.js +149 -123
- package/dist/cli/index.js +139 -78
- package/dist/cli/warnings.d.ts +2 -0
- package/dist/cli/warnings.js +14 -0
- package/dist/lib/auth.d.ts +1 -1
- package/dist/lib/auth.js +5 -5
- package/dist/lib/cart.d.ts +1 -1
- package/dist/lib/cart.js +11 -11
- package/dist/lib/client.d.ts +1 -1
- package/dist/lib/client.js +30 -20
- package/dist/lib/config.d.ts +2 -1
- package/dist/lib/config.js +22 -13
- package/dist/lib/cookies.js +10 -7
- package/dist/lib/index.d.ts +9 -9
- package/dist/lib/lists.d.ts +1 -1
- package/dist/lib/lists.js +4 -4
- package/dist/lib/log.d.ts +8 -0
- package/dist/lib/log.js +115 -0
- package/dist/lib/order-status.d.ts +9 -0
- package/dist/lib/order-status.js +34 -0
- package/dist/lib/orders.d.ts +1 -1
- package/dist/lib/orders.js +83 -46
- package/dist/lib/products.d.ts +1 -1
- package/dist/lib/search.d.ts +1 -1
- package/dist/lib/search.js +26 -20
- package/dist/lib/slots.d.ts +1 -1
- package/dist/lib/slots.js +3 -3
- package/dist/lib/types.d.ts +3 -3
- package/package.json +5 -2
package/dist/cli/index.js
CHANGED
|
@@ -16,7 +16,9 @@ const orders_1 = require("../lib/orders");
|
|
|
16
16
|
const products_1 = require("../lib/products");
|
|
17
17
|
const search_1 = require("../lib/search");
|
|
18
18
|
const slots_1 = require("../lib/slots");
|
|
19
|
+
const log_1 = require("../lib/log");
|
|
19
20
|
const format_1 = require("./format");
|
|
21
|
+
const warnings_1 = require("./warnings");
|
|
20
22
|
function requireSessionCookie() {
|
|
21
23
|
const session = (0, config_1.loadSession)();
|
|
22
24
|
if (!session.cookies) {
|
|
@@ -35,26 +37,60 @@ function formatError(err) {
|
|
|
35
37
|
}
|
|
36
38
|
async function main() {
|
|
37
39
|
const program = new commander_1.Command();
|
|
40
|
+
let lastCommand = "unknown";
|
|
41
|
+
let lastArgs = [];
|
|
42
|
+
let lastStart = Date.now();
|
|
38
43
|
function getPackageVersion() {
|
|
39
44
|
try {
|
|
40
|
-
const packagePath = node_path_1.default.resolve(__dirname,
|
|
41
|
-
const raw = node_fs_1.default.readFileSync(packagePath,
|
|
45
|
+
const packagePath = node_path_1.default.resolve(__dirname, "../../package.json");
|
|
46
|
+
const raw = node_fs_1.default.readFileSync(packagePath, "utf8");
|
|
42
47
|
const parsed = JSON.parse(raw);
|
|
43
|
-
return parsed.version ||
|
|
48
|
+
return parsed.version || "unknown";
|
|
44
49
|
}
|
|
45
50
|
catch {
|
|
46
|
-
return
|
|
51
|
+
return "unknown";
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
program
|
|
50
|
-
.name(
|
|
51
|
-
.description(
|
|
52
|
-
.version(getPackageVersion(),
|
|
53
|
-
.option(
|
|
55
|
+
.name("ebag")
|
|
56
|
+
.description("CLI for interacting with ebag.bg")
|
|
57
|
+
.version(getPackageVersion(), "-v, --version", "Show CLI version")
|
|
58
|
+
.option("--json", "Output JSON");
|
|
59
|
+
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
60
|
+
lastStart = Date.now();
|
|
61
|
+
const commandPath = actionCommand.commandPath?.();
|
|
62
|
+
lastCommand = commandPath || actionCommand.name() || "unknown";
|
|
63
|
+
lastArgs = process.argv.slice(2);
|
|
64
|
+
(0, log_1.appendLog)({
|
|
65
|
+
level: "info",
|
|
66
|
+
event: "command.start",
|
|
67
|
+
command: lastCommand,
|
|
68
|
+
args: lastArgs,
|
|
69
|
+
json: Boolean(program.opts().json),
|
|
70
|
+
pid: process.pid,
|
|
71
|
+
ppid: process.ppid,
|
|
72
|
+
cwd: process.cwd(),
|
|
73
|
+
node: process.version,
|
|
74
|
+
configDir: (0, config_1.getConfigDir)(),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
program.hook("postAction", () => {
|
|
78
|
+
const durationMs = Date.now() - lastStart;
|
|
79
|
+
(0, log_1.appendLog)({
|
|
80
|
+
level: "info",
|
|
81
|
+
event: "command.finish",
|
|
82
|
+
command: lastCommand,
|
|
83
|
+
args: lastArgs,
|
|
84
|
+
json: Boolean(program.opts().json),
|
|
85
|
+
pid: process.pid,
|
|
86
|
+
durationMs,
|
|
87
|
+
configDir: (0, config_1.getConfigDir)(),
|
|
88
|
+
});
|
|
89
|
+
});
|
|
54
90
|
program
|
|
55
|
-
.command(
|
|
56
|
-
.description(
|
|
57
|
-
.option(
|
|
91
|
+
.command("login")
|
|
92
|
+
.description("Store session cookie and validate it")
|
|
93
|
+
.option("--cookie <cookie>", "Cookie header value from browser")
|
|
58
94
|
.action(async (options) => {
|
|
59
95
|
const config = (0, config_1.loadConfig)();
|
|
60
96
|
const json = program.opts().json;
|
|
@@ -81,20 +117,20 @@ async function main() {
|
|
|
81
117
|
const email = user.email ||
|
|
82
118
|
user.username;
|
|
83
119
|
if (!email) {
|
|
84
|
-
throw new Error(
|
|
120
|
+
throw new Error("Session validated but no user email was returned.");
|
|
85
121
|
}
|
|
86
122
|
(0, config_1.saveSession)(session);
|
|
87
123
|
if (json) {
|
|
88
|
-
(0, format_1.outputJson)({ status:
|
|
124
|
+
(0, format_1.outputJson)({ status: "ok", user, email });
|
|
89
125
|
}
|
|
90
126
|
else {
|
|
91
|
-
process.stdout.write(
|
|
127
|
+
process.stdout.write("Login session validated and saved.\n");
|
|
92
128
|
process.stdout.write(`Logged in as: ${email}\n`);
|
|
93
129
|
}
|
|
94
130
|
}
|
|
95
131
|
catch (err) {
|
|
96
132
|
if (json) {
|
|
97
|
-
(0, format_1.outputJson)({ status:
|
|
133
|
+
(0, format_1.outputJson)({ status: "error", message: err.message });
|
|
98
134
|
}
|
|
99
135
|
else {
|
|
100
136
|
process.stderr.write(`Login failed: ${err.message}\n`);
|
|
@@ -102,29 +138,30 @@ async function main() {
|
|
|
102
138
|
}
|
|
103
139
|
});
|
|
104
140
|
program
|
|
105
|
-
.command(
|
|
106
|
-
.description(
|
|
141
|
+
.command("status")
|
|
142
|
+
.description("Show current login status")
|
|
107
143
|
.action(async () => {
|
|
108
144
|
const config = (0, config_1.loadConfig)();
|
|
109
145
|
const json = program.opts().json;
|
|
110
146
|
const session = (0, config_1.loadSession)();
|
|
111
147
|
if (!session.cookies) {
|
|
112
148
|
if (json) {
|
|
113
|
-
(0, format_1.outputJson)({ status:
|
|
149
|
+
(0, format_1.outputJson)({ status: "logged_out" });
|
|
114
150
|
}
|
|
115
151
|
else {
|
|
116
|
-
process.stdout.write(
|
|
152
|
+
process.stdout.write("Logged out (no session cookie).\n");
|
|
117
153
|
}
|
|
118
154
|
return;
|
|
119
155
|
}
|
|
120
156
|
try {
|
|
121
157
|
const user = await (0, auth_1.validateSession)(config, session);
|
|
122
|
-
const email = user.email ||
|
|
158
|
+
const email = user.email ||
|
|
159
|
+
user.username;
|
|
123
160
|
if (json) {
|
|
124
|
-
(0, format_1.outputJson)({ status:
|
|
161
|
+
(0, format_1.outputJson)({ status: "logged_in", user, email });
|
|
125
162
|
}
|
|
126
163
|
else {
|
|
127
|
-
process.stdout.write(
|
|
164
|
+
process.stdout.write("Logged in.\n");
|
|
128
165
|
if (email) {
|
|
129
166
|
process.stdout.write(`Email: ${email}\n`);
|
|
130
167
|
}
|
|
@@ -134,10 +171,10 @@ async function main() {
|
|
|
134
171
|
const error = err;
|
|
135
172
|
if (error.status && [401, 403].includes(error.status)) {
|
|
136
173
|
if (json) {
|
|
137
|
-
(0, format_1.outputJson)({ status:
|
|
174
|
+
(0, format_1.outputJson)({ status: "logged_out" });
|
|
138
175
|
}
|
|
139
176
|
else {
|
|
140
|
-
process.stdout.write(
|
|
177
|
+
process.stdout.write("Logged out.\n");
|
|
141
178
|
}
|
|
142
179
|
return;
|
|
143
180
|
}
|
|
@@ -145,9 +182,9 @@ async function main() {
|
|
|
145
182
|
}
|
|
146
183
|
});
|
|
147
184
|
program
|
|
148
|
-
.command(
|
|
149
|
-
.description(
|
|
150
|
-
.option(
|
|
185
|
+
.command("slots")
|
|
186
|
+
.description("Show the next available delivery slots")
|
|
187
|
+
.option("--limit <n>", "Limit number of slots", "10")
|
|
151
188
|
.action(async (options) => {
|
|
152
189
|
const config = (0, config_1.loadConfig)();
|
|
153
190
|
const session = requireSessionCookie();
|
|
@@ -162,7 +199,7 @@ async function main() {
|
|
|
162
199
|
return;
|
|
163
200
|
}
|
|
164
201
|
if (!limited.length) {
|
|
165
|
-
process.stdout.write(
|
|
202
|
+
process.stdout.write("No available delivery slots.\n");
|
|
166
203
|
return;
|
|
167
204
|
}
|
|
168
205
|
const today = new Date();
|
|
@@ -170,7 +207,7 @@ async function main() {
|
|
|
170
207
|
const tomorrow = new Date(today);
|
|
171
208
|
tomorrow.setDate(today.getDate() + 1);
|
|
172
209
|
const tomorrowDate = tomorrow.toISOString().slice(0, 10);
|
|
173
|
-
let currentDate =
|
|
210
|
+
let currentDate = "";
|
|
174
211
|
let printedHeader = false;
|
|
175
212
|
for (const slot of limited) {
|
|
176
213
|
if (slot.date !== currentDate) {
|
|
@@ -182,27 +219,30 @@ async function main() {
|
|
|
182
219
|
else if (currentDate === tomorrowDate) {
|
|
183
220
|
label = `Tomorrow (${currentDate})`;
|
|
184
221
|
}
|
|
185
|
-
const headerPrefix = printedHeader ?
|
|
222
|
+
const headerPrefix = printedHeader ? "\n" : "";
|
|
186
223
|
process.stdout.write(`${headerPrefix}${(0, format_1.formatHeading)(`# ${label}`)}\n`);
|
|
187
224
|
printedHeader = true;
|
|
188
225
|
}
|
|
189
226
|
process.stdout.write(`${(0, slots_1.formatSlotRange)(slot.start, slot.end)} (${(0, slots_1.formatLoadPercent)(slot.loadPercent)})\n`);
|
|
190
227
|
}
|
|
191
228
|
});
|
|
192
|
-
const product = program.command(
|
|
229
|
+
const product = program.command("product").description("Product operations");
|
|
193
230
|
product
|
|
194
|
-
.command(
|
|
195
|
-
.description(
|
|
196
|
-
.argument(
|
|
197
|
-
.option(
|
|
198
|
-
.option(
|
|
231
|
+
.command("search")
|
|
232
|
+
.description("Search for products")
|
|
233
|
+
.argument("<query>", "Search query")
|
|
234
|
+
.option("--limit <n>", "Limit number of results", "20")
|
|
235
|
+
.option("--page <n>", "Algolia page number (0-based)", "0")
|
|
199
236
|
.action(async (query, options) => {
|
|
200
237
|
const config = (0, config_1.loadConfig)();
|
|
201
238
|
const session = (0, config_1.loadSession)();
|
|
202
239
|
const json = program.opts().json;
|
|
203
240
|
const limit = Number(options.limit);
|
|
204
241
|
const page = Number(options.page);
|
|
205
|
-
const result = await (0, search_1.searchProducts)(config, session, query, {
|
|
242
|
+
const result = await (0, search_1.searchProducts)(config, session, query, {
|
|
243
|
+
limit,
|
|
244
|
+
page,
|
|
245
|
+
});
|
|
206
246
|
if (json) {
|
|
207
247
|
(0, format_1.outputJson)(result);
|
|
208
248
|
}
|
|
@@ -211,9 +251,9 @@ async function main() {
|
|
|
211
251
|
}
|
|
212
252
|
});
|
|
213
253
|
product
|
|
214
|
-
.command(
|
|
215
|
-
.description(
|
|
216
|
-
.argument(
|
|
254
|
+
.command("show")
|
|
255
|
+
.description("Get product details by ID")
|
|
256
|
+
.argument("<productId>", "Product ID")
|
|
217
257
|
.action(async (productId) => {
|
|
218
258
|
const config = (0, config_1.loadConfig)();
|
|
219
259
|
const session = (0, config_1.loadSession)();
|
|
@@ -226,14 +266,14 @@ async function main() {
|
|
|
226
266
|
(0, format_1.outputProductDetail)(result);
|
|
227
267
|
}
|
|
228
268
|
});
|
|
229
|
-
const order = program.command(
|
|
269
|
+
const order = program.command("order").description("Order operations");
|
|
230
270
|
order
|
|
231
|
-
.command(
|
|
232
|
-
.description(
|
|
233
|
-
.option(
|
|
234
|
-
.option(
|
|
235
|
-
.option(
|
|
236
|
-
.option(
|
|
271
|
+
.command("list")
|
|
272
|
+
.description("List recent orders")
|
|
273
|
+
.option("--limit <n>", "Limit number of results", "10")
|
|
274
|
+
.option("--page <n>", "Page number")
|
|
275
|
+
.option("--from <date>", "Filter from date (YYYY-MM-DD)")
|
|
276
|
+
.option("--to <date>", "Filter to date (YYYY-MM-DD)")
|
|
237
277
|
.action(async (options) => {
|
|
238
278
|
const config = (0, config_1.loadConfig)();
|
|
239
279
|
const session = requireSessionCookie();
|
|
@@ -248,25 +288,27 @@ async function main() {
|
|
|
248
288
|
from,
|
|
249
289
|
to,
|
|
250
290
|
});
|
|
291
|
+
(0, warnings_1.warnUnknownOrderStatuses)(result.results);
|
|
251
292
|
if (json) {
|
|
252
293
|
(0, format_1.outputJson)(result);
|
|
253
294
|
}
|
|
254
295
|
else if (!result.results.length) {
|
|
255
|
-
process.stdout.write(
|
|
296
|
+
process.stdout.write("No orders found.\n");
|
|
256
297
|
}
|
|
257
298
|
else {
|
|
258
299
|
(0, format_1.outputOrdersList)(result.results);
|
|
259
300
|
}
|
|
260
301
|
});
|
|
261
302
|
order
|
|
262
|
-
.command(
|
|
263
|
-
.description(
|
|
264
|
-
.argument(
|
|
303
|
+
.command("show")
|
|
304
|
+
.description("Show order details")
|
|
305
|
+
.argument("<orderId>", "Order ID")
|
|
265
306
|
.action(async (orderId) => {
|
|
266
307
|
const config = (0, config_1.loadConfig)();
|
|
267
308
|
const session = requireSessionCookie();
|
|
268
309
|
const json = program.opts().json;
|
|
269
310
|
const detail = await (0, orders_1.getOrderDetail)(config, session, String(orderId));
|
|
311
|
+
(0, warnings_1.warnUnknownOrderStatuses)([detail]);
|
|
270
312
|
if (json) {
|
|
271
313
|
(0, format_1.outputJson)(detail);
|
|
272
314
|
}
|
|
@@ -274,11 +316,11 @@ async function main() {
|
|
|
274
316
|
(0, format_1.outputOrderDetail)(detail);
|
|
275
317
|
}
|
|
276
318
|
});
|
|
277
|
-
const cart = program.command(
|
|
319
|
+
const cart = program.command("cart").description("Cart operations");
|
|
278
320
|
cart
|
|
279
|
-
.command(
|
|
280
|
-
.argument(
|
|
281
|
-
.option(
|
|
321
|
+
.command("add")
|
|
322
|
+
.argument("<productId>", "Product ID")
|
|
323
|
+
.option("--qty <n>", "Quantity", "1")
|
|
282
324
|
.action(async (productId, options) => {
|
|
283
325
|
const config = (0, config_1.loadConfig)();
|
|
284
326
|
const session = requireSessionCookie();
|
|
@@ -289,13 +331,13 @@ async function main() {
|
|
|
289
331
|
(0, format_1.outputJson)(result);
|
|
290
332
|
}
|
|
291
333
|
else {
|
|
292
|
-
process.stdout.write(
|
|
334
|
+
process.stdout.write("Added to cart.\n");
|
|
293
335
|
}
|
|
294
336
|
});
|
|
295
337
|
cart
|
|
296
|
-
.command(
|
|
297
|
-
.argument(
|
|
298
|
-
.option(
|
|
338
|
+
.command("update")
|
|
339
|
+
.argument("<productId>", "Product ID")
|
|
340
|
+
.option("--qty <n>", "Quantity", "1")
|
|
299
341
|
.action(async (productId, options) => {
|
|
300
342
|
const config = (0, config_1.loadConfig)();
|
|
301
343
|
const session = requireSessionCookie();
|
|
@@ -306,12 +348,12 @@ async function main() {
|
|
|
306
348
|
(0, format_1.outputJson)(result);
|
|
307
349
|
}
|
|
308
350
|
else {
|
|
309
|
-
process.stdout.write(
|
|
351
|
+
process.stdout.write("Cart updated.\n");
|
|
310
352
|
}
|
|
311
353
|
});
|
|
312
354
|
cart
|
|
313
|
-
.command(
|
|
314
|
-
.description(
|
|
355
|
+
.command("show")
|
|
356
|
+
.description("Show cart contents")
|
|
315
357
|
.action(async () => {
|
|
316
358
|
const config = (0, config_1.loadConfig)();
|
|
317
359
|
const session = requireSessionCookie();
|
|
@@ -327,8 +369,11 @@ async function main() {
|
|
|
327
369
|
const listItems = items
|
|
328
370
|
.map((item) => {
|
|
329
371
|
const entry = item;
|
|
330
|
-
const id = entry.product?.id ??
|
|
331
|
-
|
|
372
|
+
const id = entry.product?.id ??
|
|
373
|
+
entry.product_id ??
|
|
374
|
+
entry.productId ??
|
|
375
|
+
entry.id;
|
|
376
|
+
const name = entry.product?.name ?? entry.name ?? "Unknown";
|
|
332
377
|
const count = entry.quantity ?? entry.qty;
|
|
333
378
|
if (!id)
|
|
334
379
|
return null;
|
|
@@ -339,14 +384,14 @@ async function main() {
|
|
|
339
384
|
(0, format_1.outputList)(listItems);
|
|
340
385
|
}
|
|
341
386
|
else {
|
|
342
|
-
process.stdout.write(
|
|
387
|
+
process.stdout.write("Cart is empty.\n");
|
|
343
388
|
}
|
|
344
389
|
});
|
|
345
|
-
const list = program.command(
|
|
390
|
+
const list = program.command("list").description("List operations");
|
|
346
391
|
list
|
|
347
|
-
.command(
|
|
348
|
-
.description(
|
|
349
|
-
.argument(
|
|
392
|
+
.command("show")
|
|
393
|
+
.description("Show your lists")
|
|
394
|
+
.argument("[listId]", "List ID")
|
|
350
395
|
.action(async (listId) => {
|
|
351
396
|
const config = (0, config_1.loadConfig)();
|
|
352
397
|
const session = requireSessionCookie();
|
|
@@ -361,7 +406,7 @@ async function main() {
|
|
|
361
406
|
const results = Array.isArray(listItems.results)
|
|
362
407
|
? listItems.results
|
|
363
408
|
: [];
|
|
364
|
-
const count = typeof listItems.count ===
|
|
409
|
+
const count = typeof listItems.count === "number"
|
|
365
410
|
? listItems.count
|
|
366
411
|
: results.length;
|
|
367
412
|
if (json) {
|
|
@@ -376,7 +421,7 @@ async function main() {
|
|
|
376
421
|
else {
|
|
377
422
|
process.stdout.write(`${listEntry.name} (${listEntry.id})`);
|
|
378
423
|
if (!count) {
|
|
379
|
-
process.stdout.write(
|
|
424
|
+
process.stdout.write(" - empty\n");
|
|
380
425
|
return;
|
|
381
426
|
}
|
|
382
427
|
process.stdout.write(` - ${count} items\n`);
|
|
@@ -385,7 +430,7 @@ async function main() {
|
|
|
385
430
|
const entry = item;
|
|
386
431
|
const product = entry.product;
|
|
387
432
|
const id = product?.id ?? entry.product_id ?? entry.productId ?? entry.id;
|
|
388
|
-
const name = product?.name ?? entry.name ??
|
|
433
|
+
const name = product?.name ?? entry.name ?? "Unknown";
|
|
389
434
|
const itemCount = entry.quantity ?? entry.qty;
|
|
390
435
|
if (!id)
|
|
391
436
|
return null;
|
|
@@ -407,10 +452,10 @@ async function main() {
|
|
|
407
452
|
})));
|
|
408
453
|
});
|
|
409
454
|
list
|
|
410
|
-
.command(
|
|
411
|
-
.argument(
|
|
412
|
-
.argument(
|
|
413
|
-
.option(
|
|
455
|
+
.command("add")
|
|
456
|
+
.argument("<listId>", "List ID")
|
|
457
|
+
.argument("<productId>", "Product ID")
|
|
458
|
+
.option("--qty <n>", "Quantity", "1")
|
|
414
459
|
.action(async (listId, productId, options) => {
|
|
415
460
|
const config = (0, config_1.loadConfig)();
|
|
416
461
|
const session = requireSessionCookie();
|
|
@@ -421,7 +466,7 @@ async function main() {
|
|
|
421
466
|
(0, format_1.outputJson)(result);
|
|
422
467
|
}
|
|
423
468
|
else {
|
|
424
|
-
process.stdout.write(
|
|
469
|
+
process.stdout.write("Added to list.\n");
|
|
425
470
|
}
|
|
426
471
|
});
|
|
427
472
|
try {
|
|
@@ -429,8 +474,24 @@ async function main() {
|
|
|
429
474
|
}
|
|
430
475
|
catch (err) {
|
|
431
476
|
const json = program.opts().json;
|
|
477
|
+
const error = err;
|
|
478
|
+
(0, log_1.appendLog)({
|
|
479
|
+
level: "error",
|
|
480
|
+
event: "command.error",
|
|
481
|
+
command: lastCommand,
|
|
482
|
+
args: lastArgs,
|
|
483
|
+
json: Boolean(json),
|
|
484
|
+
pid: process.pid,
|
|
485
|
+
durationMs: Date.now() - lastStart,
|
|
486
|
+
configDir: (0, config_1.getConfigDir)(),
|
|
487
|
+
message: error.message,
|
|
488
|
+
status: error.status,
|
|
489
|
+
body: error.body,
|
|
490
|
+
url: error.url,
|
|
491
|
+
method: error.method,
|
|
492
|
+
});
|
|
432
493
|
if (json) {
|
|
433
|
-
(0, format_1.outputJson)({ status:
|
|
494
|
+
(0, format_1.outputJson)({ status: "error", ...formatError(err) });
|
|
434
495
|
}
|
|
435
496
|
else {
|
|
436
497
|
const details = formatError(err);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.warnUnknownOrderStatuses = warnUnknownOrderStatuses;
|
|
4
|
+
const order_status_1 = require("../lib/order-status");
|
|
5
|
+
const ISSUE_URL = "https://github.com/nb/ebag/issues";
|
|
6
|
+
function warnUnknownOrderStatuses(orders) {
|
|
7
|
+
for (const order of orders) {
|
|
8
|
+
const status = order.status;
|
|
9
|
+
if ((0, order_status_1.isKnownOrderStatus)(status) || status === undefined)
|
|
10
|
+
continue;
|
|
11
|
+
const orderId = order.id ? ` for order ${order.id}` : "";
|
|
12
|
+
process.stderr.write(`Warning: Unknown order status${orderId}. Please check this order on the website and file a GitHub issue so we can update the status mapping: ${ISSUE_URL}\n`);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/dist/lib/auth.d.ts
CHANGED
package/dist/lib/auth.js
CHANGED
|
@@ -5,13 +5,13 @@ exports.validateSession = validateSession;
|
|
|
5
5
|
const client_1 = require("./client");
|
|
6
6
|
function getLoginInstructions() {
|
|
7
7
|
return [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
"1) Log in to https://www.ebag.bg in your browser.",
|
|
9
|
+
"2) Open DevTools > Network and click any request to https://www.ebag.bg (not a static asset).",
|
|
10
|
+
"3) In the request headers, copy the full Cookie header value (semicolon-separated).",
|
|
11
11
|
'4) Run: ebag login --cookie "<cookie>"',
|
|
12
|
-
].join(
|
|
12
|
+
].join("\n");
|
|
13
13
|
}
|
|
14
14
|
async function validateSession(config, session) {
|
|
15
|
-
const result = await (0, client_1.requestEbag)(config, session,
|
|
15
|
+
const result = await (0, client_1.requestEbag)(config, session, "/user/json");
|
|
16
16
|
return result.data;
|
|
17
17
|
}
|
package/dist/lib/cart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Config, Session } from
|
|
1
|
+
import type { Config, Session } from "./types";
|
|
2
2
|
export declare function addToCart(config: Config, session: Session, productId: number, quantity: number, unitTypeOverride?: string): Promise<unknown>;
|
|
3
3
|
export declare function updateCart(config: Config, session: Session, productId: number, quantity: number, unitTypeOverride?: string): Promise<unknown>;
|
|
4
4
|
export declare function getCart(config: Config, session: Session): Promise<unknown>;
|
package/dist/lib/cart.js
CHANGED
|
@@ -4,17 +4,17 @@ exports.addToCart = addToCart;
|
|
|
4
4
|
exports.updateCart = updateCart;
|
|
5
5
|
exports.getCart = getCart;
|
|
6
6
|
const client_1 = require("./client");
|
|
7
|
-
async function addToCart(config, session, productId, quantity, unitTypeOverride =
|
|
8
|
-
const baseUrl = config.baseUrl ||
|
|
7
|
+
async function addToCart(config, session, productId, quantity, unitTypeOverride = "false") {
|
|
8
|
+
const baseUrl = config.baseUrl || "https://www.ebag.bg";
|
|
9
9
|
const body = new URLSearchParams({
|
|
10
10
|
product_id: String(productId),
|
|
11
11
|
quantity: String(quantity),
|
|
12
12
|
unit_type_override: unitTypeOverride,
|
|
13
13
|
});
|
|
14
|
-
const result = await (0, client_1.requestEbag)(config, session,
|
|
15
|
-
method:
|
|
14
|
+
const result = await (0, client_1.requestEbag)(config, session, "/cart/add", {
|
|
15
|
+
method: "POST",
|
|
16
16
|
headers: {
|
|
17
|
-
|
|
17
|
+
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
18
18
|
origin: baseUrl,
|
|
19
19
|
referer: `${baseUrl}/search/`,
|
|
20
20
|
},
|
|
@@ -22,17 +22,17 @@ async function addToCart(config, session, productId, quantity, unitTypeOverride
|
|
|
22
22
|
});
|
|
23
23
|
return result.data;
|
|
24
24
|
}
|
|
25
|
-
async function updateCart(config, session, productId, quantity, unitTypeOverride =
|
|
26
|
-
const baseUrl = config.baseUrl ||
|
|
25
|
+
async function updateCart(config, session, productId, quantity, unitTypeOverride = "false") {
|
|
26
|
+
const baseUrl = config.baseUrl || "https://www.ebag.bg";
|
|
27
27
|
const body = new URLSearchParams({
|
|
28
28
|
product_id: String(productId),
|
|
29
29
|
quantity: String(quantity),
|
|
30
30
|
unit_type_override: unitTypeOverride,
|
|
31
31
|
});
|
|
32
|
-
const result = await (0, client_1.requestEbag)(config, session,
|
|
33
|
-
method:
|
|
32
|
+
const result = await (0, client_1.requestEbag)(config, session, "/cart/update", {
|
|
33
|
+
method: "POST",
|
|
34
34
|
headers: {
|
|
35
|
-
|
|
35
|
+
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
36
36
|
origin: baseUrl,
|
|
37
37
|
referer: `${baseUrl}/search/`,
|
|
38
38
|
},
|
|
@@ -41,6 +41,6 @@ async function updateCart(config, session, productId, quantity, unitTypeOverride
|
|
|
41
41
|
return result.data;
|
|
42
42
|
}
|
|
43
43
|
async function getCart(config, session) {
|
|
44
|
-
const result = await (0, client_1.requestEbag)(config, session,
|
|
44
|
+
const result = await (0, client_1.requestEbag)(config, session, "/cart/json");
|
|
45
45
|
return result.data;
|
|
46
46
|
}
|
package/dist/lib/client.d.ts
CHANGED