@wtfalch/edge 0.4.0 → 0.5.1

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,6 +48,19 @@ await edge.platform.dns.create({
48
48
  });
49
49
  ```
50
50
 
51
+ ```ts
52
+ // With the platform credential only: a tunnel with many hostnames
53
+ const tunnel = await edge.platform.tunnels.create({ name: 'acme-tunnel' });
54
+ await edge.platform.tunnels.putConfig(tunnel.id, {
55
+ ingress: [
56
+ { hostname: 'app.acme.com', service: 'http://proxy:80' },
57
+ { hostname: 'cms.acme.com', service: 'http://proxy:80' },
58
+ { service: 'http_status:404' },
59
+ ],
60
+ });
61
+ const { token } = await edge.platform.tunnels.token(tunnel.id);
62
+ ```
63
+
51
64
  The key carries the organisation and the one domain its names live under, so
52
65
  no call names either. `claim` is safe to repeat: the same `ref` returns the same
53
66
  claim, and a new `port` moves its route. `get(ref)` finds the claim for a `ref` without listing. `close` makes the name answer 404 and
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type ClientOptions } from './transport.js';
2
- import type { AdoptRecordsRequest, AdoptRecordsResponse, AvailableResponse, ClaimNameRequest, CreatePlatformRecordRequest, ListClaimsResponse, ListPlatformRecordsRequest, ListPlatformRecordsResponse, ListRecordsResponse, MintKeyRequest, MintKeyResponse, NameClaim, OrgSettingsRequest, PlatformRecordView, RecordInput, RecordPatch, RecordView, TokenResponse, UpdatePlatformRecordRequest } from './types.js';
2
+ import type { AdoptRecordsRequest, AdoptRecordsResponse, AdoptTunnelsRequest, AdoptTunnelsResponse, AvailableResponse, ClaimNameRequest, CreatePlatformRecordRequest, CreatePlatformTunnelRequest, ListClaimsResponse, ListPlatformRecordsRequest, ListPlatformRecordsResponse, ListPlatformTunnelsResponse, ListRecordsResponse, MintKeyRequest, MintKeyResponse, NameClaim, OrgSettingsRequest, PlatformRecordView, PlatformTunnelView, PutPlatformTunnelConfigRequest, RecordInput, RecordPatch, RecordView, TokenResponse, UpdatePlatformRecordRequest } from './types.js';
3
3
  export { EdgeApiError, type ClientOptions } from './transport.js';
4
4
  /** Called with an entry's key: the key carries its organisation and domain, so
5
5
  * no call names either. `setReservedLabels`, `mintKey` and `revokeKey` are
@@ -39,6 +39,28 @@ export declare function createEdgeClient(options: ClientOptions): {
39
39
  * deleted or recreated, and a record nobody names is left alone. */
40
40
  adopt: (input: AdoptRecordsRequest) => Promise<AdoptRecordsResponse>;
41
41
  };
42
+ /** Tunnels the platform owns, one per company or service, each with
43
+ * many hostnames in its ingress. A name claim's own tunnel is never
44
+ * reachable here. `id` is Cloudflare's tunnel id. */
45
+ tunnels: {
46
+ /** Every live tunnel with its owner, optionally only the one named `name`. */
47
+ list: (filter?: {
48
+ name?: string;
49
+ }) => Promise<ListPlatformTunnelsResponse>;
50
+ /** Creates the tunnel, or returns the one edge already made under that
51
+ * name. Rejects with `conflict` when a live tunnel of that name exists
52
+ * that nobody adopted (adopt it instead). */
53
+ create: (input: CreatePlatformTunnelRequest) => Promise<PlatformTunnelView>;
54
+ /** Replaces the tunnel's whole ingress. */
55
+ putConfig: (id: string, input: PutPlatformTunnelConfigRequest) => Promise<PlatformTunnelView>;
56
+ /** The connector token: a secret. Hand it to the connector and nowhere else. */
57
+ token: (id: string) => Promise<TokenResponse>;
58
+ /** Drops the connections and deletes the tunnel; returns the tombstone. */
59
+ remove: (id: string) => Promise<PlatformTunnelView>;
60
+ /** Writes platform rows for the live tunnels named. Nothing is deleted
61
+ * or recreated, and a tunnel nobody names is left alone. */
62
+ adopt: (input: AdoptTunnelsRequest) => Promise<AdoptTunnelsResponse>;
63
+ };
42
64
  };
43
65
  /** True when the name is free: not reserved, no record in the zone, not claimed. */
44
66
  available: (name: string) => Promise<AvailableResponse>;
package/dist/client.js CHANGED
@@ -40,6 +40,26 @@ export function createEdgeClient(options) {
40
40
  * deleted or recreated, and a record nobody names is left alone. */
41
41
  adopt: (input) => call('POST', '/v1/platform/dns/adopt', input),
42
42
  },
43
+ /** Tunnels the platform owns, one per company or service, each with
44
+ * many hostnames in its ingress. A name claim's own tunnel is never
45
+ * reachable here. `id` is Cloudflare's tunnel id. */
46
+ tunnels: {
47
+ /** Every live tunnel with its owner, optionally only the one named `name`. */
48
+ list: (filter = {}) => call('GET', `/v1/platform/tunnels${filter.name === undefined ? '' : `?${new URLSearchParams({ name: filter.name })}`}`),
49
+ /** Creates the tunnel, or returns the one edge already made under that
50
+ * name. Rejects with `conflict` when a live tunnel of that name exists
51
+ * that nobody adopted (adopt it instead). */
52
+ create: (input) => call('POST', '/v1/platform/tunnels', input),
53
+ /** Replaces the tunnel's whole ingress. */
54
+ putConfig: (id, input) => call('PUT', `/v1/platform/tunnels/${encodeURIComponent(id)}/config`, input),
55
+ /** The connector token: a secret. Hand it to the connector and nowhere else. */
56
+ token: (id) => call('GET', `/v1/platform/tunnels/${encodeURIComponent(id)}/token`),
57
+ /** Drops the connections and deletes the tunnel; returns the tombstone. */
58
+ remove: (id) => call('DELETE', `/v1/platform/tunnels/${encodeURIComponent(id)}`),
59
+ /** Writes platform rows for the live tunnels named. Nothing is deleted
60
+ * or recreated, and a tunnel nobody names is left alone. */
61
+ adopt: (input) => call('POST', '/v1/platform/tunnels/adopt', input),
62
+ },
43
63
  },
44
64
  /** True when the name is free: not reserved, no record in the zone, not claimed. */
45
65
  available: (name) => call('GET', `/v1/names/available?${new URLSearchParams({ name })}`),
package/dist/types.d.ts CHANGED
@@ -243,3 +243,59 @@ export interface AdoptRecordsResponse {
243
243
  /** Live records no entry named. Reported, never touched. */
244
244
  unclaimed: PlatformRecordView[];
245
245
  }
246
+ /** A tunnel seen with the platform credential. `id` is Cloudflare's tunnel id,
247
+ * which every platform tunnel call takes. */
248
+ export interface PlatformTunnelView {
249
+ id: string;
250
+ name: string;
251
+ /** Who owns it: the platform, a name claim (an organisation's own: never
252
+ * touched here), or `null` when no row exists (a live tunnel nobody
253
+ * adopted: reported, never touched). */
254
+ owner: 'platform' | 'organisation' | null;
255
+ /** The company the tunnel serves; `'platform'` when none. `null` for a tunnel with no row. */
256
+ organisationId: string | null;
257
+ state: 'pending' | 'active' | 'removing' | 'removed';
258
+ }
259
+ export interface ListPlatformTunnelsResponse {
260
+ tunnels: PlatformTunnelView[];
261
+ }
262
+ /** Creates the named tunnel, or returns the one edge already made for it. */
263
+ export interface CreatePlatformTunnelRequest {
264
+ /** Lower-case letters, digits, dots, dashes and underscores; not `names-…`. */
265
+ name: string;
266
+ /** The company the tunnel serves. Omit for a tunnel that serves none. */
267
+ organisationId?: string;
268
+ }
269
+ /** One ingress rule. Every rule but the last names a hostname; the last is the catch-all. */
270
+ export interface TunnelIngressRule {
271
+ hostname?: string;
272
+ service: string;
273
+ originRequest?: Record<string, unknown>;
274
+ }
275
+ /** Replaces the tunnel's whole ingress (at most 100 rules). */
276
+ export interface PutPlatformTunnelConfigRequest {
277
+ ingress: TunnelIngressRule[];
278
+ }
279
+ export interface AdoptTunnelEntry {
280
+ name: string;
281
+ /** Cloudflare's id, when the caller recorded it: the match must carry it. */
282
+ id?: string;
283
+ }
284
+ export interface AdoptTunnelsRequest {
285
+ tunnels: AdoptTunnelEntry[];
286
+ /** The company the adopted tunnels serve. Omit for none. */
287
+ organisationId?: string;
288
+ }
289
+ export interface AdoptTunnelsResponse {
290
+ adopted: PlatformTunnelView[];
291
+ alreadyAdopted: PlatformTunnelView[];
292
+ /** `organisation`: a name claim's tunnel. `taken`: a row with that name exists. */
293
+ skipped: Array<{
294
+ tunnel: PlatformTunnelView;
295
+ reason: 'organisation' | 'taken';
296
+ }>;
297
+ /** Entries with no live tunnel. Nothing is created for them. */
298
+ notFound: AdoptTunnelEntry[];
299
+ /** Live tunnels no entry named. Reported, never touched. */
300
+ unclaimed: PlatformTunnelView[];
301
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wtfalch/edge",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Public client SDK and API types for the edge service.",