@reykjavik/webtools 0.3.0 → 0.3.2
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/CHANGELOG.md +9 -1
- package/CookieHubConsent.d.ts +2 -2
- package/CookieHubConsent.js +2 -2
- package/README.md +24 -0
- package/SiteImprove.d.ts +3 -3
- package/SiteImprove.js +3 -3
- package/async.d.ts +4 -4
- package/async.js +3 -3
- package/errorhandling.d.ts +17 -10
- package/errorhandling.js +7 -7
- package/esm/CookieHubConsent.d.ts +2 -2
- package/esm/CookieHubConsent.js +2 -2
- package/esm/SiteImprove.d.ts +3 -3
- package/esm/SiteImprove.js +3 -3
- package/esm/async.d.ts +4 -4
- package/esm/async.js +3 -3
- package/esm/errorhandling.d.ts +17 -10
- package/esm/errorhandling.js +7 -7
- package/esm/hooks.d.ts +2 -2
- package/esm/hooks.js +2 -2
- package/esm/http.d.ts +5 -5
- package/esm/http.js +4 -4
- package/esm/next/http.d.ts +2 -2
- package/esm/next/http.js +3 -3
- package/esm/react-router/Wait.d.ts +2 -2
- package/esm/react-router/Wait.js +1 -1
- package/esm/react-router/http.d.ts +1 -1
- package/esm/react-router/http.js +1 -1
- package/esm/vanillaExtract.d.ts +4 -4
- package/esm/vanillaExtract.js +3 -3
- package/hooks.d.ts +2 -2
- package/hooks.js +2 -2
- package/http.d.ts +5 -5
- package/http.js +4 -4
- package/next/http.d.ts +2 -2
- package/next/http.js +3 -3
- package/package.json +1 -1
- package/react-router/Wait.d.ts +2 -2
- package/react-router/Wait.js +1 -1
- package/react-router/http.d.ts +1 -1
- package/react-router/http.js +1 -1
- package/vanillaExtract.d.ts +4 -4
- package/vanillaExtract.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.3.
|
|
7
|
+
## 0.3.2
|
|
8
|
+
|
|
9
|
+
_2025-12-01_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/errorhandling`:
|
|
12
|
+
- feat: Add type `Result.PayloadOf<T>` to extract the successful payload
|
|
13
|
+
type from a `ResultTuple<T>` or a `ResultTuple`-returning function.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 – 0.3.1
|
|
8
16
|
|
|
9
17
|
_2025-11-10_
|
|
10
18
|
|
package/CookieHubConsent.d.ts
CHANGED
|
@@ -220,14 +220,14 @@ export type CookieHubProviderProps = EitherObj<{
|
|
|
220
220
|
* management script and sets up a React state object with the relevant user
|
|
221
221
|
* consent flags.
|
|
222
222
|
*
|
|
223
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
223
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cookiehubprovider-component
|
|
224
224
|
*/
|
|
225
225
|
export declare const CookieHubProvider: (props: CookieHubProviderProps) => React.JSX.Element;
|
|
226
226
|
/**
|
|
227
227
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
228
228
|
* functions.
|
|
229
229
|
*
|
|
230
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
230
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usecookiehubconsent
|
|
231
231
|
*/
|
|
232
232
|
export declare const useCookieHubConsent: () => Partial<CookieHubContextState["consent"]>;
|
|
233
233
|
export {};
|
package/CookieHubConsent.js
CHANGED
|
@@ -71,7 +71,7 @@ const moveCookiehubScriptInDomTree = () => {
|
|
|
71
71
|
* management script and sets up a React state object with the relevant user
|
|
72
72
|
* consent flags.
|
|
73
73
|
*
|
|
74
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
74
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cookiehubprovider-component
|
|
75
75
|
*/
|
|
76
76
|
const CookieHubProvider = (props) => {
|
|
77
77
|
const [state, setState] = (0, react_1.useState)(initialConsentState);
|
|
@@ -159,7 +159,7 @@ exports.CookieHubProvider = CookieHubProvider;
|
|
|
159
159
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
160
160
|
* functions.
|
|
161
161
|
*
|
|
162
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
162
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usecookiehubconsent
|
|
163
163
|
*/
|
|
164
164
|
const useCookieHubConsent = () => { var _a; return ((_a = (0, react_1.useContext)(CookieHubContext)) === null || _a === void 0 ? void 0 : _a.consent) || {}; };
|
|
165
165
|
exports.useCookieHubConsent = useCookieHubConsent;
|
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ bun add @reykjavik/webtools
|
|
|
46
46
|
- [`Result.Success`](#resultsuccess)
|
|
47
47
|
- [`Result.Fail`](#resultfail)
|
|
48
48
|
- [`Result.throw`](#resultthrow)
|
|
49
|
+
- [Type `Result.PayloadOf`](#type-resultpayloadof)
|
|
49
50
|
- [`@reykjavik/webtools/SiteImprove`](#reykjavikwebtoolssiteimprove)
|
|
50
51
|
- [`SiteImprove` component](#siteimprove-component)
|
|
51
52
|
- [`pingSiteImprove` helper](#pingsiteimprove-helper)
|
|
@@ -838,6 +839,29 @@ try {
|
|
|
838
839
|
|
|
839
840
|
This function acts as the inverse of [`Result.catch()`](#resultcatch).
|
|
840
841
|
|
|
842
|
+
### Type `Result.PayloadOf`
|
|
843
|
+
|
|
844
|
+
**Syntax:**
|
|
845
|
+
`Result.PayloadOf<T extends | ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)>`
|
|
846
|
+
|
|
847
|
+
This utility type extracts the successful payload type `T` from a
|
|
848
|
+
`Result.Tuple<T>`-like type, a `Promise` of such type, or a function returning
|
|
849
|
+
either of those.
|
|
850
|
+
|
|
851
|
+
```ts
|
|
852
|
+
import { Result } from '@reykjavik/webtools/errorhandling';
|
|
853
|
+
|
|
854
|
+
type ResTpl = Result.Tuple<string, Error>;
|
|
855
|
+
type ResTplPromise = Promise<Result.Tuple<number, Error>>;
|
|
856
|
+
type ResTplFn = (arg: unknown) => Result.Tuple<boolean, Error>;
|
|
857
|
+
type ResTplPromiseFn = (arg: unknown) => Promise<Result.Tuple<Date, Error>>;
|
|
858
|
+
|
|
859
|
+
type Payload1 = Result.PayloadOf<ResTpl>; // string
|
|
860
|
+
type Payload2 = Result.PayloadOf<ResTplPromise>; // number
|
|
861
|
+
type Payload3 = Result.PayloadOf<ResTplFn>; // boolean
|
|
862
|
+
type Payload4 = Result.PayloadOf<ResTplPromiseFn>; // Date
|
|
863
|
+
```
|
|
864
|
+
|
|
841
865
|
---
|
|
842
866
|
|
|
843
867
|
## `@reykjavik/webtools/SiteImprove`
|
package/SiteImprove.d.ts
CHANGED
|
@@ -45,14 +45,14 @@ type SiteImproveCustomEvent = [
|
|
|
45
45
|
/**
|
|
46
46
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
47
47
|
*
|
|
48
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimprove-helper
|
|
49
49
|
*/
|
|
50
50
|
export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
|
|
51
51
|
/**
|
|
52
52
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
53
53
|
* being sent to a different URL/resource.
|
|
54
54
|
*
|
|
55
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
55
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimproveoutbound-helper
|
|
56
56
|
*/
|
|
57
57
|
export declare const pingSiteImproveOutbound: (ourl: string) => void;
|
|
58
58
|
export type SiteImproveProps = EitherObj<{
|
|
@@ -94,7 +94,7 @@ export type SiteImproveProps = EitherObj<{
|
|
|
94
94
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
95
95
|
* tracking across client-side (pushState, replaceState) routing.
|
|
96
96
|
*
|
|
97
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
97
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#siteimprove-component
|
|
98
98
|
*/
|
|
99
99
|
export declare const SiteImprove: (props: SiteImproveProps) => null;
|
|
100
100
|
export {};
|
package/SiteImprove.js
CHANGED
|
@@ -29,7 +29,7 @@ const trackDynamicPageView = (url, refUrl, title) => _emitEvent(['trackdynamic',
|
|
|
29
29
|
/**
|
|
30
30
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
31
31
|
*
|
|
32
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
32
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimprove-helper
|
|
33
33
|
*/
|
|
34
34
|
const pingSiteImprove = (category, action, label) => {
|
|
35
35
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -44,7 +44,7 @@ exports.pingSiteImprove = pingSiteImprove;
|
|
|
44
44
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
45
45
|
* being sent to a different URL/resource.
|
|
46
46
|
*
|
|
47
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
47
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimproveoutbound-helper
|
|
48
48
|
*/
|
|
49
49
|
const pingSiteImproveOutbound = (ourl) => {
|
|
50
50
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -125,7 +125,7 @@ const loc = typeof document !== 'undefined' ? document.location : {};
|
|
|
125
125
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
126
126
|
* tracking across client-side (pushState, replaceState) routing.
|
|
127
127
|
*
|
|
128
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
128
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#siteimprove-component
|
|
129
129
|
*/
|
|
130
130
|
const SiteImprove = (props) => {
|
|
131
131
|
const consented = useResolvedAnalyticsConsent(props.hasConsented);
|
package/async.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const addLag: (length: number, opts?: {
|
|
|
18
18
|
* Resolves as soon as all of the passed `promises` have resolved/settled,
|
|
19
19
|
* or after `timeout` milliseconds — whichever comes first.
|
|
20
20
|
*
|
|
21
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
21
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#maxwait
|
|
22
22
|
*/
|
|
23
23
|
export declare function maxWait(timeout: number, promises: Array<unknown>): Promise<void>;
|
|
24
24
|
export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, promises: PromiseMap): Promise<{
|
|
@@ -28,7 +28,7 @@ export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, pr
|
|
|
28
28
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
29
29
|
* and returns a same-shaped object with the resolved values.
|
|
30
30
|
*
|
|
31
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
31
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#promiseallobject
|
|
32
32
|
*/
|
|
33
33
|
export declare const promiseAllObject: <T extends PlainObj>(promisesMap: T) => Promise<{ -readonly [K in keyof T]: Awaited<T[K]>; }>;
|
|
34
34
|
type Cancellable<A extends Array<unknown>> = ((...args: A) => void) & {
|
|
@@ -44,7 +44,7 @@ type Cancellable<A extends Array<unknown>> = ((...args: A) => void) & {
|
|
|
44
44
|
* of quiet-time. \
|
|
45
45
|
* The returned function also has a nice `.cancel()` method.
|
|
46
46
|
*
|
|
47
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
47
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#debounce
|
|
48
48
|
*/
|
|
49
49
|
export declare const debounce: {
|
|
50
50
|
<A extends Array<unknown>>(func: (...args: A) => void, delay: number, immediate?: boolean): Cancellable<A>;
|
|
@@ -64,7 +64,7 @@ type Finishable<A extends Array<unknown>> = ((...args: A) => void) & {
|
|
|
64
64
|
* The returned function also has a nice `.finish()` method to reset the
|
|
65
65
|
* throttle timer
|
|
66
66
|
*
|
|
67
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
67
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#throttle
|
|
68
68
|
*/
|
|
69
69
|
export declare const throttle: {
|
|
70
70
|
<A extends Array<unknown>>(func: (...args: A) => void, delay: number, skipFirst?: boolean): Finishable<A>;
|
package/async.js
CHANGED
|
@@ -67,7 +67,7 @@ function maxWait(timeout, promises) {
|
|
|
67
67
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
68
68
|
* and returns a same-shaped object with the resolved values.
|
|
69
69
|
*
|
|
70
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
70
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#promiseallobject
|
|
71
71
|
*/
|
|
72
72
|
/*#__NO_SIDE_EFFECTS__*/
|
|
73
73
|
const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
|
|
@@ -84,7 +84,7 @@ exports.promiseAllObject = promiseAllObject;
|
|
|
84
84
|
* of quiet-time. \
|
|
85
85
|
* The returned function also has a nice `.cancel()` method.
|
|
86
86
|
*
|
|
87
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
87
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#debounce
|
|
88
88
|
*/
|
|
89
89
|
/*#__NO_SIDE_EFFECTS__*/
|
|
90
90
|
const debounce = (
|
|
@@ -136,7 +136,7 @@ exports.debounce.d = (delay, immediate) => (0, exports.debounce)(function (fn, .
|
|
|
136
136
|
* The returned function also has a nice `.finish()` method to reset the
|
|
137
137
|
* throttle timer
|
|
138
138
|
*
|
|
139
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
139
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#throttle
|
|
140
140
|
*/
|
|
141
141
|
/*#__NO_SIDE_EFFECTS__*/
|
|
142
142
|
const throttle = (
|
package/errorhandling.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
3
3
|
* Error, with the original thrown value as the `payload` property.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
6
6
|
*/
|
|
7
7
|
export declare class ErrorFromPayload extends Error {
|
|
8
8
|
/**
|
|
@@ -25,7 +25,7 @@ export declare class ErrorFromPayload extends Error {
|
|
|
25
25
|
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
26
26
|
* original value is stored in a `payload`
|
|
27
27
|
*
|
|
28
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
28
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
29
29
|
*/
|
|
30
30
|
export declare const asError: (maybeError: unknown) => ErrorFromPayload;
|
|
31
31
|
type SuccessResult<T> = [error: undefined, result: T] & {
|
|
@@ -41,14 +41,14 @@ type FailResult<E extends Error> = [error: E, result?: undefined] & {
|
|
|
41
41
|
/**
|
|
42
42
|
* Simple bare-bones discriminated tuple type for a [error, result] pair.
|
|
43
43
|
*
|
|
44
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
44
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resulttuple
|
|
45
45
|
*/
|
|
46
46
|
export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E, result?: undefined];
|
|
47
47
|
/**
|
|
48
48
|
* Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
|
|
49
49
|
* but with named properties `error` and `result` attached for dev convenience.
|
|
50
50
|
*
|
|
51
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
51
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resulttupleobj
|
|
52
52
|
*/
|
|
53
53
|
export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
|
|
54
54
|
/**
|
|
@@ -60,7 +60,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
|
|
|
60
60
|
*
|
|
61
61
|
* Works on both promises and (synchronous) callback functions.
|
|
62
62
|
*
|
|
63
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
63
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultcatch
|
|
64
64
|
*/
|
|
65
65
|
declare function catch_<T, E extends Error = ErrorFromPayload>(promise: Promise<T>): Promise<ResultTupleObj<T, E>>;
|
|
66
66
|
declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T): ResultTupleObj<T, E>;
|
|
@@ -68,19 +68,19 @@ declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T
|
|
|
68
68
|
* Singleton object with small methods for creating, mapping or handling
|
|
69
69
|
* `ResultTupleObj` instances.
|
|
70
70
|
*
|
|
71
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
71
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#result-singleton
|
|
72
72
|
*/
|
|
73
73
|
export declare const Result: {
|
|
74
74
|
/**
|
|
75
75
|
* Factory for creating a successful `Result.TupleObj`.
|
|
76
76
|
*
|
|
77
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
77
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsuccess
|
|
78
78
|
*/
|
|
79
79
|
Success: <T>(result: T) => SuccessResult<T>;
|
|
80
80
|
/**
|
|
81
81
|
* Factory for creating a failed `Result.TupleObj`.
|
|
82
82
|
*
|
|
83
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
83
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsfail
|
|
84
84
|
*/
|
|
85
85
|
Fail: <E extends Error = Error>(e: unknown) => FailResult<E>;
|
|
86
86
|
catch: typeof catch_;
|
|
@@ -90,14 +90,14 @@ export declare const Result: {
|
|
|
90
90
|
* object, applying a transformation function to the result, but retaining
|
|
91
91
|
* the error as-is.
|
|
92
92
|
*
|
|
93
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
93
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulmap
|
|
94
94
|
*/
|
|
95
95
|
map: <T, T2, E extends Error>(result: ResultTuple<T, E>, mapFn: (resultValue: T) => T2) => ResultTupleObj<T2, E>;
|
|
96
96
|
/**
|
|
97
97
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
98
98
|
* and throws if there's an error, but returns the result otherwise.
|
|
99
99
|
*
|
|
100
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
100
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulthrow
|
|
101
101
|
*/
|
|
102
102
|
throw: <T>(result: ResultTuple<T>) => T;
|
|
103
103
|
};
|
|
@@ -106,5 +106,12 @@ export declare namespace Result {
|
|
|
106
106
|
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
107
107
|
type SuccessObj<T> = SuccessResult<T>;
|
|
108
108
|
type FailObj<E extends Error> = FailResult<E>;
|
|
109
|
+
/**
|
|
110
|
+
* Extracts the successful payload type `T` from a `Result.Tuple<T>`-like
|
|
111
|
+
* type, a `Promise` of such type, or a function returning either of those.
|
|
112
|
+
*
|
|
113
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
|
|
114
|
+
*/
|
|
115
|
+
type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
|
|
109
116
|
}
|
|
110
117
|
export {};
|
package/errorhandling.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.Result = exports.asError = exports.ErrorFromPayload = void 0;
|
|
|
5
5
|
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
6
6
|
* Error, with the original thrown value as the `payload` property.
|
|
7
7
|
*
|
|
8
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
8
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
9
9
|
*/
|
|
10
10
|
/*#__NO_SIDE_EFFECTS__*/
|
|
11
11
|
class ErrorFromPayload extends Error {
|
|
@@ -28,7 +28,7 @@ exports.ErrorFromPayload = ErrorFromPayload;
|
|
|
28
28
|
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
29
29
|
* original value is stored in a `payload`
|
|
30
30
|
*
|
|
31
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
31
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
32
32
|
*/
|
|
33
33
|
/*#__NO_SIDE_EFFECTS__*/
|
|
34
34
|
const asError = (maybeError) => {
|
|
@@ -79,19 +79,19 @@ mapFn) => {
|
|
|
79
79
|
* Singleton object with small methods for creating, mapping or handling
|
|
80
80
|
* `ResultTupleObj` instances.
|
|
81
81
|
*
|
|
82
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
82
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#result-singleton
|
|
83
83
|
*/
|
|
84
84
|
exports.Result = {
|
|
85
85
|
/**
|
|
86
86
|
* Factory for creating a successful `Result.TupleObj`.
|
|
87
87
|
*
|
|
88
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
88
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsuccess
|
|
89
89
|
*/
|
|
90
90
|
Success,
|
|
91
91
|
/**
|
|
92
92
|
* Factory for creating a failed `Result.TupleObj`.
|
|
93
93
|
*
|
|
94
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
94
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsfail
|
|
95
95
|
*/
|
|
96
96
|
Fail,
|
|
97
97
|
// NOTE: The JSDoc must be placed above the `catch_` function above.
|
|
@@ -102,7 +102,7 @@ exports.Result = {
|
|
|
102
102
|
* object, applying a transformation function to the result, but retaining
|
|
103
103
|
* the error as-is.
|
|
104
104
|
*
|
|
105
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
105
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulmap
|
|
106
106
|
*/
|
|
107
107
|
/*#__NO_SIDE_EFFECTS__*/
|
|
108
108
|
map: (result, mapFn) => {
|
|
@@ -116,7 +116,7 @@ exports.Result = {
|
|
|
116
116
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
117
117
|
* and throws if there's an error, but returns the result otherwise.
|
|
118
118
|
*
|
|
119
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
119
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulthrow
|
|
120
120
|
*/
|
|
121
121
|
/*#__NO_SIDE_EFFECTS__*/
|
|
122
122
|
throw: (result) => {
|
|
@@ -220,14 +220,14 @@ export type CookieHubProviderProps = EitherObj<{
|
|
|
220
220
|
* management script and sets up a React state object with the relevant user
|
|
221
221
|
* consent flags.
|
|
222
222
|
*
|
|
223
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
223
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cookiehubprovider-component
|
|
224
224
|
*/
|
|
225
225
|
export declare const CookieHubProvider: (props: CookieHubProviderProps) => React.JSX.Element;
|
|
226
226
|
/**
|
|
227
227
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
228
228
|
* functions.
|
|
229
229
|
*
|
|
230
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
230
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usecookiehubconsent
|
|
231
231
|
*/
|
|
232
232
|
export declare const useCookieHubConsent: () => Partial<CookieHubContextState["consent"]>;
|
|
233
233
|
export {};
|
package/esm/CookieHubConsent.js
CHANGED
|
@@ -35,7 +35,7 @@ const moveCookiehubScriptInDomTree = () => {
|
|
|
35
35
|
* management script and sets up a React state object with the relevant user
|
|
36
36
|
* consent flags.
|
|
37
37
|
*
|
|
38
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
38
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#cookiehubprovider-component
|
|
39
39
|
*/
|
|
40
40
|
export const CookieHubProvider = (props) => {
|
|
41
41
|
const [state, setState] = useState(initialConsentState);
|
|
@@ -122,6 +122,6 @@ export const CookieHubProvider = (props) => {
|
|
|
122
122
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
123
123
|
* functions.
|
|
124
124
|
*
|
|
125
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
125
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#usecookiehubconsent
|
|
126
126
|
*/
|
|
127
127
|
export const useCookieHubConsent = () => { var _a; return ((_a = useContext(CookieHubContext)) === null || _a === void 0 ? void 0 : _a.consent) || {}; };
|
package/esm/SiteImprove.d.ts
CHANGED
|
@@ -45,14 +45,14 @@ type SiteImproveCustomEvent = [
|
|
|
45
45
|
/**
|
|
46
46
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
47
47
|
*
|
|
48
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimprove-helper
|
|
49
49
|
*/
|
|
50
50
|
export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
|
|
51
51
|
/**
|
|
52
52
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
53
53
|
* being sent to a different URL/resource.
|
|
54
54
|
*
|
|
55
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
55
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimproveoutbound-helper
|
|
56
56
|
*/
|
|
57
57
|
export declare const pingSiteImproveOutbound: (ourl: string) => void;
|
|
58
58
|
export type SiteImproveProps = EitherObj<{
|
|
@@ -94,7 +94,7 @@ export type SiteImproveProps = EitherObj<{
|
|
|
94
94
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
95
95
|
* tracking across client-side (pushState, replaceState) routing.
|
|
96
96
|
*
|
|
97
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
97
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#siteimprove-component
|
|
98
98
|
*/
|
|
99
99
|
export declare const SiteImprove: (props: SiteImproveProps) => null;
|
|
100
100
|
export {};
|
package/esm/SiteImprove.js
CHANGED
|
@@ -26,7 +26,7 @@ const trackDynamicPageView = (url, refUrl, title) => _emitEvent(['trackdynamic',
|
|
|
26
26
|
/**
|
|
27
27
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
28
28
|
*
|
|
29
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
29
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimprove-helper
|
|
30
30
|
*/
|
|
31
31
|
export const pingSiteImprove = (category, action, label) => {
|
|
32
32
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -40,7 +40,7 @@ export const pingSiteImprove = (category, action, label) => {
|
|
|
40
40
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
41
41
|
* being sent to a different URL/resource.
|
|
42
42
|
*
|
|
43
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
43
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#pingsiteimproveoutbound-helper
|
|
44
44
|
*/
|
|
45
45
|
export const pingSiteImproveOutbound = (ourl) => {
|
|
46
46
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -120,7 +120,7 @@ const loc = typeof document !== 'undefined' ? document.location : {};
|
|
|
120
120
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
121
121
|
* tracking across client-side (pushState, replaceState) routing.
|
|
122
122
|
*
|
|
123
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
123
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#siteimprove-component
|
|
124
124
|
*/
|
|
125
125
|
export const SiteImprove = (props) => {
|
|
126
126
|
const consented = useResolvedAnalyticsConsent(props.hasConsented);
|
package/esm/async.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const addLag: (length: number, opts?: {
|
|
|
18
18
|
* Resolves as soon as all of the passed `promises` have resolved/settled,
|
|
19
19
|
* or after `timeout` milliseconds — whichever comes first.
|
|
20
20
|
*
|
|
21
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
21
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#maxwait
|
|
22
22
|
*/
|
|
23
23
|
export declare function maxWait(timeout: number, promises: Array<unknown>): Promise<void>;
|
|
24
24
|
export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, promises: PromiseMap): Promise<{
|
|
@@ -28,7 +28,7 @@ export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, pr
|
|
|
28
28
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
29
29
|
* and returns a same-shaped object with the resolved values.
|
|
30
30
|
*
|
|
31
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
31
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#promiseallobject
|
|
32
32
|
*/
|
|
33
33
|
export declare const promiseAllObject: <T extends PlainObj>(promisesMap: T) => Promise<{ -readonly [K in keyof T]: Awaited<T[K]>; }>;
|
|
34
34
|
type Cancellable<A extends Array<unknown>> = ((...args: A) => void) & {
|
|
@@ -44,7 +44,7 @@ type Cancellable<A extends Array<unknown>> = ((...args: A) => void) & {
|
|
|
44
44
|
* of quiet-time. \
|
|
45
45
|
* The returned function also has a nice `.cancel()` method.
|
|
46
46
|
*
|
|
47
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
47
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#debounce
|
|
48
48
|
*/
|
|
49
49
|
export declare const debounce: {
|
|
50
50
|
<A extends Array<unknown>>(func: (...args: A) => void, delay: number, immediate?: boolean): Cancellable<A>;
|
|
@@ -64,7 +64,7 @@ type Finishable<A extends Array<unknown>> = ((...args: A) => void) & {
|
|
|
64
64
|
* The returned function also has a nice `.finish()` method to reset the
|
|
65
65
|
* throttle timer
|
|
66
66
|
*
|
|
67
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
67
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#throttle
|
|
68
68
|
*/
|
|
69
69
|
export declare const throttle: {
|
|
70
70
|
<A extends Array<unknown>>(func: (...args: A) => void, delay: number, skipFirst?: boolean): Finishable<A>;
|
package/esm/async.js
CHANGED
|
@@ -61,7 +61,7 @@ export function maxWait(timeout, promises) {
|
|
|
61
61
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
62
62
|
* and returns a same-shaped object with the resolved values.
|
|
63
63
|
*
|
|
64
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
64
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#promiseallobject
|
|
65
65
|
*/
|
|
66
66
|
/*#__NO_SIDE_EFFECTS__*/
|
|
67
67
|
export const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
|
|
@@ -77,7 +77,7 @@ export const promiseAllObject = (promisesMap) => Promise.all(Object.values(promi
|
|
|
77
77
|
* of quiet-time. \
|
|
78
78
|
* The returned function also has a nice `.cancel()` method.
|
|
79
79
|
*
|
|
80
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
80
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#debounce
|
|
81
81
|
*/
|
|
82
82
|
/*#__NO_SIDE_EFFECTS__*/
|
|
83
83
|
export const debounce = (
|
|
@@ -128,7 +128,7 @@ debounce.d = (delay, immediate) => debounce(function (fn, ...args) {
|
|
|
128
128
|
* The returned function also has a nice `.finish()` method to reset the
|
|
129
129
|
* throttle timer
|
|
130
130
|
*
|
|
131
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
131
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#throttle
|
|
132
132
|
*/
|
|
133
133
|
/*#__NO_SIDE_EFFECTS__*/
|
|
134
134
|
export const throttle = (
|
package/esm/errorhandling.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
3
3
|
* Error, with the original thrown value as the `payload` property.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
6
6
|
*/
|
|
7
7
|
export declare class ErrorFromPayload extends Error {
|
|
8
8
|
/**
|
|
@@ -25,7 +25,7 @@ export declare class ErrorFromPayload extends Error {
|
|
|
25
25
|
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
26
26
|
* original value is stored in a `payload`
|
|
27
27
|
*
|
|
28
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
28
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#aserror
|
|
29
29
|
*/
|
|
30
30
|
export declare const asError: (maybeError: unknown) => ErrorFromPayload;
|
|
31
31
|
type SuccessResult<T> = [error: undefined, result: T] & {
|
|
@@ -41,14 +41,14 @@ type FailResult<E extends Error> = [error: E, result?: undefined] & {
|
|
|
41
41
|
/**
|
|
42
42
|
* Simple bare-bones discriminated tuple type for a [error, result] pair.
|
|
43
43
|
*
|
|
44
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
44
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resulttuple
|
|
45
45
|
*/
|
|
46
46
|
export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E, result?: undefined];
|
|
47
47
|
/**
|
|
48
48
|
* Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
|
|
49
49
|
* but with named properties `error` and `result` attached for dev convenience.
|
|
50
50
|
*
|
|
51
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
51
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resulttupleobj
|
|
52
52
|
*/
|
|
53
53
|
export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
|
|
54
54
|
/**
|
|
@@ -60,7 +60,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
|
|
|
60
60
|
*
|
|
61
61
|
* Works on both promises and (synchronous) callback functions.
|
|
62
62
|
*
|
|
63
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
63
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultcatch
|
|
64
64
|
*/
|
|
65
65
|
declare function catch_<T, E extends Error = ErrorFromPayload>(promise: Promise<T>): Promise<ResultTupleObj<T, E>>;
|
|
66
66
|
declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T): ResultTupleObj<T, E>;
|
|
@@ -68,19 +68,19 @@ declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T
|
|
|
68
68
|
* Singleton object with small methods for creating, mapping or handling
|
|
69
69
|
* `ResultTupleObj` instances.
|
|
70
70
|
*
|
|
71
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
71
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#result-singleton
|
|
72
72
|
*/
|
|
73
73
|
export declare const Result: {
|
|
74
74
|
/**
|
|
75
75
|
* Factory for creating a successful `Result.TupleObj`.
|
|
76
76
|
*
|
|
77
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
77
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsuccess
|
|
78
78
|
*/
|
|
79
79
|
Success: <T>(result: T) => SuccessResult<T>;
|
|
80
80
|
/**
|
|
81
81
|
* Factory for creating a failed `Result.TupleObj`.
|
|
82
82
|
*
|
|
83
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
83
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsfail
|
|
84
84
|
*/
|
|
85
85
|
Fail: <E extends Error = Error>(e: unknown) => FailResult<E>;
|
|
86
86
|
catch: typeof catch_;
|
|
@@ -90,14 +90,14 @@ export declare const Result: {
|
|
|
90
90
|
* object, applying a transformation function to the result, but retaining
|
|
91
91
|
* the error as-is.
|
|
92
92
|
*
|
|
93
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
93
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulmap
|
|
94
94
|
*/
|
|
95
95
|
map: <T, T2, E extends Error>(result: ResultTuple<T, E>, mapFn: (resultValue: T) => T2) => ResultTupleObj<T2, E>;
|
|
96
96
|
/**
|
|
97
97
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
98
98
|
* and throws if there's an error, but returns the result otherwise.
|
|
99
99
|
*
|
|
100
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
100
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resulthrow
|
|
101
101
|
*/
|
|
102
102
|
throw: <T>(result: ResultTuple<T>) => T;
|
|
103
103
|
};
|
|
@@ -106,5 +106,12 @@ export declare namespace Result {
|
|
|
106
106
|
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
107
107
|
type SuccessObj<T> = SuccessResult<T>;
|
|
108
108
|
type FailObj<E extends Error> = FailResult<E>;
|
|
109
|
+
/**
|
|
110
|
+
* Extracts the successful payload type `T` from a `Result.Tuple<T>`-like
|
|
111
|
+
* type, a `Promise` of such type, or a function returning either of those.
|
|
112
|
+
*
|
|
113
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
|
|
114
|
+
*/
|
|
115
|
+
type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
|
|
109
116
|
}
|
|
110
117
|
export {};
|