@reykjavik/webtools 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
- ## 0.1.0
7
+ ## 0.1.0 – 0.1.2
8
8
 
9
9
  _2023-03-24_
10
10
 
package/esm/http.d.ts CHANGED
@@ -44,12 +44,12 @@ export declare const HTTP_500_InternalServerError = 500;
44
44
  export type HTTP_SUCCESS = typeof HTTP_200_OK | typeof HTTP_201_Created | typeof HTTP_202_Accepted;
45
45
  export type HTTP_REDIRECTION = typeof HTTP_301_MovedPermanently | typeof HTTP_302_Found | typeof HTTP_303_SeeOther | typeof HTTP_304_NotModified | typeof HTTP_307_TemporaryRedirect | typeof HTTP_308_PermanentRedirect;
46
46
  export type HTTP_NOTMODIFIED = typeof HTTP_304_NotModified;
47
- export type HTTP_CLIENT_ERROR = typeof HTTP_400_BadRequest | typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden | typeof HTTP_404_NotFound | typeof HTTP_410_Gone | typeof HTTP_418_ImATeapot;
47
+ export type HTTP_CLIENT_ERROR = typeof HTTP_400_BadRequest | typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden | typeof HTTP_404_NotFound | typeof HTTP_410_Gone;
48
48
  export type HTTP_NOT_FOUND = typeof HTTP_400_BadRequest | typeof HTTP_404_NotFound | typeof HTTP_410_Gone;
49
49
  export type HTTP_BANNED = typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden;
50
50
  export type HTTP_SERVER_ERROR = typeof HTTP_500_InternalServerError;
51
51
  export type HTTP_ERROR = HTTP_CLIENT_ERROR | HTTP_SERVER_ERROR;
52
- export type HTTP_STATUS = HTTP_SUCCESS | HTTP_REDIRECTION | HTTP_CLIENT_ERROR | HTTP_SERVER_ERROR;
52
+ export type HTTP_STATUS = HTTP_SUCCESS | HTTP_REDIRECTION | HTTP_CLIENT_ERROR | typeof HTTP_418_ImATeapot | HTTP_SERVER_ERROR;
53
53
  type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w';
54
54
  type TTL = number | `${number}${TimeUnit}`;
55
55
  type TTLKeywords = 'permanent' | 'unset' | 'no-cache';
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { Router } from 'next/router';
3
3
  import Script from 'next/script';
4
- import { useCookieHubConsent } from '../CookieHubConsent';
4
+ import { useCookieHubConsent } from '../CookieHubConsent.js';
5
5
  // END: Mock typing of SiteImprove's event tracking API
6
6
  // --------------------------------------------------------------------------
7
7
  //
@@ -3,20 +3,20 @@ import React, { FunctionComponent } from 'react';
3
3
  import { Cleanup } from '@reykjavik/hanna-utils';
4
4
  import { ServerResponse } from 'http';
5
5
  import type { AppType } from 'next/app';
6
- import type { HTTP_ERROR, TTLConfig } from '../http';
7
- export * from '../http';
6
+ import type { HTTP_418_ImATeapot, HTTP_ERROR, TTLConfig } from '../http.js';
7
+ type HTTP_ERROR_all = HTTP_ERROR | typeof HTTP_418_ImATeapot;
8
+ export * from '../http.js';
8
9
  type NextContextLike = {
9
10
  res: ServerResponse;
10
11
  };
11
12
  export type ErrorProps = {
12
- statusCode: HTTP_ERROR;
13
- /** If a HTTP_ERROR code is passed, a default error message is displayed */
13
+ statusCode: HTTP_ERROR_all;
14
14
  message?: string;
15
15
  };
16
16
  type ErrorizedPageProps<EP extends ErrorProps = ErrorProps> = {
17
17
  __error: ErrorProps;
18
18
  } & Omit<EP, keyof ErrorProps>;
19
- type ShowErrorPageFn<EP extends ErrorProps = ErrorProps> = (response: ServerResponse | NextContextLike, error: (ErrorProps extends EP ? HTTP_ERROR : never) | EP,
19
+ type ShowErrorPageFn<EP extends ErrorProps = ErrorProps> = (response: ServerResponse | NextContextLike, error: (ErrorProps extends EP ? HTTP_ERROR_all : never) | EP,
20
20
  /** Defaults to `"2s"`. Gets forwarded on to the `cacheControl` helper from `@reykjavik/webtools/http` */
21
21
  ttl?: TTLConfig) => {
22
22
  props: ErrorizedPageProps<EP>;
@@ -33,10 +33,10 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
33
33
  <P extends {
34
34
  [key: string]: unknown;
35
35
  __error?: undefined;
36
- }>(App: AppType<P>): React.FunctionComponent<import("next/dist/shared/lib/utils").AppPropsType<any, P | ({
36
+ }>(App: AppType<P>): React.FunctionComponent<import("next/dist/shared/lib/utils.js").AppPropsType<any, P | ({
37
37
  __error: ErrorProps;
38
38
  } & Omit<ErrorProps & EP, keyof ErrorProps>)>> & {
39
- getInitialProps?(context: import("next/dist/shared/lib/utils").AppContextType<import("next/router").NextRouter>): P | ({
39
+ getInitialProps?(context: import("next/dist/shared/lib/utils.js").AppContextType<import("next/router.js").NextRouter>): P | ({
40
40
  __error: ErrorProps;
41
41
  } & Omit<ErrorProps & EP, keyof ErrorProps>) | Promise<P | ({
42
42
  __error: ErrorProps;
package/esm/next/http.js CHANGED
@@ -10,12 +10,12 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import React from 'react';
13
- import { cacheControl, HTTP_304_NotModified } from '../http';
13
+ import { cacheControl, HTTP_304_NotModified } from '../http.js';
14
14
  /*
15
15
  Re-export all of the base [http module](#reykjavikwebtoolshttp)'s exports,
16
16
  purely for convenience.
17
17
  */
18
- export * from '../http';
18
+ export * from '../http.js';
19
19
  /**
20
20
  * Use this method inside a `getServerSideProps` method (or API route)
21
21
  * to return an error page with proper HTTP status code and all the shit.
package/http.d.ts CHANGED
@@ -44,12 +44,12 @@ export declare const HTTP_500_InternalServerError = 500;
44
44
  export type HTTP_SUCCESS = typeof HTTP_200_OK | typeof HTTP_201_Created | typeof HTTP_202_Accepted;
45
45
  export type HTTP_REDIRECTION = typeof HTTP_301_MovedPermanently | typeof HTTP_302_Found | typeof HTTP_303_SeeOther | typeof HTTP_304_NotModified | typeof HTTP_307_TemporaryRedirect | typeof HTTP_308_PermanentRedirect;
46
46
  export type HTTP_NOTMODIFIED = typeof HTTP_304_NotModified;
47
- export type HTTP_CLIENT_ERROR = typeof HTTP_400_BadRequest | typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden | typeof HTTP_404_NotFound | typeof HTTP_410_Gone | typeof HTTP_418_ImATeapot;
47
+ export type HTTP_CLIENT_ERROR = typeof HTTP_400_BadRequest | typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden | typeof HTTP_404_NotFound | typeof HTTP_410_Gone;
48
48
  export type HTTP_NOT_FOUND = typeof HTTP_400_BadRequest | typeof HTTP_404_NotFound | typeof HTTP_410_Gone;
49
49
  export type HTTP_BANNED = typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden;
50
50
  export type HTTP_SERVER_ERROR = typeof HTTP_500_InternalServerError;
51
51
  export type HTTP_ERROR = HTTP_CLIENT_ERROR | HTTP_SERVER_ERROR;
52
- export type HTTP_STATUS = HTTP_SUCCESS | HTTP_REDIRECTION | HTTP_CLIENT_ERROR | HTTP_SERVER_ERROR;
52
+ export type HTTP_STATUS = HTTP_SUCCESS | HTTP_REDIRECTION | HTTP_CLIENT_ERROR | typeof HTTP_418_ImATeapot | HTTP_SERVER_ERROR;
53
53
  type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w';
54
54
  type TTL = number | `${number}${TimeUnit}`;
55
55
  type TTLKeywords = 'permanent' | 'unset' | 'no-cache';
@@ -30,7 +30,7 @@ exports.pingSiteImprove = exports.SiteImprove = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
31
  const router_1 = require("next/router");
32
32
  const script_1 = __importDefault(require("next/script"));
33
- const CookieHubConsent_1 = require("../CookieHubConsent");
33
+ const CookieHubConsent_js_1 = require("../CookieHubConsent.js");
34
34
  // END: Mock typing of SiteImprove's event tracking API
35
35
  // --------------------------------------------------------------------------
36
36
  //
@@ -83,7 +83,7 @@ const scriptUrlTemplate = `https://siteimproveanalytics.com/js/siteanalyze_${idT
83
83
  * @see https://github.com/reykjavikcity/webtools/tree/v0.1##siteimprove-component
84
84
  */
85
85
  const SiteImprove = (props) => {
86
- const { analytics } = (0, CookieHubConsent_1.useCookieHubConsent)();
86
+ const { analytics } = (0, CookieHubConsent_js_1.useCookieHubConsent)();
87
87
  const consented = (analytics && props.hasConstented !== false) ||
88
88
  (analytics === undefined && props.hasConstented);
89
89
  (0, react_1.useEffect)(() => {
package/next/http.d.ts CHANGED
@@ -3,20 +3,20 @@ import React, { FunctionComponent } from 'react';
3
3
  import { Cleanup } from '@reykjavik/hanna-utils';
4
4
  import { ServerResponse } from 'http';
5
5
  import type { AppType } from 'next/app';
6
- import type { HTTP_ERROR, TTLConfig } from '../http';
7
- export * from '../http';
6
+ import type { HTTP_418_ImATeapot, HTTP_ERROR, TTLConfig } from '../http.js';
7
+ type HTTP_ERROR_all = HTTP_ERROR | typeof HTTP_418_ImATeapot;
8
+ export * from '../http.js';
8
9
  type NextContextLike = {
9
10
  res: ServerResponse;
10
11
  };
11
12
  export type ErrorProps = {
12
- statusCode: HTTP_ERROR;
13
- /** If a HTTP_ERROR code is passed, a default error message is displayed */
13
+ statusCode: HTTP_ERROR_all;
14
14
  message?: string;
15
15
  };
16
16
  type ErrorizedPageProps<EP extends ErrorProps = ErrorProps> = {
17
17
  __error: ErrorProps;
18
18
  } & Omit<EP, keyof ErrorProps>;
19
- type ShowErrorPageFn<EP extends ErrorProps = ErrorProps> = (response: ServerResponse | NextContextLike, error: (ErrorProps extends EP ? HTTP_ERROR : never) | EP,
19
+ type ShowErrorPageFn<EP extends ErrorProps = ErrorProps> = (response: ServerResponse | NextContextLike, error: (ErrorProps extends EP ? HTTP_ERROR_all : never) | EP,
20
20
  /** Defaults to `"2s"`. Gets forwarded on to the `cacheControl` helper from `@reykjavik/webtools/http` */
21
21
  ttl?: TTLConfig) => {
22
22
  props: ErrorizedPageProps<EP>;
@@ -33,10 +33,10 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
33
33
  <P extends {
34
34
  [key: string]: unknown;
35
35
  __error?: undefined;
36
- }>(App: AppType<P>): React.FunctionComponent<import("next/dist/shared/lib/utils").AppPropsType<any, P | ({
36
+ }>(App: AppType<P>): React.FunctionComponent<import("next/dist/shared/lib/utils.js").AppPropsType<any, P | ({
37
37
  __error: ErrorProps;
38
38
  } & Omit<ErrorProps & EP, keyof ErrorProps>)>> & {
39
- getInitialProps?(context: import("next/dist/shared/lib/utils").AppContextType<import("next/router").NextRouter>): P | ({
39
+ getInitialProps?(context: import("next/dist/shared/lib/utils.js").AppContextType<import("next/router.js").NextRouter>): P | ({
40
40
  __error: ErrorProps;
41
41
  } & Omit<ErrorProps & EP, keyof ErrorProps>) | Promise<P | ({
42
42
  __error: ErrorProps;
package/next/http.js CHANGED
@@ -30,12 +30,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.notModified304 = exports.makeErrorizeAppHOC = void 0;
32
32
  const react_1 = __importDefault(require("react"));
33
- const http_1 = require("../http");
33
+ const http_js_1 = require("../http.js");
34
34
  /*
35
35
  Re-export all of the base [http module](#reykjavikwebtoolshttp)'s exports,
36
36
  purely for convenience.
37
37
  */
38
- __exportStar(require("../http"), exports);
38
+ __exportStar(require("../http.js"), exports);
39
39
  /**
40
40
  * Use this method inside a `getServerSideProps` method (or API route)
41
41
  * to return an error page with proper HTTP status code and all the shit.
@@ -50,7 +50,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
50
50
  const { statusCode, message } = error, otherProps = __rest(error, ["statusCode", "message"]);
51
51
  response = 'res' in response ? response.res : response;
52
52
  response.statusCode = error.statusCode;
53
- (0, http_1.cacheControl)(response, ttl);
53
+ (0, http_js_1.cacheControl)(response, ttl);
54
54
  return {
55
55
  props: Object.assign(Object.assign({}, otherProps), { __error: { statusCode, message } }),
56
56
  };
@@ -92,7 +92,7 @@ exports.makeErrorizeAppHOC = makeErrorizeAppHOC;
92
92
  */
93
93
  const notModified304 = (response) => {
94
94
  response = 'res' in response ? response.res : response;
95
- response.statusCode = http_1.HTTP_304_NotModified;
95
+ response.statusCode = http_js_1.HTTP_304_NotModified;
96
96
  return {
97
97
  props:
98
98
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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,9 +23,9 @@
23
23
  },
24
24
  "sideEffects": false,
25
25
  "exports": {
26
- "./CookieHubConsent.tsx": {
27
- "import": "./esm/CookieHubConsent.tsx.js",
28
- "require": "./CookieHubConsent.tsx.js"
26
+ "./CookieHubConsent": {
27
+ "import": "./esm/CookieHubConsent.js",
28
+ "require": "./CookieHubConsent.js"
29
29
  },
30
30
  "./http": {
31
31
  "import": "./esm/http.js",
@@ -35,13 +35,13 @@
35
35
  "import": "./esm/index.js",
36
36
  "require": "./index.js"
37
37
  },
38
- "./next/http.tsx": {
39
- "import": "./esm/next/http.tsx.js",
40
- "require": "./next/http.tsx.js"
38
+ "./next/http": {
39
+ "import": "./esm/next/http.js",
40
+ "require": "./next/http.js"
41
41
  },
42
- "./next/SiteImprove.tsx": {
43
- "import": "./esm/next/SiteImprove.tsx.js",
44
- "require": "./next/SiteImprove.tsx.js"
42
+ "./next/SiteImprove": {
43
+ "import": "./esm/next/SiteImprove.js",
44
+ "require": "./next/SiteImprove.js"
45
45
  }
46
46
  }
47
47
  }