@smartlyio/oats-runtime 4.3.1 → 4.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/redirect.d.ts +6 -0
- package/dist/redirect.js +8 -1
- package/dist/redirect.js.map +1 -1
- package/package.json +4 -2
- package/src/redirect.ts +8 -1
package/dist/redirect.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ declare type DefaultValue<ContentType extends string> = ContentType extends type
|
|
|
14
14
|
* But it will pass if type inference is not prevented.
|
|
15
15
|
*/
|
|
16
16
|
declare type PreventGenericDefaultValueOverride<T> = [T][T extends unknown ? 0 : never];
|
|
17
|
+
/**
|
|
18
|
+
* Use to perform HTTP redirect.
|
|
19
|
+
* @param url an absolute or relative URL string. Will be encoded with `encodeurl` and set as "Location" header (@see https://github.com/pillarjs/encodeurl).
|
|
20
|
+
* @param options optional `status`, `contentType`, `value` that will override the default ones. Default `status` is 302, `contentType` is "text/html".
|
|
21
|
+
* @returns redirect server response.
|
|
22
|
+
*/
|
|
17
23
|
export declare function redirect<Status extends RedirectStatus = typeof DEFAULT_REDIRECT_STATUS, ContentType extends string = typeof TEXT_HTML_CONTENT_TYPE, Value = DefaultValue<ContentType>>(url: string, options?: {
|
|
18
24
|
status?: Status;
|
|
19
25
|
contentType?: ContentType;
|
package/dist/redirect.js
CHANGED
|
@@ -2,13 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.redirect = void 0;
|
|
4
4
|
const escapeHtml = require("escape-html");
|
|
5
|
+
const encodeUrl = require("encodeurl");
|
|
5
6
|
const REDIRECT_STATUSES = [300, 301, 302, 303, 305, 307, 308];
|
|
6
7
|
const DEFAULT_REDIRECT_STATUS = 302;
|
|
7
8
|
const TEXT_HTML_CONTENT_TYPE = 'text/html';
|
|
8
9
|
const TEXT_PLAIN_CONTENT_TYPE = 'text/plain';
|
|
10
|
+
/**
|
|
11
|
+
* Use to perform HTTP redirect.
|
|
12
|
+
* @param url an absolute or relative URL string. Will be encoded with `encodeurl` and set as "Location" header (@see https://github.com/pillarjs/encodeurl).
|
|
13
|
+
* @param options optional `status`, `contentType`, `value` that will override the default ones. Default `status` is 302, `contentType` is "text/html".
|
|
14
|
+
* @returns redirect server response.
|
|
15
|
+
*/
|
|
9
16
|
function redirect(url, options = {}) {
|
|
10
17
|
const { status = DEFAULT_REDIRECT_STATUS } = options;
|
|
11
|
-
const encodedUrl =
|
|
18
|
+
const encodedUrl = encodeUrl(url);
|
|
12
19
|
if (!REDIRECT_STATUSES.includes(status)) {
|
|
13
20
|
throw new Error(`Status "${status}" is not a redirect status.`);
|
|
14
21
|
}
|
package/dist/redirect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":";;;AACA,0CAA2C;
|
|
1
|
+
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":";;;AACA,0CAA2C;AAC3C,uCAAwC;AAExC,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AACvE,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,sBAAsB,GAAG,WAAW,CAAC;AAC3C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAsB7C;;;;;GAKG;AACH,SAAgB,QAAQ,CAKtB,GAAW,EACX,UAII,EAAE;IAON,MAAM,EAAE,MAAM,GAAG,uBAAiC,EAAE,GAAG,OAAO,CAAC;IAC/D,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,6BAA6B,CAAC,CAAC;KACjE;IACD,MAAM,EACJ,WAAW,GAAG,sBAAqC,EACnD,KAAK,GAAG,uBAAuB,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAqB,EACjF,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,MAAM;QACN,KAAK,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;QAC7B,OAAO,EAAE;YACP,QAAQ,EAAE,UAAU;SACrB;KACF,CAAC;AACJ,CAAC;AAnCD,4BAmCC;AAED,SAAS,uBAAuB,CAAC,EAC/B,UAAU,EACV,WAAW,EAIZ;IACC,IAAI,aAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,EAAE;QAChE,oGAAoG;QACpG,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1C,OAAO,2BAA2B,UAAU,KAAK,UAAU,OAAO,CAAC;KACpE;IACD,IAAI,aAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC,EAAE;QACjE,OAAO,kBAAkB,UAAU,GAAG,CAAC;KACxC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAyC;IACjF,OAAO,WAAW,KAAK,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;AACpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartlyio/oats-runtime",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Runtime for Oats a Openapi3 based generator for typescript aware servers and clients",
|
|
6
6
|
"private": false,
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@smartlyio/safe-navigation": "^5.0.1",
|
|
26
|
+
"@types/encodeurl": "1.0.0",
|
|
26
27
|
"@types/escape-html": "1.0.1",
|
|
28
|
+
"encodeurl": "1.0.2",
|
|
27
29
|
"escape-html": "1.0.3",
|
|
28
30
|
"lodash": "^4.17.20"
|
|
29
31
|
},
|
|
@@ -49,5 +51,5 @@
|
|
|
49
51
|
"tsconfig-paths": "3.14.1",
|
|
50
52
|
"typescript": "4.6.3"
|
|
51
53
|
},
|
|
52
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "8e6ff688c82fb559b853f01041343441be32e15a"
|
|
53
55
|
}
|
package/src/redirect.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Response } from './server';
|
|
2
2
|
import escapeHtml = require('escape-html');
|
|
3
|
+
import encodeUrl = require('encodeurl');
|
|
3
4
|
|
|
4
5
|
const REDIRECT_STATUSES = [300, 301, 302, 303, 305, 307, 308] as const;
|
|
5
6
|
const DEFAULT_REDIRECT_STATUS = 302;
|
|
@@ -26,6 +27,12 @@ type DefaultValue<ContentType extends string> = ContentType extends
|
|
|
26
27
|
*/
|
|
27
28
|
type PreventGenericDefaultValueOverride<T> = [T][T extends unknown ? 0 : never];
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Use to perform HTTP redirect.
|
|
32
|
+
* @param url an absolute or relative URL string. Will be encoded with `encodeurl` and set as "Location" header (@see https://github.com/pillarjs/encodeurl).
|
|
33
|
+
* @param options optional `status`, `contentType`, `value` that will override the default ones. Default `status` is 302, `contentType` is "text/html".
|
|
34
|
+
* @returns redirect server response.
|
|
35
|
+
*/
|
|
29
36
|
export function redirect<
|
|
30
37
|
Status extends RedirectStatus = typeof DEFAULT_REDIRECT_STATUS,
|
|
31
38
|
ContentType extends string = typeof TEXT_HTML_CONTENT_TYPE,
|
|
@@ -44,7 +51,7 @@ export function redirect<
|
|
|
44
51
|
{ Location: string }
|
|
45
52
|
> {
|
|
46
53
|
const { status = DEFAULT_REDIRECT_STATUS as Status } = options;
|
|
47
|
-
const encodedUrl =
|
|
54
|
+
const encodedUrl = encodeUrl(url);
|
|
48
55
|
|
|
49
56
|
if (!REDIRECT_STATUSES.includes(status)) {
|
|
50
57
|
throw new Error(`Status "${status}" is not a redirect status.`);
|