@wtfalch/edge 0.5.1 → 0.6.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/README.md +11 -0
- package/dist/client.d.ts +25 -1
- package/dist/client.js +28 -0
- package/dist/types.d.ts +95 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,17 @@ await edge.platform.tunnels.putConfig(tunnel.id, {
|
|
|
61
61
|
const { token } = await edge.platform.tunnels.token(tunnel.id);
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
```ts
|
|
65
|
+
// With the platform credential only: an Access app and its policy
|
|
66
|
+
const app = await edge.platform.access.create({ name: 'gate', domain: 'app.acme.com' });
|
|
67
|
+
await edge.platform.access.createPolicy(app.id, {
|
|
68
|
+
name: 'staff',
|
|
69
|
+
decision: 'allow',
|
|
70
|
+
include: [{ email: { email: 'a@acme.com' } }],
|
|
71
|
+
});
|
|
72
|
+
const { token } = await edge.platform.access.findServiceToken('ci'); // id and name, never a secret
|
|
73
|
+
```
|
|
74
|
+
|
|
64
75
|
The key carries the organisation and the one domain its names live under, so
|
|
65
76
|
no call names either. `claim` is safe to repeat: the same `ref` returns the same
|
|
66
77
|
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, 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';
|
|
2
|
+
import type { AdoptAccessAppsRequest, AdoptAccessAppsResponse, AdoptRecordsRequest, AdoptRecordsResponse, AdoptTunnelsRequest, AdoptTunnelsResponse, AvailableResponse, ClaimNameRequest, CreatePlatformAccessAppRequest, CreatePlatformAccessPolicyRequest, CreatePlatformRecordRequest, CreatePlatformTunnelRequest, FindServiceTokenResponse, ListClaimsResponse, ListPlatformAccessAppsRequest, ListPlatformAccessAppsResponse, ListPlatformAccessPoliciesResponse, ListPlatformRecordsRequest, ListPlatformRecordsResponse, ListPlatformTunnelsResponse, ListRecordsResponse, MintKeyRequest, MintKeyResponse, NameClaim, OrgSettingsRequest, PlatformAccessAppView, PlatformAccessPolicyView, 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
|
|
@@ -61,6 +61,30 @@ export declare function createEdgeClient(options: ClientOptions): {
|
|
|
61
61
|
* or recreated, and a tunnel nobody names is left alone. */
|
|
62
62
|
adopt: (input: AdoptTunnelsRequest) => Promise<AdoptTunnelsResponse>;
|
|
63
63
|
};
|
|
64
|
+
/** Cloudflare Access applications the platform owns, and their policies.
|
|
65
|
+
* `id` is Cloudflare's app id. */
|
|
66
|
+
access: {
|
|
67
|
+
/** Every live app with its owner (`null`: no row), optionally narrowed
|
|
68
|
+
* by exact `domain` and/or `name`. */
|
|
69
|
+
list: (filter?: ListPlatformAccessAppsRequest) => Promise<ListPlatformAccessAppsResponse>;
|
|
70
|
+
/** Creates the app, or returns the one edge already made for that
|
|
71
|
+
* domain and name. Rejects with `conflict` when a live app holds the
|
|
72
|
+
* domain that nobody adopted (adopt it instead). */
|
|
73
|
+
create: (input: CreatePlatformAccessAppRequest) => Promise<PlatformAccessAppView>;
|
|
74
|
+
/** Deletes the app; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
75
|
+
remove: (id: string) => Promise<PlatformAccessAppView>;
|
|
76
|
+
/** The policies on an app the platform owns. */
|
|
77
|
+
listPolicies: (appId: string) => Promise<ListPlatformAccessPoliciesResponse>;
|
|
78
|
+
/** Adds a policy. The same name with the same content returns it as it
|
|
79
|
+
* is (safe to repeat); the same name with other content rejects with `conflict`. */
|
|
80
|
+
createPolicy: (appId: string, input: CreatePlatformAccessPolicyRequest) => Promise<PlatformAccessPolicyView>;
|
|
81
|
+
/** A service token's id by exact name; `token` is `null` when none has
|
|
82
|
+
* it. Read-only: the secret is never returned. */
|
|
83
|
+
findServiceToken: (name: string) => Promise<FindServiceTokenResponse>;
|
|
84
|
+
/** Writes platform rows for the live apps named. Nothing is deleted or
|
|
85
|
+
* recreated, and an app nobody names is left alone. */
|
|
86
|
+
adopt: (input: AdoptAccessAppsRequest) => Promise<AdoptAccessAppsResponse>;
|
|
87
|
+
};
|
|
64
88
|
};
|
|
65
89
|
/** True when the name is free: not reserved, no record in the zone, not claimed. */
|
|
66
90
|
available: (name: string) => Promise<AvailableResponse>;
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { createTransport } from './transport.js';
|
|
2
2
|
export { EdgeApiError } from './transport.js';
|
|
3
|
+
function query(values) {
|
|
4
|
+
const search = new URLSearchParams(Object.entries(values).filter((entry) => entry[1] !== undefined)).toString();
|
|
5
|
+
return search === '' ? '' : `?${search}`;
|
|
6
|
+
}
|
|
3
7
|
/** Called with an entry's key: the key carries its organisation and domain, so
|
|
4
8
|
* no call names either. `setReservedLabels`, `mintKey` and `revokeKey` are
|
|
5
9
|
* refused by the service for any credential but the platform's own. */
|
|
@@ -60,6 +64,30 @@ export function createEdgeClient(options) {
|
|
|
60
64
|
* or recreated, and a tunnel nobody names is left alone. */
|
|
61
65
|
adopt: (input) => call('POST', '/v1/platform/tunnels/adopt', input),
|
|
62
66
|
},
|
|
67
|
+
/** Cloudflare Access applications the platform owns, and their policies.
|
|
68
|
+
* `id` is Cloudflare's app id. */
|
|
69
|
+
access: {
|
|
70
|
+
/** Every live app with its owner (`null`: no row), optionally narrowed
|
|
71
|
+
* by exact `domain` and/or `name`. */
|
|
72
|
+
list: (filter = {}) => call('GET', `/v1/platform/access/apps${query(filter)}`),
|
|
73
|
+
/** Creates the app, or returns the one edge already made for that
|
|
74
|
+
* domain and name. Rejects with `conflict` when a live app holds the
|
|
75
|
+
* domain that nobody adopted (adopt it instead). */
|
|
76
|
+
create: (input) => call('POST', '/v1/platform/access/apps', input),
|
|
77
|
+
/** Deletes the app; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
78
|
+
remove: (id) => call('DELETE', `/v1/platform/access/apps/${encodeURIComponent(id)}`),
|
|
79
|
+
/** The policies on an app the platform owns. */
|
|
80
|
+
listPolicies: (appId) => call('GET', `/v1/platform/access/apps/${encodeURIComponent(appId)}/policies`),
|
|
81
|
+
/** Adds a policy. The same name with the same content returns it as it
|
|
82
|
+
* is (safe to repeat); the same name with other content rejects with `conflict`. */
|
|
83
|
+
createPolicy: (appId, input) => call('POST', `/v1/platform/access/apps/${encodeURIComponent(appId)}/policies`, input),
|
|
84
|
+
/** A service token's id by exact name; `token` is `null` when none has
|
|
85
|
+
* it. Read-only: the secret is never returned. */
|
|
86
|
+
findServiceToken: (name) => call('GET', `/v1/platform/access/service-tokens?${new URLSearchParams({ name })}`),
|
|
87
|
+
/** Writes platform rows for the live apps named. Nothing is deleted or
|
|
88
|
+
* recreated, and an app nobody names is left alone. */
|
|
89
|
+
adopt: (input) => call('POST', '/v1/platform/access/apps/adopt', input),
|
|
90
|
+
},
|
|
63
91
|
},
|
|
64
92
|
/** True when the name is free: not reserved, no record in the zone, not claimed. */
|
|
65
93
|
available: (name) => call('GET', `/v1/names/available?${new URLSearchParams({ name })}`),
|
package/dist/types.d.ts
CHANGED
|
@@ -101,8 +101,9 @@ export interface OrgSettingsRequest {
|
|
|
101
101
|
* soon. `pending`: still being set up. `removing`: teardown in progress, retry
|
|
102
102
|
* the remove. `taken`: the name or ref belongs to something else; do not
|
|
103
103
|
* retry. `held`: the name was removed less than 30 days ago; do not retry
|
|
104
|
-
* until the hold ends. `
|
|
105
|
-
|
|
104
|
+
* until the hold ends. `exists`: a tunnel of that name already exists at
|
|
105
|
+
* Cloudflare; adopt it instead. `upstream_rejected`: Cloudflare permanently refused; do not retry. */
|
|
106
|
+
export type EdgeConflictReason = 'busy' | 'pending' | 'removing' | 'taken' | 'held' | 'exists' | 'upstream_rejected';
|
|
106
107
|
export type RecordType = 'TXT' | 'MX' | 'CNAME' | 'A' | 'AAAA' | 'CAA';
|
|
107
108
|
/** CAA's structured value, in Cloudflare's form. */
|
|
108
109
|
export interface CaaData {
|
|
@@ -269,6 +270,8 @@ export interface CreatePlatformTunnelRequest {
|
|
|
269
270
|
/** One ingress rule. Every rule but the last names a hostname; the last is the catch-all. */
|
|
270
271
|
export interface TunnelIngressRule {
|
|
271
272
|
hostname?: string;
|
|
273
|
+
/** A regex Cloudflare matches against the request path, to tell rules on one hostname apart. */
|
|
274
|
+
path?: string;
|
|
272
275
|
service: string;
|
|
273
276
|
originRequest?: Record<string, unknown>;
|
|
274
277
|
}
|
|
@@ -299,3 +302,93 @@ export interface AdoptTunnelsResponse {
|
|
|
299
302
|
/** Live tunnels no entry named. Reported, never touched. */
|
|
300
303
|
unclaimed: PlatformTunnelView[];
|
|
301
304
|
}
|
|
305
|
+
/** An Access application seen with the platform credential. `id` is Cloudflare's
|
|
306
|
+
* app id, which every platform Access call takes. */
|
|
307
|
+
export interface PlatformAccessAppView {
|
|
308
|
+
id: string;
|
|
309
|
+
name: string;
|
|
310
|
+
domain: string;
|
|
311
|
+
/** Who owns it: the platform, or `null` when no row exists (a live app
|
|
312
|
+
* nobody adopted: reported, never touched). */
|
|
313
|
+
owner: 'platform' | null;
|
|
314
|
+
/** The company the app serves; `'platform'` when none. `null` for an app with no row. */
|
|
315
|
+
organisationId: string | null;
|
|
316
|
+
state: 'pending' | 'active' | 'removing' | 'removed';
|
|
317
|
+
}
|
|
318
|
+
export interface ListPlatformAccessAppsRequest {
|
|
319
|
+
/** Only the app on exactly this domain. */
|
|
320
|
+
domain?: string;
|
|
321
|
+
/** Only the apps with exactly this name. */
|
|
322
|
+
name?: string;
|
|
323
|
+
}
|
|
324
|
+
export interface ListPlatformAccessAppsResponse {
|
|
325
|
+
apps: PlatformAccessAppView[];
|
|
326
|
+
}
|
|
327
|
+
/** Creates the app, or returns the one edge already made for that domain and name. */
|
|
328
|
+
export interface CreatePlatformAccessAppRequest {
|
|
329
|
+
name: string;
|
|
330
|
+
/** A lower-case hostname, optionally with a leading `*.`. */
|
|
331
|
+
domain: string;
|
|
332
|
+
/** Only `self_hosted` is supported (the default). */
|
|
333
|
+
type?: 'self_hosted';
|
|
334
|
+
/** Like `30m` or `24h`. */
|
|
335
|
+
sessionDuration?: string;
|
|
336
|
+
autoRedirectToIdentity?: boolean;
|
|
337
|
+
/** The company the app serves. Omit for an app that serves none. */
|
|
338
|
+
organisationId?: string;
|
|
339
|
+
}
|
|
340
|
+
/** One Access rule, in Cloudflare's own shape: `{ email: { email } }`, `{ everyone: {} }`, `{ service_token: { token_id } }`. */
|
|
341
|
+
export type AccessRule = Record<string, unknown>;
|
|
342
|
+
export type AccessDecision = 'allow' | 'deny' | 'non_identity' | 'bypass';
|
|
343
|
+
export interface PlatformAccessPolicyView {
|
|
344
|
+
id: string;
|
|
345
|
+
name: string;
|
|
346
|
+
decision: AccessDecision;
|
|
347
|
+
include: AccessRule[];
|
|
348
|
+
exclude?: AccessRule[];
|
|
349
|
+
require?: AccessRule[];
|
|
350
|
+
}
|
|
351
|
+
export interface ListPlatformAccessPoliciesResponse {
|
|
352
|
+
policies: PlatformAccessPolicyView[];
|
|
353
|
+
}
|
|
354
|
+
/** Adds a policy to an app the platform owns. At least one `include` rule is required. */
|
|
355
|
+
export interface CreatePlatformAccessPolicyRequest {
|
|
356
|
+
name: string;
|
|
357
|
+
decision: AccessDecision;
|
|
358
|
+
include: AccessRule[];
|
|
359
|
+
exclude?: AccessRule[];
|
|
360
|
+
require?: AccessRule[];
|
|
361
|
+
}
|
|
362
|
+
/** A service token's id and name. Its secret is never returned. */
|
|
363
|
+
export interface FindServiceTokenResponse {
|
|
364
|
+
token: {
|
|
365
|
+
id: string;
|
|
366
|
+
name: string;
|
|
367
|
+
} | null;
|
|
368
|
+
}
|
|
369
|
+
export interface AdoptAccessAppEntry {
|
|
370
|
+
name: string;
|
|
371
|
+
/** Narrows several apps of one name. */
|
|
372
|
+
domain?: string;
|
|
373
|
+
/** Cloudflare's id, when the caller recorded it: the match must carry it. */
|
|
374
|
+
id?: string;
|
|
375
|
+
}
|
|
376
|
+
export interface AdoptAccessAppsRequest {
|
|
377
|
+
apps: AdoptAccessAppEntry[];
|
|
378
|
+
/** The company the adopted apps serve. Omit for none. */
|
|
379
|
+
organisationId?: string;
|
|
380
|
+
}
|
|
381
|
+
export interface AdoptAccessAppsResponse {
|
|
382
|
+
adopted: PlatformAccessAppView[];
|
|
383
|
+
alreadyAdopted: PlatformAccessAppView[];
|
|
384
|
+
/** `taken`: a row for that domain exists. `unsupported_type`: the app has
|
|
385
|
+
* no domain (not self-hosted). */
|
|
386
|
+
skipped: Array<{
|
|
387
|
+
app: PlatformAccessAppView;
|
|
388
|
+
reason: 'taken' | 'unsupported_type';
|
|
389
|
+
}>;
|
|
390
|
+
/** Entries with no live app. Nothing is created for them. */
|
|
391
|
+
notFound: AdoptAccessAppEntry[];
|
|
392
|
+
/** Live apps no entry named. Reported, never touched. */
|
|
393
|
+
unclaimed: PlatformAccessAppView[];
|
|
394
|
+
}
|