@stryke/http 0.3.1 â 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -6
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +11 -10
- package/dist/url-builder.cjs +58 -56
- package/dist/url-builder.d.ts +2 -2
- package/dist/url-builder.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<!-- markdownlint-disable -->
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
<div align="center"><img src="https://
|
|
6
|
+
<div align="center"><img src="https://public.storm-cdn.com/storm-banner.gif" width="100%" alt="Storm Software" /></div>
|
|
7
7
|
<br />
|
|
8
8
|
|
|
9
9
|
<div align="center">
|
|
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŠī¸ Stryke** monorepo. Stryke pac
|
|
|
22
22
|
|
|
23
23
|
<h3 align="center">đģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
|
|
24
24
|
|
|
25
|
-
[](https://prettier.io/) [](http://nx.dev/) [](https://nextjs.org/) [](http://commitizen.github.io/cz-cli/)  [](https://fumadocs.vercel.app/) 
|
|
26
26
|
|
|
27
27
|
> [!IMPORTANT] This repository, and the apps, libraries, and tools contained
|
|
28
28
|
> within, is still in it's initial development phase. As a result, bugs and
|
|
@@ -51,7 +51,6 @@ between processes easier in other packages/applications.
|
|
|
51
51
|
|
|
52
52
|
<!-- START doctoc -->
|
|
53
53
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
54
|
-
|
|
55
54
|
## Table of Contents
|
|
56
55
|
|
|
57
56
|
- [Installing](#installing)
|
|
@@ -247,7 +246,7 @@ specification. Contributions of any kind welcome!
|
|
|
247
246
|
<br />
|
|
248
247
|
|
|
249
248
|
<div align="center">
|
|
250
|
-
<img src="https://
|
|
249
|
+
<img src="https://public.storm-cdn.com/logo-banner.png" width="100%" alt="Storm Software" />
|
|
251
250
|
</div>
|
|
252
251
|
<br />
|
|
253
252
|
|
|
@@ -278,9 +277,9 @@ generation of development tools, please reach out on our
|
|
|
278
277
|
|
|
279
278
|
<br />
|
|
280
279
|
|
|
281
|
-
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://
|
|
280
|
+
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/icon-fill.png" alt="Storm Software" width="200px"/></a></div>
|
|
282
281
|
<br />
|
|
283
|
-
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://
|
|
282
|
+
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/visit-us-text.svg" alt="Visit us at stormsoftware.com" height="90px"/></a></div>
|
|
284
283
|
|
|
285
284
|
<br />
|
|
286
285
|
|
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,17 @@ Object.keys(_formatDataUri).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
var _types = require("./types.cjs");
|
|
29
|
+
Object.keys(_types).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _types[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
28
39
|
var _urlBuilder = require("./url-builder.cjs");
|
|
29
40
|
Object.keys(_urlBuilder).forEach(function (key) {
|
|
30
41
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./cookie";export*from"./format-data-uri";export*from"./url-builder";
|
|
1
|
+
export*from"./cookie";export*from"./format-data-uri";export*from"./types";export*from"./url-builder";
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ParsedURL } from "ufo";
|
|
2
2
|
export type StormURL = ParsedURL & {
|
|
3
3
|
__typename: "StormURL";
|
|
4
|
-
|
|
4
|
+
queryParams: Record<string, any>;
|
|
5
|
+
paths: string[];
|
|
5
6
|
username?: string;
|
|
6
7
|
password?: string;
|
|
7
8
|
hostname?: string;
|
|
@@ -27,13 +28,13 @@ export interface CookieSerializeOptions {
|
|
|
27
28
|
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
|
|
28
29
|
* any that fall outside of the cookie range.
|
|
29
30
|
*/
|
|
30
|
-
encode
|
|
31
|
+
encode?: (value: string) => string;
|
|
31
32
|
/**
|
|
32
33
|
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1 | `Expires` `Set-Cookie` attribute}. By default,
|
|
33
34
|
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
|
|
34
35
|
* it on a condition like exiting a web browser application.
|
|
35
36
|
*
|
|
36
|
-
*
|
|
37
|
+
* Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3 | cookie storage model specification}
|
|
37
38
|
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
38
39
|
* possible not all clients by obey this, so if both are set, they should
|
|
39
40
|
* point to the same date and time.
|
|
@@ -44,7 +45,7 @@ export interface CookieSerializeOptions {
|
|
|
44
45
|
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
|
|
45
46
|
* default, the `HttpOnly` attribute is not set.
|
|
46
47
|
*
|
|
47
|
-
*
|
|
48
|
+
* Note* be careful when setting this to true, as compliant clients will
|
|
48
49
|
* not allow client-side JavaScript to see the cookie in `document.cookie`.
|
|
49
50
|
*/
|
|
50
51
|
httpOnly?: boolean | undefined;
|
|
@@ -53,7 +54,7 @@ export interface CookieSerializeOptions {
|
|
|
53
54
|
* `Set-Cookie` attribute. The given number will be converted to an integer
|
|
54
55
|
* by rounding down. By default, no maximum age is set.
|
|
55
56
|
*
|
|
56
|
-
*
|
|
57
|
+
* Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3 | cookie storage model specification}
|
|
57
58
|
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
58
59
|
* possible not all clients by obey this, so if both are set, they should
|
|
59
60
|
* point to the same date and time.
|
|
@@ -93,14 +94,14 @@ export interface CookieSerializeOptions {
|
|
|
93
94
|
*
|
|
94
95
|
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
|
|
95
96
|
*
|
|
96
|
-
*
|
|
97
|
+
* note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
|
|
97
98
|
*/
|
|
98
99
|
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
99
100
|
/**
|
|
100
101
|
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5 | `Secure` `Set-Cookie` attribute}. When truthy, the
|
|
101
102
|
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
|
102
103
|
*
|
|
103
|
-
*
|
|
104
|
+
* Note* be careful when setting this to `true`, as compliant clients will
|
|
104
105
|
* not send the cookie back to the server in the future if the browser does
|
|
105
106
|
* not have an HTTPS connection.
|
|
106
107
|
*/
|
|
@@ -130,14 +131,14 @@ export interface CookieParseOptions {
|
|
|
130
131
|
* The default function is the global `decodeURIComponent`, which will decode
|
|
131
132
|
* any URL-encoded sequences into their byte representations.
|
|
132
133
|
*
|
|
133
|
-
*
|
|
134
|
+
* Note* if an error is thrown from this function, the original, non-decoded
|
|
134
135
|
* cookie value will be returned as the cookie's value.
|
|
135
136
|
*/
|
|
136
|
-
decode
|
|
137
|
+
decode?: (value: string) => string;
|
|
137
138
|
/**
|
|
138
139
|
* Custom function to filter parsing specific keys.
|
|
139
140
|
*/
|
|
140
|
-
filter
|
|
141
|
+
filter?: (key: string) => boolean;
|
|
141
142
|
}
|
|
142
143
|
export interface SetCookieParseOptions {
|
|
143
144
|
/**
|
package/dist/url-builder.cjs
CHANGED
|
@@ -8,89 +8,91 @@ var _stormJson = require("@stryke/json/storm-json");
|
|
|
8
8
|
var _isString = require("@stryke/type-checks/is-string");
|
|
9
9
|
var _ufo = require("ufo");
|
|
10
10
|
class StormURLBuilder {
|
|
11
|
-
#
|
|
12
|
-
static create(
|
|
13
|
-
return new StormURLBuilder(
|
|
14
|
-
}
|
|
15
|
-
constructor(
|
|
16
|
-
const s =
|
|
17
|
-
|
|
18
|
-
this.#
|
|
11
|
+
#t;
|
|
12
|
+
static create(t, r) {
|
|
13
|
+
return new StormURLBuilder(t, r);
|
|
14
|
+
}
|
|
15
|
+
constructor(t, r) {
|
|
16
|
+
const s = r?.decode ?? !0,
|
|
17
|
+
i = (0, _isString.isString)(t) ? s ? (0, _ufo.parseURL)((0, _ufo.decode)(t)) : (0, _ufo.parseURL)(t) : t;
|
|
18
|
+
this.#t = {
|
|
19
19
|
__typename: "StormURL",
|
|
20
|
-
|
|
21
|
-
...
|
|
22
|
-
|
|
20
|
+
queryParams: {},
|
|
21
|
+
...i,
|
|
22
|
+
paths: i.pathname ? i.pathname.split("/").filter(Boolean) : []
|
|
23
|
+
}, this.#t.host && this.withHost(this.#t.host), this.#t.auth && this.withAuth(this.#t.auth);
|
|
23
24
|
}
|
|
24
25
|
get _url() {
|
|
25
|
-
return this.#
|
|
26
|
+
return this.#t;
|
|
26
27
|
}
|
|
27
|
-
withProtocol(
|
|
28
|
-
return this.#
|
|
28
|
+
withProtocol(t) {
|
|
29
|
+
return this.#t.protocol = t, this;
|
|
29
30
|
}
|
|
30
|
-
withHostname(
|
|
31
|
-
return this.#
|
|
31
|
+
withHostname(t) {
|
|
32
|
+
return this.#t.hostname = t, this;
|
|
32
33
|
}
|
|
33
|
-
withPort(
|
|
34
|
-
return this.#
|
|
34
|
+
withPort(t) {
|
|
35
|
+
return this.#t.port = String(t), this;
|
|
35
36
|
}
|
|
36
|
-
withUsername(
|
|
37
|
-
return this.#
|
|
37
|
+
withUsername(t) {
|
|
38
|
+
return this.#t.username = t, this;
|
|
38
39
|
}
|
|
39
|
-
withPassword(
|
|
40
|
-
return this.#
|
|
40
|
+
withPassword(t) {
|
|
41
|
+
return this.#t.password = t, this;
|
|
41
42
|
}
|
|
42
|
-
withHost(
|
|
43
|
-
if ((0, _isString.isString)(
|
|
44
|
-
this.#
|
|
45
|
-
const
|
|
46
|
-
this.#
|
|
47
|
-
} else this.#
|
|
43
|
+
withHost(t) {
|
|
44
|
+
if ((0, _isString.isString)(t)) {
|
|
45
|
+
this.#t.host = t;
|
|
46
|
+
const r = (0, _ufo.parseAuth)(t);
|
|
47
|
+
this.#t.username = r.username, this.#t.password = r.password;
|
|
48
|
+
} else this.#t.hostname = t.hostname, this.#t.port = t.port, this.#t.auth = `${t.hostname}${t.port ? `:${t.port}` : ""}`;
|
|
48
49
|
return this;
|
|
49
50
|
}
|
|
50
|
-
withPath(
|
|
51
|
-
const
|
|
52
|
-
return this.#
|
|
53
|
-
...this.#
|
|
54
|
-
...
|
|
51
|
+
withPath(t) {
|
|
52
|
+
const r = (0, _ufo.parsePath)(t);
|
|
53
|
+
return this.#t = {
|
|
54
|
+
...this.#t,
|
|
55
|
+
...r,
|
|
56
|
+
paths: r.pathname.split("/").filter(Boolean)
|
|
55
57
|
}, this;
|
|
56
58
|
}
|
|
57
|
-
withHash(
|
|
58
|
-
return this.#
|
|
59
|
+
withHash(t) {
|
|
60
|
+
return this.#t.hash = t, this;
|
|
59
61
|
}
|
|
60
|
-
withAuth(
|
|
61
|
-
if ((0, _isString.isString)(
|
|
62
|
-
this.#
|
|
63
|
-
const
|
|
64
|
-
this.#
|
|
65
|
-
} else this.#
|
|
62
|
+
withAuth(t) {
|
|
63
|
+
if ((0, _isString.isString)(t)) {
|
|
64
|
+
this.#t.auth = t;
|
|
65
|
+
const r = (0, _ufo.parseAuth)(t);
|
|
66
|
+
this.#t.username = r.username, this.#t.password = r.password;
|
|
67
|
+
} else this.#t.username = t.username, this.#t.password = t.password, this.#t.auth = `${t.username}:${t.password}`;
|
|
66
68
|
return this;
|
|
67
69
|
}
|
|
68
|
-
withQuery(
|
|
69
|
-
return this.#
|
|
70
|
+
withQuery(t) {
|
|
71
|
+
return this.#t.queryParams = {}, this.addQueryParam(t), this;
|
|
70
72
|
}
|
|
71
|
-
addQueryParam(
|
|
72
|
-
if ((0, _isString.isString)(
|
|
73
|
-
const
|
|
74
|
-
for (const s
|
|
75
|
-
} else if (Array.isArray(
|
|
73
|
+
addQueryParam(t) {
|
|
74
|
+
if ((0, _isString.isString)(t)) {
|
|
75
|
+
const r = (0, _ufo.parseQuery)(t);
|
|
76
|
+
for (const s of Object.entries(r)) s[0] && (this.#t.queryParams[s[0]] = this.parseQueryParamValue(s[1]));
|
|
77
|
+
} else if (Array.isArray(t) && t.length === 2) this.#t.queryParams[t[0]] = this.parseQueryParamValue(t[1]);else for (const r of Object.entries(t)) r[0] && (this.#t.queryParams[r[0]] = this.parseQueryParamValue(r[1]));
|
|
76
78
|
return this;
|
|
77
79
|
}
|
|
78
80
|
build() {
|
|
79
|
-
return this.#
|
|
81
|
+
return this.#t;
|
|
80
82
|
}
|
|
81
83
|
toString() {
|
|
82
|
-
return (0, _ufo.cleanDoubleSlashes)((0, _ufo.stringifyParsedURL)(this.#
|
|
84
|
+
return (0, _ufo.cleanDoubleSlashes)((0, _ufo.stringifyParsedURL)(this.#t));
|
|
83
85
|
}
|
|
84
86
|
toEncoded() {
|
|
85
87
|
return (0, _ufo.encode)(this.toString());
|
|
86
88
|
}
|
|
87
|
-
parseQueryParamValue(
|
|
88
|
-
if (Array.isArray(
|
|
89
|
-
const
|
|
90
|
-
for (const s
|
|
91
|
-
return
|
|
89
|
+
parseQueryParamValue(t) {
|
|
90
|
+
if (Array.isArray(t)) {
|
|
91
|
+
const r = [];
|
|
92
|
+
for (const s of t) r.push(this.parseQueryParamValue(s));
|
|
93
|
+
return r;
|
|
92
94
|
}
|
|
93
|
-
return _stormJson.StormJSON.parse(
|
|
95
|
+
return _stormJson.StormJSON.parse(t);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
exports.StormURLBuilder = StormURLBuilder;
|
package/dist/url-builder.d.ts
CHANGED
|
@@ -106,10 +106,10 @@ export declare class StormURLBuilder {
|
|
|
106
106
|
/**
|
|
107
107
|
* Add a query parameter to the URL
|
|
108
108
|
*
|
|
109
|
-
* @param
|
|
109
|
+
* @param queryParam - The query parameter to add
|
|
110
110
|
* @returns The URL builder
|
|
111
111
|
*/
|
|
112
|
-
addQueryParam(
|
|
112
|
+
addQueryParam(queryParam: string | [string, any] | Record<string, any>): StormURLBuilder;
|
|
113
113
|
/**
|
|
114
114
|
* Returns the built URL
|
|
115
115
|
*
|
package/dist/url-builder.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{StormJSON as a}from"@stryke/json/storm-json";import{isString as
|
|
1
|
+
import{StormJSON as a}from"@stryke/json/storm-json";import{isString as e}from"@stryke/type-checks/is-string";import{cleanDoubleSlashes as h,decode as u,encode as p,parseAuth as o,parsePath as m,parseQuery as d,parseURL as n,stringifyParsedURL as l}from"ufo";export class StormURLBuilder{#t;static create(t,r){return new StormURLBuilder(t,r)}constructor(t,r){const s=r?.decode??!0,i=e(t)?s?n(u(t)):n(t):t;this.#t={__typename:"StormURL",queryParams:{},...i,paths:i.pathname?i.pathname.split("/").filter(Boolean):[]},this.#t.host&&this.withHost(this.#t.host),this.#t.auth&&this.withAuth(this.#t.auth)}get _url(){return this.#t}withProtocol(t){return this.#t.protocol=t,this}withHostname(t){return this.#t.hostname=t,this}withPort(t){return this.#t.port=String(t),this}withUsername(t){return this.#t.username=t,this}withPassword(t){return this.#t.password=t,this}withHost(t){if(e(t)){this.#t.host=t;const r=o(t);this.#t.username=r.username,this.#t.password=r.password}else this.#t.hostname=t.hostname,this.#t.port=t.port,this.#t.auth=`${t.hostname}${t.port?`:${t.port}`:""}`;return this}withPath(t){const r=m(t);return this.#t={...this.#t,...r,paths:r.pathname.split("/").filter(Boolean)},this}withHash(t){return this.#t.hash=t,this}withAuth(t){if(e(t)){this.#t.auth=t;const r=o(t);this.#t.username=r.username,this.#t.password=r.password}else this.#t.username=t.username,this.#t.password=t.password,this.#t.auth=`${t.username}:${t.password}`;return this}withQuery(t){return this.#t.queryParams={},this.addQueryParam(t),this}addQueryParam(t){if(e(t)){const r=d(t);for(const s of Object.entries(r))s[0]&&(this.#t.queryParams[s[0]]=this.parseQueryParamValue(s[1]))}else if(Array.isArray(t)&&t.length===2)this.#t.queryParams[t[0]]=this.parseQueryParamValue(t[1]);else for(const r of Object.entries(t))r[0]&&(this.#t.queryParams[r[0]]=this.parseQueryParamValue(r[1]));return this}build(){return this.#t}toString(){return h(l(this.#t))}toEncoded(){return p(this.toString())}parseQueryParamValue(t){if(Array.isArray(t)){const r=[];for(const s of t)r.push(this.parseQueryParamValue(s));return r}return a.parse(t)}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing HTTP communication utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"private": false,
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"ufo": "1.5.4",
|
|
14
|
-
"@stryke/json": ">=0.5.
|
|
15
|
-
"@stryke/type-checks": ">=0.1.
|
|
14
|
+
"@stryke/json": ">=0.5.2",
|
|
15
|
+
"@stryke/type-checks": ">=0.1.2"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": { "@types/node": "^22.13.1" },
|
|
18
18
|
"publishConfig": { "access": "public" },
|