@edge-markets/connect-node 1.5.0 → 1.6.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.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { EdgeEnvironment, User, VerifyIdentityOptions, VerifyIdentityResult, Balance, Transfer, ListTransfersParams, TransferList, CreateVerificationSessionRequest, VerificationSession, VerificationSessionStatusResponse, EdgeTokens } from '@edge-markets/connect';
2
- export { Balance, CreateVerificationSessionRequest, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeInsufficientScopeError, EdgeNetworkError, EdgeNotFoundError, EdgeTokenExchangeError, EdgeTokens, ListTransfersParams, Transfer, TransferList, TransferListItem, TransferStatus, TransferType, User, VerificationSession, VerificationSessionStatus, VerificationSessionStatusResponse, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isEdgeError, isNetworkError, isProductionEnvironment } from '@edge-markets/connect';
1
+ import * as node_https from 'node:https';
2
+ import { EdgeEnvironment, TransferCategory, SdkGeolocation, User, VerifyIdentityOptions, VerifyIdentityResult, Balance, Transfer, ListTransfersParams, TransferList, CreateVerificationSessionRequest, VerificationSession, VerificationSessionStatusResponse, EdgeTokens } from '@edge-markets/connect';
3
+ export { Balance, CreateVerificationSessionRequest, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeIdentityVerificationError, EdgeInsufficientScopeError, EdgeNetworkError, EdgeNotFoundError, EdgeTokenExchangeError, EdgeTokens, ListTransfersParams, SdkGeolocation, TRANSFER_CATEGORIES, Transfer, TransferCategory, TransferList, TransferListItem, TransferStatus, TransferType, User, UserAddress, VerificationSession, VerificationSessionStatus, VerificationSessionStatusResponse, VerifyIdentityAddress, VerifyIdentityOptions, VerifyIdentityResult, VerifyIdentityScores, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isEdgeError, isIdentityVerificationError, isNetworkError, isProductionEnvironment } from '@edge-markets/connect';
3
4
 
4
5
  interface RequestInfo {
5
6
  method: string;
@@ -40,11 +41,27 @@ interface EdgeConnectServerConfig {
40
41
  partnerKeyId: string;
41
42
  strictResponseEncryption?: boolean;
42
43
  };
44
+ mtls?: MtlsConfig;
45
+ }
46
+ interface MtlsConfig {
47
+ enabled: boolean;
48
+ cert: string;
49
+ key: string;
50
+ ca?: string;
43
51
  }
44
52
  interface TransferOptions {
45
53
  type: 'debit' | 'credit';
46
54
  amount: string;
47
55
  idempotencyKey: string;
56
+ /** Optional transaction category for settlement window determination */
57
+ category?: TransferCategory;
58
+ }
59
+ /**
60
+ * Options for verifying a transfer with OTP.
61
+ */
62
+ interface VerifyTransferOptions {
63
+ /** SDK-reported geolocation for cross-referencing against IP-based geo */
64
+ sdkGeo?: SdkGeolocation;
48
65
  }
49
66
 
50
67
  /**
@@ -61,7 +78,7 @@ declare class EdgeUserClient {
61
78
  verifyIdentity(options: VerifyIdentityOptions): Promise<VerifyIdentityResult>;
62
79
  getBalance(): Promise<Balance>;
63
80
  initiateTransfer(options: TransferOptions): Promise<Transfer>;
64
- verifyTransfer(transferId: string, otp: string): Promise<Transfer>;
81
+ verifyTransfer(transferId: string, otp: string, options?: VerifyTransferOptions): Promise<Transfer>;
65
82
  getTransfer(transferId: string): Promise<Transfer>;
66
83
  listTransfers(params?: ListTransfersParams): Promise<TransferList>;
67
84
  revokeConsent(): Promise<{
@@ -86,9 +103,16 @@ declare class EdgeConnectServer {
86
103
  private readonly oauthBaseUrl;
87
104
  private readonly timeout;
88
105
  private readonly retryConfig;
106
+ private readonly httpsAgent;
107
+ private readonly dispatcher;
89
108
  static getInstance(config: EdgeConnectServerConfig): EdgeConnectServer;
90
109
  static clearInstances(): void;
91
110
  constructor(config: EdgeConnectServerConfig);
111
+ /**
112
+ * Returns the `node:https.Agent` configured with mTLS client certificates.
113
+ * Use this with axios, got, or other HTTP clients. Returns `undefined` if mTLS is not configured.
114
+ */
115
+ getHttpsAgent(): node_https.Agent | undefined;
92
116
  /**
93
117
  * Create a user-scoped client for making authenticated API calls.
94
118
  *
@@ -108,4 +132,4 @@ declare class EdgeConnectServer {
108
132
  private handleApiErrorFromBody;
109
133
  }
110
134
 
111
- export { EdgeConnectServer, type EdgeConnectServerConfig, EdgeUserClient, type RequestInfo, type ResponseInfo, type RetryConfig, type TransferOptions };
135
+ export { EdgeConnectServer, type EdgeConnectServerConfig, EdgeUserClient, type MtlsConfig, type RequestInfo, type ResponseInfo, type RetryConfig, type TransferOptions, type VerifyTransferOptions };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { EdgeEnvironment, User, VerifyIdentityOptions, VerifyIdentityResult, Balance, Transfer, ListTransfersParams, TransferList, CreateVerificationSessionRequest, VerificationSession, VerificationSessionStatusResponse, EdgeTokens } from '@edge-markets/connect';
2
- export { Balance, CreateVerificationSessionRequest, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeInsufficientScopeError, EdgeNetworkError, EdgeNotFoundError, EdgeTokenExchangeError, EdgeTokens, ListTransfersParams, Transfer, TransferList, TransferListItem, TransferStatus, TransferType, User, VerificationSession, VerificationSessionStatus, VerificationSessionStatusResponse, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isEdgeError, isNetworkError, isProductionEnvironment } from '@edge-markets/connect';
1
+ import * as node_https from 'node:https';
2
+ import { EdgeEnvironment, TransferCategory, SdkGeolocation, User, VerifyIdentityOptions, VerifyIdentityResult, Balance, Transfer, ListTransfersParams, TransferList, CreateVerificationSessionRequest, VerificationSession, VerificationSessionStatusResponse, EdgeTokens } from '@edge-markets/connect';
3
+ export { Balance, CreateVerificationSessionRequest, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeIdentityVerificationError, EdgeInsufficientScopeError, EdgeNetworkError, EdgeNotFoundError, EdgeTokenExchangeError, EdgeTokens, ListTransfersParams, SdkGeolocation, TRANSFER_CATEGORIES, Transfer, TransferCategory, TransferList, TransferListItem, TransferStatus, TransferType, User, UserAddress, VerificationSession, VerificationSessionStatus, VerificationSessionStatusResponse, VerifyIdentityAddress, VerifyIdentityOptions, VerifyIdentityResult, VerifyIdentityScores, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isEdgeError, isIdentityVerificationError, isNetworkError, isProductionEnvironment } from '@edge-markets/connect';
3
4
 
4
5
  interface RequestInfo {
5
6
  method: string;
@@ -40,11 +41,27 @@ interface EdgeConnectServerConfig {
40
41
  partnerKeyId: string;
41
42
  strictResponseEncryption?: boolean;
42
43
  };
44
+ mtls?: MtlsConfig;
45
+ }
46
+ interface MtlsConfig {
47
+ enabled: boolean;
48
+ cert: string;
49
+ key: string;
50
+ ca?: string;
43
51
  }
44
52
  interface TransferOptions {
45
53
  type: 'debit' | 'credit';
46
54
  amount: string;
47
55
  idempotencyKey: string;
56
+ /** Optional transaction category for settlement window determination */
57
+ category?: TransferCategory;
58
+ }
59
+ /**
60
+ * Options for verifying a transfer with OTP.
61
+ */
62
+ interface VerifyTransferOptions {
63
+ /** SDK-reported geolocation for cross-referencing against IP-based geo */
64
+ sdkGeo?: SdkGeolocation;
48
65
  }
49
66
 
50
67
  /**
@@ -61,7 +78,7 @@ declare class EdgeUserClient {
61
78
  verifyIdentity(options: VerifyIdentityOptions): Promise<VerifyIdentityResult>;
62
79
  getBalance(): Promise<Balance>;
63
80
  initiateTransfer(options: TransferOptions): Promise<Transfer>;
64
- verifyTransfer(transferId: string, otp: string): Promise<Transfer>;
81
+ verifyTransfer(transferId: string, otp: string, options?: VerifyTransferOptions): Promise<Transfer>;
65
82
  getTransfer(transferId: string): Promise<Transfer>;
66
83
  listTransfers(params?: ListTransfersParams): Promise<TransferList>;
67
84
  revokeConsent(): Promise<{
@@ -86,9 +103,16 @@ declare class EdgeConnectServer {
86
103
  private readonly oauthBaseUrl;
87
104
  private readonly timeout;
88
105
  private readonly retryConfig;
106
+ private readonly httpsAgent;
107
+ private readonly dispatcher;
89
108
  static getInstance(config: EdgeConnectServerConfig): EdgeConnectServer;
90
109
  static clearInstances(): void;
91
110
  constructor(config: EdgeConnectServerConfig);
111
+ /**
112
+ * Returns the `node:https.Agent` configured with mTLS client certificates.
113
+ * Use this with axios, got, or other HTTP clients. Returns `undefined` if mTLS is not configured.
114
+ */
115
+ getHttpsAgent(): node_https.Agent | undefined;
92
116
  /**
93
117
  * Create a user-scoped client for making authenticated API calls.
94
118
  *
@@ -108,4 +132,4 @@ declare class EdgeConnectServer {
108
132
  private handleApiErrorFromBody;
109
133
  }
110
134
 
111
- export { EdgeConnectServer, type EdgeConnectServerConfig, EdgeUserClient, type RequestInfo, type ResponseInfo, type RetryConfig, type TransferOptions };
135
+ export { EdgeConnectServer, type EdgeConnectServerConfig, EdgeUserClient, type MtlsConfig, type RequestInfo, type ResponseInfo, type RetryConfig, type TransferOptions, type VerifyTransferOptions };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -25,16 +35,19 @@ __export(index_exports, {
25
35
  EdgeConnectServer: () => EdgeConnectServer,
26
36
  EdgeConsentRequiredError: () => import_connect3.EdgeConsentRequiredError,
27
37
  EdgeError: () => import_connect3.EdgeError,
38
+ EdgeIdentityVerificationError: () => import_connect3.EdgeIdentityVerificationError,
28
39
  EdgeInsufficientScopeError: () => import_connect3.EdgeInsufficientScopeError,
29
40
  EdgeNetworkError: () => import_connect3.EdgeNetworkError,
30
41
  EdgeNotFoundError: () => import_connect3.EdgeNotFoundError,
31
42
  EdgeTokenExchangeError: () => import_connect3.EdgeTokenExchangeError,
32
43
  EdgeUserClient: () => EdgeUserClient,
44
+ TRANSFER_CATEGORIES: () => import_connect4.TRANSFER_CATEGORIES,
33
45
  getEnvironmentConfig: () => import_connect4.getEnvironmentConfig,
34
46
  isApiError: () => import_connect3.isApiError,
35
47
  isAuthenticationError: () => import_connect3.isAuthenticationError,
36
48
  isConsentRequiredError: () => import_connect3.isConsentRequiredError,
37
49
  isEdgeError: () => import_connect3.isEdgeError,
50
+ isIdentityVerificationError: () => import_connect3.isIdentityVerificationError,
38
51
  isNetworkError: () => import_connect3.isNetworkError,
39
52
  isProductionEnvironment: () => import_connect4.isProductionEnvironment
40
53
  });
@@ -85,6 +98,9 @@ function validateTransferOptions(options) {
85
98
  } else if (options.idempotencyKey.length > 255) {
86
99
  errors.idempotencyKey = ["Must be 255 characters or less"];
87
100
  }
101
+ if (options.category && !["sportsbook", "casino", "dfs", "sweepstakes"].includes(options.category)) {
102
+ errors.category = ["Must be one of: sportsbook, casino, dfs, sweepstakes"];
103
+ }
88
104
  if (Object.keys(errors).length > 0) {
89
105
  throw new import_connect.EdgeValidationError("Invalid transfer options", errors);
90
106
  }
@@ -113,14 +129,21 @@ var EdgeUserClient = class {
113
129
  amount: options.amount,
114
130
  idempotencyKey: options.idempotencyKey
115
131
  };
132
+ if (options.category) {
133
+ body.category = options.category;
134
+ }
116
135
  return this.server._apiRequest("POST", "/transfer", this.accessToken, body);
117
136
  }
118
- async verifyTransfer(transferId, otp) {
137
+ async verifyTransfer(transferId, otp, options) {
138
+ const body = { otp };
139
+ if (options?.sdkGeo) {
140
+ body.sdkGeo = options.sdkGeo;
141
+ }
119
142
  return this.server._apiRequest(
120
143
  "POST",
121
144
  `/transfer/${encodeURIComponent(transferId)}/verify`,
122
145
  this.accessToken,
123
- { otp }
146
+ body
124
147
  );
125
148
  }
126
149
  async getTransfer(transferId) {
@@ -239,6 +262,37 @@ function fromBase64Url(value) {
239
262
  return Buffer.from(normalized, "base64");
240
263
  }
241
264
 
265
+ // src/mtls.ts
266
+ var import_node_https = __toESM(require("https"));
267
+ function createHttpsAgent(config) {
268
+ return new import_node_https.default.Agent({
269
+ cert: config.cert,
270
+ key: config.key,
271
+ rejectUnauthorized: true,
272
+ ...config.ca ? { ca: config.ca } : {}
273
+ });
274
+ }
275
+ function createUndiciDispatcher(config) {
276
+ const moduleName = "undici";
277
+ const { Agent } = require(moduleName);
278
+ return new Agent({
279
+ connect: {
280
+ cert: config.cert,
281
+ key: config.key,
282
+ rejectUnauthorized: true,
283
+ ...config.ca ? { ca: config.ca } : {}
284
+ }
285
+ });
286
+ }
287
+ function validateMtlsConfig(config) {
288
+ if (!config.cert?.trim()) {
289
+ throw new Error("EdgeConnectServer: mTLS cert is required when enabled");
290
+ }
291
+ if (!config.key?.trim()) {
292
+ throw new Error("EdgeConnectServer: mTLS key is required when enabled");
293
+ }
294
+ }
295
+
242
296
  // src/types.ts
243
297
  var DEFAULT_TIMEOUT = 3e4;
244
298
  var USER_AGENT = "@edge-markets/connect-node/1.0.0";
@@ -285,6 +339,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
285
339
  ...DEFAULT_RETRY_CONFIG,
286
340
  ...config.retry
287
341
  };
342
+ if (config.mtls?.enabled) {
343
+ validateMtlsConfig(config.mtls);
344
+ this.httpsAgent = createHttpsAgent(config.mtls);
345
+ this.dispatcher = createUndiciDispatcher(config.mtls);
346
+ }
347
+ }
348
+ /**
349
+ * Returns the `node:https.Agent` configured with mTLS client certificates.
350
+ * Use this with axios, got, or other HTTP clients. Returns `undefined` if mTLS is not configured.
351
+ */
352
+ getHttpsAgent() {
353
+ return this.httpsAgent;
288
354
  }
289
355
  /**
290
356
  * Create a user-scoped client for making authenticated API calls.
@@ -309,14 +375,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
309
375
  redirect_uri: redirectUri || this.config.redirectUri || ""
310
376
  };
311
377
  try {
312
- const response = await this.fetchWithTimeout(tokenUrl, {
313
- method: "POST",
314
- headers: {
315
- "Content-Type": "application/json",
316
- "User-Agent": USER_AGENT
378
+ const response = await this.fetchWithTimeout(
379
+ tokenUrl,
380
+ {
381
+ method: "POST",
382
+ headers: {
383
+ "Content-Type": "application/json",
384
+ "User-Agent": USER_AGENT
385
+ },
386
+ body: JSON.stringify(body)
317
387
  },
318
- body: JSON.stringify(body)
319
- });
388
+ this.dispatcher
389
+ );
320
390
  if (!response.ok) {
321
391
  const error = await response.json().catch(() => ({}));
322
392
  throw this.handleTokenError(error, response.status);
@@ -337,14 +407,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
337
407
  client_secret: this.config.clientSecret
338
408
  };
339
409
  try {
340
- const response = await this.fetchWithTimeout(tokenUrl, {
341
- method: "POST",
342
- headers: {
343
- "Content-Type": "application/json",
344
- "User-Agent": USER_AGENT
410
+ const response = await this.fetchWithTimeout(
411
+ tokenUrl,
412
+ {
413
+ method: "POST",
414
+ headers: {
415
+ "Content-Type": "application/json",
416
+ "User-Agent": USER_AGENT
417
+ },
418
+ body: JSON.stringify(body)
345
419
  },
346
- body: JSON.stringify(body)
347
- });
420
+ this.dispatcher
421
+ );
348
422
  if (!response.ok) {
349
423
  const error = await response.json().catch(() => ({}));
350
424
  throw new import_connect2.EdgeAuthenticationError(
@@ -384,11 +458,15 @@ var EdgeConnectServer = class _EdgeConnectServer {
384
458
  requestBody = { jwe: encryptMle(body, this.config.clientId, mleConfig) };
385
459
  }
386
460
  }
387
- const response = await this.fetchWithTimeout(url, {
388
- method,
389
- headers: requestHeaders,
390
- body: requestBody !== void 0 ? JSON.stringify(requestBody) : void 0
391
- });
461
+ const response = await this.fetchWithTimeout(
462
+ url,
463
+ {
464
+ method,
465
+ headers: requestHeaders,
466
+ body: requestBody !== void 0 ? JSON.stringify(requestBody) : void 0
467
+ },
468
+ this.dispatcher
469
+ );
392
470
  const rawResponseBody = await response.json().catch(() => ({}));
393
471
  let responseBody = rawResponseBody;
394
472
  if (mleEnabled && typeof rawResponseBody?.jwe === "string") {
@@ -447,14 +525,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
447
525
  async sleep(ms) {
448
526
  return new Promise((resolve) => setTimeout(resolve, ms));
449
527
  }
450
- async fetchWithTimeout(url, options) {
528
+ async fetchWithTimeout(url, options, dispatcher) {
451
529
  const controller = new AbortController();
452
530
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
453
531
  try {
454
- return await fetch(url, {
532
+ const fetchOptions = {
455
533
  ...options,
456
534
  signal: controller.signal
457
- });
535
+ };
536
+ if (dispatcher) {
537
+ fetchOptions.dispatcher = dispatcher;
538
+ }
539
+ return await fetch(url, fetchOptions);
458
540
  } finally {
459
541
  clearTimeout(timeoutId);
460
542
  }
@@ -552,16 +634,19 @@ var import_connect4 = require("@edge-markets/connect");
552
634
  EdgeConnectServer,
553
635
  EdgeConsentRequiredError,
554
636
  EdgeError,
637
+ EdgeIdentityVerificationError,
555
638
  EdgeInsufficientScopeError,
556
639
  EdgeNetworkError,
557
640
  EdgeNotFoundError,
558
641
  EdgeTokenExchangeError,
559
642
  EdgeUserClient,
643
+ TRANSFER_CATEGORIES,
560
644
  getEnvironmentConfig,
561
645
  isApiError,
562
646
  isAuthenticationError,
563
647
  isConsentRequiredError,
564
648
  isEdgeError,
649
+ isIdentityVerificationError,
565
650
  isNetworkError,
566
651
  isProductionEnvironment
567
652
  });
package/dist/index.mjs CHANGED
@@ -1,3 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/edge-connect-server.ts
2
9
  import {
3
10
  EdgeApiError,
@@ -54,6 +61,9 @@ function validateTransferOptions(options) {
54
61
  } else if (options.idempotencyKey.length > 255) {
55
62
  errors.idempotencyKey = ["Must be 255 characters or less"];
56
63
  }
64
+ if (options.category && !["sportsbook", "casino", "dfs", "sweepstakes"].includes(options.category)) {
65
+ errors.category = ["Must be one of: sportsbook, casino, dfs, sweepstakes"];
66
+ }
57
67
  if (Object.keys(errors).length > 0) {
58
68
  throw new EdgeValidationError("Invalid transfer options", errors);
59
69
  }
@@ -82,14 +92,21 @@ var EdgeUserClient = class {
82
92
  amount: options.amount,
83
93
  idempotencyKey: options.idempotencyKey
84
94
  };
95
+ if (options.category) {
96
+ body.category = options.category;
97
+ }
85
98
  return this.server._apiRequest("POST", "/transfer", this.accessToken, body);
86
99
  }
87
- async verifyTransfer(transferId, otp) {
100
+ async verifyTransfer(transferId, otp, options) {
101
+ const body = { otp };
102
+ if (options?.sdkGeo) {
103
+ body.sdkGeo = options.sdkGeo;
104
+ }
88
105
  return this.server._apiRequest(
89
106
  "POST",
90
107
  `/transfer/${encodeURIComponent(transferId)}/verify`,
91
108
  this.accessToken,
92
- { otp }
109
+ body
93
110
  );
94
111
  }
95
112
  async getTransfer(transferId) {
@@ -208,6 +225,37 @@ function fromBase64Url(value) {
208
225
  return Buffer.from(normalized, "base64");
209
226
  }
210
227
 
228
+ // src/mtls.ts
229
+ import https from "https";
230
+ function createHttpsAgent(config) {
231
+ return new https.Agent({
232
+ cert: config.cert,
233
+ key: config.key,
234
+ rejectUnauthorized: true,
235
+ ...config.ca ? { ca: config.ca } : {}
236
+ });
237
+ }
238
+ function createUndiciDispatcher(config) {
239
+ const moduleName = "undici";
240
+ const { Agent } = __require(moduleName);
241
+ return new Agent({
242
+ connect: {
243
+ cert: config.cert,
244
+ key: config.key,
245
+ rejectUnauthorized: true,
246
+ ...config.ca ? { ca: config.ca } : {}
247
+ }
248
+ });
249
+ }
250
+ function validateMtlsConfig(config) {
251
+ if (!config.cert?.trim()) {
252
+ throw new Error("EdgeConnectServer: mTLS cert is required when enabled");
253
+ }
254
+ if (!config.key?.trim()) {
255
+ throw new Error("EdgeConnectServer: mTLS key is required when enabled");
256
+ }
257
+ }
258
+
211
259
  // src/types.ts
212
260
  var DEFAULT_TIMEOUT = 3e4;
213
261
  var USER_AGENT = "@edge-markets/connect-node/1.0.0";
@@ -254,6 +302,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
254
302
  ...DEFAULT_RETRY_CONFIG,
255
303
  ...config.retry
256
304
  };
305
+ if (config.mtls?.enabled) {
306
+ validateMtlsConfig(config.mtls);
307
+ this.httpsAgent = createHttpsAgent(config.mtls);
308
+ this.dispatcher = createUndiciDispatcher(config.mtls);
309
+ }
310
+ }
311
+ /**
312
+ * Returns the `node:https.Agent` configured with mTLS client certificates.
313
+ * Use this with axios, got, or other HTTP clients. Returns `undefined` if mTLS is not configured.
314
+ */
315
+ getHttpsAgent() {
316
+ return this.httpsAgent;
257
317
  }
258
318
  /**
259
319
  * Create a user-scoped client for making authenticated API calls.
@@ -278,14 +338,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
278
338
  redirect_uri: redirectUri || this.config.redirectUri || ""
279
339
  };
280
340
  try {
281
- const response = await this.fetchWithTimeout(tokenUrl, {
282
- method: "POST",
283
- headers: {
284
- "Content-Type": "application/json",
285
- "User-Agent": USER_AGENT
341
+ const response = await this.fetchWithTimeout(
342
+ tokenUrl,
343
+ {
344
+ method: "POST",
345
+ headers: {
346
+ "Content-Type": "application/json",
347
+ "User-Agent": USER_AGENT
348
+ },
349
+ body: JSON.stringify(body)
286
350
  },
287
- body: JSON.stringify(body)
288
- });
351
+ this.dispatcher
352
+ );
289
353
  if (!response.ok) {
290
354
  const error = await response.json().catch(() => ({}));
291
355
  throw this.handleTokenError(error, response.status);
@@ -306,14 +370,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
306
370
  client_secret: this.config.clientSecret
307
371
  };
308
372
  try {
309
- const response = await this.fetchWithTimeout(tokenUrl, {
310
- method: "POST",
311
- headers: {
312
- "Content-Type": "application/json",
313
- "User-Agent": USER_AGENT
373
+ const response = await this.fetchWithTimeout(
374
+ tokenUrl,
375
+ {
376
+ method: "POST",
377
+ headers: {
378
+ "Content-Type": "application/json",
379
+ "User-Agent": USER_AGENT
380
+ },
381
+ body: JSON.stringify(body)
314
382
  },
315
- body: JSON.stringify(body)
316
- });
383
+ this.dispatcher
384
+ );
317
385
  if (!response.ok) {
318
386
  const error = await response.json().catch(() => ({}));
319
387
  throw new EdgeAuthenticationError(
@@ -353,11 +421,15 @@ var EdgeConnectServer = class _EdgeConnectServer {
353
421
  requestBody = { jwe: encryptMle(body, this.config.clientId, mleConfig) };
354
422
  }
355
423
  }
356
- const response = await this.fetchWithTimeout(url, {
357
- method,
358
- headers: requestHeaders,
359
- body: requestBody !== void 0 ? JSON.stringify(requestBody) : void 0
360
- });
424
+ const response = await this.fetchWithTimeout(
425
+ url,
426
+ {
427
+ method,
428
+ headers: requestHeaders,
429
+ body: requestBody !== void 0 ? JSON.stringify(requestBody) : void 0
430
+ },
431
+ this.dispatcher
432
+ );
361
433
  const rawResponseBody = await response.json().catch(() => ({}));
362
434
  let responseBody = rawResponseBody;
363
435
  if (mleEnabled && typeof rawResponseBody?.jwe === "string") {
@@ -416,14 +488,18 @@ var EdgeConnectServer = class _EdgeConnectServer {
416
488
  async sleep(ms) {
417
489
  return new Promise((resolve) => setTimeout(resolve, ms));
418
490
  }
419
- async fetchWithTimeout(url, options) {
491
+ async fetchWithTimeout(url, options, dispatcher) {
420
492
  const controller = new AbortController();
421
493
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
422
494
  try {
423
- return await fetch(url, {
495
+ const fetchOptions = {
424
496
  ...options,
425
497
  signal: controller.signal
426
- });
498
+ };
499
+ if (dispatcher) {
500
+ fetchOptions.dispatcher = dispatcher;
501
+ }
502
+ return await fetch(url, fetchOptions);
427
503
  } finally {
428
504
  clearTimeout(timeoutId);
429
505
  }
@@ -517,6 +593,7 @@ import {
517
593
  EdgeAuthenticationError as EdgeAuthenticationError2,
518
594
  EdgeConsentRequiredError as EdgeConsentRequiredError2,
519
595
  EdgeError as EdgeError2,
596
+ EdgeIdentityVerificationError as EdgeIdentityVerificationError2,
520
597
  EdgeInsufficientScopeError as EdgeInsufficientScopeError2,
521
598
  EdgeNetworkError as EdgeNetworkError2,
522
599
  EdgeNotFoundError as EdgeNotFoundError2,
@@ -525,25 +602,29 @@ import {
525
602
  isAuthenticationError,
526
603
  isConsentRequiredError,
527
604
  isEdgeError,
605
+ isIdentityVerificationError,
528
606
  isNetworkError
529
607
  } from "@edge-markets/connect";
530
- import { getEnvironmentConfig as getEnvironmentConfig2, isProductionEnvironment } from "@edge-markets/connect";
608
+ import { TRANSFER_CATEGORIES, getEnvironmentConfig as getEnvironmentConfig2, isProductionEnvironment } from "@edge-markets/connect";
531
609
  export {
532
610
  EdgeApiError2 as EdgeApiError,
533
611
  EdgeAuthenticationError2 as EdgeAuthenticationError,
534
612
  EdgeConnectServer,
535
613
  EdgeConsentRequiredError2 as EdgeConsentRequiredError,
536
614
  EdgeError2 as EdgeError,
615
+ EdgeIdentityVerificationError2 as EdgeIdentityVerificationError,
537
616
  EdgeInsufficientScopeError2 as EdgeInsufficientScopeError,
538
617
  EdgeNetworkError2 as EdgeNetworkError,
539
618
  EdgeNotFoundError2 as EdgeNotFoundError,
540
619
  EdgeTokenExchangeError2 as EdgeTokenExchangeError,
541
620
  EdgeUserClient,
621
+ TRANSFER_CATEGORIES,
542
622
  getEnvironmentConfig2 as getEnvironmentConfig,
543
623
  isApiError,
544
624
  isAuthenticationError,
545
625
  isConsentRequiredError,
546
626
  isEdgeError,
627
+ isIdentityVerificationError,
547
628
  isNetworkError,
548
629
  isProductionEnvironment
549
630
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edge-markets/connect-node",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Server SDK for EDGE Connect token exchange and API calls",
5
5
  "author": "Edge Markets",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@edge-markets/connect": "^1.4.0"
24
+ "@edge-markets/connect": "^1.5.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsup": "^8.0.0",