@reykjavik/webtools 0.1.9 → 0.1.10

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 CHANGED
@@ -1,9 +1,18 @@
1
- # Change Log for `es-in-css`
1
+ # Change Log for `@reykjavik/webtools`
2
2
 
3
3
  ## Upcoming...
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.1.10
8
+
9
+ _2024-02-14_
10
+
11
+ - `@reykjavik/webtools/http`
12
+ - feat: Add the rest of the more obscure HTTP status constants (WebDAV,
13
+ etc.)
14
+ - fix: Add `429`, `432`, `451` to `HTTP_CLIENT_ERROR_ALL` type
15
+
7
16
  ## 0.1.9
8
17
 
9
18
  _2023-04-27_
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { EitherObj } from '@reykjavik/hanna-utils';
3
3
  declare global {
4
4
  interface Window {
@@ -220,7 +220,7 @@ export type CookieHubProviderProps = EitherObj<{
220
220
  *
221
221
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1##cookiehubprovider-component
222
222
  */
223
- export declare const CookieHubProvider: (props: CookieHubProviderProps) => JSX.Element;
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.
@@ -74,7 +74,9 @@ const CookieHubProvider = (props) => {
74
74
  ? props.scriptUrl
75
75
  : scriptUrlTemplate.replace(idToken, props.accountId);
76
76
  script.onload = () => {
77
- window.cookiehub.load(Object.assign(Object.assign({}, opts), { onInitialise(status) {
77
+ window.cookiehub.load({
78
+ ...opts,
79
+ onInitialise(status) {
78
80
  const analytics = this.hasConsented('analytics');
79
81
  const preferences = this.hasConsented('preferences');
80
82
  const marketing = this.hasConsented('marketing');
@@ -96,16 +98,27 @@ const CookieHubProvider = (props) => {
96
98
  if (category === 'necessary') {
97
99
  return;
98
100
  }
99
- setState((state) => (Object.assign(Object.assign({}, state), { consent: Object.assign(Object.assign({}, state.consent), { [category]: true }) })));
101
+ setState((state) => ({
102
+ ...state,
103
+ consent: { ...state.consent, [category]: true },
104
+ }));
100
105
  opts.onAllow && opts.onAllow.call(this, category);
101
106
  },
102
107
  onRevoke(category) {
103
108
  if (category === 'necessary') {
104
109
  return;
105
110
  }
106
- setState((state) => (Object.assign(Object.assign({}, state), { consent: Object.assign(Object.assign({}, state.consent), { [category]: false }) })));
111
+ setState((state) => ({
112
+ ...state,
113
+ consent: { ...state.consent, [category]: false },
114
+ }));
107
115
  opts.onAllow && opts.onAllow.call(this, category);
108
- }, cookie: Object.assign({ secure: true }, opts.cookie) }));
116
+ },
117
+ cookie: {
118
+ secure: true,
119
+ ...opts.cookie,
120
+ },
121
+ });
109
122
  moveCookiehubScriptInDomTree();
110
123
  };
111
124
  props.onError && (script.onerror = props.onError);
package/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
  Miscellaneous JavaScript/TypeScript helpers used by Reykjavík City's web dev
4
4
  teams.
5
5
 
6
- This library is split up into multple individual modules to help keep your
6
+ This library is split up into multiple individual modules to help keep your
7
7
  bundles slim and aid tree-shaking.
8
8
 
9
9
  ```
10
+ npm install @reykjavik/webtools
10
11
  yarn add @reykjavik/webtools
12
+ bun add @reykjavik/webtools
11
13
  ```
12
14
 
13
15
  **Table of Contents:**
@@ -31,6 +33,8 @@ yarn add @reykjavik/webtools
31
33
  - [`SiteImprove` component](#siteimprove-component)
32
34
  - [`pingSiteImprove` helper](#pingsiteimprove-helper)
33
35
  - [`pingSiteImproveOutbound` helper](#pingsiteimproveoutbound-helper)
36
+ - [Contributing](#contributing)
37
+ - [Changelog](#changelog)
34
38
 
35
39
  <!-- prettier-ignore-start -->
36
40
 
@@ -158,8 +162,8 @@ behavior.
158
162
 
159
163
  ### `toSec` TTL helper
160
164
 
161
- **Syntax:** <code>toSec; (ttl: number | `${number}${'s'|'m'|'h'|'d'|'w'}`) =>
162
- number</code>
165
+ **Syntax:**
166
+ `` toSec; (ttl: number | `${number}${'s'|'m'|'h'|'d'|'w'}`) => number ``
163
167
 
164
168
  Converts a `TTL` (max-age) value into seconds, and returns `0` for bad and/or
165
169
  negative input values.
@@ -416,12 +420,23 @@ applications and perform custom event tracking.
416
420
  A component for loading a SiteImprove analytics script and set up page-view
417
421
  tracking across Next.js routes.
418
422
 
419
- It also automatically logs all outbound link clicks.
423
+ It also automatically logs all out-bound link clicks.
424
+
425
+ Example usage in pages/\_app.tsx
420
426
 
421
427
  ```js
422
428
  import { SiteImprove } from '@reykjavik/webtools/next/SiteImprove';
423
429
 
424
430
  const siteImproveAccountId = '[ACCOUNT_ID]'; // e.g. "7654321"
431
+
432
+ // Inside MyApp component
433
+ <Component {...pageProps} />
434
+ <SiteImprove
435
+ accountId={siteImproveAccountId}
436
+ onError={(error) =>
437
+ Logger('error', 'An error occured initializing siteimprove', error)
438
+ }
439
+ />;
425
440
  ```
426
441
 
427
442
  The component has an optional `hasConsented` prop which can be used to
@@ -441,7 +456,7 @@ editor), but there's a brief summary:
441
456
  (alternative to `accountId` prop).
442
457
  - `hasConstented?: boolean` — Manual GDPR 'analytics' consent flag. Allows
443
458
  hard opt-out, but defers to
444
- [`CookieHubProvider` values](#usecookiehubconsent) by default.
459
+ [`CookieHubProvider` values](#usecookiehubconsent) if they are available.
445
460
  - `onLoad?: (e: unknown) => void` — Fires when the script has loaded.
446
461
  - `onError?: (e: unknown) => void` — Fires if loading the script failed.
447
462
 
@@ -478,13 +493,21 @@ import { pingSiteImproveOutbound } from '@reykjavik/webtools/next/SiteImprove';
478
493
  const handleSubmit = () => {
479
494
  // perform submit action...
480
495
  if (success) {
481
- const fileUrl ='/download/report.pdf'
496
+ const fileUrl = '/download/report.pdf';
482
497
  pingSiteImproveOutbound(fileUrl);
483
- document.location.href = fileUrl
498
+ document.location.href = fileUrl;
484
499
  }
485
500
  };
501
+ ```
486
502
 
503
+ ---
487
504
 
505
+ ## Contributing
506
+
507
+ This project uses the [Bun runtime](https://bun.sh) for development (tests,
508
+ build, etc.)
509
+
510
+ PRs are welcoms!
488
511
 
489
512
  ---
490
513
 
@@ -492,4 +515,7 @@ const handleSubmit = () => {
492
515
 
493
516
  See
494
517
  [CHANGELOG.md](https://github.com/reykjavikcity/webtools/blob/main/CHANGELOG.md)
518
+
519
+ ```
520
+
495
521
  ```
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { EitherObj } from '@reykjavik/hanna-utils';
3
3
  declare global {
4
4
  interface Window {
@@ -220,7 +220,7 @@ export type CookieHubProviderProps = EitherObj<{
220
220
  *
221
221
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1##cookiehubprovider-component
222
222
  */
223
- export declare const CookieHubProvider: (props: CookieHubProviderProps) => JSX.Element;
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.
@@ -48,7 +48,9 @@ export const CookieHubProvider = (props) => {
48
48
  ? props.scriptUrl
49
49
  : scriptUrlTemplate.replace(idToken, props.accountId);
50
50
  script.onload = () => {
51
- window.cookiehub.load(Object.assign(Object.assign({}, opts), { onInitialise(status) {
51
+ window.cookiehub.load({
52
+ ...opts,
53
+ onInitialise(status) {
52
54
  const analytics = this.hasConsented('analytics');
53
55
  const preferences = this.hasConsented('preferences');
54
56
  const marketing = this.hasConsented('marketing');
@@ -70,16 +72,27 @@ export const CookieHubProvider = (props) => {
70
72
  if (category === 'necessary') {
71
73
  return;
72
74
  }
73
- setState((state) => (Object.assign(Object.assign({}, state), { consent: Object.assign(Object.assign({}, state.consent), { [category]: true }) })));
75
+ setState((state) => ({
76
+ ...state,
77
+ consent: { ...state.consent, [category]: true },
78
+ }));
74
79
  opts.onAllow && opts.onAllow.call(this, category);
75
80
  },
76
81
  onRevoke(category) {
77
82
  if (category === 'necessary') {
78
83
  return;
79
84
  }
80
- setState((state) => (Object.assign(Object.assign({}, state), { consent: Object.assign(Object.assign({}, state.consent), { [category]: false }) })));
85
+ setState((state) => ({
86
+ ...state,
87
+ consent: { ...state.consent, [category]: false },
88
+ }));
81
89
  opts.onAllow && opts.onAllow.call(this, category);
82
- }, cookie: Object.assign({ secure: true }, opts.cookie) }));
90
+ },
91
+ cookie: {
92
+ secure: true,
93
+ ...opts.cookie,
94
+ },
95
+ });
83
96
  moveCookiehubScriptInDomTree();
84
97
  };
85
98
  props.onError && (script.onerror = props.onError);
package/esm/http.d.ts CHANGED
@@ -3,6 +3,10 @@ import { ServerResponse } from 'http';
3
3
  export declare const HTTP_100_Continue = 100;
4
4
  /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
5
5
  export declare const HTTP_101_SwitchingProtocols = 101;
6
+ /** (WebDAV) The server has received and is processing the request, but no response is available yet. */
7
+ export declare const HTTP_102_Processing = 102;
8
+ /** This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response or preconnect to an origin from which the page will need resources. */
9
+ export declare const HTTP_103_EarlyHints = 103;
6
10
  /** The request succeeded, and the response body contains the requested resource. */
7
11
  export declare const HTTP_200_OK = 200;
8
12
  /** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
@@ -12,8 +16,16 @@ export declare const HTTP_202_Accepted = 202;
12
16
  export declare const HTTP_203_NonAuthoritativeInformation = 203;
13
17
  /** The response body is empty. */
14
18
  export declare const HTTP_204_NoContent = 204;
19
+ /** Tells the user agent to reset the document which sent this request. */
20
+ export declare const HTTP_205_ResetContent = 205;
15
21
  /** The request succeeded, but the returned metadata is not necessarily complete. */
16
22
  export declare const HTTP_206_PartialContent = 206;
23
+ /** (WebDAV) Conveys information about multiple resources, for situations where multiple status codes might be appropriate. */
24
+ export declare const HTTP_207_MultiStatus = 207;
25
+ /** (WebDAV) Used inside a `<dav:propstat>` response element to avoid repeatedly enumerating the internal members of multiple bindings to the same collection. */
26
+ export declare const HTTP_208_AlreadyReported = 208;
27
+ /** (HTTP Delta Encoding) The server has fulfilled a `GET` request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance. */
28
+ export declare const HTTP_226_IMUsed = 226;
17
29
  /**
18
30
  * Only safe to use in response to GET and HEAD requests
19
31
  *
@@ -70,6 +82,12 @@ export declare const HTTP_417_ExpectationFailed = 417;
70
82
  export declare const HTTP_418_ImATeapot = 418;
71
83
  /** The request was directed at a server that is not able to produce a response. */
72
84
  export declare const HTTP_421_MisdirectedRequest = 421;
85
+ /** (WebDAV) The request was well-formed but was unable to be followed due to semantic errors. */
86
+ export declare const HTTP_422_UnprocessableContent = 422;
87
+ /** (WebDAV) The resource that is being accessed is locked. */
88
+ export declare const HTTP_423_Locked = 423;
89
+ /** (WebDAV) The request failed due to failure of a previous request. */
90
+ export declare const HTTP_424_FailedDependency = 424;
73
91
  /** The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. */
74
92
  export declare const HTTP_426_UpgradeRequired = 426;
75
93
  /** The origin server requires the request to be conditional. */
@@ -94,6 +112,10 @@ export declare const HTTP_504_GatewayTimeout = 504;
94
112
  export declare const HTTP_505_HTTPVersionNotSupported = 505;
95
113
  /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
96
114
  export declare const HTTP_506_VariantAlsoNegotiates = 506;
115
+ /** (WebDAV) The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. */
116
+ export declare const HTTP_507_InsufficientStorage = 507;
117
+ /** (WebDAV) The server detected an infinite loop while processing the request. */
118
+ export declare const HTTP_508_LoopDetected = 508;
97
119
  /** Further extensions to the request are required for the server to fulfill it. */
98
120
  export declare const HTTP_510_NotExtended = 510;
99
121
  /** The client needs to authenticate to gain network access. */
@@ -108,11 +130,11 @@ export type HTTP_CLIENT_ERROR = HTTP_NOT_FOUND | HTTP_BANNED;
108
130
  export type HTTP_SERVER_ERROR = typeof HTTP_500_InternalServerError;
109
131
  export type HTTP_ERROR = HTTP_CLIENT_ERROR | HTTP_SERVER_ERROR;
110
132
  export type HTTP_STATUS = HTTP_INFO_ALL | HTTP_SUCCESS_ALL | HTTP_REDIRECTION_ALL | HTTP_CLIENT_ERROR_ALL | HTTP_SERVER_ERROR_ALL;
111
- export type HTTP_INFO_ALL = HTTP_INFO;
112
- export type HTTP_SUCCESS_ALL = HTTP_SUCCESS | typeof HTTP_203_NonAuthoritativeInformation | typeof HTTP_204_NoContent | typeof HTTP_206_PartialContent;
133
+ export type HTTP_INFO_ALL = HTTP_INFO | typeof HTTP_102_Processing | typeof HTTP_103_EarlyHints;
134
+ export type HTTP_SUCCESS_ALL = HTTP_SUCCESS | typeof HTTP_203_NonAuthoritativeInformation | typeof HTTP_204_NoContent | typeof HTTP_205_ResetContent | typeof HTTP_206_PartialContent | typeof HTTP_207_MultiStatus | typeof HTTP_208_AlreadyReported | typeof HTTP_226_IMUsed;
113
135
  export type HTTP_REDIRECTION_ALL = HTTP_REDIRECTION;
114
- export type HTTP_CLIENT_ERROR_ALL = HTTP_CLIENT_ERROR | typeof HTTP_405_MethodNotAllowed | typeof HTTP_406_NotAcceptable | typeof HTTP_407_ProxyAuthenticationRequired | typeof HTTP_408_RequestTimeout | typeof HTTP_409_Conflict | typeof HTTP_411_LengthRequired | typeof HTTP_412_PreconditionFailed | typeof HTTP_413_PayloadTooLarge | typeof HTTP_414_URITooLong | typeof HTTP_415_UnsupportedMediaType | typeof HTTP_416_RangeNotSatisfiable | typeof HTTP_417_ExpectationFailed | typeof HTTP_418_ImATeapot | typeof HTTP_421_MisdirectedRequest | typeof HTTP_426_UpgradeRequired | typeof HTTP_428_PreconditionRequired;
115
- export type HTTP_SERVER_ERROR_ALL = HTTP_SERVER_ERROR | typeof HTTP_501_NotImplemented | typeof HTTP_502_BadGateway | typeof HTTP_503_ServiceUnavailable | typeof HTTP_504_GatewayTimeout | typeof HTTP_505_HTTPVersionNotSupported | typeof HTTP_506_VariantAlsoNegotiates | typeof HTTP_510_NotExtended | typeof HTTP_511_NetworkAuthenticationRequired;
136
+ export type HTTP_CLIENT_ERROR_ALL = HTTP_CLIENT_ERROR | typeof HTTP_405_MethodNotAllowed | typeof HTTP_406_NotAcceptable | typeof HTTP_407_ProxyAuthenticationRequired | typeof HTTP_408_RequestTimeout | typeof HTTP_409_Conflict | typeof HTTP_411_LengthRequired | typeof HTTP_412_PreconditionFailed | typeof HTTP_413_PayloadTooLarge | typeof HTTP_414_URITooLong | typeof HTTP_415_UnsupportedMediaType | typeof HTTP_416_RangeNotSatisfiable | typeof HTTP_417_ExpectationFailed | typeof HTTP_418_ImATeapot | typeof HTTP_421_MisdirectedRequest | typeof HTTP_422_UnprocessableContent | typeof HTTP_423_Locked | typeof HTTP_424_FailedDependency | typeof HTTP_426_UpgradeRequired | typeof HTTP_428_PreconditionRequired | typeof HTTP_429_TooManyRequests | typeof HTTP_431_RequestHeaderFieldsTooLarge | typeof HTTP_451_UnavailableForLegalReasons;
137
+ export type HTTP_SERVER_ERROR_ALL = HTTP_SERVER_ERROR | typeof HTTP_501_NotImplemented | typeof HTTP_502_BadGateway | typeof HTTP_503_ServiceUnavailable | typeof HTTP_504_GatewayTimeout | typeof HTTP_505_HTTPVersionNotSupported | typeof HTTP_506_VariantAlsoNegotiates | typeof HTTP_507_InsufficientStorage | typeof HTTP_508_LoopDetected | typeof HTTP_510_NotExtended | typeof HTTP_511_NetworkAuthenticationRequired;
116
138
  export type HTTP_ERROR_ALL = HTTP_CLIENT_ERROR_ALL | HTTP_SERVER_ERROR_ALL;
117
139
  type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w';
118
140
  export type TTL = number | `${number}${TimeUnit}`;
package/esm/http.js CHANGED
@@ -3,6 +3,10 @@
3
3
  export const HTTP_100_Continue = 100;
4
4
  /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
5
5
  export const HTTP_101_SwitchingProtocols = 101;
6
+ /** (WebDAV) The server has received and is processing the request, but no response is available yet. */
7
+ export const HTTP_102_Processing = 102;
8
+ /** This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response or preconnect to an origin from which the page will need resources. */
9
+ export const HTTP_103_EarlyHints = 103;
6
10
  // SUCCESS
7
11
  /** The request succeeded, and the response body contains the requested resource. */
8
12
  export const HTTP_200_OK = 200;
@@ -14,8 +18,16 @@ export const HTTP_202_Accepted = 202;
14
18
  export const HTTP_203_NonAuthoritativeInformation = 203;
15
19
  /** The response body is empty. */
16
20
  export const HTTP_204_NoContent = 204;
21
+ /** Tells the user agent to reset the document which sent this request. */
22
+ export const HTTP_205_ResetContent = 205;
17
23
  /** The request succeeded, but the returned metadata is not necessarily complete. */
18
24
  export const HTTP_206_PartialContent = 206;
25
+ /** (WebDAV) Conveys information about multiple resources, for situations where multiple status codes might be appropriate. */
26
+ export const HTTP_207_MultiStatus = 207;
27
+ /** (WebDAV) Used inside a `<dav:propstat>` response element to avoid repeatedly enumerating the internal members of multiple bindings to the same collection. */
28
+ export const HTTP_208_AlreadyReported = 208;
29
+ /** (HTTP Delta Encoding) The server has fulfilled a `GET` request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance. */
30
+ export const HTTP_226_IMUsed = 226;
19
31
  // REDIRECTION
20
32
  /**
21
33
  * Only safe to use in response to GET and HEAD requests
@@ -74,6 +86,12 @@ export const HTTP_417_ExpectationFailed = 417;
74
86
  export const HTTP_418_ImATeapot = 418;
75
87
  /** The request was directed at a server that is not able to produce a response. */
76
88
  export const HTTP_421_MisdirectedRequest = 421;
89
+ /** (WebDAV) The request was well-formed but was unable to be followed due to semantic errors. */
90
+ export const HTTP_422_UnprocessableContent = 422;
91
+ /** (WebDAV) The resource that is being accessed is locked. */
92
+ export const HTTP_423_Locked = 423;
93
+ /** (WebDAV) The request failed due to failure of a previous request. */
94
+ export const HTTP_424_FailedDependency = 424;
77
95
  /** The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. */
78
96
  export const HTTP_426_UpgradeRequired = 426;
79
97
  /** The origin server requires the request to be conditional. */
@@ -99,6 +117,10 @@ export const HTTP_504_GatewayTimeout = 504;
99
117
  export const HTTP_505_HTTPVersionNotSupported = 505;
100
118
  /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
101
119
  export const HTTP_506_VariantAlsoNegotiates = 506;
120
+ /** (WebDAV) The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. */
121
+ export const HTTP_507_InsufficientStorage = 507;
122
+ /** (WebDAV) The server detected an infinite loop while processing the request. */
123
+ export const HTTP_508_LoopDetected = 508;
102
124
  /** Further extensions to the request are required for the server to fulfill it. */
103
125
  export const HTTP_510_NotExtended = 510;
104
126
  /** The client needs to authenticate to gain network access. */
package/esm/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- /// <reference path="./CookieHubConsent.d.tsx" />
2
1
  /// <reference path="./http.d.ts" />
3
- /// <reference path="./next/http.d.tsx" />
2
+ /// <reference path="./CookieHubConsent.d.tsx" />
4
3
  /// <reference path="./next/SiteImprove.d.tsx" />
4
+ /// <reference path="./next/http.d.tsx" />
5
5
 
6
6
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { EitherObj } from '@reykjavik/hanna-utils';
3
3
  declare global {
4
4
  interface Window {
@@ -43,6 +43,19 @@ type SiteImproveCustomEvent = [
43
43
  action: string,
44
44
  label?: string
45
45
  ];
46
+ /**
47
+ * A small helper for tracking custom UI events and reporting them to SiteImrove.
48
+ *
49
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
50
+ */
51
+ export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
52
+ /**
53
+ * A small helper for reporting to SiteImrove when the user is programmatically
54
+ * being sent to a different URL/resource.
55
+ *
56
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
57
+ */
58
+ export declare const pingSiteImproveOutbound: (ourl: string) => void;
46
59
  export type SiteImproveProps = EitherObj<{
47
60
  /**
48
61
  * Your SiteImprove account ID.
@@ -65,8 +78,8 @@ export type SiteImproveProps = EitherObj<{
65
78
  *
66
79
  * A value of `false` prevents the analytics script being loaded.
67
80
  *
68
- * Any other value causes the component to defer to the `CookieHubProvider`
69
- * component, and only applies if the cookiehub flag is undefined.
81
+ * A value of `true` still defers to the 'analytics' consent state provided
82
+ * by the `CookieHubProvider` component (if present).
70
83
  */
71
84
  hasConstented?: boolean;
72
85
  /**
@@ -84,18 +97,5 @@ export type SiteImproveProps = EitherObj<{
84
97
  *
85
98
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1##siteimprove-component
86
99
  */
87
- export declare const SiteImprove: (props: SiteImproveProps) => JSX.Element | null;
88
- /**
89
- * A small helper for tracking custom UI events and reporting them to SiteImrove.
90
- *
91
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
92
- */
93
- export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
94
- /**
95
- * A small helper for reporting to SiteImrove when the user is programmatically
96
- * being sent to a different URL/resource.
97
- *
98
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
99
- */
100
- export declare const pingSiteImproveOutbound: (ourl: string) => void;
100
+ export declare const SiteImprove: (props: SiteImproveProps) => React.JSX.Element | null;
101
101
  export {};
@@ -1,7 +1,9 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { Router } from 'next/router.js';
3
- import Script from 'next/script.js';
3
+ import NextScript from 'next/script.js';
4
4
  import { useCookieHubConsent } from '../CookieHubConsent.js';
5
+ // Fixes an issue with `next/script` types when `pkgJson.type === "module"`
6
+ const Script = NextScript;
5
7
  // END: Mock typing of SiteImprove's event tracking API
6
8
  // --------------------------------------------------------------------------
7
9
  //
@@ -19,6 +21,34 @@ const _emitEvent = typeof window === 'undefined'
19
21
  console.info('SiteImprove:', event);
20
22
  }
21
23
  };
24
+ // ---------------------------------------------------------------------------
25
+ /**
26
+ * A small helper for tracking custom UI events and reporting them to SiteImrove.
27
+ *
28
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
29
+ */
30
+ export const pingSiteImprove = (category, action, label) => {
31
+ if (process.env.NODE_ENV === 'development' &&
32
+ (!window._sz || window._sz._jit_defined_)) {
33
+ console.warn('`pingSiteImprove` was called before SiteImprove script was loaded.');
34
+ }
35
+ _emitEvent(['event', category, action, label]);
36
+ };
37
+ // ---------------------------------------------------------------------------
38
+ /**
39
+ * A small helper for reporting to SiteImrove when the user is programmatically
40
+ * being sent to a different URL/resource.
41
+ *
42
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
43
+ */
44
+ export const pingSiteImproveOutbound = (ourl) => {
45
+ if (process.env.NODE_ENV === 'development' &&
46
+ (!window._sz || window._sz._jit_defined_)) {
47
+ console.warn('`pingSiteImproveOutbound` was called before SiteImprove script was loaded.');
48
+ }
49
+ _emitEvent(['request', { ourl, ref: document.location.href }]);
50
+ };
51
+ // ---------------------------------------------------------------------------
22
52
  /*
23
53
  SiteImprove's "trackdynamic" (page view) event requires both the new URL
24
54
  and the old (referer) URL.
@@ -89,25 +119,26 @@ export const SiteImprove = (props) => {
89
119
  const consented = (analytics && props.hasConstented !== false) ||
90
120
  (analytics === undefined && props.hasConstented);
91
121
  useEffect(() => {
92
- if (consented) {
93
- if (process.env.NODE_ENV !== 'production') {
94
- console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
95
- if (!window._sz) {
96
- setTimeout(() => {
97
- window._sz = window._sz || [];
98
- }, 300);
99
- }
122
+ if (!consented) {
123
+ return;
124
+ }
125
+ if (process.env.NODE_ENV !== 'production') {
126
+ console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
127
+ if (!window._sz) {
128
+ setTimeout(() => {
129
+ window._sz = window._sz || [];
130
+ }, 300);
100
131
  }
101
- const routerEvents = Router.events;
102
- routerEvents.on('routeChangeStart', captureRefUrl);
103
- routerEvents.on('routeChangeComplete', sendRoutingEvent);
104
- const stopLoggingOutboundLinks = logOutboundLinks();
105
- return () => {
106
- routerEvents.off('routeChangeStart', captureRefUrl);
107
- routerEvents.off('routeChangeComplete', sendRoutingEvent);
108
- stopLoggingOutboundLinks();
109
- };
110
132
  }
133
+ const routerEvents = Router.events;
134
+ routerEvents.on('routeChangeStart', captureRefUrl);
135
+ routerEvents.on('routeChangeComplete', sendRoutingEvent);
136
+ const stopLoggingOutboundLinks = logOutboundLinks();
137
+ return () => {
138
+ routerEvents.off('routeChangeStart', captureRefUrl);
139
+ routerEvents.off('routeChangeComplete', sendRoutingEvent);
140
+ stopLoggingOutboundLinks();
141
+ };
111
142
  },
112
143
  // eslint-disable-next-line react-hooks/exhaustive-deps
113
144
  [consented]);
@@ -119,30 +150,3 @@ export const SiteImprove = (props) => {
119
150
  : scriptUrlTemplate.replace(idToken, props.accountId);
120
151
  return (React.createElement(Script, { type: "text/javascript", strategy: "afterInteractive", src: scriptUrl, onLoad: props.onLoad, onError: props.onError }));
121
152
  };
122
- // ---------------------------------------------------------------------------
123
- /**
124
- * A small helper for tracking custom UI events and reporting them to SiteImrove.
125
- *
126
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
127
- */
128
- export const pingSiteImprove = (category, action, label) => {
129
- if (process.env.NODE_ENV === 'development' &&
130
- (!window._sz || window._sz._jit_defined_)) {
131
- console.warn('`pingSiteImprove` was called before SiteImprove script was loaded.');
132
- }
133
- _emitEvent(['event', category, action, label]);
134
- };
135
- // ---------------------------------------------------------------------------
136
- /**
137
- * A small helper for reporting to SiteImrove when the user is programmatically
138
- * being sent to a different URL/resource.
139
- *
140
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
141
- */
142
- export const pingSiteImproveOutbound = (ourl) => {
143
- if (process.env.NODE_ENV === 'development' &&
144
- (!window._sz || window._sz._jit_defined_)) {
145
- console.warn('`pingSiteImproveOutbound` was called before SiteImprove script was loaded.');
146
- }
147
- _emitEvent(['request', { ourl, ref: document.location.href }]);
148
- };
@@ -1,4 +1,4 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  import React, { FunctionComponent } from 'react';
3
3
  import { Cleanup } from '@reykjavik/hanna-utils';
4
4
  import { ServerResponse } from 'http';
@@ -46,7 +46,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
46
46
  /**
47
47
  * Use this method to inside a `getServerSideProps` method (or API route)
48
48
  * to return an `HTTP_304_NotModified` response with an empty props object,
49
- * in a way that doesn't make TypeScript at you.
49
+ * in a way that doesn't make TypeScript shout at you.
50
50
  *
51
51
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1#notmodified304-helper
52
52
  */
package/esm/next/http.js CHANGED
@@ -1,14 +1,3 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import React from 'react';
13
2
  import { cacheControl, HTTP_304_NotModified } from '../http.js';
14
3
  /*
@@ -27,12 +16,15 @@ const showErrorPage = (response, error, ttl = '2s') => {
27
16
  typeof error === 'number'
28
17
  ? { statusCode: error }
29
18
  : error;
30
- const { statusCode, message } = error, otherProps = __rest(error, ["statusCode", "message"]);
19
+ const { statusCode, message, ...otherProps } = error;
31
20
  response = 'res' in response ? response.res : response;
32
21
  response.statusCode = error.statusCode;
33
22
  cacheControl(response, ttl);
34
23
  return {
35
- props: Object.assign(Object.assign({}, otherProps), { __error: { statusCode, message } }),
24
+ props: {
25
+ ...otherProps,
26
+ __error: { statusCode, message },
27
+ },
36
28
  };
37
29
  };
38
30
  // ===========================================================================
@@ -49,13 +41,16 @@ export const makeErrorizeAppHOC = (ErrorPage) => {
49
41
  const ErrorizedApp = (appProps) => {
50
42
  const { pageProps } = appProps;
51
43
  if (pageProps.__error) {
52
- const { __error } = pageProps, otherProps = __rest(pageProps, ["__error"]);
53
- return (React.createElement(App, Object.assign({}, appProps, { Component: ErrorPage, pageProps: Object.assign(Object.assign({}, otherProps), __error) })));
44
+ const { __error, ...otherProps } = pageProps;
45
+ return (React.createElement(App, { ...appProps, Component: ErrorPage, pageProps: {
46
+ ...otherProps,
47
+ ...__error,
48
+ } }));
54
49
  }
55
- return React.createElement(App, Object.assign({}, appProps));
50
+ return React.createElement(App, { ...appProps });
56
51
  };
57
52
  ErrorizedApp.getInitialProps = App.getInitialProps;
58
- ErrorizedApp.displayName = 'Errorized' + (App.displayName || App.name || 'App');
53
+ ErrorizedApp.displayName = `Errorized${App.displayName || App.name || 'App'}`;
59
54
  return ErrorizedApp;
60
55
  };
61
56
  withErrorHandling.showErrorPage = showErrorPage;
@@ -65,7 +60,7 @@ export const makeErrorizeAppHOC = (ErrorPage) => {
65
60
  /**
66
61
  * Use this method to inside a `getServerSideProps` method (or API route)
67
62
  * to return an `HTTP_304_NotModified` response with an empty props object,
68
- * in a way that doesn't make TypeScript at you.
63
+ * in a way that doesn't make TypeScript shout at you.
69
64
  *
70
65
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1#notmodified304-helper
71
66
  */
package/http.d.ts CHANGED
@@ -3,6 +3,10 @@ import { ServerResponse } from 'http';
3
3
  export declare const HTTP_100_Continue = 100;
4
4
  /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
5
5
  export declare const HTTP_101_SwitchingProtocols = 101;
6
+ /** (WebDAV) The server has received and is processing the request, but no response is available yet. */
7
+ export declare const HTTP_102_Processing = 102;
8
+ /** This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response or preconnect to an origin from which the page will need resources. */
9
+ export declare const HTTP_103_EarlyHints = 103;
6
10
  /** The request succeeded, and the response body contains the requested resource. */
7
11
  export declare const HTTP_200_OK = 200;
8
12
  /** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
@@ -12,8 +16,16 @@ export declare const HTTP_202_Accepted = 202;
12
16
  export declare const HTTP_203_NonAuthoritativeInformation = 203;
13
17
  /** The response body is empty. */
14
18
  export declare const HTTP_204_NoContent = 204;
19
+ /** Tells the user agent to reset the document which sent this request. */
20
+ export declare const HTTP_205_ResetContent = 205;
15
21
  /** The request succeeded, but the returned metadata is not necessarily complete. */
16
22
  export declare const HTTP_206_PartialContent = 206;
23
+ /** (WebDAV) Conveys information about multiple resources, for situations where multiple status codes might be appropriate. */
24
+ export declare const HTTP_207_MultiStatus = 207;
25
+ /** (WebDAV) Used inside a `<dav:propstat>` response element to avoid repeatedly enumerating the internal members of multiple bindings to the same collection. */
26
+ export declare const HTTP_208_AlreadyReported = 208;
27
+ /** (HTTP Delta Encoding) The server has fulfilled a `GET` request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance. */
28
+ export declare const HTTP_226_IMUsed = 226;
17
29
  /**
18
30
  * Only safe to use in response to GET and HEAD requests
19
31
  *
@@ -70,6 +82,12 @@ export declare const HTTP_417_ExpectationFailed = 417;
70
82
  export declare const HTTP_418_ImATeapot = 418;
71
83
  /** The request was directed at a server that is not able to produce a response. */
72
84
  export declare const HTTP_421_MisdirectedRequest = 421;
85
+ /** (WebDAV) The request was well-formed but was unable to be followed due to semantic errors. */
86
+ export declare const HTTP_422_UnprocessableContent = 422;
87
+ /** (WebDAV) The resource that is being accessed is locked. */
88
+ export declare const HTTP_423_Locked = 423;
89
+ /** (WebDAV) The request failed due to failure of a previous request. */
90
+ export declare const HTTP_424_FailedDependency = 424;
73
91
  /** The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. */
74
92
  export declare const HTTP_426_UpgradeRequired = 426;
75
93
  /** The origin server requires the request to be conditional. */
@@ -94,6 +112,10 @@ export declare const HTTP_504_GatewayTimeout = 504;
94
112
  export declare const HTTP_505_HTTPVersionNotSupported = 505;
95
113
  /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
96
114
  export declare const HTTP_506_VariantAlsoNegotiates = 506;
115
+ /** (WebDAV) The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. */
116
+ export declare const HTTP_507_InsufficientStorage = 507;
117
+ /** (WebDAV) The server detected an infinite loop while processing the request. */
118
+ export declare const HTTP_508_LoopDetected = 508;
97
119
  /** Further extensions to the request are required for the server to fulfill it. */
98
120
  export declare const HTTP_510_NotExtended = 510;
99
121
  /** The client needs to authenticate to gain network access. */
@@ -108,11 +130,11 @@ export type HTTP_CLIENT_ERROR = HTTP_NOT_FOUND | HTTP_BANNED;
108
130
  export type HTTP_SERVER_ERROR = typeof HTTP_500_InternalServerError;
109
131
  export type HTTP_ERROR = HTTP_CLIENT_ERROR | HTTP_SERVER_ERROR;
110
132
  export type HTTP_STATUS = HTTP_INFO_ALL | HTTP_SUCCESS_ALL | HTTP_REDIRECTION_ALL | HTTP_CLIENT_ERROR_ALL | HTTP_SERVER_ERROR_ALL;
111
- export type HTTP_INFO_ALL = HTTP_INFO;
112
- export type HTTP_SUCCESS_ALL = HTTP_SUCCESS | typeof HTTP_203_NonAuthoritativeInformation | typeof HTTP_204_NoContent | typeof HTTP_206_PartialContent;
133
+ export type HTTP_INFO_ALL = HTTP_INFO | typeof HTTP_102_Processing | typeof HTTP_103_EarlyHints;
134
+ export type HTTP_SUCCESS_ALL = HTTP_SUCCESS | typeof HTTP_203_NonAuthoritativeInformation | typeof HTTP_204_NoContent | typeof HTTP_205_ResetContent | typeof HTTP_206_PartialContent | typeof HTTP_207_MultiStatus | typeof HTTP_208_AlreadyReported | typeof HTTP_226_IMUsed;
113
135
  export type HTTP_REDIRECTION_ALL = HTTP_REDIRECTION;
114
- export type HTTP_CLIENT_ERROR_ALL = HTTP_CLIENT_ERROR | typeof HTTP_405_MethodNotAllowed | typeof HTTP_406_NotAcceptable | typeof HTTP_407_ProxyAuthenticationRequired | typeof HTTP_408_RequestTimeout | typeof HTTP_409_Conflict | typeof HTTP_411_LengthRequired | typeof HTTP_412_PreconditionFailed | typeof HTTP_413_PayloadTooLarge | typeof HTTP_414_URITooLong | typeof HTTP_415_UnsupportedMediaType | typeof HTTP_416_RangeNotSatisfiable | typeof HTTP_417_ExpectationFailed | typeof HTTP_418_ImATeapot | typeof HTTP_421_MisdirectedRequest | typeof HTTP_426_UpgradeRequired | typeof HTTP_428_PreconditionRequired;
115
- export type HTTP_SERVER_ERROR_ALL = HTTP_SERVER_ERROR | typeof HTTP_501_NotImplemented | typeof HTTP_502_BadGateway | typeof HTTP_503_ServiceUnavailable | typeof HTTP_504_GatewayTimeout | typeof HTTP_505_HTTPVersionNotSupported | typeof HTTP_506_VariantAlsoNegotiates | typeof HTTP_510_NotExtended | typeof HTTP_511_NetworkAuthenticationRequired;
136
+ export type HTTP_CLIENT_ERROR_ALL = HTTP_CLIENT_ERROR | typeof HTTP_405_MethodNotAllowed | typeof HTTP_406_NotAcceptable | typeof HTTP_407_ProxyAuthenticationRequired | typeof HTTP_408_RequestTimeout | typeof HTTP_409_Conflict | typeof HTTP_411_LengthRequired | typeof HTTP_412_PreconditionFailed | typeof HTTP_413_PayloadTooLarge | typeof HTTP_414_URITooLong | typeof HTTP_415_UnsupportedMediaType | typeof HTTP_416_RangeNotSatisfiable | typeof HTTP_417_ExpectationFailed | typeof HTTP_418_ImATeapot | typeof HTTP_421_MisdirectedRequest | typeof HTTP_422_UnprocessableContent | typeof HTTP_423_Locked | typeof HTTP_424_FailedDependency | typeof HTTP_426_UpgradeRequired | typeof HTTP_428_PreconditionRequired | typeof HTTP_429_TooManyRequests | typeof HTTP_431_RequestHeaderFieldsTooLarge | typeof HTTP_451_UnavailableForLegalReasons;
137
+ export type HTTP_SERVER_ERROR_ALL = HTTP_SERVER_ERROR | typeof HTTP_501_NotImplemented | typeof HTTP_502_BadGateway | typeof HTTP_503_ServiceUnavailable | typeof HTTP_504_GatewayTimeout | typeof HTTP_505_HTTPVersionNotSupported | typeof HTTP_506_VariantAlsoNegotiates | typeof HTTP_507_InsufficientStorage | typeof HTTP_508_LoopDetected | typeof HTTP_510_NotExtended | typeof HTTP_511_NetworkAuthenticationRequired;
116
138
  export type HTTP_ERROR_ALL = HTTP_CLIENT_ERROR_ALL | HTTP_SERVER_ERROR_ALL;
117
139
  type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w';
118
140
  export type TTL = number | `${number}${TimeUnit}`;
package/http.js CHANGED
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cacheControl = exports.toSec = exports.HTTP_511_NetworkAuthenticationRequired = exports.HTTP_510_NotExtended = exports.HTTP_506_VariantAlsoNegotiates = exports.HTTP_505_HTTPVersionNotSupported = exports.HTTP_504_GatewayTimeout = exports.HTTP_503_ServiceUnavailable = exports.HTTP_502_BadGateway = exports.HTTP_501_NotImplemented = exports.HTTP_500_InternalServerError = exports.HTTP_451_UnavailableForLegalReasons = exports.HTTP_431_RequestHeaderFieldsTooLarge = exports.HTTP_429_TooManyRequests = exports.HTTP_428_PreconditionRequired = exports.HTTP_426_UpgradeRequired = exports.HTTP_421_MisdirectedRequest = exports.HTTP_418_ImATeapot = exports.HTTP_417_ExpectationFailed = exports.HTTP_416_RangeNotSatisfiable = exports.HTTP_415_UnsupportedMediaType = exports.HTTP_414_URITooLong = exports.HTTP_413_PayloadTooLarge = exports.HTTP_412_PreconditionFailed = exports.HTTP_411_LengthRequired = exports.HTTP_410_Gone = exports.HTTP_409_Conflict = exports.HTTP_408_RequestTimeout = exports.HTTP_407_ProxyAuthenticationRequired = exports.HTTP_406_NotAcceptable = exports.HTTP_405_MethodNotAllowed = exports.HTTP_404_NotFound = exports.HTTP_403_Forbidden = exports.HTTP_401_Unauthorized = exports.HTTP_400_BadRequest = exports.HTTP_308_PermanentRedirect = exports.HTTP_307_TemporaryRedirect = exports.HTTP_304_NotModified = exports.HTTP_303_SeeOther = exports.HTTP_302_Found = exports.HTTP_301_MovedPermanently = exports.HTTP_206_PartialContent = exports.HTTP_204_NoContent = exports.HTTP_203_NonAuthoritativeInformation = exports.HTTP_202_Accepted = exports.HTTP_201_Created = exports.HTTP_200_OK = exports.HTTP_101_SwitchingProtocols = exports.HTTP_100_Continue = void 0;
3
+ exports.HTTP_502_BadGateway = exports.HTTP_501_NotImplemented = exports.HTTP_500_InternalServerError = exports.HTTP_451_UnavailableForLegalReasons = exports.HTTP_431_RequestHeaderFieldsTooLarge = exports.HTTP_429_TooManyRequests = exports.HTTP_428_PreconditionRequired = exports.HTTP_426_UpgradeRequired = exports.HTTP_424_FailedDependency = exports.HTTP_423_Locked = exports.HTTP_422_UnprocessableContent = exports.HTTP_421_MisdirectedRequest = exports.HTTP_418_ImATeapot = exports.HTTP_417_ExpectationFailed = exports.HTTP_416_RangeNotSatisfiable = exports.HTTP_415_UnsupportedMediaType = exports.HTTP_414_URITooLong = exports.HTTP_413_PayloadTooLarge = exports.HTTP_412_PreconditionFailed = exports.HTTP_411_LengthRequired = exports.HTTP_410_Gone = exports.HTTP_409_Conflict = exports.HTTP_408_RequestTimeout = exports.HTTP_407_ProxyAuthenticationRequired = exports.HTTP_406_NotAcceptable = exports.HTTP_405_MethodNotAllowed = exports.HTTP_404_NotFound = exports.HTTP_403_Forbidden = exports.HTTP_401_Unauthorized = exports.HTTP_400_BadRequest = exports.HTTP_308_PermanentRedirect = exports.HTTP_307_TemporaryRedirect = exports.HTTP_304_NotModified = exports.HTTP_303_SeeOther = exports.HTTP_302_Found = exports.HTTP_301_MovedPermanently = exports.HTTP_226_IMUsed = exports.HTTP_208_AlreadyReported = exports.HTTP_207_MultiStatus = exports.HTTP_206_PartialContent = exports.HTTP_205_ResetContent = exports.HTTP_204_NoContent = exports.HTTP_203_NonAuthoritativeInformation = exports.HTTP_202_Accepted = exports.HTTP_201_Created = exports.HTTP_200_OK = exports.HTTP_103_EarlyHints = exports.HTTP_102_Processing = exports.HTTP_101_SwitchingProtocols = exports.HTTP_100_Continue = void 0;
4
+ exports.cacheControl = exports.toSec = exports.HTTP_511_NetworkAuthenticationRequired = exports.HTTP_510_NotExtended = exports.HTTP_508_LoopDetected = exports.HTTP_507_InsufficientStorage = exports.HTTP_506_VariantAlsoNegotiates = exports.HTTP_505_HTTPVersionNotSupported = exports.HTTP_504_GatewayTimeout = exports.HTTP_503_ServiceUnavailable = void 0;
4
5
  // INFORMATION
5
6
  /** The client should continue the request or ignore the response if the request is already finished. */
6
7
  exports.HTTP_100_Continue = 100;
7
8
  /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
8
9
  exports.HTTP_101_SwitchingProtocols = 101;
10
+ /** (WebDAV) The server has received and is processing the request, but no response is available yet. */
11
+ exports.HTTP_102_Processing = 102;
12
+ /** This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response or preconnect to an origin from which the page will need resources. */
13
+ exports.HTTP_103_EarlyHints = 103;
9
14
  // SUCCESS
10
15
  /** The request succeeded, and the response body contains the requested resource. */
11
16
  exports.HTTP_200_OK = 200;
@@ -17,8 +22,16 @@ exports.HTTP_202_Accepted = 202;
17
22
  exports.HTTP_203_NonAuthoritativeInformation = 203;
18
23
  /** The response body is empty. */
19
24
  exports.HTTP_204_NoContent = 204;
25
+ /** Tells the user agent to reset the document which sent this request. */
26
+ exports.HTTP_205_ResetContent = 205;
20
27
  /** The request succeeded, but the returned metadata is not necessarily complete. */
21
28
  exports.HTTP_206_PartialContent = 206;
29
+ /** (WebDAV) Conveys information about multiple resources, for situations where multiple status codes might be appropriate. */
30
+ exports.HTTP_207_MultiStatus = 207;
31
+ /** (WebDAV) Used inside a `<dav:propstat>` response element to avoid repeatedly enumerating the internal members of multiple bindings to the same collection. */
32
+ exports.HTTP_208_AlreadyReported = 208;
33
+ /** (HTTP Delta Encoding) The server has fulfilled a `GET` request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance. */
34
+ exports.HTTP_226_IMUsed = 226;
22
35
  // REDIRECTION
23
36
  /**
24
37
  * Only safe to use in response to GET and HEAD requests
@@ -77,6 +90,12 @@ exports.HTTP_417_ExpectationFailed = 417;
77
90
  exports.HTTP_418_ImATeapot = 418;
78
91
  /** The request was directed at a server that is not able to produce a response. */
79
92
  exports.HTTP_421_MisdirectedRequest = 421;
93
+ /** (WebDAV) The request was well-formed but was unable to be followed due to semantic errors. */
94
+ exports.HTTP_422_UnprocessableContent = 422;
95
+ /** (WebDAV) The resource that is being accessed is locked. */
96
+ exports.HTTP_423_Locked = 423;
97
+ /** (WebDAV) The request failed due to failure of a previous request. */
98
+ exports.HTTP_424_FailedDependency = 424;
80
99
  /** The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. */
81
100
  exports.HTTP_426_UpgradeRequired = 426;
82
101
  /** The origin server requires the request to be conditional. */
@@ -102,6 +121,10 @@ exports.HTTP_504_GatewayTimeout = 504;
102
121
  exports.HTTP_505_HTTPVersionNotSupported = 505;
103
122
  /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
104
123
  exports.HTTP_506_VariantAlsoNegotiates = 506;
124
+ /** (WebDAV) The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. */
125
+ exports.HTTP_507_InsufficientStorage = 507;
126
+ /** (WebDAV) The server detected an infinite loop while processing the request. */
127
+ exports.HTTP_508_LoopDetected = 508;
105
128
  /** Further extensions to the request are required for the server to fulfill it. */
106
129
  exports.HTTP_510_NotExtended = 510;
107
130
  /** The client needs to authenticate to gain network access. */
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- /// <reference path="./CookieHubConsent.d.tsx" />
2
1
  /// <reference path="./http.d.ts" />
3
- /// <reference path="./next/http.d.tsx" />
2
+ /// <reference path="./CookieHubConsent.d.tsx" />
4
3
  /// <reference path="./next/SiteImprove.d.tsx" />
4
+ /// <reference path="./next/http.d.tsx" />
5
5
 
6
6
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { EitherObj } from '@reykjavik/hanna-utils';
3
3
  declare global {
4
4
  interface Window {
@@ -43,6 +43,19 @@ type SiteImproveCustomEvent = [
43
43
  action: string,
44
44
  label?: string
45
45
  ];
46
+ /**
47
+ * A small helper for tracking custom UI events and reporting them to SiteImrove.
48
+ *
49
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
50
+ */
51
+ export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
52
+ /**
53
+ * A small helper for reporting to SiteImrove when the user is programmatically
54
+ * being sent to a different URL/resource.
55
+ *
56
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
57
+ */
58
+ export declare const pingSiteImproveOutbound: (ourl: string) => void;
46
59
  export type SiteImproveProps = EitherObj<{
47
60
  /**
48
61
  * Your SiteImprove account ID.
@@ -65,8 +78,8 @@ export type SiteImproveProps = EitherObj<{
65
78
  *
66
79
  * A value of `false` prevents the analytics script being loaded.
67
80
  *
68
- * Any other value causes the component to defer to the `CookieHubProvider`
69
- * component, and only applies if the cookiehub flag is undefined.
81
+ * A value of `true` still defers to the 'analytics' consent state provided
82
+ * by the `CookieHubProvider` component (if present).
70
83
  */
71
84
  hasConstented?: boolean;
72
85
  /**
@@ -84,18 +97,5 @@ export type SiteImproveProps = EitherObj<{
84
97
  *
85
98
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1##siteimprove-component
86
99
  */
87
- export declare const SiteImprove: (props: SiteImproveProps) => JSX.Element | null;
88
- /**
89
- * A small helper for tracking custom UI events and reporting them to SiteImrove.
90
- *
91
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
92
- */
93
- export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
94
- /**
95
- * A small helper for reporting to SiteImrove when the user is programmatically
96
- * being sent to a different URL/resource.
97
- *
98
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
99
- */
100
- export declare const pingSiteImproveOutbound: (ourl: string) => void;
100
+ export declare const SiteImprove: (props: SiteImproveProps) => React.JSX.Element | null;
101
101
  export {};
@@ -26,11 +26,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.pingSiteImproveOutbound = exports.pingSiteImprove = exports.SiteImprove = void 0;
29
+ exports.SiteImprove = exports.pingSiteImproveOutbound = exports.pingSiteImprove = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
31
  const router_js_1 = require("next/router.js");
32
32
  const script_js_1 = __importDefault(require("next/script.js"));
33
33
  const CookieHubConsent_js_1 = require("../CookieHubConsent.js");
34
+ // Fixes an issue with `next/script` types when `pkgJson.type === "module"`
35
+ const Script = script_js_1.default;
34
36
  // END: Mock typing of SiteImprove's event tracking API
35
37
  // --------------------------------------------------------------------------
36
38
  //
@@ -48,6 +50,36 @@ const _emitEvent = typeof window === 'undefined'
48
50
  console.info('SiteImprove:', event);
49
51
  }
50
52
  };
53
+ // ---------------------------------------------------------------------------
54
+ /**
55
+ * A small helper for tracking custom UI events and reporting them to SiteImrove.
56
+ *
57
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
58
+ */
59
+ const pingSiteImprove = (category, action, label) => {
60
+ if (process.env.NODE_ENV === 'development' &&
61
+ (!window._sz || window._sz._jit_defined_)) {
62
+ console.warn('`pingSiteImprove` was called before SiteImprove script was loaded.');
63
+ }
64
+ _emitEvent(['event', category, action, label]);
65
+ };
66
+ exports.pingSiteImprove = pingSiteImprove;
67
+ // ---------------------------------------------------------------------------
68
+ /**
69
+ * A small helper for reporting to SiteImrove when the user is programmatically
70
+ * being sent to a different URL/resource.
71
+ *
72
+ * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
73
+ */
74
+ const pingSiteImproveOutbound = (ourl) => {
75
+ if (process.env.NODE_ENV === 'development' &&
76
+ (!window._sz || window._sz._jit_defined_)) {
77
+ console.warn('`pingSiteImproveOutbound` was called before SiteImprove script was loaded.');
78
+ }
79
+ _emitEvent(['request', { ourl, ref: document.location.href }]);
80
+ };
81
+ exports.pingSiteImproveOutbound = pingSiteImproveOutbound;
82
+ // ---------------------------------------------------------------------------
51
83
  /*
52
84
  SiteImprove's "trackdynamic" (page view) event requires both the new URL
53
85
  and the old (referer) URL.
@@ -118,25 +150,26 @@ const SiteImprove = (props) => {
118
150
  const consented = (analytics && props.hasConstented !== false) ||
119
151
  (analytics === undefined && props.hasConstented);
120
152
  (0, react_1.useEffect)(() => {
121
- if (consented) {
122
- if (process.env.NODE_ENV !== 'production') {
123
- console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
124
- if (!window._sz) {
125
- setTimeout(() => {
126
- window._sz = window._sz || [];
127
- }, 300);
128
- }
153
+ if (!consented) {
154
+ return;
155
+ }
156
+ if (process.env.NODE_ENV !== 'production') {
157
+ console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
158
+ if (!window._sz) {
159
+ setTimeout(() => {
160
+ window._sz = window._sz || [];
161
+ }, 300);
129
162
  }
130
- const routerEvents = router_js_1.Router.events;
131
- routerEvents.on('routeChangeStart', captureRefUrl);
132
- routerEvents.on('routeChangeComplete', sendRoutingEvent);
133
- const stopLoggingOutboundLinks = logOutboundLinks();
134
- return () => {
135
- routerEvents.off('routeChangeStart', captureRefUrl);
136
- routerEvents.off('routeChangeComplete', sendRoutingEvent);
137
- stopLoggingOutboundLinks();
138
- };
139
163
  }
164
+ const routerEvents = router_js_1.Router.events;
165
+ routerEvents.on('routeChangeStart', captureRefUrl);
166
+ routerEvents.on('routeChangeComplete', sendRoutingEvent);
167
+ const stopLoggingOutboundLinks = logOutboundLinks();
168
+ return () => {
169
+ routerEvents.off('routeChangeStart', captureRefUrl);
170
+ routerEvents.off('routeChangeComplete', sendRoutingEvent);
171
+ stopLoggingOutboundLinks();
172
+ };
140
173
  },
141
174
  // eslint-disable-next-line react-hooks/exhaustive-deps
142
175
  [consented]);
@@ -146,35 +179,6 @@ const SiteImprove = (props) => {
146
179
  const scriptUrl = props.scriptUrl != null
147
180
  ? props.scriptUrl
148
181
  : scriptUrlTemplate.replace(idToken, props.accountId);
149
- return (react_1.default.createElement(script_js_1.default, { type: "text/javascript", strategy: "afterInteractive", src: scriptUrl, onLoad: props.onLoad, onError: props.onError }));
182
+ return (react_1.default.createElement(Script, { type: "text/javascript", strategy: "afterInteractive", src: scriptUrl, onLoad: props.onLoad, onError: props.onError }));
150
183
  };
151
184
  exports.SiteImprove = SiteImprove;
152
- // ---------------------------------------------------------------------------
153
- /**
154
- * A small helper for tracking custom UI events and reporting them to SiteImrove.
155
- *
156
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
157
- */
158
- const pingSiteImprove = (category, action, label) => {
159
- if (process.env.NODE_ENV === 'development' &&
160
- (!window._sz || window._sz._jit_defined_)) {
161
- console.warn('`pingSiteImprove` was called before SiteImprove script was loaded.');
162
- }
163
- _emitEvent(['event', category, action, label]);
164
- };
165
- exports.pingSiteImprove = pingSiteImprove;
166
- // ---------------------------------------------------------------------------
167
- /**
168
- * A small helper for reporting to SiteImrove when the user is programmatically
169
- * being sent to a different URL/resource.
170
- *
171
- * @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
172
- */
173
- const pingSiteImproveOutbound = (ourl) => {
174
- if (process.env.NODE_ENV === 'development' &&
175
- (!window._sz || window._sz._jit_defined_)) {
176
- console.warn('`pingSiteImproveOutbound` was called before SiteImprove script was loaded.');
177
- }
178
- _emitEvent(['request', { ourl, ref: document.location.href }]);
179
- };
180
- exports.pingSiteImproveOutbound = pingSiteImproveOutbound;
package/next/http.d.ts CHANGED
@@ -46,7 +46,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
46
46
  /**
47
47
  * Use this method to inside a `getServerSideProps` method (or API route)
48
48
  * to return an `HTTP_304_NotModified` response with an empty props object,
49
- * in a way that doesn't make TypeScript at you.
49
+ * in a way that doesn't make TypeScript shout at you.
50
50
  *
51
51
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1#notmodified304-helper
52
52
  */
package/next/http.js CHANGED
@@ -13,17 +13,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __rest = (this && this.__rest) || function (s, e) {
17
- var t = {};
18
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
- t[p] = s[p];
20
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
- t[p[i]] = s[p[i]];
24
- }
25
- return t;
26
- };
27
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
28
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
29
18
  };
@@ -47,12 +36,15 @@ const showErrorPage = (response, error, ttl = '2s') => {
47
36
  typeof error === 'number'
48
37
  ? { statusCode: error }
49
38
  : error;
50
- const { statusCode, message } = error, otherProps = __rest(error, ["statusCode", "message"]);
39
+ const { statusCode, message, ...otherProps } = error;
51
40
  response = 'res' in response ? response.res : response;
52
41
  response.statusCode = error.statusCode;
53
42
  (0, http_js_1.cacheControl)(response, ttl);
54
43
  return {
55
- props: Object.assign(Object.assign({}, otherProps), { __error: { statusCode, message } }),
44
+ props: {
45
+ ...otherProps,
46
+ __error: { statusCode, message },
47
+ },
56
48
  };
57
49
  };
58
50
  // ===========================================================================
@@ -69,13 +61,16 @@ const makeErrorizeAppHOC = (ErrorPage) => {
69
61
  const ErrorizedApp = (appProps) => {
70
62
  const { pageProps } = appProps;
71
63
  if (pageProps.__error) {
72
- const { __error } = pageProps, otherProps = __rest(pageProps, ["__error"]);
73
- return (react_1.default.createElement(App, Object.assign({}, appProps, { Component: ErrorPage, pageProps: Object.assign(Object.assign({}, otherProps), __error) })));
64
+ const { __error, ...otherProps } = pageProps;
65
+ return (react_1.default.createElement(App, { ...appProps, Component: ErrorPage, pageProps: {
66
+ ...otherProps,
67
+ ...__error,
68
+ } }));
74
69
  }
75
- return react_1.default.createElement(App, Object.assign({}, appProps));
70
+ return react_1.default.createElement(App, { ...appProps });
76
71
  };
77
72
  ErrorizedApp.getInitialProps = App.getInitialProps;
78
- ErrorizedApp.displayName = 'Errorized' + (App.displayName || App.name || 'App');
73
+ ErrorizedApp.displayName = `Errorized${App.displayName || App.name || 'App'}`;
79
74
  return ErrorizedApp;
80
75
  };
81
76
  withErrorHandling.showErrorPage = showErrorPage;
@@ -86,7 +81,7 @@ exports.makeErrorizeAppHOC = makeErrorizeAppHOC;
86
81
  /**
87
82
  * Use this method to inside a `getServerSideProps` method (or API route)
88
83
  * to return an `HTTP_304_NotModified` response with an empty props object,
89
- * in a way that doesn't make TypeScript at you.
84
+ * in a way that doesn't make TypeScript shout at you.
90
85
  *
91
86
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1#notmodified304-helper
92
87
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
5
5
  "main": "index.js",
6
6
  "repository": "ssh://git@github.com:reykjavikcity/webtools.git",
@@ -23,25 +23,25 @@
23
23
  },
24
24
  "sideEffects": false,
25
25
  "exports": {
26
- "./CookieHubConsent": {
27
- "import": "./esm/CookieHubConsent.js",
28
- "require": "./CookieHubConsent.js"
26
+ ".": {
27
+ "import": "./esm/index.js",
28
+ "require": "./index.js"
29
29
  },
30
30
  "./http": {
31
31
  "import": "./esm/http.js",
32
32
  "require": "./http.js"
33
33
  },
34
- ".": {
35
- "import": "./esm/index.js",
36
- "require": "./index.js"
37
- },
38
- "./next/http": {
39
- "import": "./esm/next/http.js",
40
- "require": "./next/http.js"
34
+ "./CookieHubConsent": {
35
+ "import": "./esm/CookieHubConsent.js",
36
+ "require": "./CookieHubConsent.js"
41
37
  },
42
38
  "./next/SiteImprove": {
43
39
  "import": "./esm/next/SiteImprove.js",
44
40
  "require": "./next/SiteImprove.js"
41
+ },
42
+ "./next/http": {
43
+ "import": "./esm/next/http.js",
44
+ "require": "./next/http.js"
45
45
  }
46
46
  }
47
47
  }