@flash-tunnel/adapter-cloudflare 0.3.0 → 0.4.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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { DnsRecordType, DnsRecordSpec, DnsAdapter, TunnelAdapter } from '@flash-tunnel/types';
1
+ import { TunnelAdapter } from '@flash-tunnel/types';
2
2
 
3
3
  interface CloudflareApiOptions {
4
4
  apiToken: string;
@@ -9,11 +9,6 @@ interface CloudflareAccount {
9
9
  id: string;
10
10
  name: string;
11
11
  }
12
- interface CloudflareZone {
13
- id: string;
14
- name: string;
15
- status: string;
16
- }
17
12
  interface CloudflareTunnel {
18
13
  id: string;
19
14
  name: string;
@@ -23,14 +18,6 @@ interface CloudflareTunnel {
23
18
  }>;
24
19
  token?: string;
25
20
  }
26
- interface CloudflareDnsRecord {
27
- id: string;
28
- name: string;
29
- type: DnsRecordType;
30
- content: string;
31
- proxied: boolean;
32
- comment?: string;
33
- }
34
21
  declare class CloudflareApi {
35
22
  private readonly apiToken;
36
23
  private readonly apiBase;
@@ -40,29 +27,13 @@ declare class CloudflareApi {
40
27
  verifyToken(): Promise<void>;
41
28
  listAccounts(): Promise<CloudflareAccount[]>;
42
29
  resolveAccountId(preferred?: string): Promise<string>;
43
- listZones(name?: string): Promise<CloudflareZone[]>;
44
- resolveZone(zone: string): Promise<CloudflareZone>;
45
30
  createTunnel(accountId: string, name: string): Promise<CloudflareTunnel>;
46
31
  getTunnel(accountId: string, tunnelId: string): Promise<CloudflareTunnel>;
47
32
  getTunnelToken(accountId: string, tunnelId: string): Promise<string>;
48
33
  putIngress(accountId: string, tunnelId: string, ingress: unknown[]): Promise<void>;
49
34
  cleanupConnections(accountId: string, tunnelId: string): Promise<void>;
50
35
  deleteTunnel(accountId: string, tunnelId: string): Promise<void>;
51
- listDnsRecords(zoneId: string, query?: {
52
- name?: string;
53
- comment?: string;
54
- }): Promise<CloudflareDnsRecord[]>;
55
- createDnsRecord(zoneId: string, spec: DnsRecordSpec): Promise<CloudflareDnsRecord>;
56
- deleteDnsRecord(zoneId: string, recordId: string): Promise<void>;
57
- }
58
-
59
- interface CloudflareDnsOptions {
60
- apiToken: string;
61
- zoneId?: string;
62
- apiBase?: string;
63
- fetcher?: typeof fetch;
64
36
  }
65
- declare function createCloudflareDns(options: CloudflareDnsOptions): DnsAdapter;
66
37
 
67
38
  interface CloudflareTunnelOptions {
68
39
  cloudflaredPath?: string;
@@ -78,9 +49,8 @@ interface CloudflareTunnelOptions {
78
49
  declare function createCloudflareTunnel(options?: CloudflareTunnelOptions): TunnelAdapter;
79
50
  declare const cloudflareTunnel: TunnelAdapter;
80
51
 
81
- declare const CLOUDFLARE_DNS_ADAPTER_ID = "cloudflare";
82
52
  declare const CLOUDFLARE_TUNNEL_ADAPTER_ID = "cloudflare";
83
53
  declare const CLOUDFLARE_API_BASE = "https://api.cloudflare.com/client/v4";
84
54
 
85
- export { CLOUDFLARE_API_BASE, CLOUDFLARE_DNS_ADAPTER_ID, CLOUDFLARE_TUNNEL_ADAPTER_ID, CloudflareApi, cloudflareTunnel, createCloudflareDns, createCloudflareTunnel };
86
- export type { CloudflareAccount, CloudflareDnsOptions, CloudflareDnsRecord, CloudflareTunnel, CloudflareTunnelOptions, CloudflareZone };
55
+ export { CLOUDFLARE_API_BASE, CLOUDFLARE_TUNNEL_ADAPTER_ID, CloudflareApi, cloudflareTunnel, createCloudflareTunnel };
56
+ export type { CloudflareAccount, CloudflareTunnel, CloudflareTunnelOptions };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DnsRecordType, DnsRecordSpec, DnsAdapter, TunnelAdapter } from '@flash-tunnel/types';
1
+ import { TunnelAdapter } from '@flash-tunnel/types';
2
2
 
3
3
  interface CloudflareApiOptions {
4
4
  apiToken: string;
@@ -9,11 +9,6 @@ interface CloudflareAccount {
9
9
  id: string;
10
10
  name: string;
11
11
  }
12
- interface CloudflareZone {
13
- id: string;
14
- name: string;
15
- status: string;
16
- }
17
12
  interface CloudflareTunnel {
18
13
  id: string;
19
14
  name: string;
@@ -23,14 +18,6 @@ interface CloudflareTunnel {
23
18
  }>;
24
19
  token?: string;
25
20
  }
26
- interface CloudflareDnsRecord {
27
- id: string;
28
- name: string;
29
- type: DnsRecordType;
30
- content: string;
31
- proxied: boolean;
32
- comment?: string;
33
- }
34
21
  declare class CloudflareApi {
35
22
  private readonly apiToken;
36
23
  private readonly apiBase;
@@ -40,29 +27,13 @@ declare class CloudflareApi {
40
27
  verifyToken(): Promise<void>;
41
28
  listAccounts(): Promise<CloudflareAccount[]>;
42
29
  resolveAccountId(preferred?: string): Promise<string>;
43
- listZones(name?: string): Promise<CloudflareZone[]>;
44
- resolveZone(zone: string): Promise<CloudflareZone>;
45
30
  createTunnel(accountId: string, name: string): Promise<CloudflareTunnel>;
46
31
  getTunnel(accountId: string, tunnelId: string): Promise<CloudflareTunnel>;
47
32
  getTunnelToken(accountId: string, tunnelId: string): Promise<string>;
48
33
  putIngress(accountId: string, tunnelId: string, ingress: unknown[]): Promise<void>;
49
34
  cleanupConnections(accountId: string, tunnelId: string): Promise<void>;
50
35
  deleteTunnel(accountId: string, tunnelId: string): Promise<void>;
51
- listDnsRecords(zoneId: string, query?: {
52
- name?: string;
53
- comment?: string;
54
- }): Promise<CloudflareDnsRecord[]>;
55
- createDnsRecord(zoneId: string, spec: DnsRecordSpec): Promise<CloudflareDnsRecord>;
56
- deleteDnsRecord(zoneId: string, recordId: string): Promise<void>;
57
- }
58
-
59
- interface CloudflareDnsOptions {
60
- apiToken: string;
61
- zoneId?: string;
62
- apiBase?: string;
63
- fetcher?: typeof fetch;
64
36
  }
65
- declare function createCloudflareDns(options: CloudflareDnsOptions): DnsAdapter;
66
37
 
67
38
  interface CloudflareTunnelOptions {
68
39
  cloudflaredPath?: string;
@@ -78,9 +49,8 @@ interface CloudflareTunnelOptions {
78
49
  declare function createCloudflareTunnel(options?: CloudflareTunnelOptions): TunnelAdapter;
79
50
  declare const cloudflareTunnel: TunnelAdapter;
80
51
 
81
- declare const CLOUDFLARE_DNS_ADAPTER_ID = "cloudflare";
82
52
  declare const CLOUDFLARE_TUNNEL_ADAPTER_ID = "cloudflare";
83
53
  declare const CLOUDFLARE_API_BASE = "https://api.cloudflare.com/client/v4";
84
54
 
85
- export { CLOUDFLARE_API_BASE, CLOUDFLARE_DNS_ADAPTER_ID, CLOUDFLARE_TUNNEL_ADAPTER_ID, CloudflareApi, cloudflareTunnel, createCloudflareDns, createCloudflareTunnel };
86
- export type { CloudflareAccount, CloudflareDnsOptions, CloudflareDnsRecord, CloudflareTunnel, CloudflareTunnelOptions, CloudflareZone };
55
+ export { CLOUDFLARE_API_BASE, CLOUDFLARE_TUNNEL_ADAPTER_ID, CloudflareApi, cloudflareTunnel, createCloudflareTunnel };
56
+ export type { CloudflareAccount, CloudflareTunnel, CloudflareTunnelOptions };
package/dist/index.mjs CHANGED
@@ -72,7 +72,7 @@ class CloudflareApi {
72
72
  if (result?.status !== "active") {
73
73
  throw new AdapterError("Cloudflare API token is not active", {
74
74
  code: "AUTH_INVALID",
75
- hint: "Create a token with Account Cloudflare Tunnel Edit and Zone DNS Edit"
75
+ hint: "Create a token with Account Cloudflare Tunnel Edit"
76
76
  });
77
77
  }
78
78
  }
@@ -95,30 +95,6 @@ class CloudflareApi {
95
95
  }
96
96
  });
97
97
  }
98
- async listZones(name) {
99
- const query = new URLSearchParams({ per_page: "50" });
100
- if (name) {
101
- query.set("name", name);
102
- }
103
- return this.request("GET", `/zones?${query.toString()}`);
104
- }
105
- async resolveZone(zone) {
106
- const zones = await this.listZones(zone);
107
- const match = zones.find((item) => item.name === zone);
108
- if (!match) {
109
- throw new AdapterError(`Zone "${zone}" was not found`, {
110
- code: "ZONE_NOT_FOUND",
111
- hint: "Check domain.zone, or set CLOUDFLARE_ZONE_ID"
112
- });
113
- }
114
- if (match.status !== "active") {
115
- throw new AdapterError(`Zone "${zone}" is ${match.status}`, {
116
- code: "ZONE_NOT_ACTIVE",
117
- hint: "Wait for the zone to become active in Cloudflare"
118
- });
119
- }
120
- return match;
121
- }
122
98
  async createTunnel(accountId, name) {
123
99
  return this.request("POST", `/accounts/${accountId}/cfd_tunnel`, {
124
100
  name,
@@ -154,134 +130,6 @@ class CloudflareApi {
154
130
  async deleteTunnel(accountId, tunnelId) {
155
131
  await this.request("DELETE", `/accounts/${accountId}/cfd_tunnel/${tunnelId}`);
156
132
  }
157
- async listDnsRecords(zoneId, query = {}) {
158
- const params = new URLSearchParams({ per_page: "100" });
159
- if (query.name) {
160
- params.set("name", query.name);
161
- }
162
- if (query.comment) {
163
- params.set("comment", query.comment);
164
- }
165
- return this.request("GET", `/zones/${zoneId}/dns_records?${params.toString()}`);
166
- }
167
- async createDnsRecord(zoneId, spec) {
168
- return this.request("POST", `/zones/${zoneId}/dns_records`, {
169
- type: spec.type,
170
- name: spec.name,
171
- content: spec.content,
172
- proxied: spec.proxied ?? false,
173
- ttl: spec.ttl ?? 1,
174
- comment: spec.comment
175
- });
176
- }
177
- async deleteDnsRecord(zoneId, recordId) {
178
- await this.request("DELETE", `/zones/${zoneId}/dns_records/${recordId}`);
179
- }
180
- }
181
-
182
- const OWNED_COMMENT_PREFIX = "flash-tunnel:";
183
- function isOwned(comment) {
184
- return comment?.startsWith(OWNED_COMMENT_PREFIX) ?? false;
185
- }
186
- function toRef(provider, zoneId, record) {
187
- return {
188
- provider,
189
- zoneId,
190
- recordId: record.id,
191
- name: record.name,
192
- type: record.type,
193
- content: record.content,
194
- proxied: record.proxied
195
- };
196
- }
197
- function createCloudflareDns(options) {
198
- const api = new CloudflareApi(options);
199
- const zoneIds = /* @__PURE__ */ new Map();
200
- async function zoneIdFor(zone) {
201
- if (options.zoneId) {
202
- return options.zoneId;
203
- }
204
- const cached = zoneIds.get(zone);
205
- if (cached) {
206
- return cached;
207
- }
208
- const resolved = await api.resolveZone(zone);
209
- zoneIds.set(zone, resolved.id);
210
- return resolved.id;
211
- }
212
- return {
213
- kind: "dns",
214
- id: "cloudflare",
215
- apiVersion: 1,
216
- capabilities: {
217
- recordTypes: ["CNAME", "A", "AAAA", "TXT"],
218
- proxied: true,
219
- ttl: true,
220
- comment: true,
221
- lookupByName: true
222
- },
223
- async preflight(_ctx, target) {
224
- await api.verifyToken();
225
- const zoneId = await zoneIdFor(target.zone);
226
- const existing = await api.listDnsRecords(zoneId, { name: target.name });
227
- const conflicts = existing.filter((record) => !isOwned(record.comment));
228
- if (conflicts.length > 0 && !target.overwrite) {
229
- throw new AdapterError(`DNS record "${target.name}" already exists`, {
230
- code: "RECORD_CONFLICT",
231
- hint: "Use a different subdomain, or pass --overwrite to replace a non-flash-tunnel record",
232
- details: {
233
- records: conflicts.map((record) => record.id)
234
- }
235
- });
236
- }
237
- },
238
- async ensure(_ctx, spec) {
239
- const zoneId = await zoneIdFor(spec.zone);
240
- const existing = await api.listDnsRecords(zoneId, { name: spec.name });
241
- for (const record of existing) {
242
- if (spec.overwrite || isOwned(record.comment)) {
243
- await api.deleteDnsRecord(zoneId, record.id).catch(() => {
244
- });
245
- }
246
- }
247
- try {
248
- const record = await api.createDnsRecord(zoneId, spec);
249
- return toRef("cloudflare", zoneId, record);
250
- } catch (error) {
251
- if (error instanceof AdapterError && error.code === "RECORD_CONFLICT") {
252
- const current = await api.listDnsRecords(zoneId, { name: spec.name });
253
- const owned = current.filter((record2) => isOwned(record2.comment));
254
- if (owned.length === 0) {
255
- throw error;
256
- }
257
- for (const record2 of owned) {
258
- await api.deleteDnsRecord(zoneId, record2.id);
259
- }
260
- const record = await api.createDnsRecord(zoneId, spec);
261
- return toRef("cloudflare", zoneId, record);
262
- }
263
- throw error;
264
- }
265
- },
266
- async remove(_ctx, ref) {
267
- try {
268
- await api.deleteDnsRecord(ref.zoneId, ref.recordId);
269
- } catch (error) {
270
- if (error instanceof AdapterError && error.code === "NOT_FOUND") {
271
- return;
272
- }
273
- throw error;
274
- }
275
- },
276
- async find(_ctx, query) {
277
- const zoneId = await zoneIdFor(query.zone);
278
- const records = await api.listDnsRecords(zoneId, {
279
- name: query.name,
280
- comment: query.comment
281
- });
282
- return records.map((record) => toRef("cloudflare", zoneId, record));
283
- }
284
- };
285
133
  }
286
134
 
287
135
  const ADAPTER_ID = "cloudflare";
@@ -388,13 +236,6 @@ function createCloudflareTunnel(options = {}) {
388
236
  capabilities: {
389
237
  modes: ["named", "quick"],
390
238
  publicHostname: "both",
391
- requiresDns: false,
392
- dns: {
393
- type: "CNAME",
394
- targetFrom: "handle",
395
- proxied: true,
396
- providerAffinity: ["cloudflare"]
397
- },
398
239
  concurrent: true
399
240
  },
400
241
  async preflight(ctx, { mode }) {
@@ -427,7 +268,7 @@ function createCloudflareTunnel(options = {}) {
427
268
  if (spec.hostname === void 0) {
428
269
  throw new AdapterError("Named tunnel requires a hostname", {
429
270
  code: "TUNNEL_CREATE_FAILED",
430
- hint: "Set domain.zone (and optionally domain.subdomain) in flash-tunnel.ts"
271
+ hint: "Set tunnel.hostname in flash-nexus.config.ts or pass --hostname"
431
272
  });
432
273
  }
433
274
  const client = requireApi();
@@ -454,7 +295,7 @@ function createCloudflareTunnel(options = {}) {
454
295
  tunnelId: tunnel.id,
455
296
  name: spec.name,
456
297
  publicUrl: `https://${spec.hostname}`,
457
- dns: {
298
+ target: {
458
299
  type: "CNAME",
459
300
  target: `${tunnel.id}.cfargotunnel.com`,
460
301
  proxied: true
@@ -640,8 +481,7 @@ ${output.slice(-10).join("\n")}` : ""}`,
640
481
  }
641
482
  const cloudflareTunnel = createCloudflareTunnel();
642
483
 
643
- const CLOUDFLARE_DNS_ADAPTER_ID = "cloudflare";
644
484
  const CLOUDFLARE_TUNNEL_ADAPTER_ID = "cloudflare";
645
485
  const CLOUDFLARE_API_BASE = "https://api.cloudflare.com/client/v4";
646
486
 
647
- export { CLOUDFLARE_API_BASE, CLOUDFLARE_DNS_ADAPTER_ID, CLOUDFLARE_TUNNEL_ADAPTER_ID, CloudflareApi, cloudflareTunnel, createCloudflareDns, createCloudflareTunnel };
487
+ export { CLOUDFLARE_API_BASE, CLOUDFLARE_TUNNEL_ADAPTER_ID, CloudflareApi, cloudflareTunnel, createCloudflareTunnel };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@flash-tunnel/adapter-cloudflare",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "license": "MIT",
6
- "homepage": "https://github.com/flash-tunnel/flash-tunnel#readme",
6
+ "homepage": "https://github.com/flash-nexus/flash-tunnel#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/flash-tunnel/flash-tunnel.git"
9
+ "url": "git+https://github.com/flash-nexus/flash-tunnel.git"
10
10
  },
11
11
  "bugs": {
12
- "url": "https://github.com/flash-tunnel/flash-tunnel/issues"
12
+ "url": "https://github.com/flash-nexus/flash-tunnel/issues"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
@@ -30,8 +30,8 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@flash-tunnel/types": "0.3.0",
34
- "@flash-tunnel/utils": "0.3.0"
33
+ "@flash-tunnel/types": "0.4.0",
34
+ "@flash-tunnel/utils": "0.4.0"
35
35
  },
36
36
  "scripts": {
37
37
  "stub": "unbuild --stub",