@dynamic-labs/utils 3.0.0-alpha.45 → 3.0.0-alpha.47

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 CHANGED
@@ -1,4 +1,44 @@
1
1
 
2
+ ## [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)
3
+
4
+
5
+ ### ⚠ BREAKING CHANGES
6
+
7
+ * rename useSelectWalletOption to useWalletOptions (#6616)
8
+ * stop exposing walletConnectorOptions from dynamic context (#6622)
9
+
10
+ ### Features
11
+
12
+ * 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))
13
+ * expose wallet options from useWalletOptions hook ([#6624](https://github.com/dynamic-labs/DynamicAuth/issues/6624)) ([7287359](https://github.com/dynamic-labs/DynamicAuth/commit/7287359d1564564b87e82bf182edef8ef02c16f1))
14
+ * global wallet chain switching ([#6648](https://github.com/dynamic-labs/DynamicAuth/issues/6648)) ([10179fc](https://github.com/dynamic-labs/DynamicAuth/commit/10179fcddc747977c7dd250abd78bad0ec375f8f))
15
+ * implement Apple Sign-In for mobile ([#6632](https://github.com/dynamic-labs/DynamicAuth/issues/6632)) ([e68b088](https://github.com/dynamic-labs/DynamicAuth/commit/e68b088b1c13c1140b43a6d0c215383455a71a4a))
16
+ * surface mfa rate limit error ([#6658](https://github.com/dynamic-labs/DynamicAuth/issues/6658)) ([5fbcbc2](https://github.com/dynamic-labs/DynamicAuth/commit/5fbcbc2382ebcf2721a308d8e87bc8b2b5cb38cf))
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * update bottom nav border radius ([#6651](https://github.com/dynamic-labs/DynamicAuth/issues/6651)) ([79212c2](https://github.com/dynamic-labs/DynamicAuth/commit/79212c26735eb06f31655e8b98a3d9c2c8371489))
22
+
23
+
24
+ * rename useSelectWalletOption to useWalletOptions ([#6616](https://github.com/dynamic-labs/DynamicAuth/issues/6616)) ([3850dad](https://github.com/dynamic-labs/DynamicAuth/commit/3850dad47f847ace84aadc63a84c4e62f84f7df2))
25
+ * stop exposing walletConnectorOptions from dynamic context ([#6622](https://github.com/dynamic-labs/DynamicAuth/issues/6622)) ([b9da7db](https://github.com/dynamic-labs/DynamicAuth/commit/b9da7dbfc4020913ba3d95ec496811e9d8ee17b8))
26
+
27
+ ## [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)
28
+
29
+
30
+ ### Features
31
+
32
+ * add overrides for chain info ([#6614](https://github.com/dynamic-labs/DynamicAuth/issues/6614)) ([07b76a0](https://github.com/dynamic-labs/DynamicAuth/commit/07b76a0887d3147a00d93a37bdf49a83bfec0ceb))
33
+ * add use token balances state in global store ([#6598](https://github.com/dynamic-labs/DynamicAuth/issues/6598)) ([05baefe](https://github.com/dynamic-labs/DynamicAuth/commit/05baefe7155f197c048557b15240ad93556a8604))
34
+ * refresh token balances ([#6578](https://github.com/dynamic-labs/DynamicAuth/issues/6578)) ([0768857](https://github.com/dynamic-labs/DynamicAuth/commit/0768857c924ce0e01b736173e50ea85b956ab067))
35
+
36
+
37
+ ### Bug Fixes
38
+
39
+ * createEmbeddedWalletAccount ([#6642](https://github.com/dynamic-labs/DynamicAuth/issues/6642)) ([bce08de](https://github.com/dynamic-labs/DynamicAuth/commit/bce08deaa4a5e1ea0b134efb5c4d252c82af5eec))
40
+ * jwt x error when singing with embedded wallet ([#6633](https://github.com/dynamic-labs/DynamicAuth/issues/6633)) ([7d1a6d4](https://github.com/dynamic-labs/DynamicAuth/commit/7d1a6d432807c5b361ff31e6feac2e10d0145d90))
41
+
2
42
  ## [3.0.0-alpha.45](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.44...v3.0.0-alpha.45) (2024-08-16)
3
43
 
4
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "3.0.0-alpha.45",
3
+ "version": "3.0.0-alpha.47",
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.516",
29
+ "@dynamic-labs/sdk-api-core": "0.0.519",
30
30
  "tldts": "6.0.16",
31
- "@dynamic-labs/logger": "3.0.0-alpha.45",
32
- "@dynamic-labs/types": "3.0.0-alpha.45",
31
+ "@dynamic-labs/logger": "3.0.0-alpha.47",
32
+ "@dynamic-labs/types": "3.0.0-alpha.47",
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;
@@ -0,0 +1,4 @@
1
+ import { DynamicError } from './DynamicError';
2
+ export declare class MfaRateLimitedError extends DynamicError {
3
+ constructor();
4
+ }
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ import { DynamicError } from './DynamicError.js';
3
+
4
+ class MfaRateLimitedError extends DynamicError {
5
+ constructor() {
6
+ super('Rate limit reached');
7
+ }
8
+ }
9
+
10
+ export { MfaRateLimitedError };
@@ -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: () => Promise<void>;
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().then(() => {
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().then(() => {
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,7 @@
1
+ type ConnectWithAppleIdOptions = {
2
+ clientId: string | undefined;
3
+ oauthLoginUrl: URL;
4
+ state: string;
5
+ };
6
+ export declare const connectWithAppleId: ({ clientId, oauthLoginUrl, state, }: ConnectWithAppleIdOptions) => Promise<void>;
7
+ export {};
@@ -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 };