@bigbinary/neeto-commons-frontend 2.0.2 → 2.0.3

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/README.md CHANGED
@@ -7,7 +7,7 @@ The commons frontend library for Neeto Applications.
7
7
  Install from npm:
8
8
 
9
9
  ```bash
10
- yarn add "@bigbinary/neeto-commons-frontend@2.0.2"
10
+ yarn add "@bigbinary/neeto-commons-frontend@2.0.3"
11
11
  ```
12
12
 
13
13
  This package relies on the host project's tailwind configuration. So add
@@ -119,6 +119,22 @@ var keysToCamelCase = function keysToCamelCase(object) {
119
119
  return [snakeToCamelCase(key), value];
120
120
  });
121
121
  };
122
+ var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
123
+ if (Array.isArray(object)) {
124
+ return object.map(serializeKeysToSnakeCase);
125
+ } else if (object === null || _typeof(object) !== "object") {
126
+ return object;
127
+ }
128
+
129
+ return Object.fromEntries(Object.entries(object).map(function (_ref3) {
130
+ var _ref4 = _slicedToArray(_ref3, 2),
131
+ key = _ref4[0],
132
+ value = _ref4[1];
133
+
134
+ var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
135
+ return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
136
+ }));
137
+ };
122
138
  var deepFreezeObject = function deepFreezeObject(object) {
123
139
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
124
140
  Object.keys(object).forEach(function (property) {
@@ -136,10 +152,10 @@ var matches = ramda.curry(function (pattern, object) {
136
152
  if (typeof pattern === "function" && pattern(object, __parent)) return true;
137
153
  if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
138
154
  if (_typeof(pattern) !== "object") return false;
139
- return Object.entries(pattern).every(function (_ref3) {
140
- var _ref4 = _slicedToArray(_ref3, 2),
141
- key = _ref4[0],
142
- value = _ref4[1];
155
+ return Object.entries(pattern).every(function (_ref5) {
156
+ var _ref6 = _slicedToArray(_ref5, 2),
157
+ key = _ref6[0],
158
+ value = _ref6[1];
143
159
 
144
160
  return matches(value, object[key], __parent);
145
161
  });
@@ -281,7 +297,7 @@ var buildErrorResponseHandler = function buildErrorResponseHandler(skip) {
281
297
  if (!(skip !== null && skip !== void 0 && skip.redirectOn404)) interceptors.push(redirect404);
282
298
  if (!(skip !== null && skip !== void 0 && skip.logoutOn401)) interceptors.push(handleUnauthorizedErrorResponse);
283
299
  if (!(skip !== null && skip !== void 0 && skip.showToastr)) interceptors.push(showErrorToastr);
284
- interceptors.push(Promise.reject);
300
+ interceptors.push(Promise.reject.bind(Promise));
285
301
  return createPipe(interceptors);
286
302
  };
287
303
 
@@ -293,23 +309,6 @@ var cleanupCredentialsForCrossOrigin = function cleanupCredentialsForCrossOrigin
293
309
  })(request);
294
310
  };
295
311
 
296
- var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
297
- if (Array.isArray(object)) {
298
- return object.map(serializeKeysToSnakeCase);
299
- } else if (object === null || _typeof(object) !== "object") {
300
- return object;
301
- }
302
-
303
- return Object.fromEntries(Object.entries(object).map(function (_ref) {
304
- var _ref2 = _slicedToArray(_ref, 2),
305
- key = _ref2[0],
306
- value = _ref2[1];
307
-
308
- var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
309
- return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
310
- }));
311
- };
312
-
313
312
  var transformDataToSnakeCase = function transformDataToSnakeCase(request) {
314
313
  var _request$transformReq = request.transformRequestCase,
315
314
  transformRequestCase = _request$transformReq === void 0 ? true : _request$transformReq;
package/initializers.js CHANGED
@@ -109,6 +109,22 @@ var keysToCamelCase = function keysToCamelCase(object) {
109
109
  return [snakeToCamelCase(key), value];
110
110
  });
111
111
  };
112
+ var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
113
+ if (Array.isArray(object)) {
114
+ return object.map(serializeKeysToSnakeCase);
115
+ } else if (object === null || _typeof(object) !== "object") {
116
+ return object;
117
+ }
118
+
119
+ return Object.fromEntries(Object.entries(object).map(function (_ref3) {
120
+ var _ref4 = _slicedToArray(_ref3, 2),
121
+ key = _ref4[0],
122
+ value = _ref4[1];
123
+
124
+ var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
125
+ return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
126
+ }));
127
+ };
112
128
  var deepFreezeObject = function deepFreezeObject(object) {
113
129
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
114
130
  Object.keys(object).forEach(function (property) {
@@ -126,10 +142,10 @@ var matches = curry(function (pattern, object) {
126
142
  if (typeof pattern === "function" && pattern(object, __parent)) return true;
127
143
  if (isNil(pattern) || isNil(object)) return false;
128
144
  if (_typeof(pattern) !== "object") return false;
129
- return Object.entries(pattern).every(function (_ref3) {
130
- var _ref4 = _slicedToArray(_ref3, 2),
131
- key = _ref4[0],
132
- value = _ref4[1];
145
+ return Object.entries(pattern).every(function (_ref5) {
146
+ var _ref6 = _slicedToArray(_ref5, 2),
147
+ key = _ref6[0],
148
+ value = _ref6[1];
133
149
 
134
150
  return matches(value, object[key], __parent);
135
151
  });
@@ -271,7 +287,7 @@ var buildErrorResponseHandler = function buildErrorResponseHandler(skip) {
271
287
  if (!(skip !== null && skip !== void 0 && skip.redirectOn404)) interceptors.push(redirect404);
272
288
  if (!(skip !== null && skip !== void 0 && skip.logoutOn401)) interceptors.push(handleUnauthorizedErrorResponse);
273
289
  if (!(skip !== null && skip !== void 0 && skip.showToastr)) interceptors.push(showErrorToastr);
274
- interceptors.push(Promise.reject);
290
+ interceptors.push(Promise.reject.bind(Promise));
275
291
  return createPipe(interceptors);
276
292
  };
277
293
 
@@ -283,23 +299,6 @@ var cleanupCredentialsForCrossOrigin = function cleanupCredentialsForCrossOrigin
283
299
  })(request);
284
300
  };
285
301
 
286
- var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
287
- if (Array.isArray(object)) {
288
- return object.map(serializeKeysToSnakeCase);
289
- } else if (object === null || _typeof(object) !== "object") {
290
- return object;
291
- }
292
-
293
- return Object.fromEntries(Object.entries(object).map(function (_ref) {
294
- var _ref2 = _slicedToArray(_ref, 2),
295
- key = _ref2[0],
296
- value = _ref2[1];
297
-
298
- var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
299
- return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
300
- }));
301
- };
302
-
303
302
  var transformDataToSnakeCase = function transformDataToSnakeCase(request) {
304
303
  var _request$transformReq = request.transformRequestCase,
305
304
  transformRequestCase = _request$transformReq === void 0 ? true : _request$transformReq;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
5
5
  "repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -81,6 +81,7 @@
81
81
  "lint-staged": "^12.3.7",
82
82
  "mixpanel-browser": "^2.45.0",
83
83
  "prettier": "^2.6.2",
84
+ "query-string": "^7.1.1",
84
85
  "ramda": "^0.28.0",
85
86
  "react": "^17.0.2",
86
87
  "react-dom": "17.0.2",
package/pure.cjs.js CHANGED
@@ -133,6 +133,22 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
133
133
  return [camelToSnakeCase(key), value];
134
134
  });
135
135
  };
136
+ var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
137
+ if (Array.isArray(object)) {
138
+ return object.map(serializeKeysToSnakeCase);
139
+ } else if (object === null || _typeof(object) !== "object") {
140
+ return object;
141
+ }
142
+
143
+ return Object.fromEntries(Object.entries(object).map(function (_ref3) {
144
+ var _ref4 = _slicedToArray(_ref3, 2),
145
+ key = _ref4[0],
146
+ value = _ref4[1];
147
+
148
+ var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
149
+ return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
150
+ }));
151
+ };
136
152
  var deepFreezeObject = function deepFreezeObject(object) {
137
153
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
138
154
  Object.keys(object).forEach(function (property) {
@@ -150,25 +166,25 @@ var matches = ramda.curry(function (pattern, object) {
150
166
  if (typeof pattern === "function" && pattern(object, __parent)) return true;
151
167
  if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
152
168
  if (_typeof(pattern) !== "object") return false;
153
- return Object.entries(pattern).every(function (_ref3) {
154
- var _ref4 = _slicedToArray(_ref3, 2),
155
- key = _ref4[0],
156
- value = _ref4[1];
169
+ return Object.entries(pattern).every(function (_ref5) {
170
+ var _ref6 = _slicedToArray(_ref5, 2),
171
+ key = _ref6[0],
172
+ value = _ref6[1];
157
173
 
158
174
  return matches(value, object[key], __parent);
159
175
  });
160
176
  });
161
177
  var filterNonNull = function filterNonNull(object) {
162
- return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
163
- var _ref6 = _slicedToArray(_ref5, 2),
164
- v = _ref6[1];
165
-
166
- return !ramda.isNil(v);
167
- }).map(function (_ref7) {
178
+ return Object.fromEntries(Object.entries(object).filter(function (_ref7) {
168
179
  var _ref8 = _slicedToArray(_ref7, 2),
169
- k = _ref8[0],
170
180
  v = _ref8[1];
171
181
 
182
+ return !ramda.isNil(v);
183
+ }).map(function (_ref9) {
184
+ var _ref10 = _slicedToArray(_ref9, 2),
185
+ k = _ref10[0],
186
+ v = _ref10[1];
187
+
172
188
  return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
173
189
  }));
174
190
  };
@@ -385,6 +401,7 @@ exports.removeById = removeById;
385
401
  exports.renameKeys = renameKeys;
386
402
  exports.replaceBy = replaceBy;
387
403
  exports.replaceById = replaceById;
404
+ exports.serializeKeysToSnakeCase = serializeKeysToSnakeCase;
388
405
  exports.slugify = slugify;
389
406
  exports.snakeToCamelCase = snakeToCamelCase;
390
407
  exports.toLabelAndValue = toLabelAndValue;
package/pure.d.ts CHANGED
@@ -168,6 +168,7 @@ export function replaceBy(pattern: MatchPattern): <T>(entityArray: T[]) => T[];
168
168
  export function replaceById<T>(id: any, entityArray: T[]): T[];
169
169
  export function replaceById(id: any): <T>(entityArray: T[]) => T[];
170
170
 
171
+ export function serializeKeysToSnakeCase(object: object): object;
171
172
  export function slugify(string: string): string;
172
173
  export function snakeToCamelCase(string: string): string;
173
174
  export function toLabelAndValue(string: string): {
package/pure.js CHANGED
@@ -129,6 +129,22 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
129
129
  return [camelToSnakeCase(key), value];
130
130
  });
131
131
  };
132
+ var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
133
+ if (Array.isArray(object)) {
134
+ return object.map(serializeKeysToSnakeCase);
135
+ } else if (object === null || _typeof(object) !== "object") {
136
+ return object;
137
+ }
138
+
139
+ return Object.fromEntries(Object.entries(object).map(function (_ref3) {
140
+ var _ref4 = _slicedToArray(_ref3, 2),
141
+ key = _ref4[0],
142
+ value = _ref4[1];
143
+
144
+ var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
145
+ return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
146
+ }));
147
+ };
132
148
  var deepFreezeObject = function deepFreezeObject(object) {
133
149
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
134
150
  Object.keys(object).forEach(function (property) {
@@ -146,25 +162,25 @@ var matches = curry(function (pattern, object) {
146
162
  if (typeof pattern === "function" && pattern(object, __parent)) return true;
147
163
  if (isNil(pattern) || isNil(object)) return false;
148
164
  if (_typeof(pattern) !== "object") return false;
149
- return Object.entries(pattern).every(function (_ref3) {
150
- var _ref4 = _slicedToArray(_ref3, 2),
151
- key = _ref4[0],
152
- value = _ref4[1];
165
+ return Object.entries(pattern).every(function (_ref5) {
166
+ var _ref6 = _slicedToArray(_ref5, 2),
167
+ key = _ref6[0],
168
+ value = _ref6[1];
153
169
 
154
170
  return matches(value, object[key], __parent);
155
171
  });
156
172
  });
157
173
  var filterNonNull = function filterNonNull(object) {
158
- return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
159
- var _ref6 = _slicedToArray(_ref5, 2),
160
- v = _ref6[1];
161
-
162
- return !isNil(v);
163
- }).map(function (_ref7) {
174
+ return Object.fromEntries(Object.entries(object).filter(function (_ref7) {
164
175
  var _ref8 = _slicedToArray(_ref7, 2),
165
- k = _ref8[0],
166
176
  v = _ref8[1];
167
177
 
178
+ return !isNil(v);
179
+ }).map(function (_ref9) {
180
+ var _ref10 = _slicedToArray(_ref9, 2),
181
+ k = _ref10[0],
182
+ v = _ref10[1];
183
+
168
184
  return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
169
185
  }));
170
186
  };
@@ -344,4 +360,4 @@ var isNot = notEquals;
344
360
  var notEqualsDeep = complement(equals);
345
361
  var isNotEqualDeep = notEqualsDeep;
346
362
 
347
- export { camelToSnakeCase, capitalize, copyKeys, copyKeysDeep, countBy, deepFreezeObject, dynamicArray, existsBy, existsById, filterBy, filterNonNull, findBy, findById, findIndexBy, findIndexById, findLastBy, findLastIndexBy, getRandomInt, humanize, isNot, isNotEmpty, isNotEqualDeep, isNotNil, keysToCamelCase, keysToSnakeCase, matches, modifyBy, modifyById, noop, notEquals, notEqualsDeep, randomPick, removeBy, removeById, renameKeys, replaceBy, replaceById, slugify, snakeToCamelCase, toLabelAndValue, transformObjectDeep, truncate };
363
+ export { camelToSnakeCase, capitalize, copyKeys, copyKeysDeep, countBy, deepFreezeObject, dynamicArray, existsBy, existsById, filterBy, filterNonNull, findBy, findById, findIndexBy, findIndexById, findLastBy, findLastIndexBy, getRandomInt, humanize, isNot, isNotEmpty, isNotEqualDeep, isNotNil, keysToCamelCase, keysToSnakeCase, matches, modifyBy, modifyById, noop, notEquals, notEqualsDeep, randomPick, removeBy, removeById, renameKeys, replaceBy, replaceById, serializeKeysToSnakeCase, slugify, snakeToCamelCase, toLabelAndValue, transformObjectDeep, truncate };
@@ -1174,15 +1174,14 @@ function SignIn(_ref) {
1174
1174
  response = _context.sent;
1175
1175
  neetoui.Toastr.success("Logged in successfully.");
1176
1176
  redirectAfterSuccessfulLogin(response.redirectTo);
1177
- _context.next = 11;
1177
+ _context.next = 10;
1178
1178
  break;
1179
1179
 
1180
1180
  case 8:
1181
1181
  _context.prev = 8;
1182
1182
  _context.t0 = _context["catch"](0);
1183
- neetoui.Toastr.error(_context.t0);
1184
1183
 
1185
- case 11:
1184
+ case 10:
1186
1185
  case "end":
1187
1186
  return _context.stop();
1188
1187
  }
package/react-utils.js CHANGED
@@ -1145,15 +1145,14 @@ function SignIn(_ref) {
1145
1145
  response = _context.sent;
1146
1146
  Toastr.success("Logged in successfully.");
1147
1147
  redirectAfterSuccessfulLogin(response.redirectTo);
1148
- _context.next = 11;
1148
+ _context.next = 10;
1149
1149
  break;
1150
1150
 
1151
1151
  case 8:
1152
1152
  _context.prev = 8;
1153
1153
  _context.t0 = _context["catch"](0);
1154
- Toastr.error(_context.t0);
1155
1154
 
1156
- case 11:
1155
+ case 10:
1157
1156
  case "end":
1158
1157
  return _context.stop();
1159
1158
  }