@dynamic-labs/utils 3.0.0-alpha.46 → 3.0.0-alpha.48
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/CHANGELOG.md +34 -0
- package/package.json +4 -4
- package/src/errors/MfaRateLimitedError.cjs +14 -0
- package/src/errors/MfaRateLimitedError.d.ts +4 -0
- package/src/errors/MfaRateLimitedError.js +10 -0
- package/src/errors/index.d.ts +1 -0
- package/src/index.cjs +3 -0
- package/src/index.js +2 -1
- package/src/isMobile.cjs +11 -0
- package/src/isMobile.d.ts +1 -0
- package/src/isMobile.js +11 -1
- package/src/services/Oauth2Service/Oauth2Service.d.ts +3 -1
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.cjs +20 -3
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.js +19 -2
- package/src/services/Oauth2Service/utils/connectWithAppleId/connectWithAppleId.cjs +26 -0
- package/src/services/Oauth2Service/utils/connectWithAppleId/connectWithAppleId.d.ts +7 -0
- package/src/services/Oauth2Service/utils/connectWithAppleId/connectWithAppleId.js +22 -0
- package/src/services/Oauth2Service/utils/connectWithAppleId/index.d.ts +1 -0
- package/src/services/Oauth2Service/utils/loadAppleId/index.d.ts +1 -0
- package/src/services/Oauth2Service/utils/loadAppleId/loadAppleId.cjs +34 -0
- package/src/services/Oauth2Service/utils/loadAppleId/loadAppleId.d.ts +1 -0
- package/src/services/Oauth2Service/utils/loadAppleId/loadAppleId.js +30 -0
- package/src/services/PlatformService/PlatformService.cjs +25 -1
- package/src/services/PlatformService/PlatformService.d.ts +23 -0
- package/src/services/PlatformService/PlatformService.js +25 -1
- package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.cjs +1 -0
- package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.js +1 -0
- package/src/services/PlatformService/types.d.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.48](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.47...v3.0.0-alpha.48) (2024-08-21)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* collect user data to work when no wallet is selected ([#6670](https://github.com/dynamic-labs/DynamicAuth/issues/6670)) ([b86aae8](https://github.com/dynamic-labs/DynamicAuth/commit/b86aae8e7ceb35793f792941a34cabd19b9e65d4))
|
|
8
|
+
* disable cookie when running on native mobile ([#6668](https://github.com/dynamic-labs/DynamicAuth/issues/6668)) ([e52a3d9](https://github.com/dynamic-labs/DynamicAuth/commit/e52a3d94a9028e36525be2e80a9f0916efad4320))
|
|
9
|
+
* prevent external auth blocking pending user requirements views ([#6669](https://github.com/dynamic-labs/DynamicAuth/issues/6669)) ([848356c](https://github.com/dynamic-labs/DynamicAuth/commit/848356c57e730a8516c642da84274a236e026f40))
|
|
10
|
+
|
|
11
|
+
## [3.0.0-alpha.47](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.46...v3.0.0-alpha.47) (2024-08-21)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### ⚠ BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* rename useSelectWalletOption to useWalletOptions (#6616)
|
|
17
|
+
* stop exposing walletConnectorOptions from dynamic context (#6622)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* add support for base.eth ens resolution ([#6655](https://github.com/dynamic-labs/DynamicAuth/issues/6655)) ([e2fb1c0](https://github.com/dynamic-labs/DynamicAuth/commit/e2fb1c0ca8410e85b7464d032abc6686bd46149f))
|
|
22
|
+
* expose wallet options from useWalletOptions hook ([#6624](https://github.com/dynamic-labs/DynamicAuth/issues/6624)) ([7287359](https://github.com/dynamic-labs/DynamicAuth/commit/7287359d1564564b87e82bf182edef8ef02c16f1))
|
|
23
|
+
* global wallet chain switching ([#6648](https://github.com/dynamic-labs/DynamicAuth/issues/6648)) ([10179fc](https://github.com/dynamic-labs/DynamicAuth/commit/10179fcddc747977c7dd250abd78bad0ec375f8f))
|
|
24
|
+
* implement Apple Sign-In for mobile ([#6632](https://github.com/dynamic-labs/DynamicAuth/issues/6632)) ([e68b088](https://github.com/dynamic-labs/DynamicAuth/commit/e68b088b1c13c1140b43a6d0c215383455a71a4a))
|
|
25
|
+
* surface mfa rate limit error ([#6658](https://github.com/dynamic-labs/DynamicAuth/issues/6658)) ([5fbcbc2](https://github.com/dynamic-labs/DynamicAuth/commit/5fbcbc2382ebcf2721a308d8e87bc8b2b5cb38cf))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* update bottom nav border radius ([#6651](https://github.com/dynamic-labs/DynamicAuth/issues/6651)) ([79212c2](https://github.com/dynamic-labs/DynamicAuth/commit/79212c26735eb06f31655e8b98a3d9c2c8371489))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
* rename useSelectWalletOption to useWalletOptions ([#6616](https://github.com/dynamic-labs/DynamicAuth/issues/6616)) ([3850dad](https://github.com/dynamic-labs/DynamicAuth/commit/3850dad47f847ace84aadc63a84c4e62f84f7df2))
|
|
34
|
+
* stop exposing walletConnectorOptions from dynamic context ([#6622](https://github.com/dynamic-labs/DynamicAuth/issues/6622)) ([b9da7db](https://github.com/dynamic-labs/DynamicAuth/commit/b9da7dbfc4020913ba3d95ec496811e9d8ee17b8))
|
|
35
|
+
|
|
2
36
|
## [3.0.0-alpha.46](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.45...v3.0.0-alpha.46) (2024-08-19)
|
|
3
37
|
|
|
4
38
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/utils",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.48",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.519",
|
|
30
30
|
"tldts": "6.0.16",
|
|
31
|
-
"@dynamic-labs/logger": "3.0.0-alpha.
|
|
32
|
-
"@dynamic-labs/types": "3.0.0-alpha.
|
|
31
|
+
"@dynamic-labs/logger": "3.0.0-alpha.48",
|
|
32
|
+
"@dynamic-labs/types": "3.0.0-alpha.48",
|
|
33
33
|
"buffer": "6.0.3",
|
|
34
34
|
"stream": "0.0.2"
|
|
35
35
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var DynamicError = require('./DynamicError.cjs');
|
|
7
|
+
|
|
8
|
+
class MfaRateLimitedError extends DynamicError.DynamicError {
|
|
9
|
+
constructor() {
|
|
10
|
+
super('Rate limit reached');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.MfaRateLimitedError = MfaRateLimitedError;
|
package/src/errors/index.d.ts
CHANGED
|
@@ -30,5 +30,6 @@ export * from './CookieInvalidError';
|
|
|
30
30
|
export * from './AccessBlockedError';
|
|
31
31
|
export * from './EmbeddedWalletException';
|
|
32
32
|
export * from './MfaInvalidOtpError';
|
|
33
|
+
export * from './MfaRateLimitedError';
|
|
33
34
|
export * from './ExternalAuthError';
|
|
34
35
|
export * from './WalletAddressMismatchError';
|
package/src/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ var CookieInvalidError = require('./errors/CookieInvalidError.cjs');
|
|
|
36
36
|
var AccessBlockedError = require('./errors/AccessBlockedError.cjs');
|
|
37
37
|
var EmbeddedWalletException = require('./errors/EmbeddedWalletException.cjs');
|
|
38
38
|
var MfaInvalidOtpError = require('./errors/MfaInvalidOtpError.cjs');
|
|
39
|
+
var MfaRateLimitedError = require('./errors/MfaRateLimitedError.cjs');
|
|
39
40
|
var ExternalAuthError = require('./errors/ExternalAuthError.cjs');
|
|
40
41
|
var WalletAddressMismatchError = require('./errors/WalletAddressMismatchError.cjs');
|
|
41
42
|
var CancellablePromise = require('./CancellablePromise/CancellablePromise.cjs');
|
|
@@ -105,6 +106,7 @@ exports.CookieInvalidError = CookieInvalidError.CookieInvalidError;
|
|
|
105
106
|
exports.AccessBlockedError = AccessBlockedError.AccessBlockedError;
|
|
106
107
|
exports.EmbeddedWalletException = EmbeddedWalletException.EmbeddedWalletException;
|
|
107
108
|
exports.MfaInvalidOtpError = MfaInvalidOtpError.MfaInvalidOtpError;
|
|
109
|
+
exports.MfaRateLimitedError = MfaRateLimitedError.MfaRateLimitedError;
|
|
108
110
|
exports.ExternalAuthError = ExternalAuthError.ExternalAuthError;
|
|
109
111
|
exports.WalletAddressMismatchError = WalletAddressMismatchError.WalletAddressMismatchError;
|
|
110
112
|
exports.CancellablePromise = CancellablePromise.CancellablePromise;
|
|
@@ -117,6 +119,7 @@ exports.isIPhone = isMobile.isIPhone;
|
|
|
117
119
|
exports.isIPhone8OrEarlier = isMobile.isIPhone8OrEarlier;
|
|
118
120
|
exports.isLegacySafari = isMobile.isLegacySafari;
|
|
119
121
|
exports.isMobile = isMobile.isMobile;
|
|
122
|
+
exports.isSafariBrowser = isMobile.isSafariBrowser;
|
|
120
123
|
exports.isSamsungBrowser = isMobile.isSamsungBrowser;
|
|
121
124
|
exports.isWindows = isMobile.isWindows;
|
|
122
125
|
exports.getItemAsync = localStorageAsync.getItemAsync;
|
package/src/index.js
CHANGED
|
@@ -32,11 +32,12 @@ export { CookieInvalidError } from './errors/CookieInvalidError.js';
|
|
|
32
32
|
export { AccessBlockedError } from './errors/AccessBlockedError.js';
|
|
33
33
|
export { EmbeddedWalletException } from './errors/EmbeddedWalletException.js';
|
|
34
34
|
export { MfaInvalidOtpError } from './errors/MfaInvalidOtpError.js';
|
|
35
|
+
export { MfaRateLimitedError } from './errors/MfaRateLimitedError.js';
|
|
35
36
|
export { ExternalAuthError } from './errors/ExternalAuthError.js';
|
|
36
37
|
export { WalletAddressMismatchError } from './errors/WalletAddressMismatchError.js';
|
|
37
38
|
export { CancellablePromise } from './CancellablePromise/CancellablePromise.js';
|
|
38
39
|
export { isFunction } from './isFunction/isFunction.js';
|
|
39
|
-
export { getAndroidVersion, isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSamsungBrowser, isWindows } from './isMobile.js';
|
|
40
|
+
export { getAndroidVersion, isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSafariBrowser, isSamsungBrowser, isWindows } from './isMobile.js';
|
|
40
41
|
export { getItemAsync, removeItemAsync, setItemAsync } from './localStorageAsync.js';
|
|
41
42
|
export { bufferToBase64 } from './bufferToBase64.js';
|
|
42
43
|
export { last } from './last.js';
|
package/src/isMobile.cjs
CHANGED
|
@@ -65,6 +65,16 @@ const isSamsungBrowser = () => {
|
|
|
65
65
|
}
|
|
66
66
|
return navigator.userAgent.includes('SamsungBrowser');
|
|
67
67
|
};
|
|
68
|
+
const isSafariBrowser = () => {
|
|
69
|
+
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const { userAgent } = navigator;
|
|
73
|
+
const isSafari = userAgent.includes('Safari') &&
|
|
74
|
+
!userAgent.includes('Chrome') &&
|
|
75
|
+
!userAgent.includes('Chromium');
|
|
76
|
+
return isSafari;
|
|
77
|
+
};
|
|
68
78
|
const isWindows = () => {
|
|
69
79
|
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
|
|
70
80
|
return false;
|
|
@@ -142,5 +152,6 @@ exports.isIPhone = isIPhone;
|
|
|
142
152
|
exports.isIPhone8OrEarlier = isIPhone8OrEarlier;
|
|
143
153
|
exports.isLegacySafari = isLegacySafari;
|
|
144
154
|
exports.isMobile = isMobile;
|
|
155
|
+
exports.isSafariBrowser = isSafariBrowser;
|
|
145
156
|
exports.isSamsungBrowser = isSamsungBrowser;
|
|
146
157
|
exports.isWindows = isWindows;
|
package/src/isMobile.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ export declare const isIOS: (maxTouchPointsOverride?: number) => boolean;
|
|
|
14
14
|
export declare const isAndroid: () => boolean;
|
|
15
15
|
export declare const isLegacySafari: () => boolean;
|
|
16
16
|
export declare const isSamsungBrowser: () => boolean;
|
|
17
|
+
export declare const isSafariBrowser: () => boolean;
|
|
17
18
|
export declare const isWindows: () => boolean;
|
|
18
19
|
export declare const getAndroidVersion: () => number | undefined;
|
package/src/isMobile.js
CHANGED
|
@@ -61,6 +61,16 @@ const isSamsungBrowser = () => {
|
|
|
61
61
|
}
|
|
62
62
|
return navigator.userAgent.includes('SamsungBrowser');
|
|
63
63
|
};
|
|
64
|
+
const isSafariBrowser = () => {
|
|
65
|
+
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const { userAgent } = navigator;
|
|
69
|
+
const isSafari = userAgent.includes('Safari') &&
|
|
70
|
+
!userAgent.includes('Chrome') &&
|
|
71
|
+
!userAgent.includes('Chromium');
|
|
72
|
+
return isSafari;
|
|
73
|
+
};
|
|
64
74
|
const isWindows = () => {
|
|
65
75
|
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
|
|
66
76
|
return false;
|
|
@@ -130,4 +140,4 @@ const getAndroidVersion = () => {
|
|
|
130
140
|
return androidVersion;
|
|
131
141
|
};
|
|
132
142
|
|
|
133
|
-
export { getAndroidVersion, isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSamsungBrowser, isWindows };
|
|
143
|
+
export { getAndroidVersion, isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSafariBrowser, isSamsungBrowser, isWindows };
|
|
@@ -6,7 +6,9 @@ export type GetOauthCodeProps = {
|
|
|
6
6
|
setIsProcessing: (value: boolean) => void;
|
|
7
7
|
onSettled?: VoidFunction;
|
|
8
8
|
getOAuthResultFromApi: () => Promise<OauthResultResponse | undefined>;
|
|
9
|
-
initWebAuth: (
|
|
9
|
+
initWebAuth: (options?: {
|
|
10
|
+
redirectUrl?: string;
|
|
11
|
+
}) => Promise<void>;
|
|
10
12
|
state: string;
|
|
11
13
|
oauthLoginUrl: URL;
|
|
12
14
|
sessionTimeout: number;
|
|
@@ -6,15 +6,32 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
7
|
var types = require('@dynamic-labs/types');
|
|
8
8
|
var logger = require('../../../logger/logger.cjs');
|
|
9
|
+
var connectWithAppleId = require('../utils/connectWithAppleId/connectWithAppleId.cjs');
|
|
10
|
+
var isMobile = require('../../../isMobile.cjs');
|
|
9
11
|
|
|
10
12
|
let authWindowInterval;
|
|
11
13
|
const createWindowOauth2Service = () => ({
|
|
12
|
-
getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, isMobile, initWebAuth, }) => new Promise((resolve, _reject) => {
|
|
14
|
+
getOauthCode: ({ apiProvider, provider, redirectUrl, setIsProcessing, state, oauthLoginUrl, isMobile: isMobile$1, initWebAuth, }) => new Promise((resolve, _reject) => {
|
|
15
|
+
/**
|
|
16
|
+
* Use AppleID SDK for Apple provider on mobile
|
|
17
|
+
*/
|
|
18
|
+
if ((isMobile$1 || isMobile.isSafariBrowser()) && provider === types.ProviderEnum.Apple) {
|
|
19
|
+
initWebAuth({
|
|
20
|
+
redirectUrl: redirectUrl || window.location.href,
|
|
21
|
+
}).then(() => connectWithAppleId.connectWithAppleId({
|
|
22
|
+
clientId: apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.clientId,
|
|
23
|
+
oauthLoginUrl,
|
|
24
|
+
state,
|
|
25
|
+
}).catch(_reject));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
13
28
|
/**
|
|
14
29
|
* Use redirect flow on mobile for all providers except Telegram
|
|
15
30
|
*/
|
|
16
|
-
if (isMobile && provider !== types.ProviderEnum.Telegram) {
|
|
17
|
-
initWebAuth(
|
|
31
|
+
if (isMobile$1 && provider !== types.ProviderEnum.Telegram) {
|
|
32
|
+
initWebAuth({
|
|
33
|
+
redirectUrl: redirectUrl || window.location.href,
|
|
34
|
+
}).then(() => {
|
|
18
35
|
window.location.assign(oauthLoginUrl);
|
|
19
36
|
});
|
|
20
37
|
return;
|
|
@@ -2,15 +2,32 @@
|
|
|
2
2
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
3
|
import { ProviderEnum, SocialOAuthErrorCode } from '@dynamic-labs/types';
|
|
4
4
|
import { logger } from '../../../logger/logger.js';
|
|
5
|
+
import { connectWithAppleId } from '../utils/connectWithAppleId/connectWithAppleId.js';
|
|
6
|
+
import { isSafariBrowser } from '../../../isMobile.js';
|
|
5
7
|
|
|
6
8
|
let authWindowInterval;
|
|
7
9
|
const createWindowOauth2Service = () => ({
|
|
8
|
-
getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, isMobile, initWebAuth, }) => new Promise((resolve, _reject) => {
|
|
10
|
+
getOauthCode: ({ apiProvider, provider, redirectUrl, setIsProcessing, state, oauthLoginUrl, isMobile, initWebAuth, }) => new Promise((resolve, _reject) => {
|
|
11
|
+
/**
|
|
12
|
+
* Use AppleID SDK for Apple provider on mobile
|
|
13
|
+
*/
|
|
14
|
+
if ((isMobile || isSafariBrowser()) && provider === ProviderEnum.Apple) {
|
|
15
|
+
initWebAuth({
|
|
16
|
+
redirectUrl: redirectUrl || window.location.href,
|
|
17
|
+
}).then(() => connectWithAppleId({
|
|
18
|
+
clientId: apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.clientId,
|
|
19
|
+
oauthLoginUrl,
|
|
20
|
+
state,
|
|
21
|
+
}).catch(_reject));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
9
24
|
/**
|
|
10
25
|
* Use redirect flow on mobile for all providers except Telegram
|
|
11
26
|
*/
|
|
12
27
|
if (isMobile && provider !== ProviderEnum.Telegram) {
|
|
13
|
-
initWebAuth(
|
|
28
|
+
initWebAuth({
|
|
29
|
+
redirectUrl: redirectUrl || window.location.href,
|
|
30
|
+
}).then(() => {
|
|
14
31
|
window.location.assign(oauthLoginUrl);
|
|
15
32
|
});
|
|
16
33
|
return;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var loadAppleId = require('../loadAppleId/loadAppleId.cjs');
|
|
8
|
+
|
|
9
|
+
const connectWithAppleId = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ clientId, oauthLoginUrl, state, }) {
|
|
10
|
+
yield loadAppleId.loadAppleId();
|
|
11
|
+
// Because the AppleID is loaded from a script tag, there is not type for it
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
AppleID.auth.init({
|
|
15
|
+
clientId,
|
|
16
|
+
redirectURI: oauthLoginUrl.searchParams.get('redirect_uri'),
|
|
17
|
+
scope: 'name email',
|
|
18
|
+
state,
|
|
19
|
+
usePopup: false,
|
|
20
|
+
});
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
AppleID.auth.signIn();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
exports.connectWithAppleId = connectWithAppleId;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { loadAppleId } from '../loadAppleId/loadAppleId.js';
|
|
4
|
+
|
|
5
|
+
const connectWithAppleId = (_a) => __awaiter(void 0, [_a], void 0, function* ({ clientId, oauthLoginUrl, state, }) {
|
|
6
|
+
yield loadAppleId();
|
|
7
|
+
// Because the AppleID is loaded from a script tag, there is not type for it
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
AppleID.auth.init({
|
|
11
|
+
clientId,
|
|
12
|
+
redirectURI: oauthLoginUrl.searchParams.get('redirect_uri'),
|
|
13
|
+
scope: 'name email',
|
|
14
|
+
state,
|
|
15
|
+
usePopup: false,
|
|
16
|
+
});
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
AppleID.auth.signIn();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export { connectWithAppleId };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { connectWithAppleId } from './connectWithAppleId';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadAppleId } from './loadAppleId';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const appleIdScriptSrc = 'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js';
|
|
7
|
+
const loadAppleId = () => new Promise((resolve, reject) => {
|
|
8
|
+
const script = document.querySelector('script[data-apple-sdk]');
|
|
9
|
+
if (script) {
|
|
10
|
+
// Script already exists, attach event listeners
|
|
11
|
+
if (script.hasAttribute('data-loaded')) {
|
|
12
|
+
resolve();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
script.addEventListener('load', () => resolve());
|
|
16
|
+
script.addEventListener('error', () => reject(new Error('Failed to load Apple SDK')));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// If the script does not exist, create and add it
|
|
21
|
+
const script = document.createElement('script');
|
|
22
|
+
script.type = 'text/javascript';
|
|
23
|
+
script.src = appleIdScriptSrc;
|
|
24
|
+
script.setAttribute('data-apple-sdk', 'true');
|
|
25
|
+
script.onload = () => {
|
|
26
|
+
script === null || script === void 0 ? void 0 : script.setAttribute('data-loaded', 'true');
|
|
27
|
+
resolve();
|
|
28
|
+
};
|
|
29
|
+
script.onerror = () => reject(new Error('Failed to load Apple SDK'));
|
|
30
|
+
window.document.head.appendChild(script);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.loadAppleId = loadAppleId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loadAppleId: () => Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const appleIdScriptSrc = 'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js';
|
|
3
|
+
const loadAppleId = () => new Promise((resolve, reject) => {
|
|
4
|
+
const script = document.querySelector('script[data-apple-sdk]');
|
|
5
|
+
if (script) {
|
|
6
|
+
// Script already exists, attach event listeners
|
|
7
|
+
if (script.hasAttribute('data-loaded')) {
|
|
8
|
+
resolve();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
script.addEventListener('load', () => resolve());
|
|
12
|
+
script.addEventListener('error', () => reject(new Error('Failed to load Apple SDK')));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// If the script does not exist, create and add it
|
|
17
|
+
const script = document.createElement('script');
|
|
18
|
+
script.type = 'text/javascript';
|
|
19
|
+
script.src = appleIdScriptSrc;
|
|
20
|
+
script.setAttribute('data-apple-sdk', 'true');
|
|
21
|
+
script.onload = () => {
|
|
22
|
+
script === null || script === void 0 ? void 0 : script.setAttribute('data-loaded', 'true');
|
|
23
|
+
resolve();
|
|
24
|
+
};
|
|
25
|
+
script.onerror = () => reject(new Error('Failed to load Apple SDK'));
|
|
26
|
+
window.document.head.appendChild(script);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export { loadAppleId };
|
|
@@ -17,19 +17,43 @@ class PlatformService {
|
|
|
17
17
|
static set implementation(implementation) {
|
|
18
18
|
_tslib.__classPrivateFieldSet(_a, _a, implementation, "f", _PlatformService_implementation);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Indicates if the current platform is a native mobile app
|
|
22
|
+
* like react-native or flutter.
|
|
23
|
+
*/
|
|
24
|
+
static get isNativeMobile() {
|
|
25
|
+
return _a.implementation.isNativeMobile;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets the origin of the current location.
|
|
29
|
+
*
|
|
30
|
+
* @example window.location.origin
|
|
31
|
+
*/
|
|
20
32
|
static get getOrigin() {
|
|
21
33
|
return _a.implementation.getOrigin;
|
|
22
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the host of the current location.
|
|
37
|
+
*
|
|
38
|
+
* @example window.location.host
|
|
39
|
+
*/
|
|
23
40
|
static get getHost() {
|
|
24
41
|
return _a.implementation.getHost;
|
|
25
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the hostname of the current location.
|
|
45
|
+
*
|
|
46
|
+
* @example window.location.hostname
|
|
47
|
+
*/
|
|
26
48
|
static get getHostname() {
|
|
27
49
|
return _a.implementation.getHostname;
|
|
28
50
|
}
|
|
29
51
|
static get getTLD() {
|
|
30
52
|
return _a.implementation.getTLD;
|
|
31
53
|
}
|
|
32
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Opens a URL. If possible, should avoid new windows.
|
|
56
|
+
*/
|
|
33
57
|
static get openURL() {
|
|
34
58
|
return _a.implementation.openURL;
|
|
35
59
|
}
|
|
@@ -3,9 +3,32 @@ export declare class PlatformService {
|
|
|
3
3
|
#private;
|
|
4
4
|
static get implementation(): IPlatformService;
|
|
5
5
|
static set implementation(implementation: IPlatformService);
|
|
6
|
+
/**
|
|
7
|
+
* Indicates if the current platform is a native mobile app
|
|
8
|
+
* like react-native or flutter.
|
|
9
|
+
*/
|
|
10
|
+
static get isNativeMobile(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the origin of the current location.
|
|
13
|
+
*
|
|
14
|
+
* @example window.location.origin
|
|
15
|
+
*/
|
|
6
16
|
static get getOrigin(): () => string;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the host of the current location.
|
|
19
|
+
*
|
|
20
|
+
* @example window.location.host
|
|
21
|
+
*/
|
|
7
22
|
static get getHost(): () => string;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the hostname of the current location.
|
|
25
|
+
*
|
|
26
|
+
* @example window.location.hostname
|
|
27
|
+
*/
|
|
8
28
|
static get getHostname(): () => string;
|
|
9
29
|
static get getTLD(): () => string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Opens a URL. If possible, should avoid new windows.
|
|
32
|
+
*/
|
|
10
33
|
static get openURL(): (url: string) => Promise<void>;
|
|
11
34
|
}
|
|
@@ -13,19 +13,43 @@ class PlatformService {
|
|
|
13
13
|
static set implementation(implementation) {
|
|
14
14
|
__classPrivateFieldSet(_a, _a, implementation, "f", _PlatformService_implementation);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Indicates if the current platform is a native mobile app
|
|
18
|
+
* like react-native or flutter.
|
|
19
|
+
*/
|
|
20
|
+
static get isNativeMobile() {
|
|
21
|
+
return _a.implementation.isNativeMobile;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Gets the origin of the current location.
|
|
25
|
+
*
|
|
26
|
+
* @example window.location.origin
|
|
27
|
+
*/
|
|
16
28
|
static get getOrigin() {
|
|
17
29
|
return _a.implementation.getOrigin;
|
|
18
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the host of the current location.
|
|
33
|
+
*
|
|
34
|
+
* @example window.location.host
|
|
35
|
+
*/
|
|
19
36
|
static get getHost() {
|
|
20
37
|
return _a.implementation.getHost;
|
|
21
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the hostname of the current location.
|
|
41
|
+
*
|
|
42
|
+
* @example window.location.hostname
|
|
43
|
+
*/
|
|
22
44
|
static get getHostname() {
|
|
23
45
|
return _a.implementation.getHostname;
|
|
24
46
|
}
|
|
25
47
|
static get getTLD() {
|
|
26
48
|
return _a.implementation.getTLD;
|
|
27
49
|
}
|
|
28
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Opens a URL. If possible, should avoid new windows.
|
|
52
|
+
*/
|
|
29
53
|
static get openURL() {
|
|
30
54
|
return _a.implementation.openURL;
|
|
31
55
|
}
|