@dynamic-labs/utils 3.0.0-alpha.39 → 3.0.0-alpha.40

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,19 @@
1
1
 
2
+ ## [3.0.0-alpha.40](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.39...v3.0.0-alpha.40) (2024-08-13)
3
+
4
+
5
+ ### Features
6
+
7
+ * add log out button to mfa screens ([#6557](https://github.com/dynamic-labs/DynamicAuth/issues/6557)) ([a006f6a](https://github.com/dynamic-labs/DynamicAuth/commit/a006f6a3f801a93d305fbd8151a51c7b08b73983))
8
+ * signIn/link using dynamicOauthState ([#6523](https://github.com/dynamic-labs/DynamicAuth/issues/6523)) ([b72e98f](https://github.com/dynamic-labs/DynamicAuth/commit/b72e98f0d243591c1a8ca14c3a4a6e5024560141))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * clicking back on MFA verification view should take you to MFA secure device view ([#6556](https://github.com/dynamic-labs/DynamicAuth/issues/6556)) ([7ae39c9](https://github.com/dynamic-labs/DynamicAuth/commit/7ae39c9b073b42a14d3e77fba28217905a1dbf0c))
14
+ * mfa design feedback ([#6551](https://github.com/dynamic-labs/DynamicAuth/issues/6551)) ([c367e38](https://github.com/dynamic-labs/DynamicAuth/commit/c367e3836e331a2dc24496ea81436b6bd57460a1))
15
+ * remove 2 factor authenticator header unless there is an applicable security option available ([#6545](https://github.com/dynamic-labs/DynamicAuth/issues/6545)) ([11f7f5a](https://github.com/dynamic-labs/DynamicAuth/commit/11f7f5ae87bf26be783c353607b39943e4a2b796))
16
+
2
17
  ## [3.0.0-alpha.39](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.38...v3.0.0-alpha.39) (2024-08-09)
3
18
 
4
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "3.0.0-alpha.39",
3
+ "version": "3.0.0-alpha.40",
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.509",
29
+ "@dynamic-labs/sdk-api-core": "0.0.510",
30
30
  "tldts": "6.0.16",
31
- "@dynamic-labs/logger": "3.0.0-alpha.39",
32
- "@dynamic-labs/types": "3.0.0-alpha.39",
31
+ "@dynamic-labs/logger": "3.0.0-alpha.40",
32
+ "@dynamic-labs/types": "3.0.0-alpha.40",
33
33
  "buffer": "6.0.3",
34
34
  "stream": "0.0.2"
35
35
  },
@@ -0,0 +1,15 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var DynamicError = require('./DynamicError.cjs');
7
+
8
+ class SandboxMaximumThresholdReachedError extends DynamicError.DynamicError {
9
+ constructor(errorMessage) {
10
+ super(errorMessage);
11
+ this.errorMessage = errorMessage;
12
+ }
13
+ }
14
+
15
+ exports.SandboxMaximumThresholdReachedError = SandboxMaximumThresholdReachedError;
@@ -0,0 +1,5 @@
1
+ import { DynamicError } from './DynamicError';
2
+ export declare class SandboxMaximumThresholdReachedError extends DynamicError {
3
+ errorMessage: string;
4
+ constructor(errorMessage: string);
5
+ }
@@ -0,0 +1,11 @@
1
+ 'use client'
2
+ import { DynamicError } from './DynamicError.js';
3
+
4
+ class SandboxMaximumThresholdReachedError extends DynamicError {
5
+ constructor(errorMessage) {
6
+ super(errorMessage);
7
+ this.errorMessage = errorMessage;
8
+ }
9
+ }
10
+
11
+ export { SandboxMaximumThresholdReachedError };
@@ -1,5 +1,6 @@
1
1
  export * from './AccountExistsError';
2
2
  export * from './ChainalysisError';
3
+ export * from './SandboxMaximumThresholdReachedError';
3
4
  export * from './CustomError';
4
5
  export * from './DynamicError';
5
6
  export * from './EmailAlreadyExistsError';
package/src/index.cjs CHANGED
@@ -7,6 +7,7 @@ var parseChainId = require('./parseChainId.cjs');
7
7
  var parseEvmNetworks = require('./parseEvmNetworks.cjs');
8
8
  var AccountExistsError = require('./errors/AccountExistsError.cjs');
9
9
  var ChainalysisError = require('./errors/ChainalysisError.cjs');
10
+ var SandboxMaximumThresholdReachedError = require('./errors/SandboxMaximumThresholdReachedError.cjs');
10
11
  var CustomError = require('./errors/CustomError.cjs');
11
12
  var DynamicError = require('./errors/DynamicError.cjs');
12
13
  var EmailAlreadyExistsError = require('./errors/EmailAlreadyExistsError.cjs');
@@ -75,6 +76,7 @@ exports.parseChainId = parseChainId.parseChainId;
75
76
  exports.parseEvmNetworks = parseEvmNetworks.parseEvmNetworks;
76
77
  exports.AccountExistsError = AccountExistsError.AccountExistsError;
77
78
  exports.ChainalysisError = ChainalysisError.ChainalysisError;
79
+ exports.SandboxMaximumThresholdReachedError = SandboxMaximumThresholdReachedError.SandboxMaximumThresholdReachedError;
78
80
  exports.CustomError = CustomError.CustomError;
79
81
  exports.DynamicError = DynamicError.DynamicError;
80
82
  exports.EmailAlreadyExistsError = EmailAlreadyExistsError.EmailAlreadyExistsError;
package/src/index.js CHANGED
@@ -3,6 +3,7 @@ export { parseChainId } from './parseChainId.js';
3
3
  export { parseEvmNetworks } from './parseEvmNetworks.js';
4
4
  export { AccountExistsError } from './errors/AccountExistsError.js';
5
5
  export { ChainalysisError } from './errors/ChainalysisError.js';
6
+ export { SandboxMaximumThresholdReachedError } from './errors/SandboxMaximumThresholdReachedError.js';
6
7
  export { CustomError } from './errors/CustomError.js';
7
8
  export { DynamicError } from './errors/DynamicError.js';
8
9
  export { EmailAlreadyExistsError } from './errors/EmailAlreadyExistsError.js';
@@ -6,6 +6,7 @@ export type GetOauthCodeProps = {
6
6
  setIsProcessing: (value: boolean) => void;
7
7
  onSettled?: VoidFunction;
8
8
  getOAuthResultFromApi: () => Promise<OauthResultResponse | undefined>;
9
+ initWebAuth: () => Promise<void>;
9
10
  state: string;
10
11
  oauthLoginUrl: URL;
11
12
  sessionTimeout: number;
@@ -11,7 +11,16 @@ var logger = require('../../../logger/logger.cjs');
11
11
  const providersWithoutWindowOpenerReference = ['twitter'];
12
12
  let authWindowInterval;
13
13
  const createWindowOauth2Service = () => ({
14
- getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, getOAuthResultFromApi, sessionTimeout, isMobile, onSettled, }) => new Promise((resolve, _reject) => {
14
+ getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, getOAuthResultFromApi, sessionTimeout, isMobile, onSettled, initWebAuth, }) => new Promise((resolve, _reject) => {
15
+ /**
16
+ * Use redirect flow on mobile for all providers except Telegram
17
+ */
18
+ if (isMobile && provider !== types.ProviderEnum.Telegram) {
19
+ initWebAuth().then(() => {
20
+ window.location.assign(oauthLoginUrl);
21
+ });
22
+ return;
23
+ }
15
24
  // When we catch this error we assume it follows this type, so we must enforce it
16
25
  // here to ensure the assumption is correct
17
26
  const typedReject = (params) => _reject(params);
@@ -126,20 +135,22 @@ const createWindowOauth2Service = () => ({
126
135
  window.addEventListener('message', handleWindowMessage);
127
136
  providersWaitingOauthMessage[provider] = true;
128
137
  }
129
- authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
130
- if (!providersWithoutWindowOpenerReference.includes(provider)) {
131
- // For provider that support window.opener, we need to clear all states/listeners when the window is closed
132
- authWindowInterval = setInterval(() => {
133
- if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed))
134
- return;
135
- clearInterval(authWindowInterval);
136
- setIsProcessing(false);
137
- // user didn't complete oauth
138
- if (providersWaitingOauthMessage[provider])
139
- typedReject('user-cancelled');
140
- }, 2000);
141
- }
142
- else {
138
+ // First we store the state in backend
139
+ initWebAuth().then(() => {
140
+ authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
141
+ if (!providersWithoutWindowOpenerReference.includes(provider)) {
142
+ // For provider that support window.opener, we need to clear all states/listeners when the window is closed
143
+ authWindowInterval = setInterval(() => {
144
+ if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed))
145
+ return;
146
+ clearInterval(authWindowInterval);
147
+ setIsProcessing(false);
148
+ // user didn't complete oauth
149
+ if (providersWaitingOauthMessage[provider])
150
+ typedReject('user-cancelled');
151
+ }, 2000);
152
+ return;
153
+ }
143
154
  // For provider that don't support window.opener, we need to use a timeout to pool the oauth result
144
155
  // If we don't get a valid result in {async sessionTimeout} ms, we'll assume the user closed the window
145
156
  // and we'll clear all states/listeners
@@ -185,7 +196,7 @@ const createWindowOauth2Service = () => ({
185
196
  setIsProcessing(false);
186
197
  onSettled === null || onSettled === void 0 ? void 0 : onSettled();
187
198
  }), authWindowTimeout);
188
- }
199
+ });
189
200
  }),
190
201
  });
191
202
 
@@ -1,13 +1,22 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../_virtual/_tslib.js';
3
- import { SocialOAuthErrorCode } from '@dynamic-labs/types';
3
+ import { ProviderEnum, SocialOAuthErrorCode } from '@dynamic-labs/types';
4
4
  import { OauthResultStatus } from '@dynamic-labs/sdk-api-core';
5
5
  import { logger } from '../../../logger/logger.js';
6
6
 
7
7
  const providersWithoutWindowOpenerReference = ['twitter'];
8
8
  let authWindowInterval;
9
9
  const createWindowOauth2Service = () => ({
10
- getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, getOAuthResultFromApi, sessionTimeout, isMobile, onSettled, }) => new Promise((resolve, _reject) => {
10
+ getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, getOAuthResultFromApi, sessionTimeout, isMobile, onSettled, initWebAuth, }) => new Promise((resolve, _reject) => {
11
+ /**
12
+ * Use redirect flow on mobile for all providers except Telegram
13
+ */
14
+ if (isMobile && provider !== ProviderEnum.Telegram) {
15
+ initWebAuth().then(() => {
16
+ window.location.assign(oauthLoginUrl);
17
+ });
18
+ return;
19
+ }
11
20
  // When we catch this error we assume it follows this type, so we must enforce it
12
21
  // here to ensure the assumption is correct
13
22
  const typedReject = (params) => _reject(params);
@@ -122,20 +131,22 @@ const createWindowOauth2Service = () => ({
122
131
  window.addEventListener('message', handleWindowMessage);
123
132
  providersWaitingOauthMessage[provider] = true;
124
133
  }
125
- authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
126
- if (!providersWithoutWindowOpenerReference.includes(provider)) {
127
- // For provider that support window.opener, we need to clear all states/listeners when the window is closed
128
- authWindowInterval = setInterval(() => {
129
- if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed))
130
- return;
131
- clearInterval(authWindowInterval);
132
- setIsProcessing(false);
133
- // user didn't complete oauth
134
- if (providersWaitingOauthMessage[provider])
135
- typedReject('user-cancelled');
136
- }, 2000);
137
- }
138
- else {
134
+ // First we store the state in backend
135
+ initWebAuth().then(() => {
136
+ authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
137
+ if (!providersWithoutWindowOpenerReference.includes(provider)) {
138
+ // For provider that support window.opener, we need to clear all states/listeners when the window is closed
139
+ authWindowInterval = setInterval(() => {
140
+ if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed))
141
+ return;
142
+ clearInterval(authWindowInterval);
143
+ setIsProcessing(false);
144
+ // user didn't complete oauth
145
+ if (providersWaitingOauthMessage[provider])
146
+ typedReject('user-cancelled');
147
+ }, 2000);
148
+ return;
149
+ }
139
150
  // For provider that don't support window.opener, we need to use a timeout to pool the oauth result
140
151
  // If we don't get a valid result in {async sessionTimeout} ms, we'll assume the user closed the window
141
152
  // and we'll clear all states/listeners
@@ -181,7 +192,7 @@ const createWindowOauth2Service = () => ({
181
192
  setIsProcessing(false);
182
193
  onSettled === null || onSettled === void 0 ? void 0 : onSettled();
183
194
  }), authWindowTimeout);
184
- }
195
+ });
185
196
  }),
186
197
  });
187
198