@wooksjs/http-proxy 0.6.2 → 0.6.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/README.md CHANGED
@@ -48,7 +48,7 @@ It's easy as `proxy` returns fetch response
48
48
  import { useProxy } from '@wooksjs/http-proxy'
49
49
  app.get('/to-proxy', async () => {
50
50
  const proxy = useProxy()
51
- const response = proxy('https://mayapi.com/json-api')
51
+ const response = await proxy('https://mayapi.com/json-api')
52
52
  const data = { ...(await response.json()), newField: 'new value' }
53
53
  return data
54
54
  })
@@ -58,7 +58,7 @@ app.get('/to-proxy', async () => {
58
58
 
59
59
  ```ts
60
60
  import { useProxy } from '@wooksjs/http-proxy'
61
- import { useRequest } from '@wooksjs/composables'
61
+ import { useRequest } from '@wooksjs/event-http'
62
62
  //...
63
63
  app.get('*', async () => {
64
64
  const proxy = useProxy()
package/dist/index.cjs CHANGED
@@ -103,6 +103,23 @@ const resHeadersToBlock = [
103
103
  "content-encoding",
104
104
  SET_COOKIE
105
105
  ];
106
+ /**
107
+ * Composable that returns a `proxy` function for forwarding HTTP requests to a target URL.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * app.get('/api/*', async () => {
112
+ * const proxy = useProxy()
113
+ * const response = await proxy('https://backend.example.com/api', {
114
+ * reqHeaders: { allow: '*' },
115
+ * resHeaders: { allow: '*' },
116
+ * })
117
+ * return response
118
+ * })
119
+ * ```
120
+ *
121
+ * @returns An async `proxy(target, opts?)` function that forwards the current request to the given target URL.
122
+ */
106
123
  function useProxy() {
107
124
  const status = (0, __wooksjs_event_http.useStatus)();
108
125
  const { setHeader, headers: getSetHeaders } = (0, __wooksjs_event_http.useSetHeaders)();
package/dist/index.d.ts CHANGED
@@ -1,17 +1,46 @@
1
+ /** Controls for filtering and transforming proxied headers or cookies. */
1
2
  interface TWooksProxyControls {
3
+ /** Override specific key-value pairs, or provide a transform function. */
2
4
  overwrite?: Record<string, string> | ((data: Record<string, string>) => Record<string, string>);
5
+ /** Allowlist of keys (strings or patterns) to forward; use `'*'` to allow all. */
3
6
  allow?: Array<string | RegExp> | '*';
7
+ /** Blocklist of keys (strings or patterns) to suppress; use `'*'` to block all. */
4
8
  block?: Array<string | RegExp> | '*';
5
9
  }
10
+ /** Options for configuring the proxy request, including header/cookie controls and debugging. */
6
11
  interface TWooksProxyOptions {
12
+ /** Override the HTTP method used for the proxied request. */
7
13
  method?: string;
14
+ /** Controls for filtering/transforming outgoing request headers. */
8
15
  reqHeaders?: TWooksProxyControls;
16
+ /** Controls for filtering/transforming outgoing request cookies. */
9
17
  reqCookies?: TWooksProxyControls;
18
+ /** Controls for filtering/transforming incoming response headers. */
10
19
  resHeaders?: TWooksProxyControls;
20
+ /** Controls for filtering/transforming incoming response cookies. */
11
21
  resCookies?: TWooksProxyControls;
22
+ /** When true, logs proxy request and response details. */
12
23
  debug?: boolean;
13
24
  }
14
25
 
26
+ /**
27
+ * Composable that returns a `proxy` function for forwarding HTTP requests to a target URL.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * app.get('/api/*', async () => {
32
+ * const proxy = useProxy()
33
+ * const response = await proxy('https://backend.example.com/api', {
34
+ * reqHeaders: { allow: '*' },
35
+ * resHeaders: { allow: '*' },
36
+ * })
37
+ * return response
38
+ * })
39
+ * ```
40
+ *
41
+ * @returns An async `proxy(target, opts?)` function that forwards the current request to the given target URL.
42
+ */
15
43
  declare function useProxy(): (target: string, opts?: TWooksProxyOptions) => Promise<Response>;
16
44
 
17
- export { type TWooksProxyControls, type TWooksProxyOptions, useProxy };
45
+ export { useProxy };
46
+ export type { TWooksProxyControls, TWooksProxyOptions };
package/dist/index.mjs CHANGED
@@ -80,6 +80,23 @@ const resHeadersToBlock = [
80
80
  "content-encoding",
81
81
  SET_COOKIE
82
82
  ];
83
+ /**
84
+ * Composable that returns a `proxy` function for forwarding HTTP requests to a target URL.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * app.get('/api/*', async () => {
89
+ * const proxy = useProxy()
90
+ * const response = await proxy('https://backend.example.com/api', {
91
+ * reqHeaders: { allow: '*' },
92
+ * resHeaders: { allow: '*' },
93
+ * })
94
+ * return response
95
+ * })
96
+ * ```
97
+ *
98
+ * @returns An async `proxy(target, opts?)` function that forwards the current request to the given target URL.
99
+ */
83
100
  function useProxy() {
84
101
  const status = useStatus();
85
102
  const { setHeader, headers: getSetHeaders } = useSetHeaders();
package/package.json CHANGED
@@ -1,52 +1,53 @@
1
1
  {
2
2
  "name": "@wooksjs/http-proxy",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Proxy Wooks composable",
5
- "main": "dist/index.cjs",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "exports": {
12
- "./package.json": "./package.json",
13
- ".": {
14
- "require": "./dist/index.cjs",
15
- "import": "./dist/index.mjs",
16
- "types": "./dist/index.d.ts"
17
- }
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/wooksjs/wooksjs.git",
22
- "directory": "packages/http-proxy"
23
- },
24
5
  "keywords": [
25
- "http",
26
- "wooks",
6
+ "api",
7
+ "app",
27
8
  "composables",
28
- "web",
29
9
  "framework",
30
- "app",
31
- "api",
10
+ "http",
11
+ "prostojs",
32
12
  "rest",
33
13
  "restful",
34
- "prostojs"
14
+ "web",
15
+ "wooks"
35
16
  ],
36
- "author": "Artem Maltsev",
37
- "license": "MIT",
17
+ "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-proxy#readme",
38
18
  "bugs": {
39
19
  "url": "https://github.com/wooksjs/wooksjs/issues"
40
20
  },
41
- "peerDependencies": {
42
- "@wooksjs/event-core": "^0.6.2",
43
- "@wooksjs/event-http": "^0.6.2"
21
+ "license": "MIT",
22
+ "author": "Artem Maltsev",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/wooksjs/wooksjs.git",
26
+ "directory": "packages/http-proxy"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "main": "dist/index.cjs",
32
+ "module": "dist/index.mjs",
33
+ "types": "dist/index.d.ts",
34
+ "exports": {
35
+ "./package.json": "./package.json",
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "require": "./dist/index.cjs",
39
+ "import": "./dist/index.mjs"
40
+ }
44
41
  },
45
- "dependencies": {},
46
- "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-proxy#readme",
47
42
  "devDependencies": {
48
- "typescript": "^5.8.3",
49
- "vitest": "^3.2.4"
43
+ "typescript": "^5.9.3",
44
+ "vitest": "^3.2.4",
45
+ "@wooksjs/event-core": "^0.6.4",
46
+ "@wooksjs/event-http": "^0.6.4"
47
+ },
48
+ "peerDependencies": {
49
+ "@wooksjs/event-core": "^0.6.4",
50
+ "@wooksjs/event-http": "^0.6.4"
50
51
  },
51
52
  "scripts": {
52
53
  "build": "rolldown -c ../../rolldown.config.mjs"