@scalemule/nextjs 0.0.37 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +1 -5
- package/dist/client.d.ts +1 -5
- package/dist/{index-BIIUrnPr.d.mts → index-BoENfro3.d.mts} +1 -54
- package/dist/{index-BIIUrnPr.d.ts → index-BoENfro3.d.ts} +1 -54
- package/dist/index.d.mts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.js +42 -112
- package/dist/index.mjs +42 -112
- package/dist/server/auth.js +6 -266
- package/dist/server/auth.mjs +6 -266
- package/dist/server/index.d.mts +4 -68
- package/dist/server/index.d.ts +4 -68
- package/dist/server/index.js +6 -273
- package/dist/server/index.mjs +7 -267
- 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-BobYTuNP.d.ts → webhook-handler-CjSSCdvI.d.ts} +1 -1
- package/dist/{webhook-handler-CNKQ1k2a.d.mts → webhook-handler-Cz9jtet2.d.mts} +1 -1
- package/package.json +2 -2
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a7 as StorageAdapter } from './index-BoENfro3.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ScaleMule API Client
|
|
@@ -34,10 +34,6 @@ interface ClientConfig {
|
|
|
34
34
|
* preventing race conditions where requests fire before the auth token is available.
|
|
35
35
|
*/
|
|
36
36
|
pendingSessionInit?: boolean;
|
|
37
|
-
/** Enable the account switcher */
|
|
38
|
-
enableAccountSwitcher?: boolean;
|
|
39
|
-
/** Privacy level for account switcher */
|
|
40
|
-
accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
|
|
41
37
|
}
|
|
42
38
|
interface RequestOptions extends RequestInit {
|
|
43
39
|
/** Skip adding auth headers (for public endpoints) */
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a7 as StorageAdapter } from './index-BoENfro3.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ScaleMule API Client
|
|
@@ -34,10 +34,6 @@ interface ClientConfig {
|
|
|
34
34
|
* preventing race conditions where requests fire before the auth token is available.
|
|
35
35
|
*/
|
|
36
36
|
pendingSessionInit?: boolean;
|
|
37
|
-
/** Enable the account switcher */
|
|
38
|
-
enableAccountSwitcher?: boolean;
|
|
39
|
-
/** Privacy level for account switcher */
|
|
40
|
-
accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
|
|
41
37
|
}
|
|
42
38
|
interface RequestOptions extends RequestInit {
|
|
43
39
|
/** Skip adding auth headers (for public endpoints) */
|
|
@@ -66,29 +66,6 @@ interface ScaleMuleConfig {
|
|
|
66
66
|
* publishableKey: 'sm_pb_production_a1b2c3d4...'
|
|
67
67
|
*/
|
|
68
68
|
publishableKey?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Enable the account switcher — remembers which accounts have logged in on
|
|
71
|
-
* this device so users can pick an account and re-authenticate.
|
|
72
|
-
*
|
|
73
|
-
* Stores only display metadata (email, name, avatar) — no tokens.
|
|
74
|
-
* Switching accounts always requires re-authentication.
|
|
75
|
-
*
|
|
76
|
-
* When using auth proxy mode, this works via a non-httpOnly cookie.
|
|
77
|
-
* The server route config must also have `enableAccountSwitcher: true`.
|
|
78
|
-
*
|
|
79
|
-
* Default: false
|
|
80
|
-
*/
|
|
81
|
-
enableAccountSwitcher?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Privacy level for account switcher display metadata.
|
|
84
|
-
*
|
|
85
|
-
* - 'full': Store email, name, avatar as-is (default)
|
|
86
|
-
* - 'masked': Mask email (j***@g***.com), truncate name to initial
|
|
87
|
-
* - 'minimal': No PII at all — just a colored "Account" label
|
|
88
|
-
*
|
|
89
|
-
* Applies to both server-side cookie writes and client-side reads.
|
|
90
|
-
*/
|
|
91
|
-
accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
|
|
92
69
|
}
|
|
93
70
|
interface StorageAdapter {
|
|
94
71
|
getItem(key: string): string | null | Promise<string | null>;
|
|
@@ -467,36 +444,6 @@ interface UseAuthReturn {
|
|
|
467
444
|
verifyPhone: (request: PhoneVerifyRequest) => Promise<void>;
|
|
468
445
|
/** Login with phone number */
|
|
469
446
|
loginWithPhone: (request: PhoneLoginRequest) => Promise<LoginResponse>;
|
|
470
|
-
/**
|
|
471
|
-
* All accounts that have previously logged in on this device.
|
|
472
|
-
* Contains display metadata only — no tokens.
|
|
473
|
-
* Requires `enableAccountSwitcher: true` in config.
|
|
474
|
-
*/
|
|
475
|
-
knownAccounts: KnownAccountInfo[];
|
|
476
|
-
/**
|
|
477
|
-
* Switch to a different known account.
|
|
478
|
-
* Logs out the current session and returns the target account's info
|
|
479
|
-
* so the login form can be pre-filled. User must re-authenticate.
|
|
480
|
-
*/
|
|
481
|
-
switchAccount: (userId: string) => Promise<KnownAccountInfo | null>;
|
|
482
|
-
/** Remove a specific account from the known accounts list */
|
|
483
|
-
removeKnownAccount: (userId: string) => Promise<void>;
|
|
484
|
-
/** Clear all known accounts from this device */
|
|
485
|
-
clearKnownAccounts: () => Promise<void>;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Known account info — display metadata only, no tokens.
|
|
489
|
-
* Used by the account switcher to show previously logged-in accounts.
|
|
490
|
-
*/
|
|
491
|
-
interface KnownAccountInfo {
|
|
492
|
-
userId: string;
|
|
493
|
-
email?: string;
|
|
494
|
-
fullName?: string;
|
|
495
|
-
avatarUrl?: string;
|
|
496
|
-
provider?: string;
|
|
497
|
-
lastActiveAt: string;
|
|
498
|
-
displayLabel?: string;
|
|
499
|
-
colorIndex?: number;
|
|
500
447
|
}
|
|
501
448
|
interface UseContentReturn {
|
|
502
449
|
/** User's files */
|
|
@@ -895,4 +842,4 @@ interface UseBillingReturn {
|
|
|
895
842
|
}) => Promise<string | null>;
|
|
896
843
|
}
|
|
897
844
|
|
|
898
|
-
export { type
|
|
845
|
+
export { type ResetPasswordRequest as $, type ApiError as A, type BatchTrackRequest as B, type ChangeEmailRequest as C, type DeviceFingerprint as D, type EnhancedAnalyticsEvent as E, type ForgotPasswordRequest as F, type MFASetupRequest as G, type MFAStatus as H, type MFATOTPSetupResponse as I, type MFAVerifyRequest as J, type OAuthCallbackResponse as K, type LoginResponse as L, type MFAChallengeResponse as M, type OAuthConfig as N, type OAuthCallbackRequest as O, type OAuthProvider as P, type OAuthStartResponse as Q, type PageViewData as R, type ScaleMuleConfig as S, type PayoutSchedule as T, type User as U, type PhoneLoginRequest as V, type PhoneSendCodeRequest as W, type PhoneVerifyRequest as X, type Profile as Y, type RefreshResponse as Z, type RegisterRequest as _, type UseAuthReturn as a, ScaleMuleApiError as a0, type ScaleMuleEnvironment as a1, type Session as a2, type SignedUploadCompleteRequest as a3, type SignedUploadRequest as a4, type SignedUploadResponse as a5, type SignedUploadUrl as a6, type StorageAdapter as a7, type StorageFile as a8, type TrackEventResponse as a9, type TransactionSummary as aa, type UTMParams as ab, type UpdateProfileRequest as ac, type UploadOptions as ad, type UploadResponse as ae, type VerifyEmailRequest as af, type UseBillingReturn as b, type ListFilesParams as c, type UseContentReturn as d, type UseUserReturn as e, type UseAnalyticsOptions as f, type UseAnalyticsReturn as g, type AccountBalance as h, type AnalyticsEvent as i, type ApiResponse as j, type BillingPayment as k, type BillingPayout as l, type BillingRefund as m, type BillingTransaction as n, type ChangePasswordRequest as o, type ClientContext as p, type ConnectedAccount as q, type DeviceInfo as r, type LinkedAccount as s, type ListFilesResponse as t, type LoginDeviceInfo as u, type LoginRequest as v, type LoginResponseWithMFA as w, type LoginRiskInfo as x, type MFAMethod as y, type MFASMSSetupResponse as z };
|
|
@@ -66,29 +66,6 @@ interface ScaleMuleConfig {
|
|
|
66
66
|
* publishableKey: 'sm_pb_production_a1b2c3d4...'
|
|
67
67
|
*/
|
|
68
68
|
publishableKey?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Enable the account switcher — remembers which accounts have logged in on
|
|
71
|
-
* this device so users can pick an account and re-authenticate.
|
|
72
|
-
*
|
|
73
|
-
* Stores only display metadata (email, name, avatar) — no tokens.
|
|
74
|
-
* Switching accounts always requires re-authentication.
|
|
75
|
-
*
|
|
76
|
-
* When using auth proxy mode, this works via a non-httpOnly cookie.
|
|
77
|
-
* The server route config must also have `enableAccountSwitcher: true`.
|
|
78
|
-
*
|
|
79
|
-
* Default: false
|
|
80
|
-
*/
|
|
81
|
-
enableAccountSwitcher?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Privacy level for account switcher display metadata.
|
|
84
|
-
*
|
|
85
|
-
* - 'full': Store email, name, avatar as-is (default)
|
|
86
|
-
* - 'masked': Mask email (j***@g***.com), truncate name to initial
|
|
87
|
-
* - 'minimal': No PII at all — just a colored "Account" label
|
|
88
|
-
*
|
|
89
|
-
* Applies to both server-side cookie writes and client-side reads.
|
|
90
|
-
*/
|
|
91
|
-
accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
|
|
92
69
|
}
|
|
93
70
|
interface StorageAdapter {
|
|
94
71
|
getItem(key: string): string | null | Promise<string | null>;
|
|
@@ -467,36 +444,6 @@ interface UseAuthReturn {
|
|
|
467
444
|
verifyPhone: (request: PhoneVerifyRequest) => Promise<void>;
|
|
468
445
|
/** Login with phone number */
|
|
469
446
|
loginWithPhone: (request: PhoneLoginRequest) => Promise<LoginResponse>;
|
|
470
|
-
/**
|
|
471
|
-
* All accounts that have previously logged in on this device.
|
|
472
|
-
* Contains display metadata only — no tokens.
|
|
473
|
-
* Requires `enableAccountSwitcher: true` in config.
|
|
474
|
-
*/
|
|
475
|
-
knownAccounts: KnownAccountInfo[];
|
|
476
|
-
/**
|
|
477
|
-
* Switch to a different known account.
|
|
478
|
-
* Logs out the current session and returns the target account's info
|
|
479
|
-
* so the login form can be pre-filled. User must re-authenticate.
|
|
480
|
-
*/
|
|
481
|
-
switchAccount: (userId: string) => Promise<KnownAccountInfo | null>;
|
|
482
|
-
/** Remove a specific account from the known accounts list */
|
|
483
|
-
removeKnownAccount: (userId: string) => Promise<void>;
|
|
484
|
-
/** Clear all known accounts from this device */
|
|
485
|
-
clearKnownAccounts: () => Promise<void>;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Known account info — display metadata only, no tokens.
|
|
489
|
-
* Used by the account switcher to show previously logged-in accounts.
|
|
490
|
-
*/
|
|
491
|
-
interface KnownAccountInfo {
|
|
492
|
-
userId: string;
|
|
493
|
-
email?: string;
|
|
494
|
-
fullName?: string;
|
|
495
|
-
avatarUrl?: string;
|
|
496
|
-
provider?: string;
|
|
497
|
-
lastActiveAt: string;
|
|
498
|
-
displayLabel?: string;
|
|
499
|
-
colorIndex?: number;
|
|
500
447
|
}
|
|
501
448
|
interface UseContentReturn {
|
|
502
449
|
/** User's files */
|
|
@@ -895,4 +842,4 @@ interface UseBillingReturn {
|
|
|
895
842
|
}) => Promise<string | null>;
|
|
896
843
|
}
|
|
897
844
|
|
|
898
|
-
export { type
|
|
845
|
+
export { type ResetPasswordRequest as $, type ApiError as A, type BatchTrackRequest as B, type ChangeEmailRequest as C, type DeviceFingerprint as D, type EnhancedAnalyticsEvent as E, type ForgotPasswordRequest as F, type MFASetupRequest as G, type MFAStatus as H, type MFATOTPSetupResponse as I, type MFAVerifyRequest as J, type OAuthCallbackResponse as K, type LoginResponse as L, type MFAChallengeResponse as M, type OAuthConfig as N, type OAuthCallbackRequest as O, type OAuthProvider as P, type OAuthStartResponse as Q, type PageViewData as R, type ScaleMuleConfig as S, type PayoutSchedule as T, type User as U, type PhoneLoginRequest as V, type PhoneSendCodeRequest as W, type PhoneVerifyRequest as X, type Profile as Y, type RefreshResponse as Z, type RegisterRequest as _, type UseAuthReturn as a, ScaleMuleApiError as a0, type ScaleMuleEnvironment as a1, type Session as a2, type SignedUploadCompleteRequest as a3, type SignedUploadRequest as a4, type SignedUploadResponse as a5, type SignedUploadUrl as a6, type StorageAdapter as a7, type StorageFile as a8, type TrackEventResponse as a9, type TransactionSummary as aa, type UTMParams as ab, type UpdateProfileRequest as ac, type UploadOptions as ad, type UploadResponse as ae, type VerifyEmailRequest as af, type UseBillingReturn as b, type ListFilesParams as c, type UseContentReturn as d, type UseUserReturn as e, type UseAnalyticsOptions as f, type UseAnalyticsReturn as g, type AccountBalance as h, type AnalyticsEvent as i, type ApiResponse as j, type BillingPayment as k, type BillingPayout as l, type BillingRefund as m, type BillingTransaction as n, type ChangePasswordRequest as o, type ClientContext as p, type ConnectedAccount as q, type DeviceInfo as r, type LinkedAccount as s, type ListFilesResponse as t, type LoginDeviceInfo as u, type LoginRequest as v, type LoginResponseWithMFA as w, type LoginRiskInfo as x, type MFAMethod as y, type MFASMSSetupResponse as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { RealtimeService } from '@scalemule/sdk';
|
|
4
4
|
import { ScaleMuleClient } from './client.mjs';
|
|
5
5
|
export { ClientConfig, RequestOptions, createClient } from './client.mjs';
|
|
6
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
7
|
-
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,
|
|
6
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BoENfro3.mjs';
|
|
7
|
+
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, 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, K as OAuthCallbackResponse, N as OAuthConfig, P as OAuthProvider, Q as OAuthStartResponse, R as PageViewData, T as PayoutSchedule, V as PhoneLoginRequest, W as PhoneSendCodeRequest, X as PhoneVerifyRequest, Y as Profile, Z as RefreshResponse, _ as RegisterRequest, $ as ResetPasswordRequest, a0 as ScaleMuleApiError, a1 as ScaleMuleEnvironment, a2 as Session, a3 as SignedUploadCompleteRequest, a4 as SignedUploadRequest, a5 as SignedUploadResponse, a6 as SignedUploadUrl, a7 as StorageAdapter, a8 as StorageFile, a9 as TrackEventResponse, aa as TransactionSummary, ab as UTMParams, ac as UpdateProfileRequest, ad as UploadOptions, ae as UploadResponse, af as VerifyEmailRequest } from './index-BoENfro3.mjs';
|
|
8
8
|
|
|
9
9
|
interface ScaleMuleContextValue {
|
|
10
10
|
/** The API client instance */
|
|
@@ -31,10 +31,6 @@ interface ScaleMuleContextValue {
|
|
|
31
31
|
gatewayUrl?: string;
|
|
32
32
|
/** Configured environment ('dev' or 'prod') */
|
|
33
33
|
environment?: string;
|
|
34
|
-
/** Whether the account switcher is enabled */
|
|
35
|
-
enableAccountSwitcher?: boolean;
|
|
36
|
-
/** Privacy level for account switcher */
|
|
37
|
-
accountSwitcherPrivacy?: string;
|
|
38
34
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
39
35
|
bootstrapFlags?: Record<string, unknown>;
|
|
40
36
|
}
|
|
@@ -49,7 +45,7 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
49
45
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
50
46
|
bootstrapFlags?: Record<string, unknown>;
|
|
51
47
|
}
|
|
52
|
-
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, publishableKey,
|
|
48
|
+
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, publishableKey, children, onLogin, onLogout, onAuthError, bootstrapFlags, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
53
49
|
declare function useScaleMule(): ScaleMuleContextValue;
|
|
54
50
|
declare function useScaleMuleClient(): ScaleMuleClient;
|
|
55
51
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { RealtimeService } from '@scalemule/sdk';
|
|
4
4
|
import { ScaleMuleClient } from './client.js';
|
|
5
5
|
export { ClientConfig, RequestOptions, createClient } from './client.js';
|
|
6
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
7
|
-
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,
|
|
6
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BoENfro3.js';
|
|
7
|
+
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, 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, K as OAuthCallbackResponse, N as OAuthConfig, P as OAuthProvider, Q as OAuthStartResponse, R as PageViewData, T as PayoutSchedule, V as PhoneLoginRequest, W as PhoneSendCodeRequest, X as PhoneVerifyRequest, Y as Profile, Z as RefreshResponse, _ as RegisterRequest, $ as ResetPasswordRequest, a0 as ScaleMuleApiError, a1 as ScaleMuleEnvironment, a2 as Session, a3 as SignedUploadCompleteRequest, a4 as SignedUploadRequest, a5 as SignedUploadResponse, a6 as SignedUploadUrl, a7 as StorageAdapter, a8 as StorageFile, a9 as TrackEventResponse, aa as TransactionSummary, ab as UTMParams, ac as UpdateProfileRequest, ad as UploadOptions, ae as UploadResponse, af as VerifyEmailRequest } from './index-BoENfro3.js';
|
|
8
8
|
|
|
9
9
|
interface ScaleMuleContextValue {
|
|
10
10
|
/** The API client instance */
|
|
@@ -31,10 +31,6 @@ interface ScaleMuleContextValue {
|
|
|
31
31
|
gatewayUrl?: string;
|
|
32
32
|
/** Configured environment ('dev' or 'prod') */
|
|
33
33
|
environment?: string;
|
|
34
|
-
/** Whether the account switcher is enabled */
|
|
35
|
-
enableAccountSwitcher?: boolean;
|
|
36
|
-
/** Privacy level for account switcher */
|
|
37
|
-
accountSwitcherPrivacy?: string;
|
|
38
34
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
39
35
|
bootstrapFlags?: Record<string, unknown>;
|
|
40
36
|
}
|
|
@@ -49,7 +45,7 @@ interface ScaleMuleProviderProps extends ScaleMuleConfig {
|
|
|
49
45
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
50
46
|
bootstrapFlags?: Record<string, unknown>;
|
|
51
47
|
}
|
|
52
|
-
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, publishableKey,
|
|
48
|
+
declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, publishableKey, children, onLogin, onLogout, onAuthError, bootstrapFlags, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
|
|
53
49
|
declare function useScaleMule(): ScaleMuleContextValue;
|
|
54
50
|
declare function useScaleMuleClient(): ScaleMuleClient;
|
|
55
51
|
|
package/dist/index.js
CHANGED
|
@@ -3089,6 +3089,7 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3089
3089
|
super(...arguments);
|
|
3090
3090
|
this.basePath = "/v1/realtime";
|
|
3091
3091
|
this.ws = null;
|
|
3092
|
+
this.usedTicketAuth = false;
|
|
3092
3093
|
this.subscriptions = /* @__PURE__ */ new Map();
|
|
3093
3094
|
this.presenceCallbacks = /* @__PURE__ */ new Map();
|
|
3094
3095
|
this.statusCallbacks = /* @__PURE__ */ new Set();
|
|
@@ -3217,10 +3218,31 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3217
3218
|
// --------------------------------------------------------------------------
|
|
3218
3219
|
connect() {
|
|
3219
3220
|
if (this._status === "connecting" || this._status === "connected") return;
|
|
3220
|
-
const baseUrl = this.client.getBaseUrl();
|
|
3221
|
-
const wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3222
3221
|
this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
|
|
3222
|
+
this.fetchTicketAndConnect();
|
|
3223
|
+
}
|
|
3224
|
+
async fetchTicketAndConnect() {
|
|
3225
|
+
const baseUrl = this.client.getBaseUrl();
|
|
3223
3226
|
try {
|
|
3227
|
+
const headers = { "Content-Type": "application/json" };
|
|
3228
|
+
const apiKey = this.client.getApiKey();
|
|
3229
|
+
if (apiKey) headers["x-api-key"] = apiKey;
|
|
3230
|
+
const token = this.client.getSessionToken();
|
|
3231
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
3232
|
+
const ticketRes = await fetch(`${baseUrl}/v1/realtime/ws/ticket`, {
|
|
3233
|
+
method: "POST",
|
|
3234
|
+
headers
|
|
3235
|
+
});
|
|
3236
|
+
let wsUrl;
|
|
3237
|
+
if (ticketRes.ok) {
|
|
3238
|
+
const ticketData = await ticketRes.json();
|
|
3239
|
+
const ticket = ticketData.ticket;
|
|
3240
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
|
|
3241
|
+
this.usedTicketAuth = true;
|
|
3242
|
+
} else {
|
|
3243
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3244
|
+
this.usedTicketAuth = false;
|
|
3245
|
+
}
|
|
3224
3246
|
this.ws = new WebSocket(wsUrl);
|
|
3225
3247
|
} catch {
|
|
3226
3248
|
this.scheduleReconnect();
|
|
@@ -3228,8 +3250,21 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3228
3250
|
}
|
|
3229
3251
|
this.ws.onopen = () => {
|
|
3230
3252
|
this.reconnectAttempt = 0;
|
|
3231
|
-
this.
|
|
3253
|
+
if (!this.usedTicketAuth) {
|
|
3254
|
+
this.authenticate();
|
|
3255
|
+
}
|
|
3232
3256
|
this.startHeartbeat();
|
|
3257
|
+
if (this.usedTicketAuth) {
|
|
3258
|
+
setTimeout(() => {
|
|
3259
|
+
if (!this.authenticated) {
|
|
3260
|
+
this.authenticated = true;
|
|
3261
|
+
this.setStatus("connected");
|
|
3262
|
+
for (const channel of this.subscriptions.keys()) {
|
|
3263
|
+
this.sendWs({ type: "subscribe", channel });
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
}, 2e3);
|
|
3267
|
+
}
|
|
3233
3268
|
};
|
|
3234
3269
|
this.ws.onmessage = (event) => {
|
|
3235
3270
|
try {
|
|
@@ -6916,8 +6951,6 @@ function ScaleMuleProvider({
|
|
|
6916
6951
|
analyticsProxyUrl,
|
|
6917
6952
|
authProxyUrl,
|
|
6918
6953
|
publishableKey,
|
|
6919
|
-
enableAccountSwitcher,
|
|
6920
|
-
accountSwitcherPrivacy,
|
|
6921
6954
|
children,
|
|
6922
6955
|
onLogin,
|
|
6923
6956
|
onLogout,
|
|
@@ -7055,11 +7088,9 @@ function ScaleMuleProvider({
|
|
|
7055
7088
|
publishableKey,
|
|
7056
7089
|
gatewayUrl: gatewayUrl || (environment === "dev" ? "https://api-dev.scalemule.com" : "https://api.scalemule.com"),
|
|
7057
7090
|
environment: environment || void 0,
|
|
7058
|
-
enableAccountSwitcher,
|
|
7059
|
-
accountSwitcherPrivacy,
|
|
7060
7091
|
bootstrapFlags
|
|
7061
7092
|
}),
|
|
7062
|
-
[client, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, gatewayUrl, environment,
|
|
7093
|
+
[client, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, gatewayUrl, environment, bootstrapFlags]
|
|
7063
7094
|
);
|
|
7064
7095
|
return /* @__PURE__ */ jsxRuntime.jsx(ScaleMuleContext.Provider, { value, children });
|
|
7065
7096
|
}
|
|
@@ -7076,41 +7107,6 @@ function useScaleMuleClient() {
|
|
|
7076
7107
|
const { client } = useScaleMule();
|
|
7077
7108
|
return client;
|
|
7078
7109
|
}
|
|
7079
|
-
function maskEmail2(email) {
|
|
7080
|
-
const [local, domain] = email.split("@");
|
|
7081
|
-
if (!domain) return "***@***.***";
|
|
7082
|
-
const tldDot = domain.lastIndexOf(".");
|
|
7083
|
-
const tld = tldDot > 0 ? domain.slice(tldDot) : "";
|
|
7084
|
-
const domainBase = tldDot > 0 ? domain.slice(0, tldDot) : domain;
|
|
7085
|
-
return `${local[0] || "*"}***@${domainBase[0] || "*"}***${tld}`;
|
|
7086
|
-
}
|
|
7087
|
-
function stableColorIndex2(userId) {
|
|
7088
|
-
let hash = 0;
|
|
7089
|
-
for (let i = 0; i < userId.length; i++) {
|
|
7090
|
-
hash = (hash << 5) - hash + userId.charCodeAt(i) | 0;
|
|
7091
|
-
}
|
|
7092
|
-
return Math.abs(hash) % 8;
|
|
7093
|
-
}
|
|
7094
|
-
function applyClientPrivacy(entry, privacy) {
|
|
7095
|
-
if (!privacy || privacy === "full") return entry;
|
|
7096
|
-
if (privacy === "masked") {
|
|
7097
|
-
return {
|
|
7098
|
-
userId: entry.userId,
|
|
7099
|
-
email: entry.email ? maskEmail2(entry.email) : void 0,
|
|
7100
|
-
fullName: entry.fullName ? `${entry.fullName[0].toUpperCase()}.` : void 0,
|
|
7101
|
-
provider: entry.provider,
|
|
7102
|
-
lastActiveAt: entry.lastActiveAt,
|
|
7103
|
-
colorIndex: stableColorIndex2(entry.userId)
|
|
7104
|
-
};
|
|
7105
|
-
}
|
|
7106
|
-
return {
|
|
7107
|
-
userId: entry.userId,
|
|
7108
|
-
provider: entry.provider,
|
|
7109
|
-
lastActiveAt: entry.lastActiveAt,
|
|
7110
|
-
displayLabel: "Account",
|
|
7111
|
-
colorIndex: stableColorIndex2(entry.userId)
|
|
7112
|
-
};
|
|
7113
|
-
}
|
|
7114
7110
|
function getCookie(name) {
|
|
7115
7111
|
if (typeof document === "undefined") return void 0;
|
|
7116
7112
|
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
@@ -7139,7 +7135,7 @@ async function proxyFetch(proxyUrl, path, options = {}) {
|
|
|
7139
7135
|
return data;
|
|
7140
7136
|
}
|
|
7141
7137
|
function useAuth() {
|
|
7142
|
-
const { client, user, setUser, initializing, error, setError, authProxyUrl
|
|
7138
|
+
const { client, user, setUser, initializing, error, setError, authProxyUrl } = useScaleMule();
|
|
7143
7139
|
const register = react.useCallback(
|
|
7144
7140
|
async (data) => {
|
|
7145
7141
|
setError(null);
|
|
@@ -7747,63 +7743,6 @@ function useAuth() {
|
|
|
7747
7743
|
},
|
|
7748
7744
|
[client, setUser, setError, authProxyUrl]
|
|
7749
7745
|
);
|
|
7750
|
-
const readKnownAccountsCookie = react.useCallback(() => {
|
|
7751
|
-
if (!enableAccountSwitcher) return [];
|
|
7752
|
-
if (typeof document === "undefined") return [];
|
|
7753
|
-
const match = document.cookie.match(/(?:^|; )sm_known_accounts=([^;]*)/);
|
|
7754
|
-
if (!match) return [];
|
|
7755
|
-
try {
|
|
7756
|
-
const decoded = decodeURIComponent(match[1]);
|
|
7757
|
-
const accounts = JSON.parse(decoded);
|
|
7758
|
-
let entries = Object.values(accounts);
|
|
7759
|
-
if (accountSwitcherPrivacy && accountSwitcherPrivacy !== "full") {
|
|
7760
|
-
entries = entries.map((e) => applyClientPrivacy(e, accountSwitcherPrivacy));
|
|
7761
|
-
}
|
|
7762
|
-
return entries;
|
|
7763
|
-
} catch {
|
|
7764
|
-
return [];
|
|
7765
|
-
}
|
|
7766
|
-
}, [enableAccountSwitcher, accountSwitcherPrivacy]);
|
|
7767
|
-
const [knownAccounts, setKnownAccounts] = react.useState([]);
|
|
7768
|
-
react.useEffect(() => {
|
|
7769
|
-
setKnownAccounts(readKnownAccountsCookie());
|
|
7770
|
-
}, [readKnownAccountsCookie, user]);
|
|
7771
|
-
const switchAccount = react.useCallback(
|
|
7772
|
-
async (userId) => {
|
|
7773
|
-
const target = knownAccounts.find((a) => a.userId === userId) || null;
|
|
7774
|
-
if (!target) return null;
|
|
7775
|
-
if (authProxyUrl) {
|
|
7776
|
-
await proxyFetch(authProxyUrl, "switch-account");
|
|
7777
|
-
} else {
|
|
7778
|
-
const sessionToken = client.getSessionToken();
|
|
7779
|
-
if (sessionToken) {
|
|
7780
|
-
try {
|
|
7781
|
-
await client.post("/v1/auth/logout", { session_token: sessionToken });
|
|
7782
|
-
} catch {
|
|
7783
|
-
}
|
|
7784
|
-
}
|
|
7785
|
-
await client.clearSession();
|
|
7786
|
-
}
|
|
7787
|
-
setUser(null);
|
|
7788
|
-
return target;
|
|
7789
|
-
},
|
|
7790
|
-
[client, setUser, knownAccounts, authProxyUrl]
|
|
7791
|
-
);
|
|
7792
|
-
const removeKnownAccount = react.useCallback(
|
|
7793
|
-
async (userId) => {
|
|
7794
|
-
if (authProxyUrl) {
|
|
7795
|
-
await proxyFetch(authProxyUrl, "forget-account", { body: { user_id: userId } });
|
|
7796
|
-
}
|
|
7797
|
-
setKnownAccounts((prev) => prev.filter((a) => a.userId !== userId));
|
|
7798
|
-
},
|
|
7799
|
-
[authProxyUrl]
|
|
7800
|
-
);
|
|
7801
|
-
const clearKnownAccounts = react.useCallback(async () => {
|
|
7802
|
-
if (authProxyUrl) {
|
|
7803
|
-
await proxyFetch(authProxyUrl, "forget-all-accounts");
|
|
7804
|
-
}
|
|
7805
|
-
setKnownAccounts([]);
|
|
7806
|
-
}, [authProxyUrl]);
|
|
7807
7746
|
return react.useMemo(
|
|
7808
7747
|
() => ({
|
|
7809
7748
|
user,
|
|
@@ -7835,12 +7774,7 @@ function useAuth() {
|
|
|
7835
7774
|
// Phone auth
|
|
7836
7775
|
sendPhoneCode,
|
|
7837
7776
|
verifyPhone,
|
|
7838
|
-
loginWithPhone
|
|
7839
|
-
// Account switcher
|
|
7840
|
-
knownAccounts,
|
|
7841
|
-
switchAccount,
|
|
7842
|
-
removeKnownAccount,
|
|
7843
|
-
clearKnownAccounts
|
|
7777
|
+
loginWithPhone
|
|
7844
7778
|
}),
|
|
7845
7779
|
[
|
|
7846
7780
|
user,
|
|
@@ -7867,11 +7801,7 @@ function useAuth() {
|
|
|
7867
7801
|
regenerateBackupCodes,
|
|
7868
7802
|
sendPhoneCode,
|
|
7869
7803
|
verifyPhone,
|
|
7870
|
-
loginWithPhone
|
|
7871
|
-
knownAccounts,
|
|
7872
|
-
switchAccount,
|
|
7873
|
-
removeKnownAccount,
|
|
7874
|
-
clearKnownAccounts
|
|
7804
|
+
loginWithPhone
|
|
7875
7805
|
]
|
|
7876
7806
|
);
|
|
7877
7807
|
}
|