@flowgram.ai/utils 0.4.15 → 0.4.17

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/dist/index.d.mts CHANGED
@@ -905,6 +905,12 @@ declare namespace Angle {
905
905
  */
906
906
  declare function deepFreeze<T>(obj: T): T;
907
907
  declare function notEmpty<T>(arg: T | undefined | null): arg is T;
908
+ /**
909
+ * filter dangerous key, prevent prototype pollution injection
910
+ * @param key key to be filtered
911
+ * @returns filtered key
912
+ */
913
+ declare const safeKey: (key: string) => string;
908
914
  /**
909
915
  * `true` if the argument is an empty object. Otherwise, `false`.
910
916
  */
@@ -1362,4 +1368,4 @@ declare const DecorationStyle: {
1362
1368
  */
1363
1369
  declare function useRefresh(defaultValue?: any): (v?: any) => void;
1364
1370
 
1365
- export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, setByKey, useRefresh, values };
1371
+ export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, safeKey, setByKey, useRefresh, values };
package/dist/index.d.ts CHANGED
@@ -905,6 +905,12 @@ declare namespace Angle {
905
905
  */
906
906
  declare function deepFreeze<T>(obj: T): T;
907
907
  declare function notEmpty<T>(arg: T | undefined | null): arg is T;
908
+ /**
909
+ * filter dangerous key, prevent prototype pollution injection
910
+ * @param key key to be filtered
911
+ * @returns filtered key
912
+ */
913
+ declare const safeKey: (key: string) => string;
908
914
  /**
909
915
  * `true` if the argument is an empty object. Otherwise, `false`.
910
916
  */
@@ -1362,4 +1368,4 @@ declare const DecorationStyle: {
1362
1368
  */
1363
1369
  declare function useRefresh(defaultValue?: any): (v?: any) => void;
1364
1370
 
1365
- export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, setByKey, useRefresh, values };
1371
+ export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, safeKey, setByKey, useRefresh, values };
package/dist/index.js CHANGED
@@ -116,6 +116,7 @@ __export(index_exports, {
116
116
  reduce: () => reduce,
117
117
  requestWithMemo: () => requestWithMemo,
118
118
  retry: () => retry,
119
+ safeKey: () => safeKey,
119
120
  setByKey: () => setByKey,
120
121
  useRefresh: () => useRefresh,
121
122
  values: () => values
@@ -1399,6 +1400,27 @@ var _hasOwnProperty = Object.prototype.hasOwnProperty;
1399
1400
  function notEmpty(arg) {
1400
1401
  return arg !== void 0 && arg !== null;
1401
1402
  }
1403
+ var safeKey = (key) => {
1404
+ const dangerousProps = [
1405
+ "__proto__",
1406
+ "constructor",
1407
+ "prototype",
1408
+ "__defineGetter__",
1409
+ "__defineSetter__",
1410
+ "__lookupGetter__",
1411
+ "__lookupSetter__",
1412
+ "hasOwnProperty",
1413
+ "isPrototypeOf",
1414
+ "propertyIsEnumerable",
1415
+ "toString",
1416
+ "valueOf",
1417
+ "toLocaleString"
1418
+ ];
1419
+ if (dangerousProps.includes(key.toLowerCase())) {
1420
+ return "";
1421
+ }
1422
+ return key;
1423
+ };
1402
1424
  function isEmpty(arg) {
1403
1425
  return keys(arg).length === 0 && arg.constructor === Object;
1404
1426
  }
@@ -1430,18 +1452,18 @@ function setByKey(target, key, newValue, autoCreateObject = true, clone = false)
1430
1452
  while (targetKeys.length > 0) {
1431
1453
  key = targetKeys.shift();
1432
1454
  if (targetKeys.length === 0) {
1433
- target[key] = newValue;
1455
+ target[safeKey(key)] = newValue;
1434
1456
  return originTarget;
1435
1457
  }
1436
1458
  if (typeof target[key] !== "object") {
1437
1459
  if (!autoCreateObject) return originTarget;
1438
- target[key] = {};
1460
+ target[safeKey(key)] = {};
1439
1461
  }
1440
1462
  if (clone) {
1441
1463
  if (Array.isArray(target[key])) {
1442
- target[key] = target[key].slice();
1464
+ target[safeKey(key)] = target[key].slice();
1443
1465
  } else {
1444
- target[key] = { ...target[key] };
1466
+ target[safeKey(key)] = { ...target[key] };
1445
1467
  }
1446
1468
  }
1447
1469
  target = target[key];
@@ -2616,6 +2638,7 @@ function useRefresh(defaultValue) {
2616
2638
  reduce,
2617
2639
  requestWithMemo,
2618
2640
  retry,
2641
+ safeKey,
2619
2642
  setByKey,
2620
2643
  useRefresh,
2621
2644
  values