@frontegg/redux-store 7.106.0 → 7.107.0-alpha.0
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/auth/Security/RestrictionsState/actions.d.ts +2 -1
- package/auth/Security/RestrictionsState/actions.js +59 -1
- package/auth/Security/RestrictionsState/interfaces.d.ts +3 -0
- package/index.js +1 -1
- package/mocks/auth-mocks/security/restrictionsActions.mocks.d.ts +2 -1
- package/mocks/auth-mocks/security/restrictionsActions.mocks.js +44 -0
- package/node/auth/Security/RestrictionsState/actions.js +59 -1
- package/node/index.js +1 -1
- package/node/mocks/auth-mocks/security/restrictionsActions.mocks.js +44 -0
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FronteggState, RestApi, SharedActions, WithCallback } from '../../../interfaces';
|
|
2
|
-
import { EmailDomainRestrictionsState, CountryRestrictionsState, IPRestrictionsState, RestrictionsState, SaveCountryRestrictionConfigPayload, SaveCountryRestrictionsPayload, SaveEmailDomainRestrictionConfigPayload, SaveEmailDomainRestrictionsPayload } from './interfaces';
|
|
2
|
+
import { EmailDomainRestrictionsState, CountryRestrictionsState, IPRestrictionsState, RestrictionsState, AddCurrentUserCountryAndActivatePayload, SaveCountryRestrictionConfigPayload, SaveCountryRestrictionsPayload, SaveEmailDomainRestrictionConfigPayload, SaveEmailDomainRestrictionsPayload } from './interfaces';
|
|
3
3
|
import { CreateIpRestriction, IPRestrictionsConfig } from '@frontegg/rest-api';
|
|
4
4
|
declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
|
|
5
5
|
setRestrictionsState: (state: Partial<RestrictionsState>) => void;
|
|
@@ -24,5 +24,6 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
|
|
|
24
24
|
loadCountryRestrictions: () => Promise<void>;
|
|
25
25
|
saveCountryRestrictionsConfig: (payload: SaveCountryRestrictionConfigPayload) => Promise<void>;
|
|
26
26
|
saveCountryRestrictions: (payload: SaveCountryRestrictionsPayload) => Promise<void>;
|
|
27
|
+
addCurrentUserCountryAndActivate: (payload: AddCurrentUserCountryAndActivatePayload) => Promise<void>;
|
|
27
28
|
};
|
|
28
29
|
export default _default;
|
|
@@ -505,6 +505,62 @@ export default ((store, api, sharedActions) => {
|
|
|
505
505
|
callback == null ? void 0 : callback(null, e);
|
|
506
506
|
}
|
|
507
507
|
};
|
|
508
|
+
const addCurrentUserCountryAndActivate = async payload => {
|
|
509
|
+
var _ref2, _store$auth$userIpDat2, _countryRestrictionsS3, _countryRestrictionsS4, _countryRestrictionsS5, _countryRestrictionsS6;
|
|
510
|
+
const {
|
|
511
|
+
callback,
|
|
512
|
+
countryCode: payloadCountryCode
|
|
513
|
+
} = payload;
|
|
514
|
+
const currentCountryCode = ((_ref2 = payloadCountryCode != null ? payloadCountryCode : (_store$auth$userIpDat2 = store.auth.userIpData) == null ? void 0 : _store$auth$userIpDat2.countryCode) != null ? _ref2 : '').trim();
|
|
515
|
+
setCountryRestrictionsState({
|
|
516
|
+
saving: true,
|
|
517
|
+
error: null
|
|
518
|
+
});
|
|
519
|
+
if (!currentCountryCode) {
|
|
520
|
+
const error = new Error('Current country could not be detected');
|
|
521
|
+
setCountryRestrictionsState({
|
|
522
|
+
saving: false,
|
|
523
|
+
error
|
|
524
|
+
});
|
|
525
|
+
callback == null ? void 0 : callback(false, error);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const countryRestrictionsState = store.auth.restrictionsState.countryRestrictions;
|
|
529
|
+
const currentConfig = (_countryRestrictionsS3 = (_countryRestrictionsS4 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS4.config) != null ? _countryRestrictionsS3 : {
|
|
530
|
+
enabled: false,
|
|
531
|
+
action: RestrictionType.ALLOW,
|
|
532
|
+
failStrategy: RestrictionType.ALLOW,
|
|
533
|
+
shouldSendRestrictionEmail: false
|
|
534
|
+
};
|
|
535
|
+
const countryCodes = (_countryRestrictionsS5 = (_countryRestrictionsS6 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS6.restrictions.map(({
|
|
536
|
+
countryCode
|
|
537
|
+
}) => countryCode)) != null ? _countryRestrictionsS5 : [];
|
|
538
|
+
const uniqueUpper = Array.from(new Set([...countryCodes, currentCountryCode].map(code => code.toUpperCase())));
|
|
539
|
+
try {
|
|
540
|
+
await Promise.all([api.auth.updateCountryRestrictions({
|
|
541
|
+
countries: uniqueUpper.map(countryCode => ({
|
|
542
|
+
countryCode
|
|
543
|
+
}))
|
|
544
|
+
}), api.auth.updateCountryRestrictionsConfig(_extends({}, currentConfig, {
|
|
545
|
+
enabled: true
|
|
546
|
+
}))]);
|
|
547
|
+
const [config, restrictions] = await Promise.all([api.auth.getCountryRestrictionsConfig(), api.auth.getCountryRestrictions()]);
|
|
548
|
+
setCountryRestrictionsState({
|
|
549
|
+
data: {
|
|
550
|
+
config,
|
|
551
|
+
restrictions
|
|
552
|
+
},
|
|
553
|
+
saving: false
|
|
554
|
+
});
|
|
555
|
+
callback == null ? void 0 : callback(true);
|
|
556
|
+
} catch (e) {
|
|
557
|
+
setCountryRestrictionsState({
|
|
558
|
+
saving: false,
|
|
559
|
+
error: errorHandler(e)
|
|
560
|
+
});
|
|
561
|
+
callback == null ? void 0 : callback(false, e);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
508
564
|
const wrappedLoadIpRestrictions = __securityCenterSagaWrapper(loadIpRestrictions);
|
|
509
565
|
const wrappedSaveIpRestriction = __securityCenterSagaWrapper(saveIpRestriction);
|
|
510
566
|
const wrappedSaveIpRestrictionsConfig = __securityCenterSagaWrapper(saveIpRestrictionsConfig);
|
|
@@ -518,6 +574,7 @@ export default ((store, api, sharedActions) => {
|
|
|
518
574
|
const wrappedLoadCountryRestrictions = __securityCenterSagaWrapper(loadCountryRestrictions);
|
|
519
575
|
const wrappedSaveCountryRestrictionsConfig = __securityCenterSagaWrapper(saveCountryRestrictionsConfig);
|
|
520
576
|
const wrappedSaveCountryRestrictions = __securityCenterSagaWrapper(saveCountryRestrictions);
|
|
577
|
+
const wrappedAddCurrentUserCountryAndActivate = __securityCenterSagaWrapper(addCurrentUserCountryAndActivate);
|
|
521
578
|
return {
|
|
522
579
|
// reducers
|
|
523
580
|
setRestrictionsState,
|
|
@@ -538,6 +595,7 @@ export default ((store, api, sharedActions) => {
|
|
|
538
595
|
deleteEmailDomainRestriction: wrappedDeleteEmailDomainRestriction,
|
|
539
596
|
loadCountryRestrictions: wrappedLoadCountryRestrictions,
|
|
540
597
|
saveCountryRestrictionsConfig: wrappedSaveCountryRestrictionsConfig,
|
|
541
|
-
saveCountryRestrictions: wrappedSaveCountryRestrictions
|
|
598
|
+
saveCountryRestrictions: wrappedSaveCountryRestrictions,
|
|
599
|
+
addCurrentUserCountryAndActivate: wrappedAddCurrentUserCountryAndActivate
|
|
542
600
|
};
|
|
543
601
|
});
|
|
@@ -27,6 +27,9 @@ export type SaveCountryRestrictionConfigPayload = WithCallback<Partial<UpdateCou
|
|
|
27
27
|
export type SaveCountryRestrictionsPayload = WithCallback<{
|
|
28
28
|
countryCodes: string[];
|
|
29
29
|
}>;
|
|
30
|
+
export type AddCurrentUserCountryAndActivatePayload = WithCallback<{
|
|
31
|
+
countryCode?: string | null;
|
|
32
|
+
}>;
|
|
30
33
|
export interface RestrictionsState {
|
|
31
34
|
ipRestrictions: IPRestrictionsState;
|
|
32
35
|
emailDomainRestrictions: EmailDomainRestrictionsState;
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FronteggState, RestApi, SharedActions, WithCallback } from '../../../interfaces';
|
|
2
2
|
import { CreateIpRestriction, IPRestrictionsConfig } from '@frontegg/rest-api';
|
|
3
3
|
import { SaveEmailDomainRestrictionConfigPayload, SaveEmailDomainRestrictionsPayload } from '../../../auth';
|
|
4
|
-
import { SaveCountryRestrictionConfigPayload, SaveCountryRestrictionsPayload } from '../../../auth/Security/RestrictionsState/interfaces';
|
|
4
|
+
import { AddCurrentUserCountryAndActivatePayload, SaveCountryRestrictionConfigPayload, SaveCountryRestrictionsPayload } from '../../../auth/Security/RestrictionsState/interfaces';
|
|
5
5
|
declare const _default: (store: FronteggState, api: RestApi, actions: SharedActions) => {
|
|
6
6
|
setRestrictionsState: (state: Partial<import("../../../auth").RestrictionsState>) => void;
|
|
7
7
|
setIpRestrictionsState: (state: Partial<import("../../../auth").IPRestrictionsState>) => void;
|
|
@@ -25,5 +25,6 @@ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActi
|
|
|
25
25
|
loadCountryRestrictions: () => Promise<void>;
|
|
26
26
|
saveCountryRestrictionsConfig: (payload: SaveCountryRestrictionConfigPayload) => Promise<void>;
|
|
27
27
|
saveCountryRestrictions: (payload: SaveCountryRestrictionsPayload) => Promise<void>;
|
|
28
|
+
addCurrentUserCountryAndActivate: (payload: AddCurrentUserCountryAndActivatePayload) => Promise<void>;
|
|
28
29
|
};
|
|
29
30
|
export default _default;
|
|
@@ -299,6 +299,50 @@ export default ((store, api, actions) => {
|
|
|
299
299
|
saving: false
|
|
300
300
|
});
|
|
301
301
|
};
|
|
302
|
+
mockedActions.addCurrentUserCountryAndActivate = async payload => {
|
|
303
|
+
var _ref5, _store$auth$userIpDat, _countryRestrictionsS8, _countryRestrictionsS9, _countryRestrictionsS10, _countryRestrictionsS11;
|
|
304
|
+
const {
|
|
305
|
+
callback,
|
|
306
|
+
countryCode: payloadCountryCode
|
|
307
|
+
} = payload;
|
|
308
|
+
const countryRestrictionsState = store.auth.restrictionsState.countryRestrictions;
|
|
309
|
+
const currentCountryCode = ((_ref5 = payloadCountryCode != null ? payloadCountryCode : (_store$auth$userIpDat = store.auth.userIpData) == null ? void 0 : _store$auth$userIpDat.countryCode) != null ? _ref5 : '').trim();
|
|
310
|
+
mockedActions.setCountryRestrictionsState({
|
|
311
|
+
saving: true,
|
|
312
|
+
error: null
|
|
313
|
+
});
|
|
314
|
+
await delay();
|
|
315
|
+
if (!currentCountryCode) {
|
|
316
|
+
const error = new Error('Current country could not be detected');
|
|
317
|
+
mockedActions.setCountryRestrictionsState({
|
|
318
|
+
saving: false,
|
|
319
|
+
error
|
|
320
|
+
});
|
|
321
|
+
callback == null ? void 0 : callback(false, error);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const countryCodes = [...((_countryRestrictionsS8 = (_countryRestrictionsS9 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS9.restrictions.map(({
|
|
325
|
+
countryCode
|
|
326
|
+
}) => countryCode)) != null ? _countryRestrictionsS8 : []), currentCountryCode];
|
|
327
|
+
const restrictions = Array.from(new Set(countryCodes.map(code => code.toUpperCase()))).map((countryCode, index) => ({
|
|
328
|
+
id: `mock-${countryCode}-${index}`,
|
|
329
|
+
countryCode
|
|
330
|
+
}));
|
|
331
|
+
callback == null ? void 0 : callback(true);
|
|
332
|
+
mockedActions.setCountryRestrictionsState({
|
|
333
|
+
data: {
|
|
334
|
+
config: _extends({}, (_countryRestrictionsS10 = (_countryRestrictionsS11 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS11.config) != null ? _countryRestrictionsS10 : {
|
|
335
|
+
action: RestrictionType.ALLOW,
|
|
336
|
+
failStrategy: RestrictionType.ALLOW,
|
|
337
|
+
shouldSendRestrictionEmail: false
|
|
338
|
+
}, {
|
|
339
|
+
enabled: true
|
|
340
|
+
}),
|
|
341
|
+
restrictions
|
|
342
|
+
},
|
|
343
|
+
saving: false
|
|
344
|
+
});
|
|
345
|
+
};
|
|
302
346
|
mockedActions.deleteEmailDomainRestriction = async payload => {
|
|
303
347
|
var _emailDomainRestricti4, _emailDomainRestricti5;
|
|
304
348
|
const {
|
|
@@ -512,6 +512,62 @@ var _default = (store, api, sharedActions) => {
|
|
|
512
512
|
callback == null ? void 0 : callback(null, e);
|
|
513
513
|
}
|
|
514
514
|
};
|
|
515
|
+
const addCurrentUserCountryAndActivate = async payload => {
|
|
516
|
+
var _ref2, _store$auth$userIpDat2, _countryRestrictionsS3, _countryRestrictionsS4, _countryRestrictionsS5, _countryRestrictionsS6;
|
|
517
|
+
const {
|
|
518
|
+
callback,
|
|
519
|
+
countryCode: payloadCountryCode
|
|
520
|
+
} = payload;
|
|
521
|
+
const currentCountryCode = ((_ref2 = payloadCountryCode != null ? payloadCountryCode : (_store$auth$userIpDat2 = store.auth.userIpData) == null ? void 0 : _store$auth$userIpDat2.countryCode) != null ? _ref2 : '').trim();
|
|
522
|
+
setCountryRestrictionsState({
|
|
523
|
+
saving: true,
|
|
524
|
+
error: null
|
|
525
|
+
});
|
|
526
|
+
if (!currentCountryCode) {
|
|
527
|
+
const error = new Error('Current country could not be detected');
|
|
528
|
+
setCountryRestrictionsState({
|
|
529
|
+
saving: false,
|
|
530
|
+
error
|
|
531
|
+
});
|
|
532
|
+
callback == null ? void 0 : callback(false, error);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const countryRestrictionsState = store.auth.restrictionsState.countryRestrictions;
|
|
536
|
+
const currentConfig = (_countryRestrictionsS3 = (_countryRestrictionsS4 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS4.config) != null ? _countryRestrictionsS3 : {
|
|
537
|
+
enabled: false,
|
|
538
|
+
action: _restApi.RestrictionType.ALLOW,
|
|
539
|
+
failStrategy: _restApi.RestrictionType.ALLOW,
|
|
540
|
+
shouldSendRestrictionEmail: false
|
|
541
|
+
};
|
|
542
|
+
const countryCodes = (_countryRestrictionsS5 = (_countryRestrictionsS6 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS6.restrictions.map(({
|
|
543
|
+
countryCode
|
|
544
|
+
}) => countryCode)) != null ? _countryRestrictionsS5 : [];
|
|
545
|
+
const uniqueUpper = Array.from(new Set([...countryCodes, currentCountryCode].map(code => code.toUpperCase())));
|
|
546
|
+
try {
|
|
547
|
+
await Promise.all([api.auth.updateCountryRestrictions({
|
|
548
|
+
countries: uniqueUpper.map(countryCode => ({
|
|
549
|
+
countryCode
|
|
550
|
+
}))
|
|
551
|
+
}), api.auth.updateCountryRestrictionsConfig((0, _extends2.default)({}, currentConfig, {
|
|
552
|
+
enabled: true
|
|
553
|
+
}))]);
|
|
554
|
+
const [config, restrictions] = await Promise.all([api.auth.getCountryRestrictionsConfig(), api.auth.getCountryRestrictions()]);
|
|
555
|
+
setCountryRestrictionsState({
|
|
556
|
+
data: {
|
|
557
|
+
config,
|
|
558
|
+
restrictions
|
|
559
|
+
},
|
|
560
|
+
saving: false
|
|
561
|
+
});
|
|
562
|
+
callback == null ? void 0 : callback(true);
|
|
563
|
+
} catch (e) {
|
|
564
|
+
setCountryRestrictionsState({
|
|
565
|
+
saving: false,
|
|
566
|
+
error: (0, _helpers.errorHandler)(e)
|
|
567
|
+
});
|
|
568
|
+
callback == null ? void 0 : callback(false, e);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
515
571
|
const wrappedLoadIpRestrictions = __securityCenterSagaWrapper(loadIpRestrictions);
|
|
516
572
|
const wrappedSaveIpRestriction = __securityCenterSagaWrapper(saveIpRestriction);
|
|
517
573
|
const wrappedSaveIpRestrictionsConfig = __securityCenterSagaWrapper(saveIpRestrictionsConfig);
|
|
@@ -525,6 +581,7 @@ var _default = (store, api, sharedActions) => {
|
|
|
525
581
|
const wrappedLoadCountryRestrictions = __securityCenterSagaWrapper(loadCountryRestrictions);
|
|
526
582
|
const wrappedSaveCountryRestrictionsConfig = __securityCenterSagaWrapper(saveCountryRestrictionsConfig);
|
|
527
583
|
const wrappedSaveCountryRestrictions = __securityCenterSagaWrapper(saveCountryRestrictions);
|
|
584
|
+
const wrappedAddCurrentUserCountryAndActivate = __securityCenterSagaWrapper(addCurrentUserCountryAndActivate);
|
|
528
585
|
return {
|
|
529
586
|
// reducers
|
|
530
587
|
setRestrictionsState,
|
|
@@ -545,7 +602,8 @@ var _default = (store, api, sharedActions) => {
|
|
|
545
602
|
deleteEmailDomainRestriction: wrappedDeleteEmailDomainRestriction,
|
|
546
603
|
loadCountryRestrictions: wrappedLoadCountryRestrictions,
|
|
547
604
|
saveCountryRestrictionsConfig: wrappedSaveCountryRestrictionsConfig,
|
|
548
|
-
saveCountryRestrictions: wrappedSaveCountryRestrictions
|
|
605
|
+
saveCountryRestrictions: wrappedSaveCountryRestrictions,
|
|
606
|
+
addCurrentUserCountryAndActivate: wrappedAddCurrentUserCountryAndActivate
|
|
549
607
|
};
|
|
550
608
|
};
|
|
551
609
|
exports.default = _default;
|
package/node/index.js
CHANGED
|
@@ -306,6 +306,50 @@ var _default = (store, api, actions) => {
|
|
|
306
306
|
saving: false
|
|
307
307
|
});
|
|
308
308
|
};
|
|
309
|
+
mockedActions.addCurrentUserCountryAndActivate = async payload => {
|
|
310
|
+
var _ref5, _store$auth$userIpDat, _countryRestrictionsS8, _countryRestrictionsS9, _countryRestrictionsS10, _countryRestrictionsS11;
|
|
311
|
+
const {
|
|
312
|
+
callback,
|
|
313
|
+
countryCode: payloadCountryCode
|
|
314
|
+
} = payload;
|
|
315
|
+
const countryRestrictionsState = store.auth.restrictionsState.countryRestrictions;
|
|
316
|
+
const currentCountryCode = ((_ref5 = payloadCountryCode != null ? payloadCountryCode : (_store$auth$userIpDat = store.auth.userIpData) == null ? void 0 : _store$auth$userIpDat.countryCode) != null ? _ref5 : '').trim();
|
|
317
|
+
mockedActions.setCountryRestrictionsState({
|
|
318
|
+
saving: true,
|
|
319
|
+
error: null
|
|
320
|
+
});
|
|
321
|
+
await (0, _helpers.delay)();
|
|
322
|
+
if (!currentCountryCode) {
|
|
323
|
+
const error = new Error('Current country could not be detected');
|
|
324
|
+
mockedActions.setCountryRestrictionsState({
|
|
325
|
+
saving: false,
|
|
326
|
+
error
|
|
327
|
+
});
|
|
328
|
+
callback == null ? void 0 : callback(false, error);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const countryCodes = [...((_countryRestrictionsS8 = (_countryRestrictionsS9 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS9.restrictions.map(({
|
|
332
|
+
countryCode
|
|
333
|
+
}) => countryCode)) != null ? _countryRestrictionsS8 : []), currentCountryCode];
|
|
334
|
+
const restrictions = Array.from(new Set(countryCodes.map(code => code.toUpperCase()))).map((countryCode, index) => ({
|
|
335
|
+
id: `mock-${countryCode}-${index}`,
|
|
336
|
+
countryCode
|
|
337
|
+
}));
|
|
338
|
+
callback == null ? void 0 : callback(true);
|
|
339
|
+
mockedActions.setCountryRestrictionsState({
|
|
340
|
+
data: {
|
|
341
|
+
config: (0, _extends2.default)({}, (_countryRestrictionsS10 = (_countryRestrictionsS11 = countryRestrictionsState.data) == null ? void 0 : _countryRestrictionsS11.config) != null ? _countryRestrictionsS10 : {
|
|
342
|
+
action: _restApi.RestrictionType.ALLOW,
|
|
343
|
+
failStrategy: _restApi.RestrictionType.ALLOW,
|
|
344
|
+
shouldSendRestrictionEmail: false
|
|
345
|
+
}, {
|
|
346
|
+
enabled: true
|
|
347
|
+
}),
|
|
348
|
+
restrictions
|
|
349
|
+
},
|
|
350
|
+
saving: false
|
|
351
|
+
});
|
|
352
|
+
};
|
|
309
353
|
mockedActions.deleteEmailDomainRestriction = async payload => {
|
|
310
354
|
var _emailDomainRestricti4, _emailDomainRestricti5;
|
|
311
355
|
const {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/redux-store",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.107.0-alpha.0",
|
|
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
9
|
"@frontegg/entitlements-javascript-commons": "1.1.2",
|
|
10
|
-
"@frontegg/rest-api": "7.
|
|
10
|
+
"@frontegg/rest-api": "7.107.0-alpha.0",
|
|
11
11
|
"fast-deep-equal": "3.1.3",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"proxy-compare": "^3.0.0",
|