@reykjavik/webtools 0.1.36 → 0.2.0
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 +19 -6
- package/CookieHubConsent.d.ts +2 -2
- package/CookieHubConsent.js +2 -2
- package/README.md +9 -5
- package/SiteImprove.d.ts +6 -7
- package/SiteImprove.js +23 -37
- package/async.d.ts +2 -2
- package/async.js +1 -1
- package/errorhandling.d.ts +10 -10
- package/errorhandling.js +7 -7
- package/esm/CookieHubConsent.d.ts +2 -2
- package/esm/CookieHubConsent.js +2 -2
- package/esm/SiteImprove.d.ts +6 -7
- package/esm/SiteImprove.js +23 -14
- package/esm/async.d.ts +2 -2
- package/esm/async.js +1 -1
- package/esm/errorhandling.d.ts +10 -10
- package/esm/errorhandling.js +7 -7
- package/esm/http.d.ts +5 -5
- package/esm/http.js +4 -4
- package/esm/index.d.ts +2 -3
- package/esm/next/http.d.ts +2 -2
- package/esm/next/http.js +3 -3
- package/{remix → esm/react-router}/Wait.d.ts +2 -2
- package/esm/{remix → react-router}/Wait.js +2 -2
- package/esm/{remix → react-router}/http.d.ts +1 -1
- package/esm/{remix → react-router}/http.js +1 -1
- package/esm/vanillaExtract.d.ts +3 -132
- package/esm/vanillaExtract.js +2 -67
- package/http.d.ts +5 -5
- package/http.js +4 -4
- package/index.d.ts +2 -3
- package/next/http.d.ts +2 -2
- package/next/http.js +3 -3
- package/package.json +13 -17
- package/{esm/remix → react-router}/Wait.d.ts +2 -2
- package/{remix → react-router}/Wait.js +3 -3
- package/{remix → react-router}/http.d.ts +1 -1
- package/{remix → react-router}/http.js +1 -1
- package/vanillaExtract.d.ts +3 -132
- package/vanillaExtract.js +3 -70
- package/esm/next/SiteImprove.d.ts +0 -10
- package/esm/next/SiteImprove.js +0 -7
- package/next/SiteImprove.d.ts +0 -10
- package/next/SiteImprove.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -4,19 +4,32 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.
|
|
7
|
+
## 0.2.0
|
|
8
8
|
|
|
9
|
-
_2024-
|
|
9
|
+
_2024-12-12_
|
|
10
10
|
|
|
11
|
-
- `@reykjavik/webtools/
|
|
12
|
-
|
|
11
|
+
- feat: Add `@reykjavik/webtools/react-router/*` (previously `/remix/*`)
|
|
12
|
+
- **BREAKING** feat: Remove all `@reykjavik/webtools/react-router/*` modules
|
|
13
|
+
- **BREAKING** feat: Bump `pkg.engines.node` version to >=20
|
|
14
|
+
- **BREAKING** feat: Remove `@reykjavik/webtools/next/SiteImprove` (deprecated
|
|
15
|
+
module)
|
|
16
|
+
- **BREAKING** feat: Remove deprecated exports `vanillaNest` and
|
|
17
|
+
`vanillaClassNested` from `@reykjavik/webtools/vanillaExtract`
|
|
18
|
+
|
|
19
|
+
## 0.1.37
|
|
20
|
+
|
|
21
|
+
_2024-10-23_
|
|
22
|
+
|
|
23
|
+
- `@reykjavik/webtools/SiteImprove`:
|
|
24
|
+
- fix: `onLoad` and `onError` callback arguments are now typed as `Event`
|
|
25
|
+
- fix: Script wasn't actually loading. Now it does.
|
|
13
26
|
|
|
14
|
-
## 0.1.35
|
|
27
|
+
## 0.1.35 – 0.1.36
|
|
15
28
|
|
|
16
29
|
_2024-10-18_
|
|
17
30
|
|
|
18
31
|
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
19
|
-
- feat: `vanillaClass` auto-replaces
|
|
32
|
+
- feat: `vanillaClass` auto-replaces `&&` tokens in a plain-string input
|
|
20
33
|
- docs: Minor improvements to README and JSDoc comments
|
|
21
34
|
|
|
22
35
|
## 0.1.34
|
package/CookieHubConsent.d.ts
CHANGED
|
@@ -218,14 +218,14 @@ export type CookieHubProviderProps = EitherObj<{
|
|
|
218
218
|
* management script and sets up a React state object with the relevant user
|
|
219
219
|
* consent flags.
|
|
220
220
|
*
|
|
221
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
221
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
|
|
222
222
|
*/
|
|
223
223
|
export declare const CookieHubProvider: (props: CookieHubProviderProps) => React.JSX.Element;
|
|
224
224
|
/**
|
|
225
225
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
226
226
|
* functions.
|
|
227
227
|
*
|
|
228
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
228
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
|
|
229
229
|
*/
|
|
230
230
|
export declare const useCookieHubConsent: () => Partial<CookieHubContextState['consent']>;
|
|
231
231
|
export {};
|
package/CookieHubConsent.js
CHANGED
|
@@ -61,7 +61,7 @@ const moveCookiehubScriptInDomTree = () => {
|
|
|
61
61
|
* management script and sets up a React state object with the relevant user
|
|
62
62
|
* consent flags.
|
|
63
63
|
*
|
|
64
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
64
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
|
|
65
65
|
*/
|
|
66
66
|
const CookieHubProvider = (props) => {
|
|
67
67
|
const [state, setState] = (0, react_1.useState)(initialConsentState);
|
|
@@ -134,7 +134,7 @@ exports.CookieHubProvider = CookieHubProvider;
|
|
|
134
134
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
135
135
|
* functions.
|
|
136
136
|
*
|
|
137
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
137
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
|
|
138
138
|
*/
|
|
139
139
|
const useCookieHubConsent = () => { var _a; return ((_a = (0, react_1.useContext)(CookieHubContext)) === null || _a === void 0 ? void 0 : _a.consent) || {}; };
|
|
140
140
|
exports.useCookieHubConsent = useCookieHubConsent;
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ bun add @reykjavik/webtools
|
|
|
51
51
|
- [`vanillaGlobal`](#vanillaglobal)
|
|
52
52
|
- [`vanillaProps`](#vanillaprops)
|
|
53
53
|
- [Framework Specific Tools](#framework-specific-tools)
|
|
54
|
-
- [
|
|
54
|
+
- [React-Router Tools](#react-router-tools)
|
|
55
55
|
- [Next.js Tools](#nextjs-tools)
|
|
56
56
|
- [Contributing](#contributing)
|
|
57
57
|
- [Changelog](#changelog)
|
|
@@ -484,7 +484,8 @@ if (myResult.error) {
|
|
|
484
484
|
|
|
485
485
|
### `Result.catch`
|
|
486
486
|
|
|
487
|
-
**Syntax:**
|
|
487
|
+
**Syntax:**
|
|
488
|
+
`Result.catch<T, Err>(callback: () => T): ResultTupleObj<T, Err>`
|
|
488
489
|
**Syntax:**
|
|
489
490
|
`Result.catch<T, Err>(promise: Promise<T>): Promise<ResultTupleObj<T, Err>>`
|
|
490
491
|
|
|
@@ -881,10 +882,13 @@ const myStyle = style({
|
|
|
881
882
|
|
|
882
883
|
## Framework Specific Tools
|
|
883
884
|
|
|
884
|
-
###
|
|
885
|
+
### React-Router Tools
|
|
886
|
+
|
|
887
|
+
See [README-rr.md](./README-rr.md) for helpers and components specifically
|
|
888
|
+
designed for use in Remix.run projects.
|
|
885
889
|
|
|
886
|
-
|
|
887
|
-
|
|
890
|
+
(NOTE: If you're still using [Remix.run](https://remix.run) you can install
|
|
891
|
+
version `"^0.1.22"` of this package.)
|
|
888
892
|
|
|
889
893
|
<!-- #fragment anchors to not break older v0.1 @see links -->
|
|
890
894
|
|
package/SiteImprove.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
3
2
|
declare global {
|
|
4
3
|
interface Window {
|
|
@@ -46,14 +45,14 @@ type SiteImproveCustomEvent = [
|
|
|
46
45
|
/**
|
|
47
46
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
48
47
|
*
|
|
49
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
|
|
50
49
|
*/
|
|
51
50
|
export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
|
|
52
51
|
/**
|
|
53
52
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
54
53
|
* being sent to a different URL/resource.
|
|
55
54
|
*
|
|
56
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
55
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
|
|
57
56
|
*/
|
|
58
57
|
export declare const pingSiteImproveOutbound: (ourl: string) => void;
|
|
59
58
|
export type SiteImproveProps = EitherObj<{
|
|
@@ -85,17 +84,17 @@ export type SiteImproveProps = EitherObj<{
|
|
|
85
84
|
/**
|
|
86
85
|
* Custom callback for when the SiteImprove script has loaded.
|
|
87
86
|
*/
|
|
88
|
-
onLoad?: (e:
|
|
87
|
+
onLoad?: (e: Event) => void;
|
|
89
88
|
/**
|
|
90
89
|
* Error callback for if the SiteImprove script fails to load.
|
|
91
90
|
*/
|
|
92
|
-
onError?: (e:
|
|
91
|
+
onError?: (e: Event | string) => void;
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
94
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
96
95
|
* tracking across client-side (pushState, replaceState) routing.
|
|
97
96
|
*
|
|
98
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
97
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
|
|
99
98
|
*/
|
|
100
|
-
export declare const SiteImprove: (props: SiteImproveProps) =>
|
|
99
|
+
export declare const SiteImprove: (props: SiteImproveProps) => null;
|
|
101
100
|
export {};
|
package/SiteImprove.js
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.SiteImprove = exports.pingSiteImproveOutbound = exports.pingSiteImprove = void 0;
|
|
27
|
-
const react_1 =
|
|
4
|
+
const react_1 = require("react");
|
|
28
5
|
const CookieHubConsent_js_1 = require("./CookieHubConsent.js");
|
|
29
6
|
// END: Mock typing of SiteImprove's event tracking API
|
|
30
7
|
// --------------------------------------------------------------------------
|
|
@@ -52,7 +29,7 @@ const trackDynamicPageView = (url, refUrl, title) => _emitEvent(['trackdynamic',
|
|
|
52
29
|
/**
|
|
53
30
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
54
31
|
*
|
|
55
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
32
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
|
|
56
33
|
*/
|
|
57
34
|
const pingSiteImprove = (category, action, label) => {
|
|
58
35
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -67,7 +44,7 @@ exports.pingSiteImprove = pingSiteImprove;
|
|
|
67
44
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
68
45
|
* being sent to a different URL/resource.
|
|
69
46
|
*
|
|
70
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
47
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
|
|
71
48
|
*/
|
|
72
49
|
const pingSiteImproveOutbound = (ourl) => {
|
|
73
50
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -117,14 +94,28 @@ const useResolvedAnalyticsConsent = (hasConsented) => {
|
|
|
117
94
|
return ((analytics && hasConsented !== false) || (analytics === undefined && hasConsented));
|
|
118
95
|
};
|
|
119
96
|
// ---------------------------------------------------------------------------
|
|
120
|
-
const
|
|
121
|
-
|
|
97
|
+
const loadSIScript = (props) => {
|
|
98
|
+
var _a;
|
|
99
|
+
if (process.env.NODE_ENV === 'production') {
|
|
100
|
+
if (window._sz || document.querySelector('script#siteimprove-analytics-script')) {
|
|
101
|
+
console.warn('SiteImprove script already loaded.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const script = document.createElement('script');
|
|
105
|
+
script.defer = true;
|
|
106
|
+
script.id = 'siteimprove-analytics-script';
|
|
107
|
+
script.src = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
108
|
+
props.onLoad && (script.onload = props.onLoad);
|
|
109
|
+
props.onError && (script.onerror = props.onError);
|
|
110
|
+
document.body.append(script);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
122
113
|
setTimeout(() => {
|
|
123
114
|
if (!window._sz) {
|
|
124
115
|
console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
|
|
125
116
|
window._sz = [];
|
|
126
117
|
}
|
|
127
|
-
}, 300);
|
|
118
|
+
}, 300); // Aribtrary delay to simulate script loading
|
|
128
119
|
}
|
|
129
120
|
};
|
|
130
121
|
// ===========================================================================
|
|
@@ -134,10 +125,9 @@ const loc = typeof document !== 'undefined' ? document.location : {};
|
|
|
134
125
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
135
126
|
* tracking across client-side (pushState, replaceState) routing.
|
|
136
127
|
*
|
|
137
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
128
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
|
|
138
129
|
*/
|
|
139
130
|
const SiteImprove = (props) => {
|
|
140
|
-
var _a;
|
|
141
131
|
const consented = useResolvedAnalyticsConsent(props.hasConsented);
|
|
142
132
|
const thisUrl = `${loc.pathname}${loc.search}${loc.hash}`;
|
|
143
133
|
(0, react_1.useEffect)(() => {
|
|
@@ -162,15 +152,11 @@ const SiteImprove = (props) => {
|
|
|
162
152
|
if (!consented) {
|
|
163
153
|
return;
|
|
164
154
|
}
|
|
165
|
-
|
|
155
|
+
loadSIScript(props);
|
|
166
156
|
return logOutboundLinks();
|
|
167
157
|
},
|
|
168
158
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
159
|
[consented]);
|
|
170
|
-
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
const scriptUrl = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
174
|
-
return react_1.default.createElement("script", { defer: true, src: scriptUrl, onLoad: props.onLoad, onError: props.onError });
|
|
160
|
+
return null;
|
|
175
161
|
};
|
|
176
162
|
exports.SiteImprove = SiteImprove;
|
package/async.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const addLag: (length: number) => <T>(res: T) => Promise<T>;
|
|
|
14
14
|
* Resolves as soon as all of the passed `promises` have resolved/settled,
|
|
15
15
|
* or after `timeout` milliseconds — whichever comes first.
|
|
16
16
|
*
|
|
17
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
17
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#maxwait
|
|
18
18
|
*/
|
|
19
19
|
export declare function maxWait(timeout: number, promises: Array<unknown>): Promise<void>;
|
|
20
20
|
export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, promises: PromiseMap): Promise<{
|
|
@@ -24,7 +24,7 @@ export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, pr
|
|
|
24
24
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
25
25
|
* and returns a same-shaped object with the resolved values.
|
|
26
26
|
*
|
|
27
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
27
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
|
|
28
28
|
*/
|
|
29
29
|
export declare const promiseAllObject: <T extends PlainObj>(promisesMap: T) => Promise<{ -readonly [K in keyof T]: Awaited<T[K]>; }>;
|
|
30
30
|
export {};
|
package/async.js
CHANGED
|
@@ -45,7 +45,7 @@ exports.maxWait = maxWait;
|
|
|
45
45
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
46
46
|
* and returns a same-shaped object with the resolved values.
|
|
47
47
|
*
|
|
48
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
|
|
49
49
|
*/
|
|
50
50
|
const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
|
|
51
51
|
const keys = Object.keys(promisesMap);
|
package/errorhandling.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error subclass for thrown values that got cought and turned into an actual
|
|
3
3
|
* Error, with the 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.2/README.md#aserror
|
|
6
6
|
*/
|
|
7
7
|
export declare class ErrorFromPayload extends Error {
|
|
8
8
|
payload?: unknown;
|
|
@@ -17,7 +17,7 @@ export declare class ErrorFromPayload extends Error {
|
|
|
17
17
|
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
18
18
|
* original value is stored in a `payload`
|
|
19
19
|
*
|
|
20
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
20
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
21
21
|
*/
|
|
22
22
|
export declare const asError: (maybeError: unknown) => ErrorFromPayload;
|
|
23
23
|
type SuccessResult<T> = [error: undefined, result: T] & {
|
|
@@ -31,14 +31,14 @@ type FailResult<E extends Error> = [error: E] & {
|
|
|
31
31
|
/**
|
|
32
32
|
* Simple bare-bones discriminated tuple type for a [error, result] pair.
|
|
33
33
|
*
|
|
34
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-resulttuple
|
|
35
35
|
*/
|
|
36
36
|
export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E];
|
|
37
37
|
/**
|
|
38
38
|
* Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
|
|
39
39
|
* but with named properties `error` and `result` attached for dev convenience.
|
|
40
40
|
*
|
|
41
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
41
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-resulttupleobj
|
|
42
42
|
*/
|
|
43
43
|
export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
|
|
44
44
|
/**
|
|
@@ -50,7 +50,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
|
|
|
50
50
|
*
|
|
51
51
|
* Works on both promises and sync callback functions.
|
|
52
52
|
*
|
|
53
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
53
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultcatch
|
|
54
54
|
*/
|
|
55
55
|
declare function catch_<T, E extends Error = ErrorFromPayload>(promise: Promise<T>): Promise<ResultTupleObj<T, E>>;
|
|
56
56
|
declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T): ResultTupleObj<T, E>;
|
|
@@ -58,19 +58,19 @@ declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T
|
|
|
58
58
|
* Singleton object with small methods for creating, mapping or handling
|
|
59
59
|
* `ResultTupleObj` instances.
|
|
60
60
|
*
|
|
61
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
61
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#result-singleton
|
|
62
62
|
*/
|
|
63
63
|
export declare const Result: {
|
|
64
64
|
/**
|
|
65
65
|
* Factory for creating a successful `Result.TupleObj`.
|
|
66
66
|
*
|
|
67
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
67
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsuccess
|
|
68
68
|
*/
|
|
69
69
|
Success: <T>(result: T) => SuccessResult<T>;
|
|
70
70
|
/**
|
|
71
71
|
* Factory for creating a failed `Result.TupleObj`.
|
|
72
72
|
*
|
|
73
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
73
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsfail
|
|
74
74
|
*/
|
|
75
75
|
Fail: <E extends Error = Error>(e: unknown) => FailResult<E>;
|
|
76
76
|
catch: typeof catch_;
|
|
@@ -79,14 +79,14 @@ export declare const Result: {
|
|
|
79
79
|
* object, applying a transformation function to the result, but retaining
|
|
80
80
|
* the error as-is.
|
|
81
81
|
*
|
|
82
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
82
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
|
|
83
83
|
*/
|
|
84
84
|
map: <T_1, T2, E_1 extends Error>(result: ResultTuple<T_1, E_1>, mapFn: (resultValue: T_1) => T2) => ResultTupleObj<T2, E_1>;
|
|
85
85
|
/**
|
|
86
86
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
87
87
|
* and throws if there's an error, but returns the result otherwise.
|
|
88
88
|
*
|
|
89
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
89
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
|
|
90
90
|
*/
|
|
91
91
|
throw: <T_2>(result: ResultTuple<T_2, Error>) => T_2;
|
|
92
92
|
};
|
package/errorhandling.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.Result = exports.asError = exports.ErrorFromPayload = void 0;
|
|
|
5
5
|
* Error subclass for thrown values that got cought and turned into an actual
|
|
6
6
|
* Error, with the 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.2/README.md#aserror
|
|
9
9
|
*/
|
|
10
10
|
class ErrorFromPayload extends Error {
|
|
11
11
|
constructor(payload) {
|
|
@@ -27,7 +27,7 @@ exports.ErrorFromPayload = ErrorFromPayload;
|
|
|
27
27
|
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
28
28
|
* original value is stored in a `payload`
|
|
29
29
|
*
|
|
30
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
30
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
31
31
|
*/
|
|
32
32
|
const asError = (maybeError) => {
|
|
33
33
|
if (maybeError instanceof Error) {
|
|
@@ -61,19 +61,19 @@ function catch_(something) {
|
|
|
61
61
|
* Singleton object with small methods for creating, mapping or handling
|
|
62
62
|
* `ResultTupleObj` instances.
|
|
63
63
|
*
|
|
64
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
64
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#result-singleton
|
|
65
65
|
*/
|
|
66
66
|
exports.Result = {
|
|
67
67
|
/**
|
|
68
68
|
* Factory for creating a successful `Result.TupleObj`.
|
|
69
69
|
*
|
|
70
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
70
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsuccess
|
|
71
71
|
*/
|
|
72
72
|
Success,
|
|
73
73
|
/**
|
|
74
74
|
* Factory for creating a failed `Result.TupleObj`.
|
|
75
75
|
*
|
|
76
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
76
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsfail
|
|
77
77
|
*/
|
|
78
78
|
Fail,
|
|
79
79
|
// NOTE: The JSDoc must be placed above the `catch_` function above.
|
|
@@ -83,7 +83,7 @@ exports.Result = {
|
|
|
83
83
|
* object, applying a transformation function to the result, but retaining
|
|
84
84
|
* the error as-is.
|
|
85
85
|
*
|
|
86
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
86
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
|
|
87
87
|
*/
|
|
88
88
|
map: (result, mapFn) => {
|
|
89
89
|
const [error, resultValue] = result;
|
|
@@ -96,7 +96,7 @@ exports.Result = {
|
|
|
96
96
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
97
97
|
* and throws if there's an error, but returns the result otherwise.
|
|
98
98
|
*
|
|
99
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
99
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
|
|
100
100
|
*/
|
|
101
101
|
throw: (result) => {
|
|
102
102
|
if (result[0]) {
|
|
@@ -218,14 +218,14 @@ export type CookieHubProviderProps = EitherObj<{
|
|
|
218
218
|
* management script and sets up a React state object with the relevant user
|
|
219
219
|
* consent flags.
|
|
220
220
|
*
|
|
221
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
221
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
|
|
222
222
|
*/
|
|
223
223
|
export declare const CookieHubProvider: (props: CookieHubProviderProps) => React.JSX.Element;
|
|
224
224
|
/**
|
|
225
225
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
226
226
|
* functions.
|
|
227
227
|
*
|
|
228
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
228
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
|
|
229
229
|
*/
|
|
230
230
|
export declare const useCookieHubConsent: () => Partial<CookieHubContextState['consent']>;
|
|
231
231
|
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.2/README.md#cookiehubprovider-component
|
|
39
39
|
*/
|
|
40
40
|
export const CookieHubProvider = (props) => {
|
|
41
41
|
const [state, setState] = useState(initialConsentState);
|
|
@@ -107,6 +107,6 @@ export const CookieHubProvider = (props) => {
|
|
|
107
107
|
* Returns up-to-date cookie consent flags. For use in React components or hook
|
|
108
108
|
* functions.
|
|
109
109
|
*
|
|
110
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
110
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
|
|
111
111
|
*/
|
|
112
112
|
export const useCookieHubConsent = () => { var _a; return ((_a = useContext(CookieHubContext)) === null || _a === void 0 ? void 0 : _a.consent) || {}; };
|
package/esm/SiteImprove.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
3
2
|
declare global {
|
|
4
3
|
interface Window {
|
|
@@ -46,14 +45,14 @@ type SiteImproveCustomEvent = [
|
|
|
46
45
|
/**
|
|
47
46
|
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
48
47
|
*
|
|
49
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
|
|
50
49
|
*/
|
|
51
50
|
export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
|
|
52
51
|
/**
|
|
53
52
|
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
54
53
|
* being sent to a different URL/resource.
|
|
55
54
|
*
|
|
56
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
55
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
|
|
57
56
|
*/
|
|
58
57
|
export declare const pingSiteImproveOutbound: (ourl: string) => void;
|
|
59
58
|
export type SiteImproveProps = EitherObj<{
|
|
@@ -85,17 +84,17 @@ export type SiteImproveProps = EitherObj<{
|
|
|
85
84
|
/**
|
|
86
85
|
* Custom callback for when the SiteImprove script has loaded.
|
|
87
86
|
*/
|
|
88
|
-
onLoad?: (e:
|
|
87
|
+
onLoad?: (e: Event) => void;
|
|
89
88
|
/**
|
|
90
89
|
* Error callback for if the SiteImprove script fails to load.
|
|
91
90
|
*/
|
|
92
|
-
onError?: (e:
|
|
91
|
+
onError?: (e: Event | string) => void;
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
94
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
96
95
|
* tracking across client-side (pushState, replaceState) routing.
|
|
97
96
|
*
|
|
98
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
97
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
|
|
99
98
|
*/
|
|
100
|
-
export declare const SiteImprove: (props: SiteImproveProps) =>
|
|
99
|
+
export declare const SiteImprove: (props: SiteImproveProps) => null;
|
|
101
100
|
export {};
|
package/esm/SiteImprove.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
2
|
import { useCookieHubConsent } from './CookieHubConsent.js';
|
|
3
3
|
// END: Mock typing of SiteImprove's event tracking API
|
|
4
4
|
// --------------------------------------------------------------------------
|
|
@@ -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.2/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.2/README.md#pingsiteimproveoutbound-helper
|
|
44
44
|
*/
|
|
45
45
|
export const pingSiteImproveOutbound = (ourl) => {
|
|
46
46
|
if (process.env.NODE_ENV === 'development' &&
|
|
@@ -89,14 +89,28 @@ const useResolvedAnalyticsConsent = (hasConsented) => {
|
|
|
89
89
|
return ((analytics && hasConsented !== false) || (analytics === undefined && hasConsented));
|
|
90
90
|
};
|
|
91
91
|
// ---------------------------------------------------------------------------
|
|
92
|
-
const
|
|
93
|
-
|
|
92
|
+
const loadSIScript = (props) => {
|
|
93
|
+
var _a;
|
|
94
|
+
if (process.env.NODE_ENV === 'production') {
|
|
95
|
+
if (window._sz || document.querySelector('script#siteimprove-analytics-script')) {
|
|
96
|
+
console.warn('SiteImprove script already loaded.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const script = document.createElement('script');
|
|
100
|
+
script.defer = true;
|
|
101
|
+
script.id = 'siteimprove-analytics-script';
|
|
102
|
+
script.src = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
103
|
+
props.onLoad && (script.onload = props.onLoad);
|
|
104
|
+
props.onError && (script.onerror = props.onError);
|
|
105
|
+
document.body.append(script);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
94
108
|
setTimeout(() => {
|
|
95
109
|
if (!window._sz) {
|
|
96
110
|
console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
|
|
97
111
|
window._sz = [];
|
|
98
112
|
}
|
|
99
|
-
}, 300);
|
|
113
|
+
}, 300); // Aribtrary delay to simulate script loading
|
|
100
114
|
}
|
|
101
115
|
};
|
|
102
116
|
// ===========================================================================
|
|
@@ -106,10 +120,9 @@ const loc = typeof document !== 'undefined' ? document.location : {};
|
|
|
106
120
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
107
121
|
* tracking across client-side (pushState, replaceState) routing.
|
|
108
122
|
*
|
|
109
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
123
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
|
|
110
124
|
*/
|
|
111
125
|
export const SiteImprove = (props) => {
|
|
112
|
-
var _a;
|
|
113
126
|
const consented = useResolvedAnalyticsConsent(props.hasConsented);
|
|
114
127
|
const thisUrl = `${loc.pathname}${loc.search}${loc.hash}`;
|
|
115
128
|
useEffect(() => {
|
|
@@ -134,14 +147,10 @@ export const SiteImprove = (props) => {
|
|
|
134
147
|
if (!consented) {
|
|
135
148
|
return;
|
|
136
149
|
}
|
|
137
|
-
|
|
150
|
+
loadSIScript(props);
|
|
138
151
|
return logOutboundLinks();
|
|
139
152
|
},
|
|
140
153
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
141
154
|
[consented]);
|
|
142
|
-
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
const scriptUrl = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
146
|
-
return React.createElement("script", { defer: true, src: scriptUrl, onLoad: props.onLoad, onError: props.onError });
|
|
155
|
+
return null;
|
|
147
156
|
};
|
package/esm/async.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const addLag: (length: number) => <T>(res: T) => Promise<T>;
|
|
|
14
14
|
* Resolves as soon as all of the passed `promises` have resolved/settled,
|
|
15
15
|
* or after `timeout` milliseconds — whichever comes first.
|
|
16
16
|
*
|
|
17
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
17
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#maxwait
|
|
18
18
|
*/
|
|
19
19
|
export declare function maxWait(timeout: number, promises: Array<unknown>): Promise<void>;
|
|
20
20
|
export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, promises: PromiseMap): Promise<{
|
|
@@ -24,7 +24,7 @@ export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, pr
|
|
|
24
24
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
25
25
|
* and returns a same-shaped object with the resolved values.
|
|
26
26
|
*
|
|
27
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
27
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
|
|
28
28
|
*/
|
|
29
29
|
export declare const promiseAllObject: <T extends PlainObj>(promisesMap: T) => Promise<{ -readonly [K in keyof T]: Awaited<T[K]>; }>;
|
|
30
30
|
export {};
|
package/esm/async.js
CHANGED
|
@@ -39,7 +39,7 @@ export function maxWait(timeout, promises) {
|
|
|
39
39
|
* A variation of `Promise.all()` that accepts an object with named promises
|
|
40
40
|
* and returns a same-shaped object with the resolved values.
|
|
41
41
|
*
|
|
42
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
42
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
|
|
43
43
|
*/
|
|
44
44
|
export const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
|
|
45
45
|
const keys = Object.keys(promisesMap);
|