@waffo/waffo-node 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -455,7 +455,7 @@ var HEADER_SDK_VERSION = "x-sdk-version";
455
455
  var HEADER_CONTENT_TYPE = "content-type";
456
456
  var CONTENT_TYPE_JSON = "application/json";
457
457
  var API_VERSION = "1.0.0";
458
- var SDK_VERSION = "waffo-node/3.0.1";
458
+ var SDK_VERSION = "waffo-node/3.1.0";
459
459
  var WaffoHttpClient = class {
460
460
  baseUrl;
461
461
  apiKey;
@@ -485,15 +485,16 @@ var WaffoHttpClient = class {
485
485
  * @param path - API endpoint path (e.g., "/order/create")
486
486
  * @param request - Request body
487
487
  * @param options - Per-request options
488
+ * @param merchantIdPath - Contract path for merchantId, null for no injection, or omitted for legacy inference
488
489
  * @returns API response
489
490
  * @throws WaffoUnknownStatusError for network errors or unknown status
490
491
  */
491
- async post(path, request, options) {
492
+ async post(path, request, options, merchantIdPath) {
492
493
  const url = this.baseUrl + path;
493
494
  const effectiveConnectTimeout = options?.connectTimeout ?? this.connectTimeout;
494
495
  const effectiveReadTimeout = options?.readTimeout ?? this.readTimeout;
495
496
  try {
496
- this.injectMerchantIdIfNeeded(request);
497
+ this.injectMerchantIdIfNeeded(request, merchantIdPath);
497
498
  const requestBody = JSON.stringify(request);
498
499
  const signature = RsaUtils.sign(requestBody, this.privateKey);
499
500
  this.logger?.debug(`Request URL: ${url}`);
@@ -586,9 +587,24 @@ var WaffoHttpClient = class {
586
587
  /**
587
588
  * Auto-injects merchantId into the request if configured.
588
589
  */
589
- injectMerchantIdIfNeeded(request) {
590
+ injectMerchantIdIfNeeded(request, merchantIdPath) {
590
591
  if (!this.merchantId) return;
591
592
  const req = request;
593
+ if (merchantIdPath === null) return;
594
+ if (merchantIdPath === "merchantInfo.merchantId") {
595
+ const merchantInfo = typeof req.merchantInfo === "object" && req.merchantInfo !== null ? req.merchantInfo : {};
596
+ if (!merchantInfo.merchantId) {
597
+ merchantInfo.merchantId = this.merchantId;
598
+ }
599
+ req.merchantInfo = merchantInfo;
600
+ return;
601
+ }
602
+ if (merchantIdPath === "merchantId") {
603
+ if (!req.merchantId) {
604
+ req.merchantId = this.merchantId;
605
+ }
606
+ return;
607
+ }
592
608
  if (typeof req.merchantInfo === "object" && req.merchantInfo !== null) {
593
609
  const info = req.merchantInfo;
594
610
  if (!info.merchantId) {
@@ -833,7 +849,8 @@ var OrderResource = class _OrderResource extends BaseResource {
833
849
  return this.httpClient.post(
834
850
  this.getPath(_OrderResource.PATH_CREATE),
835
851
  params,
836
- options
852
+ options,
853
+ "merchantInfo.merchantId"
837
854
  );
838
855
  }
839
856
  /**
@@ -848,7 +865,8 @@ var OrderResource = class _OrderResource extends BaseResource {
848
865
  return this.httpClient.post(
849
866
  this.getPath(_OrderResource.PATH_INQUIRY),
850
867
  params,
851
- options
868
+ options,
869
+ null
852
870
  );
853
871
  }
854
872
  /**
@@ -866,7 +884,8 @@ var OrderResource = class _OrderResource extends BaseResource {
866
884
  return this.httpClient.post(
867
885
  this.getPath(_OrderResource.PATH_CANCEL),
868
886
  params,
869
- options
887
+ options,
888
+ "merchantId"
870
889
  );
871
890
  }
872
891
  /**
@@ -884,7 +903,8 @@ var OrderResource = class _OrderResource extends BaseResource {
884
903
  return this.httpClient.post(
885
904
  this.getPath(_OrderResource.PATH_REFUND),
886
905
  params,
887
- options
906
+ options,
907
+ "merchantId"
888
908
  );
889
909
  }
890
910
  /**
@@ -902,7 +922,8 @@ var OrderResource = class _OrderResource extends BaseResource {
902
922
  return this.httpClient.post(
903
923
  this.getPath(_OrderResource.PATH_CAPTURE),
904
924
  params,
905
- options
925
+ options,
926
+ "merchantId"
906
927
  );
907
928
  }
908
929
  };
@@ -931,7 +952,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
931
952
  return this.httpClient.post(
932
953
  this.getPath(_SubscriptionResource.PATH_CREATE),
933
954
  params,
934
- options
955
+ options,
956
+ "merchantInfo.merchantId"
935
957
  );
936
958
  }
937
959
  /**
@@ -946,7 +968,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
946
968
  return this.httpClient.post(
947
969
  this.getPath(_SubscriptionResource.PATH_INQUIRY),
948
970
  params,
949
- options
971
+ options,
972
+ null
950
973
  );
951
974
  }
952
975
  /**
@@ -964,7 +987,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
964
987
  return this.httpClient.post(
965
988
  this.getPath(_SubscriptionResource.PATH_CANCEL),
966
989
  params,
967
- options
990
+ options,
991
+ "merchantId"
968
992
  );
969
993
  }
970
994
  /**
@@ -979,7 +1003,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
979
1003
  return this.httpClient.post(
980
1004
  this.getPath(_SubscriptionResource.PATH_MANAGE),
981
1005
  params,
982
- options
1006
+ options,
1007
+ null
983
1008
  );
984
1009
  }
985
1010
  /**
@@ -997,7 +1022,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
997
1022
  return this.httpClient.post(
998
1023
  this.getPath(_SubscriptionResource.PATH_UPDATE),
999
1024
  params,
1000
- options
1025
+ options,
1026
+ null
1001
1027
  );
1002
1028
  }
1003
1029
  /**
@@ -1048,7 +1074,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
1048
1074
  return this.httpClient.post(
1049
1075
  this.getPath(_SubscriptionResource.PATH_CHANGE),
1050
1076
  params,
1051
- options
1077
+ options,
1078
+ "merchantInfo.merchantId"
1052
1079
  );
1053
1080
  }
1054
1081
  /**
@@ -1079,11 +1106,16 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
1079
1106
  return await this.httpClient.post(
1080
1107
  this.getPath(_SubscriptionResource.PATH_CHANGE_INQUIRY),
1081
1108
  params,
1082
- options
1109
+ options,
1110
+ null
1083
1111
  );
1084
1112
  } catch (error) {
1085
1113
  if (error && typeof error === "object" && "errorCode" in error) {
1086
- return ApiResponse.error("E0001", String(error.message || "Unknown error"));
1114
+ const unknownStatus = error;
1115
+ return ApiResponse.error(
1116
+ String(unknownStatus.errorCode),
1117
+ String(unknownStatus.message || "Unknown error")
1118
+ );
1087
1119
  }
1088
1120
  throw error;
1089
1121
  }
@@ -1105,7 +1137,8 @@ var RefundResource = class _RefundResource extends BaseResource {
1105
1137
  return this.httpClient.post(
1106
1138
  this.getPath(_RefundResource.PATH_INQUIRY),
1107
1139
  params,
1108
- options
1140
+ options,
1141
+ null
1109
1142
  );
1110
1143
  }
1111
1144
  };
@@ -1125,7 +1158,8 @@ var MerchantConfigResource = class _MerchantConfigResource extends BaseResource
1125
1158
  return this.httpClient.post(
1126
1159
  this.getPath(_MerchantConfigResource.PATH_INQUIRY),
1127
1160
  params,
1128
- options
1161
+ options,
1162
+ "merchantId"
1129
1163
  );
1130
1164
  }
1131
1165
  };
@@ -1145,7 +1179,8 @@ var PayMethodConfigResource = class _PayMethodConfigResource extends BaseResourc
1145
1179
  return this.httpClient.post(
1146
1180
  this.getPath(_PayMethodConfigResource.PATH_INQUIRY),
1147
1181
  params,
1148
- options
1182
+ options,
1183
+ "merchantId"
1149
1184
  );
1150
1185
  }
1151
1186
  };
@@ -1165,7 +1200,8 @@ var WalletResource = class _WalletResource extends BaseResource {
1165
1200
  return this.httpClient.post(
1166
1201
  this.getPath(_WalletResource.PATH_INQUIRY),
1167
1202
  params,
1168
- options
1203
+ options,
1204
+ "merchantInfo.merchantId"
1169
1205
  );
1170
1206
  }
1171
1207
  };