playttm 0.0.7 → 0.0.9

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/dist/lib.js CHANGED
@@ -175,200 +175,370 @@ class ThaiTicketMajor {
175
175
  });
176
176
  }
177
177
  /**
178
- * Setup declarativeNetRequest session rules in Chrome Extension to set Referer header for API requests only.
178
+ * Setup declarativeNetRequest session rules for Chrome Extension environment.
179
+ * Overrides forbidden headers (Referer, Origin) to bypass TTM and Kasikorn referrer checks.
180
+ * Uses excludedInitiatorDomains to NEVER alter requests made directly by tabs on thaiticketmajor.com.
179
181
  */
180
- /**
181
- * Setup declarativeNetRequest session rules in Chrome Extension to set Referer headers accurately for each endpoint.
182
- */
183
- static setupExtensionRules() {
182
+ static setupExtensionRules(context) {
184
183
  return __awaiter(this, void 0, void 0, function* () {
185
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
184
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28;
186
185
  if (typeof chrome === "undefined" || !((_a = chrome === null || chrome === void 0 ? void 0 : chrome.declarativeNetRequest) === null || _a === void 0 ? void 0 : _a.updateSessionRules)) {
187
186
  return;
188
187
  }
188
+ const fixedReferer = ((context === null || context === void 0 ? void 0 : context.k) && (context === null || context === void 0 ? void 0 : context.zone) && (context === null || context === void 0 ? void 0 : context.roundId))
189
+ ? `https://booking.thaiticketmajor.com/booking/3m/fixed.php?k=${context.k}&zone=${context.zone}&round=${context.roundId}`
190
+ : "https://booking.thaiticketmajor.com/booking/3m/fixed.php";
191
+ const festivalReferer = ((context === null || context === void 0 ? void 0 : context.k) && (context === null || context === void 0 ? void 0 : context.zone) && (context === null || context === void 0 ? void 0 : context.roundId))
192
+ ? `https://booking.thaiticketmajor.com/booking/3m/festival.php?k=${context.k}&zone=${context.zone}&round=${context.roundId}`
193
+ : "https://booking.thaiticketmajor.com/booking/3m/festival.php";
194
+ const enrollReferer = ((context === null || context === void 0 ? void 0 : context.k) && (context === null || context === void 0 ? void 0 : context.zone) && (context === null || context === void 0 ? void 0 : context.roundId))
195
+ ? `https://booking.thaiticketmajor.com/booking/3m/enroll.php?k=${context.k}&zone=${context.zone}&round=${context.roundId}`
196
+ : "https://booking.thaiticketmajor.com/booking/3m/enroll.php";
197
+ const excludedDomains = ["booking.thaiticketmajor.com", "www.thaiticketmajor.com", "thaiticketmajor.com"];
189
198
  try {
190
- const ruleIdsToRemove = [1001, 1002, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019];
199
+ const ruleIdsToRemove = [
200
+ 1001, 1002, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019,
201
+ 1020, 1021, 1022, 1023
202
+ ];
191
203
  yield chrome.declarativeNetRequest.updateSessionRules({
192
204
  removeRuleIds: ruleIdsToRemove,
193
205
  addRules: [
194
206
  {
195
- id: 1010,
196
- priority: 20,
207
+ id: 1020,
208
+ priority: 25,
197
209
  action: {
198
210
  type: ((_b = chrome.declarativeNetRequest.RuleActionType) === null || _b === void 0 ? void 0 : _b.MODIFY_HEADERS) || "modifyHeaders",
199
211
  requestHeaders: [
200
212
  {
201
213
  header: "Referer",
202
214
  operation: ((_c = chrome.declarativeNetRequest.HeaderOperation) === null || _c === void 0 ? void 0 : _c.SET) || "set",
215
+ value: fixedReferer,
216
+ },
217
+ {
218
+ header: "Origin",
219
+ operation: ((_d = chrome.declarativeNetRequest.HeaderOperation) === null || _d === void 0 ? void 0 : _d.SET) || "set",
220
+ value: "https://booking.thaiticketmajor.com",
221
+ },
222
+ ],
223
+ },
224
+ condition: {
225
+ urlFilter: "bookingseats.php",
226
+ resourceTypes: [
227
+ ((_e = chrome.declarativeNetRequest.ResourceType) === null || _e === void 0 ? void 0 : _e.XMLHTTPREQUEST) || "xmlhttprequest",
228
+ ],
229
+ excludedInitiatorDomains: excludedDomains,
230
+ },
231
+ },
232
+ {
233
+ id: 1021,
234
+ priority: 25,
235
+ action: {
236
+ type: ((_f = chrome.declarativeNetRequest.RuleActionType) === null || _f === void 0 ? void 0 : _f.MODIFY_HEADERS) || "modifyHeaders",
237
+ requestHeaders: [
238
+ {
239
+ header: "Referer",
240
+ operation: ((_g = chrome.declarativeNetRequest.HeaderOperation) === null || _g === void 0 ? void 0 : _g.SET) || "set",
241
+ value: fixedReferer,
242
+ },
243
+ {
244
+ header: "Origin",
245
+ operation: ((_h = chrome.declarativeNetRequest.HeaderOperation) === null || _h === void 0 ? void 0 : _h.SET) || "set",
246
+ value: "https://booking.thaiticketmajor.com",
247
+ },
248
+ ],
249
+ },
250
+ condition: {
251
+ urlFilter: "validateseat.php",
252
+ resourceTypes: [
253
+ ((_j = chrome.declarativeNetRequest.ResourceType) === null || _j === void 0 ? void 0 : _j.XMLHTTPREQUEST) || "xmlhttprequest",
254
+ ],
255
+ excludedInitiatorDomains: excludedDomains,
256
+ },
257
+ },
258
+ {
259
+ id: 1022,
260
+ priority: 25,
261
+ action: {
262
+ type: ((_k = chrome.declarativeNetRequest.RuleActionType) === null || _k === void 0 ? void 0 : _k.MODIFY_HEADERS) || "modifyHeaders",
263
+ requestHeaders: [
264
+ {
265
+ header: "Referer",
266
+ operation: ((_l = chrome.declarativeNetRequest.HeaderOperation) === null || _l === void 0 ? void 0 : _l.SET) || "set",
267
+ value: festivalReferer,
268
+ },
269
+ {
270
+ header: "Origin",
271
+ operation: ((_m = chrome.declarativeNetRequest.HeaderOperation) === null || _m === void 0 ? void 0 : _m.SET) || "set",
272
+ value: "https://booking.thaiticketmajor.com",
273
+ },
274
+ ],
275
+ },
276
+ condition: {
277
+ urlFilter: "bookingfestival.php",
278
+ resourceTypes: [
279
+ ((_o = chrome.declarativeNetRequest.ResourceType) === null || _o === void 0 ? void 0 : _o.XMLHTTPREQUEST) || "xmlhttprequest",
280
+ ],
281
+ excludedInitiatorDomains: excludedDomains,
282
+ },
283
+ },
284
+ {
285
+ id: 1023,
286
+ priority: 25,
287
+ action: {
288
+ type: ((_p = chrome.declarativeNetRequest.RuleActionType) === null || _p === void 0 ? void 0 : _p.MODIFY_HEADERS) || "modifyHeaders",
289
+ requestHeaders: [
290
+ {
291
+ header: "Referer",
292
+ operation: ((_q = chrome.declarativeNetRequest.HeaderOperation) === null || _q === void 0 ? void 0 : _q.SET) || "set",
293
+ value: enrollReferer,
294
+ },
295
+ {
296
+ header: "Origin",
297
+ operation: ((_r = chrome.declarativeNetRequest.HeaderOperation) === null || _r === void 0 ? void 0 : _r.SET) || "set",
298
+ value: "https://booking.thaiticketmajor.com",
299
+ },
300
+ ],
301
+ },
302
+ condition: {
303
+ urlFilter: "enroll_process.php",
304
+ resourceTypes: [
305
+ ((_s = chrome.declarativeNetRequest.ResourceType) === null || _s === void 0 ? void 0 : _s.XMLHTTPREQUEST) || "xmlhttprequest",
306
+ ],
307
+ excludedInitiatorDomains: excludedDomains,
308
+ },
309
+ },
310
+ {
311
+ id: 1010,
312
+ priority: 20,
313
+ action: {
314
+ type: ((_t = chrome.declarativeNetRequest.RuleActionType) === null || _t === void 0 ? void 0 : _t.MODIFY_HEADERS) || "modifyHeaders",
315
+ requestHeaders: [
316
+ {
317
+ header: "Referer",
318
+ operation: ((_u = chrome.declarativeNetRequest.HeaderOperation) === null || _u === void 0 ? void 0 : _u.SET) || "set",
203
319
  value: "https://booking.thaiticketmajor.com/booking/3m/orderenc_kbankqr.php",
204
320
  },
321
+ {
322
+ header: "Origin",
323
+ operation: ((_v = chrome.declarativeNetRequest.HeaderOperation) === null || _v === void 0 ? void 0 : _v.SET) || "set",
324
+ value: "https://booking.thaiticketmajor.com",
325
+ },
205
326
  ],
206
327
  },
207
328
  condition: {
208
329
  urlFilter: "getkbankqr.php",
209
330
  resourceTypes: [
210
- ((_d = chrome.declarativeNetRequest.ResourceType) === null || _d === void 0 ? void 0 : _d.XMLHTTPREQUEST) || "xmlhttprequest",
331
+ ((_w = chrome.declarativeNetRequest.ResourceType) === null || _w === void 0 ? void 0 : _w.XMLHTTPREQUEST) || "xmlhttprequest",
211
332
  ],
333
+ excludedInitiatorDomains: excludedDomains,
212
334
  },
213
335
  },
214
336
  {
215
337
  id: 1011,
216
338
  priority: 20,
217
339
  action: {
218
- type: ((_e = chrome.declarativeNetRequest.RuleActionType) === null || _e === void 0 ? void 0 : _e.MODIFY_HEADERS) || "modifyHeaders",
340
+ type: ((_x = chrome.declarativeNetRequest.RuleActionType) === null || _x === void 0 ? void 0 : _x.MODIFY_HEADERS) || "modifyHeaders",
219
341
  requestHeaders: [
220
342
  {
221
343
  header: "Referer",
222
- operation: ((_f = chrome.declarativeNetRequest.HeaderOperation) === null || _f === void 0 ? void 0 : _f.SET) || "set",
344
+ operation: ((_y = chrome.declarativeNetRequest.HeaderOperation) === null || _y === void 0 ? void 0 : _y.SET) || "set",
223
345
  value: "https://booking.thaiticketmajor.com/booking/3m/orderenc_kbankqr.php",
224
346
  },
347
+ {
348
+ header: "Origin",
349
+ operation: ((_z = chrome.declarativeNetRequest.HeaderOperation) === null || _z === void 0 ? void 0 : _z.SET) || "set",
350
+ value: "https://booking.thaiticketmajor.com",
351
+ },
225
352
  ],
226
353
  },
227
354
  condition: {
228
355
  urlFilter: "payment_kbankqr.php",
229
356
  resourceTypes: [
230
- ((_g = chrome.declarativeNetRequest.ResourceType) === null || _g === void 0 ? void 0 : _g.XMLHTTPREQUEST) || "xmlhttprequest",
357
+ ((_0 = chrome.declarativeNetRequest.ResourceType) === null || _0 === void 0 ? void 0 : _0.XMLHTTPREQUEST) || "xmlhttprequest",
231
358
  ],
359
+ excludedInitiatorDomains: excludedDomains,
232
360
  },
233
361
  },
234
362
  {
235
363
  id: 1012,
236
364
  priority: 20,
237
365
  action: {
238
- type: ((_h = chrome.declarativeNetRequest.RuleActionType) === null || _h === void 0 ? void 0 : _h.MODIFY_HEADERS) || "modifyHeaders",
366
+ type: ((_1 = chrome.declarativeNetRequest.RuleActionType) === null || _1 === void 0 ? void 0 : _1.MODIFY_HEADERS) || "modifyHeaders",
239
367
  requestHeaders: [
240
368
  {
241
369
  header: "Referer",
242
- operation: ((_j = chrome.declarativeNetRequest.HeaderOperation) === null || _j === void 0 ? void 0 : _j.SET) || "set",
370
+ operation: ((_2 = chrome.declarativeNetRequest.HeaderOperation) === null || _2 === void 0 ? void 0 : _2.SET) || "set",
243
371
  value: "https://booking.thaiticketmajor.com/booking/3m/paycfmall.php",
244
372
  },
373
+ {
374
+ header: "Origin",
375
+ operation: ((_3 = chrome.declarativeNetRequest.HeaderOperation) === null || _3 === void 0 ? void 0 : _3.SET) || "set",
376
+ value: "https://booking.thaiticketmajor.com",
377
+ },
245
378
  ],
246
379
  },
247
380
  condition: {
248
381
  urlFilter: "orderenc_kbankqr.php",
249
382
  resourceTypes: [
250
- ((_k = chrome.declarativeNetRequest.ResourceType) === null || _k === void 0 ? void 0 : _k.XMLHTTPREQUEST) || "xmlhttprequest",
383
+ ((_4 = chrome.declarativeNetRequest.ResourceType) === null || _4 === void 0 ? void 0 : _4.XMLHTTPREQUEST) || "xmlhttprequest",
251
384
  ],
385
+ excludedInitiatorDomains: excludedDomains,
252
386
  },
253
387
  },
254
388
  {
255
389
  id: 1013,
256
390
  priority: 20,
257
391
  action: {
258
- type: ((_l = chrome.declarativeNetRequest.RuleActionType) === null || _l === void 0 ? void 0 : _l.MODIFY_HEADERS) || "modifyHeaders",
392
+ type: ((_5 = chrome.declarativeNetRequest.RuleActionType) === null || _5 === void 0 ? void 0 : _5.MODIFY_HEADERS) || "modifyHeaders",
259
393
  requestHeaders: [
260
394
  {
261
395
  header: "Referer",
262
- operation: ((_m = chrome.declarativeNetRequest.HeaderOperation) === null || _m === void 0 ? void 0 : _m.SET) || "set",
396
+ operation: ((_6 = chrome.declarativeNetRequest.HeaderOperation) === null || _6 === void 0 ? void 0 : _6.SET) || "set",
263
397
  value: "https://booking.thaiticketmajor.com/booking/3m/paymentall.php",
264
398
  },
399
+ {
400
+ header: "Origin",
401
+ operation: ((_7 = chrome.declarativeNetRequest.HeaderOperation) === null || _7 === void 0 ? void 0 : _7.SET) || "set",
402
+ value: "https://booking.thaiticketmajor.com",
403
+ },
265
404
  ],
266
405
  },
267
406
  condition: {
268
407
  urlFilter: "paycfmall.php",
269
408
  resourceTypes: [
270
- ((_o = chrome.declarativeNetRequest.ResourceType) === null || _o === void 0 ? void 0 : _o.XMLHTTPREQUEST) || "xmlhttprequest",
409
+ ((_8 = chrome.declarativeNetRequest.ResourceType) === null || _8 === void 0 ? void 0 : _8.XMLHTTPREQUEST) || "xmlhttprequest",
271
410
  ],
411
+ excludedInitiatorDomains: excludedDomains,
272
412
  },
273
413
  },
274
414
  {
275
415
  id: 1014,
276
416
  priority: 20,
277
417
  action: {
278
- type: ((_p = chrome.declarativeNetRequest.RuleActionType) === null || _p === void 0 ? void 0 : _p.MODIFY_HEADERS) || "modifyHeaders",
418
+ type: ((_9 = chrome.declarativeNetRequest.RuleActionType) === null || _9 === void 0 ? void 0 : _9.MODIFY_HEADERS) || "modifyHeaders",
279
419
  requestHeaders: [
280
420
  {
281
421
  header: "Referer",
282
- operation: ((_q = chrome.declarativeNetRequest.HeaderOperation) === null || _q === void 0 ? void 0 : _q.SET) || "set",
422
+ operation: ((_10 = chrome.declarativeNetRequest.HeaderOperation) === null || _10 === void 0 ? void 0 : _10.SET) || "set",
283
423
  value: "https://booking.thaiticketmajor.com/booking/3m/fixed.php",
284
424
  },
425
+ {
426
+ header: "Origin",
427
+ operation: ((_11 = chrome.declarativeNetRequest.HeaderOperation) === null || _11 === void 0 ? void 0 : _11.SET) || "set",
428
+ value: "https://booking.thaiticketmajor.com",
429
+ },
285
430
  ],
286
431
  },
287
432
  condition: {
288
433
  urlFilter: "paymentall.php",
289
434
  resourceTypes: [
290
- ((_r = chrome.declarativeNetRequest.ResourceType) === null || _r === void 0 ? void 0 : _r.XMLHTTPREQUEST) || "xmlhttprequest",
435
+ ((_12 = chrome.declarativeNetRequest.ResourceType) === null || _12 === void 0 ? void 0 : _12.XMLHTTPREQUEST) || "xmlhttprequest",
291
436
  ],
437
+ excludedInitiatorDomains: excludedDomains,
292
438
  },
293
439
  },
294
440
  {
295
441
  id: 1015,
296
442
  priority: 20,
297
443
  action: {
298
- type: ((_s = chrome.declarativeNetRequest.RuleActionType) === null || _s === void 0 ? void 0 : _s.MODIFY_HEADERS) || "modifyHeaders",
444
+ type: ((_13 = chrome.declarativeNetRequest.RuleActionType) === null || _13 === void 0 ? void 0 : _13.MODIFY_HEADERS) || "modifyHeaders",
299
445
  requestHeaders: [
300
446
  {
301
447
  header: "Referer",
302
- operation: ((_t = chrome.declarativeNetRequest.HeaderOperation) === null || _t === void 0 ? void 0 : _t.SET) || "set",
448
+ operation: ((_14 = chrome.declarativeNetRequest.HeaderOperation) === null || _14 === void 0 ? void 0 : _14.SET) || "set",
303
449
  value: "https://booking.thaiticketmajor.com/booking/3m/fixed.php",
304
450
  },
451
+ {
452
+ header: "Origin",
453
+ operation: ((_15 = chrome.declarativeNetRequest.HeaderOperation) === null || _15 === void 0 ? void 0 : _15.SET) || "set",
454
+ value: "https://booking.thaiticketmajor.com",
455
+ },
305
456
  ],
306
457
  },
307
458
  condition: {
308
- urlFilter: "enroll",
459
+ urlFilter: "enroll.php",
309
460
  resourceTypes: [
310
- ((_u = chrome.declarativeNetRequest.ResourceType) === null || _u === void 0 ? void 0 : _u.XMLHTTPREQUEST) || "xmlhttprequest",
461
+ ((_16 = chrome.declarativeNetRequest.ResourceType) === null || _16 === void 0 ? void 0 : _16.XMLHTTPREQUEST) || "xmlhttprequest",
311
462
  ],
463
+ excludedInitiatorDomains: excludedDomains,
312
464
  },
313
465
  },
314
466
  {
315
467
  id: 1018,
316
468
  priority: 20,
317
469
  action: {
318
- type: ((_v = chrome.declarativeNetRequest.RuleActionType) === null || _v === void 0 ? void 0 : _v.MODIFY_HEADERS) || "modifyHeaders",
470
+ type: ((_17 = chrome.declarativeNetRequest.RuleActionType) === null || _17 === void 0 ? void 0 : _17.MODIFY_HEADERS) || "modifyHeaders",
319
471
  requestHeaders: [
320
472
  {
321
473
  header: "Referer",
322
- operation: ((_w = chrome.declarativeNetRequest.HeaderOperation) === null || _w === void 0 ? void 0 : _w.SET) || "set",
474
+ operation: ((_18 = chrome.declarativeNetRequest.HeaderOperation) === null || _18 === void 0 ? void 0 : _18.SET) || "set",
323
475
  value: "https://booking.thaiticketmajor.com/booking/3m/zones.php",
324
476
  },
477
+ {
478
+ header: "Origin",
479
+ operation: ((_19 = chrome.declarativeNetRequest.HeaderOperation) === null || _19 === void 0 ? void 0 : _19.SET) || "set",
480
+ value: "https://booking.thaiticketmajor.com",
481
+ },
325
482
  ],
326
483
  },
327
484
  condition: {
328
485
  urlFilter: "zonesavail.php",
329
486
  resourceTypes: [
330
- ((_x = chrome.declarativeNetRequest.ResourceType) === null || _x === void 0 ? void 0 : _x.XMLHTTPREQUEST) || "xmlhttprequest",
487
+ ((_20 = chrome.declarativeNetRequest.ResourceType) === null || _20 === void 0 ? void 0 : _20.XMLHTTPREQUEST) || "xmlhttprequest",
331
488
  ],
489
+ excludedInitiatorDomains: excludedDomains,
332
490
  },
333
491
  },
334
492
  {
335
493
  id: 1002,
336
494
  priority: 20,
337
495
  action: {
338
- type: ((_y = chrome.declarativeNetRequest.RuleActionType) === null || _y === void 0 ? void 0 : _y.MODIFY_HEADERS) || "modifyHeaders",
496
+ type: ((_21 = chrome.declarativeNetRequest.RuleActionType) === null || _21 === void 0 ? void 0 : _21.MODIFY_HEADERS) || "modifyHeaders",
339
497
  requestHeaders: [
340
498
  {
341
499
  header: "Referer",
342
- operation: ((_z = chrome.declarativeNetRequest.HeaderOperation) === null || _z === void 0 ? void 0 : _z.SET) || "set",
500
+ operation: ((_22 = chrome.declarativeNetRequest.HeaderOperation) === null || _22 === void 0 ? void 0 : _22.SET) || "set",
343
501
  value: "https://kpaymentgateway.kasikornbank.com/",
344
502
  },
503
+ {
504
+ header: "Origin",
505
+ operation: ((_23 = chrome.declarativeNetRequest.HeaderOperation) === null || _23 === void 0 ? void 0 : _23.SET) || "set",
506
+ value: "https://kpaymentgateway.kasikornbank.com",
507
+ },
345
508
  ],
346
509
  },
347
510
  condition: {
348
511
  urlFilter: "kasikornbank.com",
349
512
  resourceTypes: [
350
- ((_0 = chrome.declarativeNetRequest.ResourceType) === null || _0 === void 0 ? void 0 : _0.XMLHTTPREQUEST) || "xmlhttprequest",
513
+ ((_24 = chrome.declarativeNetRequest.ResourceType) === null || _24 === void 0 ? void 0 : _24.XMLHTTPREQUEST) || "xmlhttprequest",
351
514
  ],
515
+ excludedInitiatorDomains: excludedDomains,
352
516
  },
353
517
  },
354
518
  {
355
519
  id: 1001,
356
520
  priority: 1,
357
521
  action: {
358
- type: ((_1 = chrome.declarativeNetRequest.RuleActionType) === null || _1 === void 0 ? void 0 : _1.MODIFY_HEADERS) || "modifyHeaders",
522
+ type: ((_25 = chrome.declarativeNetRequest.RuleActionType) === null || _25 === void 0 ? void 0 : _25.MODIFY_HEADERS) || "modifyHeaders",
359
523
  requestHeaders: [
360
524
  {
361
525
  header: "Referer",
362
- operation: ((_2 = chrome.declarativeNetRequest.HeaderOperation) === null || _2 === void 0 ? void 0 : _2.SET) || "set",
526
+ operation: ((_26 = chrome.declarativeNetRequest.HeaderOperation) === null || _26 === void 0 ? void 0 : _26.SET) || "set",
363
527
  value: "https://booking.thaiticketmajor.com/booking/3m/",
364
528
  },
529
+ {
530
+ header: "Origin",
531
+ operation: ((_27 = chrome.declarativeNetRequest.HeaderOperation) === null || _27 === void 0 ? void 0 : _27.SET) || "set",
532
+ value: "https://booking.thaiticketmajor.com",
533
+ },
365
534
  ],
366
535
  },
367
536
  condition: {
368
537
  urlFilter: "thaiticketmajor.com",
369
538
  resourceTypes: [
370
- ((_3 = chrome.declarativeNetRequest.ResourceType) === null || _3 === void 0 ? void 0 : _3.XMLHTTPREQUEST) || "xmlhttprequest",
539
+ ((_28 = chrome.declarativeNetRequest.ResourceType) === null || _28 === void 0 ? void 0 : _28.XMLHTTPREQUEST) || "xmlhttprequest",
371
540
  ],
541
+ excludedInitiatorDomains: excludedDomains,
372
542
  },
373
543
  },
374
544
  ],
@@ -399,36 +569,57 @@ class ThaiTicketMajor {
399
569
  */
400
570
  getRounds(eventUrl) {
401
571
  return __awaiter(this, void 0, void 0, function* () {
402
- this.emitProgress("GET_ROUNDS", `Fetching rounds from ${eventUrl}`);
403
- const response = yield this.client.get(eventUrl, {
404
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://www.thaiticketmajor.com/all-event/" }),
572
+ var _a, _b;
573
+ this.emitProgress("GET_ROUNDS", `Fetching rounds from ${eventUrl}`, {
574
+ url: eventUrl,
575
+ requestPayload: null,
405
576
  });
406
- const $ = cheerio.load(response.data);
407
- const rounds = [];
408
- $("a[data-button]").each((_, el) => {
409
- var _a, _b, _c, _d;
410
- const link = $(el);
411
- const href = (_a = link.attr("href")) !== null && _a !== void 0 ? _a : "";
412
- const onclick = (_b = link.attr("onclick")) !== null && _b !== void 0 ? _b : "";
413
- const dataUrl = (_c = link.attr("data-url")) !== null && _c !== void 0 ? _c : "";
414
- const dataHref = (_d = link.attr("data-href")) !== null && _d !== void 0 ? _d : "";
415
- const allLinkAttrs = `${href} ${onclick} ${dataUrl} ${dataHref}`;
416
- const queryMatch = allLinkAttrs.match(/query=([0-9a-zA-Z_-]+)/);
417
- const query = queryMatch ? queryMatch[1] : "";
418
- const time = link.find(".item-show").text().trim();
419
- const date = link.closest(".row").find(".date").text().trim();
420
- const isDisabled = link.is(":disabled") || link.attr("disabled") !== undefined || !query;
421
- rounds.push({
422
- id: query || link.attr("data-button") || "",
423
- label: `${date} ${time}`.trim(),
424
- date,
425
- time,
426
- url: href,
427
- query,
428
- isDisabled,
577
+ try {
578
+ const response = yield this.client.get(eventUrl, {
579
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://www.thaiticketmajor.com/all-event/" }),
429
580
  });
430
- });
431
- return rounds;
581
+ const $ = cheerio.load(response.data);
582
+ const rounds = [];
583
+ $("a[data-button]").each((_, el) => {
584
+ var _a, _b, _c, _d;
585
+ const link = $(el);
586
+ const href = (_a = link.attr("href")) !== null && _a !== void 0 ? _a : "";
587
+ const onclick = (_b = link.attr("onclick")) !== null && _b !== void 0 ? _b : "";
588
+ const dataUrl = (_c = link.attr("data-url")) !== null && _c !== void 0 ? _c : "";
589
+ const dataHref = (_d = link.attr("data-href")) !== null && _d !== void 0 ? _d : "";
590
+ const allLinkAttrs = `${href} ${onclick} ${dataUrl} ${dataHref}`;
591
+ const queryMatch = allLinkAttrs.match(/query=([0-9a-zA-Z_-]+)/);
592
+ const query = queryMatch ? queryMatch[1] : "";
593
+ const time = link.find(".item-show").text().trim();
594
+ const date = link.closest(".row").find(".date").text().trim();
595
+ const isDisabled = link.is(":disabled") || link.attr("disabled") !== undefined || !query;
596
+ rounds.push({
597
+ id: query || link.attr("data-button") || "",
598
+ label: `${date} ${time}`.trim(),
599
+ date,
600
+ time,
601
+ url: href,
602
+ query,
603
+ isDisabled,
604
+ });
605
+ });
606
+ this.emitProgress("GET_ROUNDS_RES", `Found ${rounds.length} rounds`, {
607
+ url: eventUrl,
608
+ requestPayload: null,
609
+ responseStatus: response.status,
610
+ responseData: rounds,
611
+ });
612
+ return rounds;
613
+ }
614
+ catch (err) {
615
+ this.emitProgress("GET_ROUNDS_ERR", `Failed to fetch rounds: ${err.message}`, {
616
+ url: eventUrl,
617
+ requestPayload: null,
618
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
619
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
620
+ });
621
+ throw err;
622
+ }
432
623
  });
433
624
  }
434
625
  /**
@@ -436,17 +627,40 @@ class ThaiTicketMajor {
436
627
  */
437
628
  verifyCheckCondition(query) {
438
629
  return __awaiter(this, void 0, void 0, function* () {
630
+ var _a, _b, _c;
439
631
  if (!query) {
440
632
  throw new Error("Query ID is missing. The selected round might be disabled or not open for sale yet.");
441
633
  }
442
- this.emitProgress("VERIFY_CONDITION", `Verifying condition for query ${query}`);
443
- const response = yield this.client.post(`${this.endpoint}/verify_checkcondition.php`, new URLSearchParams({
634
+ const url = `${this.endpoint}/verify_checkcondition.php`;
635
+ const payload = {
444
636
  rdagree: "1",
445
637
  rdId: "",
446
638
  autopopup: "",
447
639
  query: query,
448
- }), { headers: this.defaultHeaders });
449
- return response.data;
640
+ };
641
+ this.emitProgress("VERIFY_CONDITION", `Verifying condition for query ${query}`, {
642
+ url,
643
+ requestPayload: payload,
644
+ });
645
+ try {
646
+ const response = yield this.client.post(url, new URLSearchParams(payload), { headers: this.defaultHeaders });
647
+ this.emitProgress("VERIFY_CONDITION_RES", `Condition check: ${((_a = response.data) === null || _a === void 0 ? void 0 : _a.result) ? "PASS" : "FAIL"}`, {
648
+ url,
649
+ requestPayload: payload,
650
+ responseStatus: response.status,
651
+ responseData: response.data,
652
+ });
653
+ return response.data;
654
+ }
655
+ catch (err) {
656
+ this.emitProgress("VERIFY_CONDITION_ERR", `Condition check error: ${err.message}`, {
657
+ url,
658
+ requestPayload: payload,
659
+ responseStatus: (_b = err.response) === null || _b === void 0 ? void 0 : _b.status,
660
+ responseData: ((_c = err.response) === null || _c === void 0 ? void 0 : _c.data) || err.message,
661
+ });
662
+ throw err;
663
+ }
450
664
  });
451
665
  }
452
666
  /**
@@ -454,38 +668,61 @@ class ThaiTicketMajor {
454
668
  */
455
669
  getZones(query) {
456
670
  return __awaiter(this, void 0, void 0, function* () {
457
- this.emitProgress("GET_ZONES", `Fetching zone data and tokens for query ${query}`);
458
- const response = yield this.client.get(`${this.endpoint}/zones.php?query=${query}`, {
459
- headers: this.defaultHeaders,
460
- });
461
- const $ = cheerio.load(response.data);
462
- const rawInputs = {};
463
- $("#frm input[type='hidden']").each((_, el) => {
464
- var _a;
465
- const name = $(el).attr("name");
466
- const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
467
- if (name) {
468
- rawInputs[name] = value;
469
- }
671
+ var _a, _b;
672
+ const url = `${this.endpoint}/zones.php?query=${query}`;
673
+ this.emitProgress("GET_ZONES", `Fetching zone data and tokens for query ${query}`, {
674
+ url,
675
+ requestPayload: { query },
470
676
  });
471
- const rounds = $("#rdId option")
472
- .filter((_, el) => !!$(el).attr("value"))
473
- .map((_, el) => {
474
- var _a;
475
- const opt = $(el);
476
- return {
477
- id: (_a = opt.attr("value")) !== null && _a !== void 0 ? _a : "",
478
- label: opt.text().trim(),
677
+ try {
678
+ const response = yield this.client.get(url, {
679
+ headers: this.defaultHeaders,
680
+ });
681
+ const $ = cheerio.load(response.data);
682
+ const rawInputs = {};
683
+ $("#frm input[type='hidden']").each((_, el) => {
684
+ var _a;
685
+ const name = $(el).attr("name");
686
+ const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
687
+ if (name) {
688
+ rawInputs[name] = value;
689
+ }
690
+ });
691
+ const rounds = $("#rdId option")
692
+ .filter((_, el) => !!$(el).attr("value"))
693
+ .map((_, el) => {
694
+ var _a;
695
+ const opt = $(el);
696
+ return {
697
+ id: (_a = opt.attr("value")) !== null && _a !== void 0 ? _a : "",
698
+ label: opt.text().trim(),
699
+ };
700
+ })
701
+ .get();
702
+ const result = {
703
+ k: rawInputs["k"] || "",
704
+ tk: rawInputs["tk"] || "",
705
+ query,
706
+ rounds,
707
+ rawInputs,
479
708
  };
480
- })
481
- .get();
482
- return {
483
- k: rawInputs["k"] || "",
484
- tk: rawInputs["tk"] || "",
485
- query,
486
- rounds,
487
- rawInputs,
488
- };
709
+ this.emitProgress("GET_ZONES_RES", `Extracted tokens k=${result.k ? result.k.slice(0, 10) + '...' : 'none'} and ${rounds.length} rounds`, {
710
+ url,
711
+ requestPayload: { query },
712
+ responseStatus: response.status,
713
+ responseData: result,
714
+ });
715
+ return result;
716
+ }
717
+ catch (err) {
718
+ this.emitProgress("GET_ZONES_ERR", `Failed to get zones: ${err.message}`, {
719
+ url,
720
+ requestPayload: { query },
721
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
722
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
723
+ });
724
+ throw err;
725
+ }
489
726
  });
490
727
  }
491
728
  /**
@@ -493,43 +730,65 @@ class ThaiTicketMajor {
493
730
  */
494
731
  getZoneAvailability(roundId, tk, k, query) {
495
732
  return __awaiter(this, void 0, void 0, function* () {
496
- this.emitProgress("GET_ZONE_AVAIL", `Checking zone availability for round ${roundId}`);
497
- const response = yield this.client.get(`${this.endpoint}/zonesavail.php?round=${roundId}&tk=${tk}`, {
498
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?query=${query}` }),
733
+ var _a, _b;
734
+ const url = `${this.endpoint}/zonesavail.php?round=${roundId}&tk=${tk}`;
735
+ this.emitProgress("GET_ZONE_AVAIL", `Checking zone availability for round ${roundId}`, {
736
+ url,
737
+ requestPayload: { roundId, tk, query },
499
738
  });
500
- const $ = cheerio.load(response.data);
501
- const zones = [];
502
- $(".table tbody tr").each((_, el) => {
503
- var _a, _b, _c, _d;
504
- const row = $(el);
505
- const zoneId = (_a = row.find("td:nth-child(1) a").attr("id")) !== null && _a !== void 0 ? _a : "";
506
- const onclick = (_b = row.attr("onclick")) !== null && _b !== void 0 ? _b : "";
507
- const match = onclick.match(/gonextstep\('([^']+)','([^']+)'/);
508
- const page = ((_c = match === null || match === void 0 ? void 0 : match[1]) !== null && _c !== void 0 ? _c : "");
509
- const zoneValue = (_d = match === null || match === void 0 ? void 0 : match[2]) !== null && _d !== void 0 ? _d : "";
510
- const statusText = row.find("td:nth-child(2) a").text().trim();
511
- let available = 0;
512
- let isAvailable = false;
513
- if (statusText.toLowerCase() === "available") {
514
- available = 1;
515
- isAvailable = true;
516
- }
517
- else {
518
- const num = Number(statusText);
519
- if (!Number.isNaN(num) && num > 0) {
520
- available = num;
739
+ try {
740
+ const response = yield this.client.get(url, {
741
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?query=${query}` }),
742
+ });
743
+ const $ = cheerio.load(response.data);
744
+ const zones = [];
745
+ $(".table tbody tr").each((_, el) => {
746
+ var _a, _b, _c, _d;
747
+ const row = $(el);
748
+ const zoneId = (_a = row.find("td:nth-child(1) a").attr("id")) !== null && _a !== void 0 ? _a : "";
749
+ const onclick = (_b = row.attr("onclick")) !== null && _b !== void 0 ? _b : "";
750
+ const match = onclick.match(/gonextstep\('([^']+)','([^']+)'/);
751
+ const page = ((_c = match === null || match === void 0 ? void 0 : match[1]) !== null && _c !== void 0 ? _c : "");
752
+ const zoneValue = (_d = match === null || match === void 0 ? void 0 : match[2]) !== null && _d !== void 0 ? _d : "";
753
+ const statusText = row.find("td:nth-child(2) a").text().trim();
754
+ let available = 0;
755
+ let isAvailable = false;
756
+ if (statusText.toLowerCase() === "available") {
757
+ available = 1;
521
758
  isAvailable = true;
522
759
  }
523
- }
524
- zones.push({
525
- id: zoneId,
526
- value: zoneValue,
527
- available,
528
- page,
529
- isAvailable,
760
+ else {
761
+ const num = Number(statusText);
762
+ if (!Number.isNaN(num) && num > 0) {
763
+ available = num;
764
+ isAvailable = true;
765
+ }
766
+ }
767
+ zones.push({
768
+ id: zoneId,
769
+ value: zoneValue,
770
+ available,
771
+ page,
772
+ isAvailable,
773
+ });
530
774
  });
531
- });
532
- return zones;
775
+ this.emitProgress("GET_ZONE_AVAIL_RES", `Found ${zones.length} zones (${zones.filter(z => z.isAvailable).length} available)`, {
776
+ url,
777
+ requestPayload: { roundId, tk, query },
778
+ responseStatus: response.status,
779
+ responseData: zones,
780
+ });
781
+ return zones;
782
+ }
783
+ catch (err) {
784
+ this.emitProgress("GET_ZONE_AVAIL_ERR", `Failed to check zone availability: ${err.message}`, {
785
+ url,
786
+ requestPayload: { roundId, tk, query },
787
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
788
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
789
+ });
790
+ throw err;
791
+ }
533
792
  });
534
793
  }
535
794
  // --- Flow บัตรนั่ง (Fixed Seats) ---
@@ -538,31 +797,57 @@ class ThaiTicketMajor {
538
797
  */
539
798
  getFixedSeats(k, zone, roundId) {
540
799
  return __awaiter(this, void 0, void 0, function* () {
541
- this.emitProgress("GET_FIXED_SEATS", `Fetching seat layout for zone ${zone}`);
542
- const response = yield this.client.get(`${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}`, {
543
- headers: this.defaultHeaders,
544
- });
545
- const $ = cheerio.load(response.data);
546
- const seats = $("#tableseats .seatuncheck")
547
- .map((_, el) => {
548
- var _a, _b, _c;
549
- const seat = $(el);
550
- return {
551
- id: (_a = seat.attr("id")) !== null && _a !== void 0 ? _a : "",
552
- seat: (_b = seat.attr("data-seat")) !== null && _b !== void 0 ? _b : "",
553
- seatk: (_c = seat.attr("data-seatk")) !== null && _c !== void 0 ? _c : "",
554
- };
555
- })
556
- .get();
557
- const form = {};
558
- $("#frmPayment input").each((_, el) => {
559
- var _a;
560
- const name = $(el).attr("name");
561
- if (name) {
562
- form[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
563
- }
800
+ var _a, _b;
801
+ const url = `${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}`;
802
+ this.emitProgress("GET_FIXED_SEATS", `Fetching seat layout for zone ${zone}`, {
803
+ url,
804
+ requestPayload: { k, zone, roundId },
564
805
  });
565
- return { seats, form };
806
+ try {
807
+ const response = yield this.client.get(url, {
808
+ headers: this.defaultHeaders,
809
+ });
810
+ const $ = cheerio.load(response.data);
811
+ const seats = $("#tableseats .seatuncheck")
812
+ .map((_, el) => {
813
+ var _a, _b, _c;
814
+ const seat = $(el);
815
+ return {
816
+ id: (_a = seat.attr("id")) !== null && _a !== void 0 ? _a : "",
817
+ seat: (_b = seat.attr("data-seat")) !== null && _b !== void 0 ? _b : "",
818
+ seatk: (_c = seat.attr("data-seatk")) !== null && _c !== void 0 ? _c : "",
819
+ };
820
+ })
821
+ .get();
822
+ const form = {};
823
+ $("#frmPayment input").each((_, el) => {
824
+ var _a;
825
+ const name = $(el).attr("name");
826
+ if (name) {
827
+ form[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
828
+ }
829
+ });
830
+ this.emitProgress("GET_FIXED_SEATS_RES", `Found ${seats.length} available seats in zone ${zone}`, {
831
+ url,
832
+ requestPayload: { k, zone, roundId },
833
+ responseStatus: response.status,
834
+ responseData: {
835
+ seatsCount: seats.length,
836
+ seatsSample: seats.slice(0, 10),
837
+ form,
838
+ },
839
+ });
840
+ return { seats, form };
841
+ }
842
+ catch (err) {
843
+ this.emitProgress("GET_FIXED_SEATS_ERR", `Failed to get fixed seats: ${err.message}`, {
844
+ url,
845
+ requestPayload: { k, zone, roundId },
846
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
847
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
848
+ });
849
+ throw err;
850
+ }
566
851
  });
567
852
  }
568
853
  /**
@@ -570,7 +855,8 @@ class ThaiTicketMajor {
570
855
  */
571
856
  validateFixedSeats(k_1, zone_1, payload_1, chkSeats_1) {
572
857
  return __awaiter(this, arguments, void 0, function* (k, zone, payload, chkSeats, bookType = "fix") {
573
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
858
+ var _a, _b;
859
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
574
860
  this.emitProgress("VALIDATE_FIXED_SEATS", `Validating ${chkSeats.length} fixed seats`);
575
861
  let lastResponse = null;
576
862
  const accumulatedSeats = [];
@@ -583,27 +869,27 @@ class ThaiTicketMajor {
583
869
  for (const seat of accumulatedSeats) {
584
870
  formData.append("chkSeats[]", seat);
585
871
  }
586
- formData.append("ehId", (_a = payload.ehId) !== null && _a !== void 0 ? _a : "");
587
- formData.append("curentdate", (_b = payload.curentdate) !== null && _b !== void 0 ? _b : "");
588
- formData.append("max_payment", (_c = payload.max_payment) !== null && _c !== void 0 ? _c : "6");
589
- formData.append("payment_cnt", (_d = payload.payment_cnt) !== null && _d !== void 0 ? _d : "0");
590
- formData.append("paytype", (_e = payload.paytype) !== null && _e !== void 0 ? _e : "BOAI");
591
- formData.append("performance", (_f = payload.performance) !== null && _f !== void 0 ? _f : "");
872
+ formData.append("ehId", (_c = payload.ehId) !== null && _c !== void 0 ? _c : "");
873
+ formData.append("curentdate", (_d = payload.curentdate) !== null && _d !== void 0 ? _d : "");
874
+ formData.append("max_payment", (_e = payload.max_payment) !== null && _e !== void 0 ? _e : "6");
875
+ formData.append("payment_cnt", (_f = payload.payment_cnt) !== null && _f !== void 0 ? _f : "0");
876
+ formData.append("paytype", (_g = payload.paytype) !== null && _g !== void 0 ? _g : "BOAI");
877
+ formData.append("performance", (_h = payload.performance) !== null && _h !== void 0 ? _h : "");
592
878
  formData.append("pricelist", "");
593
- formData.append("rdId", (_g = payload.rdId) !== null && _g !== void 0 ? _g : "");
879
+ formData.append("rdId", (_j = payload.rdId) !== null && _j !== void 0 ? _j : "");
594
880
  formData.append("seatlist", "");
595
- formData.append("showdate", (_h = payload.showdate) !== null && _h !== void 0 ? _h : "");
596
- formData.append("showtime", (_j = payload.showtime) !== null && _j !== void 0 ? _j : "");
597
- formData.append("venue", (_k = payload.venue) !== null && _k !== void 0 ? _k : "");
598
- formData.append("zone", (_l = payload.zone) !== null && _l !== void 0 ? _l : "");
599
- formData.append("zoneDesc", (_m = payload.zoneDesc) !== null && _m !== void 0 ? _m : "");
881
+ formData.append("showdate", (_k = payload.showdate) !== null && _k !== void 0 ? _k : "");
882
+ formData.append("showtime", (_l = payload.showtime) !== null && _l !== void 0 ? _l : "");
883
+ formData.append("venue", (_m = payload.venue) !== null && _m !== void 0 ? _m : "");
884
+ formData.append("zone", (_o = payload.zone) !== null && _o !== void 0 ? _o : "");
885
+ formData.append("zoneDesc", (_p = payload.zoneDesc) !== null && _p !== void 0 ? _p : "");
600
886
  formData.append("travelChild1", "");
601
887
  formData.append("travelChild2", "");
602
888
  formData.append("travelChild2", "");
603
- formData.append("enroll_val", (_o = payload.enroll_val) !== null && _o !== void 0 ? _o : "");
604
- formData.append("dval", (_p = payload.dval) !== null && _p !== void 0 ? _p : "");
605
- formData.append("companyid", (_q = payload.companyid) !== null && _q !== void 0 ? _q : "");
606
- formData.append("ks", (_r = payload.ks) !== null && _r !== void 0 ? _r : "");
889
+ formData.append("enroll_val", (_q = payload.enroll_val) !== null && _q !== void 0 ? _q : "");
890
+ formData.append("dval", (_r = payload.dval) !== null && _r !== void 0 ? _r : "");
891
+ formData.append("companyid", (_s = payload.companyid) !== null && _s !== void 0 ? _s : "");
892
+ formData.append("ks", (_t = payload.ks) !== null && _t !== void 0 ? _t : "");
607
893
  formData.append("inclvat", "");
608
894
  const seatParts = currentSeat.seat.split("-");
609
895
  const row = seatParts[0];
@@ -611,12 +897,31 @@ class ThaiTicketMajor {
611
897
  formData.append("row", row);
612
898
  formData.append("seat", seatNo);
613
899
  formData.append("book_type", bookType);
614
- const response = yield this.client.post(`${this.endpoint}/validateseat.php?k=${k}&zw=${zone}`, formData.toString(), {
615
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
616
- });
617
- lastResponse = response.data;
618
- if (!lastResponse.result) {
619
- throw new Error(`Validate seat failed (${currentSeat.seat}): ${lastResponse.message || "Unknown error"}`);
900
+ const url = `${this.endpoint}/validateseat.php?k=${k}&zw=${zone}`;
901
+ const reqPayloadObj = Object.fromEntries(formData.entries());
902
+ try {
903
+ const response = yield this.client.post(url, formData.toString(), {
904
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
905
+ });
906
+ lastResponse = response.data;
907
+ this.emitProgress("VALIDATE_FIXED_SEATS_RES", `Seat validated (${currentSeat.seat}): ${(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.result) ? "SUCCESS" : "FAIL"}`, {
908
+ url,
909
+ requestPayload: reqPayloadObj,
910
+ responseStatus: response.status,
911
+ responseData: lastResponse,
912
+ });
913
+ if (!lastResponse.result) {
914
+ throw new Error(`Validate seat failed (${currentSeat.seat}): ${lastResponse.message || "Unknown error"}`);
915
+ }
916
+ }
917
+ catch (err) {
918
+ this.emitProgress("VALIDATE_FIXED_SEATS_ERR", `Validate seat failed (${currentSeat.seat}): ${err.message}`, {
919
+ url,
920
+ requestPayload: reqPayloadObj,
921
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
922
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
923
+ });
924
+ throw err;
620
925
  }
621
926
  }
622
927
  return lastResponse;
@@ -627,6 +932,7 @@ class ThaiTicketMajor {
627
932
  */
628
933
  bookFixedSeats(k, payload, seats) {
629
934
  return __awaiter(this, void 0, void 0, function* () {
935
+ var _a, _b;
630
936
  this.emitProgress("BOOK_FIXED_SEATS", `Booking fixed seats`);
631
937
  let pricelistvalue = "";
632
938
  let seatlistvalue = "";
@@ -661,13 +967,32 @@ class ThaiTicketMajor {
661
967
  bodyParams.set("ks", "");
662
968
  bodyParams.set("inclvat", "");
663
969
  bodyParams.set("seatklist", seatklistvalue);
664
- const response = yield this.client.post(`${this.endpoint}/bookingseats.php?k=${k}`, bodyParams.toString(), {
665
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { accept: "application/json, text/javascript, */*; q=0.01", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}`, origin: "https://booking.thaiticketmajor.com" }),
666
- });
667
- return {
668
- data: response.data,
669
- nextPayload: bodyParams,
670
- };
970
+ const url = `${this.endpoint}/bookingseats.php?k=${k}`;
971
+ const reqPayloadObj = Object.fromEntries(bodyParams.entries());
972
+ try {
973
+ const response = yield this.client.post(url, bodyParams.toString(), {
974
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { accept: "application/json, text/javascript, */*; q=0.01", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}`, origin: "https://booking.thaiticketmajor.com" }),
975
+ });
976
+ this.emitProgress("BOOK_FIXED_SEATS_RES", `Book fixed seats completed`, {
977
+ url,
978
+ requestPayload: reqPayloadObj,
979
+ responseStatus: response.status,
980
+ responseData: response.data,
981
+ });
982
+ return {
983
+ data: response.data,
984
+ nextPayload: bodyParams,
985
+ };
986
+ }
987
+ catch (err) {
988
+ this.emitProgress("BOOK_FIXED_SEATS_ERR", `Booking seats error: ${err.message}`, {
989
+ url,
990
+ requestPayload: reqPayloadObj,
991
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
992
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
993
+ });
994
+ throw err;
995
+ }
671
996
  });
672
997
  }
673
998
  // --- Flow บัตรยืน (Festival / Standing) ---
@@ -676,20 +1001,42 @@ class ThaiTicketMajor {
676
1001
  */
677
1002
  getFestival(k, tk, query, zone, roundId) {
678
1003
  return __awaiter(this, void 0, void 0, function* () {
679
- this.emitProgress("GET_FESTIVAL", `Fetching festival zone ${zone}`);
680
- const response = yield this.client.get(`${this.endpoint}/festival.php?k=${k}&zone=${zone}&round=${roundId}`, {
681
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?rdId=${roundId}&k=${k}&tk=${tk}&query=${query}` }),
682
- });
683
- const $ = cheerio.load(response.data);
684
- const formData = {};
685
- $("#frm input").each((_, el) => {
686
- var _a;
687
- const name = $(el).attr("name");
688
- if (name) {
689
- formData[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
690
- }
1004
+ var _a, _b;
1005
+ const url = `${this.endpoint}/festival.php?k=${k}&zone=${zone}&round=${roundId}`;
1006
+ this.emitProgress("GET_FESTIVAL", `Fetching festival zone ${zone}`, {
1007
+ url,
1008
+ requestPayload: { k, tk, query, zone, roundId },
691
1009
  });
692
- return formData;
1010
+ try {
1011
+ const response = yield this.client.get(url, {
1012
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?rdId=${roundId}&k=${k}&tk=${tk}&query=${query}` }),
1013
+ });
1014
+ const $ = cheerio.load(response.data);
1015
+ const formData = {};
1016
+ $("#frm input").each((_, el) => {
1017
+ var _a;
1018
+ const name = $(el).attr("name");
1019
+ if (name) {
1020
+ formData[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
1021
+ }
1022
+ });
1023
+ this.emitProgress("GET_FESTIVAL_RES", `Loaded festival form (${Object.keys(formData).length} fields)`, {
1024
+ url,
1025
+ requestPayload: { k, tk, query, zone, roundId },
1026
+ responseStatus: response.status,
1027
+ responseData: formData,
1028
+ });
1029
+ return formData;
1030
+ }
1031
+ catch (err) {
1032
+ this.emitProgress("GET_FESTIVAL_ERR", `Failed to get festival page: ${err.message}`, {
1033
+ url,
1034
+ requestPayload: { k, tk, query, zone, roundId },
1035
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1036
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1037
+ });
1038
+ throw err;
1039
+ }
693
1040
  });
694
1041
  }
695
1042
  /**
@@ -697,13 +1044,32 @@ class ThaiTicketMajor {
697
1044
  */
698
1045
  validateFestivalSeats(k, payload, ticketCount) {
699
1046
  return __awaiter(this, void 0, void 0, function* () {
1047
+ var _a, _b, _c;
700
1048
  this.emitProgress("VALIDATE_FESTIVAL", `Validating ${ticketCount} festival tickets`);
701
1049
  const preparePayload = Object.assign(Object.assign({}, payload), { book_cnt: ticketCount.toString(), book_type: "fest" });
702
1050
  const formData = new URLSearchParams(preparePayload);
703
- const response = yield this.client.post(`${this.endpoint}/validateseat.php?k=${k}&zw=${payload.zone}`, formData.toString(), {
704
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
705
- });
706
- return response.data;
1051
+ const url = `${this.endpoint}/validateseat.php?k=${k}&zw=${payload.zone}`;
1052
+ try {
1053
+ const response = yield this.client.post(url, formData.toString(), {
1054
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
1055
+ });
1056
+ this.emitProgress("VALIDATE_FESTIVAL_RES", `Validate festival tickets: ${((_a = response.data) === null || _a === void 0 ? void 0 : _a.result) ? "SUCCESS" : "FAIL"}`, {
1057
+ url,
1058
+ requestPayload: preparePayload,
1059
+ responseStatus: response.status,
1060
+ responseData: response.data,
1061
+ });
1062
+ return response.data;
1063
+ }
1064
+ catch (err) {
1065
+ this.emitProgress("VALIDATE_FESTIVAL_ERR", `Validate festival error: ${err.message}`, {
1066
+ url,
1067
+ requestPayload: preparePayload,
1068
+ responseStatus: (_b = err.response) === null || _b === void 0 ? void 0 : _b.status,
1069
+ responseData: ((_c = err.response) === null || _c === void 0 ? void 0 : _c.data) || err.message,
1070
+ });
1071
+ throw err;
1072
+ }
707
1073
  });
708
1074
  }
709
1075
  /**
@@ -711,13 +1077,32 @@ class ThaiTicketMajor {
711
1077
  */
712
1078
  bookFestivalSeats(k, payload, ticketCount) {
713
1079
  return __awaiter(this, void 0, void 0, function* () {
1080
+ var _a, _b;
714
1081
  this.emitProgress("BOOK_FESTIVAL", `Booking ${ticketCount} festival tickets`);
715
1082
  const preparePayload = Object.assign(Object.assign({}, payload), { book_cnt: ticketCount.toString() });
716
1083
  const formData = new URLSearchParams(preparePayload);
717
- const response = yield this.client.post(`${this.endpoint}/bookingfestival.php?k=${k}`, formData.toString(), {
718
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
719
- });
720
- return response.data;
1084
+ const url = `${this.endpoint}/bookingfestival.php?k=${k}`;
1085
+ try {
1086
+ const response = yield this.client.post(url, formData.toString(), {
1087
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
1088
+ });
1089
+ this.emitProgress("BOOK_FESTIVAL_RES", `Book festival tickets completed`, {
1090
+ url,
1091
+ requestPayload: preparePayload,
1092
+ responseStatus: response.status,
1093
+ responseData: response.data,
1094
+ });
1095
+ return response.data;
1096
+ }
1097
+ catch (err) {
1098
+ this.emitProgress("BOOK_FESTIVAL_ERR", `Book festival error: ${err.message}`, {
1099
+ url,
1100
+ requestPayload: preparePayload,
1101
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1102
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1103
+ });
1104
+ throw err;
1105
+ }
721
1106
  });
722
1107
  }
723
1108
  // --- Flow การลงทะเบียนผู้เข้าชม (Enrollment) ---
@@ -726,20 +1111,42 @@ class ThaiTicketMajor {
726
1111
  */
727
1112
  enroll(k, zone, roundId, payload) {
728
1113
  return __awaiter(this, void 0, void 0, function* () {
729
- this.emitProgress("GET_ENROLL", `Fetching enrollment form`);
730
- const response = yield this.client.post(`${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}`, payload.toString(), {
731
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}` }),
732
- });
733
- const $ = cheerio.load(response.data);
734
- const formData = {};
735
- $("#form input, #form select").each((_, el) => {
736
- var _a, _b;
737
- const name = $(el).attr("name");
738
- if (name) {
739
- formData[name] = (_b = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : $(el).find("option:selected").attr("value")) !== null && _b !== void 0 ? _b : "";
740
- }
1114
+ var _a, _b;
1115
+ const url = `${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}`;
1116
+ this.emitProgress("GET_ENROLL", `Fetching enrollment form`, {
1117
+ url,
1118
+ requestPayload: payload.toString(),
741
1119
  });
742
- return formData;
1120
+ try {
1121
+ const response = yield this.client.post(url, payload.toString(), {
1122
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}` }),
1123
+ });
1124
+ const $ = cheerio.load(response.data);
1125
+ const formData = {};
1126
+ $("#form input, #form select").each((_, el) => {
1127
+ var _a, _b;
1128
+ const name = $(el).attr("name");
1129
+ if (name) {
1130
+ formData[name] = (_b = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : $(el).find("option:selected").attr("value")) !== null && _b !== void 0 ? _b : "";
1131
+ }
1132
+ });
1133
+ this.emitProgress("GET_ENROLL_RES", `Loaded enrollment form (${Object.keys(formData).length} fields)`, {
1134
+ url,
1135
+ requestPayload: payload.toString(),
1136
+ responseStatus: response.status,
1137
+ responseData: formData,
1138
+ });
1139
+ return formData;
1140
+ }
1141
+ catch (err) {
1142
+ this.emitProgress("GET_ENROLL_ERR", `Enroll form error: ${err.message}`, {
1143
+ url,
1144
+ requestPayload: payload.toString(),
1145
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1146
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1147
+ });
1148
+ throw err;
1149
+ }
743
1150
  });
744
1151
  }
745
1152
  /**
@@ -747,8 +1154,13 @@ class ThaiTicketMajor {
747
1154
  */
748
1155
  enrollProcess(k, payload, attendees) {
749
1156
  return __awaiter(this, void 0, void 0, function* () {
750
- var _a;
751
- this.emitProgress("ENROLL_PROCESS", `Submitting info for ${attendees.length} attendees`);
1157
+ var _a, _b;
1158
+ var _c;
1159
+ const url = `${this.endpoint}/enroll_process.php?k=${k}`;
1160
+ this.emitProgress("ENROLL_PROCESS", `Submitting info for ${attendees.length} attendees`, {
1161
+ url,
1162
+ requestPayload: { attendeesCount: attendees.length, attendees },
1163
+ });
752
1164
  const formData = new URLSearchParams();
753
1165
  for (const user of attendees) {
754
1166
  formData.append("txt_fullname[]", user.fullname || "");
@@ -757,7 +1169,7 @@ class ThaiTicketMajor {
757
1169
  formData.append("txt_lastname[]", user.lastname || "");
758
1170
  formData.append("txt_phone[]", user.phone || "");
759
1171
  formData.append("sel_options[]", user.options || "");
760
- formData.append("zones[]", (_a = payload.zone) !== null && _a !== void 0 ? _a : "");
1172
+ formData.append("zones[]", (_c = payload.zone) !== null && _c !== void 0 ? _c : "");
761
1173
  }
762
1174
  const excludedKeys = new Set([
763
1175
  "txt_fullname[]",
@@ -773,13 +1185,31 @@ class ThaiTicketMajor {
773
1185
  formData.append(key, value !== undefined && value !== null ? String(value) : "");
774
1186
  }
775
1187
  }
776
- const response = yield this.client.post(`${this.endpoint}/enroll_process.php?k=${k}`, formData.toString(), {
777
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
778
- });
779
- return {
780
- data: response.data,
781
- nextPayload: formData,
782
- };
1188
+ const reqPayloadObj = Object.fromEntries(formData.entries());
1189
+ try {
1190
+ const response = yield this.client.post(url, formData.toString(), {
1191
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
1192
+ });
1193
+ this.emitProgress("ENROLL_PROCESS_RES", `Enrollment processed successfully`, {
1194
+ url,
1195
+ requestPayload: reqPayloadObj,
1196
+ responseStatus: response.status,
1197
+ responseData: response.data,
1198
+ });
1199
+ return {
1200
+ data: response.data,
1201
+ nextPayload: formData,
1202
+ };
1203
+ }
1204
+ catch (err) {
1205
+ this.emitProgress("ENROLL_PROCESS_ERR", `Enrollment error: ${err.message}`, {
1206
+ url,
1207
+ requestPayload: reqPayloadObj,
1208
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1209
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1210
+ });
1211
+ throw err;
1212
+ }
783
1213
  });
784
1214
  }
785
1215
  // --- Flow การชำระเงิน (Payment) ---
@@ -788,51 +1218,73 @@ class ThaiTicketMajor {
788
1218
  */
789
1219
  getPaymentDetails(k_1, formData_1, zone_1, roundId_1) {
790
1220
  return __awaiter(this, arguments, void 0, function* (k, formData, zone, roundId, delayMs = 1000) {
791
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
792
- var _k, _l, _m, _o, _p, _q, _r, _s, _t;
793
- this.emitProgress("GET_PAYMENT_DETAILS", `Loading payment confirmation page`);
1221
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1222
+ var _m, _o, _p, _q, _r, _s, _t, _u, _v;
1223
+ const url = `${this.endpoint}/paymentall.php?k=${k}`;
794
1224
  const body = formData instanceof URLSearchParams ? formData.toString() : new URLSearchParams(formData).toString();
795
- const response = yield this.client.post(`${this.endpoint}/paymentall.php?k=${k}`, body, {
796
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}` }),
1225
+ const reqPayloadObj = formData instanceof URLSearchParams ? Object.fromEntries(formData.entries()) : formData;
1226
+ this.emitProgress("GET_PAYMENT_DETAILS", `Loading payment confirmation page`, {
1227
+ url,
1228
+ requestPayload: reqPayloadObj,
797
1229
  });
798
- const $ = cheerio.load(response.data);
799
- const hiddenInputs = {};
800
- $("#frm-confirm input").each((_, el) => {
801
- var _a;
802
- var _b, _c;
803
- const key = (_b = $(el).attr("name")) !== null && _b !== void 0 ? _b : $(el).attr("id");
804
- if (key) {
805
- hiddenInputs[key] = (_c = (_a = $(el).val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _c !== void 0 ? _c : "";
1230
+ try {
1231
+ const response = yield this.client.post(url, body, {
1232
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}` }),
1233
+ });
1234
+ const $ = cheerio.load(response.data);
1235
+ const hiddenInputs = {};
1236
+ $("#frm-confirm input").each((_, el) => {
1237
+ var _a;
1238
+ var _b, _c;
1239
+ const key = (_b = $(el).attr("name")) !== null && _b !== void 0 ? _b : $(el).attr("id");
1240
+ if (key) {
1241
+ hiddenInputs[key] = (_c = (_a = $(el).val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _c !== void 0 ? _c : "";
1242
+ }
1243
+ });
1244
+ const addressForm = $("#frm-address");
1245
+ if (addressForm.length > 0) {
1246
+ const fname = (_m = (_a = addressForm.find("input[name='c_fname_m']").val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _m !== void 0 ? _m : "";
1247
+ const lname = (_o = (_b = addressForm.find("input[name='c_lname_m']").val()) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _o !== void 0 ? _o : "";
1248
+ const address = (_p = (_c = addressForm.find("textarea[name='c_address_m']").val()) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _p !== void 0 ? _p : "";
1249
+ const ctId = (_q = (_d = addressForm.find("select[name='c_ctCode'] option:selected").val()) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _q !== void 0 ? _q : "";
1250
+ const pvId = (_r = (_e = addressForm.find("select[name='c_pvId'] option:selected").val()) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _r !== void 0 ? _r : "";
1251
+ const amId = (_s = (_f = addressForm.find("select[name='c_amId'] option:selected").val()) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _s !== void 0 ? _s : "";
1252
+ const zipcode = (_t = (_g = addressForm.find("input[name='c_PostCode']").val()) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _t !== void 0 ? _t : "";
1253
+ let rawPhone = (_u = (_h = addressForm.find("input[name='c_ContactRecipient']").val()) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _u !== void 0 ? _u : "";
1254
+ if (rawPhone.startsWith("66")) {
1255
+ rawPhone = rawPhone.slice(2);
1256
+ }
1257
+ const phoneArea = (_v = (_j = addressForm.find("input[name='telephoneArea']").val()) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _v !== void 0 ? _v : "66";
1258
+ hiddenInputs["adr_fname"] = fname;
1259
+ hiddenInputs["adr_lname"] = lname;
1260
+ hiddenInputs["adr_address"] = address;
1261
+ hiddenInputs["adr_ctId"] = ctId;
1262
+ hiddenInputs["adr_pvId"] = pvId;
1263
+ hiddenInputs["adr_amId"] = amId;
1264
+ hiddenInputs["adr_zipcode"] = zipcode;
1265
+ hiddenInputs["adr_mobile"] = rawPhone.replace(/(\d{2})(\d{3})(\d{4})/, "$1 $2 $3");
1266
+ hiddenInputs["adr_mobilearea"] = phoneArea;
806
1267
  }
807
- });
808
- const addressForm = $("#frm-address");
809
- if (addressForm.length > 0) {
810
- const fname = (_k = (_a = addressForm.find("input[name='c_fname_m']").val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _k !== void 0 ? _k : "";
811
- const lname = (_l = (_b = addressForm.find("input[name='c_lname_m']").val()) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _l !== void 0 ? _l : "";
812
- const address = (_m = (_c = addressForm.find("textarea[name='c_address_m']").val()) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _m !== void 0 ? _m : "";
813
- const ctId = (_o = (_d = addressForm.find("select[name='c_ctCode'] option:selected").val()) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _o !== void 0 ? _o : "";
814
- const pvId = (_p = (_e = addressForm.find("select[name='c_pvId'] option:selected").val()) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _p !== void 0 ? _p : "";
815
- const amId = (_q = (_f = addressForm.find("select[name='c_amId'] option:selected").val()) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _q !== void 0 ? _q : "";
816
- const zipcode = (_r = (_g = addressForm.find("input[name='c_PostCode']").val()) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _r !== void 0 ? _r : "";
817
- let rawPhone = (_s = (_h = addressForm.find("input[name='c_ContactRecipient']").val()) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _s !== void 0 ? _s : "";
818
- if (rawPhone.startsWith("66")) {
819
- rawPhone = rawPhone.slice(2);
1268
+ this.emitProgress("GET_PAYMENT_DETAILS_RES", `Loaded payment confirmation details (${Object.keys(hiddenInputs).length} fields)`, {
1269
+ url,
1270
+ requestPayload: reqPayloadObj,
1271
+ responseStatus: response.status,
1272
+ responseData: hiddenInputs,
1273
+ });
1274
+ if (delayMs > 0) {
1275
+ yield new Promise((resolve) => setTimeout(resolve, delayMs));
820
1276
  }
821
- const phoneArea = (_t = (_j = addressForm.find("input[name='telephoneArea']").val()) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _t !== void 0 ? _t : "66";
822
- hiddenInputs["adr_fname"] = fname;
823
- hiddenInputs["adr_lname"] = lname;
824
- hiddenInputs["adr_address"] = address;
825
- hiddenInputs["adr_ctId"] = ctId;
826
- hiddenInputs["adr_pvId"] = pvId;
827
- hiddenInputs["adr_amId"] = amId;
828
- hiddenInputs["adr_zipcode"] = zipcode;
829
- hiddenInputs["adr_mobile"] = rawPhone.replace(/(\d{2})(\d{3})(\d{4})/, "$1 $2 $3");
830
- hiddenInputs["adr_mobilearea"] = phoneArea;
1277
+ return hiddenInputs;
831
1278
  }
832
- if (delayMs > 0) {
833
- yield new Promise((resolve) => setTimeout(resolve, delayMs));
1279
+ catch (err) {
1280
+ this.emitProgress("GET_PAYMENT_DETAILS_ERR", `Payment details error: ${err.message}`, {
1281
+ url,
1282
+ requestPayload: reqPayloadObj,
1283
+ responseStatus: (_k = err.response) === null || _k === void 0 ? void 0 : _k.status,
1284
+ responseData: ((_l = err.response) === null || _l === void 0 ? void 0 : _l.data) || err.message,
1285
+ });
1286
+ throw err;
834
1287
  }
835
- return hiddenInputs;
836
1288
  });
837
1289
  }
838
1290
  /**
@@ -840,7 +1292,8 @@ class ThaiTicketMajor {
840
1292
  */
841
1293
  confirmPayment(k_1, payload_1) {
842
1294
  return __awaiter(this, arguments, void 0, function* (k, payload, deliver = "1", payType = "KBQR") {
843
- this.emitProgress("CONFIRM_PAYMENT", `Calculating total and confirming payment (${payType})`);
1295
+ var _a, _b;
1296
+ const url = `${this.endpoint}/paycfmall.php?k=${k}`;
844
1297
  const cntTicket = parseInt(payload.cal_cntticket || "0", 10);
845
1298
  const amountCode = parseFloat(payload.amountcode || "0");
846
1299
  const deliverFee = parseFloat(payload.cal_deliverfee || payload.val_deliverfee || "80");
@@ -850,26 +1303,47 @@ class ThaiTicketMajor {
850
1303
  const ticketFee = cntTicket * 191; // Ticket Fee 191 THB per ticket
851
1304
  const totalAmount = amountCode + deliverFee + ticketFee + addCharge - discount - voucher;
852
1305
  const computedPayload = Object.assign(Object.assign({}, payload), { paytype: payType, deliver: deliver, cal_ticketfee: ticketFee.toString(), cal_totalamount: Math.round(totalAmount).toString() });
1306
+ this.emitProgress("CONFIRM_PAYMENT", `Calculating total and confirming payment (${payType})`, {
1307
+ url,
1308
+ requestPayload: computedPayload,
1309
+ });
853
1310
  const formData = new URLSearchParams();
854
1311
  for (const [key, value] of Object.entries(computedPayload)) {
855
1312
  if (key !== "check-protect") {
856
1313
  formData.append(key, value !== undefined && value !== null ? String(value) : "");
857
1314
  }
858
1315
  }
859
- const response = yield this.client.post(`${this.endpoint}/paycfmall.php?k=${k}`, formData.toString(), {
860
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paymentall.php?k=${k}` }),
861
- });
862
- const $ = cheerio.load(response.data);
863
- const nextJsonData = {};
864
- $("#payallfrm input[type='hidden']").each((_, el) => {
865
- var _a;
866
- const name = $(el).attr("name");
867
- const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
868
- if (name) {
869
- nextJsonData[name] = value;
870
- }
871
- });
872
- return nextJsonData;
1316
+ try {
1317
+ const response = yield this.client.post(url, formData.toString(), {
1318
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paymentall.php?k=${k}` }),
1319
+ });
1320
+ const $ = cheerio.load(response.data);
1321
+ const nextJsonData = {};
1322
+ $("#payallfrm input[type='hidden']").each((_, el) => {
1323
+ var _a;
1324
+ const name = $(el).attr("name");
1325
+ const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
1326
+ if (name) {
1327
+ nextJsonData[name] = value;
1328
+ }
1329
+ });
1330
+ this.emitProgress("CONFIRM_PAYMENT_RES", `Confirmed payment (Total: ฿${computedPayload.cal_totalamount})`, {
1331
+ url,
1332
+ requestPayload: computedPayload,
1333
+ responseStatus: response.status,
1334
+ responseData: nextJsonData,
1335
+ });
1336
+ return nextJsonData;
1337
+ }
1338
+ catch (err) {
1339
+ this.emitProgress("CONFIRM_PAYMENT_ERR", `Payment confirmation error: ${err.message}`, {
1340
+ url,
1341
+ requestPayload: computedPayload,
1342
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1343
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1344
+ });
1345
+ throw err;
1346
+ }
873
1347
  });
874
1348
  }
875
1349
  /**
@@ -877,28 +1351,44 @@ class ThaiTicketMajor {
877
1351
  */
878
1352
  orderEncKBankQR(k, payCfmData) {
879
1353
  return __awaiter(this, void 0, void 0, function* () {
880
- this.emitProgress("ORDER_ENC_KBANK", `Encrypting order payload for KBank`);
881
- const formData = new URLSearchParams(payCfmData);
882
- const response = yield this.client.post(`${this.endpoint}/orderenc_kbankqr.php`, formData.toString(), {
883
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paycfmall.php?k=${k}` }),
884
- });
885
- this.emitProgress("ORDER_ENC_KBANK_RES", `Received orderenc_kbankqr.php response`, {
886
- url: `${this.endpoint}/orderenc_kbankqr.php`,
1354
+ var _a, _b;
1355
+ const url = `${this.endpoint}/orderenc_kbankqr.php`;
1356
+ this.emitProgress("ORDER_ENC_KBANK", `Encrypting order payload for KBank`, {
1357
+ url,
887
1358
  requestPayload: payCfmData,
888
- responseStatus: response.status,
889
- responseData: response.data,
890
- });
891
- const $ = cheerio.load(response.data);
892
- const kbankqrData = {};
893
- $("#kbankqr input[type='hidden']").each((_, el) => {
894
- var _a;
895
- const name = $(el).attr("name");
896
- const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
897
- if (name) {
898
- kbankqrData[name] = value;
899
- }
900
1359
  });
901
- return kbankqrData;
1360
+ const formData = new URLSearchParams(payCfmData);
1361
+ try {
1362
+ const response = yield this.client.post(url, formData.toString(), {
1363
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paycfmall.php?k=${k}` }),
1364
+ });
1365
+ const $ = cheerio.load(response.data);
1366
+ const kbankqrData = {};
1367
+ $("#kbankqr input[type='hidden']").each((_, el) => {
1368
+ var _a;
1369
+ const name = $(el).attr("name");
1370
+ const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
1371
+ if (name) {
1372
+ kbankqrData[name] = value;
1373
+ }
1374
+ });
1375
+ this.emitProgress("ORDER_ENC_KBANK_RES", `Received orderenc_kbankqr.php response`, {
1376
+ url,
1377
+ requestPayload: payCfmData,
1378
+ responseStatus: response.status,
1379
+ responseData: Object.keys(kbankqrData).length > 0 ? kbankqrData : response.data,
1380
+ });
1381
+ return kbankqrData;
1382
+ }
1383
+ catch (err) {
1384
+ this.emitProgress("ORDER_ENC_KBANK_ERR", `Order encrypt error: ${err.message}`, {
1385
+ url,
1386
+ requestPayload: payCfmData,
1387
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1388
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1389
+ });
1390
+ throw err;
1391
+ }
902
1392
  });
903
1393
  }
904
1394
  /**
@@ -906,18 +1396,34 @@ class ThaiTicketMajor {
906
1396
  */
907
1397
  getKBankQR(orderEncData) {
908
1398
  return __awaiter(this, void 0, void 0, function* () {
909
- this.emitProgress("GET_KBANK_QR", `Calling KBank Gateway info`);
910
- const formData = new URLSearchParams(orderEncData);
911
- const response = yield this.client.post(`${this.endpoint}/getkbankqr.php`, formData.toString(), {
912
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
913
- });
914
- this.emitProgress("GET_KBANK_QR_RES", `Received getkbankqr.php response`, {
915
- url: `${this.endpoint}/getkbankqr.php`,
1399
+ var _a, _b;
1400
+ const url = `${this.endpoint}/getkbankqr.php`;
1401
+ this.emitProgress("GET_KBANK_QR", `Calling KBank Gateway info`, {
1402
+ url,
916
1403
  requestPayload: orderEncData,
917
- responseStatus: response.status,
918
- responseData: response.data,
919
1404
  });
920
- return response.data;
1405
+ const formData = new URLSearchParams(orderEncData);
1406
+ try {
1407
+ const response = yield this.client.post(url, formData.toString(), {
1408
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
1409
+ });
1410
+ this.emitProgress("GET_KBANK_QR_RES", `Received getkbankqr.php response`, {
1411
+ url,
1412
+ requestPayload: orderEncData,
1413
+ responseStatus: response.status,
1414
+ responseData: response.data,
1415
+ });
1416
+ return response.data;
1417
+ }
1418
+ catch (err) {
1419
+ this.emitProgress("GET_KBANK_QR_ERR", `Get KBank QR error: ${err.message}`, {
1420
+ url,
1421
+ requestPayload: orderEncData,
1422
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1423
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1424
+ });
1425
+ throw err;
1426
+ }
921
1427
  });
922
1428
  }
923
1429
  /**
@@ -926,26 +1432,42 @@ class ThaiTicketMajor {
926
1432
  paymentKBankQR(orderEncData, kbankPayload) {
927
1433
  return __awaiter(this, void 0, void 0, function* () {
928
1434
  var _a, _b;
929
- this.emitProgress("PAYMENT_KBANK_QR", `Extracting KBank OrderID and API Key`);
1435
+ var _c, _d;
930
1436
  const preparePayload = Object.assign(Object.assign({}, orderEncData), { reasoncode: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.reasoncode, eventname: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.eventname, rounddetail: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.rounddetail, totalamount: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.totalamount, orderstatus: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.orderstatus, kbankqr_txExpiry: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.kbankqr_txExpiry });
931
- const formData = new URLSearchParams(preparePayload);
932
- const response = yield this.client.post(`${this.endpoint}/payment_kbankqr.php`, formData.toString(), {
933
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
934
- });
935
- this.emitProgress("PAYMENT_KBANK_QR_RES", `Received payment_kbankqr.php response`, {
936
- url: `${this.endpoint}/payment_kbankqr.php`,
1437
+ const url = `${this.endpoint}/payment_kbankqr.php`;
1438
+ this.emitProgress("PAYMENT_KBANK_QR", `Extracting KBank OrderID and API Key`, {
1439
+ url,
937
1440
  requestPayload: preparePayload,
938
- responseStatus: response.status,
939
- responseData: response.data,
940
1441
  });
941
- const $ = cheerio.load(response.data);
942
- const script = $("#kbankpost script[data-order-id]");
943
- const orderId = (_a = script.attr("data-order-id")) !== null && _a !== void 0 ? _a : "";
944
- const apiKey = (_b = script.attr("data-apikey")) !== null && _b !== void 0 ? _b : "";
945
- if (!orderId || !apiKey) {
946
- throw new Error("Unable to extract KBank orderId or apiKey from response");
1442
+ const formData = new URLSearchParams(preparePayload);
1443
+ try {
1444
+ const response = yield this.client.post(url, formData.toString(), {
1445
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
1446
+ });
1447
+ const $ = cheerio.load(response.data);
1448
+ const script = $("#kbankpost script[data-order-id]");
1449
+ const orderId = (_c = script.attr("data-order-id")) !== null && _c !== void 0 ? _c : "";
1450
+ const apiKey = (_d = script.attr("data-apikey")) !== null && _d !== void 0 ? _d : "";
1451
+ this.emitProgress("PAYMENT_KBANK_QR_RES", `Received payment_kbankqr.php response (OrderID: ${orderId || "N/A"})`, {
1452
+ url,
1453
+ requestPayload: preparePayload,
1454
+ responseStatus: response.status,
1455
+ responseData: orderId && apiKey ? { orderId, apiKey, htmlSnippet: $("#kbankpost").html() } : response.data,
1456
+ });
1457
+ if (!orderId || !apiKey) {
1458
+ throw new Error("Unable to extract KBank orderId or apiKey from response");
1459
+ }
1460
+ return { orderId, apiKey };
1461
+ }
1462
+ catch (err) {
1463
+ this.emitProgress("PAYMENT_KBANK_QR_ERR", `Payment KBank QR error: ${err.message}`, {
1464
+ url,
1465
+ requestPayload: preparePayload,
1466
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1467
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1468
+ });
1469
+ throw err;
947
1470
  }
948
- return { orderId, apiKey };
949
1471
  });
950
1472
  }
951
1473
  /**
@@ -953,7 +1475,8 @@ class ThaiTicketMajor {
953
1475
  */
954
1476
  generateThaiQR(orderId, apiKey, amount) {
955
1477
  return __awaiter(this, void 0, void 0, function* () {
956
- this.emitProgress("GENERATE_THAI_QR", `Requesting ThaiQR code from Kasikorn Bank`);
1478
+ var _a, _b;
1479
+ const url = "https://kpaymentgateway-services.kasikornbank.com/qr/v2/qr";
957
1480
  const payload = {
958
1481
  amount: amount,
959
1482
  currency: "THB",
@@ -961,10 +1484,31 @@ class ThaiTicketMajor {
961
1484
  order_id: orderId,
962
1485
  sof: "ThaiQR",
963
1486
  };
964
- const response = yield this.client.post("https://kpaymentgateway-services.kasikornbank.com/qr/v2/qr", payload, {
965
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://kpaymentgateway.kasikornbank.com/", "x-api-key": apiKey }),
1487
+ this.emitProgress("GENERATE_THAI_QR", `Requesting ThaiQR code from Kasikorn Bank`, {
1488
+ url,
1489
+ requestPayload: payload,
966
1490
  });
967
- return response.data;
1491
+ try {
1492
+ const response = yield this.client.post(url, payload, {
1493
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://kpaymentgateway.kasikornbank.com/", "x-api-key": apiKey }),
1494
+ });
1495
+ this.emitProgress("GENERATE_THAI_QR_RES", `Received ThaiQR from Kasikorn Bank`, {
1496
+ url,
1497
+ requestPayload: payload,
1498
+ responseStatus: response.status,
1499
+ responseData: response.data,
1500
+ });
1501
+ return response.data;
1502
+ }
1503
+ catch (err) {
1504
+ this.emitProgress("GENERATE_THAI_QR_ERR", `Kasikorn ThaiQR error: ${err.message}`, {
1505
+ url,
1506
+ requestPayload: payload,
1507
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1508
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1509
+ });
1510
+ throw err;
1511
+ }
968
1512
  });
969
1513
  }
970
1514
  // ==========================================
@@ -1045,6 +1589,13 @@ class ThaiTicketMajor {
1045
1589
  let paymentAllData;
1046
1590
  // 5. ดำเนินการตามประเภทโซน (Fixed vs Festival)
1047
1591
  if (targetZone.page === "fixed.php") {
1592
+ if (this.inBrowser) {
1593
+ yield ThaiTicketMajor.setupExtensionRules({
1594
+ k: zoneData.k,
1595
+ zone: targetZone.value,
1596
+ roundId: targetPerformRound.id,
1597
+ });
1598
+ }
1048
1599
  const fixedData = yield this.getFixedSeats(zoneData.k, targetZone.value, targetPerformRound.id);
1049
1600
  const availableSeats = fixedData.seats;
1050
1601
  if (availableSeats.length < ticketCount) {
@@ -1087,6 +1638,13 @@ class ThaiTicketMajor {
1087
1638
  }
1088
1639
  else {
1089
1640
  // Festival Flow
1641
+ if (this.inBrowser) {
1642
+ yield ThaiTicketMajor.setupExtensionRules({
1643
+ k: zoneData.k,
1644
+ zone: targetZone.value,
1645
+ roundId: targetPerformRound.id,
1646
+ });
1647
+ }
1090
1648
  const festivalForm = yield this.getFestival(zoneData.k, zoneData.tk, selectedRound.query, targetZone.value, targetPerformRound.id);
1091
1649
  yield this.validateFestivalSeats(zoneData.k, festivalForm, ticketCount);
1092
1650
  const bookingFestivalRes = yield this.bookFestivalSeats(zoneData.k, festivalForm, ticketCount);