@waffo/waffo-node 2.0.4 → 2.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.js CHANGED
@@ -22,279 +22,242 @@ function _interopNamespace(e) {
22
22
 
23
23
  var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
24
24
 
25
- var __defProp = Object.defineProperty;
26
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
27
- var __getOwnPropNames = Object.getOwnPropertyNames;
28
- var __hasOwnProp = Object.prototype.hasOwnProperty;
29
- var __esm = (fn, res) => function __init() {
30
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
31
- };
32
- var __export = (target, all) => {
33
- for (var name in all)
34
- __defProp(target, name, { get: all[name], enumerable: true });
35
- };
36
- var __copyProps = (to, from, except, desc) => {
37
- if (from && typeof from === "object" || typeof from === "function") {
38
- for (let key of __getOwnPropNames(from))
39
- if (!__hasOwnProp.call(to, key) && key !== except)
40
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
41
- }
42
- return to;
43
- };
44
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
-
46
25
  // src/types/config/environment.ts
47
- exports.Environment = void 0; exports.EnvironmentBaseUrl = void 0;
48
- var init_environment = __esm({
49
- "src/types/config/environment.ts"() {
50
- exports.Environment = /* @__PURE__ */ ((Environment2) => {
51
- Environment2["SANDBOX"] = "SANDBOX";
52
- Environment2["PRODUCTION"] = "PRODUCTION";
53
- return Environment2;
54
- })(exports.Environment || {});
55
- exports.EnvironmentBaseUrl = {
56
- ["SANDBOX" /* SANDBOX */]: "https://api-sandbox.waffo.com/api/v1",
57
- ["PRODUCTION" /* PRODUCTION */]: "https://api.waffo.com/api/v1"
58
- };
59
- }
60
- });
26
+ var Environment = /* @__PURE__ */ ((Environment2) => {
27
+ Environment2["SANDBOX"] = "SANDBOX";
28
+ Environment2["PRODUCTION"] = "PRODUCTION";
29
+ return Environment2;
30
+ })(Environment || {});
31
+ var EnvironmentBaseUrl = {
32
+ ["SANDBOX" /* SANDBOX */]: "https://api-sandbox.waffo.com/api/v1",
33
+ ["PRODUCTION" /* PRODUCTION */]: "https://api.waffo.com/api/v1"
34
+ };
61
35
 
62
36
  // src/errors/waffo-error.ts
63
- exports.WaffoError = void 0; exports.WaffoErrorCode = void 0;
64
- var init_waffo_error = __esm({
65
- "src/errors/waffo-error.ts"() {
66
- exports.WaffoError = class _WaffoError extends Error {
67
- /** Error code identifying the type of error */
68
- errorCode;
69
- /** The underlying error that caused this error, if any */
70
- cause;
71
- /**
72
- * Creates a new WaffoError.
73
- *
74
- * @param errorCode - The error code (e.g., "S0003" for signing failure)
75
- * @param message - Human-readable error message
76
- * @param cause - The underlying error that caused this error
77
- */
78
- constructor(errorCode, message, cause) {
79
- super(message);
80
- this.name = "WaffoError";
81
- this.errorCode = errorCode;
82
- this.cause = cause;
83
- if (Error.captureStackTrace) {
84
- Error.captureStackTrace(this, _WaffoError);
85
- }
86
- }
87
- /**
88
- * Returns a string representation of the error.
89
- */
90
- toString() {
91
- return `[${this.errorCode}] ${this.message}`;
92
- }
93
- };
94
- exports.WaffoErrorCode = {
95
- /** Invalid public key */
96
- INVALID_PUBLIC_KEY: "S0002",
97
- /** Failed to sign data */
98
- SIGN_FAILED: "S0003",
99
- /** Response signature verification failed */
100
- VERIFY_FAILED: "S0004",
101
- /** Request serialization failed */
102
- SERIALIZE_FAILED: "S0005",
103
- /** Unexpected error */
104
- UNEXPECTED: "S0006",
105
- /** Invalid private key */
106
- INVALID_PRIVATE_KEY: "S0007"
107
- };
37
+ var WaffoError = class _WaffoError extends Error {
38
+ /** Error code identifying the type of error */
39
+ errorCode;
40
+ /** The underlying error that caused this error, if any */
41
+ cause;
42
+ /**
43
+ * Creates a new WaffoError.
44
+ *
45
+ * @param errorCode - The error code (e.g., "S0003" for signing failure)
46
+ * @param message - Human-readable error message
47
+ * @param cause - The underlying error that caused this error
48
+ */
49
+ constructor(errorCode, message, cause) {
50
+ super(message);
51
+ this.name = "WaffoError";
52
+ this.errorCode = errorCode;
53
+ this.cause = cause;
54
+ if (Error.captureStackTrace) {
55
+ Error.captureStackTrace(this, _WaffoError);
56
+ }
57
+ }
58
+ /**
59
+ * Returns a string representation of the error.
60
+ */
61
+ toString() {
62
+ return `[${this.errorCode}] ${this.message}`;
108
63
  }
109
- });
64
+ };
65
+ var WaffoErrorCode = {
66
+ /** Invalid public key */
67
+ INVALID_PUBLIC_KEY: "S0002",
68
+ /** Failed to sign data */
69
+ SIGN_FAILED: "S0003",
70
+ /** Response signature verification failed */
71
+ VERIFY_FAILED: "S0004",
72
+ /** Request serialization failed */
73
+ SERIALIZE_FAILED: "S0005",
74
+ /** Unexpected error */
75
+ UNEXPECTED: "S0006",
76
+ /** Invalid private key */
77
+ INVALID_PRIVATE_KEY: "S0007"
78
+ };
110
79
 
111
80
  // src/errors/waffo-unknown-status-error.ts
112
- exports.WaffoUnknownStatusError = void 0;
113
- var init_waffo_unknown_status_error = __esm({
114
- "src/errors/waffo-unknown-status-error.ts"() {
115
- exports.WaffoUnknownStatusError = class _WaffoUnknownStatusError extends Error {
116
- /** Error code for network errors */
117
- static CODE_NETWORK_ERROR = "S0001";
118
- /** Error code for unknown server status */
119
- static CODE_UNKNOWN_STATUS = "E0001";
120
- /** Error code identifying the type of error */
121
- errorCode;
122
- /** The underlying error that caused this error, if any */
123
- cause;
124
- /**
125
- * Creates a new WaffoUnknownStatusError.
126
- *
127
- * @param errorCode - The error code (e.g., "S0001" for network error)
128
- * @param message - Human-readable error message
129
- * @param cause - The underlying error that caused this error
130
- */
131
- constructor(errorCode, message, cause) {
132
- super(message);
133
- this.name = "WaffoUnknownStatusError";
134
- this.errorCode = errorCode;
135
- this.cause = cause;
136
- if (Error.captureStackTrace) {
137
- Error.captureStackTrace(this, _WaffoUnknownStatusError);
138
- }
139
- }
140
- /**
141
- * Returns a string representation of the error.
142
- */
143
- toString() {
144
- return `[${this.errorCode}] ${this.message}`;
145
- }
146
- };
81
+ var WaffoUnknownStatusError = class _WaffoUnknownStatusError extends Error {
82
+ /** Error code for network errors */
83
+ static CODE_NETWORK_ERROR = "S0001";
84
+ /** Error code for unknown server status */
85
+ static CODE_UNKNOWN_STATUS = "E0001";
86
+ /** Error code identifying the type of error */
87
+ errorCode;
88
+ /** The underlying error that caused this error, if any */
89
+ cause;
90
+ /**
91
+ * Creates a new WaffoUnknownStatusError.
92
+ *
93
+ * @param errorCode - The error code (e.g., "S0001" for network error)
94
+ * @param message - Human-readable error message
95
+ * @param cause - The underlying error that caused this error
96
+ */
97
+ constructor(errorCode, message, cause) {
98
+ super(message);
99
+ this.name = "WaffoUnknownStatusError";
100
+ this.errorCode = errorCode;
101
+ this.cause = cause;
102
+ if (Error.captureStackTrace) {
103
+ Error.captureStackTrace(this, _WaffoUnknownStatusError);
104
+ }
147
105
  }
148
- });
106
+ /**
107
+ * Returns a string representation of the error.
108
+ */
109
+ toString() {
110
+ return `[${this.errorCode}] ${this.message}`;
111
+ }
112
+ };
149
113
 
150
- // src/errors/index.ts
151
- var init_errors = __esm({
152
- "src/errors/index.ts"() {
153
- init_waffo_error();
154
- init_waffo_unknown_status_error();
155
- }
156
- });
157
- exports.RsaUtils = void 0;
158
- var init_rsa_utils = __esm({
159
- "src/utils/rsa-utils.ts"() {
160
- init_errors();
161
- ((RsaUtils2) => {
162
- const ALGORITHM = "RSA-SHA256";
163
- const KEY_SIZE = 2048;
164
- function sign(data, base64PrivateKey) {
165
- try {
166
- const privateKeyBuffer = Buffer.from(base64PrivateKey, "base64");
167
- const signer = crypto__namespace.createSign(ALGORITHM);
168
- signer.update(data, "utf8");
169
- const signature = signer.sign({
170
- key: privateKeyBuffer,
171
- format: "der",
172
- type: "pkcs8"
173
- });
174
- return signature.toString("base64");
175
- } catch (error) {
176
- throw new exports.WaffoError(
177
- exports.WaffoErrorCode.SIGN_FAILED,
178
- `Failed to sign data: ${error instanceof Error ? error.message : String(error)}`,
179
- error instanceof Error ? error : void 0
180
- );
181
- }
182
- }
183
- RsaUtils2.sign = sign;
184
- function verify(data, base64Signature, base64PublicKey) {
185
- try {
186
- const publicKeyBuffer = Buffer.from(base64PublicKey, "base64");
187
- const signatureBuffer = Buffer.from(base64Signature, "base64");
188
- const verifier = crypto__namespace.createVerify(ALGORITHM);
189
- verifier.update(data, "utf8");
190
- return verifier.verify(
191
- {
192
- key: publicKeyBuffer,
193
- format: "der",
194
- type: "spki"
195
- },
196
- signatureBuffer
197
- );
198
- } catch {
199
- return false;
200
- }
201
- }
202
- RsaUtils2.verify = verify;
203
- function validatePrivateKey(base64PrivateKey) {
204
- if (!base64PrivateKey || base64PrivateKey.trim() === "") {
205
- throw new exports.WaffoError(
206
- exports.WaffoErrorCode.INVALID_PRIVATE_KEY,
207
- "Private key is null or empty"
208
- );
209
- }
210
- try {
211
- const keyBuffer = Buffer.from(base64PrivateKey, "base64");
212
- crypto__namespace.createPrivateKey({
213
- key: keyBuffer,
214
- format: "der",
215
- type: "pkcs8"
216
- });
217
- } catch (error) {
218
- if (error instanceof exports.WaffoError) throw error;
219
- const message = error instanceof Error ? error.message : String(error);
220
- if (message.includes("bad base64")) {
221
- throw new exports.WaffoError(
222
- exports.WaffoErrorCode.INVALID_PRIVATE_KEY,
223
- "Invalid private key: not valid Base64 encoding",
224
- error instanceof Error ? error : void 0
225
- );
226
- }
227
- throw new exports.WaffoError(
228
- exports.WaffoErrorCode.INVALID_PRIVATE_KEY,
229
- `Invalid private key: ${message}`,
230
- error instanceof Error ? error : void 0
231
- );
232
- }
233
- }
234
- RsaUtils2.validatePrivateKey = validatePrivateKey;
235
- function validatePublicKey(base64PublicKey) {
236
- if (!base64PublicKey || base64PublicKey.trim() === "") {
237
- throw new exports.WaffoError(
238
- exports.WaffoErrorCode.INVALID_PUBLIC_KEY,
239
- "Public key is null or empty"
240
- );
241
- }
242
- try {
243
- const keyBuffer = Buffer.from(base64PublicKey, "base64");
244
- crypto__namespace.createPublicKey({
245
- key: keyBuffer,
246
- format: "der",
247
- type: "spki"
248
- });
249
- } catch (error) {
250
- if (error instanceof exports.WaffoError) throw error;
251
- const message = error instanceof Error ? error.message : String(error);
252
- if (message.includes("bad base64")) {
253
- throw new exports.WaffoError(
254
- exports.WaffoErrorCode.INVALID_PUBLIC_KEY,
255
- "Invalid public key: not valid Base64 encoding",
256
- error instanceof Error ? error : void 0
257
- );
258
- }
259
- throw new exports.WaffoError(
260
- exports.WaffoErrorCode.INVALID_PUBLIC_KEY,
261
- `Invalid public key: ${message}`,
262
- error instanceof Error ? error : void 0
263
- );
264
- }
265
- }
266
- RsaUtils2.validatePublicKey = validatePublicKey;
267
- function generateKeyPair() {
268
- try {
269
- const { privateKey, publicKey } = crypto__namespace.generateKeyPairSync("rsa", {
270
- modulusLength: KEY_SIZE,
271
- publicKeyEncoding: {
272
- type: "spki",
273
- format: "der"
274
- },
275
- privateKeyEncoding: {
276
- type: "pkcs8",
277
- format: "der"
278
- }
279
- });
280
- return {
281
- privateKey: privateKey.toString("base64"),
282
- publicKey: publicKey.toString("base64")
283
- };
284
- } catch (error) {
285
- throw new exports.WaffoError(
286
- exports.WaffoErrorCode.SIGN_FAILED,
287
- `Failed to generate key pair: ${error instanceof Error ? error.message : String(error)}`,
288
- error instanceof Error ? error : void 0
289
- );
290
- }
114
+ // src/utils/rsa-utils.ts
115
+ var ALGORITHM = "RSA-SHA256";
116
+ var KEY_SIZE = 2048;
117
+ function sign(data, base64PrivateKey) {
118
+ try {
119
+ const privateKeyBuffer = Buffer.from(base64PrivateKey, "base64");
120
+ const signer = crypto__namespace.createSign(ALGORITHM);
121
+ signer.update(data, "utf8");
122
+ const signature = signer.sign({
123
+ key: privateKeyBuffer,
124
+ format: "der",
125
+ type: "pkcs8"
126
+ });
127
+ return signature.toString("base64");
128
+ } catch (error) {
129
+ throw new WaffoError(
130
+ WaffoErrorCode.SIGN_FAILED,
131
+ `Failed to sign data: ${error instanceof Error ? error.message : String(error)}`,
132
+ error instanceof Error ? error : void 0
133
+ );
134
+ }
135
+ }
136
+ function verify(data, base64Signature, base64PublicKey) {
137
+ try {
138
+ const publicKeyBuffer = Buffer.from(base64PublicKey, "base64");
139
+ const signatureBuffer = Buffer.from(base64Signature, "base64");
140
+ const verifier = crypto__namespace.createVerify(ALGORITHM);
141
+ verifier.update(data, "utf8");
142
+ return verifier.verify(
143
+ {
144
+ key: publicKeyBuffer,
145
+ format: "der",
146
+ type: "spki"
147
+ },
148
+ signatureBuffer
149
+ );
150
+ } catch {
151
+ return false;
152
+ }
153
+ }
154
+ function validatePrivateKey(base64PrivateKey) {
155
+ if (!base64PrivateKey || base64PrivateKey.trim() === "") {
156
+ throw new WaffoError(
157
+ WaffoErrorCode.INVALID_PRIVATE_KEY,
158
+ "Private key is null or empty"
159
+ );
160
+ }
161
+ try {
162
+ const keyBuffer = Buffer.from(base64PrivateKey, "base64");
163
+ crypto__namespace.createPrivateKey({
164
+ key: keyBuffer,
165
+ format: "der",
166
+ type: "pkcs8"
167
+ });
168
+ } catch (error) {
169
+ if (error instanceof WaffoError) throw error;
170
+ const message = error instanceof Error ? error.message : String(error);
171
+ if (message.includes("bad base64")) {
172
+ throw new WaffoError(
173
+ WaffoErrorCode.INVALID_PRIVATE_KEY,
174
+ "Invalid private key: not valid Base64 encoding",
175
+ error instanceof Error ? error : void 0
176
+ );
177
+ }
178
+ throw new WaffoError(
179
+ WaffoErrorCode.INVALID_PRIVATE_KEY,
180
+ `Invalid private key: ${message}`,
181
+ error instanceof Error ? error : void 0
182
+ );
183
+ }
184
+ }
185
+ function validatePublicKey(base64PublicKey) {
186
+ if (!base64PublicKey || base64PublicKey.trim() === "") {
187
+ throw new WaffoError(
188
+ WaffoErrorCode.INVALID_PUBLIC_KEY,
189
+ "Public key is null or empty"
190
+ );
191
+ }
192
+ try {
193
+ const keyBuffer = Buffer.from(base64PublicKey, "base64");
194
+ crypto__namespace.createPublicKey({
195
+ key: keyBuffer,
196
+ format: "der",
197
+ type: "spki"
198
+ });
199
+ } catch (error) {
200
+ if (error instanceof WaffoError) throw error;
201
+ const message = error instanceof Error ? error.message : String(error);
202
+ if (message.includes("bad base64")) {
203
+ throw new WaffoError(
204
+ WaffoErrorCode.INVALID_PUBLIC_KEY,
205
+ "Invalid public key: not valid Base64 encoding",
206
+ error instanceof Error ? error : void 0
207
+ );
208
+ }
209
+ throw new WaffoError(
210
+ WaffoErrorCode.INVALID_PUBLIC_KEY,
211
+ `Invalid public key: ${message}`,
212
+ error instanceof Error ? error : void 0
213
+ );
214
+ }
215
+ }
216
+ function generateKeyPair() {
217
+ try {
218
+ const { privateKey, publicKey } = crypto__namespace.generateKeyPairSync("rsa", {
219
+ modulusLength: KEY_SIZE,
220
+ publicKeyEncoding: {
221
+ type: "spki",
222
+ format: "der"
223
+ },
224
+ privateKeyEncoding: {
225
+ type: "pkcs8",
226
+ format: "der"
291
227
  }
292
- RsaUtils2.generateKeyPair = generateKeyPair;
293
- })(exports.RsaUtils || (exports.RsaUtils = {}));
228
+ });
229
+ return {
230
+ privateKey: privateKey.toString("base64"),
231
+ publicKey: publicKey.toString("base64")
232
+ };
233
+ } catch (error) {
234
+ throw new WaffoError(
235
+ WaffoErrorCode.SIGN_FAILED,
236
+ `Failed to generate key pair: ${error instanceof Error ? error.message : String(error)}`,
237
+ error instanceof Error ? error : void 0
238
+ );
294
239
  }
295
- });
240
+ }
241
+ var RsaUtils = {
242
+ sign,
243
+ verify,
244
+ validatePrivateKey,
245
+ validatePublicKey,
246
+ generateKeyPair
247
+ };
296
248
 
297
249
  // src/types/config/waffo-config.ts
250
+ var WaffoConfigEnvVars = {
251
+ API_KEY: "WAFFO_API_KEY",
252
+ PRIVATE_KEY: "WAFFO_PRIVATE_KEY",
253
+ PUBLIC_KEY: "WAFFO_PUBLIC_KEY",
254
+ MERCHANT_ID: "WAFFO_MERCHANT_ID",
255
+ ENVIRONMENT: "WAFFO_ENVIRONMENT"
256
+ };
257
+ var WaffoConfigDefaults = {
258
+ CONNECT_TIMEOUT: 1e4,
259
+ READ_TIMEOUT: 3e4
260
+ };
298
261
  function createWaffoConfig(config) {
299
262
  if (!config.apiKey) {
300
263
  throw new Error("apiKey is required");
@@ -311,12 +274,12 @@ function createWaffoConfig(config) {
311
274
  if (!config.merchantId) {
312
275
  throw new Error("merchantId is required");
313
276
  }
314
- exports.RsaUtils.validatePrivateKey(config.privateKey);
315
- exports.RsaUtils.validatePublicKey(config.waffoPublicKey);
277
+ RsaUtils.validatePrivateKey(config.privateKey);
278
+ RsaUtils.validatePublicKey(config.waffoPublicKey);
316
279
  return {
317
280
  ...config,
318
- connectTimeout: config.connectTimeout ?? exports.WaffoConfigDefaults.CONNECT_TIMEOUT,
319
- readTimeout: config.readTimeout ?? exports.WaffoConfigDefaults.READ_TIMEOUT
281
+ connectTimeout: config.connectTimeout ?? WaffoConfigDefaults.CONNECT_TIMEOUT,
282
+ readTimeout: config.readTimeout ?? WaffoConfigDefaults.READ_TIMEOUT
320
283
  };
321
284
  }
322
285
  function fromEnv() {
@@ -346,44 +309,6 @@ function fromEnv() {
346
309
  merchantId
347
310
  });
348
311
  }
349
- var WaffoConfigEnvVars; exports.WaffoConfigDefaults = void 0;
350
- var init_waffo_config = __esm({
351
- "src/types/config/waffo-config.ts"() {
352
- init_environment();
353
- init_rsa_utils();
354
- WaffoConfigEnvVars = {
355
- API_KEY: "WAFFO_API_KEY",
356
- PRIVATE_KEY: "WAFFO_PRIVATE_KEY",
357
- PUBLIC_KEY: "WAFFO_PUBLIC_KEY",
358
- MERCHANT_ID: "WAFFO_MERCHANT_ID",
359
- ENVIRONMENT: "WAFFO_ENVIRONMENT"
360
- };
361
- exports.WaffoConfigDefaults = {
362
- CONNECT_TIMEOUT: 1e4,
363
- READ_TIMEOUT: 3e4
364
- };
365
- }
366
- });
367
-
368
- // src/types/config/index.ts
369
- var config_exports = {};
370
- __export(config_exports, {
371
- Environment: () => exports.Environment,
372
- EnvironmentBaseUrl: () => exports.EnvironmentBaseUrl,
373
- WaffoConfigDefaults: () => exports.WaffoConfigDefaults,
374
- WaffoConfigEnvVars: () => WaffoConfigEnvVars,
375
- createWaffoConfig: () => createWaffoConfig,
376
- fromEnv: () => fromEnv
377
- });
378
- var init_config = __esm({
379
- "src/types/config/index.ts"() {
380
- init_environment();
381
- init_waffo_config();
382
- }
383
- });
384
-
385
- // src/core/waffo-http-client.ts
386
- init_config();
387
312
 
388
313
  // src/types/api-response.ts
389
314
  var ApiResponse = class _ApiResponse {
@@ -531,9 +456,6 @@ var DefaultHttpTransport = class {
531
456
  };
532
457
 
533
458
  // src/core/waffo-http-client.ts
534
- init_rsa_utils();
535
- init_waffo_error();
536
- init_waffo_unknown_status_error();
537
459
  var HEADER_API_KEY = "x-api-key";
538
460
  var HEADER_SIGNATURE = "x-signature";
539
461
  var HEADER_API_VERSION = "x-api-version";
@@ -541,7 +463,7 @@ var HEADER_SDK_VERSION = "x-sdk-version";
541
463
  var HEADER_CONTENT_TYPE = "content-type";
542
464
  var CONTENT_TYPE_JSON = "application/json";
543
465
  var API_VERSION = "1.0.0";
544
- var SDK_VERSION = "waffo-node/1.0.0";
466
+ var SDK_VERSION = "waffo-node/2.1.0";
545
467
  var WaffoHttpClient = class {
546
468
  baseUrl;
547
469
  apiKey;
@@ -553,13 +475,13 @@ var WaffoHttpClient = class {
553
475
  logger;
554
476
  httpTransport;
555
477
  constructor(config) {
556
- this.baseUrl = exports.EnvironmentBaseUrl[config.environment];
478
+ this.baseUrl = EnvironmentBaseUrl[config.environment];
557
479
  this.apiKey = config.apiKey;
558
480
  this.privateKey = config.privateKey;
559
481
  this.waffoPublicKey = config.waffoPublicKey;
560
482
  this.merchantId = config.merchantId;
561
- this.connectTimeout = config.connectTimeout ?? exports.WaffoConfigDefaults.CONNECT_TIMEOUT;
562
- this.readTimeout = config.readTimeout ?? exports.WaffoConfigDefaults.READ_TIMEOUT;
483
+ this.connectTimeout = config.connectTimeout ?? WaffoConfigDefaults.CONNECT_TIMEOUT;
484
+ this.readTimeout = config.readTimeout ?? WaffoConfigDefaults.READ_TIMEOUT;
563
485
  this.logger = config.logger;
564
486
  this.httpTransport = config.httpTransport ?? new DefaultHttpTransport();
565
487
  }
@@ -579,7 +501,7 @@ var WaffoHttpClient = class {
579
501
  try {
580
502
  this.injectMerchantIdIfNeeded(request);
581
503
  const requestBody = JSON.stringify(request);
582
- const signature = exports.RsaUtils.sign(requestBody, this.privateKey);
504
+ const signature = RsaUtils.sign(requestBody, this.privateKey);
583
505
  this.logger?.debug(`Request URL: ${url}`);
584
506
  this.logger?.debug(`Request Body: ${requestBody}`);
585
507
  const httpResponse = await this.httpTransport.send({
@@ -600,7 +522,7 @@ var WaffoHttpClient = class {
600
522
  this.logger?.debug(`Response Body: ${httpResponse.body}`);
601
523
  const responseSignature = httpResponse.headers[HEADER_SIGNATURE];
602
524
  if (responseSignature) {
603
- const isValid = exports.RsaUtils.verify(
525
+ const isValid = RsaUtils.verify(
604
526
  httpResponse.body,
605
527
  responseSignature,
606
528
  this.waffoPublicKey
@@ -608,27 +530,27 @@ var WaffoHttpClient = class {
608
530
  if (!isValid) {
609
531
  this.logger?.error("Response signature verification failed");
610
532
  return ApiResponse.error(
611
- exports.WaffoErrorCode.VERIFY_FAILED,
533
+ WaffoErrorCode.VERIFY_FAILED,
612
534
  "Response signature verification failed"
613
535
  );
614
536
  }
615
537
  }
616
538
  const response = this.parseResponse(httpResponse.body);
617
539
  if (response.code === "E0001") {
618
- throw new exports.WaffoUnknownStatusError(
619
- exports.WaffoUnknownStatusError.CODE_UNKNOWN_STATUS,
540
+ throw new WaffoUnknownStatusError(
541
+ WaffoUnknownStatusError.CODE_UNKNOWN_STATUS,
620
542
  response.getMessage() ?? "Unknown status from server"
621
543
  );
622
544
  }
623
545
  return response;
624
546
  } catch (error) {
625
- if (error instanceof exports.WaffoUnknownStatusError) {
547
+ if (error instanceof WaffoUnknownStatusError) {
626
548
  throw error;
627
549
  }
628
550
  if (this.isNetworkError(error)) {
629
551
  this.logger?.error("Network error", error);
630
- throw new exports.WaffoUnknownStatusError(
631
- exports.WaffoUnknownStatusError.CODE_NETWORK_ERROR,
552
+ throw new WaffoUnknownStatusError(
553
+ WaffoUnknownStatusError.CODE_NETWORK_ERROR,
632
554
  `Network error, payment status unknown: ${error instanceof Error ? error.message : String(error)}`,
633
555
  error instanceof Error ? error : void 0
634
556
  );
@@ -636,13 +558,13 @@ var WaffoHttpClient = class {
636
558
  if (error instanceof SyntaxError) {
637
559
  this.logger?.error("JSON serialization error", error);
638
560
  return ApiResponse.error(
639
- exports.WaffoErrorCode.SERIALIZE_FAILED,
561
+ WaffoErrorCode.SERIALIZE_FAILED,
640
562
  `Request serialization failed: ${error.message}`
641
563
  );
642
564
  }
643
565
  this.logger?.error("Unexpected error", error);
644
566
  return ApiResponse.error(
645
- exports.WaffoErrorCode.UNEXPECTED,
567
+ WaffoErrorCode.UNEXPECTED,
646
568
  `Unexpected error: ${error instanceof Error ? error.message : String(error)}`
647
569
  );
648
570
  }
@@ -690,7 +612,6 @@ var WaffoHttpClient = class {
690
612
  };
691
613
 
692
614
  // src/core/webhook-handler.ts
693
- init_rsa_utils();
694
615
  var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
695
616
  WebhookEventType2["PAYMENT_NOTIFICATION"] = "PAYMENT_NOTIFICATION";
696
617
  WebhookEventType2["REFUND_NOTIFICATION"] = "REFUND_NOTIFICATION";
@@ -761,7 +682,7 @@ var WebhookHandler = class {
761
682
  this.logger?.warn("Missing webhook signature");
762
683
  return this.createFailedResult("Missing signature");
763
684
  }
764
- const isValid = exports.RsaUtils.verify(body, signature, this.waffoPublicKey);
685
+ const isValid = RsaUtils.verify(body, signature, this.waffoPublicKey);
765
686
  if (!isValid) {
766
687
  this.logger?.error("Invalid webhook signature");
767
688
  return this.createFailedResult("Invalid signature");
@@ -814,14 +735,14 @@ var WebhookHandler = class {
814
735
  * @returns true if signature is valid
815
736
  */
816
737
  verifySignature(body, signature) {
817
- return exports.RsaUtils.verify(body, signature, this.waffoPublicKey);
738
+ return RsaUtils.verify(body, signature, this.waffoPublicKey);
818
739
  }
819
740
  /**
820
741
  * Builds a success response with signature.
821
742
  */
822
743
  buildSuccessResponse() {
823
744
  const body = JSON.stringify({ status: "success" });
824
- const signature = exports.RsaUtils.sign(body, this.privateKey);
745
+ const signature = RsaUtils.sign(body, this.privateKey);
825
746
  return { body, signature };
826
747
  }
827
748
  /**
@@ -829,7 +750,7 @@ var WebhookHandler = class {
829
750
  */
830
751
  buildFailedResponse(message) {
831
752
  const body = JSON.stringify({ status: "failed", message });
832
- const signature = exports.RsaUtils.sign(body, this.privateKey);
753
+ const signature = RsaUtils.sign(body, this.privateKey);
833
754
  return { body, signature };
834
755
  }
835
756
  createSuccessResult() {
@@ -1205,8 +1126,7 @@ var Waffo = class _Waffo {
1205
1126
  * @returns Waffo SDK instance
1206
1127
  */
1207
1128
  static fromEnv() {
1208
- const { WaffoConfig } = (init_config(), __toCommonJS(config_exports));
1209
- return new _Waffo(WaffoConfig.fromEnv());
1129
+ return new _Waffo(fromEnv());
1210
1130
  }
1211
1131
  /**
1212
1132
  * Returns the order resource for managing payment orders.
@@ -1306,20 +1226,21 @@ var Waffo = class _Waffo {
1306
1226
  }
1307
1227
  };
1308
1228
 
1309
- // src/index.ts
1310
- init_config();
1311
- init_waffo_error();
1312
- init_waffo_unknown_status_error();
1313
- init_rsa_utils();
1314
-
1315
1229
  exports.ApiResponse = ApiResponse;
1230
+ exports.Environment = Environment;
1231
+ exports.EnvironmentBaseUrl = EnvironmentBaseUrl;
1316
1232
  exports.MerchantConfigResource = MerchantConfigResource;
1317
1233
  exports.OrderResource = OrderResource;
1318
1234
  exports.PayMethodConfigResource = PayMethodConfigResource;
1319
1235
  exports.RefundResource = RefundResource;
1236
+ exports.RsaUtils = RsaUtils;
1320
1237
  exports.SubscriptionResource = SubscriptionResource;
1321
1238
  exports.Waffo = Waffo;
1239
+ exports.WaffoConfigDefaults = WaffoConfigDefaults;
1240
+ exports.WaffoError = WaffoError;
1241
+ exports.WaffoErrorCode = WaffoErrorCode;
1322
1242
  exports.WaffoHttpClient = WaffoHttpClient;
1243
+ exports.WaffoUnknownStatusError = WaffoUnknownStatusError;
1323
1244
  exports.WebhookEventType = WebhookEventType;
1324
1245
  exports.WebhookHandler = WebhookHandler;
1325
1246
  //# sourceMappingURL=index.js.map