@reykjavik/webtools 0.1.2 → 0.1.4

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
@@ -3,8 +3,9 @@
3
3
  ## Upcoming...
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
+ - feat: Relax the Next.js peerDependency version to include v11
6
7
 
7
- ## 0.1.0 – 0.1.2
8
+ ## 0.1.0 – 0.1.4
8
9
 
9
10
  _2023-03-24_
10
11
 
package/README.md CHANGED
@@ -41,13 +41,9 @@ Various framework agnostic helpers for leveraging HTTP magic.
41
41
 
42
42
  ### HTTP Status Codes
43
43
 
44
- The most common HTTP status codes are exported with human-readable names.
44
+ All the web-related HTTP status codes are exported with human-readable names:
45
45
 
46
46
  - `HTTP_200_OK`
47
- - `HTTP_201_Created`
48
- - `HTTP_202_Accepted`
49
- - `HTTP_301_MovedPermanently`
50
- - `HTTP_302_Found`
51
47
  - `HTTP_303_SeeOther`
52
48
  - `HTTP_304_NotModified`
53
49
  - `HTTP_307_TemporaryRedirect`
@@ -56,24 +52,38 @@ The most common HTTP status codes are exported with human-readable names.
56
52
  - `HTTP_401_Unauthorized`
57
53
  - `HTTP_403_Forbidden`
58
54
  - `HTTP_404_NotFound`
59
- - `HTTP_410_Gone`
60
55
  - `HTTP_418_ImATeapot`
61
56
  - `HTTP_500_InternalServerError`
57
+ - ...ad nauseum.
62
58
 
63
59
  ### Types for HTTP Status code groups
64
60
 
65
61
  These type unions are useful when writing HTTP helper functions and error
66
62
  handling, etc.
67
63
 
68
- - `HTTP_SUCCESS` (2xx)
69
- - `HTTP_REDIRECTION` (3xx)
70
- - `HTTP_NOTMODIFIED` (304)
71
- - `HTTP_CLIENT_ERROR` (4xx)
72
- - `HTTP_NOT_FOUND` (400, 404)
73
- - `HTTP_BANNED` (401, 403)
74
- - `HTTP_SERVER_ERROR` (5xx)
75
- - `HTTP_ERROR` (4xx, 5xx)
76
- - `HTTP_STATUS` (all of the above)
64
+ Union Types for the more commonly occurrring HTTP Status codes:
65
+
66
+ - `HTTP_STATUS` (all the status-codes!)
67
+ - `HTTP_INFO` (100, 101)
68
+ - `HTTP_SUCCESS` (200, 201, 202)
69
+ - `HTTP_REDIRECTION` (301, 302, 303, 304, 307, 308)
70
+ - `HTTP_NOTMODIFIED` (304)
71
+ - `HTTP_ERROR`
72
+ - `HTTP_CLIENT_ERROR`
73
+ - `HTTP_NOT_FOUND` (400, 404, 410)
74
+ - `HTTP_BANNED` (401, 403)
75
+ - `HTTP_SERVER_ERROR` (500)
76
+
77
+ More complete union types, including all the esoteric status codes, are also
78
+ available:
79
+
80
+ - `HTTP_STATUS` (all the status-codes!)
81
+ - `HTTP_INFO_ALL` (1\*\*)
82
+ - `HTTP_SUCCESS_ALL` (2\*\*)
83
+ - `HTTP_REDIRECTION_ALL` (3\*\*)
84
+ - `HTTP_ERROR_ALL`
85
+ - `HTTP_CLIENT_ERROR_ALL` (4\*\*)
86
+ - `HTTP_SERVER_ERROR_ALL` (4\*\*)
77
87
 
78
88
  ### `cacheControl` helper
79
89
 
package/esm/http.d.ts CHANGED
@@ -1,12 +1,19 @@
1
1
  import { ServerResponse } from 'http';
2
+ /** The client should continue the request or ignore the response if the request is already finished. */
3
+ export declare const HTTP_100_Continue = 100;
4
+ /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
5
+ export declare const HTTP_101_SwitchingProtocols = 101;
6
+ /** The request succeeded, and the response body contains the requested resource. */
2
7
  export declare const HTTP_200_OK = 200;
3
- /**
4
- * The request succeeded, and a new resource was created as a result.
5
- * This is typically the response sent after POST requests,
6
- * or some PUT requests.
7
- **/
8
+ /** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
8
9
  export declare const HTTP_201_Created = 201;
9
10
  export declare const HTTP_202_Accepted = 202;
11
+ /** The returned metadata is not necessarily complete. */
12
+ export declare const HTTP_203_NonAuthoritativeInformation = 203;
13
+ /** The response body is empty. */
14
+ export declare const HTTP_204_NoContent = 204;
15
+ /** The request succeeded, but the returned metadata is not necessarily complete. */
16
+ export declare const HTTP_206_PartialContent = 206;
10
17
  /**
11
18
  * Only safe to use in response to GET and HEAD requests
12
19
  *
@@ -25,31 +32,88 @@ export declare const HTTP_303_SeeOther = 303;
25
32
  export declare const HTTP_304_NotModified = 304;
26
33
  export declare const HTTP_307_TemporaryRedirect = 307;
27
34
  export declare const HTTP_308_PermanentRedirect = 308;
28
- /** The request is malformed (e.g. a URL param is of a wrong type) */
35
+ /** The request is malformed (e.g. a URL param is of a wrong type). */
29
36
  export declare const HTTP_400_BadRequest = 400;
30
- /** User is not authenticated (i.e. not logged in) */
37
+ /** User is not authenticated (i.e. not logged in). */
31
38
  export declare const HTTP_401_Unauthorized = 401;
32
- /** User is logged in but doesn't have the necessary privileges */
39
+ /** User is logged in but doesn't have the necessary privileges. */
33
40
  export declare const HTTP_403_Forbidden = 403;
34
- /** The request looks OK but the resource does not exist */
41
+ /** The request looks OK but the resource does not exist. */
35
42
  export declare const HTTP_404_NotFound = 404;
36
- /**
37
- * The resource has been permanently deleted from server, with no forwarding
38
- * address.
39
- */
43
+ /** The request method is not supported by the target resource. */
44
+ export declare const HTTP_405_MethodNotAllowed = 405;
45
+ /** The server can't produce a response matching the list of acceptable types. */
46
+ export declare const HTTP_406_NotAcceptable = 406;
47
+ /** Similar to `HTTP_401_Unauthorized` but authentication is needed to be done by a proxy. */
48
+ export declare const HTTP_407_ProxyAuthenticationRequired = 407;
49
+ /** The server timed out waiting for the request. */
50
+ export declare const HTTP_408_RequestTimeout = 408;
51
+ /** The request conflicts with the current state of the server. */
52
+ export declare const HTTP_409_Conflict = 409;
53
+ /** The resource has been permanently deleted from server, with no forwarding address. */
40
54
  export declare const HTTP_410_Gone = 410;
55
+ /** The request's Content-Length header field is not defined and the server requires it. */
56
+ export declare const HTTP_411_LengthRequired = 411;
57
+ /** The client has indicated preconditions in its headers which the server does not meet. */
58
+ export declare const HTTP_412_PreconditionFailed = 412;
59
+ /** The request is larger than the server is willing or able to process. */
60
+ export declare const HTTP_413_PayloadTooLarge = 413;
61
+ /** The URI requested by the client is longer than the server is willing to interpret. */
62
+ export declare const HTTP_414_URITooLong = 414;
63
+ /** The media format of the requested data is not supported by the server */
64
+ export declare const HTTP_415_UnsupportedMediaType = 415;
65
+ /** The Range header field in the request cannot be fulfilled. It's possible that the range is outside the size of the target URI's data. */
66
+ export declare const HTTP_416_RangeNotSatisfiable = 416;
67
+ /** The expectation indicated by the Expect request header field cannot be met by the server. */
68
+ export declare const HTTP_417_ExpectationFailed = 417;
41
69
  /** The server refuses the attempt to brew coffee with a teapot. */
42
70
  export declare const HTTP_418_ImATeapot = 418;
71
+ /** The request was directed at a server that is not able to produce a response. */
72
+ export declare const HTTP_421_MisdirectedRequest = 421;
73
+ /** 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
+ export declare const HTTP_426_UpgradeRequired = 426;
75
+ /** The origin server requires the request to be conditional. */
76
+ export declare const HTTP_428_PreconditionRequired = 428;
77
+ /** Received too many requests in a given amount of time ("rate limiting"). */
78
+ export declare const HTTP_429_TooManyRequests = 429;
79
+ /** The server is unwilling to process the request because its header fields are too large. */
80
+ export declare const HTTP_431_RequestHeaderFieldsTooLarge = 431;
81
+ /** The resource cannot legally be provided, such as a web page censored by a government. */
82
+ export declare const HTTP_451_UnavailableForLegalReasons = 451;
83
+ /** The server has encountered a situation it does not know how to handle. */
43
84
  export declare const HTTP_500_InternalServerError = 500;
85
+ /** The request method type is not supported by the server and cannot be handled. */
86
+ export declare const HTTP_501_NotImplemented = 501;
87
+ /** The server, while working as a gateway to get a response needed to handle the request, got an invalid response. */
88
+ export declare const HTTP_502_BadGateway = 502;
89
+ /** The server is not ready to handle the request. (Commonly: down for maintenance or overloaded.) */
90
+ export declare const HTTP_503_ServiceUnavailable = 503;
91
+ /** The server is acting as a gateway and cannot get a response in time. */
92
+ export declare const HTTP_504_GatewayTimeout = 504;
93
+ /** The HTTP version used in the request is not supported by the server. */
94
+ export declare const HTTP_505_HTTPVersionNotSupported = 505;
95
+ /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
96
+ export declare const HTTP_506_VariantAlsoNegotiates = 506;
97
+ /** Further extensions to the request are required for the server to fulfill it. */
98
+ export declare const HTTP_510_NotExtended = 510;
99
+ /** The client needs to authenticate to gain network access. */
100
+ export declare const HTTP_511_NetworkAuthenticationRequired = 511;
101
+ export type HTTP_INFO = typeof HTTP_100_Continue | typeof HTTP_101_SwitchingProtocols;
44
102
  export type HTTP_SUCCESS = typeof HTTP_200_OK | typeof HTTP_201_Created | typeof HTTP_202_Accepted;
45
103
  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
104
  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;
48
105
  export type HTTP_NOT_FOUND = typeof HTTP_400_BadRequest | typeof HTTP_404_NotFound | typeof HTTP_410_Gone;
49
106
  export type HTTP_BANNED = typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden;
107
+ export type HTTP_CLIENT_ERROR = HTTP_NOT_FOUND | HTTP_BANNED;
50
108
  export type HTTP_SERVER_ERROR = typeof HTTP_500_InternalServerError;
51
109
  export type HTTP_ERROR = 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;
110
+ 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;
113
+ 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;
116
+ export type HTTP_ERROR_ALL = HTTP_CLIENT_ERROR_ALL | HTTP_SERVER_ERROR_ALL;
53
117
  type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w';
54
118
  type TTL = number | `${number}${TimeUnit}`;
55
119
  type TTLKeywords = 'permanent' | 'unset' | 'no-cache';
package/esm/http.js CHANGED
@@ -1,15 +1,22 @@
1
+ // INFORMATION
2
+ /** The client should continue the request or ignore the response if the request is already finished. */
3
+ export const HTTP_100_Continue = 100;
4
+ /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
5
+ export const HTTP_101_SwitchingProtocols = 101;
6
+ // SUCCESS
7
+ /** The request succeeded, and the response body contains the requested resource. */
1
8
  export const HTTP_200_OK = 200;
2
- /**
3
- * The request succeeded, and a new resource was created as a result.
4
- * This is typically the response sent after POST requests,
5
- * or some PUT requests.
6
- **/
9
+ /** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
7
10
  export const HTTP_201_Created = 201;
8
- /*
9
- * The request has been received but not yet acted upon.
10
- * Uee in cases where another process or server handles the request.
11
- */
11
+ /* The request has been received but not yet acted upon. Another process or server handles the request. */
12
12
  export const HTTP_202_Accepted = 202;
13
+ /** The returned metadata is not necessarily complete. */
14
+ export const HTTP_203_NonAuthoritativeInformation = 203;
15
+ /** The response body is empty. */
16
+ export const HTTP_204_NoContent = 204;
17
+ /** The request succeeded, but the returned metadata is not necessarily complete. */
18
+ export const HTTP_206_PartialContent = 206;
19
+ // REDIRECTION
13
20
  /**
14
21
  * Only safe to use in response to GET and HEAD requests
15
22
  *
@@ -28,22 +35,74 @@ export const HTTP_303_SeeOther = 303;
28
35
  export const HTTP_304_NotModified = 304;
29
36
  export const HTTP_307_TemporaryRedirect = 307;
30
37
  export const HTTP_308_PermanentRedirect = 308;
31
- /** The request is malformed (e.g. a URL param is of a wrong type) */
38
+ // CLIENT ERROR
39
+ /** The request is malformed (e.g. a URL param is of a wrong type). */
32
40
  export const HTTP_400_BadRequest = 400;
33
- /** User is not authenticated (i.e. not logged in) */
41
+ /** User is not authenticated (i.e. not logged in). */
34
42
  export const HTTP_401_Unauthorized = 401;
35
- /** User is logged in but doesn't have the necessary privileges */
43
+ /** User is logged in but doesn't have the necessary privileges. */
36
44
  export const HTTP_403_Forbidden = 403;
37
- /** The request looks OK but the resource does not exist */
45
+ /** The request looks OK but the resource does not exist. */
38
46
  export const HTTP_404_NotFound = 404;
39
- /**
40
- * The resource has been permanently deleted from server, with no forwarding
41
- * address.
42
- */
47
+ /** The request method is not supported by the target resource. */
48
+ export const HTTP_405_MethodNotAllowed = 405;
49
+ /** The server can't produce a response matching the list of acceptable types. */
50
+ export const HTTP_406_NotAcceptable = 406;
51
+ /** Similar to `HTTP_401_Unauthorized` but authentication is needed to be done by a proxy. */
52
+ export const HTTP_407_ProxyAuthenticationRequired = 407;
53
+ /** The server timed out waiting for the request. */
54
+ export const HTTP_408_RequestTimeout = 408;
55
+ /** The request conflicts with the current state of the server. */
56
+ export const HTTP_409_Conflict = 409;
57
+ /** The resource has been permanently deleted from server, with no forwarding address. */
43
58
  export const HTTP_410_Gone = 410;
59
+ /** The request's Content-Length header field is not defined and the server requires it. */
60
+ export const HTTP_411_LengthRequired = 411;
61
+ /** The client has indicated preconditions in its headers which the server does not meet. */
62
+ export const HTTP_412_PreconditionFailed = 412;
63
+ /** The request is larger than the server is willing or able to process. */
64
+ export const HTTP_413_PayloadTooLarge = 413;
65
+ /** The URI requested by the client is longer than the server is willing to interpret. */
66
+ export const HTTP_414_URITooLong = 414;
67
+ /** The media format of the requested data is not supported by the server */
68
+ export const HTTP_415_UnsupportedMediaType = 415;
69
+ /** The Range header field in the request cannot be fulfilled. It's possible that the range is outside the size of the target URI's data. */
70
+ export const HTTP_416_RangeNotSatisfiable = 416;
71
+ /** The expectation indicated by the Expect request header field cannot be met by the server. */
72
+ export const HTTP_417_ExpectationFailed = 417;
44
73
  /** The server refuses the attempt to brew coffee with a teapot. */
45
74
  export const HTTP_418_ImATeapot = 418;
75
+ /** The request was directed at a server that is not able to produce a response. */
76
+ export const HTTP_421_MisdirectedRequest = 421;
77
+ /** 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
+ export const HTTP_426_UpgradeRequired = 426;
79
+ /** The origin server requires the request to be conditional. */
80
+ export const HTTP_428_PreconditionRequired = 428;
81
+ /** Received too many requests in a given amount of time ("rate limiting"). */
82
+ export const HTTP_429_TooManyRequests = 429;
83
+ /** The server is unwilling to process the request because its header fields are too large. */
84
+ export const HTTP_431_RequestHeaderFieldsTooLarge = 431;
85
+ /** The resource cannot legally be provided, such as a web page censored by a government. */
86
+ export const HTTP_451_UnavailableForLegalReasons = 451;
87
+ // SERVER ERROR
88
+ /** The server has encountered a situation it does not know how to handle. */
46
89
  export const HTTP_500_InternalServerError = 500;
90
+ /** The request method type is not supported by the server and cannot be handled. */
91
+ export const HTTP_501_NotImplemented = 501;
92
+ /** The server, while working as a gateway to get a response needed to handle the request, got an invalid response. */
93
+ export const HTTP_502_BadGateway = 502;
94
+ /** The server is not ready to handle the request. (Commonly: down for maintenance or overloaded.) */
95
+ export const HTTP_503_ServiceUnavailable = 503;
96
+ /** The server is acting as a gateway and cannot get a response in time. */
97
+ export const HTTP_504_GatewayTimeout = 504;
98
+ /** The HTTP version used in the request is not supported by the server. */
99
+ export const HTTP_505_HTTPVersionNotSupported = 505;
100
+ /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
101
+ export const HTTP_506_VariantAlsoNegotiates = 506;
102
+ /** Further extensions to the request are required for the server to fulfill it. */
103
+ export const HTTP_510_NotExtended = 510;
104
+ /** The client needs to authenticate to gain network access. */
105
+ export const HTTP_511_NetworkAuthenticationRequired = 511;
47
106
  const unitToSeconds = {
48
107
  s: 1,
49
108
  m: 60,
package/http.d.ts CHANGED
@@ -1,12 +1,19 @@
1
1
  import { ServerResponse } from 'http';
2
+ /** The client should continue the request or ignore the response if the request is already finished. */
3
+ export declare const HTTP_100_Continue = 100;
4
+ /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
5
+ export declare const HTTP_101_SwitchingProtocols = 101;
6
+ /** The request succeeded, and the response body contains the requested resource. */
2
7
  export declare const HTTP_200_OK = 200;
3
- /**
4
- * The request succeeded, and a new resource was created as a result.
5
- * This is typically the response sent after POST requests,
6
- * or some PUT requests.
7
- **/
8
+ /** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
8
9
  export declare const HTTP_201_Created = 201;
9
10
  export declare const HTTP_202_Accepted = 202;
11
+ /** The returned metadata is not necessarily complete. */
12
+ export declare const HTTP_203_NonAuthoritativeInformation = 203;
13
+ /** The response body is empty. */
14
+ export declare const HTTP_204_NoContent = 204;
15
+ /** The request succeeded, but the returned metadata is not necessarily complete. */
16
+ export declare const HTTP_206_PartialContent = 206;
10
17
  /**
11
18
  * Only safe to use in response to GET and HEAD requests
12
19
  *
@@ -25,31 +32,88 @@ export declare const HTTP_303_SeeOther = 303;
25
32
  export declare const HTTP_304_NotModified = 304;
26
33
  export declare const HTTP_307_TemporaryRedirect = 307;
27
34
  export declare const HTTP_308_PermanentRedirect = 308;
28
- /** The request is malformed (e.g. a URL param is of a wrong type) */
35
+ /** The request is malformed (e.g. a URL param is of a wrong type). */
29
36
  export declare const HTTP_400_BadRequest = 400;
30
- /** User is not authenticated (i.e. not logged in) */
37
+ /** User is not authenticated (i.e. not logged in). */
31
38
  export declare const HTTP_401_Unauthorized = 401;
32
- /** User is logged in but doesn't have the necessary privileges */
39
+ /** User is logged in but doesn't have the necessary privileges. */
33
40
  export declare const HTTP_403_Forbidden = 403;
34
- /** The request looks OK but the resource does not exist */
41
+ /** The request looks OK but the resource does not exist. */
35
42
  export declare const HTTP_404_NotFound = 404;
36
- /**
37
- * The resource has been permanently deleted from server, with no forwarding
38
- * address.
39
- */
43
+ /** The request method is not supported by the target resource. */
44
+ export declare const HTTP_405_MethodNotAllowed = 405;
45
+ /** The server can't produce a response matching the list of acceptable types. */
46
+ export declare const HTTP_406_NotAcceptable = 406;
47
+ /** Similar to `HTTP_401_Unauthorized` but authentication is needed to be done by a proxy. */
48
+ export declare const HTTP_407_ProxyAuthenticationRequired = 407;
49
+ /** The server timed out waiting for the request. */
50
+ export declare const HTTP_408_RequestTimeout = 408;
51
+ /** The request conflicts with the current state of the server. */
52
+ export declare const HTTP_409_Conflict = 409;
53
+ /** The resource has been permanently deleted from server, with no forwarding address. */
40
54
  export declare const HTTP_410_Gone = 410;
55
+ /** The request's Content-Length header field is not defined and the server requires it. */
56
+ export declare const HTTP_411_LengthRequired = 411;
57
+ /** The client has indicated preconditions in its headers which the server does not meet. */
58
+ export declare const HTTP_412_PreconditionFailed = 412;
59
+ /** The request is larger than the server is willing or able to process. */
60
+ export declare const HTTP_413_PayloadTooLarge = 413;
61
+ /** The URI requested by the client is longer than the server is willing to interpret. */
62
+ export declare const HTTP_414_URITooLong = 414;
63
+ /** The media format of the requested data is not supported by the server */
64
+ export declare const HTTP_415_UnsupportedMediaType = 415;
65
+ /** The Range header field in the request cannot be fulfilled. It's possible that the range is outside the size of the target URI's data. */
66
+ export declare const HTTP_416_RangeNotSatisfiable = 416;
67
+ /** The expectation indicated by the Expect request header field cannot be met by the server. */
68
+ export declare const HTTP_417_ExpectationFailed = 417;
41
69
  /** The server refuses the attempt to brew coffee with a teapot. */
42
70
  export declare const HTTP_418_ImATeapot = 418;
71
+ /** The request was directed at a server that is not able to produce a response. */
72
+ export declare const HTTP_421_MisdirectedRequest = 421;
73
+ /** 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
+ export declare const HTTP_426_UpgradeRequired = 426;
75
+ /** The origin server requires the request to be conditional. */
76
+ export declare const HTTP_428_PreconditionRequired = 428;
77
+ /** Received too many requests in a given amount of time ("rate limiting"). */
78
+ export declare const HTTP_429_TooManyRequests = 429;
79
+ /** The server is unwilling to process the request because its header fields are too large. */
80
+ export declare const HTTP_431_RequestHeaderFieldsTooLarge = 431;
81
+ /** The resource cannot legally be provided, such as a web page censored by a government. */
82
+ export declare const HTTP_451_UnavailableForLegalReasons = 451;
83
+ /** The server has encountered a situation it does not know how to handle. */
43
84
  export declare const HTTP_500_InternalServerError = 500;
85
+ /** The request method type is not supported by the server and cannot be handled. */
86
+ export declare const HTTP_501_NotImplemented = 501;
87
+ /** The server, while working as a gateway to get a response needed to handle the request, got an invalid response. */
88
+ export declare const HTTP_502_BadGateway = 502;
89
+ /** The server is not ready to handle the request. (Commonly: down for maintenance or overloaded.) */
90
+ export declare const HTTP_503_ServiceUnavailable = 503;
91
+ /** The server is acting as a gateway and cannot get a response in time. */
92
+ export declare const HTTP_504_GatewayTimeout = 504;
93
+ /** The HTTP version used in the request is not supported by the server. */
94
+ export declare const HTTP_505_HTTPVersionNotSupported = 505;
95
+ /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
96
+ export declare const HTTP_506_VariantAlsoNegotiates = 506;
97
+ /** Further extensions to the request are required for the server to fulfill it. */
98
+ export declare const HTTP_510_NotExtended = 510;
99
+ /** The client needs to authenticate to gain network access. */
100
+ export declare const HTTP_511_NetworkAuthenticationRequired = 511;
101
+ export type HTTP_INFO = typeof HTTP_100_Continue | typeof HTTP_101_SwitchingProtocols;
44
102
  export type HTTP_SUCCESS = typeof HTTP_200_OK | typeof HTTP_201_Created | typeof HTTP_202_Accepted;
45
103
  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
104
  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;
48
105
  export type HTTP_NOT_FOUND = typeof HTTP_400_BadRequest | typeof HTTP_404_NotFound | typeof HTTP_410_Gone;
49
106
  export type HTTP_BANNED = typeof HTTP_401_Unauthorized | typeof HTTP_403_Forbidden;
107
+ export type HTTP_CLIENT_ERROR = HTTP_NOT_FOUND | HTTP_BANNED;
50
108
  export type HTTP_SERVER_ERROR = typeof HTTP_500_InternalServerError;
51
109
  export type HTTP_ERROR = 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;
110
+ 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;
113
+ 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;
116
+ export type HTTP_ERROR_ALL = HTTP_CLIENT_ERROR_ALL | HTTP_SERVER_ERROR_ALL;
53
117
  type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w';
54
118
  type TTL = number | `${number}${TimeUnit}`;
55
119
  type TTLKeywords = 'permanent' | 'unset' | 'no-cache';
package/http.js CHANGED
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cacheControl = exports.HTTP_500_InternalServerError = exports.HTTP_418_ImATeapot = exports.HTTP_410_Gone = 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_202_Accepted = exports.HTTP_201_Created = exports.HTTP_200_OK = void 0;
3
+ exports.cacheControl = 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;
4
+ // INFORMATION
5
+ /** The client should continue the request or ignore the response if the request is already finished. */
6
+ exports.HTTP_100_Continue = 100;
7
+ /** Response to an Upgrade request header from the client and indicates the protocol the server is switching to. */
8
+ exports.HTTP_101_SwitchingProtocols = 101;
9
+ // SUCCESS
10
+ /** The request succeeded, and the response body contains the requested resource. */
4
11
  exports.HTTP_200_OK = 200;
5
- /**
6
- * The request succeeded, and a new resource was created as a result.
7
- * This is typically the response sent after POST requests,
8
- * or some PUT requests.
9
- **/
12
+ /** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
10
13
  exports.HTTP_201_Created = 201;
11
- /*
12
- * The request has been received but not yet acted upon.
13
- * Uee in cases where another process or server handles the request.
14
- */
14
+ /* The request has been received but not yet acted upon. Another process or server handles the request. */
15
15
  exports.HTTP_202_Accepted = 202;
16
+ /** The returned metadata is not necessarily complete. */
17
+ exports.HTTP_203_NonAuthoritativeInformation = 203;
18
+ /** The response body is empty. */
19
+ exports.HTTP_204_NoContent = 204;
20
+ /** The request succeeded, but the returned metadata is not necessarily complete. */
21
+ exports.HTTP_206_PartialContent = 206;
22
+ // REDIRECTION
16
23
  /**
17
24
  * Only safe to use in response to GET and HEAD requests
18
25
  *
@@ -31,22 +38,74 @@ exports.HTTP_303_SeeOther = 303;
31
38
  exports.HTTP_304_NotModified = 304;
32
39
  exports.HTTP_307_TemporaryRedirect = 307;
33
40
  exports.HTTP_308_PermanentRedirect = 308;
34
- /** The request is malformed (e.g. a URL param is of a wrong type) */
41
+ // CLIENT ERROR
42
+ /** The request is malformed (e.g. a URL param is of a wrong type). */
35
43
  exports.HTTP_400_BadRequest = 400;
36
- /** User is not authenticated (i.e. not logged in) */
44
+ /** User is not authenticated (i.e. not logged in). */
37
45
  exports.HTTP_401_Unauthorized = 401;
38
- /** User is logged in but doesn't have the necessary privileges */
46
+ /** User is logged in but doesn't have the necessary privileges. */
39
47
  exports.HTTP_403_Forbidden = 403;
40
- /** The request looks OK but the resource does not exist */
48
+ /** The request looks OK but the resource does not exist. */
41
49
  exports.HTTP_404_NotFound = 404;
42
- /**
43
- * The resource has been permanently deleted from server, with no forwarding
44
- * address.
45
- */
50
+ /** The request method is not supported by the target resource. */
51
+ exports.HTTP_405_MethodNotAllowed = 405;
52
+ /** The server can't produce a response matching the list of acceptable types. */
53
+ exports.HTTP_406_NotAcceptable = 406;
54
+ /** Similar to `HTTP_401_Unauthorized` but authentication is needed to be done by a proxy. */
55
+ exports.HTTP_407_ProxyAuthenticationRequired = 407;
56
+ /** The server timed out waiting for the request. */
57
+ exports.HTTP_408_RequestTimeout = 408;
58
+ /** The request conflicts with the current state of the server. */
59
+ exports.HTTP_409_Conflict = 409;
60
+ /** The resource has been permanently deleted from server, with no forwarding address. */
46
61
  exports.HTTP_410_Gone = 410;
62
+ /** The request's Content-Length header field is not defined and the server requires it. */
63
+ exports.HTTP_411_LengthRequired = 411;
64
+ /** The client has indicated preconditions in its headers which the server does not meet. */
65
+ exports.HTTP_412_PreconditionFailed = 412;
66
+ /** The request is larger than the server is willing or able to process. */
67
+ exports.HTTP_413_PayloadTooLarge = 413;
68
+ /** The URI requested by the client is longer than the server is willing to interpret. */
69
+ exports.HTTP_414_URITooLong = 414;
70
+ /** The media format of the requested data is not supported by the server */
71
+ exports.HTTP_415_UnsupportedMediaType = 415;
72
+ /** The Range header field in the request cannot be fulfilled. It's possible that the range is outside the size of the target URI's data. */
73
+ exports.HTTP_416_RangeNotSatisfiable = 416;
74
+ /** The expectation indicated by the Expect request header field cannot be met by the server. */
75
+ exports.HTTP_417_ExpectationFailed = 417;
47
76
  /** The server refuses the attempt to brew coffee with a teapot. */
48
77
  exports.HTTP_418_ImATeapot = 418;
78
+ /** The request was directed at a server that is not able to produce a response. */
79
+ exports.HTTP_421_MisdirectedRequest = 421;
80
+ /** 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
+ exports.HTTP_426_UpgradeRequired = 426;
82
+ /** The origin server requires the request to be conditional. */
83
+ exports.HTTP_428_PreconditionRequired = 428;
84
+ /** Received too many requests in a given amount of time ("rate limiting"). */
85
+ exports.HTTP_429_TooManyRequests = 429;
86
+ /** The server is unwilling to process the request because its header fields are too large. */
87
+ exports.HTTP_431_RequestHeaderFieldsTooLarge = 431;
88
+ /** The resource cannot legally be provided, such as a web page censored by a government. */
89
+ exports.HTTP_451_UnavailableForLegalReasons = 451;
90
+ // SERVER ERROR
91
+ /** The server has encountered a situation it does not know how to handle. */
49
92
  exports.HTTP_500_InternalServerError = 500;
93
+ /** The request method type is not supported by the server and cannot be handled. */
94
+ exports.HTTP_501_NotImplemented = 501;
95
+ /** The server, while working as a gateway to get a response needed to handle the request, got an invalid response. */
96
+ exports.HTTP_502_BadGateway = 502;
97
+ /** The server is not ready to handle the request. (Commonly: down for maintenance or overloaded.) */
98
+ exports.HTTP_503_ServiceUnavailable = 503;
99
+ /** The server is acting as a gateway and cannot get a response in time. */
100
+ exports.HTTP_504_GatewayTimeout = 504;
101
+ /** The HTTP version used in the request is not supported by the server. */
102
+ exports.HTTP_505_HTTPVersionNotSupported = 505;
103
+ /** The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself. */
104
+ exports.HTTP_506_VariantAlsoNegotiates = 506;
105
+ /** Further extensions to the request are required for the server to fulfill it. */
106
+ exports.HTTP_510_NotExtended = 510;
107
+ /** The client needs to authenticate to gain network access. */
108
+ exports.HTTP_511_NetworkAuthenticationRequired = 511;
50
109
  const unitToSeconds = {
51
110
  s: 1,
52
111
  m: 60,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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",
@@ -14,7 +14,7 @@
14
14
  "@reykjavik/hanna-utils": "^0.2.3"
15
15
  },
16
16
  "peerDependencies": {
17
- "next": ">12",
17
+ "next": ">11",
18
18
  "react": ">16.8.0",
19
19
  "react-dom": ">16.8.0"
20
20
  },