@scalemule/nextjs 0.1.49 → 0.1.51
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 +29 -0
- package/dist/audio.js +5 -1
- package/dist/audio.mjs +5 -1
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -2
- package/dist/client.mjs +2 -2
- package/dist/{index-Bv1m_qQ8.d.mts → index-BQgmT53x.d.mts} +2 -0
- package/dist/{index-Bv1m_qQ8.d.ts → index-BQgmT53x.d.ts} +2 -0
- package/dist/index.d.mts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +185 -28
- package/dist/index.mjs +185 -28
- package/dist/server/auth.js +43 -7
- package/dist/server/auth.mjs +43 -7
- package/dist/server/index.d.mts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +45 -8
- package/dist/server/index.mjs +45 -8
- package/dist/server/webhook-handler.d.mts +2 -2
- package/dist/server/webhook-handler.d.ts +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/{webhook-handler-5ymVecTD.d.ts → webhook-handler-44RRJH-r.d.ts} +9 -1
- package/dist/{webhook-handler-CVmBvPFN.d.mts → webhook-handler-DKt6H8FB.d.mts} +9 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,6 +40,35 @@ API keys never reach the browser. Session tokens are HTTP-only cookies.
|
|
|
40
40
|
|
|
41
41
|
Need the cookie/header lifecycle or the proxy-vs-direct decision tree? See [`docs/AUTH_PROXY_PATTERN.md`](./docs/AUTH_PROXY_PATTERN.md).
|
|
42
42
|
|
|
43
|
+
## Adaptive sign-in and password recovery
|
|
44
|
+
|
|
45
|
+
From 0.1.51, `useAuth().login()` handles email security challenges and enrolled MFA
|
|
46
|
+
through the provider's shared verification dialog. Existing login forms need no
|
|
47
|
+
challenge implementation. A session cookie is set only after verification succeeds.
|
|
48
|
+
Codes can be retried or resent; users can cancel or follow the password recovery link.
|
|
49
|
+
|
|
50
|
+
Set `passwordRecoveryUrl` on `ScaleMuleProvider` if your forgot-password page is not
|
|
51
|
+
`/auth/forgot-password`. For custom UI, pass an async `onSecurityChallenge` callback
|
|
52
|
+
that returns the entered code, `"resend"`, or `null` to cancel.
|
|
53
|
+
|
|
54
|
+
Before enabling `adaptive_email_challenges_enabled` in the application's auth settings,
|
|
55
|
+
deploy this SDK version to every login client and verify email delivery. The setting is
|
|
56
|
+
server-controlled; older clients default to observation of soft risk signals. Existing
|
|
57
|
+
account restrictions, abuse limits, and required MFA policies continue to apply.
|
|
58
|
+
Required MFA enrollment for users without a configured factor is a separate flow.
|
|
59
|
+
|
|
60
|
+
Configure the application's `public_auth_base_url` to its own auth pages, for example
|
|
61
|
+
`https://yourdomain.com/auth`. Configure a verified sending domain separately in
|
|
62
|
+
communication settings, for example `noreply@email.yourdomain.com`. The sending domain
|
|
63
|
+
does not determine where recovery links land. Publish SPF, DKIM, and DMARC records and
|
|
64
|
+
verify delivery before enabling the domain.
|
|
65
|
+
|
|
66
|
+
Your public `/auth/reset-password` page calls `useAuth().resetPassword(token, newPassword)`. Keep this page accessible even when an old session cookie exists;
|
|
67
|
+
set `Referrer-Policy: no-referrer` and `Cache-Control: no-store`. After success the SDK
|
|
68
|
+
clears the browser session and removes the reset token from the URL. The backend
|
|
69
|
+
invalidates other sessions and grants one subsequent password login relief from soft
|
|
70
|
+
risk checks for 30 minutes; it does not bypass enrolled MFA or account suspension.
|
|
71
|
+
|
|
43
72
|
## Environment Variables
|
|
44
73
|
|
|
45
74
|
```bash
|
package/dist/audio.js
CHANGED
|
@@ -1197,6 +1197,7 @@ var NetworkPlayerClient = class {
|
|
|
1197
1197
|
this.target = null;
|
|
1198
1198
|
this.connected = false;
|
|
1199
1199
|
this.pending = false;
|
|
1200
|
+
this.handoffRequested = false;
|
|
1200
1201
|
this.openedAt = 0;
|
|
1201
1202
|
this.lastSeen = 0;
|
|
1202
1203
|
this.latest = null;
|
|
@@ -1213,10 +1214,11 @@ var NetworkPlayerClient = class {
|
|
|
1213
1214
|
this.lastSeen = Date.now();
|
|
1214
1215
|
if (!this.connected) {
|
|
1215
1216
|
const local = this.controller.getSnapshot();
|
|
1216
|
-
const handoff = this.
|
|
1217
|
+
const handoff = this.handoffRequested && !data.snapshot.queue.length && local.queue.length > 0;
|
|
1217
1218
|
this.controller.pause();
|
|
1218
1219
|
this.connected = true;
|
|
1219
1220
|
this.pending = false;
|
|
1221
|
+
this.handoffRequested = false;
|
|
1220
1222
|
if (handoff) this.post({ kind: "adopt", snapshot: local, play: local.status === "playing" || local.status === "loading" });
|
|
1221
1223
|
}
|
|
1222
1224
|
this.latest = data.snapshot;
|
|
@@ -1251,6 +1253,7 @@ var NetworkPlayerClient = class {
|
|
|
1251
1253
|
return;
|
|
1252
1254
|
}
|
|
1253
1255
|
this.pending = true;
|
|
1256
|
+
this.handoffRequested = true;
|
|
1254
1257
|
this.openedAt = Date.now();
|
|
1255
1258
|
}
|
|
1256
1259
|
command(command) {
|
|
@@ -1262,6 +1265,7 @@ var NetworkPlayerClient = class {
|
|
|
1262
1265
|
disconnect(notice) {
|
|
1263
1266
|
if (this.latest) this.controller.restore(this.latest);
|
|
1264
1267
|
this.connected = false;
|
|
1268
|
+
this.handoffRequested = false;
|
|
1265
1269
|
this.target = null;
|
|
1266
1270
|
this.latest = null;
|
|
1267
1271
|
this.update(null, notice);
|
package/dist/audio.mjs
CHANGED
|
@@ -1177,6 +1177,7 @@ var NetworkPlayerClient = class {
|
|
|
1177
1177
|
this.target = null;
|
|
1178
1178
|
this.connected = false;
|
|
1179
1179
|
this.pending = false;
|
|
1180
|
+
this.handoffRequested = false;
|
|
1180
1181
|
this.openedAt = 0;
|
|
1181
1182
|
this.lastSeen = 0;
|
|
1182
1183
|
this.latest = null;
|
|
@@ -1193,10 +1194,11 @@ var NetworkPlayerClient = class {
|
|
|
1193
1194
|
this.lastSeen = Date.now();
|
|
1194
1195
|
if (!this.connected) {
|
|
1195
1196
|
const local = this.controller.getSnapshot();
|
|
1196
|
-
const handoff = this.
|
|
1197
|
+
const handoff = this.handoffRequested && !data.snapshot.queue.length && local.queue.length > 0;
|
|
1197
1198
|
this.controller.pause();
|
|
1198
1199
|
this.connected = true;
|
|
1199
1200
|
this.pending = false;
|
|
1201
|
+
this.handoffRequested = false;
|
|
1200
1202
|
if (handoff) this.post({ kind: "adopt", snapshot: local, play: local.status === "playing" || local.status === "loading" });
|
|
1201
1203
|
}
|
|
1202
1204
|
this.latest = data.snapshot;
|
|
@@ -1231,6 +1233,7 @@ var NetworkPlayerClient = class {
|
|
|
1231
1233
|
return;
|
|
1232
1234
|
}
|
|
1233
1235
|
this.pending = true;
|
|
1236
|
+
this.handoffRequested = true;
|
|
1234
1237
|
this.openedAt = Date.now();
|
|
1235
1238
|
}
|
|
1236
1239
|
command(command) {
|
|
@@ -1242,6 +1245,7 @@ var NetworkPlayerClient = class {
|
|
|
1242
1245
|
disconnect(notice) {
|
|
1243
1246
|
if (this.latest) this.controller.restore(this.latest);
|
|
1244
1247
|
this.connected = false;
|
|
1248
|
+
this.handoffRequested = false;
|
|
1245
1249
|
this.target = null;
|
|
1246
1250
|
this.latest = null;
|
|
1247
1251
|
this.update(null, notice);
|
package/dist/client.d.mts
CHANGED
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -611,7 +611,7 @@ var ScaleMuleClient = class {
|
|
|
611
611
|
responseData = text ? JSON.parse(text) : null;
|
|
612
612
|
} catch {
|
|
613
613
|
}
|
|
614
|
-
if (!response.ok) {
|
|
614
|
+
if (!response.ok || responseData?.success === false) {
|
|
615
615
|
const rawError = responseData?.error;
|
|
616
616
|
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
617
617
|
const error = withErrorContext(baseError, responseData, response.headers);
|
|
@@ -650,7 +650,7 @@ var ScaleMuleClient = class {
|
|
|
650
650
|
continue;
|
|
651
651
|
}
|
|
652
652
|
if (this.debug) {
|
|
653
|
-
console.error("[ScaleMule] Request failed:", error);
|
|
653
|
+
console.error("[ScaleMule] Request failed:", ["LOGIN_CHALLENGE_REQUIRED", "MFA_REQUIRED"].includes(error.code) ? error.code : error);
|
|
654
654
|
}
|
|
655
655
|
throw new ScaleMuleApiError(error);
|
|
656
656
|
}
|
package/dist/client.mjs
CHANGED
|
@@ -609,7 +609,7 @@ var ScaleMuleClient = class {
|
|
|
609
609
|
responseData = text ? JSON.parse(text) : null;
|
|
610
610
|
} catch {
|
|
611
611
|
}
|
|
612
|
-
if (!response.ok) {
|
|
612
|
+
if (!response.ok || responseData?.success === false) {
|
|
613
613
|
const rawError = responseData?.error;
|
|
614
614
|
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
615
615
|
const error = withErrorContext(baseError, responseData, response.headers);
|
|
@@ -648,7 +648,7 @@ var ScaleMuleClient = class {
|
|
|
648
648
|
continue;
|
|
649
649
|
}
|
|
650
650
|
if (this.debug) {
|
|
651
|
-
console.error("[ScaleMule] Request failed:", error);
|
|
651
|
+
console.error("[ScaleMule] Request failed:", ["LOGIN_CHALLENGE_REQUIRED", "MFA_REQUIRED"].includes(error.code) ? error.code : error);
|
|
652
652
|
}
|
|
653
653
|
throw new ScaleMuleApiError(error);
|
|
654
654
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@ import { MoneyClient } from '@scalemule/money';
|
|
|
6
6
|
export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
|
|
7
7
|
import { ScaleMuleClient } from './client.mjs';
|
|
8
8
|
export { ClientConfig, RequestOptions, createClient } from './client.mjs';
|
|
9
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
10
|
-
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-
|
|
9
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BQgmT53x.mjs';
|
|
10
|
+
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-BQgmT53x.mjs';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Tri-state file visibility — `'private' | 'app_public' | 'anonymous_visible'`.
|
|
@@ -204,7 +204,14 @@ interface UseMediaReturn {
|
|
|
204
204
|
*/
|
|
205
205
|
declare function useMedia(): UseMediaReturn;
|
|
206
206
|
|
|
207
|
+
interface SecurityChallenge {
|
|
208
|
+
method: 'email' | 'totp' | 'sms';
|
|
209
|
+
error?: string;
|
|
210
|
+
}
|
|
211
|
+
type SecurityChallengePrompt = (challenge: SecurityChallenge) => Promise<string | null>;
|
|
212
|
+
|
|
207
213
|
interface ScaleMuleContextValue {
|
|
214
|
+
requestSecurityCode: SecurityChallengePrompt;
|
|
208
215
|
/** The API client instance */
|
|
209
216
|
client: ScaleMuleClient;
|
|
210
217
|
/** Money client instance sharing the same session token */
|
|
@@ -269,6 +276,10 @@ interface ScaleMuleContextValue {
|
|
|
269
276
|
bootstrapFlags?: Record<string, unknown>;
|
|
270
277
|
}
|
|
271
278
|
interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
279
|
+
/** Recovery link in the built-in security challenge. */
|
|
280
|
+
passwordRecoveryUrl?: string;
|
|
281
|
+
/** Optional custom adaptive verification UI. */
|
|
282
|
+
onSecurityChallenge?: SecurityChallengePrompt;
|
|
272
283
|
children: ReactNode;
|
|
273
284
|
/** Called when user logs in */
|
|
274
285
|
onLogin?: (user: User, response: LoginResponse) => void;
|
|
@@ -329,7 +340,7 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
329
340
|
*/
|
|
330
341
|
memberTokenPollMs?: number | null;
|
|
331
342
|
}
|
|
332
|
-
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, mediaPolicy, getToken, userResolver, memberTokenPollMs, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
343
|
+
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, mediaPolicy, getToken, userResolver, memberTokenPollMs, passwordRecoveryUrl, onSecurityChallenge, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
333
344
|
declare function useScaleMule(): ScaleMuleContextValue;
|
|
334
345
|
declare function useScaleMuleClient(): ScaleMuleClient;
|
|
335
346
|
declare function useMoneyClient(): MoneyClient;
|
|
@@ -1220,4 +1231,4 @@ declare function createSafeLogger(prefix: string): {
|
|
|
1220
1231
|
error: (message: string, data?: unknown) => void;
|
|
1221
1232
|
};
|
|
1222
1233
|
|
|
1223
|
-
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
|
1234
|
+
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, type SecurityChallenge, type SecurityChallengePrompt, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { MoneyClient } from '@scalemule/money';
|
|
|
6
6
|
export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
|
|
7
7
|
import { ScaleMuleClient } from './client.js';
|
|
8
8
|
export { ClientConfig, RequestOptions, createClient } from './client.js';
|
|
9
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
10
|
-
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-
|
|
9
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BQgmT53x.js';
|
|
10
|
+
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-BQgmT53x.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Tri-state file visibility — `'private' | 'app_public' | 'anonymous_visible'`.
|
|
@@ -204,7 +204,14 @@ interface UseMediaReturn {
|
|
|
204
204
|
*/
|
|
205
205
|
declare function useMedia(): UseMediaReturn;
|
|
206
206
|
|
|
207
|
+
interface SecurityChallenge {
|
|
208
|
+
method: 'email' | 'totp' | 'sms';
|
|
209
|
+
error?: string;
|
|
210
|
+
}
|
|
211
|
+
type SecurityChallengePrompt = (challenge: SecurityChallenge) => Promise<string | null>;
|
|
212
|
+
|
|
207
213
|
interface ScaleMuleContextValue {
|
|
214
|
+
requestSecurityCode: SecurityChallengePrompt;
|
|
208
215
|
/** The API client instance */
|
|
209
216
|
client: ScaleMuleClient;
|
|
210
217
|
/** Money client instance sharing the same session token */
|
|
@@ -269,6 +276,10 @@ interface ScaleMuleContextValue {
|
|
|
269
276
|
bootstrapFlags?: Record<string, unknown>;
|
|
270
277
|
}
|
|
271
278
|
interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
279
|
+
/** Recovery link in the built-in security challenge. */
|
|
280
|
+
passwordRecoveryUrl?: string;
|
|
281
|
+
/** Optional custom adaptive verification UI. */
|
|
282
|
+
onSecurityChallenge?: SecurityChallengePrompt;
|
|
272
283
|
children: ReactNode;
|
|
273
284
|
/** Called when user logs in */
|
|
274
285
|
onLogin?: (user: User, response: LoginResponse) => void;
|
|
@@ -329,7 +340,7 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
329
340
|
*/
|
|
330
341
|
memberTokenPollMs?: number | null;
|
|
331
342
|
}
|
|
332
|
-
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, mediaPolicy, getToken, userResolver, memberTokenPollMs, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
343
|
+
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, telemetryEndpoint, publishableKey, enableAccountSwitcher, accountSwitcherPrivacy, children, onLogin, onLogout, onAuthError, bootstrapFlags, mediaPolicy, getToken, userResolver, memberTokenPollMs, passwordRecoveryUrl, onSecurityChallenge, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
333
344
|
declare function useScaleMule(): ScaleMuleContextValue;
|
|
334
345
|
declare function useScaleMuleClient(): ScaleMuleClient;
|
|
335
346
|
declare function useMoneyClient(): MoneyClient;
|
|
@@ -1220,4 +1231,4 @@ declare function createSafeLogger(prefix: string): {
|
|
|
1220
1231
|
error: (message: string, data?: unknown) => void;
|
|
1221
1232
|
};
|
|
1222
1233
|
|
|
1223
|
-
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
|
1234
|
+
export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, type SecurityChallenge, type SecurityChallengePrompt, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, type UseVoteOptions, type UseVoteReturn, User, type UsernameValidationResult, VoteButton, type VoteButtonClassNames, type VoteButtonProps, type VoteState, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, useVote, validateForm, validators };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
5
|
var money = require('@scalemule/money');
|
|
5
6
|
var sdk = require('@scalemule/sdk');
|
|
6
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
8
8
|
function _interopNamespace(e) {
|
|
9
9
|
if (e && e.__esModule) return e;
|
|
@@ -25,7 +25,129 @@ function _interopNamespace(e) {
|
|
|
25
25
|
|
|
26
26
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
27
|
|
|
28
|
-
// src/
|
|
28
|
+
// src/security-challenge.tsx
|
|
29
|
+
function useSecurityChallenge(recoveryUrl) {
|
|
30
|
+
const [challenge, setChallenge] = React.useState(null);
|
|
31
|
+
const [code, setCode] = React.useState("");
|
|
32
|
+
const resolve = React.useRef(null);
|
|
33
|
+
const dialog = React.useRef(null);
|
|
34
|
+
const answer = React.useCallback((value) => {
|
|
35
|
+
const pending = resolve.current;
|
|
36
|
+
resolve.current = null;
|
|
37
|
+
setChallenge(null);
|
|
38
|
+
setCode("");
|
|
39
|
+
pending?.(value);
|
|
40
|
+
}, []);
|
|
41
|
+
const prompt = React.useCallback((next) => {
|
|
42
|
+
resolve.current?.(null);
|
|
43
|
+
return new Promise((done) => {
|
|
44
|
+
resolve.current = done;
|
|
45
|
+
setCode("");
|
|
46
|
+
setChallenge(next);
|
|
47
|
+
});
|
|
48
|
+
}, []);
|
|
49
|
+
React.useEffect(() => () => {
|
|
50
|
+
resolve.current?.(null);
|
|
51
|
+
resolve.current = null;
|
|
52
|
+
}, []);
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
if (challenge && dialog.current && !dialog.current.open) dialog.current.showModal();
|
|
55
|
+
}, [challenge]);
|
|
56
|
+
const element = challenge ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
+
"dialog",
|
|
58
|
+
{
|
|
59
|
+
ref: dialog,
|
|
60
|
+
"aria-labelledby": "sm-security-title",
|
|
61
|
+
"aria-describedby": "sm-security-description",
|
|
62
|
+
onCancel: (event) => {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
answer(null);
|
|
65
|
+
},
|
|
66
|
+
style: { border: "1px solid #d1d5db", borderRadius: 16, padding: 28, maxWidth: 420, width: "calc(100% - 48px)", color: "#111827", background: "#fff", boxSizing: "border-box" },
|
|
67
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: (event) => {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
if (code.trim()) answer(code.trim());
|
|
70
|
+
}, children: [
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { id: "sm-security-title", style: { marginTop: 0 }, children: "Confirm your sign-in" }),
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { id: "sm-security-description", children: challenge.method === "totp" ? "Enter a code from your authenticator app." : "Enter the verification code sent to your " + (challenge.method === "sms" ? "phone." : "email.") }),
|
|
73
|
+
challenge.error && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", style: { color: "#b91c1c" }, children: challenge.error }),
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "sm-security-code", children: "Verification code" }),
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
76
|
+
"input",
|
|
77
|
+
{
|
|
78
|
+
id: "sm-security-code",
|
|
79
|
+
autoFocus: true,
|
|
80
|
+
autoComplete: "one-time-code",
|
|
81
|
+
inputMode: "numeric",
|
|
82
|
+
value: code,
|
|
83
|
+
onChange: (event) => setCode(event.target.value),
|
|
84
|
+
maxLength: 32,
|
|
85
|
+
required: true,
|
|
86
|
+
style: { display: "block", boxSizing: "border-box", width: "100%", margin: "8px 0 20px", padding: 12, fontSize: 22, border: "1px solid #9ca3af", borderRadius: 8 }
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: { padding: "10px 20px", borderRadius: 8, border: 0, background: "#2563eb", color: "#fff", cursor: "pointer" }, children: "Continue" }),
|
|
90
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => answer(null), style: { marginLeft: 12 }, children: "Cancel" }),
|
|
91
|
+
challenge.method !== "totp" && /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
92
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => answer("resend"), children: "Send a new code" }),
|
|
93
|
+
" ",
|
|
94
|
+
/* @__PURE__ */ jsxRuntime.jsx("small", { children: "(wait 60 seconds between requests)" })
|
|
95
|
+
] }),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: /* @__PURE__ */ jsxRuntime.jsx("a", { href: recoveryUrl, onClick: () => answer(null), children: "Reset your password" }) })
|
|
97
|
+
] })
|
|
98
|
+
}
|
|
99
|
+
) : null;
|
|
100
|
+
return { prompt, element };
|
|
101
|
+
}
|
|
102
|
+
async function withAdaptiveChallenge(attempt, prompt, mfa) {
|
|
103
|
+
let proof = {};
|
|
104
|
+
let challengeToken;
|
|
105
|
+
let message;
|
|
106
|
+
for (; ; ) {
|
|
107
|
+
try {
|
|
108
|
+
return await attempt(proof);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
const err = error;
|
|
111
|
+
if (err.code === "MFA_REQUIRED" && mfa) {
|
|
112
|
+
const details = JSON.parse(err.message || "{}");
|
|
113
|
+
const token = details.pending_token;
|
|
114
|
+
const method = details.mfa_method;
|
|
115
|
+
if (!token || !["totp", "email", "sms"].includes(method || "")) throw error;
|
|
116
|
+
if (method !== "totp") await mfa.send(token, method);
|
|
117
|
+
let mfaError;
|
|
118
|
+
for (; ; ) {
|
|
119
|
+
const code2 = await prompt({ method, error: mfaError });
|
|
120
|
+
if (code2 === null) throw { code: "LOGIN_CANCELLED", message: "Sign-in was cancelled." };
|
|
121
|
+
try {
|
|
122
|
+
if (code2 === "resend") {
|
|
123
|
+
await mfa.send(token, method);
|
|
124
|
+
mfaError = void 0;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
return await mfa.verify(token, code2, method);
|
|
128
|
+
} catch (failure) {
|
|
129
|
+
const failed = failure;
|
|
130
|
+
if (!["INVALID_MFA_CODE", "CHALLENGE_RATE_LIMITED"].includes(failed.code || "")) throw failure;
|
|
131
|
+
mfaError = failed.message;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (err.code === "LOGIN_CHALLENGE_REQUIRED") {
|
|
136
|
+
const details = JSON.parse(err.message || "{}");
|
|
137
|
+
if (!details.challenge_token) throw error;
|
|
138
|
+
challengeToken = details.challenge_token;
|
|
139
|
+
message = void 0;
|
|
140
|
+
} else if (challengeToken && ["LOGIN_CHALLENGE_INVALID", "CHALLENGE_RATE_LIMITED"].includes(err.code || "")) {
|
|
141
|
+
message = err.message;
|
|
142
|
+
} else {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
const code = await prompt({ method: "email", error: message });
|
|
146
|
+
if (code === null) throw { code: "LOGIN_CANCELLED", message: "Sign-in was cancelled." };
|
|
147
|
+
proof = code === "resend" ? {} : { challenge_token: challengeToken, challenge_code: code };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
29
151
|
|
|
30
152
|
// src/types/index.ts
|
|
31
153
|
var ScaleMuleApiError = class extends Error {
|
|
@@ -634,7 +756,7 @@ var ScaleMuleClient = class {
|
|
|
634
756
|
responseData = text ? JSON.parse(text) : null;
|
|
635
757
|
} catch {
|
|
636
758
|
}
|
|
637
|
-
if (!response.ok) {
|
|
759
|
+
if (!response.ok || responseData?.success === false) {
|
|
638
760
|
const rawError = responseData?.error;
|
|
639
761
|
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
640
762
|
const error = withErrorContext(baseError, responseData, response.headers);
|
|
@@ -673,7 +795,7 @@ var ScaleMuleClient = class {
|
|
|
673
795
|
continue;
|
|
674
796
|
}
|
|
675
797
|
if (this.debug) {
|
|
676
|
-
console.error("[ScaleMule] Request failed:", error);
|
|
798
|
+
console.error("[ScaleMule] Request failed:", ["LOGIN_CHALLENGE_REQUIRED", "MFA_REQUIRED"].includes(error.code) ? error.code : error);
|
|
677
799
|
}
|
|
678
800
|
throw new ScaleMuleApiError(error);
|
|
679
801
|
}
|
|
@@ -943,6 +1065,7 @@ function setSdkTelemetryEndpoint(url) {
|
|
|
943
1065
|
endpoint = url;
|
|
944
1066
|
}
|
|
945
1067
|
function reportSdkError(payload) {
|
|
1068
|
+
if (["LOGIN_CHALLENGE_REQUIRED", "MFA_REQUIRED"].includes(payload.code)) return;
|
|
946
1069
|
if (!endpoint) return;
|
|
947
1070
|
if (typeof fetch === "undefined") return;
|
|
948
1071
|
const body = JSON.stringify({
|
|
@@ -1018,8 +1141,12 @@ function ScaleMuleProvider({
|
|
|
1018
1141
|
mediaPolicy,
|
|
1019
1142
|
getToken,
|
|
1020
1143
|
userResolver,
|
|
1021
|
-
memberTokenPollMs
|
|
1144
|
+
memberTokenPollMs,
|
|
1145
|
+
passwordRecoveryUrl = "/auth/forgot-password",
|
|
1146
|
+
onSecurityChallenge
|
|
1022
1147
|
}) {
|
|
1148
|
+
const security = useSecurityChallenge(passwordRecoveryUrl);
|
|
1149
|
+
const requestSecurityCode = onSecurityChallenge || security.prompt;
|
|
1023
1150
|
const memberMode = typeof getToken === "function";
|
|
1024
1151
|
const [user, setUser] = React.useState(null);
|
|
1025
1152
|
const [initializing, setInitializing] = React.useState(true);
|
|
@@ -1261,6 +1388,7 @@ function ScaleMuleProvider({
|
|
|
1261
1388
|
);
|
|
1262
1389
|
const value = React.useMemo(
|
|
1263
1390
|
() => ({
|
|
1391
|
+
requestSecurityCode,
|
|
1264
1392
|
client,
|
|
1265
1393
|
money: money$1,
|
|
1266
1394
|
realtime: baseClient.realtime,
|
|
@@ -1288,9 +1416,12 @@ function ScaleMuleProvider({
|
|
|
1288
1416
|
accountSwitcherPrivacy,
|
|
1289
1417
|
bootstrapFlags
|
|
1290
1418
|
}),
|
|
1291
|
-
[client, money$1, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1419
|
+
[requestSecurityCode, client, money$1, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1292
1420
|
);
|
|
1293
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
1421
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ScaleMuleContext.Provider, { value, children: [
|
|
1422
|
+
children,
|
|
1423
|
+
security.element
|
|
1424
|
+
] });
|
|
1294
1425
|
}
|
|
1295
1426
|
function useScaleMule() {
|
|
1296
1427
|
const context = React.useContext(ScaleMuleContext);
|
|
@@ -1402,7 +1533,7 @@ async function proxyFetch(proxyUrl, path, options = {}) {
|
|
|
1402
1533
|
return data;
|
|
1403
1534
|
}
|
|
1404
1535
|
function useAuth() {
|
|
1405
|
-
const { client, user, setUser, initializing, error, setError, authProxyUrl, enableAccountSwitcher, accountSwitcherPrivacy } = useScaleMule();
|
|
1536
|
+
const { client, user, setUser, initializing, error, setError, authProxyUrl, enableAccountSwitcher, accountSwitcherPrivacy, requestSecurityCode } = useScaleMule();
|
|
1406
1537
|
const register = React.useCallback(
|
|
1407
1538
|
async (data) => {
|
|
1408
1539
|
setError(null);
|
|
@@ -1443,19 +1574,31 @@ function useAuth() {
|
|
|
1443
1574
|
async (data) => {
|
|
1444
1575
|
setError(null);
|
|
1445
1576
|
if (authProxyUrl) {
|
|
1446
|
-
const response = await
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
code: "LOGIN_FAILED",
|
|
1454
|
-
|
|
1455
|
-
};
|
|
1577
|
+
const response = await withAdaptiveChallenge(async (proof) => {
|
|
1578
|
+
const result = await proxyFetch(
|
|
1579
|
+
authProxyUrl,
|
|
1580
|
+
"login",
|
|
1581
|
+
{ body: { ...data, ...proof } }
|
|
1582
|
+
);
|
|
1583
|
+
if (!result.success || !result.data) {
|
|
1584
|
+
throw result.error || { code: "LOGIN_FAILED", message: "Login failed" };
|
|
1585
|
+
}
|
|
1586
|
+
return { ...result, data: result.data };
|
|
1587
|
+
}, requestSecurityCode, {
|
|
1588
|
+
send: async (pending_token, method) => {
|
|
1589
|
+
const result = await proxyFetch(authProxyUrl, "mfa/send-code", { body: { pending_token, method } });
|
|
1590
|
+
if (!result.success) throw result.error;
|
|
1591
|
+
return result;
|
|
1592
|
+
},
|
|
1593
|
+
verify: async (pending_token, code, method) => {
|
|
1594
|
+
const result = await proxyFetch(authProxyUrl, "mfa/verify", { body: { pending_token, code, method } });
|
|
1595
|
+
if (!result.success || !result.data) throw result.error;
|
|
1596
|
+
return { ...result, data: result.data };
|
|
1597
|
+
}
|
|
1598
|
+
}).catch((err) => {
|
|
1456
1599
|
setError(err);
|
|
1457
1600
|
throw err;
|
|
1458
|
-
}
|
|
1601
|
+
});
|
|
1459
1602
|
if ("requires_mfa" in response.data && response.data.requires_mfa) {
|
|
1460
1603
|
return response.data;
|
|
1461
1604
|
}
|
|
@@ -1473,7 +1616,10 @@ function useAuth() {
|
|
|
1473
1616
|
}
|
|
1474
1617
|
let loginResult;
|
|
1475
1618
|
try {
|
|
1476
|
-
loginResult = await client.post("/v1/auth/login", data)
|
|
1619
|
+
loginResult = await withAdaptiveChallenge((proof) => client.post("/v1/auth/login", { ...data, ...proof }), requestSecurityCode, {
|
|
1620
|
+
send: (pending_token, method) => client.post("/v1/auth/mfa/send-code", { pending_token, method }),
|
|
1621
|
+
verify: (pending_token, code, method) => client.post("/v1/auth/mfa/verify", { pending_token, code, method })
|
|
1622
|
+
});
|
|
1477
1623
|
} catch (err) {
|
|
1478
1624
|
if (err instanceof ScaleMuleApiError) {
|
|
1479
1625
|
setError(err);
|
|
@@ -1488,7 +1634,7 @@ function useAuth() {
|
|
|
1488
1634
|
setUser(loginData.user);
|
|
1489
1635
|
return loginData;
|
|
1490
1636
|
},
|
|
1491
|
-
[client, setUser, setError, authProxyUrl]
|
|
1637
|
+
[client, setUser, setError, authProxyUrl, requestSecurityCode]
|
|
1492
1638
|
);
|
|
1493
1639
|
const logout = React.useCallback(async () => {
|
|
1494
1640
|
setError(null);
|
|
@@ -1559,8 +1705,17 @@ function useAuth() {
|
|
|
1559
1705
|
throw err;
|
|
1560
1706
|
}
|
|
1561
1707
|
}
|
|
1708
|
+
await client.clearSession();
|
|
1709
|
+
setUser(null);
|
|
1710
|
+
if (typeof window !== "undefined") {
|
|
1711
|
+
const current = new URL(window.location.href);
|
|
1712
|
+
if (current.searchParams.get("token") === token) {
|
|
1713
|
+
current.searchParams.delete("token");
|
|
1714
|
+
window.history.replaceState(window.history.state, "", current.toString());
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1562
1717
|
},
|
|
1563
|
-
[client, setError, authProxyUrl]
|
|
1718
|
+
[client, setUser, setError, authProxyUrl]
|
|
1564
1719
|
);
|
|
1565
1720
|
const verifyEmail = React.useCallback(
|
|
1566
1721
|
async (token) => {
|
|
@@ -1841,11 +1996,13 @@ function useAuth() {
|
|
|
1841
1996
|
setError(null);
|
|
1842
1997
|
let mfaResult;
|
|
1843
1998
|
try {
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
}
|
|
1999
|
+
if (authProxyUrl) {
|
|
2000
|
+
const result = await proxyFetch(authProxyUrl, "mfa/verify", { body: { pending_token: challengeToken, code, method } });
|
|
2001
|
+
if (!result.success || !result.data) throw result.error;
|
|
2002
|
+
mfaResult = result.data;
|
|
2003
|
+
} else {
|
|
2004
|
+
mfaResult = await client.post("/v1/auth/mfa/verify", { pending_token: challengeToken, code, method });
|
|
2005
|
+
}
|
|
1849
2006
|
} catch (err) {
|
|
1850
2007
|
if (err instanceof ScaleMuleApiError) {
|
|
1851
2008
|
setError(err);
|
|
@@ -1856,7 +2013,7 @@ function useAuth() {
|
|
|
1856
2013
|
setUser(mfaResult.user);
|
|
1857
2014
|
return mfaResult;
|
|
1858
2015
|
},
|
|
1859
|
-
[client, setUser, setError]
|
|
2016
|
+
[client, setUser, setError, authProxyUrl]
|
|
1860
2017
|
);
|
|
1861
2018
|
const disableMFA = React.useCallback(
|
|
1862
2019
|
async (password) => {
|