@pushwoosh/kit-helpers 4.11.1 → 4.11.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/analytics/identifyOpenReplay.js +4 -2
- package/callWithRetry.d.ts +37 -0
- package/callWithRetry.js +57 -0
- package/expand.js +24 -18
- package/flex.d.ts +6 -6
- package/grid.d.ts +29 -29
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/package.json +2 -2
|
@@ -8,9 +8,11 @@ export const identifyOpenReplaySession = properties => {
|
|
|
8
8
|
store.push(properties);
|
|
9
9
|
window.pwOpenReplayIdentifyStore = store;
|
|
10
10
|
} else {
|
|
11
|
-
|
|
11
|
+
var _window$OpenReplay;
|
|
12
|
+
(_window$OpenReplay = window.OpenReplay) === null || _window$OpenReplay === void 0 || _window$OpenReplay.setUserID(properties.email);
|
|
12
13
|
if (properties.accountID) {
|
|
13
|
-
|
|
14
|
+
var _window$OpenReplay2;
|
|
15
|
+
(_window$OpenReplay2 = window.OpenReplay) === null || _window$OpenReplay2 === void 0 || _window$OpenReplay2.setMetadata('AccountID', `${properties.accountID}`);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry / polling policy for a single operation.
|
|
3
|
+
*
|
|
4
|
+
* Retry is always opt-in: `callWithRetry` is the only entry point, so plain calls run once and
|
|
5
|
+
* non-idempotent operations are never retried unless a policy is passed.
|
|
6
|
+
*/
|
|
7
|
+
export type RetryPolicy<T> = {
|
|
8
|
+
/** Maximum number of attempts, including the first one. Must be a positive integer. */
|
|
9
|
+
readonly attempts: number;
|
|
10
|
+
/** Delay in milliseconds between two consecutive attempts. */
|
|
11
|
+
readonly delay: number;
|
|
12
|
+
/**
|
|
13
|
+
* Poll predicate. Return `true` when the result is final and the loop must stop.
|
|
14
|
+
* Omit it to stop on the first successful result (plain retry, without polling).
|
|
15
|
+
*/
|
|
16
|
+
readonly until?: (result: T) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Decide whether to retry after a thrown error. Return `true` to retry.
|
|
19
|
+
* Omit it and errors propagate immediately, which keeps non-idempotent operations safe.
|
|
20
|
+
*/
|
|
21
|
+
readonly retryOnError?: (error: unknown, attempt: number) => boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Raised when a retry / polling policy runs out of attempts before its stop condition is met.
|
|
25
|
+
*/
|
|
26
|
+
export declare class RetryExhaustedError extends Error {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Run an async operation under a retry / polling policy — the single place that owns the
|
|
31
|
+
* attempt loop and the delay between attempts. Callers describe *when* to stop (`until`) and
|
|
32
|
+
* *whether* to retry on error (`retryOnError`); they never hand-write the loop themselves.
|
|
33
|
+
*
|
|
34
|
+
* @param operation - operation to run; receives the 1-based attempt number.
|
|
35
|
+
* @param policy - retry / polling policy.
|
|
36
|
+
*/
|
|
37
|
+
export declare const callWithRetry: <T>(operation: (attempt: number) => Promise<T>, policy: RetryPolicy<T>) => Promise<T>;
|
package/callWithRetry.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raised when a retry / polling policy runs out of attempts before its stop condition is met.
|
|
3
|
+
*/
|
|
4
|
+
export class RetryExhaustedError extends Error {
|
|
5
|
+
constructor(message = 'Retry attempts exhausted!') {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'RetryExhaustedError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const sleep = ms => new Promise(resolve => {
|
|
11
|
+
setTimeout(resolve, ms);
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Run an async operation under a retry / polling policy — the single place that owns the
|
|
15
|
+
* attempt loop and the delay between attempts. Callers describe *when* to stop (`until`) and
|
|
16
|
+
* *whether* to retry on error (`retryOnError`); they never hand-write the loop themselves.
|
|
17
|
+
*
|
|
18
|
+
* @param operation - operation to run; receives the 1-based attempt number.
|
|
19
|
+
* @param policy - retry / polling policy.
|
|
20
|
+
*/
|
|
21
|
+
export const callWithRetry = async (operation, policy) => {
|
|
22
|
+
if (!Number.isInteger(policy.attempts) || policy.attempts < 1) {
|
|
23
|
+
throw new RangeError(`callWithRetry: "attempts" must be a positive integer, got ${policy.attempts}.`);
|
|
24
|
+
}
|
|
25
|
+
let lastAttempt = {
|
|
26
|
+
kind: 'unmet'
|
|
27
|
+
};
|
|
28
|
+
for (let attempt = 1; attempt <= policy.attempts; attempt += 1) {
|
|
29
|
+
try {
|
|
30
|
+
// eslint-disable-next-line no-await-in-loop
|
|
31
|
+
const result = await operation(attempt);
|
|
32
|
+
if (!policy.until || policy.until(result)) {
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
lastAttempt = {
|
|
36
|
+
kind: 'unmet'
|
|
37
|
+
};
|
|
38
|
+
} catch (error) {
|
|
39
|
+
var _policy$retryOnError;
|
|
40
|
+
if (((_policy$retryOnError = policy.retryOnError) === null || _policy$retryOnError === void 0 ? void 0 : _policy$retryOnError.call(policy, error, attempt)) !== true) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
lastAttempt = {
|
|
44
|
+
kind: 'error',
|
|
45
|
+
error
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (attempt < policy.attempts) {
|
|
49
|
+
// eslint-disable-next-line no-await-in-loop
|
|
50
|
+
await sleep(policy.delay);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (lastAttempt.kind === 'error') {
|
|
54
|
+
throw lastAttempt.error;
|
|
55
|
+
}
|
|
56
|
+
throw new RetryExhaustedError(`Retry policy exhausted after ${policy.attempts} attempt(s) without meeting the stop condition.`);
|
|
57
|
+
};
|
package/expand.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
3
|
/* eslint-disable react/require-default-props, react/jsx-no-bind */
|
|
2
|
-
import
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
5
|
import { CSSTransition, TransitionGroup } from 'react-transition-group';
|
|
4
6
|
import styled, { css } from 'styled-components';
|
|
5
7
|
const ExpandTransitionComp = ({
|
|
@@ -22,21 +24,24 @@ const ExpandTransitionComp = ({
|
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
useEffect(updateStyle, [timeout]);
|
|
25
|
-
return
|
|
27
|
+
return _jsx(CSSTransition, {
|
|
26
28
|
...rest,
|
|
27
29
|
timeout: timeout,
|
|
28
30
|
classNames: className,
|
|
29
31
|
onEnter: updateStyle,
|
|
30
32
|
onExit: updateStyle,
|
|
31
|
-
nodeRef: refExternal
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
nodeRef: refExternal,
|
|
34
|
+
children: _jsx("div", {
|
|
35
|
+
ref: refExternal,
|
|
36
|
+
className: externalClassName ? `${className} ${externalClassName}` : className,
|
|
37
|
+
style: externalStyle,
|
|
38
|
+
children: _jsx("div", {
|
|
39
|
+
ref: refInternal,
|
|
40
|
+
className: internalClassName,
|
|
41
|
+
children: children
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
});
|
|
40
45
|
};
|
|
41
46
|
const CollapseTransition = styled(ExpandTransitionComp).withConfig({
|
|
42
47
|
displayName: "CollapseTransition",
|
|
@@ -53,10 +58,11 @@ export const Collapse = ({
|
|
|
53
58
|
children,
|
|
54
59
|
className,
|
|
55
60
|
...rest
|
|
56
|
-
}) =>
|
|
57
|
-
component: null
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}, typeof children === 'function' ? children() : children)
|
|
61
|
+
}) => _jsx(TransitionGroup, {
|
|
62
|
+
component: null,
|
|
63
|
+
children: expanded && _createElement(CollapseTransition, {
|
|
64
|
+
...rest,
|
|
65
|
+
externalClassName: className,
|
|
66
|
+
key: 0
|
|
67
|
+
}, typeof children === 'function' ? children() : children)
|
|
68
|
+
});
|
package/flex.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ type FlexContainerProps = CommonContainerProps & {
|
|
|
5
5
|
};
|
|
6
6
|
export declare const FlexContainer: import("styled-components").StyledComponent<"div", any, FlexContainerProps, never>;
|
|
7
7
|
export declare const Cluster: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
|
|
8
|
-
$alignContent?: import("./styled-helpers").AlignContentValue
|
|
9
|
-
$alignItems?: import("./styled-helpers").ItemAlignmentValue
|
|
10
|
-
$gap?: import("./styled-helpers").StrNum
|
|
11
|
-
$justifyContent?: import("./styled-helpers").JustifyContentValue
|
|
8
|
+
$alignContent?: import("./styled-helpers").AlignContentValue;
|
|
9
|
+
$alignItems?: import("./styled-helpers").ItemAlignmentValue;
|
|
10
|
+
$gap?: import("./styled-helpers").StrNum;
|
|
11
|
+
$justifyContent?: import("./styled-helpers").JustifyContentValue;
|
|
12
12
|
} & {
|
|
13
|
-
$flexDirection?: "row" | "row-reverse" | "column" | "column-reverse"
|
|
14
|
-
$flexWrap?: "
|
|
13
|
+
$flexDirection?: "row" | "row-reverse" | "column" | "column-reverse";
|
|
14
|
+
$flexWrap?: "nowrap" | "wrap" | "wrap-reverse";
|
|
15
15
|
} & {
|
|
16
16
|
$flexWrap: string;
|
|
17
17
|
}, "$flexWrap">;
|
package/grid.d.ts
CHANGED
|
@@ -7,50 +7,50 @@ type GridContainerProps = CommonContainerProps & {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const GridContainer: import("styled-components").StyledComponent<"div", any, GridContainerProps, never>;
|
|
9
9
|
export declare const Columns: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
|
|
10
|
-
$alignContent?: import("./styled-helpers").AlignContentValue
|
|
11
|
-
$alignItems?: ItemAlignmentValue
|
|
12
|
-
$gap?: StrNum
|
|
13
|
-
$justifyContent?: import("./styled-helpers").JustifyContentValue
|
|
10
|
+
$alignContent?: import("./styled-helpers").AlignContentValue;
|
|
11
|
+
$alignItems?: ItemAlignmentValue;
|
|
12
|
+
$gap?: StrNum;
|
|
13
|
+
$justifyContent?: import("./styled-helpers").JustifyContentValue;
|
|
14
14
|
} & {
|
|
15
|
-
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense"
|
|
16
|
-
$justifyItems?: ItemAlignmentValue
|
|
17
|
-
$placeItems?: ItemAlignmentValue
|
|
15
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense";
|
|
16
|
+
$justifyItems?: ItemAlignmentValue;
|
|
17
|
+
$placeItems?: ItemAlignmentValue;
|
|
18
18
|
} & {
|
|
19
19
|
$sizes: StrNum;
|
|
20
20
|
}, never>;
|
|
21
21
|
export declare const Rows: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
|
|
22
|
-
$alignContent?: import("./styled-helpers").AlignContentValue
|
|
23
|
-
$alignItems?: ItemAlignmentValue
|
|
24
|
-
$gap?: StrNum
|
|
25
|
-
$justifyContent?: import("./styled-helpers").JustifyContentValue
|
|
22
|
+
$alignContent?: import("./styled-helpers").AlignContentValue;
|
|
23
|
+
$alignItems?: ItemAlignmentValue;
|
|
24
|
+
$gap?: StrNum;
|
|
25
|
+
$justifyContent?: import("./styled-helpers").JustifyContentValue;
|
|
26
26
|
} & {
|
|
27
|
-
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense"
|
|
28
|
-
$justifyItems?: ItemAlignmentValue
|
|
29
|
-
$placeItems?: ItemAlignmentValue
|
|
27
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense";
|
|
28
|
+
$justifyItems?: ItemAlignmentValue;
|
|
29
|
+
$placeItems?: ItemAlignmentValue;
|
|
30
30
|
} & {
|
|
31
31
|
$sizes: StrNum;
|
|
32
32
|
}, never>;
|
|
33
33
|
export declare const Horizontal: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
|
|
34
|
-
$alignContent?: import("./styled-helpers").AlignContentValue
|
|
35
|
-
$alignItems?: ItemAlignmentValue
|
|
36
|
-
$gap?: StrNum
|
|
37
|
-
$justifyContent?: import("./styled-helpers").JustifyContentValue
|
|
34
|
+
$alignContent?: import("./styled-helpers").AlignContentValue;
|
|
35
|
+
$alignItems?: ItemAlignmentValue;
|
|
36
|
+
$gap?: StrNum;
|
|
37
|
+
$justifyContent?: import("./styled-helpers").JustifyContentValue;
|
|
38
38
|
} & {
|
|
39
|
-
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense"
|
|
40
|
-
$justifyItems?: ItemAlignmentValue
|
|
41
|
-
$placeItems?: ItemAlignmentValue
|
|
39
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense";
|
|
40
|
+
$justifyItems?: ItemAlignmentValue;
|
|
41
|
+
$placeItems?: ItemAlignmentValue;
|
|
42
42
|
} & {
|
|
43
43
|
$gridAutoFlow: string;
|
|
44
44
|
}, "$gridAutoFlow">;
|
|
45
45
|
export declare const Vertical: import("styled-components").StyledComponent<"div", any, import("./styled-helpers").CommonBoxProps & {
|
|
46
|
-
$alignContent?: import("./styled-helpers").AlignContentValue
|
|
47
|
-
$alignItems?: ItemAlignmentValue
|
|
48
|
-
$gap?: StrNum
|
|
49
|
-
$justifyContent?: import("./styled-helpers").JustifyContentValue
|
|
50
|
-
} & {
|
|
51
|
-
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense"
|
|
52
|
-
$justifyItems?: ItemAlignmentValue
|
|
53
|
-
$placeItems?: ItemAlignmentValue
|
|
46
|
+
$alignContent?: import("./styled-helpers").AlignContentValue;
|
|
47
|
+
$alignItems?: ItemAlignmentValue;
|
|
48
|
+
$gap?: StrNum;
|
|
49
|
+
$justifyContent?: import("./styled-helpers").JustifyContentValue;
|
|
50
|
+
} & {
|
|
51
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense";
|
|
52
|
+
$justifyItems?: ItemAlignmentValue;
|
|
53
|
+
$placeItems?: ItemAlignmentValue;
|
|
54
54
|
} & {
|
|
55
55
|
$gridAutoFlow: string;
|
|
56
56
|
}, "$gridAutoFlow">;
|
package/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export * from './hooks/useClickAway';
|
|
|
5
5
|
export { identifyOpenReplaySession } from './analytics/identifyOpenReplay';
|
|
6
6
|
export { trackEvent } from './analytics/trackEvent';
|
|
7
7
|
export { formatNumber } from './formatNumber';
|
|
8
|
+
export { callWithRetry, RetryExhaustedError } from './callWithRetry';
|
|
9
|
+
export type { RetryPolicy } from './callWithRetry';
|
|
8
10
|
export { readNavigationHistory, writeNavigationHistory } from './navigation';
|
|
9
11
|
export { default as usePersistentFunction } from './hooks/usePersistentFunction';
|
|
10
12
|
export { default as useEffectOnce } from './hooks/useEffectOnce';
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './hooks/useClickAway';
|
|
|
5
5
|
export { identifyOpenReplaySession } from './analytics/identifyOpenReplay';
|
|
6
6
|
export { trackEvent } from './analytics/trackEvent';
|
|
7
7
|
export { formatNumber } from './formatNumber';
|
|
8
|
+
export { callWithRetry, RetryExhaustedError } from './callWithRetry';
|
|
8
9
|
export { readNavigationHistory, writeNavigationHistory } from './navigation';
|
|
9
10
|
export { default as usePersistentFunction } from './hooks/usePersistentFunction';
|
|
10
11
|
export { default as useEffectOnce } from './hooks/useEffectOnce';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/kit-helpers",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.3",
|
|
4
4
|
"description": "React component for build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"react-transition-group": "^4.4.5"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@pushwoosh/frontend-builder-engine": "^
|
|
22
|
+
"@pushwoosh/frontend-builder-engine": "^2.1.1",
|
|
23
23
|
"@pushwoosh/kit-constants": "^1.6.0",
|
|
24
24
|
"@types/react": "^16.14.20",
|
|
25
25
|
"@types/react-dom": "^16.9.14",
|