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 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 * as z from "zod/mini";
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: z.ZodMiniObject<{
5
- code: z.ZodMiniNumber<number>;
6
- message: z.ZodMiniString<string>;
7
- }, z.core.$strip>;
8
- declare const CloudflareApiResponseSchema: z.ZodMiniObject<{
9
- success: z.ZodMiniBoolean<boolean>;
10
- errors: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
11
- code: z.ZodMiniNumber<number>;
12
- message: z.ZodMiniString<string>;
13
- }, z.core.$strip>>>;
14
- messages: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
15
- result: z.ZodMiniUnknown;
16
- }, z.core.$strip>;
17
- declare const AccountSchema: z.ZodMiniObject<{
18
- id: z.ZodMiniString<string>;
19
- name: z.ZodMiniString<string>;
20
- }, z.core.$strip>;
21
- declare const ZoneSchema: z.ZodMiniObject<{
22
- id: z.ZodMiniString<string>;
23
- name: z.ZodMiniString<string>;
24
- }, z.core.$strip>;
25
- declare const TunnelSchema: z.ZodMiniObject<{
26
- id: z.ZodMiniString<string>;
27
- name: z.ZodMiniString<string>;
28
- account_tag: z.ZodMiniString<string>;
29
- created_at: z.ZodMiniString<string>;
30
- connections: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
31
- }, z.core.$strip>;
32
- declare const DNSRecordSchema: z.ZodMiniObject<{
33
- id: z.ZodMiniString<string>;
34
- type: z.ZodMiniString<string>;
35
- name: z.ZodMiniString<string>;
36
- content: z.ZodMiniString<string>;
37
- proxied: z.ZodMiniBoolean<boolean>;
38
- comment: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
39
- }, z.core.$strip>;
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-CwcXCIyR.mjs";
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 src_default from "./index.mjs";
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(src_default.vite(options));
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 };
@@ -1,8 +1,7 @@
1
1
  import { CloudflareTunnelOptions } from "./index.mjs";
2
- import * as esbuild0 from "esbuild";
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) => esbuild0.Plugin;
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 { esbuild_default as default, esbuild as "module.exports" };
21
+ export { esbuild as default, esbuild as "module.exports" };
package/dist/farm.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { CloudflareTunnelOptions } from "./index.mjs";
2
2
 
3
3
  //#region src/farm.d.ts
4
-
5
4
  /**
6
5
  * This entry file is for Farm plugin.
7
6
  *
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 { farm_default as default, farm as "module.exports" };
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: z.ZodMiniObject<{
17
- success: z.ZodMiniBoolean<boolean>;
18
- errors: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
19
- code: z.ZodMiniNumber<number>;
20
- message: z.ZodMiniString<string>;
21
- }, z.core.$strip>>>;
22
- messages: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
23
- result: z.ZodMiniUnknown;
24
- }, z.core.$strip>;
25
- declare const AccountSchema: z.ZodMiniObject<{
26
- id: z.ZodMiniString<string>;
27
- name: z.ZodMiniString<string>;
28
- }, z.core.$strip>;
29
- declare const ZoneSchema: z.ZodMiniObject<{
30
- id: z.ZodMiniString<string>;
31
- name: z.ZodMiniString<string>;
32
- }, z.core.$strip>;
33
- declare const TunnelSchema: z.ZodMiniObject<{
34
- id: z.ZodMiniString<string>;
35
- name: z.ZodMiniString<string>;
36
- account_tag: z.ZodMiniString<string>;
37
- created_at: z.ZodMiniString<string>;
38
- connections: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
39
- }, z.core.$strip>;
40
- declare const DNSRecordSchema: z.ZodMiniObject<{
41
- id: z.ZodMiniString<string>;
42
- type: z.ZodMiniString<string>;
43
- name: z.ZodMiniString<string>;
44
- content: z.ZodMiniString<string>;
45
- proxied: z.ZodMiniBoolean<boolean>;
46
- comment: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
47
- }, z.core.$strip>;
48
- type CloudflareApiResponse<T = unknown> = z.infer<typeof CloudflareApiResponseSchema> & {
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 = z.infer<typeof AccountSchema>;
52
- type Zone = z.infer<typeof ZoneSchema>;
53
- type Tunnel = z.infer<typeof TunnelSchema>;
54
- type DNSRecord = z.infer<typeof DNSRecordSchema>;
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 process
72
- * @default undefined (uses cloudflared default)
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. CLOUDFLARE_API_KEY environment variable
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: Provide `hostname` for a persistent tunnel with custom domain
162
- * - Quick tunnel mode: Omit `hostname` for a temporary tunnel with random trycloudflare.com URL
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>;