@frontegg/react-hooks 7.0.0-alpha.1 → 7.0.0-alpha.3
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/FronteggProvider/FronteggProvider.d.ts +12 -0
- package/FronteggProvider/FronteggProvider.js +140 -0
- package/FronteggProvider/index.d.ts +1 -12
- package/FronteggProvider/index.js +1 -133
- package/FronteggStoreContext/FronteggStoreContext.d.ts +9 -0
- package/FronteggStoreContext/FronteggStoreContext.js +16 -0
- package/FronteggStoreContext/index.d.ts +1 -13
- package/FronteggStoreContext/index.js +1 -14
- package/audits/auditLogs.d.ts +2 -4
- package/audits/auditLogs.js +8 -6
- package/audits/auditsMetadata.d.ts +2 -4
- package/audits/auditsMetadata.js +8 -6
- package/audits/hooks.d.ts +0 -8
- package/audits/hooks.js +6 -30
- package/auth/acceptInvitation.js +10 -5
- package/auth/activateAccount.js +10 -4
- package/auth/{MSP/allAccounts.d.ts → allAccounts.d.ts} +2 -4
- package/auth/allAccounts.js +20 -0
- package/auth/apiTokens.d.ts +0 -2
- package/auth/apiTokens.js +8 -6
- package/auth/applications.d.ts +3 -0
- package/auth/applications.js +9 -0
- package/auth/customLogin.d.ts +2 -5
- package/auth/customLogin.js +10 -11
- package/auth/entitlements.d.ts +32 -13
- package/auth/entitlements.js +103 -21
- package/auth/forgotPassword.d.ts +0 -2
- package/auth/forgotPassword.js +8 -6
- package/auth/groups.d.ts +0 -4
- package/auth/groups.js +12 -13
- package/auth/hooks.d.ts +44 -12
- package/auth/hooks.js +73 -62
- package/auth/impersonate.d.ts +0 -2
- package/auth/impersonate.js +7 -6
- package/auth/index.d.ts +16 -16
- package/auth/index.js +16 -16
- package/auth/login.d.ts +1 -3
- package/auth/login.js +7 -6
- package/auth/mfa.d.ts +1 -1
- package/auth/mfa.js +13 -4
- package/auth/passkeys.d.ts +1 -4
- package/auth/passkeys.js +7 -6
- package/auth/profile.d.ts +2 -4
- package/auth/profile.js +9 -8
- package/auth/provisioning.d.ts +1 -3
- package/auth/provisioning.js +7 -6
- package/auth/resetPhoneNumber.d.ts +1 -3
- package/auth/resetPhoneNumber.js +7 -6
- package/auth/roles.d.ts +1 -3
- package/auth/roles.js +7 -6
- package/auth/security/index.d.ts +4 -0
- package/auth/security/index.js +4 -0
- package/auth/security/restrictions.d.ts +0 -2
- package/auth/security/restrictions.js +10 -10
- package/auth/security/securityCenter.d.ts +1 -4
- package/auth/security/securityCenter.js +8 -6
- package/auth/security/securityPolicy.d.ts +5 -11
- package/auth/security/securityPolicy.js +19 -30
- package/auth/security/sessionsPolicy.d.ts +1 -3
- package/auth/security/sessionsPolicy.js +8 -6
- package/auth/sessions.d.ts +1 -3
- package/auth/sessions.js +7 -6
- package/auth/signup.d.ts +1 -1
- package/auth/signup.js +13 -4
- package/auth/sms.d.ts +3 -0
- package/auth/sms.js +8 -0
- package/auth/socialLogin.d.ts +1 -1
- package/auth/socialLogin.js +10 -4
- package/auth/sso.d.ts +1 -1
- package/auth/sso.js +10 -4
- package/auth/stepUp.d.ts +16 -0
- package/auth/stepUp.js +51 -0
- package/auth/team.d.ts +9 -1
- package/auth/team.js +22 -4
- package/auth/tenants.d.ts +1 -3
- package/auth/tenants.js +8 -6
- package/common/CustomComponentHolder.js +3 -1
- package/common/index.d.ts +1 -0
- package/common/index.js +3 -3
- package/connectivity/hooks.d.ts +2 -5
- package/connectivity/hooks.js +6 -9
- package/index.d.ts +2 -2
- package/index.js +3 -3
- package/node/FronteggProvider/FronteggProvider.js +148 -0
- package/node/FronteggProvider/index.js +9 -134
- package/node/FronteggStoreContext/FronteggStoreContext.js +28 -0
- package/node/FronteggStoreContext/index.js +11 -35
- package/node/audits/auditLogs.js +8 -6
- package/node/audits/auditsMetadata.js +8 -6
- package/node/audits/hooks.js +7 -34
- package/node/auth/acceptInvitation.js +7 -5
- package/node/auth/activateAccount.js +7 -4
- package/node/auth/allAccounts.js +27 -0
- package/node/auth/apiTokens.js +8 -6
- package/node/auth/applications.js +17 -0
- package/node/auth/customLogin.js +11 -12
- package/node/auth/entitlements.js +106 -22
- package/node/auth/forgotPassword.js +8 -6
- package/node/auth/groups.js +12 -12
- package/node/auth/hooks.js +77 -67
- package/node/auth/impersonate.js +7 -6
- package/node/auth/index.js +107 -93
- package/node/auth/login.js +7 -6
- package/node/auth/mfa.js +10 -4
- package/node/auth/passkeys.js +7 -6
- package/node/auth/profile.js +10 -9
- package/node/auth/provisioning.js +7 -6
- package/node/auth/resetPhoneNumber.js +7 -6
- package/node/auth/roles.js +7 -6
- package/node/auth/security/index.js +49 -0
- package/node/auth/security/restrictions.js +10 -10
- package/node/auth/security/securityCenter.js +8 -6
- package/node/auth/security/securityPolicy.js +16 -30
- package/node/auth/security/sessionsPolicy.js +8 -6
- package/node/auth/sessions.js +7 -6
- package/node/auth/signup.js +10 -4
- package/node/auth/sms.js +16 -0
- package/node/auth/socialLogin.js +7 -4
- package/node/auth/sso.js +7 -4
- package/node/auth/stepUp.js +62 -0
- package/node/auth/team.js +25 -4
- package/node/auth/tenants.js +8 -6
- package/node/common/CustomComponentHolder.js +3 -1
- package/node/common/index.js +2 -2
- package/node/connectivity/hooks.js +5 -8
- package/node/index.js +16 -16
- package/node/subscriptions/hooks.js +84 -51
- package/node/tests/hooks.tsc-test.js +339 -0
- package/node/useSnapshot/index.js +137 -0
- package/node/vendor/hooks.js +5 -6
- package/package.json +3 -3
- package/subscriptions/hooks.d.ts +32 -10
- package/subscriptions/hooks.js +81 -49
- package/tests/hooks.tsc-test.js +338 -0
- package/useSnapshot/index.d.ts +78 -0
- package/useSnapshot/index.js +128 -0
- package/useSnapshot/package.json +6 -0
- package/vendor/hooks.d.ts +0 -1
- package/vendor/hooks.js +9 -7
- package/auth/MSP/allAccounts.js +0 -15
- package/node/auth/MSP/allAccounts.js +0 -24
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _ = require("../");
|
|
4
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
5
|
+
// noinspection JSUnusedLocalSymbols
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* useAuth hook typescript tests
|
|
9
|
+
*/
|
|
10
|
+
{
|
|
11
|
+
const {
|
|
12
|
+
isAuthenticated,
|
|
13
|
+
isLoading
|
|
14
|
+
} = (0, _.useAuth)();
|
|
15
|
+
const isLoadingDirect = (0, _.useAuth)(state => state.isLoading);
|
|
16
|
+
isLoadingDirect.valueOf();
|
|
17
|
+
const {
|
|
18
|
+
user
|
|
19
|
+
} = (0, _.useAuth)(state => ({
|
|
20
|
+
user: state.user
|
|
21
|
+
}));
|
|
22
|
+
const {
|
|
23
|
+
loginUrl
|
|
24
|
+
} = (0, _.useAuth)(state => state.routes);
|
|
25
|
+
const {
|
|
26
|
+
loadProfile,
|
|
27
|
+
setLoginState
|
|
28
|
+
} = (0, _.useAuthActions)();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* useAcceptInvitationState hook typescript tests
|
|
33
|
+
*/
|
|
34
|
+
{
|
|
35
|
+
const {
|
|
36
|
+
step
|
|
37
|
+
} = (0, _.useAcceptInvitationState)();
|
|
38
|
+
const errorDirect = (0, _.useAcceptInvitationState)(state => state.error);
|
|
39
|
+
errorDirect == null ? void 0 : errorDirect.substring(0);
|
|
40
|
+
const {
|
|
41
|
+
acceptInvitation
|
|
42
|
+
} = (0, _.useAcceptInvitationActions)();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* useActivateAccountState hook typescript tests
|
|
47
|
+
*/
|
|
48
|
+
{
|
|
49
|
+
const {
|
|
50
|
+
step
|
|
51
|
+
} = (0, _.useActivateAccountState)();
|
|
52
|
+
const loadingDirect = (0, _.useActivateAccountState)(state => state.loading);
|
|
53
|
+
loadingDirect.valueOf();
|
|
54
|
+
const {
|
|
55
|
+
activateAccount
|
|
56
|
+
} = (0, _.useActivateAccountActions)();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* useApiTokensState hook typescript tests
|
|
61
|
+
*/
|
|
62
|
+
{
|
|
63
|
+
const {
|
|
64
|
+
roles
|
|
65
|
+
} = (0, _.useApiTokensState)();
|
|
66
|
+
const {
|
|
67
|
+
loaders: loadingDirect
|
|
68
|
+
} = (0, _.useApiTokensState)();
|
|
69
|
+
const m = loadingDirect.LOAD_API_TOKENS;
|
|
70
|
+
const {
|
|
71
|
+
loadUserApiTokens
|
|
72
|
+
} = (0, _.useApiTokensActions)();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* useForgotPasswordState hook typescript tests
|
|
77
|
+
*/
|
|
78
|
+
{
|
|
79
|
+
const {
|
|
80
|
+
step
|
|
81
|
+
} = (0, _.useForgotPasswordState)();
|
|
82
|
+
const {
|
|
83
|
+
email: emailDirect
|
|
84
|
+
} = (0, _.useForgotPasswordState)();
|
|
85
|
+
emailDirect.substring(0);
|
|
86
|
+
const {
|
|
87
|
+
forgotPassword
|
|
88
|
+
} = (0, _.useForgotPasswordActions)();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* useMfaState hook typescript tests
|
|
93
|
+
*/
|
|
94
|
+
{
|
|
95
|
+
const {
|
|
96
|
+
step
|
|
97
|
+
} = (0, _.useMfaState)();
|
|
98
|
+
const loadingDirect = (0, _.useMfaState)(state => state.loading);
|
|
99
|
+
loadingDirect.valueOf();
|
|
100
|
+
const {
|
|
101
|
+
enrollMfa
|
|
102
|
+
} = (0, _.useMfaActions)();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* useLoginState hook typescript tests
|
|
107
|
+
*/
|
|
108
|
+
{
|
|
109
|
+
const {
|
|
110
|
+
step
|
|
111
|
+
} = (0, _.useLoginState)();
|
|
112
|
+
const {
|
|
113
|
+
loading: loadingDirect
|
|
114
|
+
} = (0, _.useLoginState)();
|
|
115
|
+
loadingDirect.valueOf();
|
|
116
|
+
const {
|
|
117
|
+
logout
|
|
118
|
+
} = (0, _.useLoginActions)();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* useLoginState hook typescript tests
|
|
123
|
+
*/
|
|
124
|
+
{
|
|
125
|
+
const {
|
|
126
|
+
profile
|
|
127
|
+
} = (0, _.useProfileState)();
|
|
128
|
+
const {
|
|
129
|
+
loading: loadingDirect
|
|
130
|
+
} = (0, _.useProfileState)();
|
|
131
|
+
loadingDirect.valueOf();
|
|
132
|
+
const {
|
|
133
|
+
loadProfile
|
|
134
|
+
} = (0, _.useProfileActions)();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* useResetPhoneNumberState hook typescript tests
|
|
139
|
+
*/
|
|
140
|
+
{
|
|
141
|
+
const {
|
|
142
|
+
step
|
|
143
|
+
} = (0, _.useResetPhoneNumberState)();
|
|
144
|
+
const {
|
|
145
|
+
loading: loadingDirect
|
|
146
|
+
} = (0, _.useResetPhoneNumberState)();
|
|
147
|
+
loadingDirect.valueOf();
|
|
148
|
+
const {
|
|
149
|
+
resetPhoneNumber
|
|
150
|
+
} = (0, _.useResetPhoneNumberActions)();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* useRolesState hook typescript tests
|
|
155
|
+
*/
|
|
156
|
+
{
|
|
157
|
+
var _loadingDirect$loadRo;
|
|
158
|
+
const {
|
|
159
|
+
saving
|
|
160
|
+
} = (0, _.useRolesState)();
|
|
161
|
+
const {
|
|
162
|
+
loaders: loadingDirect
|
|
163
|
+
} = (0, _.useRolesState)();
|
|
164
|
+
loadingDirect == null ? void 0 : (_loadingDirect$loadRo = loadingDirect.loadRoles) == null ? void 0 : _loadingDirect$loadRo.valueOf();
|
|
165
|
+
const {
|
|
166
|
+
loadRolesAndPermissions
|
|
167
|
+
} = (0, _.useRolesActions)();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* useSecurityPolicyState hook typescript tests
|
|
172
|
+
*/
|
|
173
|
+
{
|
|
174
|
+
const {
|
|
175
|
+
lockoutPolicy
|
|
176
|
+
} = (0, _.useSecurityPolicyState)();
|
|
177
|
+
const captchaPolicy = (0, _.useSecurityPolicyState)(state => state.captchaPolicy);
|
|
178
|
+
captchaPolicy.loading.valueOf();
|
|
179
|
+
const {
|
|
180
|
+
loadPublicSecurityPolicy
|
|
181
|
+
} = (0, _.useSecurityPolicyActions)();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* useSessionsState hook typescript tests
|
|
186
|
+
*/
|
|
187
|
+
{
|
|
188
|
+
const {
|
|
189
|
+
sessions
|
|
190
|
+
} = (0, _.useSessionsState)();
|
|
191
|
+
const {
|
|
192
|
+
loading: loadingDirect
|
|
193
|
+
} = (0, _.useSessionsState)();
|
|
194
|
+
loadingDirect.valueOf();
|
|
195
|
+
const {
|
|
196
|
+
deleteUserSession
|
|
197
|
+
} = (0, _.useSessionsActions)();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* useSessionsPolicyState hook typescript tests
|
|
202
|
+
*/
|
|
203
|
+
{
|
|
204
|
+
const {
|
|
205
|
+
configurations
|
|
206
|
+
} = (0, _.useSessionsPolicyState)();
|
|
207
|
+
const {
|
|
208
|
+
loading: loadingDirect
|
|
209
|
+
} = (0, _.useSessionsPolicyState)();
|
|
210
|
+
loadingDirect.valueOf();
|
|
211
|
+
const {
|
|
212
|
+
resetSessionsPolicyState
|
|
213
|
+
} = (0, _.useSessionsPolicyActions)();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* useSSOState hook typescript tests
|
|
218
|
+
*/
|
|
219
|
+
{
|
|
220
|
+
const {
|
|
221
|
+
authorizationRoles
|
|
222
|
+
} = (0, _.useSSOState)();
|
|
223
|
+
const {
|
|
224
|
+
loading: loadingDirect
|
|
225
|
+
} = (0, _.useSSOState)();
|
|
226
|
+
loadingDirect.valueOf();
|
|
227
|
+
const {
|
|
228
|
+
loadSSOConfigurationsV2
|
|
229
|
+
} = (0, _.useSSOActions)();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* useSignUpState hook typescript tests
|
|
234
|
+
*/
|
|
235
|
+
{
|
|
236
|
+
const {
|
|
237
|
+
stage
|
|
238
|
+
} = (0, _.useSignUpState)();
|
|
239
|
+
const loadingDirect = (0, _.useSignUpState)(state => state.loading);
|
|
240
|
+
loadingDirect.valueOf();
|
|
241
|
+
const {
|
|
242
|
+
setSignUpState
|
|
243
|
+
} = (0, _.useSignUpActions)();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* useSocialLoginState hook typescript tests
|
|
248
|
+
*/
|
|
249
|
+
{
|
|
250
|
+
const {
|
|
251
|
+
socialLoginsConfig
|
|
252
|
+
} = (0, _.useSocialLoginState)();
|
|
253
|
+
const loadingDirect = (0, _.useSocialLoginState)(state => state.loading);
|
|
254
|
+
loadingDirect.valueOf();
|
|
255
|
+
const {
|
|
256
|
+
loadSocialLoginsConfiguration
|
|
257
|
+
} = (0, _.useSocialLoginActions)();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* useSocialLoginState hook typescript tests
|
|
262
|
+
*/
|
|
263
|
+
{
|
|
264
|
+
const {
|
|
265
|
+
tenants
|
|
266
|
+
} = (0, _.useTenantsState)();
|
|
267
|
+
const {
|
|
268
|
+
loading: loadingDirect
|
|
269
|
+
} = (0, _.useTenantsState)();
|
|
270
|
+
loadingDirect.valueOf();
|
|
271
|
+
const {
|
|
272
|
+
loadTenants
|
|
273
|
+
} = (0, _.useTenantsActions)();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* useVendorState hook typescript tests
|
|
278
|
+
*/
|
|
279
|
+
{
|
|
280
|
+
const {
|
|
281
|
+
loading
|
|
282
|
+
} = (0, _.useVendorState)();
|
|
283
|
+
const {
|
|
284
|
+
loading: isLoadingDirect
|
|
285
|
+
} = (0, _.useVendorState)();
|
|
286
|
+
isLoadingDirect.valueOf();
|
|
287
|
+
const {
|
|
288
|
+
whiteLabelMode
|
|
289
|
+
} = (0, _.useVendorState)(state => ({
|
|
290
|
+
whiteLabelMode: state.whiteLabelMode
|
|
291
|
+
}));
|
|
292
|
+
const {
|
|
293
|
+
loadVendorPublicInfo
|
|
294
|
+
} = (0, _.useVendorActions)();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* useConnectivityState hook typescript tests
|
|
299
|
+
*/
|
|
300
|
+
{
|
|
301
|
+
const {
|
|
302
|
+
isLoading,
|
|
303
|
+
error
|
|
304
|
+
} = (0, _.useConnectivityState)();
|
|
305
|
+
const {
|
|
306
|
+
processIds
|
|
307
|
+
} = (0, _.useConnectivityState)();
|
|
308
|
+
processIds.map(id => id);
|
|
309
|
+
const {
|
|
310
|
+
email = []
|
|
311
|
+
} = (0, _.useConnectivityState)();
|
|
312
|
+
email.length;
|
|
313
|
+
const {
|
|
314
|
+
loadScope,
|
|
315
|
+
loadDataAction
|
|
316
|
+
} = (0, _.useConnectivityActions)();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* useAuditsState hook typescript tests
|
|
321
|
+
*/
|
|
322
|
+
{
|
|
323
|
+
const {
|
|
324
|
+
auditLogsState
|
|
325
|
+
} = (0, _.useAuditsState)();
|
|
326
|
+
const {
|
|
327
|
+
columns
|
|
328
|
+
} = (0, _.useAuditsState)(state => state.auditsMetadataState);
|
|
329
|
+
const {
|
|
330
|
+
loading
|
|
331
|
+
} = (0, _.useAuditsState)(state => ({
|
|
332
|
+
loading: state.auditLogsState.loading
|
|
333
|
+
}));
|
|
334
|
+
loading.valueOf();
|
|
335
|
+
const x = columns == null ? void 0 : columns.length;
|
|
336
|
+
const {
|
|
337
|
+
loadAuditLogs
|
|
338
|
+
} = (0, _.useAuditsActions)();
|
|
339
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useSnapshot = useSnapshot;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _proxyCompare = require("proxy-compare");
|
|
10
|
+
var _shim = _interopRequireDefault(require("use-sync-external-store/shim"));
|
|
11
|
+
var _reduxStore = require("@frontegg/redux-store");
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
/// <reference types="react/experimental" />
|
|
15
|
+
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
useSyncExternalStore
|
|
20
|
+
} = _shim.default;
|
|
21
|
+
const useAffectedDebugValue = (state, affected) => {
|
|
22
|
+
const pathList = (0, _react.useRef)();
|
|
23
|
+
(0, _react.useEffect)(() => {
|
|
24
|
+
pathList.current = (0, _proxyCompare.affectedToPathList)(state, affected, true);
|
|
25
|
+
});
|
|
26
|
+
(0, _react.useDebugValue)(pathList.current);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// This is required only for performance.
|
|
30
|
+
// Ref: https://github.com/pmndrs/valtio/issues/519
|
|
31
|
+
const targetCache = new WeakMap();
|
|
32
|
+
/**
|
|
33
|
+
* useSnapshot
|
|
34
|
+
*
|
|
35
|
+
* Create a local snapshot that catches changes. This hook actually returns a wrapped snapshot in a proxy for
|
|
36
|
+
* render optimization instead of a plain object compared to `snapshot()` method.
|
|
37
|
+
* Rule of thumb: read from snapshots, mutate the source.
|
|
38
|
+
* The component will only re-render when the parts of the state you access have changed, it is render-optimized.
|
|
39
|
+
*
|
|
40
|
+
* @example A
|
|
41
|
+
* function Counter() {
|
|
42
|
+
* const snap = useSnapshot(state)
|
|
43
|
+
* return (
|
|
44
|
+
* <div>
|
|
45
|
+
* {snap.count}
|
|
46
|
+
* <button onClick={() => ++state.count}>+1</button>
|
|
47
|
+
* </div>
|
|
48
|
+
* )
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* [Notes]
|
|
52
|
+
* Every object inside your proxy also becomes a proxy (if you don't use "ref"), so you can also use them to create
|
|
53
|
+
* the local snapshot as seen on example B.
|
|
54
|
+
*
|
|
55
|
+
* @example B
|
|
56
|
+
* function ProfileName() {
|
|
57
|
+
* const snap = useSnapshot(state.profile)
|
|
58
|
+
* return (
|
|
59
|
+
* <div>
|
|
60
|
+
* {snap.name}
|
|
61
|
+
* </div>
|
|
62
|
+
* )
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* Beware that you still can replace the child proxy with something else so it will break your snapshot. You can see
|
|
66
|
+
* above what happens with the original proxy when you replace the child proxy.
|
|
67
|
+
*
|
|
68
|
+
* > console.log(state)
|
|
69
|
+
* { profile: { name: "valtio" } }
|
|
70
|
+
* > childState = state.profile
|
|
71
|
+
* > console.log(childState)
|
|
72
|
+
* { name: "valtio" }
|
|
73
|
+
* > state.profile.name = "react"
|
|
74
|
+
* > console.log(childState)
|
|
75
|
+
* { name: "react" }
|
|
76
|
+
* > state.profile = { name: "new name" }
|
|
77
|
+
* > console.log(childState)
|
|
78
|
+
* { name: "react" }
|
|
79
|
+
* > console.log(state)
|
|
80
|
+
* { profile: { name: "new name" } }
|
|
81
|
+
*
|
|
82
|
+
* `useSnapshot()` depends on the original reference of the child proxy so if you replace it with a new one, the component
|
|
83
|
+
* that is subscribed to the old proxy won't receive new updates because it is still subscribed to the old one.
|
|
84
|
+
*
|
|
85
|
+
* In this case we recommend the example C or D. On both examples you don't need to worry with re-render,
|
|
86
|
+
* because it is render-optimized.
|
|
87
|
+
*
|
|
88
|
+
* @example C
|
|
89
|
+
* const snap = useSnapshot(state)
|
|
90
|
+
* return (
|
|
91
|
+
* <div>
|
|
92
|
+
* {snap.profile.name}
|
|
93
|
+
* </div>
|
|
94
|
+
* )
|
|
95
|
+
*
|
|
96
|
+
* @example D
|
|
97
|
+
* const { profile } = useSnapshot(state)
|
|
98
|
+
* return (
|
|
99
|
+
* <div>
|
|
100
|
+
* {profile.name}
|
|
101
|
+
* </div>
|
|
102
|
+
* )
|
|
103
|
+
*/
|
|
104
|
+
function useSnapshot(proxyObject, options) {
|
|
105
|
+
const notifyInSync = options == null ? void 0 : options.sync;
|
|
106
|
+
const lastSnapshot = (0, _react.useRef)();
|
|
107
|
+
const lastAffected = (0, _react.useRef)();
|
|
108
|
+
let inRender = true;
|
|
109
|
+
const currSnapshot = useSyncExternalStore((0, _react.useCallback)(callback => {
|
|
110
|
+
const unsub = (0, _reduxStore.subscribe)(proxyObject, callback, notifyInSync);
|
|
111
|
+
callback(); // Note: do we really need this?
|
|
112
|
+
return unsub;
|
|
113
|
+
}, [proxyObject, notifyInSync]), () => {
|
|
114
|
+
const nextSnapshot = (0, _reduxStore.snapshot)(proxyObject, _react.default.use);
|
|
115
|
+
try {
|
|
116
|
+
if (!inRender && lastSnapshot.current && lastAffected.current && !(0, _proxyCompare.isChanged)(lastSnapshot.current, nextSnapshot, lastAffected.current, new WeakMap())) {
|
|
117
|
+
// not changed
|
|
118
|
+
return lastSnapshot.current;
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
// ignore if a promise or something is thrown
|
|
122
|
+
}
|
|
123
|
+
return nextSnapshot;
|
|
124
|
+
}, () => (0, _reduxStore.snapshot)(proxyObject, _react.default.use));
|
|
125
|
+
inRender = false;
|
|
126
|
+
const currAffected = new WeakMap();
|
|
127
|
+
(0, _react.useEffect)(() => {
|
|
128
|
+
lastSnapshot.current = currSnapshot;
|
|
129
|
+
lastAffected.current = currAffected;
|
|
130
|
+
});
|
|
131
|
+
// if (import.meta.env?.MODE !== 'production') {
|
|
132
|
+
// // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
133
|
+
// useAffectedDebugValue(currSnapshot, currAffected)
|
|
134
|
+
// }
|
|
135
|
+
const proxyCache = (0, _react.useMemo)(() => new WeakMap(), []); // per-hook proxyCache
|
|
136
|
+
return (0, _proxyCompare.createProxy)(currSnapshot, currAffected, proxyCache, targetCache);
|
|
137
|
+
}
|
package/node/vendor/hooks.js
CHANGED
|
@@ -5,16 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useVendorActions = void 0;
|
|
7
7
|
exports.useVendorState = useVendorState;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
var _reactRedux = require("react-redux");
|
|
11
8
|
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
9
|
+
var _useSnapshot = require("../useSnapshot");
|
|
12
10
|
const defaultMapper = state => state;
|
|
11
|
+
// @deprecated use useVendorState() instead
|
|
13
12
|
function useVendorState(stateMapper = defaultMapper) {
|
|
14
|
-
|
|
13
|
+
const state = (0, _FronteggStoreContext.useStore)().store.vendor;
|
|
14
|
+
return stateMapper((0, _useSnapshot.useSnapshot)(state));
|
|
15
15
|
}
|
|
16
16
|
const useVendorActions = () => {
|
|
17
|
-
|
|
18
|
-
return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.vendorActions, dispatch), [_reduxStore.vendorActions]);
|
|
17
|
+
return (0, _FronteggStoreContext.useStore)().stateActions.vendor;
|
|
19
18
|
};
|
|
20
19
|
exports.useVendorActions = useVendorActions;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.3",
|
|
4
4
|
"main": "./node/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Frontegg LTD",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/runtime": "^7.18.6",
|
|
9
|
-
"@frontegg/redux-store": "7.0.0-alpha.
|
|
10
|
-
"@frontegg/types": "7.0.0-alpha.
|
|
9
|
+
"@frontegg/redux-store": "7.0.0-alpha.3",
|
|
10
|
+
"@frontegg/types": "7.0.0-alpha.3",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|
package/subscriptions/hooks.d.ts
CHANGED
|
@@ -1,21 +1,43 @@
|
|
|
1
|
-
import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState,
|
|
1
|
+
import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState, SubscriptionState, BillingInformationState, InvoicesState, PaymentMethodState, BillingStateActions, VendorPublicConfigurationState, VendorPublicConfigurationActions } from '@frontegg/redux-store';
|
|
2
2
|
export declare const usePaymentProvider: () => PaymentProviderConfigState;
|
|
3
3
|
export declare const usePaymentProviderActions: () => PaymentProviderConfigActions;
|
|
4
4
|
export declare const usePlans: () => PlansState;
|
|
5
5
|
export declare const usePlansActions: () => PlansActions;
|
|
6
6
|
export declare const useCheckout: () => CheckoutState;
|
|
7
7
|
export declare const useCheckoutActions: () => CheckoutActions;
|
|
8
|
-
export declare const useBillingInformation: () =>
|
|
9
|
-
export declare const useBillingInformationActions: () =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare const
|
|
8
|
+
export declare const useBillingInformation: () => BillingInformationState;
|
|
9
|
+
export declare const useBillingInformationActions: () => {
|
|
10
|
+
setBillingInformationState: (state: Partial<BillingInformationState>) => void;
|
|
11
|
+
resetBillingInformationState: () => void;
|
|
12
|
+
loadSummaries: (tenantId: string, forceActive?: boolean | undefined) => Promise<void>;
|
|
13
|
+
loadBillingInformation: (forceActive?: boolean | undefined) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
export declare const usePaymentMethod: () => PaymentMethodState;
|
|
16
|
+
export declare const usePaymentMethodActions: () => {
|
|
17
|
+
setBillingPaymentMethodState: (state: Partial<{}>) => void;
|
|
18
|
+
resetBillingPaymentMethodState: () => void;
|
|
19
|
+
loadPaymentMethod: () => Promise<void>;
|
|
20
|
+
submitPaymentMethod: () => Promise<void>;
|
|
21
|
+
submitPaymentMethodError: (error: string) => Promise<void>;
|
|
22
|
+
submitPaymentMethodSuccess: () => Promise<void>;
|
|
23
|
+
updatePaymentMethodBillingDetails: (payload: import("@frontegg/redux-store").WithCallback<import("@frontegg/redux-store").WithId<import("@frontegg/rest-api").ISubscriptionUpdatePaymentMethodBillingDetails>, boolean>) => Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
export declare const useInvoices: () => InvoicesState;
|
|
26
|
+
export declare const useInvoicesActions: () => {
|
|
27
|
+
setBillingInvoiceState: (state: Partial<InvoicesState>) => void;
|
|
28
|
+
resetBillingInvoiceState: () => void;
|
|
29
|
+
loadInvoices: () => Promise<void>;
|
|
30
|
+
loadBillingInvoices: () => Promise<void>;
|
|
31
|
+
downloadInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
|
|
32
|
+
downloadBillingInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
|
|
33
|
+
};
|
|
16
34
|
export declare const useSubscriptionCancellation: () => SubscriptionState['cancellation'];
|
|
17
35
|
export declare const useSubscriptionRenewal: () => SubscriptionState['renewal'];
|
|
18
36
|
export declare const useSubscription: () => SubscriptionState;
|
|
19
|
-
export declare const useSubscriptionActions: () =>
|
|
37
|
+
export declare const useSubscriptionActions: () => BillingStateActions['subscription'] & {
|
|
38
|
+
load: () => void;
|
|
39
|
+
};
|
|
40
|
+
export declare const useStripeState: () => StripeState;
|
|
41
|
+
export declare const useStripeActions: () => StripeActions;
|
|
20
42
|
export declare const useVendorPublicConfig: () => VendorPublicConfigurationState;
|
|
21
43
|
export declare const useVendorPublicConfigActions: () => VendorPublicConfigurationActions;
|