@edge-markets/connect-node 1.9.0 → 1.10.1
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/README.md +37 -1
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +184 -134
- package/dist/index.mjs +62 -17
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
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
|
-
|
|
8
1
|
// src/edge-connect-server.ts
|
|
9
2
|
import {
|
|
10
3
|
EdgeApiError,
|
|
@@ -19,8 +12,12 @@ import {
|
|
|
19
12
|
getEnvironmentConfig
|
|
20
13
|
} from "@edge-markets/connect";
|
|
21
14
|
|
|
15
|
+
// src/edge-user-client.ts
|
|
16
|
+
import { EdgeFeatureUnavailableError as EdgeFeatureUnavailableError2 } from "@edge-markets/connect";
|
|
17
|
+
|
|
22
18
|
// src/transfer-helpers.ts
|
|
23
19
|
import {
|
|
20
|
+
EdgeFeatureUnavailableError,
|
|
24
21
|
EdgeValidationError
|
|
25
22
|
} from "@edge-markets/connect";
|
|
26
23
|
import crypto from "crypto";
|
|
@@ -117,6 +114,7 @@ function mapTransferStatusToPartnerState(status, mapping) {
|
|
|
117
114
|
return partnerState;
|
|
118
115
|
}
|
|
119
116
|
async function startTransferVerification(client, options) {
|
|
117
|
+
assertTransferFeatureAvailable();
|
|
120
118
|
const origin = typeof options.origin === "string" ? options.origin.trim() : "";
|
|
121
119
|
if (!origin) {
|
|
122
120
|
throw new EdgeValidationError("Verification origin is required", {
|
|
@@ -136,6 +134,14 @@ async function startTransferVerification(client, options) {
|
|
|
136
134
|
const verificationSession = await client.createVerificationSession(transferId, { origin });
|
|
137
135
|
return { transfer, verificationSession };
|
|
138
136
|
}
|
|
137
|
+
function assertTransferFeatureAvailable() {
|
|
138
|
+
if (!isTransferFeatureAvailable()) {
|
|
139
|
+
throw new EdgeFeatureUnavailableError();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function isTransferFeatureAvailable() {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
139
145
|
function parseMoneyToCents(value, field, options = {}) {
|
|
140
146
|
let input;
|
|
141
147
|
if (typeof value === "number") {
|
|
@@ -257,6 +263,7 @@ var EdgeUserClient = class {
|
|
|
257
263
|
return this.server._apiRequest("GET", "/balance", this.accessToken);
|
|
258
264
|
}
|
|
259
265
|
async initiateTransfer(options) {
|
|
266
|
+
assertTransferFeatureAvailable2();
|
|
260
267
|
validateTransferOptions(options);
|
|
261
268
|
const body = {
|
|
262
269
|
type: options.type,
|
|
@@ -269,13 +276,16 @@ var EdgeUserClient = class {
|
|
|
269
276
|
return this.server._apiRequest("POST", "/transfer", this.accessToken, body);
|
|
270
277
|
}
|
|
271
278
|
async startTransferVerification(options) {
|
|
279
|
+
assertTransferFeatureAvailable2();
|
|
272
280
|
return startTransferVerification(this, options);
|
|
273
281
|
}
|
|
274
282
|
async getTransfer(transferId) {
|
|
283
|
+
assertTransferFeatureAvailable2();
|
|
275
284
|
validateTransferId(transferId);
|
|
276
285
|
return this.server._apiRequest("GET", `/transfer/${encodeURIComponent(transferId)}`, this.accessToken);
|
|
277
286
|
}
|
|
278
287
|
async listTransfers(params) {
|
|
288
|
+
assertTransferFeatureAvailable2();
|
|
279
289
|
const queryParams = new URLSearchParams();
|
|
280
290
|
if (params?.limit) queryParams.set("limit", String(params.limit));
|
|
281
291
|
if (params?.offset) queryParams.set("offset", String(params.offset));
|
|
@@ -288,11 +298,11 @@ var EdgeUserClient = class {
|
|
|
288
298
|
return this.server._apiRequest("DELETE", "/consent", this.accessToken);
|
|
289
299
|
}
|
|
290
300
|
/**
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* The handoff token is single-use and expires in 120 seconds.
|
|
301
|
+
* Reserved for a future transfer release.
|
|
302
|
+
* Currently throws EdgeFeatureUnavailableError before validation or network I/O.
|
|
294
303
|
*/
|
|
295
304
|
async createVerificationSession(transferId, options) {
|
|
305
|
+
assertTransferFeatureAvailable2();
|
|
296
306
|
validateTransferId(transferId);
|
|
297
307
|
return this.server._apiRequest(
|
|
298
308
|
"POST",
|
|
@@ -302,10 +312,11 @@ var EdgeUserClient = class {
|
|
|
302
312
|
);
|
|
303
313
|
}
|
|
304
314
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
315
|
+
* Reserved for a future transfer release.
|
|
316
|
+
* Currently throws EdgeFeatureUnavailableError before validation or network I/O.
|
|
307
317
|
*/
|
|
308
318
|
async getVerificationSessionStatus(transferId, sessionId) {
|
|
319
|
+
assertTransferFeatureAvailable2();
|
|
309
320
|
validateTransferId(transferId);
|
|
310
321
|
return this.server._apiRequest(
|
|
311
322
|
"GET",
|
|
@@ -314,6 +325,14 @@ var EdgeUserClient = class {
|
|
|
314
325
|
);
|
|
315
326
|
}
|
|
316
327
|
};
|
|
328
|
+
function assertTransferFeatureAvailable2() {
|
|
329
|
+
if (!isTransferFeatureAvailable2()) {
|
|
330
|
+
throw new EdgeFeatureUnavailableError2();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function isTransferFeatureAvailable2() {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
317
336
|
|
|
318
337
|
// src/mle.ts
|
|
319
338
|
import { randomUUID, randomBytes, createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from "crypto";
|
|
@@ -394,6 +413,7 @@ function fromBase64Url(value) {
|
|
|
394
413
|
import fs from "fs";
|
|
395
414
|
import https from "https";
|
|
396
415
|
import tls from "tls";
|
|
416
|
+
import { Agent as UndiciAgent } from "undici";
|
|
397
417
|
var CERT_PATTERN = /-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g;
|
|
398
418
|
function normalizeCaBundle(ca) {
|
|
399
419
|
if (!ca) return [];
|
|
@@ -431,9 +451,7 @@ function createHttpsAgent(config) {
|
|
|
431
451
|
}
|
|
432
452
|
function createUndiciDispatcher(config) {
|
|
433
453
|
const ca = buildServerCaBundle(config.ca);
|
|
434
|
-
|
|
435
|
-
const { Agent } = __require(moduleName);
|
|
436
|
-
return new Agent({
|
|
454
|
+
return new UndiciAgent({
|
|
437
455
|
connect: {
|
|
438
456
|
cert: config.cert,
|
|
439
457
|
key: config.key,
|
|
@@ -1483,6 +1501,16 @@ function readEnvironment(env) {
|
|
|
1483
1501
|
}
|
|
1484
1502
|
return value;
|
|
1485
1503
|
}
|
|
1504
|
+
function readBooleanEnv(env, name) {
|
|
1505
|
+
const value = readEnv(env, name);
|
|
1506
|
+
if (!value) return void 0;
|
|
1507
|
+
const normalized = value.toLowerCase();
|
|
1508
|
+
if (["true", "1", "yes"].includes(normalized)) return true;
|
|
1509
|
+
if (["false", "0", "no"].includes(normalized)) return false;
|
|
1510
|
+
throw new EdgeValidationError4(`Invalid ${name}`, {
|
|
1511
|
+
[name]: ["Must be one of: true, false, 1, 0, yes, no"]
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1486
1514
|
function readTimeout(env, override) {
|
|
1487
1515
|
if (override !== void 0) return override;
|
|
1488
1516
|
const value = readFirstEnv(env, ["EDGE_TIMEOUT_MS", "EDGE_REQUEST_TIMEOUT_MS"]);
|
|
@@ -1498,7 +1526,12 @@ function readTimeout(env, override) {
|
|
|
1498
1526
|
function buildMtlsConfig(env, requireMtls, warnings) {
|
|
1499
1527
|
const cert = readPemValue(env, "EDGE_MTLS_CERT", "EDGE_MTLS_CERT_PATH", warnings);
|
|
1500
1528
|
const key = readPemValue(env, "EDGE_MTLS_KEY", "EDGE_MTLS_KEY_PATH", warnings);
|
|
1501
|
-
const
|
|
1529
|
+
const serverCa = readPemValue(env, "EDGE_SERVER_CA_PEM", "EDGE_SERVER_CA_PEM_PATH", warnings);
|
|
1530
|
+
const hasLegacyCa = !!readFirstEnv(env, ["EDGE_MTLS_CA", "EDGE_MTLS_CA_PATH"]);
|
|
1531
|
+
if (serverCa && hasLegacyCa) {
|
|
1532
|
+
warnings.push("EDGE_SERVER_CA_PEM and EDGE_MTLS_CA are both set; using EDGE_SERVER_CA_PEM");
|
|
1533
|
+
}
|
|
1534
|
+
const ca = serverCa || readPemValue(env, "EDGE_MTLS_CA", "EDGE_MTLS_CA_PATH", warnings);
|
|
1502
1535
|
if (!cert && !key && !ca) {
|
|
1503
1536
|
if (requireMtls) {
|
|
1504
1537
|
throw new EdgeValidationError4("mTLS is required but no EDGE_MTLS_CERT or EDGE_MTLS_KEY was provided", {
|
|
@@ -1537,7 +1570,7 @@ function createEdgeConnectServerFromEnv(options = {}) {
|
|
|
1537
1570
|
const environment = readEnvironment(env);
|
|
1538
1571
|
const apiBaseUrl = readEnv(env, "EDGE_API_BASE_URL");
|
|
1539
1572
|
const mtlsRequiredByTarget = inferMtlsRequirement(environment, apiBaseUrl);
|
|
1540
|
-
const requireMtls = options.requireMtls ?? false;
|
|
1573
|
+
const requireMtls = options.requireMtls ?? readBooleanEnv(env, "EDGE_REQUIRE_MTLS") ?? false;
|
|
1541
1574
|
const mtls = buildMtlsConfig(env, requireMtls, warnings);
|
|
1542
1575
|
const timeout = readTimeout(env, options.timeout);
|
|
1543
1576
|
const clientId = readFirstEnv(env, ["EDGE_CLIENT_ID", "EDGE_CONNECT_CLIENT_ID"]) || "";
|
|
@@ -1592,6 +1625,7 @@ function createEdgeConnectServerFromEnv(options = {}) {
|
|
|
1592
1625
|
import {
|
|
1593
1626
|
EdgeConsentRequiredError as EdgeConsentRequiredError2,
|
|
1594
1627
|
EdgeError as EdgeError2,
|
|
1628
|
+
EdgeFeatureUnavailableError as EdgeFeatureUnavailableError3,
|
|
1595
1629
|
EdgeIdentityVerificationError as EdgeIdentityVerificationError2,
|
|
1596
1630
|
EdgeNetworkError as EdgeNetworkError2,
|
|
1597
1631
|
EdgeValidationError as EdgeValidationError5
|
|
@@ -1617,6 +1651,9 @@ function toEdgeProblemJson(error) {
|
|
|
1617
1651
|
fieldErrors: error.fieldErrors
|
|
1618
1652
|
});
|
|
1619
1653
|
}
|
|
1654
|
+
if (error instanceof EdgeFeatureUnavailableError3) {
|
|
1655
|
+
return problem(error, "Feature unavailable", error.statusCode ?? 501);
|
|
1656
|
+
}
|
|
1620
1657
|
if (error instanceof EdgeNetworkError2) {
|
|
1621
1658
|
return problem(error, "EDGE network error", error.statusCode ?? 502);
|
|
1622
1659
|
}
|
|
@@ -2541,10 +2578,12 @@ function stableStringify(value) {
|
|
|
2541
2578
|
|
|
2542
2579
|
// src/index.ts
|
|
2543
2580
|
import {
|
|
2581
|
+
EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE,
|
|
2544
2582
|
EdgeApiError as EdgeApiError2,
|
|
2545
2583
|
EdgeAuthenticationError as EdgeAuthenticationError4,
|
|
2546
2584
|
EdgeConsentRequiredError as EdgeConsentRequiredError3,
|
|
2547
2585
|
EdgeError as EdgeError3,
|
|
2586
|
+
EdgeFeatureUnavailableError as EdgeFeatureUnavailableError4,
|
|
2548
2587
|
EdgeIdentityVerificationError as EdgeIdentityVerificationError3,
|
|
2549
2588
|
EdgeInsufficientScopeError as EdgeInsufficientScopeError2,
|
|
2550
2589
|
EdgeNetworkError as EdgeNetworkError3,
|
|
@@ -2555,23 +2594,28 @@ import {
|
|
|
2555
2594
|
isAuthenticationError,
|
|
2556
2595
|
isConsentRequiredError,
|
|
2557
2596
|
isEdgeError,
|
|
2597
|
+
isFeatureUnavailableError,
|
|
2558
2598
|
isIdentityVerificationError,
|
|
2559
2599
|
isNetworkError
|
|
2560
2600
|
} from "@edge-markets/connect";
|
|
2561
2601
|
import {
|
|
2602
|
+
ACTIVE_EDGE_SCOPES,
|
|
2562
2603
|
EDGE_WEBHOOK_EVENT_TYPES as EDGE_WEBHOOK_EVENT_TYPES2,
|
|
2563
2604
|
TRANSFER_CATEGORIES,
|
|
2564
2605
|
getEnvironmentConfig as getEnvironmentConfig3,
|
|
2565
2606
|
isProductionEnvironment
|
|
2566
2607
|
} from "@edge-markets/connect";
|
|
2567
2608
|
export {
|
|
2609
|
+
ACTIVE_EDGE_SCOPES,
|
|
2568
2610
|
CONNECT_TRANSFER_DIRECTIONS,
|
|
2611
|
+
EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE,
|
|
2569
2612
|
EDGE_WEBHOOK_EVENT_TYPES2 as EDGE_WEBHOOK_EVENT_TYPES,
|
|
2570
2613
|
EdgeApiError2 as EdgeApiError,
|
|
2571
2614
|
EdgeAuthenticationError4 as EdgeAuthenticationError,
|
|
2572
2615
|
EdgeConnectServer,
|
|
2573
2616
|
EdgeConsentRequiredError3 as EdgeConsentRequiredError,
|
|
2574
2617
|
EdgeError3 as EdgeError,
|
|
2618
|
+
EdgeFeatureUnavailableError4 as EdgeFeatureUnavailableError,
|
|
2575
2619
|
EdgeIdentityVerificationError3 as EdgeIdentityVerificationError,
|
|
2576
2620
|
EdgeInsufficientScopeError2 as EdgeInsufficientScopeError,
|
|
2577
2621
|
EdgeNetworkError3 as EdgeNetworkError,
|
|
@@ -2610,6 +2654,7 @@ export {
|
|
|
2610
2654
|
isEdgeError,
|
|
2611
2655
|
isEdgeTokenVaultEnvelope,
|
|
2612
2656
|
isEdgeWebhookEvent,
|
|
2657
|
+
isFeatureUnavailableError,
|
|
2613
2658
|
isIdentityVerificationError,
|
|
2614
2659
|
isNetworkError,
|
|
2615
2660
|
isProductionEnvironment,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edge-markets/connect-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Server SDK for EDGE Connect token exchange and API calls",
|
|
5
5
|
"author": "Edge Markets",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"undici": "^5.29.0",
|
|
25
|
-
"@edge-markets/connect": "^1.
|
|
25
|
+
"@edge-markets/connect": "^1.8.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "^8.0.0",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
56
56
|
"typecheck": "tsc --noEmit",
|
|
57
57
|
"test": "vitest --passWithNoTests",
|
|
58
|
-
"test:run": "vitest run --passWithNoTests"
|
|
58
|
+
"test:run": "vitest run --passWithNoTests",
|
|
59
|
+
"test:dist": "pnpm run build && node scripts/check-dist-undici.mjs"
|
|
59
60
|
}
|
|
60
61
|
}
|