@posiwise/common-services 0.1.64 → 0.1.65
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/esm2022/lib/auth.service.mjs +7 -1
- package/esm2022/lib/google-analytics.service.mjs +15 -16
- package/esm2022/lib/permission.service.mjs +39 -31
- package/esm2022/lib/user.service.mjs +4 -1
- package/fesm2022/posiwise-common-services.mjs +61 -45
- package/fesm2022/posiwise-common-services.mjs.map +1 -1
- package/lib/auth.service.d.ts +2 -0
- package/lib/google-analytics.service.d.ts +5 -0
- package/lib/permission.service.d.ts +2 -0
- package/lib/user.service.d.ts +1 -0
- package/package.json +1 -1
|
@@ -113,7 +113,7 @@ class GoogleAnalyticsService {
|
|
|
113
113
|
this.appConfigService = appConfigService;
|
|
114
114
|
}
|
|
115
115
|
isGaAvailable() {
|
|
116
|
-
return typeof ga !== 'undefined';
|
|
116
|
+
return typeof window.ga !== 'undefined';
|
|
117
117
|
}
|
|
118
118
|
loadGScript() {
|
|
119
119
|
return new Promise((resolve, reject) => {
|
|
@@ -126,9 +126,9 @@ class GoogleAnalyticsService {
|
|
|
126
126
|
.loadScript('head', 'https://www.google-analytics.com/analytics.js', true)
|
|
127
127
|
.then(() => {
|
|
128
128
|
this.pushArgumentsGA();
|
|
129
|
-
ga.l = Date.now();
|
|
129
|
+
window.ga.l = Date.now();
|
|
130
130
|
GoogleAnalyticsService.trackingId = config.integrations.google_analytics;
|
|
131
|
-
ga('create', GoogleAnalyticsService.trackingId, 'auto');
|
|
131
|
+
window.ga('create', GoogleAnalyticsService.trackingId, 'auto');
|
|
132
132
|
resolve(); // Resolve the promise once the script is loaded and ga is initialized
|
|
133
133
|
})
|
|
134
134
|
.catch(error => {
|
|
@@ -139,14 +139,13 @@ class GoogleAnalyticsService {
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
pushArgumentsGA() {
|
|
142
|
-
ga
|
|
143
|
-
ga
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
};
|
|
142
|
+
if (typeof window.ga === 'undefined') {
|
|
143
|
+
window.ga = function (...args) {
|
|
144
|
+
(window.ga.q = window.ga.q || []).push(args);
|
|
145
|
+
};
|
|
146
|
+
window.ga.q = [];
|
|
147
|
+
window.ga.l = +new Date();
|
|
148
|
+
}
|
|
150
149
|
}
|
|
151
150
|
subscribe() {
|
|
152
151
|
if (!this.subscription) {
|
|
@@ -156,8 +155,8 @@ class GoogleAnalyticsService {
|
|
|
156
155
|
this.loadGScript().then(() => {
|
|
157
156
|
try {
|
|
158
157
|
if (this.isGaAvailable()) {
|
|
159
|
-
ga('set', 'page', e.urlAfterRedirects);
|
|
160
|
-
ga('send', 'pageview');
|
|
158
|
+
window.ga('set', 'page', e.urlAfterRedirects);
|
|
159
|
+
window.ga('send', 'pageview');
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
catch {
|
|
@@ -179,7 +178,7 @@ class GoogleAnalyticsService {
|
|
|
179
178
|
*/
|
|
180
179
|
sendEvent(eventCategory, eventAction, eventLabel = null, eventValue = null) {
|
|
181
180
|
if (this.isGaAvailable()) {
|
|
182
|
-
ga('send', 'event', {
|
|
181
|
+
window.ga('send', 'event', {
|
|
183
182
|
eventCategory,
|
|
184
183
|
eventAction,
|
|
185
184
|
eventLabel,
|
|
@@ -197,7 +196,7 @@ class GoogleAnalyticsService {
|
|
|
197
196
|
setUserContext(user) {
|
|
198
197
|
if (GoogleAnalyticsService.trackingId) {
|
|
199
198
|
if (this.isGaAvailable()) {
|
|
200
|
-
ga('set', 'userId', user?.id);
|
|
199
|
+
window.ga('set', 'userId', user?.id);
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
}
|
|
@@ -474,6 +473,9 @@ class UserService {
|
|
|
474
473
|
followUser(id) {
|
|
475
474
|
return this.api.post(`${this.endpoint}/toggle_relationship/${id}`);
|
|
476
475
|
}
|
|
476
|
+
sendSSOActivationEmail() {
|
|
477
|
+
return this.api.post(`/cognito/create_cognito_user`);
|
|
478
|
+
}
|
|
477
479
|
updateSlug(slug) {
|
|
478
480
|
return this.api.put(`${this.endpoint}/update_slug`, { slug });
|
|
479
481
|
}
|
|
@@ -711,6 +713,9 @@ class AuthService {
|
|
|
711
713
|
microsoftLogin() {
|
|
712
714
|
return this.http.get(`microsoft/get_authorize_url`);
|
|
713
715
|
}
|
|
716
|
+
cognitoLogin() {
|
|
717
|
+
return this.http.get(`cognito/get_authorize_url`);
|
|
718
|
+
}
|
|
714
719
|
microsoftAuthCallback(data) {
|
|
715
720
|
return this.http.post(`microsoft/authorization_callback`, data);
|
|
716
721
|
}
|
|
@@ -732,6 +737,9 @@ class AuthService {
|
|
|
732
737
|
appleAuthCallback(data) {
|
|
733
738
|
return this.http.post(`apple/authorization_callback`, data);
|
|
734
739
|
}
|
|
740
|
+
cognitoAuthCallback(data) {
|
|
741
|
+
return this.http.post(`cognito/authorization_callback`, data);
|
|
742
|
+
}
|
|
735
743
|
linkedinLogin() {
|
|
736
744
|
return this.appConfigService.appConfig$.pipe(switchMap(config => {
|
|
737
745
|
return this.http.get(`/linkedin/get_authorize_url?redirect_url=${config['links'].frontend_link}/linkedin-confirmation`);
|
|
@@ -890,23 +898,12 @@ class PermissionService {
|
|
|
890
898
|
}
|
|
891
899
|
}
|
|
892
900
|
}
|
|
893
|
-
else {
|
|
894
|
-
|
|
895
|
-
return true;
|
|
896
|
-
}
|
|
901
|
+
else if (user['auth']?.['granted'][permissionName]) {
|
|
902
|
+
return true;
|
|
897
903
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
return key.includes(productKey);
|
|
902
|
-
});
|
|
903
|
-
// add Pages.Product.{permission_key}
|
|
904
|
-
filteredPermissions = {
|
|
905
|
-
...{ [`Pages.Product.${permission_key}`]: true },
|
|
906
|
-
...filteredPermissions
|
|
907
|
-
};
|
|
908
|
-
// E.g., Pages.Product.CloudOlive.CloudOlive_MspKey
|
|
909
|
-
return filteredPermissions[permissionName] || false;
|
|
904
|
+
const filteredPermissions = this.handleProductKey(productKey, user, permission_key, permissionName);
|
|
905
|
+
if (filteredPermissions) {
|
|
906
|
+
return filteredPermissions;
|
|
910
907
|
}
|
|
911
908
|
// no valid permission was detected for this user
|
|
912
909
|
return false;
|
|
@@ -914,6 +911,21 @@ class PermissionService {
|
|
|
914
911
|
// user not logged-in
|
|
915
912
|
return false;
|
|
916
913
|
}
|
|
914
|
+
handleProductKey(productKey, user, permission_key, permissionName) {
|
|
915
|
+
if (productKey) {
|
|
916
|
+
// filters the permission only for the selected product.
|
|
917
|
+
let filteredPermissions = pickBy(cloneDeep(user['auth']['granted']), (_value, key) => {
|
|
918
|
+
return key.includes(productKey);
|
|
919
|
+
});
|
|
920
|
+
// add Pages.Product.{permission_key}
|
|
921
|
+
filteredPermissions = {
|
|
922
|
+
...{ [`Pages.Product.${permission_key}`]: true },
|
|
923
|
+
...filteredPermissions
|
|
924
|
+
};
|
|
925
|
+
// E.g., Pages.Product.CloudOlive.CloudOlive_MspKey
|
|
926
|
+
return filteredPermissions[permissionName] || false;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
917
929
|
getFormattedPermissionName(permissionName, productSlug) {
|
|
918
930
|
const selectedProduct = PermissionService?.selectedProduct || this.getCurrentProduct();
|
|
919
931
|
const subscriptionSlug = selectedProduct?.subscription_slug;
|
|
@@ -980,6 +992,12 @@ class PermissionService {
|
|
|
980
992
|
(this.isUserSubscriptionSuperAdmin() || this.isUserSubscriptionSuperOwner())) {
|
|
981
993
|
return true;
|
|
982
994
|
}
|
|
995
|
+
expr = this.handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug);
|
|
996
|
+
// Now expr is made of true/false values with &&, ||, ()
|
|
997
|
+
// eslint-disable-next-line no-eval
|
|
998
|
+
return eval(expr); // NOSONAR
|
|
999
|
+
}
|
|
1000
|
+
handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug) {
|
|
983
1001
|
if (typeof permission !== 'boolean') {
|
|
984
1002
|
permission.split(' ').forEach(x => {
|
|
985
1003
|
const raw = x.trim();
|
|
@@ -992,35 +1010,33 @@ class PermissionService {
|
|
|
992
1010
|
evaluated = this.isSuperAdmin();
|
|
993
1011
|
}
|
|
994
1012
|
else if (raw === PERMISSION_NAMES.SubscriptionAdmin) {
|
|
995
|
-
evaluated =
|
|
1013
|
+
evaluated =
|
|
1014
|
+
this.isUserSubscriptionAdmin() || this.isUserSubscriptionOwner();
|
|
996
1015
|
}
|
|
997
1016
|
else if (raw === PERMISSION_NAMES.SubscriptionOwner) {
|
|
998
1017
|
evaluated = this.isUserSubscriptionOwner();
|
|
999
1018
|
}
|
|
1000
1019
|
else if (raw === PERMISSION_NAMES.SubscriptionSuperAdmin) {
|
|
1001
|
-
evaluated =
|
|
1002
|
-
this.
|
|
1003
|
-
|
|
1020
|
+
evaluated =
|
|
1021
|
+
this.isUserSubscriptionSuperAdmin() ||
|
|
1022
|
+
this.isUserSubscriptionSuperOwner() ||
|
|
1023
|
+
this.isSuperAdmin();
|
|
1004
1024
|
}
|
|
1005
1025
|
else if (raw === PERMISSION_NAMES.SubscriptionSuperOwner) {
|
|
1006
1026
|
evaluated = this.isUserSubscriptionSuperOwner() || this.isSuperAdmin();
|
|
1007
1027
|
}
|
|
1028
|
+
else if (productKey) {
|
|
1029
|
+
// Assume it's Pages.Product or Pages.Role with productKey
|
|
1030
|
+
evaluated = this.isGranted(raw, productKey, permission_key, productSlug);
|
|
1031
|
+
}
|
|
1008
1032
|
else {
|
|
1009
|
-
|
|
1010
|
-
if (productKey) {
|
|
1011
|
-
evaluated = this.isGranted(raw, productKey, permission_key, productSlug);
|
|
1012
|
-
}
|
|
1013
|
-
else {
|
|
1014
|
-
evaluated = this.isGranted(raw);
|
|
1015
|
-
}
|
|
1033
|
+
evaluated = this.isGranted(raw);
|
|
1016
1034
|
}
|
|
1017
1035
|
expr += ` ${evaluated} `;
|
|
1018
1036
|
}
|
|
1019
1037
|
}, this);
|
|
1020
1038
|
}
|
|
1021
|
-
|
|
1022
|
-
// eslint-disable-next-line no-eval
|
|
1023
|
-
return eval(expr); // NOSONAR
|
|
1039
|
+
return expr;
|
|
1024
1040
|
}
|
|
1025
1041
|
getPermissionByRole(roleId) {
|
|
1026
1042
|
return this.api.get(`/admin/role_permissions/${roleId}`);
|