unplugin-cloudflare-tunnel 0.0.4 → 0.1.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/.github/README.md +71 -1
- package/dist/api.d.mts +40 -37
- package/dist/api.mjs +4 -5
- package/dist/astro.mjs +3 -5
- package/dist/esbuild.d.mts +2 -3
- package/dist/esbuild.mjs +1 -4
- package/dist/farm.d.mts +0 -1
- package/dist/farm.mjs +1 -4
- package/dist/index.d.mts +64 -43
- package/dist/index.mjs +185 -114
- package/dist/rolldown.d.mts +3681 -3
- package/dist/rolldown.mjs +1 -4
- package/dist/rollup.d.mts +2 -3
- package/dist/rollup.mjs +1 -4
- package/dist/rspack.d.mts +2 -3
- package/dist/rspack.mjs +1 -4
- package/dist/{schemas-CwcXCIyR.mjs → schemas-Cpk3vGGi.mjs} +46 -195
- package/dist/schemas-DKJtFAG_.d.mts +702 -0
- package/dist/virtual.d.mts +0 -1
- package/dist/vite.d.mts +2 -3
- package/dist/vite.mjs +1 -4
- package/dist/webpack.d.mts +2 -3
- package/dist/webpack.mjs +1 -4
- package/package.json +35 -23
package/.github/README.md
CHANGED
|
@@ -29,16 +29,80 @@ npm add unplugin-cloudflare-tunnel
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
+
### Modes
|
|
33
|
+
|
|
34
|
+
The plugin supports two modes:
|
|
35
|
+
|
|
36
|
+
- **Quick mode**: temporary `trycloudflare.com` URL, no Cloudflare credentials required
|
|
37
|
+
- **Named mode**: persistent tunnel on your own hostname
|
|
38
|
+
|
|
39
|
+
Mode selection rules:
|
|
40
|
+
|
|
41
|
+
- `mode: 'quick'` → always quick mode
|
|
42
|
+
- `mode: 'named'` → always named mode, requires `hostname`
|
|
43
|
+
- if `mode` is omitted:
|
|
44
|
+
- `hostname` provided → named mode
|
|
45
|
+
- otherwise → quick mode
|
|
46
|
+
|
|
47
|
+
### Common options
|
|
48
|
+
|
|
49
|
+
- `mode?: 'quick' | 'named'`
|
|
50
|
+
- `protocol?: 'http2' | 'quic'` — defaults to `http2` for better local dev reliability
|
|
51
|
+
- `logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'fatal'`
|
|
52
|
+
- `port?: number`
|
|
53
|
+
- `logFile?: string`
|
|
54
|
+
- `debug?: boolean`
|
|
55
|
+
- `enabled?: boolean`
|
|
56
|
+
|
|
57
|
+
### Quick mode example
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// vite.config.ts
|
|
61
|
+
import { defineConfig } from 'vite'
|
|
62
|
+
import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
plugins: [
|
|
66
|
+
CloudflareTunnel({
|
|
67
|
+
mode: 'quick',
|
|
68
|
+
protocol: 'http2',
|
|
69
|
+
}),
|
|
70
|
+
],
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Named mode example
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// vite.config.ts
|
|
78
|
+
import { defineConfig } from 'vite'
|
|
79
|
+
import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
|
|
80
|
+
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
plugins: [
|
|
83
|
+
CloudflareTunnel({
|
|
84
|
+
mode: 'named',
|
|
85
|
+
hostname: 'dev.example.com',
|
|
86
|
+
apiToken: process.env.CLOUDFLARE_API_TOKEN,
|
|
87
|
+
protocol: 'http2',
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
32
93
|
<details>
|
|
33
94
|
<summary>Vite</summary><br>
|
|
34
95
|
|
|
35
96
|
```ts
|
|
36
97
|
// vite.config.ts
|
|
98
|
+
import { defineConfig } from 'vite'
|
|
37
99
|
import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
|
|
38
100
|
|
|
39
101
|
export default defineConfig({
|
|
40
102
|
plugins: [
|
|
41
|
-
CloudflareTunnel(
|
|
103
|
+
CloudflareTunnel({
|
|
104
|
+
mode: 'quick',
|
|
105
|
+
}),
|
|
42
106
|
],
|
|
43
107
|
})
|
|
44
108
|
```
|
|
@@ -134,6 +198,12 @@ Or create a `virtual.d.ts` file in your project:
|
|
|
134
198
|
- **Named tunnel mode**: Returns your custom domain URL like `https://dev.example.com`
|
|
135
199
|
- **Plugin disabled**: Returns an empty string `""`
|
|
136
200
|
|
|
201
|
+
### Notes on modes
|
|
202
|
+
|
|
203
|
+
- Named-only options such as `hostname`, `apiToken`, `accountId`, `zoneId`, `tunnelName`, `dns`, `ssl`, and `cleanup` are only valid in named mode.
|
|
204
|
+
- Quick mode ignores Cloudflare account setup entirely and creates an ephemeral tunnel.
|
|
205
|
+
- `protocol` applies to both quick and named modes.
|
|
206
|
+
|
|
137
207
|
### Notes
|
|
138
208
|
|
|
139
209
|
- The virtual module is only available during development mode
|
package/dist/api.d.mts
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { a as ZodMiniObject, c as ZodMiniUnknown, i as ZodMiniNumber, n as ZodMiniBoolean, o as ZodMiniOptional, r as ZodMiniNullable, s as ZodMiniString, t as ZodMiniArray, u as $strip } from "./schemas-DKJtFAG_.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/api.d.ts
|
|
4
|
-
declare const CloudflareErrorSchema:
|
|
5
|
-
code:
|
|
6
|
-
message:
|
|
7
|
-
},
|
|
8
|
-
declare const CloudflareApiResponseSchema:
|
|
9
|
-
success:
|
|
10
|
-
errors:
|
|
11
|
-
code:
|
|
12
|
-
message:
|
|
13
|
-
},
|
|
14
|
-
messages:
|
|
15
|
-
result:
|
|
16
|
-
},
|
|
17
|
-
declare const AccountSchema:
|
|
18
|
-
id:
|
|
19
|
-
name:
|
|
20
|
-
},
|
|
21
|
-
declare const ZoneSchema:
|
|
22
|
-
id:
|
|
23
|
-
name:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
4
|
+
declare const CloudflareErrorSchema: ZodMiniObject<{
|
|
5
|
+
code: ZodMiniNumber<number>;
|
|
6
|
+
message: ZodMiniString<string>;
|
|
7
|
+
}, $strip>;
|
|
8
|
+
declare const CloudflareApiResponseSchema: ZodMiniObject<{
|
|
9
|
+
success: ZodMiniBoolean<boolean>;
|
|
10
|
+
errors: ZodMiniOptional<ZodMiniArray<ZodMiniObject<{
|
|
11
|
+
code: ZodMiniNumber<number>;
|
|
12
|
+
message: ZodMiniString<string>;
|
|
13
|
+
}, $strip>>>;
|
|
14
|
+
messages: ZodMiniOptional<ZodMiniArray<ZodMiniString<string>>>;
|
|
15
|
+
result: ZodMiniUnknown;
|
|
16
|
+
}, $strip>;
|
|
17
|
+
declare const AccountSchema: ZodMiniObject<{
|
|
18
|
+
id: ZodMiniString<string>;
|
|
19
|
+
name: ZodMiniString<string>;
|
|
20
|
+
}, $strip>;
|
|
21
|
+
declare const ZoneSchema: ZodMiniObject<{
|
|
22
|
+
id: ZodMiniString<string>;
|
|
23
|
+
name: ZodMiniString<string>;
|
|
24
|
+
account: ZodMiniOptional<ZodMiniObject<{
|
|
25
|
+
id: ZodMiniString<string>;
|
|
26
|
+
}, $strip>>;
|
|
27
|
+
}, $strip>;
|
|
28
|
+
declare const TunnelSchema: ZodMiniObject<{
|
|
29
|
+
id: ZodMiniString<string>;
|
|
30
|
+
name: ZodMiniString<string>;
|
|
31
|
+
account_tag: ZodMiniString<string>;
|
|
32
|
+
created_at: ZodMiniString<string>;
|
|
33
|
+
connections: ZodMiniOptional<ZodMiniArray<ZodMiniUnknown>>;
|
|
34
|
+
}, $strip>;
|
|
35
|
+
declare const DNSRecordSchema: ZodMiniObject<{
|
|
36
|
+
id: ZodMiniString<string>;
|
|
37
|
+
type: ZodMiniString<string>;
|
|
38
|
+
name: ZodMiniString<string>;
|
|
39
|
+
content: ZodMiniString<string>;
|
|
40
|
+
proxied: ZodMiniBoolean<boolean>;
|
|
41
|
+
comment: ZodMiniOptional<ZodMiniNullable<ZodMiniString<string>>>;
|
|
42
|
+
}, $strip>;
|
|
40
43
|
declare function normalizeAddress(address: string | {
|
|
41
44
|
address?: string;
|
|
42
45
|
port?: number;
|
package/dist/api.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { a as number, c as string, i as nullish, l as unknown, n as array, o as object, r as boolean, s as optional } from "./schemas-
|
|
1
|
+
import { a as number, c as string, i as nullish, l as unknown, n as array, o as object, r as boolean, s as optional } from "./schemas-Cpk3vGGi.mjs";
|
|
2
2
|
import NodeFS from "node:fs/promises";
|
|
3
3
|
import { install } from "cloudflared";
|
|
4
|
-
|
|
5
4
|
//#region src/api.ts
|
|
6
5
|
const CloudflareErrorSchema = object({
|
|
7
6
|
code: number(),
|
|
@@ -19,7 +18,8 @@ const AccountSchema = object({
|
|
|
19
18
|
});
|
|
20
19
|
const ZoneSchema = object({
|
|
21
20
|
id: string(),
|
|
22
|
-
name: string()
|
|
21
|
+
name: string(),
|
|
22
|
+
account: optional(object({ id: string() }))
|
|
23
23
|
});
|
|
24
24
|
const TunnelSchema = object({
|
|
25
25
|
id: string(),
|
|
@@ -54,6 +54,5 @@ async function ensureCloudflaredBinary(binPath) {
|
|
|
54
54
|
function getLocalTarget(host, port) {
|
|
55
55
|
return `http://${host.includes(":") ? `[${host}]` : host}:${port}`;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
57
|
//#endregion
|
|
59
|
-
export { AccountSchema, CloudflareApiResponseSchema, CloudflareErrorSchema, DNSRecordSchema, TunnelSchema, ZoneSchema, ensureCloudflaredBinary, getLocalTarget, normalizeAddress };
|
|
58
|
+
export { AccountSchema, CloudflareApiResponseSchema, CloudflareErrorSchema, DNSRecordSchema, TunnelSchema, ZoneSchema, ensureCloudflaredBinary, getLocalTarget, normalizeAddress };
|
package/dist/astro.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { CloudflareTunnel } from "./index.mjs";
|
|
3
2
|
//#region src/astro.ts
|
|
4
3
|
var astro_default = (options) => ({
|
|
5
4
|
name: "unplugin-cloudflare-tunnel",
|
|
6
5
|
hooks: { "astro:config:setup": async (astro) => {
|
|
7
6
|
astro.config.vite.plugins ||= [];
|
|
8
|
-
astro.config.vite.plugins.push(
|
|
7
|
+
astro.config.vite.plugins.push(CloudflareTunnel.vite(options));
|
|
9
8
|
} }
|
|
10
9
|
});
|
|
11
|
-
|
|
12
10
|
//#endregion
|
|
13
|
-
export { astro_default as default };
|
|
11
|
+
export { astro_default as default };
|
package/dist/esbuild.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CloudflareTunnelOptions } from "./index.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$esbuild from "esbuild";
|
|
3
3
|
|
|
4
4
|
//#region src/esbuild.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* This entry file is for esbuild plugin.
|
|
8
7
|
*
|
|
@@ -19,6 +18,6 @@ import * as esbuild0 from "esbuild";
|
|
|
19
18
|
* build({ plugins: [Starter()] })
|
|
20
19
|
```
|
|
21
20
|
*/
|
|
22
|
-
declare const esbuild: (options?: CloudflareTunnelOptions | undefined) =>
|
|
21
|
+
declare const esbuild: (options?: CloudflareTunnelOptions | undefined) => _$esbuild.Plugin;
|
|
23
22
|
//#endregion
|
|
24
23
|
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/esbuild.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CloudflareTunnel } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/esbuild.ts
|
|
4
3
|
/**
|
|
5
4
|
* This entry file is for esbuild plugin.
|
|
@@ -18,7 +17,5 @@ import { CloudflareTunnel } from "./index.mjs";
|
|
|
18
17
|
```
|
|
19
18
|
*/
|
|
20
19
|
const esbuild = CloudflareTunnel.esbuild;
|
|
21
|
-
var esbuild_default = esbuild;
|
|
22
|
-
|
|
23
20
|
//#endregion
|
|
24
|
-
export {
|
|
21
|
+
export { esbuild as default, esbuild as "module.exports" };
|
package/dist/farm.d.mts
CHANGED
package/dist/farm.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CloudflareTunnel } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/farm.ts
|
|
4
3
|
/**
|
|
5
4
|
* This entry file is for Farm plugin.
|
|
@@ -20,7 +19,5 @@ import { CloudflareTunnel } from "./index.mjs";
|
|
|
20
19
|
* ```
|
|
21
20
|
*/
|
|
22
21
|
const farm = CloudflareTunnel.farm;
|
|
23
|
-
var farm_default = farm;
|
|
24
|
-
|
|
25
22
|
//#endregion
|
|
26
|
-
export {
|
|
23
|
+
export { farm as default, farm as "module.exports" };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { a as ZodMiniObject, c as ZodMiniUnknown, i as ZodMiniNumber, l as output, n as ZodMiniBoolean, o as ZodMiniOptional, r as ZodMiniNullable, s as ZodMiniString, t as ZodMiniArray, u as $strip } from "./schemas-DKJtFAG_.mjs";
|
|
1
2
|
import { UnpluginInstance } from "unplugin";
|
|
2
|
-
import * as z from "zod/mini";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
/**
|
|
@@ -13,49 +13,61 @@ import * as z from "zod/mini";
|
|
|
13
13
|
* @version 1.0.0
|
|
14
14
|
* @license MIT
|
|
15
15
|
*/
|
|
16
|
-
declare const CloudflareApiResponseSchema:
|
|
17
|
-
success:
|
|
18
|
-
errors:
|
|
19
|
-
code:
|
|
20
|
-
message:
|
|
21
|
-
},
|
|
22
|
-
messages:
|
|
23
|
-
result:
|
|
24
|
-
},
|
|
25
|
-
declare const AccountSchema:
|
|
26
|
-
id:
|
|
27
|
-
name:
|
|
28
|
-
},
|
|
29
|
-
declare const ZoneSchema:
|
|
30
|
-
id:
|
|
31
|
-
name:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
16
|
+
declare const CloudflareApiResponseSchema: ZodMiniObject<{
|
|
17
|
+
success: ZodMiniBoolean<boolean>;
|
|
18
|
+
errors: ZodMiniOptional<ZodMiniArray<ZodMiniObject<{
|
|
19
|
+
code: ZodMiniNumber<number>;
|
|
20
|
+
message: ZodMiniString<string>;
|
|
21
|
+
}, $strip>>>;
|
|
22
|
+
messages: ZodMiniOptional<ZodMiniArray<ZodMiniString<string>>>;
|
|
23
|
+
result: ZodMiniUnknown;
|
|
24
|
+
}, $strip>;
|
|
25
|
+
declare const AccountSchema: ZodMiniObject<{
|
|
26
|
+
id: ZodMiniString<string>;
|
|
27
|
+
name: ZodMiniString<string>;
|
|
28
|
+
}, $strip>;
|
|
29
|
+
declare const ZoneSchema: ZodMiniObject<{
|
|
30
|
+
id: ZodMiniString<string>;
|
|
31
|
+
name: ZodMiniString<string>;
|
|
32
|
+
account: ZodMiniOptional<ZodMiniObject<{
|
|
33
|
+
id: ZodMiniString<string>;
|
|
34
|
+
}, $strip>>;
|
|
35
|
+
}, $strip>;
|
|
36
|
+
declare const TunnelSchema: ZodMiniObject<{
|
|
37
|
+
id: ZodMiniString<string>;
|
|
38
|
+
name: ZodMiniString<string>;
|
|
39
|
+
account_tag: ZodMiniString<string>;
|
|
40
|
+
created_at: ZodMiniString<string>;
|
|
41
|
+
connections: ZodMiniOptional<ZodMiniArray<ZodMiniUnknown>>;
|
|
42
|
+
}, $strip>;
|
|
43
|
+
declare const DNSRecordSchema: ZodMiniObject<{
|
|
44
|
+
id: ZodMiniString<string>;
|
|
45
|
+
type: ZodMiniString<string>;
|
|
46
|
+
name: ZodMiniString<string>;
|
|
47
|
+
content: ZodMiniString<string>;
|
|
48
|
+
proxied: ZodMiniBoolean<boolean>;
|
|
49
|
+
comment: ZodMiniOptional<ZodMiniNullable<ZodMiniString<string>>>;
|
|
50
|
+
}, $strip>;
|
|
51
|
+
type CloudflareApiResponse<T = unknown> = output<typeof CloudflareApiResponseSchema> & {
|
|
49
52
|
result: T;
|
|
50
53
|
};
|
|
51
|
-
type Account =
|
|
52
|
-
type Zone =
|
|
53
|
-
type Tunnel =
|
|
54
|
-
type DNSRecord =
|
|
54
|
+
type Account = output<typeof AccountSchema>;
|
|
55
|
+
type Zone = output<typeof ZoneSchema>;
|
|
56
|
+
type Tunnel = output<typeof TunnelSchema>;
|
|
57
|
+
type DNSRecord = output<typeof DNSRecordSchema>;
|
|
55
58
|
/**
|
|
56
59
|
* Base configuration options shared between named and quick tunnel modes
|
|
57
60
|
*/
|
|
58
61
|
interface BaseTunnelOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Tunnel mode.
|
|
64
|
+
* - `quick`: temporary `trycloudflare.com` URL, no hostname required
|
|
65
|
+
* - `named`: persistent tunnel using your configured hostname
|
|
66
|
+
*
|
|
67
|
+
* When omitted, the plugin uses named mode if `hostname` is provided,
|
|
68
|
+
* otherwise it uses quick mode.
|
|
69
|
+
*/
|
|
70
|
+
mode?: 'quick' | 'named';
|
|
59
71
|
/**
|
|
60
72
|
* Local port your dev server listens on
|
|
61
73
|
* If not specified, will automatically use the bundler's configured port
|
|
@@ -68,10 +80,19 @@ interface BaseTunnelOptions {
|
|
|
68
80
|
*/
|
|
69
81
|
logFile?: string;
|
|
70
82
|
/**
|
|
71
|
-
* Log level for cloudflared
|
|
72
|
-
*
|
|
83
|
+
* Log level for cloudflared output shown by the plugin.
|
|
84
|
+
* The plugin still runs cloudflared with at least `info` internally so it can
|
|
85
|
+
* detect tunnel readiness and print the tunnel URL.
|
|
86
|
+
* @default undefined
|
|
73
87
|
*/
|
|
74
88
|
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
89
|
+
/**
|
|
90
|
+
* Transport protocol used by cloudflared.
|
|
91
|
+
* `http2` is the default because it is more reliable for local development
|
|
92
|
+
* networks than QUIC.
|
|
93
|
+
* @default 'http2'
|
|
94
|
+
*/
|
|
95
|
+
protocol?: 'http2' | 'quic';
|
|
75
96
|
/**
|
|
76
97
|
* Enable additional verbose logging for easier debugging.
|
|
77
98
|
* When true, the plugin will output extra information prefixed with
|
|
@@ -103,7 +124,7 @@ interface NamedTunnelOptions extends BaseTunnelOptions {
|
|
|
103
124
|
*
|
|
104
125
|
* Fallback priority:
|
|
105
126
|
* 1. Provided apiToken option
|
|
106
|
-
* 2.
|
|
127
|
+
* 2. CLOUDFLARE_API_TOKEN environment variable
|
|
107
128
|
*/
|
|
108
129
|
apiToken?: string;
|
|
109
130
|
/**
|
|
@@ -158,8 +179,8 @@ interface QuickTunnelOptions extends BaseTunnelOptions {}
|
|
|
158
179
|
* Configuration options for the Cloudflare Tunnel plugin
|
|
159
180
|
*
|
|
160
181
|
* Two modes are supported:
|
|
161
|
-
* - Named tunnel mode:
|
|
162
|
-
* - Quick tunnel mode:
|
|
182
|
+
* - Named tunnel mode: set `mode: 'named'` or provide `hostname`
|
|
183
|
+
* - Quick tunnel mode: set `mode: 'quick'` or omit `hostname`
|
|
163
184
|
*/
|
|
164
185
|
type CloudflareTunnelOptions = NamedTunnelOptions | QuickTunnelOptions;
|
|
165
186
|
declare const CloudflareTunnel: UnpluginInstance<CloudflareTunnelOptions | undefined, false>;
|