homeflowjs 1.0.3 → 1.0.4

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,
@@ -127,19 +127,35 @@ export const postPropertyView = (payload) => () => {
127
127
  });
128
128
  };
129
129
 
130
- export const postBulkPropertyExposureCreation = (payload) => () => {
130
+ export const postBulkPropertyExposureCreation = (payload, { sendAsFormData } = {}) => () => {
131
131
  const domain = location.hostname;
132
132
  const exposuresPublicUrl = Homeflow.get('exposures_public_url');
133
133
 
134
134
  if (!exposuresPublicUrl) return;
135
135
 
136
136
  const { propertyIds, eventType } = payload;
137
+ const data = { property_ids: propertyIds, domain, event_type: eventType };
138
+ let headers = {};
139
+ let body;
140
+ let contentType;
141
+ if (sendAsFormData) {
142
+ contentType = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' };
143
+ body = JSON_to_URLEncoded(data);
144
+ } else {
145
+ contentType = { 'Content-Type': 'application/json' };
146
+ body = JSON.stringify({ property_ids: propertyIds, domain, event_type: eventType });
147
+ }
148
+
149
+ headers = {
150
+ ...headers,
151
+ ...contentType
152
+ };
137
153
  fetch(`${exposuresPublicUrl}/create_many`,
138
154
  {
139
155
  method: 'POST',
140
156
  mode: 'no-cors',
141
- headers: { 'Content-Type': 'application/json' },
142
- body: JSON.stringify({ property_ids: propertyIds, domain, event_type: eventType }),
157
+ headers,
158
+ body,
143
159
  });
144
160
  };
145
161
 
@@ -116,7 +116,7 @@ const hfInitialize = () => {
116
116
  postBulkPropertyExposureCreation({
117
117
  eventType: 'SearchResult',
118
118
  propertyIds,
119
- }),
119
+ }, Homeflow.get('createManyOptions')),
120
120
  );
121
121
  }
122
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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
+ }