homeflowjs 1.0.3 → 1.0.5

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.
@@ -3,7 +3,7 @@ import PropertiesActionTypes from './properties.types';
3
3
  import { buildQueryString } from '../search/property-search/property-search';
4
4
  import { setSearch } from './search.actions';
5
5
  import { setLoading } from './app.actions';
6
- import { getOfflineSavedProperties } from '../utils';
6
+ import { JSON_to_URLEncoded, getOfflineSavedProperties } from '../utils';
7
7
 
8
8
  export const setPropertyLinks = (payload) => ({
9
9
  type: PropertiesActionTypes.SET_PROPERTY_LINKS,
@@ -128,18 +128,35 @@ export const postPropertyView = (payload) => () => {
128
128
  };
129
129
 
130
130
  export const postBulkPropertyExposureCreation = (payload) => () => {
131
+ const { sendAsFormData } = Homeflow.get('createManyOptions') ?? {};
131
132
  const domain = location.hostname;
132
133
  const exposuresPublicUrl = Homeflow.get('exposures_public_url');
133
134
 
134
135
  if (!exposuresPublicUrl) return;
135
136
 
136
137
  const { propertyIds, eventType } = payload;
138
+ const data = { property_ids: propertyIds, domain, event_type: eventType };
139
+ let headers = {};
140
+ let body;
141
+ let contentType;
142
+ if (sendAsFormData) {
143
+ contentType = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' };
144
+ body = JSON_to_URLEncoded(data);
145
+ } else {
146
+ contentType = { 'Content-Type': 'application/json' };
147
+ body = JSON.stringify({ property_ids: propertyIds, domain, event_type: eventType });
148
+ }
149
+
150
+ headers = {
151
+ ...headers,
152
+ ...contentType
153
+ };
137
154
  fetch(`${exposuresPublicUrl}/create_many`,
138
155
  {
139
156
  method: 'POST',
140
157
  mode: 'no-cors',
141
- headers: { 'Content-Type': 'application/json' },
142
- body: JSON.stringify({ property_ids: propertyIds, domain, event_type: eventType }),
158
+ headers,
159
+ body,
143
160
  });
144
161
  };
145
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
package/utils/index.js CHANGED
@@ -141,4 +141,15 @@ export const getOfflineSavedProperties = () => {
141
141
  return Array.isArray(offlineSavedProperties)
142
142
  ? offlineSavedProperties
143
143
  : [];
144
- }
144
+ }
145
+
146
+ export function JSON_to_URLEncoded(element,key,list){
147
+ var list = list || [];
148
+ if(typeof(element)=='object'){
149
+ for (var idx in element)
150
+ JSON_to_URLEncoded(element[idx],key?key+'[]':idx,list);
151
+ } else {
152
+ list.push(key+'='+encodeURIComponent(element));
153
+ }
154
+ return encodeURI(list.join('&'));
155
+ }