@scalemule/nextjs 0.1.4 → 0.1.5
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/index.d.mts +81 -1
- package/dist/index.d.ts +81 -1
- package/dist/index.js +381 -190
- package/dist/index.mjs +173 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React = require('react');
|
|
4
4
|
var money = require('@scalemule/money');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
26
|
+
|
|
7
27
|
var __defProp = Object.defineProperty;
|
|
8
28
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
29
|
var __esm = (fn, res) => function __init() {
|
|
@@ -7408,7 +7428,7 @@ function setCachedUser(user) {
|
|
|
7408
7428
|
} catch {
|
|
7409
7429
|
}
|
|
7410
7430
|
}
|
|
7411
|
-
var ScaleMuleContext =
|
|
7431
|
+
var ScaleMuleContext = React.createContext(null);
|
|
7412
7432
|
function ScaleMuleProvider({
|
|
7413
7433
|
apiKey,
|
|
7414
7434
|
applicationId,
|
|
@@ -7427,11 +7447,11 @@ function ScaleMuleProvider({
|
|
|
7427
7447
|
onAuthError,
|
|
7428
7448
|
bootstrapFlags
|
|
7429
7449
|
}) {
|
|
7430
|
-
const [user, setUser] =
|
|
7431
|
-
const [initializing, setInitializing] =
|
|
7432
|
-
const [error, setError] =
|
|
7450
|
+
const [user, setUser] = React.useState(null);
|
|
7451
|
+
const [initializing, setInitializing] = React.useState(true);
|
|
7452
|
+
const [error, setError] = React.useState(null);
|
|
7433
7453
|
const resolvedGatewayUrl = gatewayUrl || (environment === "dev" ? "https://api-dev.scalemule.com" : "https://api.scalemule.com");
|
|
7434
|
-
const client =
|
|
7454
|
+
const client = React.useMemo(
|
|
7435
7455
|
() => createClient({
|
|
7436
7456
|
apiKey,
|
|
7437
7457
|
applicationId,
|
|
@@ -7443,7 +7463,7 @@ function ScaleMuleProvider({
|
|
|
7443
7463
|
}),
|
|
7444
7464
|
[apiKey, applicationId, environment, resolvedGatewayUrl, debug, storage, authProxyUrl]
|
|
7445
7465
|
);
|
|
7446
|
-
const money$1 =
|
|
7466
|
+
const money$1 = React.useMemo(
|
|
7447
7467
|
() => money.createMoneyClient({
|
|
7448
7468
|
apiKey,
|
|
7449
7469
|
gatewayUrl: resolvedGatewayUrl,
|
|
@@ -7453,7 +7473,7 @@ function ScaleMuleProvider({
|
|
|
7453
7473
|
}),
|
|
7454
7474
|
[apiKey, resolvedGatewayUrl, environment, client]
|
|
7455
7475
|
);
|
|
7456
|
-
const baseClient =
|
|
7476
|
+
const baseClient = React.useMemo(() => {
|
|
7457
7477
|
return new ScaleMule({
|
|
7458
7478
|
apiKey,
|
|
7459
7479
|
applicationId,
|
|
@@ -7462,7 +7482,7 @@ function ScaleMuleProvider({
|
|
|
7462
7482
|
debug
|
|
7463
7483
|
});
|
|
7464
7484
|
}, [apiKey, applicationId, environment, resolvedGatewayUrl, debug]);
|
|
7465
|
-
|
|
7485
|
+
React.useEffect(() => {
|
|
7466
7486
|
const token = client.getSessionToken();
|
|
7467
7487
|
if (token) {
|
|
7468
7488
|
baseClient.setAccessToken(token);
|
|
@@ -7472,7 +7492,7 @@ function ScaleMuleProvider({
|
|
|
7472
7492
|
money$1.setAccessToken(void 0);
|
|
7473
7493
|
}
|
|
7474
7494
|
}, [client, baseClient, money$1, user]);
|
|
7475
|
-
|
|
7495
|
+
React.useEffect(() => {
|
|
7476
7496
|
let mounted = true;
|
|
7477
7497
|
async function initialize() {
|
|
7478
7498
|
try {
|
|
@@ -7546,7 +7566,7 @@ function ScaleMuleProvider({
|
|
|
7546
7566
|
mounted = false;
|
|
7547
7567
|
};
|
|
7548
7568
|
}, [client, debug, onAuthError, authProxyUrl]);
|
|
7549
|
-
const handleSetUser =
|
|
7569
|
+
const handleSetUser = React.useCallback(
|
|
7550
7570
|
(newUser) => {
|
|
7551
7571
|
setUser(newUser);
|
|
7552
7572
|
setCachedUser(newUser);
|
|
@@ -7556,7 +7576,7 @@ function ScaleMuleProvider({
|
|
|
7556
7576
|
},
|
|
7557
7577
|
[onLogout]
|
|
7558
7578
|
);
|
|
7559
|
-
const value =
|
|
7579
|
+
const value = React.useMemo(
|
|
7560
7580
|
() => ({
|
|
7561
7581
|
client,
|
|
7562
7582
|
money: money$1,
|
|
@@ -7583,7 +7603,7 @@ function ScaleMuleProvider({
|
|
|
7583
7603
|
return /* @__PURE__ */ jsxRuntime.jsx(ScaleMuleContext.Provider, { value, children });
|
|
7584
7604
|
}
|
|
7585
7605
|
function useScaleMule() {
|
|
7586
|
-
const context =
|
|
7606
|
+
const context = React.useContext(ScaleMuleContext);
|
|
7587
7607
|
if (!context) {
|
|
7588
7608
|
throw new Error(
|
|
7589
7609
|
"useScaleMule must be used within a ScaleMuleProvider. Make sure to wrap your app with <ScaleMuleProvider>."
|
|
@@ -7663,7 +7683,7 @@ async function proxyFetch(proxyUrl, path, options = {}) {
|
|
|
7663
7683
|
}
|
|
7664
7684
|
function useAuth() {
|
|
7665
7685
|
const { client, user, setUser, initializing, error, setError, authProxyUrl, enableAccountSwitcher, accountSwitcherPrivacy } = useScaleMule();
|
|
7666
|
-
const register =
|
|
7686
|
+
const register = React.useCallback(
|
|
7667
7687
|
async (data) => {
|
|
7668
7688
|
setError(null);
|
|
7669
7689
|
if (authProxyUrl) {
|
|
@@ -7699,7 +7719,7 @@ function useAuth() {
|
|
|
7699
7719
|
},
|
|
7700
7720
|
[client, setUser, setError, authProxyUrl]
|
|
7701
7721
|
);
|
|
7702
|
-
const login =
|
|
7722
|
+
const login = React.useCallback(
|
|
7703
7723
|
async (data) => {
|
|
7704
7724
|
setError(null);
|
|
7705
7725
|
if (authProxyUrl) {
|
|
@@ -7750,7 +7770,7 @@ function useAuth() {
|
|
|
7750
7770
|
},
|
|
7751
7771
|
[client, setUser, setError, authProxyUrl]
|
|
7752
7772
|
);
|
|
7753
|
-
const logout =
|
|
7773
|
+
const logout = React.useCallback(async () => {
|
|
7754
7774
|
setError(null);
|
|
7755
7775
|
if (authProxyUrl) {
|
|
7756
7776
|
try {
|
|
@@ -7770,7 +7790,7 @@ function useAuth() {
|
|
|
7770
7790
|
await client.clearSession();
|
|
7771
7791
|
setUser(null);
|
|
7772
7792
|
}, [client, setUser, setError, authProxyUrl]);
|
|
7773
|
-
const forgotPassword =
|
|
7793
|
+
const forgotPassword = React.useCallback(
|
|
7774
7794
|
async (email) => {
|
|
7775
7795
|
setError(null);
|
|
7776
7796
|
if (authProxyUrl) {
|
|
@@ -7796,7 +7816,7 @@ function useAuth() {
|
|
|
7796
7816
|
},
|
|
7797
7817
|
[client, setError, authProxyUrl]
|
|
7798
7818
|
);
|
|
7799
|
-
const resetPassword =
|
|
7819
|
+
const resetPassword = React.useCallback(
|
|
7800
7820
|
async (token, newPassword) => {
|
|
7801
7821
|
setError(null);
|
|
7802
7822
|
if (authProxyUrl) {
|
|
@@ -7822,7 +7842,7 @@ function useAuth() {
|
|
|
7822
7842
|
},
|
|
7823
7843
|
[client, setError, authProxyUrl]
|
|
7824
7844
|
);
|
|
7825
|
-
const verifyEmail =
|
|
7845
|
+
const verifyEmail = React.useCallback(
|
|
7826
7846
|
async (token) => {
|
|
7827
7847
|
setError(null);
|
|
7828
7848
|
if (authProxyUrl) {
|
|
@@ -7871,7 +7891,7 @@ function useAuth() {
|
|
|
7871
7891
|
},
|
|
7872
7892
|
[client, setUser, setError, authProxyUrl]
|
|
7873
7893
|
);
|
|
7874
|
-
const resendVerification =
|
|
7894
|
+
const resendVerification = React.useCallback(async (email) => {
|
|
7875
7895
|
setError(null);
|
|
7876
7896
|
if (authProxyUrl) {
|
|
7877
7897
|
const body = email ? { email } : user ? {} : void 0;
|
|
@@ -7906,7 +7926,7 @@ function useAuth() {
|
|
|
7906
7926
|
}
|
|
7907
7927
|
}
|
|
7908
7928
|
}, [client, user, setError, authProxyUrl]);
|
|
7909
|
-
const refreshSession =
|
|
7929
|
+
const refreshSession = React.useCallback(async () => {
|
|
7910
7930
|
setError(null);
|
|
7911
7931
|
if (authProxyUrl) {
|
|
7912
7932
|
const response = await proxyFetch(
|
|
@@ -7954,7 +7974,7 @@ function useAuth() {
|
|
|
7954
7974
|
throw err;
|
|
7955
7975
|
}
|
|
7956
7976
|
}, [client, setUser, setError, authProxyUrl]);
|
|
7957
|
-
const startOAuth =
|
|
7977
|
+
const startOAuth = React.useCallback(
|
|
7958
7978
|
async (config) => {
|
|
7959
7979
|
setError(null);
|
|
7960
7980
|
let oauthData;
|
|
@@ -7978,7 +7998,7 @@ function useAuth() {
|
|
|
7978
7998
|
},
|
|
7979
7999
|
[client, setError]
|
|
7980
8000
|
);
|
|
7981
|
-
const completeOAuth =
|
|
8001
|
+
const completeOAuth = React.useCallback(
|
|
7982
8002
|
async (request) => {
|
|
7983
8003
|
setError(null);
|
|
7984
8004
|
if (typeof sessionStorage !== "undefined") {
|
|
@@ -8008,7 +8028,7 @@ function useAuth() {
|
|
|
8008
8028
|
},
|
|
8009
8029
|
[client, setUser, setError]
|
|
8010
8030
|
);
|
|
8011
|
-
const getLinkedAccounts =
|
|
8031
|
+
const getLinkedAccounts = React.useCallback(async () => {
|
|
8012
8032
|
setError(null);
|
|
8013
8033
|
try {
|
|
8014
8034
|
const data = await client.get("/v1/auth/oauth/accounts");
|
|
@@ -8020,7 +8040,7 @@ function useAuth() {
|
|
|
8020
8040
|
throw err;
|
|
8021
8041
|
}
|
|
8022
8042
|
}, [client, setError]);
|
|
8023
|
-
const linkAccount =
|
|
8043
|
+
const linkAccount = React.useCallback(
|
|
8024
8044
|
async (config) => {
|
|
8025
8045
|
setError(null);
|
|
8026
8046
|
if (!user) {
|
|
@@ -8051,7 +8071,7 @@ function useAuth() {
|
|
|
8051
8071
|
},
|
|
8052
8072
|
[client, user, setError]
|
|
8053
8073
|
);
|
|
8054
|
-
const unlinkAccount =
|
|
8074
|
+
const unlinkAccount = React.useCallback(
|
|
8055
8075
|
async (provider) => {
|
|
8056
8076
|
setError(null);
|
|
8057
8077
|
try {
|
|
@@ -8065,7 +8085,7 @@ function useAuth() {
|
|
|
8065
8085
|
},
|
|
8066
8086
|
[client, setError]
|
|
8067
8087
|
);
|
|
8068
|
-
const getMFAStatus =
|
|
8088
|
+
const getMFAStatus = React.useCallback(async () => {
|
|
8069
8089
|
setError(null);
|
|
8070
8090
|
try {
|
|
8071
8091
|
return await client.get("/v1/auth/mfa/status");
|
|
@@ -8076,7 +8096,7 @@ function useAuth() {
|
|
|
8076
8096
|
throw err;
|
|
8077
8097
|
}
|
|
8078
8098
|
}, [client, setError]);
|
|
8079
|
-
const setupMFA =
|
|
8099
|
+
const setupMFA = React.useCallback(
|
|
8080
8100
|
async (request) => {
|
|
8081
8101
|
setError(null);
|
|
8082
8102
|
try {
|
|
@@ -8093,7 +8113,7 @@ function useAuth() {
|
|
|
8093
8113
|
},
|
|
8094
8114
|
[client, setError]
|
|
8095
8115
|
);
|
|
8096
|
-
const verifyMFA =
|
|
8116
|
+
const verifyMFA = React.useCallback(
|
|
8097
8117
|
async (request) => {
|
|
8098
8118
|
setError(null);
|
|
8099
8119
|
try {
|
|
@@ -8107,7 +8127,7 @@ function useAuth() {
|
|
|
8107
8127
|
},
|
|
8108
8128
|
[client, setError]
|
|
8109
8129
|
);
|
|
8110
|
-
const completeMFAChallenge =
|
|
8130
|
+
const completeMFAChallenge = React.useCallback(
|
|
8111
8131
|
async (challengeToken, code, method) => {
|
|
8112
8132
|
setError(null);
|
|
8113
8133
|
let mfaResult;
|
|
@@ -8129,7 +8149,7 @@ function useAuth() {
|
|
|
8129
8149
|
},
|
|
8130
8150
|
[client, setUser, setError]
|
|
8131
8151
|
);
|
|
8132
|
-
const disableMFA =
|
|
8152
|
+
const disableMFA = React.useCallback(
|
|
8133
8153
|
async (password) => {
|
|
8134
8154
|
setError(null);
|
|
8135
8155
|
try {
|
|
@@ -8143,7 +8163,7 @@ function useAuth() {
|
|
|
8143
8163
|
},
|
|
8144
8164
|
[client, setError]
|
|
8145
8165
|
);
|
|
8146
|
-
const regenerateBackupCodes =
|
|
8166
|
+
const regenerateBackupCodes = React.useCallback(
|
|
8147
8167
|
async (password) => {
|
|
8148
8168
|
setError(null);
|
|
8149
8169
|
try {
|
|
@@ -8160,7 +8180,7 @@ function useAuth() {
|
|
|
8160
8180
|
},
|
|
8161
8181
|
[client, setError]
|
|
8162
8182
|
);
|
|
8163
|
-
const sendPhoneCode =
|
|
8183
|
+
const sendPhoneCode = React.useCallback(
|
|
8164
8184
|
async (request) => {
|
|
8165
8185
|
setError(null);
|
|
8166
8186
|
if (authProxyUrl) {
|
|
@@ -8186,7 +8206,7 @@ function useAuth() {
|
|
|
8186
8206
|
},
|
|
8187
8207
|
[client, setError, authProxyUrl]
|
|
8188
8208
|
);
|
|
8189
|
-
const verifyPhone =
|
|
8209
|
+
const verifyPhone = React.useCallback(
|
|
8190
8210
|
async (request) => {
|
|
8191
8211
|
setError(null);
|
|
8192
8212
|
if (authProxyUrl) {
|
|
@@ -8226,7 +8246,7 @@ function useAuth() {
|
|
|
8226
8246
|
},
|
|
8227
8247
|
[client, user, setUser, setError, authProxyUrl]
|
|
8228
8248
|
);
|
|
8229
|
-
const loginWithPhone =
|
|
8249
|
+
const loginWithPhone = React.useCallback(
|
|
8230
8250
|
async (request) => {
|
|
8231
8251
|
setError(null);
|
|
8232
8252
|
if (authProxyUrl) {
|
|
@@ -8270,7 +8290,7 @@ function useAuth() {
|
|
|
8270
8290
|
},
|
|
8271
8291
|
[client, setUser, setError, authProxyUrl]
|
|
8272
8292
|
);
|
|
8273
|
-
const readKnownAccountsCookie =
|
|
8293
|
+
const readKnownAccountsCookie = React.useCallback(() => {
|
|
8274
8294
|
if (!enableAccountSwitcher) return [];
|
|
8275
8295
|
if (typeof document === "undefined") return [];
|
|
8276
8296
|
const match = document.cookie.match(/(?:^|; )sm_known_accounts=([^;]*)/);
|
|
@@ -8287,11 +8307,11 @@ function useAuth() {
|
|
|
8287
8307
|
return [];
|
|
8288
8308
|
}
|
|
8289
8309
|
}, [enableAccountSwitcher, accountSwitcherPrivacy]);
|
|
8290
|
-
const [knownAccounts, setKnownAccounts] =
|
|
8291
|
-
|
|
8310
|
+
const [knownAccounts, setKnownAccounts] = React.useState([]);
|
|
8311
|
+
React.useEffect(() => {
|
|
8292
8312
|
setKnownAccounts(readKnownAccountsCookie());
|
|
8293
8313
|
}, [readKnownAccountsCookie, user]);
|
|
8294
|
-
const switchAccount =
|
|
8314
|
+
const switchAccount = React.useCallback(
|
|
8295
8315
|
async (userId) => {
|
|
8296
8316
|
const target = knownAccounts.find((a) => a.userId === userId) || null;
|
|
8297
8317
|
if (!target) return null;
|
|
@@ -8312,7 +8332,7 @@ function useAuth() {
|
|
|
8312
8332
|
},
|
|
8313
8333
|
[client, setUser, knownAccounts, authProxyUrl]
|
|
8314
8334
|
);
|
|
8315
|
-
const removeKnownAccount =
|
|
8335
|
+
const removeKnownAccount = React.useCallback(
|
|
8316
8336
|
async (userId) => {
|
|
8317
8337
|
if (authProxyUrl) {
|
|
8318
8338
|
await proxyFetch(authProxyUrl, "forget-account", { body: { user_id: userId } });
|
|
@@ -8321,13 +8341,13 @@ function useAuth() {
|
|
|
8321
8341
|
},
|
|
8322
8342
|
[authProxyUrl]
|
|
8323
8343
|
);
|
|
8324
|
-
const clearKnownAccounts =
|
|
8344
|
+
const clearKnownAccounts = React.useCallback(async () => {
|
|
8325
8345
|
if (authProxyUrl) {
|
|
8326
8346
|
await proxyFetch(authProxyUrl, "forget-all-accounts");
|
|
8327
8347
|
}
|
|
8328
8348
|
setKnownAccounts([]);
|
|
8329
8349
|
}, [authProxyUrl]);
|
|
8330
|
-
return
|
|
8350
|
+
return React.useMemo(
|
|
8331
8351
|
() => ({
|
|
8332
8352
|
user,
|
|
8333
8353
|
loading: initializing,
|
|
@@ -8406,9 +8426,9 @@ function retiredBillingRouteError(route) {
|
|
|
8406
8426
|
}
|
|
8407
8427
|
function useBilling() {
|
|
8408
8428
|
const { client } = useScaleMule();
|
|
8409
|
-
const [loading, setLoading] =
|
|
8410
|
-
const [error, setError] =
|
|
8411
|
-
const createConnectedAccount =
|
|
8429
|
+
const [loading, setLoading] = React.useState(false);
|
|
8430
|
+
const [error, setError] = React.useState(null);
|
|
8431
|
+
const createConnectedAccount = React.useCallback(
|
|
8412
8432
|
async (data) => {
|
|
8413
8433
|
setError(null);
|
|
8414
8434
|
setLoading(true);
|
|
@@ -8424,7 +8444,7 @@ function useBilling() {
|
|
|
8424
8444
|
},
|
|
8425
8445
|
[client]
|
|
8426
8446
|
);
|
|
8427
|
-
const getMyConnectedAccount =
|
|
8447
|
+
const getMyConnectedAccount = React.useCallback(async () => {
|
|
8428
8448
|
setError(null);
|
|
8429
8449
|
setLoading(true);
|
|
8430
8450
|
try {
|
|
@@ -8437,7 +8457,7 @@ function useBilling() {
|
|
|
8437
8457
|
setLoading(false);
|
|
8438
8458
|
}
|
|
8439
8459
|
}, [client]);
|
|
8440
|
-
const getConnectedAccount =
|
|
8460
|
+
const getConnectedAccount = React.useCallback(
|
|
8441
8461
|
async (id) => {
|
|
8442
8462
|
setError(null);
|
|
8443
8463
|
setLoading(true);
|
|
@@ -8453,7 +8473,7 @@ function useBilling() {
|
|
|
8453
8473
|
},
|
|
8454
8474
|
[client]
|
|
8455
8475
|
);
|
|
8456
|
-
const createOnboardingLink =
|
|
8476
|
+
const createOnboardingLink = React.useCallback(
|
|
8457
8477
|
async (id, data) => {
|
|
8458
8478
|
setError(null);
|
|
8459
8479
|
setLoading(true);
|
|
@@ -8473,7 +8493,7 @@ function useBilling() {
|
|
|
8473
8493
|
},
|
|
8474
8494
|
[client]
|
|
8475
8495
|
);
|
|
8476
|
-
const getAccountBalance =
|
|
8496
|
+
const getAccountBalance = React.useCallback(
|
|
8477
8497
|
async (id) => {
|
|
8478
8498
|
setError(null);
|
|
8479
8499
|
setLoading(true);
|
|
@@ -8487,7 +8507,7 @@ function useBilling() {
|
|
|
8487
8507
|
},
|
|
8488
8508
|
[client]
|
|
8489
8509
|
);
|
|
8490
|
-
const createPayment =
|
|
8510
|
+
const createPayment = React.useCallback(
|
|
8491
8511
|
async (data) => {
|
|
8492
8512
|
setError(null);
|
|
8493
8513
|
setLoading(true);
|
|
@@ -8502,7 +8522,7 @@ function useBilling() {
|
|
|
8502
8522
|
},
|
|
8503
8523
|
[client]
|
|
8504
8524
|
);
|
|
8505
|
-
const getPayment =
|
|
8525
|
+
const getPayment = React.useCallback(
|
|
8506
8526
|
async (id) => {
|
|
8507
8527
|
setError(null);
|
|
8508
8528
|
setLoading(true);
|
|
@@ -8516,7 +8536,7 @@ function useBilling() {
|
|
|
8516
8536
|
},
|
|
8517
8537
|
[client]
|
|
8518
8538
|
);
|
|
8519
|
-
const listPayments =
|
|
8539
|
+
const listPayments = React.useCallback(
|
|
8520
8540
|
async (params) => {
|
|
8521
8541
|
setError(null);
|
|
8522
8542
|
setLoading(true);
|
|
@@ -8531,7 +8551,7 @@ function useBilling() {
|
|
|
8531
8551
|
},
|
|
8532
8552
|
[client]
|
|
8533
8553
|
);
|
|
8534
|
-
const refundPayment =
|
|
8554
|
+
const refundPayment = React.useCallback(
|
|
8535
8555
|
async (id, data) => {
|
|
8536
8556
|
setError(null);
|
|
8537
8557
|
setLoading(true);
|
|
@@ -8546,7 +8566,7 @@ function useBilling() {
|
|
|
8546
8566
|
},
|
|
8547
8567
|
[client]
|
|
8548
8568
|
);
|
|
8549
|
-
const getPayoutHistory =
|
|
8569
|
+
const getPayoutHistory = React.useCallback(
|
|
8550
8570
|
async (accountId, params) => {
|
|
8551
8571
|
setError(null);
|
|
8552
8572
|
setLoading(true);
|
|
@@ -8561,7 +8581,7 @@ function useBilling() {
|
|
|
8561
8581
|
},
|
|
8562
8582
|
[client]
|
|
8563
8583
|
);
|
|
8564
|
-
const getPayoutSchedule =
|
|
8584
|
+
const getPayoutSchedule = React.useCallback(
|
|
8565
8585
|
async (accountId) => {
|
|
8566
8586
|
setError(null);
|
|
8567
8587
|
setLoading(true);
|
|
@@ -8579,7 +8599,7 @@ function useBilling() {
|
|
|
8579
8599
|
},
|
|
8580
8600
|
[client]
|
|
8581
8601
|
);
|
|
8582
|
-
const setPayoutSchedule =
|
|
8602
|
+
const setPayoutSchedule = React.useCallback(
|
|
8583
8603
|
async (accountId, data) => {
|
|
8584
8604
|
setError(null);
|
|
8585
8605
|
setLoading(true);
|
|
@@ -8598,7 +8618,7 @@ function useBilling() {
|
|
|
8598
8618
|
},
|
|
8599
8619
|
[client]
|
|
8600
8620
|
);
|
|
8601
|
-
const getTransactions =
|
|
8621
|
+
const getTransactions = React.useCallback(
|
|
8602
8622
|
async (params) => {
|
|
8603
8623
|
setError(null);
|
|
8604
8624
|
setLoading(true);
|
|
@@ -8613,7 +8633,7 @@ function useBilling() {
|
|
|
8613
8633
|
},
|
|
8614
8634
|
[client]
|
|
8615
8635
|
);
|
|
8616
|
-
const getTransactionSummary =
|
|
8636
|
+
const getTransactionSummary = React.useCallback(
|
|
8617
8637
|
async (params) => {
|
|
8618
8638
|
setError(null);
|
|
8619
8639
|
setLoading(true);
|
|
@@ -8628,7 +8648,7 @@ function useBilling() {
|
|
|
8628
8648
|
},
|
|
8629
8649
|
[client]
|
|
8630
8650
|
);
|
|
8631
|
-
const createSetupSession =
|
|
8651
|
+
const createSetupSession = React.useCallback(
|
|
8632
8652
|
async (data) => {
|
|
8633
8653
|
setError(null);
|
|
8634
8654
|
setLoading(true);
|
|
@@ -8648,7 +8668,7 @@ function useBilling() {
|
|
|
8648
8668
|
},
|
|
8649
8669
|
[client]
|
|
8650
8670
|
);
|
|
8651
|
-
return
|
|
8671
|
+
return React.useMemo(
|
|
8652
8672
|
() => ({
|
|
8653
8673
|
loading,
|
|
8654
8674
|
error,
|
|
@@ -8692,11 +8712,11 @@ function useBilling() {
|
|
|
8692
8712
|
function useContent(options = {}) {
|
|
8693
8713
|
const { autoFetch = false, initialParams } = options;
|
|
8694
8714
|
const { client, user, setError } = useScaleMule();
|
|
8695
|
-
const [files, setFiles] =
|
|
8696
|
-
const [loading, setLoading] =
|
|
8697
|
-
const [uploadProgress, setUploadProgress] =
|
|
8698
|
-
const [error, setLocalError] =
|
|
8699
|
-
const list =
|
|
8715
|
+
const [files, setFiles] = React.useState([]);
|
|
8716
|
+
const [loading, setLoading] = React.useState(false);
|
|
8717
|
+
const [uploadProgress, setUploadProgress] = React.useState(null);
|
|
8718
|
+
const [error, setLocalError] = React.useState(null);
|
|
8719
|
+
const list = React.useCallback(
|
|
8700
8720
|
async (params) => {
|
|
8701
8721
|
setLocalError(null);
|
|
8702
8722
|
setLoading(true);
|
|
@@ -8718,7 +8738,7 @@ function useContent(options = {}) {
|
|
|
8718
8738
|
},
|
|
8719
8739
|
[client, initialParams]
|
|
8720
8740
|
);
|
|
8721
|
-
const upload =
|
|
8741
|
+
const upload = React.useCallback(
|
|
8722
8742
|
async (file, options2) => {
|
|
8723
8743
|
setLocalError(null);
|
|
8724
8744
|
setLoading(true);
|
|
@@ -8753,7 +8773,7 @@ function useContent(options = {}) {
|
|
|
8753
8773
|
},
|
|
8754
8774
|
[client, list]
|
|
8755
8775
|
);
|
|
8756
|
-
const remove =
|
|
8776
|
+
const remove = React.useCallback(
|
|
8757
8777
|
async (fileId) => {
|
|
8758
8778
|
setLocalError(null);
|
|
8759
8779
|
setLoading(true);
|
|
@@ -8766,24 +8786,24 @@ function useContent(options = {}) {
|
|
|
8766
8786
|
},
|
|
8767
8787
|
[client]
|
|
8768
8788
|
);
|
|
8769
|
-
const get =
|
|
8789
|
+
const get = React.useCallback(
|
|
8770
8790
|
async (fileId) => {
|
|
8771
8791
|
setLocalError(null);
|
|
8772
8792
|
return await client.get(`/v1/storage/files/${fileId}/info`);
|
|
8773
8793
|
},
|
|
8774
8794
|
[client]
|
|
8775
8795
|
);
|
|
8776
|
-
const refresh =
|
|
8796
|
+
const refresh = React.useCallback(async () => {
|
|
8777
8797
|
await list(initialParams);
|
|
8778
8798
|
}, [list, initialParams]);
|
|
8779
|
-
const getSignedUploadUrl =
|
|
8799
|
+
const getSignedUploadUrl = React.useCallback(
|
|
8780
8800
|
async (request) => {
|
|
8781
8801
|
setLocalError(null);
|
|
8782
8802
|
return await client.post("/v1/storage/signed-upload", request);
|
|
8783
8803
|
},
|
|
8784
8804
|
[client]
|
|
8785
8805
|
);
|
|
8786
|
-
const uploadToSignedUrl =
|
|
8806
|
+
const uploadToSignedUrl = React.useCallback(
|
|
8787
8807
|
async (signedUrl, file, headers, onProgress) => {
|
|
8788
8808
|
setLocalError(null);
|
|
8789
8809
|
setLoading(true);
|
|
@@ -8831,7 +8851,7 @@ function useContent(options = {}) {
|
|
|
8831
8851
|
},
|
|
8832
8852
|
[]
|
|
8833
8853
|
);
|
|
8834
|
-
const completeSignedUpload =
|
|
8854
|
+
const completeSignedUpload = React.useCallback(
|
|
8835
8855
|
async (fileId) => {
|
|
8836
8856
|
setLocalError(null);
|
|
8837
8857
|
const data = await client.post(`/v1/storage/signed-upload/${fileId}/complete`);
|
|
@@ -8840,12 +8860,12 @@ function useContent(options = {}) {
|
|
|
8840
8860
|
},
|
|
8841
8861
|
[client, list]
|
|
8842
8862
|
);
|
|
8843
|
-
|
|
8863
|
+
React.useEffect(() => {
|
|
8844
8864
|
if (autoFetch && user) {
|
|
8845
8865
|
list(initialParams);
|
|
8846
8866
|
}
|
|
8847
8867
|
}, [autoFetch, user, list, initialParams]);
|
|
8848
|
-
return
|
|
8868
|
+
return React.useMemo(
|
|
8849
8869
|
() => ({
|
|
8850
8870
|
files,
|
|
8851
8871
|
loading,
|
|
@@ -8878,9 +8898,9 @@ function useContent(options = {}) {
|
|
|
8878
8898
|
}
|
|
8879
8899
|
function useMedia() {
|
|
8880
8900
|
const { storage, photo, video } = useScaleMule();
|
|
8881
|
-
const [uploading, setUploading] =
|
|
8882
|
-
const [error, setError] =
|
|
8883
|
-
const upload =
|
|
8901
|
+
const [uploading, setUploading] = React.useState(false);
|
|
8902
|
+
const [error, setError] = React.useState(null);
|
|
8903
|
+
const upload = React.useCallback(
|
|
8884
8904
|
async (file, options) => {
|
|
8885
8905
|
setUploading(true);
|
|
8886
8906
|
setError(null);
|
|
@@ -8967,7 +8987,7 @@ function useMedia() {
|
|
|
8967
8987
|
},
|
|
8968
8988
|
[storage, photo]
|
|
8969
8989
|
);
|
|
8970
|
-
const cancelUpload =
|
|
8990
|
+
const cancelUpload = React.useCallback(
|
|
8971
8991
|
async (fileId) => {
|
|
8972
8992
|
setError(null);
|
|
8973
8993
|
try {
|
|
@@ -8989,11 +9009,11 @@ function useMedia() {
|
|
|
8989
9009
|
function useFileStatus(options) {
|
|
8990
9010
|
const { storage } = useScaleMule();
|
|
8991
9011
|
const { fileId, pollIntervalMs = null, disabled = false } = options;
|
|
8992
|
-
const [status, setStatus] =
|
|
8993
|
-
const [loading, setLoading] =
|
|
8994
|
-
const [error, setError] =
|
|
8995
|
-
const requestSeqRef =
|
|
8996
|
-
const fetchStatus =
|
|
9012
|
+
const [status, setStatus] = React.useState(null);
|
|
9013
|
+
const [loading, setLoading] = React.useState(false);
|
|
9014
|
+
const [error, setError] = React.useState(null);
|
|
9015
|
+
const requestSeqRef = React.useRef(0);
|
|
9016
|
+
const fetchStatus = React.useCallback(async () => {
|
|
8997
9017
|
if (!fileId || disabled) return;
|
|
8998
9018
|
const seq = ++requestSeqRef.current;
|
|
8999
9019
|
setLoading(true);
|
|
@@ -9015,10 +9035,10 @@ function useFileStatus(options) {
|
|
|
9015
9035
|
}
|
|
9016
9036
|
}
|
|
9017
9037
|
}, [storage, fileId, disabled]);
|
|
9018
|
-
|
|
9038
|
+
React.useEffect(() => {
|
|
9019
9039
|
void fetchStatus();
|
|
9020
9040
|
}, [fetchStatus]);
|
|
9021
|
-
|
|
9041
|
+
React.useEffect(() => {
|
|
9022
9042
|
if (!pollIntervalMs || disabled || !fileId) return;
|
|
9023
9043
|
const isClean = status?.scan.status === "clean";
|
|
9024
9044
|
if (isClean) return;
|
|
@@ -9030,14 +9050,184 @@ function useFileStatus(options) {
|
|
|
9030
9050
|
const isReady = status?.scan.status === "clean";
|
|
9031
9051
|
return { status, loading, error, isReady, refresh: fetchStatus };
|
|
9032
9052
|
}
|
|
9053
|
+
function ScaleMuleMedia(props) {
|
|
9054
|
+
const {
|
|
9055
|
+
fileId,
|
|
9056
|
+
mimeType,
|
|
9057
|
+
blobPreview,
|
|
9058
|
+
width,
|
|
9059
|
+
height,
|
|
9060
|
+
className,
|
|
9061
|
+
style,
|
|
9062
|
+
alt,
|
|
9063
|
+
pollIntervalMs = 2e3,
|
|
9064
|
+
renderPlaceholder,
|
|
9065
|
+
renderBlocked,
|
|
9066
|
+
renderOverride
|
|
9067
|
+
} = props;
|
|
9068
|
+
const { status, isReady } = useFileStatus({ fileId, pollIntervalMs });
|
|
9069
|
+
const isImage = mimeType.startsWith("image/");
|
|
9070
|
+
const isVideo = mimeType.startsWith("video/");
|
|
9071
|
+
const isAudio = mimeType.startsWith("audio/");
|
|
9072
|
+
const src = React.useMemo(() => {
|
|
9073
|
+
const scan = status?.scan.status;
|
|
9074
|
+
if (scan === "threat" || scan === "quarantined") return null;
|
|
9075
|
+
if (status && isReady) {
|
|
9076
|
+
if (isImage && status.urls.optimized) return status.urls.optimized;
|
|
9077
|
+
if (isVideo && status.urls.hls) return status.urls.hls;
|
|
9078
|
+
return status.urls.original ?? null;
|
|
9079
|
+
}
|
|
9080
|
+
if (blobPreview) return blobPreview;
|
|
9081
|
+
return null;
|
|
9082
|
+
}, [status, isReady, isImage, isVideo, blobPreview]);
|
|
9083
|
+
const renderState = React.useMemo(() => {
|
|
9084
|
+
const scan = status?.scan.status;
|
|
9085
|
+
if (scan === "threat" || scan === "quarantined") return "blocked";
|
|
9086
|
+
if (isReady) return "ready";
|
|
9087
|
+
if (blobPreview) return "preview";
|
|
9088
|
+
return "pending";
|
|
9089
|
+
}, [status?.scan.status, isReady, blobPreview]);
|
|
9090
|
+
const videoRef = React__namespace.useRef(null);
|
|
9091
|
+
React.useEffect(() => {
|
|
9092
|
+
if (!isVideo) return;
|
|
9093
|
+
if (!src) return;
|
|
9094
|
+
if (!src.endsWith(".m3u8")) return;
|
|
9095
|
+
const el = videoRef.current;
|
|
9096
|
+
if (!el) return;
|
|
9097
|
+
if (el.canPlayType("application/vnd.apple.mpegurl")) {
|
|
9098
|
+
el.src = src;
|
|
9099
|
+
return;
|
|
9100
|
+
}
|
|
9101
|
+
let cancelled = false;
|
|
9102
|
+
let hls = null;
|
|
9103
|
+
void (async () => {
|
|
9104
|
+
try {
|
|
9105
|
+
const moduleName = "hls.js";
|
|
9106
|
+
const mod = await import(
|
|
9107
|
+
/* @vite-ignore */
|
|
9108
|
+
/* webpackIgnore: true */
|
|
9109
|
+
moduleName
|
|
9110
|
+
).catch(
|
|
9111
|
+
() => null
|
|
9112
|
+
);
|
|
9113
|
+
if (cancelled || !mod) return;
|
|
9114
|
+
const Hls = mod.default ?? mod;
|
|
9115
|
+
if (Hls.isSupported()) {
|
|
9116
|
+
hls = new Hls();
|
|
9117
|
+
hls.loadSource(src);
|
|
9118
|
+
hls.attachMedia(el);
|
|
9119
|
+
} else {
|
|
9120
|
+
el.src = src;
|
|
9121
|
+
}
|
|
9122
|
+
} catch {
|
|
9123
|
+
}
|
|
9124
|
+
})();
|
|
9125
|
+
return () => {
|
|
9126
|
+
cancelled = true;
|
|
9127
|
+
if (hls) hls.destroy();
|
|
9128
|
+
};
|
|
9129
|
+
}, [isVideo, src]);
|
|
9130
|
+
if (renderOverride) {
|
|
9131
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderOverride({ src, state: renderState }) });
|
|
9132
|
+
}
|
|
9133
|
+
if (renderState === "blocked") {
|
|
9134
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderBlocked ? renderBlocked() : /* @__PURE__ */ jsxRuntime.jsx(
|
|
9135
|
+
"div",
|
|
9136
|
+
{
|
|
9137
|
+
role: "alert",
|
|
9138
|
+
className,
|
|
9139
|
+
style: { padding: 12, color: "#a00", ...style },
|
|
9140
|
+
children: "This file was blocked."
|
|
9141
|
+
}
|
|
9142
|
+
) });
|
|
9143
|
+
}
|
|
9144
|
+
if (renderState === "pending" && !src) {
|
|
9145
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderPlaceholder ? renderPlaceholder() : /* @__PURE__ */ jsxRuntime.jsx(
|
|
9146
|
+
"div",
|
|
9147
|
+
{
|
|
9148
|
+
role: "status",
|
|
9149
|
+
"aria-busy": true,
|
|
9150
|
+
className,
|
|
9151
|
+
style: { padding: 12, color: "#666", ...style },
|
|
9152
|
+
children: "Loading\u2026"
|
|
9153
|
+
}
|
|
9154
|
+
) });
|
|
9155
|
+
}
|
|
9156
|
+
if (isImage) {
|
|
9157
|
+
const finalSrc = src && status?.urls.optimized && (width || height) ? appendQuery(src, {
|
|
9158
|
+
width: width ? String(width) : void 0,
|
|
9159
|
+
height: height ? String(height) : void 0,
|
|
9160
|
+
fit: "cover"
|
|
9161
|
+
}) : src;
|
|
9162
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9163
|
+
"img",
|
|
9164
|
+
{
|
|
9165
|
+
src: finalSrc ?? void 0,
|
|
9166
|
+
alt: alt ?? "",
|
|
9167
|
+
width,
|
|
9168
|
+
height,
|
|
9169
|
+
className,
|
|
9170
|
+
style
|
|
9171
|
+
}
|
|
9172
|
+
);
|
|
9173
|
+
}
|
|
9174
|
+
if (isVideo) {
|
|
9175
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9176
|
+
"video",
|
|
9177
|
+
{
|
|
9178
|
+
ref: videoRef,
|
|
9179
|
+
src: src && !src.endsWith(".m3u8") ? src : void 0,
|
|
9180
|
+
controls: true,
|
|
9181
|
+
playsInline: true,
|
|
9182
|
+
preload: "metadata",
|
|
9183
|
+
className,
|
|
9184
|
+
style,
|
|
9185
|
+
"aria-label": alt,
|
|
9186
|
+
width,
|
|
9187
|
+
height
|
|
9188
|
+
}
|
|
9189
|
+
);
|
|
9190
|
+
}
|
|
9191
|
+
if (isAudio) {
|
|
9192
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9193
|
+
"audio",
|
|
9194
|
+
{
|
|
9195
|
+
src: src ?? void 0,
|
|
9196
|
+
controls: true,
|
|
9197
|
+
preload: "metadata",
|
|
9198
|
+
className,
|
|
9199
|
+
style,
|
|
9200
|
+
"aria-label": alt
|
|
9201
|
+
}
|
|
9202
|
+
);
|
|
9203
|
+
}
|
|
9204
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9205
|
+
"a",
|
|
9206
|
+
{
|
|
9207
|
+
href: src ?? "#",
|
|
9208
|
+
target: "_blank",
|
|
9209
|
+
rel: "noopener noreferrer",
|
|
9210
|
+
className,
|
|
9211
|
+
style,
|
|
9212
|
+
children: alt ?? "Download file"
|
|
9213
|
+
}
|
|
9214
|
+
);
|
|
9215
|
+
}
|
|
9216
|
+
function appendQuery(url, params) {
|
|
9217
|
+
const filtered = Object.entries(params).filter(([, v]) => v != null && v !== "");
|
|
9218
|
+
if (filtered.length === 0) return url;
|
|
9219
|
+
const sep = url.includes("?") ? "&" : "?";
|
|
9220
|
+
const qs = new URLSearchParams(filtered).toString();
|
|
9221
|
+
return url + sep + qs;
|
|
9222
|
+
}
|
|
9033
9223
|
|
|
9034
9224
|
// src/hooks/useMoney.ts
|
|
9035
9225
|
var useMoney = useMoneyClient;
|
|
9036
9226
|
function useUser() {
|
|
9037
9227
|
const { client, user, setUser, setError } = useScaleMule();
|
|
9038
|
-
const [loading, setLoading] =
|
|
9039
|
-
const [localError, setLocalError] =
|
|
9040
|
-
const update =
|
|
9228
|
+
const [loading, setLoading] = React.useState(false);
|
|
9229
|
+
const [localError, setLocalError] = React.useState(null);
|
|
9230
|
+
const update = React.useCallback(
|
|
9041
9231
|
async (data) => {
|
|
9042
9232
|
setLocalError(null);
|
|
9043
9233
|
setLoading(true);
|
|
@@ -9051,7 +9241,7 @@ function useUser() {
|
|
|
9051
9241
|
},
|
|
9052
9242
|
[client, setUser]
|
|
9053
9243
|
);
|
|
9054
|
-
const changePassword =
|
|
9244
|
+
const changePassword = React.useCallback(
|
|
9055
9245
|
async (currentPassword, newPassword) => {
|
|
9056
9246
|
setLocalError(null);
|
|
9057
9247
|
setLoading(true);
|
|
@@ -9066,7 +9256,7 @@ function useUser() {
|
|
|
9066
9256
|
},
|
|
9067
9257
|
[client]
|
|
9068
9258
|
);
|
|
9069
|
-
const changeEmail =
|
|
9259
|
+
const changeEmail = React.useCallback(
|
|
9070
9260
|
async (newEmail, password) => {
|
|
9071
9261
|
setLocalError(null);
|
|
9072
9262
|
setLoading(true);
|
|
@@ -9081,7 +9271,7 @@ function useUser() {
|
|
|
9081
9271
|
},
|
|
9082
9272
|
[client]
|
|
9083
9273
|
);
|
|
9084
|
-
const deleteAccount =
|
|
9274
|
+
const deleteAccount = React.useCallback(
|
|
9085
9275
|
async (password) => {
|
|
9086
9276
|
setLocalError(null);
|
|
9087
9277
|
setLoading(true);
|
|
@@ -9097,7 +9287,7 @@ function useUser() {
|
|
|
9097
9287
|
},
|
|
9098
9288
|
[client, setUser]
|
|
9099
9289
|
);
|
|
9100
|
-
const exportData =
|
|
9290
|
+
const exportData = React.useCallback(async () => {
|
|
9101
9291
|
setLocalError(null);
|
|
9102
9292
|
setLoading(true);
|
|
9103
9293
|
try {
|
|
@@ -9108,7 +9298,7 @@ function useUser() {
|
|
|
9108
9298
|
setLoading(false);
|
|
9109
9299
|
}
|
|
9110
9300
|
}, [client]);
|
|
9111
|
-
return
|
|
9301
|
+
return React.useMemo(
|
|
9112
9302
|
() => ({
|
|
9113
9303
|
profile: user,
|
|
9114
9304
|
loading,
|
|
@@ -9124,19 +9314,19 @@ function useUser() {
|
|
|
9124
9314
|
}
|
|
9125
9315
|
function useRealtime(options) {
|
|
9126
9316
|
const { realtime } = useScaleMule();
|
|
9127
|
-
const [status, setStatus] =
|
|
9128
|
-
const [lastMessage, setLastMessage] =
|
|
9129
|
-
const manualUnsubscribesRef =
|
|
9130
|
-
const autoUnsubscribesRef =
|
|
9131
|
-
const onMessageRef =
|
|
9317
|
+
const [status, setStatus] = React.useState("disconnected");
|
|
9318
|
+
const [lastMessage, setLastMessage] = React.useState(null);
|
|
9319
|
+
const manualUnsubscribesRef = React.useRef([]);
|
|
9320
|
+
const autoUnsubscribesRef = React.useRef([]);
|
|
9321
|
+
const onMessageRef = React.useRef(void 0);
|
|
9132
9322
|
const channelSignature = (options?.channels ?? []).join("");
|
|
9133
|
-
|
|
9323
|
+
React.useEffect(() => {
|
|
9134
9324
|
onMessageRef.current = options?.onMessage;
|
|
9135
9325
|
}, [options?.onMessage]);
|
|
9136
|
-
const disconnect =
|
|
9326
|
+
const disconnect = React.useCallback(() => {
|
|
9137
9327
|
realtime.disconnect();
|
|
9138
9328
|
}, [realtime]);
|
|
9139
|
-
const subscribe =
|
|
9329
|
+
const subscribe = React.useCallback(
|
|
9140
9330
|
(channel, callback) => {
|
|
9141
9331
|
const unsub = realtime.subscribe(channel, (data) => {
|
|
9142
9332
|
setLastMessage({ channel, data });
|
|
@@ -9151,19 +9341,19 @@ function useRealtime(options) {
|
|
|
9151
9341
|
},
|
|
9152
9342
|
[realtime]
|
|
9153
9343
|
);
|
|
9154
|
-
const publish =
|
|
9344
|
+
const publish = React.useCallback(
|
|
9155
9345
|
(channel, data) => {
|
|
9156
9346
|
realtime.publish(channel, data);
|
|
9157
9347
|
},
|
|
9158
9348
|
[realtime]
|
|
9159
9349
|
);
|
|
9160
|
-
|
|
9350
|
+
React.useEffect(() => {
|
|
9161
9351
|
const unsub = realtime.onStatusChange((newStatus) => {
|
|
9162
9352
|
setStatus(newStatus);
|
|
9163
9353
|
});
|
|
9164
9354
|
return unsub;
|
|
9165
9355
|
}, [realtime]);
|
|
9166
|
-
|
|
9356
|
+
React.useEffect(() => {
|
|
9167
9357
|
for (const unsub of autoUnsubscribesRef.current) {
|
|
9168
9358
|
unsub();
|
|
9169
9359
|
}
|
|
@@ -9182,7 +9372,7 @@ function useRealtime(options) {
|
|
|
9182
9372
|
autoUnsubscribesRef.current = [];
|
|
9183
9373
|
};
|
|
9184
9374
|
}, [realtime, channelSignature]);
|
|
9185
|
-
|
|
9375
|
+
React.useEffect(() => {
|
|
9186
9376
|
return () => {
|
|
9187
9377
|
for (const unsub of manualUnsubscribesRef.current) {
|
|
9188
9378
|
unsub();
|
|
@@ -9401,20 +9591,20 @@ function useAnalytics(options = {}) {
|
|
|
9401
9591
|
} = options;
|
|
9402
9592
|
const shouldAutoCaptureUtmParams = autoCaptureUtmParams ?? autoCapturUtmParams ?? true;
|
|
9403
9593
|
const { client, user, analyticsProxyUrl, publishableKey, gatewayUrl } = useScaleMule();
|
|
9404
|
-
const [loading, setLoading] =
|
|
9405
|
-
const [error, setError] =
|
|
9406
|
-
const [utmParams, setUtmParams] =
|
|
9407
|
-
const sessionIdRef =
|
|
9408
|
-
const anonymousIdRef =
|
|
9409
|
-
const sessionStartRef =
|
|
9410
|
-
const originalReferrerRef =
|
|
9411
|
-
const idsReadyRef =
|
|
9412
|
-
const [sessionId, setSessionId] =
|
|
9413
|
-
const [anonymousId, setAnonymousId] =
|
|
9414
|
-
const initialized =
|
|
9415
|
-
const landingPage =
|
|
9416
|
-
const eventQueue =
|
|
9417
|
-
|
|
9594
|
+
const [loading, setLoading] = React.useState(false);
|
|
9595
|
+
const [error, setError] = React.useState(null);
|
|
9596
|
+
const [utmParams, setUtmParams] = React.useState(null);
|
|
9597
|
+
const sessionIdRef = React.useRef(null);
|
|
9598
|
+
const anonymousIdRef = React.useRef(null);
|
|
9599
|
+
const sessionStartRef = React.useRef(Date.now());
|
|
9600
|
+
const originalReferrerRef = React.useRef(null);
|
|
9601
|
+
const idsReadyRef = React.useRef(false);
|
|
9602
|
+
const [sessionId, setSessionId] = React.useState(null);
|
|
9603
|
+
const [anonymousId, setAnonymousId] = React.useState(null);
|
|
9604
|
+
const initialized = React.useRef(false);
|
|
9605
|
+
const landingPage = React.useRef(null);
|
|
9606
|
+
const eventQueue = React.useRef([]);
|
|
9607
|
+
React.useEffect(() => {
|
|
9418
9608
|
if (initialized.current) return;
|
|
9419
9609
|
initialized.current = true;
|
|
9420
9610
|
if (!autoGenerateSessionId) {
|
|
@@ -9438,7 +9628,7 @@ function useAnalytics(options = {}) {
|
|
|
9438
9628
|
}, 0);
|
|
9439
9629
|
}
|
|
9440
9630
|
}, [autoGenerateSessionId, sessionStorageKey, anonymousStorageKey]);
|
|
9441
|
-
|
|
9631
|
+
React.useEffect(() => {
|
|
9442
9632
|
if (typeof window === "undefined") return;
|
|
9443
9633
|
if (shouldAutoCaptureUtmParams) {
|
|
9444
9634
|
const utm = parseUtmParams();
|
|
@@ -9463,11 +9653,11 @@ function useAnalytics(options = {}) {
|
|
|
9463
9653
|
}
|
|
9464
9654
|
}
|
|
9465
9655
|
}, [shouldAutoCaptureUtmParams]);
|
|
9466
|
-
const sendEventRef =
|
|
9467
|
-
const getDeviceInfo =
|
|
9656
|
+
const sendEventRef = React.useRef(null);
|
|
9657
|
+
const getDeviceInfo = React.useCallback(() => {
|
|
9468
9658
|
return detectDeviceInfo();
|
|
9469
9659
|
}, []);
|
|
9470
|
-
const buildFullEvent =
|
|
9660
|
+
const buildFullEvent = React.useCallback(
|
|
9471
9661
|
(event) => {
|
|
9472
9662
|
const device = getDeviceInfo();
|
|
9473
9663
|
const fullEvent = {
|
|
@@ -9507,7 +9697,7 @@ function useAnalytics(options = {}) {
|
|
|
9507
9697
|
// Note: sessionId/anonymousId removed - we use refs to keep this stable
|
|
9508
9698
|
[user, utmParams, getDeviceInfo]
|
|
9509
9699
|
);
|
|
9510
|
-
const sendEvent =
|
|
9700
|
+
const sendEvent = React.useCallback(
|
|
9511
9701
|
async (event) => {
|
|
9512
9702
|
const fullEvent = buildFullEvent(event);
|
|
9513
9703
|
const payload = JSON.stringify(fullEvent);
|
|
@@ -9550,7 +9740,7 @@ function useAnalytics(options = {}) {
|
|
|
9550
9740
|
[client, buildFullEvent, useV2, analyticsProxyUrl, publishableKey, gatewayUrl]
|
|
9551
9741
|
);
|
|
9552
9742
|
sendEventRef.current = sendEvent;
|
|
9553
|
-
const trackEvent =
|
|
9743
|
+
const trackEvent = React.useCallback(
|
|
9554
9744
|
async (event) => {
|
|
9555
9745
|
if (shouldDedup(event.event_name, eventDedupMs, event.properties)) {
|
|
9556
9746
|
return { tracked: 0, session_id: sessionIdRef.current || void 0 };
|
|
@@ -9576,7 +9766,7 @@ function useAnalytics(options = {}) {
|
|
|
9576
9766
|
// Note: idsReady removed - we use ref to keep callback stable
|
|
9577
9767
|
[sendEvent, eventDedupMs]
|
|
9578
9768
|
);
|
|
9579
|
-
const trackPageView =
|
|
9769
|
+
const trackPageView = React.useCallback(
|
|
9580
9770
|
async (data) => {
|
|
9581
9771
|
const pageEvent = {
|
|
9582
9772
|
event_name: "page_viewed",
|
|
@@ -9592,7 +9782,7 @@ function useAnalytics(options = {}) {
|
|
|
9592
9782
|
},
|
|
9593
9783
|
[trackEvent]
|
|
9594
9784
|
);
|
|
9595
|
-
const trackBatch =
|
|
9785
|
+
const trackBatch = React.useCallback(
|
|
9596
9786
|
async (events) => {
|
|
9597
9787
|
setError(null);
|
|
9598
9788
|
setLoading(true);
|
|
@@ -9646,7 +9836,7 @@ function useAnalytics(options = {}) {
|
|
|
9646
9836
|
// Note: sessionId removed - we use ref to keep callback stable
|
|
9647
9837
|
[client, buildFullEvent, useV2, analyticsProxyUrl, publishableKey, gatewayUrl]
|
|
9648
9838
|
);
|
|
9649
|
-
const identify =
|
|
9839
|
+
const identify = React.useCallback(
|
|
9650
9840
|
async (userId, traits) => {
|
|
9651
9841
|
await trackEvent({
|
|
9652
9842
|
event_name: "user_identified",
|
|
@@ -9661,7 +9851,7 @@ function useAnalytics(options = {}) {
|
|
|
9661
9851
|
// Note: anonymousId removed - we use ref
|
|
9662
9852
|
[trackEvent]
|
|
9663
9853
|
);
|
|
9664
|
-
const reset =
|
|
9854
|
+
const reset = React.useCallback(() => {
|
|
9665
9855
|
const newSessionId = generateUUID();
|
|
9666
9856
|
const newSessionStart = Date.now();
|
|
9667
9857
|
sessionIdRef.current = newSessionId;
|
|
@@ -9675,10 +9865,10 @@ function useAnalytics(options = {}) {
|
|
|
9675
9865
|
originalReferrerRef.current = null;
|
|
9676
9866
|
setUtmParams(null);
|
|
9677
9867
|
}, [sessionStorageKey]);
|
|
9678
|
-
const setUtmParamsManual =
|
|
9868
|
+
const setUtmParamsManual = React.useCallback((params) => {
|
|
9679
9869
|
setUtmParams(params);
|
|
9680
9870
|
}, []);
|
|
9681
|
-
return
|
|
9871
|
+
return React.useMemo(
|
|
9682
9872
|
() => ({
|
|
9683
9873
|
loading,
|
|
9684
9874
|
error,
|
|
@@ -9731,8 +9921,8 @@ function useFeatureFlags(options = {}) {
|
|
|
9731
9921
|
enabled = true
|
|
9732
9922
|
} = options;
|
|
9733
9923
|
const { client, publishableKey, gatewayUrl, bootstrapFlags } = smContext;
|
|
9734
|
-
const warnedRef =
|
|
9735
|
-
|
|
9924
|
+
const warnedRef = React.useRef(false);
|
|
9925
|
+
React.useEffect(() => {
|
|
9736
9926
|
if (!warnedRef.current && (!keys || keys.length === 0)) {
|
|
9737
9927
|
warnedRef.current = true;
|
|
9738
9928
|
console.warn(
|
|
@@ -9740,7 +9930,7 @@ function useFeatureFlags(options = {}) {
|
|
|
9740
9930
|
);
|
|
9741
9931
|
}
|
|
9742
9932
|
}, [keys]);
|
|
9743
|
-
const initialFlags =
|
|
9933
|
+
const initialFlags = React.useMemo(() => {
|
|
9744
9934
|
if (!bootstrapFlags) return {};
|
|
9745
9935
|
const result = {};
|
|
9746
9936
|
for (const [key, value] of Object.entries(bootstrapFlags)) {
|
|
@@ -9751,19 +9941,19 @@ function useFeatureFlags(options = {}) {
|
|
|
9751
9941
|
return result;
|
|
9752
9942
|
}, [bootstrapFlags]);
|
|
9753
9943
|
const hasBootstrap = Object.keys(initialFlags).length > 0;
|
|
9754
|
-
const [flags, setFlags] =
|
|
9755
|
-
const [loading, setLoading] =
|
|
9756
|
-
const [error, setError] =
|
|
9757
|
-
const contextRef =
|
|
9758
|
-
const keysRef =
|
|
9759
|
-
const keysKey =
|
|
9760
|
-
|
|
9944
|
+
const [flags, setFlags] = React.useState(initialFlags);
|
|
9945
|
+
const [loading, setLoading] = React.useState(enabled && !hasBootstrap);
|
|
9946
|
+
const [error, setError] = React.useState(null);
|
|
9947
|
+
const contextRef = React.useRef(context);
|
|
9948
|
+
const keysRef = React.useRef(keys);
|
|
9949
|
+
const keysKey = React.useMemo(() => keys && keys.length > 0 ? [...keys].sort().join("|") : "", [keys]);
|
|
9950
|
+
React.useEffect(() => {
|
|
9761
9951
|
contextRef.current = context;
|
|
9762
9952
|
}, [context]);
|
|
9763
|
-
|
|
9953
|
+
React.useEffect(() => {
|
|
9764
9954
|
keysRef.current = keys;
|
|
9765
9955
|
}, [keys]);
|
|
9766
|
-
const refresh =
|
|
9956
|
+
const refresh = React.useCallback(async () => {
|
|
9767
9957
|
if (!enabled) {
|
|
9768
9958
|
setLoading(false);
|
|
9769
9959
|
return;
|
|
@@ -9799,7 +9989,7 @@ function useFeatureFlags(options = {}) {
|
|
|
9799
9989
|
setLoading(false);
|
|
9800
9990
|
}
|
|
9801
9991
|
}, [client, enabled, environment, keysKey, publishableKey, gatewayUrl]);
|
|
9802
|
-
const bootstrapCoversKeys =
|
|
9992
|
+
const bootstrapCoversKeys = React.useMemo(() => {
|
|
9803
9993
|
if (!hasBootstrap || !keys || keys.length === 0) return false;
|
|
9804
9994
|
if (!keys.every((k) => k in initialFlags)) return false;
|
|
9805
9995
|
if (environment !== (smContext.environment ?? "prod")) return false;
|
|
@@ -9807,12 +9997,12 @@ function useFeatureFlags(options = {}) {
|
|
|
9807
9997
|
if (contextKeys.length > 0) return false;
|
|
9808
9998
|
return true;
|
|
9809
9999
|
}, [hasBootstrap, keys, initialFlags, environment, smContext.environment, context]);
|
|
9810
|
-
|
|
10000
|
+
React.useEffect(() => {
|
|
9811
10001
|
if (!bootstrapCoversKeys) {
|
|
9812
10002
|
void refresh();
|
|
9813
10003
|
}
|
|
9814
10004
|
}, [refresh, bootstrapCoversKeys]);
|
|
9815
|
-
const isEnabled =
|
|
10005
|
+
const isEnabled = React.useCallback(
|
|
9816
10006
|
(flagKey, fallback = false) => {
|
|
9817
10007
|
const evaluation = flags[flagKey];
|
|
9818
10008
|
if (!evaluation) return fallback;
|
|
@@ -9820,7 +10010,7 @@ function useFeatureFlags(options = {}) {
|
|
|
9820
10010
|
},
|
|
9821
10011
|
[flags]
|
|
9822
10012
|
);
|
|
9823
|
-
const getFlag =
|
|
10013
|
+
const getFlag = React.useCallback(
|
|
9824
10014
|
(flagKey, fallback) => {
|
|
9825
10015
|
const evaluation = flags[flagKey];
|
|
9826
10016
|
if (!evaluation) return fallback;
|
|
@@ -9845,18 +10035,18 @@ function getCsrfToken() {
|
|
|
9845
10035
|
function usePushNotifications(options = {}) {
|
|
9846
10036
|
const { serviceWorkerUrl = "/sw.js", pushProxyUrl = "/api/push", registrationSource, onNotification } = options;
|
|
9847
10037
|
const { user } = useScaleMule();
|
|
9848
|
-
const [isSupported, setIsSupported] =
|
|
9849
|
-
const [permission, setPermission] =
|
|
9850
|
-
const [isSubscribed, setIsSubscribed] =
|
|
9851
|
-
const [isLoading, setIsLoading] =
|
|
9852
|
-
const [error, setError] =
|
|
9853
|
-
const [tokenId, setTokenId] =
|
|
9854
|
-
const onNotificationRef =
|
|
9855
|
-
|
|
10038
|
+
const [isSupported, setIsSupported] = React.useState(false);
|
|
10039
|
+
const [permission, setPermission] = React.useState("unsupported");
|
|
10040
|
+
const [isSubscribed, setIsSubscribed] = React.useState(false);
|
|
10041
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
10042
|
+
const [error, setError] = React.useState(null);
|
|
10043
|
+
const [tokenId, setTokenId] = React.useState(null);
|
|
10044
|
+
const onNotificationRef = React.useRef(onNotification);
|
|
10045
|
+
React.useEffect(() => {
|
|
9856
10046
|
onNotificationRef.current = onNotification;
|
|
9857
10047
|
}, [onNotification]);
|
|
9858
|
-
const prevUserRef =
|
|
9859
|
-
const fetcher =
|
|
10048
|
+
const prevUserRef = React.useRef(null);
|
|
10049
|
+
const fetcher = React.useMemo(() => {
|
|
9860
10050
|
async function proxyGet(path) {
|
|
9861
10051
|
const res = await fetch(`${pushProxyUrl}/${path}`);
|
|
9862
10052
|
const json = await res.json();
|
|
@@ -9907,7 +10097,7 @@ function usePushNotifications(options = {}) {
|
|
|
9907
10097
|
disassociateUser: (id) => proxyDelete(`tokens/by-id/${id}/user`)
|
|
9908
10098
|
};
|
|
9909
10099
|
}, [pushProxyUrl]);
|
|
9910
|
-
const manager =
|
|
10100
|
+
const manager = React.useMemo(() => {
|
|
9911
10101
|
if (typeof window === "undefined") return null;
|
|
9912
10102
|
try {
|
|
9913
10103
|
return new WebPushManager({ fetcher, serviceWorkerUrl, registrationSource });
|
|
@@ -9915,7 +10105,7 @@ function usePushNotifications(options = {}) {
|
|
|
9915
10105
|
return null;
|
|
9916
10106
|
}
|
|
9917
10107
|
}, [fetcher, serviceWorkerUrl]);
|
|
9918
|
-
|
|
10108
|
+
React.useEffect(() => {
|
|
9919
10109
|
if (!manager) return;
|
|
9920
10110
|
const supported = manager.isSupported();
|
|
9921
10111
|
setIsSupported(supported);
|
|
@@ -9936,7 +10126,7 @@ function usePushNotifications(options = {}) {
|
|
|
9936
10126
|
});
|
|
9937
10127
|
}
|
|
9938
10128
|
}, [manager]);
|
|
9939
|
-
|
|
10129
|
+
React.useEffect(() => {
|
|
9940
10130
|
if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) return;
|
|
9941
10131
|
function handleMessage(event) {
|
|
9942
10132
|
if (event.data?.type === "push-received") {
|
|
@@ -9955,7 +10145,7 @@ function usePushNotifications(options = {}) {
|
|
|
9955
10145
|
navigator.serviceWorker.addEventListener("message", handleMessage);
|
|
9956
10146
|
return () => navigator.serviceWorker.removeEventListener("message", handleMessage);
|
|
9957
10147
|
}, [manager]);
|
|
9958
|
-
|
|
10148
|
+
React.useEffect(() => {
|
|
9959
10149
|
if (!manager) return;
|
|
9960
10150
|
const currentUserId = user?.id || null;
|
|
9961
10151
|
const prevUserId = prevUserRef.current;
|
|
@@ -9965,7 +10155,7 @@ function usePushNotifications(options = {}) {
|
|
|
9965
10155
|
}
|
|
9966
10156
|
prevUserRef.current = currentUserId;
|
|
9967
10157
|
}, [user?.id, manager, isSubscribed]);
|
|
9968
|
-
const subscribe =
|
|
10158
|
+
const subscribe = React.useCallback(async () => {
|
|
9969
10159
|
if (!manager) return;
|
|
9970
10160
|
setIsLoading(true);
|
|
9971
10161
|
setError(null);
|
|
@@ -9987,7 +10177,7 @@ function usePushNotifications(options = {}) {
|
|
|
9987
10177
|
setIsLoading(false);
|
|
9988
10178
|
}
|
|
9989
10179
|
}, [manager]);
|
|
9990
|
-
const unsubscribe =
|
|
10180
|
+
const unsubscribe = React.useCallback(async () => {
|
|
9991
10181
|
if (!manager) return;
|
|
9992
10182
|
setIsLoading(true);
|
|
9993
10183
|
setError(null);
|
|
@@ -10004,7 +10194,7 @@ function usePushNotifications(options = {}) {
|
|
|
10004
10194
|
setIsLoading(false);
|
|
10005
10195
|
}
|
|
10006
10196
|
}, [manager]);
|
|
10007
|
-
const disassociateUser =
|
|
10197
|
+
const disassociateUser = React.useCallback(async () => {
|
|
10008
10198
|
if (!manager) return;
|
|
10009
10199
|
try {
|
|
10010
10200
|
await manager.disassociateUser();
|
|
@@ -10025,12 +10215,12 @@ function usePushNotifications(options = {}) {
|
|
|
10025
10215
|
}
|
|
10026
10216
|
function useShare(options) {
|
|
10027
10217
|
const { client, user } = useScaleMule();
|
|
10028
|
-
const [referralCode, setReferralCode] =
|
|
10218
|
+
const [referralCode, setReferralCode] = React.useState(
|
|
10029
10219
|
options?.referralCode ?? null
|
|
10030
10220
|
);
|
|
10031
|
-
const [loading, setLoading] =
|
|
10032
|
-
const [copied, setCopied] =
|
|
10033
|
-
|
|
10221
|
+
const [loading, setLoading] = React.useState(false);
|
|
10222
|
+
const [copied, setCopied] = React.useState(false);
|
|
10223
|
+
React.useEffect(() => {
|
|
10034
10224
|
if (!user) {
|
|
10035
10225
|
setReferralCode(options?.referralCode ?? null);
|
|
10036
10226
|
setLoading(false);
|
|
@@ -10059,7 +10249,7 @@ function useShare(options) {
|
|
|
10059
10249
|
cancelled = true;
|
|
10060
10250
|
};
|
|
10061
10251
|
}, [user?.id, options?.url, options?.referralCode, options?.autoFetchReferral, client]);
|
|
10062
|
-
const shareUrl =
|
|
10252
|
+
const shareUrl = React.useMemo(() => {
|
|
10063
10253
|
const raw = options?.url || (typeof window !== "undefined" ? window.location.href : "");
|
|
10064
10254
|
if (!raw) return raw;
|
|
10065
10255
|
try {
|
|
@@ -10073,7 +10263,7 @@ function useShare(options) {
|
|
|
10073
10263
|
return raw;
|
|
10074
10264
|
}
|
|
10075
10265
|
}, [options?.url, referralCode]);
|
|
10076
|
-
const copyLink =
|
|
10266
|
+
const copyLink = React.useCallback(async () => {
|
|
10077
10267
|
try {
|
|
10078
10268
|
await navigator.clipboard.writeText(shareUrl);
|
|
10079
10269
|
} catch {
|
|
@@ -10112,10 +10302,10 @@ function toApiError2(error) {
|
|
|
10112
10302
|
function useFeedback(options = {}) {
|
|
10113
10303
|
const { client } = useScaleMule();
|
|
10114
10304
|
const { status, type, enabled = true } = options;
|
|
10115
|
-
const [items, setItems] =
|
|
10116
|
-
const [loading, setLoading] =
|
|
10117
|
-
const [error, setError] =
|
|
10118
|
-
const refresh =
|
|
10305
|
+
const [items, setItems] = React.useState([]);
|
|
10306
|
+
const [loading, setLoading] = React.useState(enabled);
|
|
10307
|
+
const [error, setError] = React.useState(null);
|
|
10308
|
+
const refresh = React.useCallback(async () => {
|
|
10119
10309
|
if (!enabled) {
|
|
10120
10310
|
setLoading(false);
|
|
10121
10311
|
return;
|
|
@@ -10136,10 +10326,10 @@ function useFeedback(options = {}) {
|
|
|
10136
10326
|
setLoading(false);
|
|
10137
10327
|
}
|
|
10138
10328
|
}, [client, enabled, status, type]);
|
|
10139
|
-
|
|
10329
|
+
React.useEffect(() => {
|
|
10140
10330
|
refresh();
|
|
10141
10331
|
}, [refresh]);
|
|
10142
|
-
const submit =
|
|
10332
|
+
const submit = React.useCallback(
|
|
10143
10333
|
async (input) => {
|
|
10144
10334
|
try {
|
|
10145
10335
|
const created = await client.post("/v1/feedback/submit", input);
|
|
@@ -10272,18 +10462,18 @@ function FeedbackWidget(props) {
|
|
|
10272
10462
|
const sm = useScaleMule();
|
|
10273
10463
|
const { client } = sm;
|
|
10274
10464
|
const { submit } = useFeedback({ enabled: false });
|
|
10275
|
-
const [serverConfig, setServerConfig] =
|
|
10276
|
-
const [configLoaded, setConfigLoaded] =
|
|
10277
|
-
const [open, setOpen] =
|
|
10278
|
-
const [type, setType] =
|
|
10279
|
-
const [title, setTitle] =
|
|
10280
|
-
const [description, setDescription] =
|
|
10281
|
-
const [email, setEmail] =
|
|
10282
|
-
const [rating, setRating] =
|
|
10283
|
-
const [hoverRating, setHoverRating] =
|
|
10284
|
-
const [submitting, setSubmitting] =
|
|
10285
|
-
const [errMsg, setErrMsg] =
|
|
10286
|
-
const [done, setDone] =
|
|
10465
|
+
const [serverConfig, setServerConfig] = React.useState(null);
|
|
10466
|
+
const [configLoaded, setConfigLoaded] = React.useState(false);
|
|
10467
|
+
const [open, setOpen] = React.useState(false);
|
|
10468
|
+
const [type, setType] = React.useState("feature_request");
|
|
10469
|
+
const [title, setTitle] = React.useState("");
|
|
10470
|
+
const [description, setDescription] = React.useState("");
|
|
10471
|
+
const [email, setEmail] = React.useState("");
|
|
10472
|
+
const [rating, setRating] = React.useState(null);
|
|
10473
|
+
const [hoverRating, setHoverRating] = React.useState(null);
|
|
10474
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
10475
|
+
const [errMsg, setErrMsg] = React.useState(null);
|
|
10476
|
+
const [done, setDone] = React.useState(false);
|
|
10287
10477
|
const signedIn = Boolean(sm.user);
|
|
10288
10478
|
const resolvedAllowedTypes = props.allowedTypes ?? serverConfig?.allowed_types ?? ALL_TYPES;
|
|
10289
10479
|
const resolvedDefaultType = (props.defaultType && resolvedAllowedTypes.includes(props.defaultType) ? props.defaultType : resolvedAllowedTypes[0]) ?? "feature_request";
|
|
@@ -10291,7 +10481,7 @@ function FeedbackWidget(props) {
|
|
|
10291
10481
|
const resolvedTheme = props.theme ?? serverConfig?.widget_theme ?? "auto";
|
|
10292
10482
|
const allowAnonymous = serverConfig?.allow_anonymous ?? true;
|
|
10293
10483
|
const anonymousBlocked = !signedIn && !allowAnonymous;
|
|
10294
|
-
|
|
10484
|
+
React.useEffect(() => {
|
|
10295
10485
|
let active = true;
|
|
10296
10486
|
client.get("/v1/feedback/widget-config").then((config) => {
|
|
10297
10487
|
if (active) setServerConfig(config);
|
|
@@ -10304,7 +10494,7 @@ function FeedbackWidget(props) {
|
|
|
10304
10494
|
active = false;
|
|
10305
10495
|
};
|
|
10306
10496
|
}, [client]);
|
|
10307
|
-
|
|
10497
|
+
React.useEffect(() => {
|
|
10308
10498
|
setType(
|
|
10309
10499
|
(current) => resolvedAllowedTypes.includes(current) ? current : resolvedDefaultType
|
|
10310
10500
|
);
|
|
@@ -10827,6 +11017,7 @@ Object.defineProperty(exports, "createMoneyClient", {
|
|
|
10827
11017
|
exports.FeedbackWidget = FeedbackWidget;
|
|
10828
11018
|
exports.ScaleMuleApiError = ScaleMuleApiError;
|
|
10829
11019
|
exports.ScaleMuleClient = ScaleMuleClient2;
|
|
11020
|
+
exports.ScaleMuleMedia = ScaleMuleMedia;
|
|
10830
11021
|
exports.ScaleMuleProvider = ScaleMuleProvider;
|
|
10831
11022
|
exports.composePhone = composePhone;
|
|
10832
11023
|
exports.createClient = createClient;
|