@edge-markets/connect-react-native 1.4.2 → 1.5.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 +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +30 -10
- package/dist/index.mjs +36 -14
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EdgeLinkConfigBase, EdgeEnvironment, EdgeScope, EdgeLinkSuccess, EdgeLinkEvent, SdkGeolocation, PKCEPair } from '@edge-markets/connect';
|
|
2
|
-
export { ALL_EDGE_SCOPES, Balance, EDGE_ENVIRONMENTS, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeLinkEvent, EdgeLinkEventName, EdgeLinkExit, EdgeLinkSuccess, EdgeNetworkError, EdgePopupBlockedError, EdgeScope, EdgeStateMismatchError, EdgeTokenExchangeError, EdgeTokens, PKCEPair, SCOPE_DESCRIPTIONS, SdkGeolocation, Transfer, User, formatScopesForEnvironment, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isNetworkError } from '@edge-markets/connect';
|
|
2
|
+
export { ACTIVE_EDGE_SCOPES, ALL_EDGE_SCOPES, Balance, EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE, EDGE_ENVIRONMENTS, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeFeatureUnavailableError, EdgeLinkEvent, EdgeLinkEventName, EdgeLinkExit, EdgeLinkSuccess, EdgeNetworkError, EdgePopupBlockedError, EdgeScope, EdgeStateMismatchError, EdgeTokenExchangeError, EdgeTokens, PKCEPair, SCOPE_DESCRIPTIONS, SdkGeolocation, Transfer, User, formatScopesForEnvironment, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isFeatureUnavailableError, isNetworkError } from '@edge-markets/connect';
|
|
3
3
|
|
|
4
4
|
interface EdgeLinkConfig extends EdgeLinkConfigBase {
|
|
5
5
|
redirectUri: string;
|
|
@@ -18,6 +18,8 @@ declare class EdgeLink {
|
|
|
18
18
|
close(): Promise<void>;
|
|
19
19
|
destroy(): void;
|
|
20
20
|
private buildLinkUrl;
|
|
21
|
+
private getScopes;
|
|
22
|
+
private assertActiveScopes;
|
|
21
23
|
private setupLinkListener;
|
|
22
24
|
private removeLinkListener;
|
|
23
25
|
private processCallback;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EdgeLinkConfigBase, EdgeEnvironment, EdgeScope, EdgeLinkSuccess, EdgeLinkEvent, SdkGeolocation, PKCEPair } from '@edge-markets/connect';
|
|
2
|
-
export { ALL_EDGE_SCOPES, Balance, EDGE_ENVIRONMENTS, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeLinkEvent, EdgeLinkEventName, EdgeLinkExit, EdgeLinkSuccess, EdgeNetworkError, EdgePopupBlockedError, EdgeScope, EdgeStateMismatchError, EdgeTokenExchangeError, EdgeTokens, PKCEPair, SCOPE_DESCRIPTIONS, SdkGeolocation, Transfer, User, formatScopesForEnvironment, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isNetworkError } from '@edge-markets/connect';
|
|
2
|
+
export { ACTIVE_EDGE_SCOPES, ALL_EDGE_SCOPES, Balance, EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE, EDGE_ENVIRONMENTS, EdgeApiError, EdgeAuthenticationError, EdgeConsentRequiredError, EdgeEnvironment, EdgeError, EdgeFeatureUnavailableError, EdgeLinkEvent, EdgeLinkEventName, EdgeLinkExit, EdgeLinkSuccess, EdgeNetworkError, EdgePopupBlockedError, EdgeScope, EdgeStateMismatchError, EdgeTokenExchangeError, EdgeTokens, PKCEPair, SCOPE_DESCRIPTIONS, SdkGeolocation, Transfer, User, formatScopesForEnvironment, getEnvironmentConfig, isApiError, isAuthenticationError, isConsentRequiredError, isFeatureUnavailableError, isNetworkError } from '@edge-markets/connect';
|
|
3
3
|
|
|
4
4
|
interface EdgeLinkConfig extends EdgeLinkConfigBase {
|
|
5
5
|
redirectUri: string;
|
|
@@ -18,6 +18,8 @@ declare class EdgeLink {
|
|
|
18
18
|
close(): Promise<void>;
|
|
19
19
|
destroy(): void;
|
|
20
20
|
private buildLinkUrl;
|
|
21
|
+
private getScopes;
|
|
22
|
+
private assertActiveScopes;
|
|
21
23
|
private setupLinkListener;
|
|
22
24
|
private removeLinkListener;
|
|
23
25
|
private processCallback;
|
package/dist/index.js
CHANGED
|
@@ -30,12 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
ACTIVE_EDGE_SCOPES: () => import_connect2.ACTIVE_EDGE_SCOPES,
|
|
33
34
|
ALL_EDGE_SCOPES: () => import_connect2.ALL_EDGE_SCOPES,
|
|
35
|
+
EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE: () => import_connect2.EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE,
|
|
34
36
|
EDGE_ENVIRONMENTS: () => import_connect2.EDGE_ENVIRONMENTS,
|
|
35
37
|
EdgeApiError: () => import_connect2.EdgeApiError,
|
|
36
38
|
EdgeAuthenticationError: () => import_connect2.EdgeAuthenticationError,
|
|
37
39
|
EdgeConsentRequiredError: () => import_connect2.EdgeConsentRequiredError,
|
|
38
40
|
EdgeError: () => import_connect2.EdgeError,
|
|
41
|
+
EdgeFeatureUnavailableError: () => import_connect2.EdgeFeatureUnavailableError,
|
|
39
42
|
EdgeLink: () => EdgeLink,
|
|
40
43
|
EdgeNetworkError: () => import_connect2.EdgeNetworkError,
|
|
41
44
|
EdgePopupBlockedError: () => import_connect2.EdgePopupBlockedError,
|
|
@@ -50,6 +53,7 @@ __export(index_exports, {
|
|
|
50
53
|
isApiError: () => import_connect2.isApiError,
|
|
51
54
|
isAuthenticationError: () => import_connect2.isAuthenticationError,
|
|
52
55
|
isConsentRequiredError: () => import_connect2.isConsentRequiredError,
|
|
56
|
+
isFeatureUnavailableError: () => import_connect2.isFeatureUnavailableError,
|
|
53
57
|
isNetworkError: () => import_connect2.isNetworkError,
|
|
54
58
|
isSecureCryptoAvailable: () => isSecureCryptoAvailable,
|
|
55
59
|
useEdgeLink: () => useEdgeLink,
|
|
@@ -381,6 +385,8 @@ var EdgeLink = class {
|
|
|
381
385
|
console.warn("[EdgeLink] Already open");
|
|
382
386
|
return;
|
|
383
387
|
}
|
|
388
|
+
const scopes = this.getScopes();
|
|
389
|
+
this.assertActiveScopes(scopes);
|
|
384
390
|
this.emitEvent("OPEN");
|
|
385
391
|
this.isOpen = true;
|
|
386
392
|
try {
|
|
@@ -424,7 +430,7 @@ var EdgeLink = class {
|
|
|
424
430
|
}
|
|
425
431
|
buildLinkUrl() {
|
|
426
432
|
const url = new URL((0, import_connect.getLinkUrl)(this.config.environment, this.config.linkUrl));
|
|
427
|
-
const scopes = this.
|
|
433
|
+
const scopes = this.getScopes();
|
|
428
434
|
url.searchParams.set("client_id", this.config.clientId);
|
|
429
435
|
url.searchParams.set("state", this.state);
|
|
430
436
|
url.searchParams.set("code_challenge", this.pkce.challenge);
|
|
@@ -436,6 +442,14 @@ var EdgeLink = class {
|
|
|
436
442
|
url.searchParams.set("flow", "redirect");
|
|
437
443
|
return url.toString();
|
|
438
444
|
}
|
|
445
|
+
getScopes() {
|
|
446
|
+
return this.config.scopes || import_connect.ACTIVE_EDGE_SCOPES;
|
|
447
|
+
}
|
|
448
|
+
assertActiveScopes(scopes) {
|
|
449
|
+
if (scopes.some((scope) => (0, import_connect.isTransferWriteScope)(scope))) {
|
|
450
|
+
throw new import_connect.EdgeFeatureUnavailableError();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
439
453
|
setupLinkListener() {
|
|
440
454
|
this.removeLinkListener();
|
|
441
455
|
this.linkListener = import_react_native.Linking.addEventListener("url", ({ url }) => {
|
|
@@ -568,21 +582,23 @@ function useEdgeLink(config) {
|
|
|
568
582
|
linkRef.current?.destroy();
|
|
569
583
|
linkRef.current = null;
|
|
570
584
|
};
|
|
571
|
-
}, [
|
|
572
|
-
config.clientId,
|
|
573
|
-
config.environment,
|
|
574
|
-
config.redirectUri,
|
|
575
|
-
config.scopes,
|
|
576
|
-
config.linkUrl,
|
|
577
|
-
config.useExternalBrowser
|
|
578
|
-
]);
|
|
585
|
+
}, [config.clientId, config.environment, config.redirectUri, config.scopes, config.linkUrl, config.useExternalBrowser]);
|
|
579
586
|
const open = (0, import_react.useCallback)(async () => {
|
|
580
587
|
if (!linkRef.current) return;
|
|
581
588
|
setIsOpen(true);
|
|
582
589
|
setIsSuccess(false);
|
|
583
590
|
setIsError(false);
|
|
584
591
|
setError(null);
|
|
585
|
-
|
|
592
|
+
try {
|
|
593
|
+
await linkRef.current.open();
|
|
594
|
+
} catch (err) {
|
|
595
|
+
setIsOpen(false);
|
|
596
|
+
setIsError(true);
|
|
597
|
+
setError({
|
|
598
|
+
code: err instanceof Error && "code" in err ? String(err.code) : "open_failed",
|
|
599
|
+
message: err instanceof Error ? err.message : "Failed to open EdgeLink"
|
|
600
|
+
});
|
|
601
|
+
}
|
|
586
602
|
}, []);
|
|
587
603
|
const close = (0, import_react.useCallback)(async () => {
|
|
588
604
|
if (!linkRef.current) return;
|
|
@@ -694,12 +710,15 @@ async function collectGeolocation() {
|
|
|
694
710
|
}
|
|
695
711
|
// Annotate the CommonJS export names for ESM import in node:
|
|
696
712
|
0 && (module.exports = {
|
|
713
|
+
ACTIVE_EDGE_SCOPES,
|
|
697
714
|
ALL_EDGE_SCOPES,
|
|
715
|
+
EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE,
|
|
698
716
|
EDGE_ENVIRONMENTS,
|
|
699
717
|
EdgeApiError,
|
|
700
718
|
EdgeAuthenticationError,
|
|
701
719
|
EdgeConsentRequiredError,
|
|
702
720
|
EdgeError,
|
|
721
|
+
EdgeFeatureUnavailableError,
|
|
703
722
|
EdgeLink,
|
|
704
723
|
EdgeNetworkError,
|
|
705
724
|
EdgePopupBlockedError,
|
|
@@ -714,6 +733,7 @@ async function collectGeolocation() {
|
|
|
714
733
|
isApiError,
|
|
715
734
|
isAuthenticationError,
|
|
716
735
|
isConsentRequiredError,
|
|
736
|
+
isFeatureUnavailableError,
|
|
717
737
|
isNetworkError,
|
|
718
738
|
isSecureCryptoAvailable,
|
|
719
739
|
useEdgeLink,
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
ACTIVE_EDGE_SCOPES as ACTIVE_EDGE_SCOPES2,
|
|
4
|
+
ALL_EDGE_SCOPES,
|
|
5
|
+
EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE,
|
|
4
6
|
EDGE_ENVIRONMENTS,
|
|
5
7
|
EdgeApiError,
|
|
6
8
|
EdgeAuthenticationError,
|
|
7
9
|
EdgeConsentRequiredError,
|
|
8
10
|
EdgeError,
|
|
11
|
+
EdgeFeatureUnavailableError as EdgeFeatureUnavailableError2,
|
|
9
12
|
EdgeNetworkError,
|
|
10
13
|
EdgePopupBlockedError,
|
|
11
14
|
EdgeStateMismatchError,
|
|
@@ -16,14 +19,17 @@ import {
|
|
|
16
19
|
isApiError,
|
|
17
20
|
isAuthenticationError,
|
|
18
21
|
isConsentRequiredError,
|
|
22
|
+
isFeatureUnavailableError,
|
|
19
23
|
isNetworkError
|
|
20
24
|
} from "@edge-markets/connect";
|
|
21
25
|
|
|
22
26
|
// src/edge-link.ts
|
|
23
27
|
import {
|
|
24
|
-
|
|
28
|
+
ACTIVE_EDGE_SCOPES,
|
|
29
|
+
EdgeFeatureUnavailableError,
|
|
25
30
|
formatScopesForEnvironment,
|
|
26
|
-
getLinkUrl
|
|
31
|
+
getLinkUrl,
|
|
32
|
+
isTransferWriteScope
|
|
27
33
|
} from "@edge-markets/connect";
|
|
28
34
|
import { Linking, Platform } from "react-native";
|
|
29
35
|
|
|
@@ -345,6 +351,8 @@ var EdgeLink = class {
|
|
|
345
351
|
console.warn("[EdgeLink] Already open");
|
|
346
352
|
return;
|
|
347
353
|
}
|
|
354
|
+
const scopes = this.getScopes();
|
|
355
|
+
this.assertActiveScopes(scopes);
|
|
348
356
|
this.emitEvent("OPEN");
|
|
349
357
|
this.isOpen = true;
|
|
350
358
|
try {
|
|
@@ -388,7 +396,7 @@ var EdgeLink = class {
|
|
|
388
396
|
}
|
|
389
397
|
buildLinkUrl() {
|
|
390
398
|
const url = new URL(getLinkUrl(this.config.environment, this.config.linkUrl));
|
|
391
|
-
const scopes = this.
|
|
399
|
+
const scopes = this.getScopes();
|
|
392
400
|
url.searchParams.set("client_id", this.config.clientId);
|
|
393
401
|
url.searchParams.set("state", this.state);
|
|
394
402
|
url.searchParams.set("code_challenge", this.pkce.challenge);
|
|
@@ -400,6 +408,14 @@ var EdgeLink = class {
|
|
|
400
408
|
url.searchParams.set("flow", "redirect");
|
|
401
409
|
return url.toString();
|
|
402
410
|
}
|
|
411
|
+
getScopes() {
|
|
412
|
+
return this.config.scopes || ACTIVE_EDGE_SCOPES;
|
|
413
|
+
}
|
|
414
|
+
assertActiveScopes(scopes) {
|
|
415
|
+
if (scopes.some((scope) => isTransferWriteScope(scope))) {
|
|
416
|
+
throw new EdgeFeatureUnavailableError();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
403
419
|
setupLinkListener() {
|
|
404
420
|
this.removeLinkListener();
|
|
405
421
|
this.linkListener = Linking.addEventListener("url", ({ url }) => {
|
|
@@ -532,21 +548,23 @@ function useEdgeLink(config) {
|
|
|
532
548
|
linkRef.current?.destroy();
|
|
533
549
|
linkRef.current = null;
|
|
534
550
|
};
|
|
535
|
-
}, [
|
|
536
|
-
config.clientId,
|
|
537
|
-
config.environment,
|
|
538
|
-
config.redirectUri,
|
|
539
|
-
config.scopes,
|
|
540
|
-
config.linkUrl,
|
|
541
|
-
config.useExternalBrowser
|
|
542
|
-
]);
|
|
551
|
+
}, [config.clientId, config.environment, config.redirectUri, config.scopes, config.linkUrl, config.useExternalBrowser]);
|
|
543
552
|
const open = useCallback(async () => {
|
|
544
553
|
if (!linkRef.current) return;
|
|
545
554
|
setIsOpen(true);
|
|
546
555
|
setIsSuccess(false);
|
|
547
556
|
setIsError(false);
|
|
548
557
|
setError(null);
|
|
549
|
-
|
|
558
|
+
try {
|
|
559
|
+
await linkRef.current.open();
|
|
560
|
+
} catch (err) {
|
|
561
|
+
setIsOpen(false);
|
|
562
|
+
setIsError(true);
|
|
563
|
+
setError({
|
|
564
|
+
code: err instanceof Error && "code" in err ? String(err.code) : "open_failed",
|
|
565
|
+
message: err instanceof Error ? err.message : "Failed to open EdgeLink"
|
|
566
|
+
});
|
|
567
|
+
}
|
|
550
568
|
}, []);
|
|
551
569
|
const close = useCallback(async () => {
|
|
552
570
|
if (!linkRef.current) return;
|
|
@@ -657,12 +675,15 @@ async function collectGeolocation() {
|
|
|
657
675
|
return null;
|
|
658
676
|
}
|
|
659
677
|
export {
|
|
660
|
-
|
|
678
|
+
ACTIVE_EDGE_SCOPES2 as ACTIVE_EDGE_SCOPES,
|
|
679
|
+
ALL_EDGE_SCOPES,
|
|
680
|
+
EDGE_CONNECT_FEATURE_UNAVAILABLE_MESSAGE,
|
|
661
681
|
EDGE_ENVIRONMENTS,
|
|
662
682
|
EdgeApiError,
|
|
663
683
|
EdgeAuthenticationError,
|
|
664
684
|
EdgeConsentRequiredError,
|
|
665
685
|
EdgeError,
|
|
686
|
+
EdgeFeatureUnavailableError2 as EdgeFeatureUnavailableError,
|
|
666
687
|
EdgeLink,
|
|
667
688
|
EdgeNetworkError,
|
|
668
689
|
EdgePopupBlockedError,
|
|
@@ -677,6 +698,7 @@ export {
|
|
|
677
698
|
isApiError,
|
|
678
699
|
isAuthenticationError,
|
|
679
700
|
isConsentRequiredError,
|
|
701
|
+
isFeatureUnavailableError,
|
|
680
702
|
isNetworkError,
|
|
681
703
|
isSecureCryptoAvailable,
|
|
682
704
|
useEdgeLink,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edge-markets/connect-react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "React Native SDK for EDGE Connect authentication flow for mobile apps",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"author": "EdgeBoost",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@edge-markets/connect": "^1.
|
|
33
|
+
"@edge-markets/connect": "^1.8.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18.0.0",
|