@trimoz/trimoz-api-wrapper 0.0.1-security → 0.9.7

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.

Potentially problematic release.


This version of @trimoz/trimoz-api-wrapper might be problematic. Click here for more details.

@@ -0,0 +1,202 @@
1
+ 'use strict';
2
+
3
+ export default (API) => ({
4
+ services: {
5
+ get: (establishmentId, serviceId) => {
6
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId;
7
+ const request = API.http.get(url);
8
+ return API.handleError(request);
9
+ },
10
+ getAvailable: () => {
11
+ const url = 'v3/services/available';
12
+ const request = API.http.get(url);
13
+ return API.handleError(request);
14
+ },
15
+ getAllAvailableByEstablishment: (establishmentId) => {
16
+ const url = 'v3/establishments/' + establishmentId + '/services/available';
17
+ const request = API.http.get(url);
18
+ return API.handleError(request);
19
+ },
20
+ getPlaceAndResourceIndexes: (establishmentId, serviceId) => {
21
+ const url = 'v3/establishments/' + establishmentId + '/places/resources/services/' + serviceId + '/indexes';
22
+ const request = API.http.get(url);
23
+ return API.handleError(request);
24
+ },
25
+ getAllByEstablishment: (establishmentId, module = null, ignorePrest = false, withSettings = false) => {
26
+ let url = `v3/establishments/${establishmentId}/services`;
27
+ if (withSettings) {
28
+ url += `?settings=${withSettings}`;
29
+ }
30
+ if (module) {
31
+ url += `${withSettings ? '&' : '?'}module=${module}`;
32
+ }
33
+
34
+ if (ignorePrest) {
35
+ url += `${module || withSettings ? '&' : '?'}ignorePrest=${ignorePrest}`;
36
+ }
37
+ const request = API.http.get(url);
38
+ return API.handleError(request);
39
+ },
40
+ getAllEstablishmentServices: (establishmentId) => {
41
+ const url = `v3/establishments/${establishmentId}/services/all`;
42
+ const request = API.http.get(url);
43
+ return API.handleError(request);
44
+ },
45
+ getArchived: (establishmentId) => {
46
+ const url = `v3/establishments/${establishmentId}/services/archived`;
47
+ const request = API.http.get(url);
48
+ return API.handleError(request);
49
+ },
50
+ getAllMetaData: () => {
51
+ const url = 'v3/metadata';
52
+ const request = API.http.get(url);
53
+ return API.handleError(request);
54
+ },
55
+ getEstMetadata: (establishmentId, serviceId) => {
56
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/metadata/available';
57
+ const request = API.http.get(url);
58
+ return API.handleError(request);
59
+ },
60
+ getEstConfigurationMessages: (establishmentId, serviceId) => {
61
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/configuration/messages';
62
+ const request = API.http.get(url);
63
+ return API.handleError(request);
64
+ },
65
+ getAllEstSpecificSettings: (establishmentId, settingIds) => {
66
+ const values = settingIds.join(',');
67
+ const url = 'v3/establishments/' + establishmentId + '/services/settings?settingIds=' + values;
68
+ const request = API.http.get(url);
69
+ return API.handleError(request);
70
+ },
71
+ insertOrUpdateEstConfigurationMessages: (establishmentId, estId, params) => {
72
+ const url = 'v3/establishments/' + establishmentId + '/services/' + estId + '/configuration/messages';
73
+ const request = API.http.put(url, params, { headers: { 'Content-Type': 'application/json' } });
74
+ return API.handleError(request);
75
+ },
76
+ getBasicMeta: () => {
77
+ const url = 'v3/services/metas';
78
+ const request = API.http.get(url);
79
+ return API.handleError(request);
80
+ },
81
+ getEstSettings: (establishmentId, serviceId) => {
82
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/settings';
83
+ const request = API.http.get(url);
84
+ return API.handleError(request);
85
+ },
86
+ getTemplates: () => {
87
+ const url = 'v3/services/templates';
88
+ const request = API.http.get(url);
89
+ return API.handleError(request);
90
+ },
91
+ getServiceTemplatesFilters: (establishmentId, serviceUnifiedId, light = false) => {
92
+ const serviceUnified = serviceUnifiedId ? `&service_unified=${serviceUnifiedId}` : '';
93
+ const isLight = light ? '&light=true' : '';
94
+ const url = 'v3/establishments/' + establishmentId + '/services/templates/filters?' + serviceUnified + isLight;
95
+ const request = API.http.get(url);
96
+ return API.handleError(request);
97
+ },
98
+ getByIds(establishmentId, servicesIds) {
99
+ const url = `v3/establishments/${establishmentId}/findByIds?ids=${servicesIds}`;
100
+ const request = API.http.get(url);
101
+ return API.handleError(request);
102
+ },
103
+ createTemplate: (params) => {
104
+ const url = 'v3/services/templates';
105
+ const request = API.http.post(url, params, { headers: { 'Content-Type': 'application/json' } });
106
+ return API.handleError(request);
107
+ },
108
+ updateTemplate: (templateId, params) => {
109
+ const url = 'v3/services/templates/' + templateId;
110
+ const request = API.http.put(url, params, { headers: { 'Content-Type': 'application/json' } });
111
+ return API.handleError(request);
112
+ },
113
+ deleteTemplate: (templateId) => {
114
+ const url = 'v3/services/templates/' + templateId;
115
+ const request = API.http.delete(url, { headers: { 'Content-Type': 'application/json' } });
116
+ return API.handleError(request);
117
+ },
118
+ getModules: () => {
119
+ const url = 'v3/services/modules';
120
+ const request = API.http.get(url);
121
+ return API.handleError(request);
122
+ },
123
+ createUninstantiatedServices: (establishmentId, serviceTemplateId, moduleId, submodules) => {
124
+ const url = `v3/establishments/${establishmentId}/services/available`;
125
+ const data = {
126
+ serviceTemplateId: serviceTemplateId,
127
+ module: moduleId,
128
+ submodules: submodules,
129
+ };
130
+ const request = API.http.post(url, data, { headers: { 'Content-Type': 'application/json' } });
131
+ return API.handleError(request);
132
+ },
133
+ deleteUninstantiatedServices: (establishmentId, establishmentServiceTemplateId) => {
134
+ const url = `v3/establishments/${establishmentId}/services/available/${establishmentServiceTemplateId}`;
135
+ const request = API.http.delete(url);
136
+ return API.handleError(request);
137
+ },
138
+ instantiate: (establishmentId, serviceId, params) => {
139
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/instantiate';
140
+ const request = API.http.post(url, params);
141
+ return API.handleError(request);
142
+ },
143
+ restore: (establishmentId, serviceId, params) => {
144
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/restore';
145
+ const request = API.http.put(url, params);
146
+ return API.handleError(request);
147
+ },
148
+ delete: (establishmentId, serviceId, validate) => {
149
+ const url = `v3/establishments/${establishmentId}/services/${serviceId}?validate=${validate}`;
150
+ const request = API.http.delete(url);
151
+ return API.handleError(request);
152
+ },
153
+ update: (establishmentId, serviceId, params) => {
154
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId;
155
+ const request = API.http.put(url, params);
156
+ return API.handleError(request);
157
+ },
158
+ updateStatus: (establishmentId, serviceId, params) => {
159
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/status';
160
+ const request = API.http.put(url, params, { headers: { 'Content-Type': 'application/json' } });
161
+ return API.handleError(request);
162
+ },
163
+ updateOrder: (establishmentId, params) => {
164
+ const url = 'v3/establishments/' + establishmentId + '/services/order';
165
+ const request = API.http.put(url, params, { headers: { 'Content-Type': 'application/json' } });
166
+ return API.handleError(request);
167
+ },
168
+ uploadDocument: (establishmentId, serviceId, language, file) => {
169
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/upload/' + language;
170
+ const params = new FormData();
171
+ params.append('document', file, file.name);
172
+
173
+ const request = API.http.post(url, params, { headers: { 'Content-Type': 'multipart/form-data' } });
174
+ return API.handleError(request);
175
+ },
176
+ deleteDocument: (establishmentId, serviceId, language) => {
177
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceId + '/upload/' + language + '/delete';
178
+ const request = API.http.delete(url, { headers: { 'Content-Type': 'application/json' } });
179
+ return API.handleError(request);
180
+ },
181
+ createServiceMeta: (serviceTemplateId, params) => {
182
+ const url = 'v3/establishments/services/' + serviceTemplateId + '/metadata';
183
+ const request = API.http.post(url, params);
184
+ return API.handleError(request);
185
+ },
186
+ deleteServiceMeta: (serviceTemplateId, metaId) => {
187
+ const url = 'v3/establishments/services/' + serviceTemplateId + '/metadata/' + metaId;
188
+ const request = API.http.delete(url);
189
+ return API.handleError(request);
190
+ },
191
+ updateServiceMetas: (establishmentId, serviceTemplateId, params) => {
192
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceTemplateId + '/metadata';
193
+ const request = API.http.put(url, params);
194
+ return API.handleError(request);
195
+ },
196
+ updateServiceSettings: (establishmentId, serviceTemplateId, params) => {
197
+ const url = 'v3/establishments/' + establishmentId + '/services/' + serviceTemplateId + '/settings';
198
+ const request = API.http.put(url, params);
199
+ return API.handleError(request);
200
+ },
201
+ },
202
+ });
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ export default (API) => ({
4
+ setOptions: {
5
+ product: (product) => {
6
+ API.http.defaults.headers.PRODUCT = product;
7
+ },
8
+
9
+ role: (role) => {
10
+ API.http.defaults.headers['X-TRIMOZ-ROLE'] = role;
11
+ },
12
+
13
+ updateAppointmentJobId: (jobId) => {
14
+ if (jobId) {
15
+ API.http.defaults.headers['X-TRIMOZ-APPOINTMENT-UPDATE-JOB-ID'] = jobId;
16
+ }
17
+ else {
18
+ delete API.http.defaults.headers['X-TRIMOZ-APPOINTMENT-UPDATE-JOB-ID'];
19
+ }
20
+ },
21
+
22
+ updateAppointmentJobToken: (jobToken) => {
23
+ if (jobToken) {
24
+ API.http.defaults.headers['X-TRIMOZ-APPOINTMENT-UPDATE-JOB-TOKEN'] = jobToken;
25
+ }
26
+ else {
27
+ delete API.http.defaults.headers['X-TRIMOZ-APPOINTMENT-UPDATE-JOB-TOKEN'];
28
+ }
29
+ },
30
+ },
31
+ });
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ export default (API) => ({
4
+ settings: {
5
+ getBaseSettings: (appModule) => {
6
+ const url = 'v3/settings' + (appModule ? '?appModule=' + appModule : '');
7
+ const request = API.http.get(url);
8
+ return API.handleError(request);
9
+ },
10
+
11
+ getGlobalSettings: () => {
12
+ const url = 'v3/globalSettings';
13
+ const request = API.http.get(url);
14
+ return API.handleError(request);
15
+ }
16
+ }
17
+ });
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ import { forEach } from 'lodash';
4
+
5
+ export default (API) => ({
6
+ stats: {
7
+ /**
8
+ * @deprecated
9
+ */
10
+ getView: (
11
+ dateStart,
12
+ dateStop,
13
+ establishments,
14
+ places,
15
+ resources,
16
+ establishmentServiceTemplates,
17
+ timezone = null,
18
+ headOffices = null,
19
+ modules = null,
20
+ groupBy = null,
21
+ view = null,
22
+ gainValuesOverride = null
23
+ ) => {
24
+ let url = 'v3/statistics/view';
25
+ url += '?dateStart=' + dateStart;
26
+ url += '&dateStop=' + dateStop;
27
+ url += establishments ? ('&establishments=' + establishments) : '';
28
+ url += places ? ('&places=' + places) : '';
29
+ url += resources ? ('&resources=' + resources) : '';
30
+ url += establishmentServiceTemplates ? ('&establishmentServiceTemplates=' + establishmentServiceTemplates) : '';
31
+ url += timezone ? '&timezone=' + timezone : '';
32
+ url += headOffices ? '&headOffices=' + headOffices : '';
33
+ url += modules ? '&modules=' + modules : '';
34
+ url += view ? '&view=' + view : '';
35
+ url += groupBy ? '&groupBy=' + groupBy : '';
36
+
37
+ if (gainValuesOverride) {
38
+ url += gainValuesOverride['bookingGainMinutes'] ? '&bookingGainMinutes=' + gainValuesOverride['bookingGainMinutes'] : '';
39
+ url += gainValuesOverride['cancellationGainMinutes'] ? '&cancellationGainMinutes=' + gainValuesOverride['cancellationGainMinutes'] : '';
40
+ url += gainValuesOverride['reminderGainMinutes'] ? '&reminderGainMinutes=' + gainValuesOverride['reminderGainMinutes'] : '';
41
+ url += gainValuesOverride['relaunchGainMinutes'] ? '&relaunchGainMinutes=' + gainValuesOverride['relaunchGainMinutes'] : '';
42
+
43
+ url += gainValuesOverride['bookingHourlyRate'] ? '&bookingHourlyRate=' + gainValuesOverride['bookingHourlyRate'] : '';
44
+ url += gainValuesOverride['cancellationHourlyRate'] ? '&cancellationHourlyRate=' + gainValuesOverride['cancellationHourlyRate'] : '';
45
+ url += gainValuesOverride['reminderHourlyRate'] ? '&reminderHourlyRate=' + gainValuesOverride['reminderHourlyRate'] : '';
46
+ url += gainValuesOverride['relaunchHourlyRate'] ? '&relaunchHourlyRate=' + gainValuesOverride['relaunchHourlyRate'] : '';
47
+ }
48
+
49
+ const request = API.http.get(url);
50
+ return API.handleError(request);
51
+ },
52
+
53
+ insertKPIStatisticForEstablishment: (establishment, service, place, firstAvailabilityDate) => {
54
+ const url = `v3/establishments/${establishment}/statistics/kpi`;
55
+
56
+ const request = API.http.post(
57
+ url,
58
+ { place: place, service: service, firstAvailabilityDate: firstAvailabilityDate },
59
+ { headers: { 'Content-Type': 'application/json' } }
60
+ );
61
+ return API.handleError(request);
62
+ },
63
+
64
+ incrementPublicVisitsForEstablishment: (establishment) => {
65
+ const url = `v3/establishments/${establishment}/statistics/publicVisits`;
66
+
67
+ const request = API.http.post(url);
68
+ return API.handleError(request);
69
+ },
70
+
71
+ createStatisticsReportJob(payload) {
72
+ let url = `v3/statistics/job`;
73
+ const params = new FormData();
74
+ forEach(payload, (val, key) => {
75
+ params.append(key, val);
76
+ });
77
+
78
+ const request = API.http.post(url, params, { headers: { 'Content-Type': 'multipart/form-data' }, timeout: 30000 });
79
+ return API.handleError(request);
80
+ },
81
+
82
+ getStatisticsReportJob: (jobId) => {
83
+ const url = `/v3/statistics/job/${jobId}`;
84
+ const request = API.http.get(url);
85
+ return API.handleError(request);
86
+ }
87
+ }
88
+ });
@@ -0,0 +1,16 @@
1
+ const { keys, forEach, find } = require('lodash');
2
+ export const urlFromClientData = (profileUrl, clientData) => {
3
+ const requiredKeys = ['birthday', 'cellphone', 'email', 'firstName', 'lastName', 'nam', 'unknownMother', 'motherFirstName', 'motherLastName', 'unknownFather', 'fatherFirstName', 'fatherLastName', 'gender', 'baseUrl', 'locale'];
4
+ const url = new URL(profileUrl + '/auth/register');
5
+ forEach(keys(clientData), (key) => {
6
+ if (!find(requiredKeys, (it) => it === key)) {
7
+ return;
8
+ }
9
+ if (key.includes('unknown')) {
10
+ url.searchParams.append(key.replace('unknown', '').toLowerCase() + 'Unknown', clientData[key]);
11
+ return;
12
+ }
13
+ url.searchParams.append(key, clientData[key]);
14
+ });
15
+ return url.href;
16
+ };
@@ -0,0 +1,172 @@
1
+ import { signInWindow } from '../oAuthWindow';
2
+ import { inferProfileUrl, hasRtkpCookie } from '../utils';
3
+ import { urlFromClientData } from './helpers';
4
+
5
+ const state = {
6
+ accessToken: null,
7
+ isInRetryMode: false,
8
+ queuedRequest: [],
9
+ headRequest: undefined,
10
+ loggedUser: undefined,
11
+ loggedUserCommunication: undefined,
12
+ patients: [],
13
+ loading: false,
14
+ locale: null,
15
+ };
16
+
17
+ const getters = {
18
+ getAccessToken(state) {
19
+ return state.accessToken;
20
+ },
21
+
22
+ getIsInRetryMode(state) {
23
+ return state.isInRetryMode;
24
+ },
25
+
26
+ getHeadRequest(state) {
27
+ return state.headRequest;
28
+ },
29
+
30
+ getLoggedUser(state) {
31
+ return state.loggedUser;
32
+ },
33
+
34
+ getLoggedUserCommunication(state) {
35
+ return state.loggedUserCommunication;
36
+ },
37
+
38
+ getProfileUrl() {
39
+ return inferProfileUrl();
40
+ },
41
+
42
+ getPatients(state) {
43
+ return state.patients;
44
+ },
45
+
46
+ getLoading(state) {
47
+ return state.loading;
48
+ },
49
+
50
+ getLocale(state) {
51
+ return state.locale;
52
+ },
53
+ };
54
+
55
+ const mutations = {
56
+ SET_ACCESS_TOKEN(state, token) {
57
+ state.accessToken = token;
58
+ },
59
+
60
+ CLEAR_ACCESS_TOKEN(state) {
61
+ state.accessToken = null;
62
+ },
63
+
64
+ SET_IS_IN_RETRY_MODE(state, value) {
65
+ state.isInRetryMode = value;
66
+ },
67
+
68
+ ENQUEUE_REQUEST(state, req) {
69
+ state.queuedRequest.push(req);
70
+ },
71
+
72
+ DEQUEUE_REQUEST(state) {
73
+ state.headRequest = state.queuedRequest.shift();
74
+ },
75
+
76
+ SET_LOGGED_USER(state, user) {
77
+ state.loggedUser = user;
78
+ },
79
+
80
+ SET_LOGGED_USER_COMMUNICATION(state, payload) {
81
+ state.loggedUserCommunication = payload;
82
+ },
83
+
84
+ SET_PATIENTS(state, patients) {
85
+ state.patients = patients;
86
+ },
87
+
88
+ SET_LOADING(state, payload) {
89
+ state.loading = payload;
90
+ },
91
+
92
+ SET_LOCALE_FOR_PROFILE(state, locale) {
93
+ state.locale = locale;
94
+ },
95
+ };
96
+
97
+ const actions = {
98
+ async fetchAccessToken({ commit }) {
99
+ if (hasRtkpCookie()) {
100
+ const response = await this._vm.$api.auth.getAccessToken();
101
+ commit('SET_ACCESS_TOKEN', response.data.accessToken);
102
+ }
103
+ },
104
+
105
+ async logout({ commit }) {
106
+ try {
107
+ commit('SET_LOADING', true);
108
+ await this._vm.$api.auth.logoutJwt();
109
+ commit('SET_ACCESS_TOKEN', null);
110
+ commit('SET_LOGGED_USER', null);
111
+ commit('SET_PATIENTS', []);
112
+ }
113
+ finally {
114
+ commit('SET_LOADING', false);
115
+ }
116
+ },
117
+
118
+ async getLoggedUser({ getters, commit }) {
119
+ if (getters.getAccessToken) {
120
+ const response = await this._vm.$api.auth.getMyPatient();
121
+ commit('SET_LOGGED_USER', response.data);
122
+ }
123
+ },
124
+
125
+ async getLoggedUserCommunication({ getters, commit }) {
126
+ if (getters.getAccessToken) {
127
+ const response = await this._vm.$api.auth.getMyPatientCommunication();
128
+ commit('SET_LOGGED_USER_COMMUNICATION', response.data);
129
+ }
130
+ },
131
+
132
+ async getPatients({ getters, commit }) {
133
+ if (getters.getAccessToken) {
134
+ const response = await this._vm.$api.auth.getAllPatients();
135
+ commit('SET_PATIENTS', response.data);
136
+ }
137
+ },
138
+
139
+ async openSignInWindow({ getters, dispatch, commit }, isRegiser = false) {
140
+ const oAuthUrl = isRegiser
141
+ ? '/oauth/register'
142
+ : '/oauth/login';
143
+ const authenticationRoute = `${getters.getProfileUrl}${oAuthUrl}?baseUrl=${window.location.origin}&locale=${getters.getLocale}`;
144
+ try {
145
+ await signInWindow(authenticationRoute);
146
+ commit('SET_LOADING', true);
147
+ await dispatch('fetchAccessToken');
148
+ await Promise.all([
149
+ dispatch('getLoggedUser'),
150
+ dispatch('getLoggedUserCommunication'),
151
+ dispatch('getPatients'),
152
+ ]);
153
+ }
154
+ finally {
155
+ commit('SET_LOADING', false);
156
+ }
157
+ },
158
+
159
+ async openRegisterWindow({ getters }, payload) {
160
+ const { clientDataForUrl } = payload;
161
+ urlFromClientData(getters.getProfileUrl, clientDataForUrl);
162
+ await signInWindow(urlFromClientData(getters.getProfileUrl, { ...clientDataForUrl, baseUrl: window.location.origin }));
163
+ },
164
+ };
165
+
166
+ export const jwt = {
167
+ namespaced: true,
168
+ actions,
169
+ getters,
170
+ mutations,
171
+ state,
172
+ };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ export default (API) => ({
4
+ texts: {
5
+ get: (establishmentId, lang = '') => {
6
+ const url = 'v3/establishments/' + establishmentId + '/texts' + (lang ? '/' + lang : '');
7
+ const request = API.http.get(url);
8
+ return API.handleError(request);
9
+ },
10
+
11
+ updateTexts: (establishmentId, params) => {
12
+ const url = 'v3/establishments/' + establishmentId + '/texts';
13
+ const request = API.http.put(url, params);
14
+ return API.handleError(request);
15
+ }
16
+ }
17
+ });
package/src/utils.js ADDED
@@ -0,0 +1,71 @@
1
+ import { filter, forEach, get, includes, isNil, join, replace, some, split, startsWith } from 'lodash';
2
+ import { TrimozError } from '@trimoz/trimoz-vue-error-handling';
3
+
4
+ export const appendQueryParams = (url, params) => {
5
+ let hasParams = false;
6
+ forEach(params, function(value, key) {
7
+ if (!isNil(value)) {
8
+ if (!hasParams) {
9
+ url += `?${key}=${value}`;
10
+ hasParams = true;
11
+ }
12
+ else {
13
+ url += `&${key}=${value}`;
14
+ }
15
+ }
16
+ });
17
+ return url;
18
+ };
19
+
20
+ export const convertApiErrorIntoTrimozError = (error) => {
21
+ const contextCode = get(error, 'response.data.messages.errors[0].context.error_code', null);
22
+ const internalCode = retrieveErrorInternalCode(error);
23
+
24
+ return new TrimozError(error, 'errors.generic', internalCode, contextCode);
25
+ };
26
+
27
+ export const retrieveErrorInternalCode = (error) => {
28
+ return get(error, 'response.data.messages.errors[0].internal_code', null);
29
+ };
30
+
31
+ export function inferProfileUrl() {
32
+ let hostname = window.location.host;
33
+ hostname = replace(hostname, 'portal3.', 'profile.');
34
+ hostname = replace(hostname, 'portal.', 'profile.');
35
+ hostname = replace(hostname, 'portal-dot-', 'profile-dot-');
36
+ hostname = replace(hostname, 'clients3.', 'profile.');
37
+ hostname = replace(hostname, 'clients.', 'profile.');
38
+ hostname = replace(hostname, 'public-dot-', 'profile-dot-');
39
+ hostname = replace(hostname, 'admin3.', 'profile.');
40
+ hostname = replace(hostname, 'admin.', 'profile.');
41
+ hostname = replace(hostname, 'admin-dot-', 'profile-dot-');
42
+ hostname = replace(hostname, '8082', '8084');
43
+ hostname = replace(hostname, '8081', '8084');
44
+ hostname = replace(hostname, '8080', '8084');
45
+ return window.location.protocol + '//' + hostname;
46
+ }
47
+
48
+ export function inferCookieDomain(domain = null) {
49
+ let hostname = domain || process.env.VUE_APP_COOKIE_DOMAIN || window.location.hostname;
50
+ hostname = replace(hostname, 'admin3.', '');
51
+ hostname = replace(hostname, 'admin.', '');
52
+ hostname = replace(hostname, 'clients3.', '');
53
+ hostname = replace(hostname, 'clients.', '');
54
+ return hostname;
55
+ }
56
+
57
+ export function isAdminApp() {
58
+ return includes(window.location.host, 'admin') || includes(window.location.host, 'localhost:8080');
59
+ }
60
+
61
+ export const expectedRtkpValue = (domain = window.location.hostname) => {
62
+ return join(['profile', inferCookieDomain(domain)], '.');
63
+ };
64
+
65
+ export const hasRtkpCookie = (domain = window.location.hostname, cookies = document.cookie) => {
66
+ const rtkps = filter(split(cookies, '; '), cookie => startsWith(cookie, 'rtkp='));
67
+ return some(rtkps, rtkp => {
68
+ const rtkpValue = split(rtkp, '=')[1];
69
+ return rtkpValue === expectedRtkpValue(domain);
70
+ });
71
+ };
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # Security holding package
2
-
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=%40trimoz%2Ftrimoz-api-wrapper for more information.