@scalemule/nextjs 0.1.4 → 0.1.6
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 +112 -1
- package/dist/index.d.ts +112 -1
- package/dist/index.js +389 -190
- package/dist/index.mjs +181 -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,14 +8898,16 @@ 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);
|
|
8887
8907
|
const isPublic = options?.is_public ?? false;
|
|
8888
8908
|
const mimeType = file.type || "application/octet-stream";
|
|
8909
|
+
const policy = options?.policy ?? "safe_visible";
|
|
8910
|
+
const gateOnPipeline = policy === "safe_public" || policy === "moderated" || policy === "compliance";
|
|
8889
8911
|
const sharedOpts = {
|
|
8890
8912
|
filename: options?.filename,
|
|
8891
8913
|
metadata: options?.metadata,
|
|
@@ -8898,6 +8920,9 @@ function useMedia() {
|
|
|
8898
8920
|
if (r2.error || !r2.data) {
|
|
8899
8921
|
throw r2.error ?? { code: "upload_error", message: "Upload failed", status: 0 };
|
|
8900
8922
|
}
|
|
8923
|
+
if (gateOnPipeline) {
|
|
8924
|
+
await r2.data.optimized_url_promise;
|
|
8925
|
+
}
|
|
8901
8926
|
return {
|
|
8902
8927
|
file_id: r2.data.file_id,
|
|
8903
8928
|
photo_id: r2.data.photo_id,
|
|
@@ -8913,6 +8938,9 @@ function useMedia() {
|
|
|
8913
8938
|
if (r2.error || !r2.data) {
|
|
8914
8939
|
throw r2.error ?? { code: "upload_error", message: "Upload failed", status: 0 };
|
|
8915
8940
|
}
|
|
8941
|
+
if (gateOnPipeline) {
|
|
8942
|
+
await r2.data.hls_url_promise;
|
|
8943
|
+
}
|
|
8916
8944
|
return {
|
|
8917
8945
|
file_id: r2.data.file_id,
|
|
8918
8946
|
photo_id: null,
|
|
@@ -8967,7 +8995,7 @@ function useMedia() {
|
|
|
8967
8995
|
},
|
|
8968
8996
|
[storage, photo]
|
|
8969
8997
|
);
|
|
8970
|
-
const cancelUpload =
|
|
8998
|
+
const cancelUpload = React.useCallback(
|
|
8971
8999
|
async (fileId) => {
|
|
8972
9000
|
setError(null);
|
|
8973
9001
|
try {
|
|
@@ -8989,11 +9017,11 @@ function useMedia() {
|
|
|
8989
9017
|
function useFileStatus(options) {
|
|
8990
9018
|
const { storage } = useScaleMule();
|
|
8991
9019
|
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 =
|
|
9020
|
+
const [status, setStatus] = React.useState(null);
|
|
9021
|
+
const [loading, setLoading] = React.useState(false);
|
|
9022
|
+
const [error, setError] = React.useState(null);
|
|
9023
|
+
const requestSeqRef = React.useRef(0);
|
|
9024
|
+
const fetchStatus = React.useCallback(async () => {
|
|
8997
9025
|
if (!fileId || disabled) return;
|
|
8998
9026
|
const seq = ++requestSeqRef.current;
|
|
8999
9027
|
setLoading(true);
|
|
@@ -9015,10 +9043,10 @@ function useFileStatus(options) {
|
|
|
9015
9043
|
}
|
|
9016
9044
|
}
|
|
9017
9045
|
}, [storage, fileId, disabled]);
|
|
9018
|
-
|
|
9046
|
+
React.useEffect(() => {
|
|
9019
9047
|
void fetchStatus();
|
|
9020
9048
|
}, [fetchStatus]);
|
|
9021
|
-
|
|
9049
|
+
React.useEffect(() => {
|
|
9022
9050
|
if (!pollIntervalMs || disabled || !fileId) return;
|
|
9023
9051
|
const isClean = status?.scan.status === "clean";
|
|
9024
9052
|
if (isClean) return;
|
|
@@ -9030,14 +9058,184 @@ function useFileStatus(options) {
|
|
|
9030
9058
|
const isReady = status?.scan.status === "clean";
|
|
9031
9059
|
return { status, loading, error, isReady, refresh: fetchStatus };
|
|
9032
9060
|
}
|
|
9061
|
+
function ScaleMuleMedia(props) {
|
|
9062
|
+
const {
|
|
9063
|
+
fileId,
|
|
9064
|
+
mimeType,
|
|
9065
|
+
blobPreview,
|
|
9066
|
+
width,
|
|
9067
|
+
height,
|
|
9068
|
+
className,
|
|
9069
|
+
style,
|
|
9070
|
+
alt,
|
|
9071
|
+
pollIntervalMs = 2e3,
|
|
9072
|
+
renderPlaceholder,
|
|
9073
|
+
renderBlocked,
|
|
9074
|
+
renderOverride
|
|
9075
|
+
} = props;
|
|
9076
|
+
const { status, isReady } = useFileStatus({ fileId, pollIntervalMs });
|
|
9077
|
+
const isImage = mimeType.startsWith("image/");
|
|
9078
|
+
const isVideo = mimeType.startsWith("video/");
|
|
9079
|
+
const isAudio = mimeType.startsWith("audio/");
|
|
9080
|
+
const src = React.useMemo(() => {
|
|
9081
|
+
const scan = status?.scan.status;
|
|
9082
|
+
if (scan === "threat" || scan === "quarantined") return null;
|
|
9083
|
+
if (status && isReady) {
|
|
9084
|
+
if (isImage && status.urls.optimized) return status.urls.optimized;
|
|
9085
|
+
if (isVideo && status.urls.hls) return status.urls.hls;
|
|
9086
|
+
return status.urls.original ?? null;
|
|
9087
|
+
}
|
|
9088
|
+
if (blobPreview) return blobPreview;
|
|
9089
|
+
return null;
|
|
9090
|
+
}, [status, isReady, isImage, isVideo, blobPreview]);
|
|
9091
|
+
const renderState = React.useMemo(() => {
|
|
9092
|
+
const scan = status?.scan.status;
|
|
9093
|
+
if (scan === "threat" || scan === "quarantined") return "blocked";
|
|
9094
|
+
if (isReady) return "ready";
|
|
9095
|
+
if (blobPreview) return "preview";
|
|
9096
|
+
return "pending";
|
|
9097
|
+
}, [status?.scan.status, isReady, blobPreview]);
|
|
9098
|
+
const videoRef = React__namespace.useRef(null);
|
|
9099
|
+
React.useEffect(() => {
|
|
9100
|
+
if (!isVideo) return;
|
|
9101
|
+
if (!src) return;
|
|
9102
|
+
if (!src.endsWith(".m3u8")) return;
|
|
9103
|
+
const el = videoRef.current;
|
|
9104
|
+
if (!el) return;
|
|
9105
|
+
if (el.canPlayType("application/vnd.apple.mpegurl")) {
|
|
9106
|
+
el.src = src;
|
|
9107
|
+
return;
|
|
9108
|
+
}
|
|
9109
|
+
let cancelled = false;
|
|
9110
|
+
let hls = null;
|
|
9111
|
+
void (async () => {
|
|
9112
|
+
try {
|
|
9113
|
+
const moduleName = "hls.js";
|
|
9114
|
+
const mod = await import(
|
|
9115
|
+
/* @vite-ignore */
|
|
9116
|
+
/* webpackIgnore: true */
|
|
9117
|
+
moduleName
|
|
9118
|
+
).catch(
|
|
9119
|
+
() => null
|
|
9120
|
+
);
|
|
9121
|
+
if (cancelled || !mod) return;
|
|
9122
|
+
const Hls = mod.default ?? mod;
|
|
9123
|
+
if (Hls.isSupported()) {
|
|
9124
|
+
hls = new Hls();
|
|
9125
|
+
hls.loadSource(src);
|
|
9126
|
+
hls.attachMedia(el);
|
|
9127
|
+
} else {
|
|
9128
|
+
el.src = src;
|
|
9129
|
+
}
|
|
9130
|
+
} catch {
|
|
9131
|
+
}
|
|
9132
|
+
})();
|
|
9133
|
+
return () => {
|
|
9134
|
+
cancelled = true;
|
|
9135
|
+
if (hls) hls.destroy();
|
|
9136
|
+
};
|
|
9137
|
+
}, [isVideo, src]);
|
|
9138
|
+
if (renderOverride) {
|
|
9139
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderOverride({ src, state: renderState }) });
|
|
9140
|
+
}
|
|
9141
|
+
if (renderState === "blocked") {
|
|
9142
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderBlocked ? renderBlocked() : /* @__PURE__ */ jsxRuntime.jsx(
|
|
9143
|
+
"div",
|
|
9144
|
+
{
|
|
9145
|
+
role: "alert",
|
|
9146
|
+
className,
|
|
9147
|
+
style: { padding: 12, color: "#a00", ...style },
|
|
9148
|
+
children: "This file was blocked."
|
|
9149
|
+
}
|
|
9150
|
+
) });
|
|
9151
|
+
}
|
|
9152
|
+
if (renderState === "pending" && !src) {
|
|
9153
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderPlaceholder ? renderPlaceholder() : /* @__PURE__ */ jsxRuntime.jsx(
|
|
9154
|
+
"div",
|
|
9155
|
+
{
|
|
9156
|
+
role: "status",
|
|
9157
|
+
"aria-busy": true,
|
|
9158
|
+
className,
|
|
9159
|
+
style: { padding: 12, color: "#666", ...style },
|
|
9160
|
+
children: "Loading\u2026"
|
|
9161
|
+
}
|
|
9162
|
+
) });
|
|
9163
|
+
}
|
|
9164
|
+
if (isImage) {
|
|
9165
|
+
const finalSrc = src && status?.urls.optimized && (width || height) ? appendQuery(src, {
|
|
9166
|
+
width: width ? String(width) : void 0,
|
|
9167
|
+
height: height ? String(height) : void 0,
|
|
9168
|
+
fit: "cover"
|
|
9169
|
+
}) : src;
|
|
9170
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9171
|
+
"img",
|
|
9172
|
+
{
|
|
9173
|
+
src: finalSrc ?? void 0,
|
|
9174
|
+
alt: alt ?? "",
|
|
9175
|
+
width,
|
|
9176
|
+
height,
|
|
9177
|
+
className,
|
|
9178
|
+
style
|
|
9179
|
+
}
|
|
9180
|
+
);
|
|
9181
|
+
}
|
|
9182
|
+
if (isVideo) {
|
|
9183
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9184
|
+
"video",
|
|
9185
|
+
{
|
|
9186
|
+
ref: videoRef,
|
|
9187
|
+
src: src && !src.endsWith(".m3u8") ? src : void 0,
|
|
9188
|
+
controls: true,
|
|
9189
|
+
playsInline: true,
|
|
9190
|
+
preload: "metadata",
|
|
9191
|
+
className,
|
|
9192
|
+
style,
|
|
9193
|
+
"aria-label": alt,
|
|
9194
|
+
width,
|
|
9195
|
+
height
|
|
9196
|
+
}
|
|
9197
|
+
);
|
|
9198
|
+
}
|
|
9199
|
+
if (isAudio) {
|
|
9200
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9201
|
+
"audio",
|
|
9202
|
+
{
|
|
9203
|
+
src: src ?? void 0,
|
|
9204
|
+
controls: true,
|
|
9205
|
+
preload: "metadata",
|
|
9206
|
+
className,
|
|
9207
|
+
style,
|
|
9208
|
+
"aria-label": alt
|
|
9209
|
+
}
|
|
9210
|
+
);
|
|
9211
|
+
}
|
|
9212
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
9213
|
+
"a",
|
|
9214
|
+
{
|
|
9215
|
+
href: src ?? "#",
|
|
9216
|
+
target: "_blank",
|
|
9217
|
+
rel: "noopener noreferrer",
|
|
9218
|
+
className,
|
|
9219
|
+
style,
|
|
9220
|
+
children: alt ?? "Download file"
|
|
9221
|
+
}
|
|
9222
|
+
);
|
|
9223
|
+
}
|
|
9224
|
+
function appendQuery(url, params) {
|
|
9225
|
+
const filtered = Object.entries(params).filter(([, v]) => v != null && v !== "");
|
|
9226
|
+
if (filtered.length === 0) return url;
|
|
9227
|
+
const sep = url.includes("?") ? "&" : "?";
|
|
9228
|
+
const qs = new URLSearchParams(filtered).toString();
|
|
9229
|
+
return url + sep + qs;
|
|
9230
|
+
}
|
|
9033
9231
|
|
|
9034
9232
|
// src/hooks/useMoney.ts
|
|
9035
9233
|
var useMoney = useMoneyClient;
|
|
9036
9234
|
function useUser() {
|
|
9037
9235
|
const { client, user, setUser, setError } = useScaleMule();
|
|
9038
|
-
const [loading, setLoading] =
|
|
9039
|
-
const [localError, setLocalError] =
|
|
9040
|
-
const update =
|
|
9236
|
+
const [loading, setLoading] = React.useState(false);
|
|
9237
|
+
const [localError, setLocalError] = React.useState(null);
|
|
9238
|
+
const update = React.useCallback(
|
|
9041
9239
|
async (data) => {
|
|
9042
9240
|
setLocalError(null);
|
|
9043
9241
|
setLoading(true);
|
|
@@ -9051,7 +9249,7 @@ function useUser() {
|
|
|
9051
9249
|
},
|
|
9052
9250
|
[client, setUser]
|
|
9053
9251
|
);
|
|
9054
|
-
const changePassword =
|
|
9252
|
+
const changePassword = React.useCallback(
|
|
9055
9253
|
async (currentPassword, newPassword) => {
|
|
9056
9254
|
setLocalError(null);
|
|
9057
9255
|
setLoading(true);
|
|
@@ -9066,7 +9264,7 @@ function useUser() {
|
|
|
9066
9264
|
},
|
|
9067
9265
|
[client]
|
|
9068
9266
|
);
|
|
9069
|
-
const changeEmail =
|
|
9267
|
+
const changeEmail = React.useCallback(
|
|
9070
9268
|
async (newEmail, password) => {
|
|
9071
9269
|
setLocalError(null);
|
|
9072
9270
|
setLoading(true);
|
|
@@ -9081,7 +9279,7 @@ function useUser() {
|
|
|
9081
9279
|
},
|
|
9082
9280
|
[client]
|
|
9083
9281
|
);
|
|
9084
|
-
const deleteAccount =
|
|
9282
|
+
const deleteAccount = React.useCallback(
|
|
9085
9283
|
async (password) => {
|
|
9086
9284
|
setLocalError(null);
|
|
9087
9285
|
setLoading(true);
|
|
@@ -9097,7 +9295,7 @@ function useUser() {
|
|
|
9097
9295
|
},
|
|
9098
9296
|
[client, setUser]
|
|
9099
9297
|
);
|
|
9100
|
-
const exportData =
|
|
9298
|
+
const exportData = React.useCallback(async () => {
|
|
9101
9299
|
setLocalError(null);
|
|
9102
9300
|
setLoading(true);
|
|
9103
9301
|
try {
|
|
@@ -9108,7 +9306,7 @@ function useUser() {
|
|
|
9108
9306
|
setLoading(false);
|
|
9109
9307
|
}
|
|
9110
9308
|
}, [client]);
|
|
9111
|
-
return
|
|
9309
|
+
return React.useMemo(
|
|
9112
9310
|
() => ({
|
|
9113
9311
|
profile: user,
|
|
9114
9312
|
loading,
|
|
@@ -9124,19 +9322,19 @@ function useUser() {
|
|
|
9124
9322
|
}
|
|
9125
9323
|
function useRealtime(options) {
|
|
9126
9324
|
const { realtime } = useScaleMule();
|
|
9127
|
-
const [status, setStatus] =
|
|
9128
|
-
const [lastMessage, setLastMessage] =
|
|
9129
|
-
const manualUnsubscribesRef =
|
|
9130
|
-
const autoUnsubscribesRef =
|
|
9131
|
-
const onMessageRef =
|
|
9325
|
+
const [status, setStatus] = React.useState("disconnected");
|
|
9326
|
+
const [lastMessage, setLastMessage] = React.useState(null);
|
|
9327
|
+
const manualUnsubscribesRef = React.useRef([]);
|
|
9328
|
+
const autoUnsubscribesRef = React.useRef([]);
|
|
9329
|
+
const onMessageRef = React.useRef(void 0);
|
|
9132
9330
|
const channelSignature = (options?.channels ?? []).join("");
|
|
9133
|
-
|
|
9331
|
+
React.useEffect(() => {
|
|
9134
9332
|
onMessageRef.current = options?.onMessage;
|
|
9135
9333
|
}, [options?.onMessage]);
|
|
9136
|
-
const disconnect =
|
|
9334
|
+
const disconnect = React.useCallback(() => {
|
|
9137
9335
|
realtime.disconnect();
|
|
9138
9336
|
}, [realtime]);
|
|
9139
|
-
const subscribe =
|
|
9337
|
+
const subscribe = React.useCallback(
|
|
9140
9338
|
(channel, callback) => {
|
|
9141
9339
|
const unsub = realtime.subscribe(channel, (data) => {
|
|
9142
9340
|
setLastMessage({ channel, data });
|
|
@@ -9151,19 +9349,19 @@ function useRealtime(options) {
|
|
|
9151
9349
|
},
|
|
9152
9350
|
[realtime]
|
|
9153
9351
|
);
|
|
9154
|
-
const publish =
|
|
9352
|
+
const publish = React.useCallback(
|
|
9155
9353
|
(channel, data) => {
|
|
9156
9354
|
realtime.publish(channel, data);
|
|
9157
9355
|
},
|
|
9158
9356
|
[realtime]
|
|
9159
9357
|
);
|
|
9160
|
-
|
|
9358
|
+
React.useEffect(() => {
|
|
9161
9359
|
const unsub = realtime.onStatusChange((newStatus) => {
|
|
9162
9360
|
setStatus(newStatus);
|
|
9163
9361
|
});
|
|
9164
9362
|
return unsub;
|
|
9165
9363
|
}, [realtime]);
|
|
9166
|
-
|
|
9364
|
+
React.useEffect(() => {
|
|
9167
9365
|
for (const unsub of autoUnsubscribesRef.current) {
|
|
9168
9366
|
unsub();
|
|
9169
9367
|
}
|
|
@@ -9182,7 +9380,7 @@ function useRealtime(options) {
|
|
|
9182
9380
|
autoUnsubscribesRef.current = [];
|
|
9183
9381
|
};
|
|
9184
9382
|
}, [realtime, channelSignature]);
|
|
9185
|
-
|
|
9383
|
+
React.useEffect(() => {
|
|
9186
9384
|
return () => {
|
|
9187
9385
|
for (const unsub of manualUnsubscribesRef.current) {
|
|
9188
9386
|
unsub();
|
|
@@ -9401,20 +9599,20 @@ function useAnalytics(options = {}) {
|
|
|
9401
9599
|
} = options;
|
|
9402
9600
|
const shouldAutoCaptureUtmParams = autoCaptureUtmParams ?? autoCapturUtmParams ?? true;
|
|
9403
9601
|
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
|
-
|
|
9602
|
+
const [loading, setLoading] = React.useState(false);
|
|
9603
|
+
const [error, setError] = React.useState(null);
|
|
9604
|
+
const [utmParams, setUtmParams] = React.useState(null);
|
|
9605
|
+
const sessionIdRef = React.useRef(null);
|
|
9606
|
+
const anonymousIdRef = React.useRef(null);
|
|
9607
|
+
const sessionStartRef = React.useRef(Date.now());
|
|
9608
|
+
const originalReferrerRef = React.useRef(null);
|
|
9609
|
+
const idsReadyRef = React.useRef(false);
|
|
9610
|
+
const [sessionId, setSessionId] = React.useState(null);
|
|
9611
|
+
const [anonymousId, setAnonymousId] = React.useState(null);
|
|
9612
|
+
const initialized = React.useRef(false);
|
|
9613
|
+
const landingPage = React.useRef(null);
|
|
9614
|
+
const eventQueue = React.useRef([]);
|
|
9615
|
+
React.useEffect(() => {
|
|
9418
9616
|
if (initialized.current) return;
|
|
9419
9617
|
initialized.current = true;
|
|
9420
9618
|
if (!autoGenerateSessionId) {
|
|
@@ -9438,7 +9636,7 @@ function useAnalytics(options = {}) {
|
|
|
9438
9636
|
}, 0);
|
|
9439
9637
|
}
|
|
9440
9638
|
}, [autoGenerateSessionId, sessionStorageKey, anonymousStorageKey]);
|
|
9441
|
-
|
|
9639
|
+
React.useEffect(() => {
|
|
9442
9640
|
if (typeof window === "undefined") return;
|
|
9443
9641
|
if (shouldAutoCaptureUtmParams) {
|
|
9444
9642
|
const utm = parseUtmParams();
|
|
@@ -9463,11 +9661,11 @@ function useAnalytics(options = {}) {
|
|
|
9463
9661
|
}
|
|
9464
9662
|
}
|
|
9465
9663
|
}, [shouldAutoCaptureUtmParams]);
|
|
9466
|
-
const sendEventRef =
|
|
9467
|
-
const getDeviceInfo =
|
|
9664
|
+
const sendEventRef = React.useRef(null);
|
|
9665
|
+
const getDeviceInfo = React.useCallback(() => {
|
|
9468
9666
|
return detectDeviceInfo();
|
|
9469
9667
|
}, []);
|
|
9470
|
-
const buildFullEvent =
|
|
9668
|
+
const buildFullEvent = React.useCallback(
|
|
9471
9669
|
(event) => {
|
|
9472
9670
|
const device = getDeviceInfo();
|
|
9473
9671
|
const fullEvent = {
|
|
@@ -9507,7 +9705,7 @@ function useAnalytics(options = {}) {
|
|
|
9507
9705
|
// Note: sessionId/anonymousId removed - we use refs to keep this stable
|
|
9508
9706
|
[user, utmParams, getDeviceInfo]
|
|
9509
9707
|
);
|
|
9510
|
-
const sendEvent =
|
|
9708
|
+
const sendEvent = React.useCallback(
|
|
9511
9709
|
async (event) => {
|
|
9512
9710
|
const fullEvent = buildFullEvent(event);
|
|
9513
9711
|
const payload = JSON.stringify(fullEvent);
|
|
@@ -9550,7 +9748,7 @@ function useAnalytics(options = {}) {
|
|
|
9550
9748
|
[client, buildFullEvent, useV2, analyticsProxyUrl, publishableKey, gatewayUrl]
|
|
9551
9749
|
);
|
|
9552
9750
|
sendEventRef.current = sendEvent;
|
|
9553
|
-
const trackEvent =
|
|
9751
|
+
const trackEvent = React.useCallback(
|
|
9554
9752
|
async (event) => {
|
|
9555
9753
|
if (shouldDedup(event.event_name, eventDedupMs, event.properties)) {
|
|
9556
9754
|
return { tracked: 0, session_id: sessionIdRef.current || void 0 };
|
|
@@ -9576,7 +9774,7 @@ function useAnalytics(options = {}) {
|
|
|
9576
9774
|
// Note: idsReady removed - we use ref to keep callback stable
|
|
9577
9775
|
[sendEvent, eventDedupMs]
|
|
9578
9776
|
);
|
|
9579
|
-
const trackPageView =
|
|
9777
|
+
const trackPageView = React.useCallback(
|
|
9580
9778
|
async (data) => {
|
|
9581
9779
|
const pageEvent = {
|
|
9582
9780
|
event_name: "page_viewed",
|
|
@@ -9592,7 +9790,7 @@ function useAnalytics(options = {}) {
|
|
|
9592
9790
|
},
|
|
9593
9791
|
[trackEvent]
|
|
9594
9792
|
);
|
|
9595
|
-
const trackBatch =
|
|
9793
|
+
const trackBatch = React.useCallback(
|
|
9596
9794
|
async (events) => {
|
|
9597
9795
|
setError(null);
|
|
9598
9796
|
setLoading(true);
|
|
@@ -9646,7 +9844,7 @@ function useAnalytics(options = {}) {
|
|
|
9646
9844
|
// Note: sessionId removed - we use ref to keep callback stable
|
|
9647
9845
|
[client, buildFullEvent, useV2, analyticsProxyUrl, publishableKey, gatewayUrl]
|
|
9648
9846
|
);
|
|
9649
|
-
const identify =
|
|
9847
|
+
const identify = React.useCallback(
|
|
9650
9848
|
async (userId, traits) => {
|
|
9651
9849
|
await trackEvent({
|
|
9652
9850
|
event_name: "user_identified",
|
|
@@ -9661,7 +9859,7 @@ function useAnalytics(options = {}) {
|
|
|
9661
9859
|
// Note: anonymousId removed - we use ref
|
|
9662
9860
|
[trackEvent]
|
|
9663
9861
|
);
|
|
9664
|
-
const reset =
|
|
9862
|
+
const reset = React.useCallback(() => {
|
|
9665
9863
|
const newSessionId = generateUUID();
|
|
9666
9864
|
const newSessionStart = Date.now();
|
|
9667
9865
|
sessionIdRef.current = newSessionId;
|
|
@@ -9675,10 +9873,10 @@ function useAnalytics(options = {}) {
|
|
|
9675
9873
|
originalReferrerRef.current = null;
|
|
9676
9874
|
setUtmParams(null);
|
|
9677
9875
|
}, [sessionStorageKey]);
|
|
9678
|
-
const setUtmParamsManual =
|
|
9876
|
+
const setUtmParamsManual = React.useCallback((params) => {
|
|
9679
9877
|
setUtmParams(params);
|
|
9680
9878
|
}, []);
|
|
9681
|
-
return
|
|
9879
|
+
return React.useMemo(
|
|
9682
9880
|
() => ({
|
|
9683
9881
|
loading,
|
|
9684
9882
|
error,
|
|
@@ -9731,8 +9929,8 @@ function useFeatureFlags(options = {}) {
|
|
|
9731
9929
|
enabled = true
|
|
9732
9930
|
} = options;
|
|
9733
9931
|
const { client, publishableKey, gatewayUrl, bootstrapFlags } = smContext;
|
|
9734
|
-
const warnedRef =
|
|
9735
|
-
|
|
9932
|
+
const warnedRef = React.useRef(false);
|
|
9933
|
+
React.useEffect(() => {
|
|
9736
9934
|
if (!warnedRef.current && (!keys || keys.length === 0)) {
|
|
9737
9935
|
warnedRef.current = true;
|
|
9738
9936
|
console.warn(
|
|
@@ -9740,7 +9938,7 @@ function useFeatureFlags(options = {}) {
|
|
|
9740
9938
|
);
|
|
9741
9939
|
}
|
|
9742
9940
|
}, [keys]);
|
|
9743
|
-
const initialFlags =
|
|
9941
|
+
const initialFlags = React.useMemo(() => {
|
|
9744
9942
|
if (!bootstrapFlags) return {};
|
|
9745
9943
|
const result = {};
|
|
9746
9944
|
for (const [key, value] of Object.entries(bootstrapFlags)) {
|
|
@@ -9751,19 +9949,19 @@ function useFeatureFlags(options = {}) {
|
|
|
9751
9949
|
return result;
|
|
9752
9950
|
}, [bootstrapFlags]);
|
|
9753
9951
|
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
|
-
|
|
9952
|
+
const [flags, setFlags] = React.useState(initialFlags);
|
|
9953
|
+
const [loading, setLoading] = React.useState(enabled && !hasBootstrap);
|
|
9954
|
+
const [error, setError] = React.useState(null);
|
|
9955
|
+
const contextRef = React.useRef(context);
|
|
9956
|
+
const keysRef = React.useRef(keys);
|
|
9957
|
+
const keysKey = React.useMemo(() => keys && keys.length > 0 ? [...keys].sort().join("|") : "", [keys]);
|
|
9958
|
+
React.useEffect(() => {
|
|
9761
9959
|
contextRef.current = context;
|
|
9762
9960
|
}, [context]);
|
|
9763
|
-
|
|
9961
|
+
React.useEffect(() => {
|
|
9764
9962
|
keysRef.current = keys;
|
|
9765
9963
|
}, [keys]);
|
|
9766
|
-
const refresh =
|
|
9964
|
+
const refresh = React.useCallback(async () => {
|
|
9767
9965
|
if (!enabled) {
|
|
9768
9966
|
setLoading(false);
|
|
9769
9967
|
return;
|
|
@@ -9799,7 +9997,7 @@ function useFeatureFlags(options = {}) {
|
|
|
9799
9997
|
setLoading(false);
|
|
9800
9998
|
}
|
|
9801
9999
|
}, [client, enabled, environment, keysKey, publishableKey, gatewayUrl]);
|
|
9802
|
-
const bootstrapCoversKeys =
|
|
10000
|
+
const bootstrapCoversKeys = React.useMemo(() => {
|
|
9803
10001
|
if (!hasBootstrap || !keys || keys.length === 0) return false;
|
|
9804
10002
|
if (!keys.every((k) => k in initialFlags)) return false;
|
|
9805
10003
|
if (environment !== (smContext.environment ?? "prod")) return false;
|
|
@@ -9807,12 +10005,12 @@ function useFeatureFlags(options = {}) {
|
|
|
9807
10005
|
if (contextKeys.length > 0) return false;
|
|
9808
10006
|
return true;
|
|
9809
10007
|
}, [hasBootstrap, keys, initialFlags, environment, smContext.environment, context]);
|
|
9810
|
-
|
|
10008
|
+
React.useEffect(() => {
|
|
9811
10009
|
if (!bootstrapCoversKeys) {
|
|
9812
10010
|
void refresh();
|
|
9813
10011
|
}
|
|
9814
10012
|
}, [refresh, bootstrapCoversKeys]);
|
|
9815
|
-
const isEnabled =
|
|
10013
|
+
const isEnabled = React.useCallback(
|
|
9816
10014
|
(flagKey, fallback = false) => {
|
|
9817
10015
|
const evaluation = flags[flagKey];
|
|
9818
10016
|
if (!evaluation) return fallback;
|
|
@@ -9820,7 +10018,7 @@ function useFeatureFlags(options = {}) {
|
|
|
9820
10018
|
},
|
|
9821
10019
|
[flags]
|
|
9822
10020
|
);
|
|
9823
|
-
const getFlag =
|
|
10021
|
+
const getFlag = React.useCallback(
|
|
9824
10022
|
(flagKey, fallback) => {
|
|
9825
10023
|
const evaluation = flags[flagKey];
|
|
9826
10024
|
if (!evaluation) return fallback;
|
|
@@ -9845,18 +10043,18 @@ function getCsrfToken() {
|
|
|
9845
10043
|
function usePushNotifications(options = {}) {
|
|
9846
10044
|
const { serviceWorkerUrl = "/sw.js", pushProxyUrl = "/api/push", registrationSource, onNotification } = options;
|
|
9847
10045
|
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
|
-
|
|
10046
|
+
const [isSupported, setIsSupported] = React.useState(false);
|
|
10047
|
+
const [permission, setPermission] = React.useState("unsupported");
|
|
10048
|
+
const [isSubscribed, setIsSubscribed] = React.useState(false);
|
|
10049
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
10050
|
+
const [error, setError] = React.useState(null);
|
|
10051
|
+
const [tokenId, setTokenId] = React.useState(null);
|
|
10052
|
+
const onNotificationRef = React.useRef(onNotification);
|
|
10053
|
+
React.useEffect(() => {
|
|
9856
10054
|
onNotificationRef.current = onNotification;
|
|
9857
10055
|
}, [onNotification]);
|
|
9858
|
-
const prevUserRef =
|
|
9859
|
-
const fetcher =
|
|
10056
|
+
const prevUserRef = React.useRef(null);
|
|
10057
|
+
const fetcher = React.useMemo(() => {
|
|
9860
10058
|
async function proxyGet(path) {
|
|
9861
10059
|
const res = await fetch(`${pushProxyUrl}/${path}`);
|
|
9862
10060
|
const json = await res.json();
|
|
@@ -9907,7 +10105,7 @@ function usePushNotifications(options = {}) {
|
|
|
9907
10105
|
disassociateUser: (id) => proxyDelete(`tokens/by-id/${id}/user`)
|
|
9908
10106
|
};
|
|
9909
10107
|
}, [pushProxyUrl]);
|
|
9910
|
-
const manager =
|
|
10108
|
+
const manager = React.useMemo(() => {
|
|
9911
10109
|
if (typeof window === "undefined") return null;
|
|
9912
10110
|
try {
|
|
9913
10111
|
return new WebPushManager({ fetcher, serviceWorkerUrl, registrationSource });
|
|
@@ -9915,7 +10113,7 @@ function usePushNotifications(options = {}) {
|
|
|
9915
10113
|
return null;
|
|
9916
10114
|
}
|
|
9917
10115
|
}, [fetcher, serviceWorkerUrl]);
|
|
9918
|
-
|
|
10116
|
+
React.useEffect(() => {
|
|
9919
10117
|
if (!manager) return;
|
|
9920
10118
|
const supported = manager.isSupported();
|
|
9921
10119
|
setIsSupported(supported);
|
|
@@ -9936,7 +10134,7 @@ function usePushNotifications(options = {}) {
|
|
|
9936
10134
|
});
|
|
9937
10135
|
}
|
|
9938
10136
|
}, [manager]);
|
|
9939
|
-
|
|
10137
|
+
React.useEffect(() => {
|
|
9940
10138
|
if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) return;
|
|
9941
10139
|
function handleMessage(event) {
|
|
9942
10140
|
if (event.data?.type === "push-received") {
|
|
@@ -9955,7 +10153,7 @@ function usePushNotifications(options = {}) {
|
|
|
9955
10153
|
navigator.serviceWorker.addEventListener("message", handleMessage);
|
|
9956
10154
|
return () => navigator.serviceWorker.removeEventListener("message", handleMessage);
|
|
9957
10155
|
}, [manager]);
|
|
9958
|
-
|
|
10156
|
+
React.useEffect(() => {
|
|
9959
10157
|
if (!manager) return;
|
|
9960
10158
|
const currentUserId = user?.id || null;
|
|
9961
10159
|
const prevUserId = prevUserRef.current;
|
|
@@ -9965,7 +10163,7 @@ function usePushNotifications(options = {}) {
|
|
|
9965
10163
|
}
|
|
9966
10164
|
prevUserRef.current = currentUserId;
|
|
9967
10165
|
}, [user?.id, manager, isSubscribed]);
|
|
9968
|
-
const subscribe =
|
|
10166
|
+
const subscribe = React.useCallback(async () => {
|
|
9969
10167
|
if (!manager) return;
|
|
9970
10168
|
setIsLoading(true);
|
|
9971
10169
|
setError(null);
|
|
@@ -9987,7 +10185,7 @@ function usePushNotifications(options = {}) {
|
|
|
9987
10185
|
setIsLoading(false);
|
|
9988
10186
|
}
|
|
9989
10187
|
}, [manager]);
|
|
9990
|
-
const unsubscribe =
|
|
10188
|
+
const unsubscribe = React.useCallback(async () => {
|
|
9991
10189
|
if (!manager) return;
|
|
9992
10190
|
setIsLoading(true);
|
|
9993
10191
|
setError(null);
|
|
@@ -10004,7 +10202,7 @@ function usePushNotifications(options = {}) {
|
|
|
10004
10202
|
setIsLoading(false);
|
|
10005
10203
|
}
|
|
10006
10204
|
}, [manager]);
|
|
10007
|
-
const disassociateUser =
|
|
10205
|
+
const disassociateUser = React.useCallback(async () => {
|
|
10008
10206
|
if (!manager) return;
|
|
10009
10207
|
try {
|
|
10010
10208
|
await manager.disassociateUser();
|
|
@@ -10025,12 +10223,12 @@ function usePushNotifications(options = {}) {
|
|
|
10025
10223
|
}
|
|
10026
10224
|
function useShare(options) {
|
|
10027
10225
|
const { client, user } = useScaleMule();
|
|
10028
|
-
const [referralCode, setReferralCode] =
|
|
10226
|
+
const [referralCode, setReferralCode] = React.useState(
|
|
10029
10227
|
options?.referralCode ?? null
|
|
10030
10228
|
);
|
|
10031
|
-
const [loading, setLoading] =
|
|
10032
|
-
const [copied, setCopied] =
|
|
10033
|
-
|
|
10229
|
+
const [loading, setLoading] = React.useState(false);
|
|
10230
|
+
const [copied, setCopied] = React.useState(false);
|
|
10231
|
+
React.useEffect(() => {
|
|
10034
10232
|
if (!user) {
|
|
10035
10233
|
setReferralCode(options?.referralCode ?? null);
|
|
10036
10234
|
setLoading(false);
|
|
@@ -10059,7 +10257,7 @@ function useShare(options) {
|
|
|
10059
10257
|
cancelled = true;
|
|
10060
10258
|
};
|
|
10061
10259
|
}, [user?.id, options?.url, options?.referralCode, options?.autoFetchReferral, client]);
|
|
10062
|
-
const shareUrl =
|
|
10260
|
+
const shareUrl = React.useMemo(() => {
|
|
10063
10261
|
const raw = options?.url || (typeof window !== "undefined" ? window.location.href : "");
|
|
10064
10262
|
if (!raw) return raw;
|
|
10065
10263
|
try {
|
|
@@ -10073,7 +10271,7 @@ function useShare(options) {
|
|
|
10073
10271
|
return raw;
|
|
10074
10272
|
}
|
|
10075
10273
|
}, [options?.url, referralCode]);
|
|
10076
|
-
const copyLink =
|
|
10274
|
+
const copyLink = React.useCallback(async () => {
|
|
10077
10275
|
try {
|
|
10078
10276
|
await navigator.clipboard.writeText(shareUrl);
|
|
10079
10277
|
} catch {
|
|
@@ -10112,10 +10310,10 @@ function toApiError2(error) {
|
|
|
10112
10310
|
function useFeedback(options = {}) {
|
|
10113
10311
|
const { client } = useScaleMule();
|
|
10114
10312
|
const { status, type, enabled = true } = options;
|
|
10115
|
-
const [items, setItems] =
|
|
10116
|
-
const [loading, setLoading] =
|
|
10117
|
-
const [error, setError] =
|
|
10118
|
-
const refresh =
|
|
10313
|
+
const [items, setItems] = React.useState([]);
|
|
10314
|
+
const [loading, setLoading] = React.useState(enabled);
|
|
10315
|
+
const [error, setError] = React.useState(null);
|
|
10316
|
+
const refresh = React.useCallback(async () => {
|
|
10119
10317
|
if (!enabled) {
|
|
10120
10318
|
setLoading(false);
|
|
10121
10319
|
return;
|
|
@@ -10136,10 +10334,10 @@ function useFeedback(options = {}) {
|
|
|
10136
10334
|
setLoading(false);
|
|
10137
10335
|
}
|
|
10138
10336
|
}, [client, enabled, status, type]);
|
|
10139
|
-
|
|
10337
|
+
React.useEffect(() => {
|
|
10140
10338
|
refresh();
|
|
10141
10339
|
}, [refresh]);
|
|
10142
|
-
const submit =
|
|
10340
|
+
const submit = React.useCallback(
|
|
10143
10341
|
async (input) => {
|
|
10144
10342
|
try {
|
|
10145
10343
|
const created = await client.post("/v1/feedback/submit", input);
|
|
@@ -10272,18 +10470,18 @@ function FeedbackWidget(props) {
|
|
|
10272
10470
|
const sm = useScaleMule();
|
|
10273
10471
|
const { client } = sm;
|
|
10274
10472
|
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] =
|
|
10473
|
+
const [serverConfig, setServerConfig] = React.useState(null);
|
|
10474
|
+
const [configLoaded, setConfigLoaded] = React.useState(false);
|
|
10475
|
+
const [open, setOpen] = React.useState(false);
|
|
10476
|
+
const [type, setType] = React.useState("feature_request");
|
|
10477
|
+
const [title, setTitle] = React.useState("");
|
|
10478
|
+
const [description, setDescription] = React.useState("");
|
|
10479
|
+
const [email, setEmail] = React.useState("");
|
|
10480
|
+
const [rating, setRating] = React.useState(null);
|
|
10481
|
+
const [hoverRating, setHoverRating] = React.useState(null);
|
|
10482
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
10483
|
+
const [errMsg, setErrMsg] = React.useState(null);
|
|
10484
|
+
const [done, setDone] = React.useState(false);
|
|
10287
10485
|
const signedIn = Boolean(sm.user);
|
|
10288
10486
|
const resolvedAllowedTypes = props.allowedTypes ?? serverConfig?.allowed_types ?? ALL_TYPES;
|
|
10289
10487
|
const resolvedDefaultType = (props.defaultType && resolvedAllowedTypes.includes(props.defaultType) ? props.defaultType : resolvedAllowedTypes[0]) ?? "feature_request";
|
|
@@ -10291,7 +10489,7 @@ function FeedbackWidget(props) {
|
|
|
10291
10489
|
const resolvedTheme = props.theme ?? serverConfig?.widget_theme ?? "auto";
|
|
10292
10490
|
const allowAnonymous = serverConfig?.allow_anonymous ?? true;
|
|
10293
10491
|
const anonymousBlocked = !signedIn && !allowAnonymous;
|
|
10294
|
-
|
|
10492
|
+
React.useEffect(() => {
|
|
10295
10493
|
let active = true;
|
|
10296
10494
|
client.get("/v1/feedback/widget-config").then((config) => {
|
|
10297
10495
|
if (active) setServerConfig(config);
|
|
@@ -10304,7 +10502,7 @@ function FeedbackWidget(props) {
|
|
|
10304
10502
|
active = false;
|
|
10305
10503
|
};
|
|
10306
10504
|
}, [client]);
|
|
10307
|
-
|
|
10505
|
+
React.useEffect(() => {
|
|
10308
10506
|
setType(
|
|
10309
10507
|
(current) => resolvedAllowedTypes.includes(current) ? current : resolvedDefaultType
|
|
10310
10508
|
);
|
|
@@ -10827,6 +11025,7 @@ Object.defineProperty(exports, "createMoneyClient", {
|
|
|
10827
11025
|
exports.FeedbackWidget = FeedbackWidget;
|
|
10828
11026
|
exports.ScaleMuleApiError = ScaleMuleApiError;
|
|
10829
11027
|
exports.ScaleMuleClient = ScaleMuleClient2;
|
|
11028
|
+
exports.ScaleMuleMedia = ScaleMuleMedia;
|
|
10830
11029
|
exports.ScaleMuleProvider = ScaleMuleProvider;
|
|
10831
11030
|
exports.composePhone = composePhone;
|
|
10832
11031
|
exports.createClient = createClient;
|