@agenzo/merchant-cli 0.8.6 → 0.8.7

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/index.js CHANGED
@@ -60,6 +60,8 @@ var CODE_NUM = {
60
60
  PAY_PER_CALL_NOT_AVAILABLE: 4308,
61
61
  HOTEL_NOT_FOUND: 4309,
62
62
  BOOKING_RESTRICTED: 4310,
63
+ PAYORDER_FAILED: 4311,
64
+ PAYORDER_FAILED_AFTER_PAYMENT: 4312,
63
65
  RATE_LIMITED: 5001,
64
66
  UPSTREAM_ERROR: 5101,
65
67
  INTERNAL_ERROR: 5201,
@@ -77,13 +79,14 @@ function codeNum(code) {
77
79
  return CODE_NUM[code];
78
80
  }
79
81
  var CliError = class _CliError extends Error {
80
- constructor(code, message, statusCode, requestId, upstream, backendMessage) {
82
+ constructor(code, message, statusCode, requestId, upstream, backendMessage, data) {
81
83
  super(message);
82
84
  this.code = code;
83
85
  this.statusCode = statusCode;
84
86
  this.requestId = requestId;
85
87
  this.upstream = upstream;
86
88
  this.backendMessage = backendMessage;
89
+ this.data = data;
87
90
  this.name = "CliError";
88
91
  }
89
92
  code;
@@ -91,6 +94,7 @@ var CliError = class _CliError extends Error {
91
94
  requestId;
92
95
  upstream;
93
96
  backendMessage;
97
+ data;
94
98
  /**
95
99
  * Map a backend ApiError to a CLI-facing code (§8.5 transitional mapping).
96
100
  * Backend numeric codes / HTTP status are translated to §8.4 string codes.
@@ -124,7 +128,8 @@ var CliError = class _CliError extends Error {
124
128
  error.statusCode,
125
129
  error.requestId,
126
130
  error.upstream,
127
- error.errorMessage
131
+ error.errorMessage,
132
+ error.data
128
133
  );
129
134
  }
130
135
  const status = error.statusCode;
@@ -142,7 +147,8 @@ var CliError = class _CliError extends Error {
142
147
  status,
143
148
  error.requestId,
144
149
  error.upstream,
145
- error.errorMessage
150
+ error.errorMessage,
151
+ error.data
146
152
  );
147
153
  }
148
154
  };
@@ -241,8 +247,15 @@ var STABLE_MESSAGE = {
241
247
  PAY_PER_CALL_NOT_AVAILABLE: "Pay-per-call billing is not available; use monthly_settlement.",
242
248
  HOTEL_NOT_FOUND: "This hotel is no longer available from the supplier.",
243
249
  BOOKING_RESTRICTED: "This room has a booking condition that your request doesn't meet. Please check the room's booking rules and adjust your request.",
250
+ PAYORDER_FAILED: "The hotel order was created, but payment failed. Retry payment for the existing order.",
251
+ PAYORDER_FAILED_AFTER_PAYMENT: "Payment was received, but hotel confirmation failed. Contact support for reconciliation.",
244
252
  NOT_IMPLEMENTED: "This operation is not implemented yet."
245
253
  };
254
+ function errorDetailLines(envelope) {
255
+ const orderId = envelope.error.data?.order_id;
256
+ if (typeof orderId !== "string" || orderId.length === 0) return [];
257
+ return [` Order: ${orderId}`];
258
+ }
246
259
  function toErrorEnvelope(error) {
247
260
  if (error instanceof CliError) {
248
261
  const stableMessage = error.message || "Unknown error";
@@ -254,7 +267,8 @@ function toErrorEnvelope(error) {
254
267
  message: stableMessage,
255
268
  ...error.requestId ? { request_id: error.requestId } : {},
256
269
  ...error.upstream ? { upstream: error.upstream } : {},
257
- ...backendMessage ? { backend_message: backendMessage } : {}
270
+ ...backendMessage ? { backend_message: backendMessage } : {},
271
+ ...error.data ? { data: error.data } : {}
258
272
  }
259
273
  };
260
274
  }
@@ -472,7 +486,8 @@ var ApiClient = class {
472
486
  }
473
487
  }
474
488
  const errorCodeStr = responseBody.error_code;
475
- const rawData = responseBody.data;
489
+ const dataValue = responseBody.data;
490
+ const rawData = dataValue && typeof dataValue === "object" && !Array.isArray(dataValue) ? dataValue : void 0;
476
491
  const upstream = rawData?.upstream && typeof rawData.upstream === "object" ? rawData.upstream : void 0;
477
492
  return {
478
493
  success: false,
@@ -481,6 +496,7 @@ var ApiClient = class {
481
496
  statusCode: response.status,
482
497
  ...errorCodeStr ? { code: errorCodeStr } : typeof code === "string" && code ? { code } : {},
483
498
  requestId: responseBody.request_id ?? responseBody.requestId,
499
+ ...rawData ? { data: rawData } : {},
484
500
  ...upstream ? { upstream } : {}
485
501
  };
486
502
  } catch (error) {
@@ -1332,6 +1348,17 @@ var hotelCreateOrderSchema = {
1332
1348
  "arrive-time": { type: "string", required: false, description: "Expected arrival time", constraints: "HH:mm, hotel local time" },
1333
1349
  "special-requests": { type: "string", required: false, description: "Free-text special requests (non-binding)" },
1334
1350
  tips: { type: "string", required: false, description: "FCG \u5BA2\u6237\u81EA\u6D4B\u70B95 \u63D0\u793A\u4FE1\u606F: the chosen quote rate's tips (tips[].tipsDetails[]) as a JSON array [{title,text}], captured at booking. Stored on the order for the order-detail page only; platform-local, not sent upstream", constraints: "JSON array of {title (string, optional), text (string, optional)}; else PARAM_INVALID" },
1351
+ cancellation: {
1352
+ type: "string",
1353
+ required: false,
1354
+ description: "Cancellation policy snapshot copied from the selected quote rate and stored on the order.",
1355
+ constraints: "JSON object; else PARAM_INVALID"
1356
+ },
1357
+ "hotel-timezone": {
1358
+ type: "string",
1359
+ required: false,
1360
+ description: "Hotel timezone from quote (for example 'UTC+8'), used to evaluate cancellation deadlines."
1361
+ },
1335
1362
  "bed-type": {
1336
1363
  type: "string",
1337
1364
  required: false,
@@ -3433,6 +3460,19 @@ function parseTips(raw) {
3433
3460
  }
3434
3461
  return parsed;
3435
3462
  }
3463
+ function parseCancellation(raw) {
3464
+ const invalid = "--cancellation must be a JSON object.";
3465
+ let parsed;
3466
+ try {
3467
+ parsed = JSON.parse(raw);
3468
+ } catch {
3469
+ throw new CliError("PARAM_INVALID", invalid);
3470
+ }
3471
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
3472
+ throw new CliError("PARAM_INVALID", invalid);
3473
+ }
3474
+ return parsed;
3475
+ }
3436
3476
  function need7(value, flag) {
3437
3477
  if (value === void 0) {
3438
3478
  throw new CliError("PARAM_INVALID", `Missing required --${flag}.`);
@@ -3487,6 +3527,12 @@ function registerHotelCreateOrderCommand(parent, deps) {
3487
3527
  "--tips <json>",
3488
3528
  "\u5BA2\u6237\u81EA\u6D4B\u70B95 \u63D0\u793A\u4FE1\u606F: the chosen quote rate's tips as a JSON array [{title,text}]. Stored on the order for the order-detail page ONLY \u2014 platform-local, not sent upstream."
3489
3529
  ).option("--hotel-name <name>", "Hotel name (display-only, stored for order summary)").option(
3530
+ "--cancellation <json>",
3531
+ "Cancellation policy JSON from the chosen rate; stored on the order for cancellation gating and deadline display."
3532
+ ).option(
3533
+ "--hotel-timezone <tz>",
3534
+ "Hotel timezone from quote (for example 'UTC+8'); stored to evaluate cancellation deadlines in hotel-local time."
3535
+ ).option(
3490
3536
  "--bed-type <code>",
3491
3537
  "Product bed-type code from the chosen quote rate's beds[].code (e.g. 'L000000' King / '1000000' Queen); forwarded verbatim to upstream createOrder bedType."
3492
3538
  ).option(
@@ -3540,6 +3586,8 @@ function registerHotelCreateOrderCommand(parent, deps) {
3540
3586
  if (opts.arriveTime !== void 0) body.arrive_time = opts.arriveTime;
3541
3587
  if (opts.specialRequests !== void 0) body.special_requests = opts.specialRequests;
3542
3588
  if (opts.tips !== void 0) body.tips = parseTips(opts.tips);
3589
+ if (opts.cancellation !== void 0) body.cancellation = parseCancellation(opts.cancellation);
3590
+ if (opts.hotelTimezone !== void 0) body.hotel_timezone = opts.hotelTimezone;
3543
3591
  if (opts.hotelName !== void 0) body.hotel_name = opts.hotelName;
3544
3592
  if (opts.bedType !== void 0) body.bed_type = opts.bedType;
3545
3593
  if (opts.paymentMethodId !== void 0) body.payment_method_id = opts.paymentMethodId;
@@ -5833,6 +5881,9 @@ function reportError(error) {
5833
5881
  console.error(
5834
5882
  Formatter.status("error", `[${envelope.error.code_num}] ${envelope.error.message}`)
5835
5883
  );
5884
+ for (const line of errorDetailLines(envelope)) {
5885
+ console.error(line);
5886
+ }
5836
5887
  if (envelope.error.upstream) {
5837
5888
  console.error(` \u21B3 [${envelope.error.upstream.code}] ${envelope.error.upstream.message}`);
5838
5889
  }