@wtfalch/edge 0.6.0 → 0.8.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/client.d.ts +48 -1
- package/dist/client.js +45 -0
- package/dist/types.d.ts +175 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ClientOptions } from './transport.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';
|
|
2
|
+
import type { AdoptAccessAppsRequest, AdoptAccessAppsResponse, AdoptRateLimitRulesRequest, AdoptRateLimitRulesResponse, AdoptRecordsRequest, AdoptRecordsResponse, AdoptTunnelsRequest, AdoptTunnelsResponse, AdoptWorkersRequest, AdoptWorkersResponse, AvailableResponse, ClaimNameRequest, CreatePlatformAccessAppRequest, CreatePlatformAccessPolicyRequest, CreatePlatformRateLimitRuleRequest, CreatePlatformRecordRequest, CreatePlatformTunnelRequest, CreatePlatformWorkerRouteRequest, FindServiceTokenResponse, ListClaimsResponse, ListPlatformAccessAppsRequest, ListPlatformAccessAppsResponse, ListPlatformAccessPoliciesResponse, ListPlatformRateLimitRulesRequest, ListPlatformRateLimitRulesResponse, ListPlatformRecordsRequest, ListPlatformRecordsResponse, ListPlatformTunnelsResponse, ListPlatformWorkerRoutesRequest, ListPlatformWorkerRoutesResponse, ListPlatformWorkerScriptsResponse, ListRecordsResponse, MintKeyRequest, MintKeyResponse, NameClaim, OrgSettingsRequest, PlatformAccessAppView, PlatformAccessPolicyView, PlatformRateLimitRuleView, PlatformRecordView, PlatformTunnelView, PlatformWorkerRouteView, PlatformWorkerScriptView, PutPlatformTunnelConfigRequest, RecordInput, RecordPatch, RecordView, TokenResponse, UpdatePlatformRecordRequest, UploadPlatformWorkerScriptRequest } 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
|
|
@@ -85,6 +85,53 @@ export declare function createEdgeClient(options: ClientOptions): {
|
|
|
85
85
|
* recreated, and an app nobody names is left alone. */
|
|
86
86
|
adopt: (input: AdoptAccessAppsRequest) => Promise<AdoptAccessAppsResponse>;
|
|
87
87
|
};
|
|
88
|
+
/** Cloudflare rate limiting rules the platform owns. A zone's rules share
|
|
89
|
+
* one ruleset, so each rule is owned on its own; a rule's `id` is
|
|
90
|
+
* Cloudflare's rule id. */
|
|
91
|
+
ratelimits: {
|
|
92
|
+
/** Every live rule in the zone with its owner (`null`: no row), optionally only one description. */
|
|
93
|
+
list: (filter: ListPlatformRateLimitRulesRequest) => Promise<ListPlatformRateLimitRulesResponse>;
|
|
94
|
+
/** Creates the rule, or returns the one edge already made for that zone
|
|
95
|
+
* and description (201 when new, 200 after). Rejects with `conflict` when
|
|
96
|
+
* a live rule with that description exists that nobody adopted (adopt it
|
|
97
|
+
* instead, reason `exists`) or another create of it is in progress
|
|
98
|
+
* (reason `busy`), and with `conflict` (reason `upstream_rejected`) when Cloudflare
|
|
99
|
+
* refuses the rule for good. */
|
|
100
|
+
create: (input: CreatePlatformRateLimitRuleRequest) => Promise<PlatformRateLimitRuleView>;
|
|
101
|
+
/** Deletes that one rule; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
102
|
+
remove: (zoneId: string, id: string) => Promise<PlatformRateLimitRuleView>;
|
|
103
|
+
/** Writes platform rows for the rules named. Nothing is changed at
|
|
104
|
+
* Cloudflare, and anything nobody names is left alone. */
|
|
105
|
+
adopt: (input: AdoptRateLimitRulesRequest) => Promise<AdoptRateLimitRulesResponse>;
|
|
106
|
+
};
|
|
107
|
+
/** Cloudflare Workers scripts and routes the platform owns. A script's
|
|
108
|
+
* `id` is its name; a route's `id` is Cloudflare's route id. */
|
|
109
|
+
workers: {
|
|
110
|
+
/** Every live script with its owner (`null`: no row), optionally only the one named `name`. */
|
|
111
|
+
listScripts: (filter?: {
|
|
112
|
+
name?: string;
|
|
113
|
+
}) => Promise<ListPlatformWorkerScriptsResponse>;
|
|
114
|
+
/** Uploads the script (base64, at most 10 MB), or redeploys the one edge
|
|
115
|
+
* already owns (201 on the first upload, 200 after). Rejects with
|
|
116
|
+
* `conflict` when a live script of that name exists that nobody adopted
|
|
117
|
+
* (adopt it instead) or another upload of the name is in progress, and
|
|
118
|
+
* with `invalid_request` when the script is not base64 or its sha256
|
|
119
|
+
* differs from `artifactSha256`. */
|
|
120
|
+
uploadScript: (name: string, input: UploadPlatformWorkerScriptRequest) => Promise<PlatformWorkerScriptView>;
|
|
121
|
+
/** Deletes the script; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
122
|
+
removeScript: (name: string) => Promise<PlatformWorkerScriptView>;
|
|
123
|
+
/** Every live route in the zone with its owner (`null`: no row), optionally only one pattern. */
|
|
124
|
+
listRoutes: (filter: ListPlatformWorkerRoutesRequest) => Promise<ListPlatformWorkerRoutesResponse>;
|
|
125
|
+
/** Creates the route, or returns the one edge already made for that
|
|
126
|
+
* zone, pattern and script. Rejects with `conflict` when a live route
|
|
127
|
+
* holds the pattern that nobody adopted (adopt it instead). */
|
|
128
|
+
createRoute: (input: CreatePlatformWorkerRouteRequest) => Promise<PlatformWorkerRouteView>;
|
|
129
|
+
/** Deletes the route in `zoneId`; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
130
|
+
removeRoute: (zoneId: string, id: string) => Promise<PlatformWorkerRouteView>;
|
|
131
|
+
/** Writes platform rows for the scripts and routes named. Nothing is
|
|
132
|
+
* deleted or recreated, and anything nobody names is left alone. */
|
|
133
|
+
adopt: (input: AdoptWorkersRequest) => Promise<AdoptWorkersResponse>;
|
|
134
|
+
};
|
|
88
135
|
};
|
|
89
136
|
/** True when the name is free: not reserved, no record in the zone, not claimed. */
|
|
90
137
|
available: (name: string) => Promise<AvailableResponse>;
|
package/dist/client.js
CHANGED
|
@@ -88,6 +88,51 @@ export function createEdgeClient(options) {
|
|
|
88
88
|
* recreated, and an app nobody names is left alone. */
|
|
89
89
|
adopt: (input) => call('POST', '/v1/platform/access/apps/adopt', input),
|
|
90
90
|
},
|
|
91
|
+
/** Cloudflare rate limiting rules the platform owns. A zone's rules share
|
|
92
|
+
* one ruleset, so each rule is owned on its own; a rule's `id` is
|
|
93
|
+
* Cloudflare's rule id. */
|
|
94
|
+
ratelimits: {
|
|
95
|
+
/** Every live rule in the zone with its owner (`null`: no row), optionally only one description. */
|
|
96
|
+
list: (filter) => call('GET', `/v1/platform/ratelimits/rules?${new URLSearchParams(Object.entries(filter).filter((entry) => entry[1] !== undefined))}`),
|
|
97
|
+
/** Creates the rule, or returns the one edge already made for that zone
|
|
98
|
+
* and description (201 when new, 200 after). Rejects with `conflict` when
|
|
99
|
+
* a live rule with that description exists that nobody adopted (adopt it
|
|
100
|
+
* instead, reason `exists`) or another create of it is in progress
|
|
101
|
+
* (reason `busy`), and with `conflict` (reason `upstream_rejected`) when Cloudflare
|
|
102
|
+
* refuses the rule for good. */
|
|
103
|
+
create: (input) => call('POST', '/v1/platform/ratelimits/rules', input),
|
|
104
|
+
/** Deletes that one rule; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
105
|
+
remove: (zoneId, id) => call('DELETE', `/v1/platform/ratelimits/rules/${encodeURIComponent(id)}?${new URLSearchParams({ zoneId })}`),
|
|
106
|
+
/** Writes platform rows for the rules named. Nothing is changed at
|
|
107
|
+
* Cloudflare, and anything nobody names is left alone. */
|
|
108
|
+
adopt: (input) => call('POST', '/v1/platform/ratelimits/adopt', input),
|
|
109
|
+
},
|
|
110
|
+
/** Cloudflare Workers scripts and routes the platform owns. A script's
|
|
111
|
+
* `id` is its name; a route's `id` is Cloudflare's route id. */
|
|
112
|
+
workers: {
|
|
113
|
+
/** Every live script with its owner (`null`: no row), optionally only the one named `name`. */
|
|
114
|
+
listScripts: (filter = {}) => call('GET', `/v1/platform/workers/scripts${filter.name === undefined ? '' : `?${new URLSearchParams({ name: filter.name })}`}`),
|
|
115
|
+
/** Uploads the script (base64, at most 10 MB), or redeploys the one edge
|
|
116
|
+
* already owns (201 on the first upload, 200 after). Rejects with
|
|
117
|
+
* `conflict` when a live script of that name exists that nobody adopted
|
|
118
|
+
* (adopt it instead) or another upload of the name is in progress, and
|
|
119
|
+
* with `invalid_request` when the script is not base64 or its sha256
|
|
120
|
+
* differs from `artifactSha256`. */
|
|
121
|
+
uploadScript: (name, input) => call('PUT', `/v1/platform/workers/scripts/${encodeURIComponent(name)}`, input),
|
|
122
|
+
/** Deletes the script; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
123
|
+
removeScript: (name) => call('DELETE', `/v1/platform/workers/scripts/${encodeURIComponent(name)}`),
|
|
124
|
+
/** Every live route in the zone with its owner (`null`: no row), optionally only one pattern. */
|
|
125
|
+
listRoutes: (filter) => call('GET', `/v1/platform/workers/routes?${new URLSearchParams(Object.entries(filter).filter((entry) => entry[1] !== undefined))}`),
|
|
126
|
+
/** Creates the route, or returns the one edge already made for that
|
|
127
|
+
* zone, pattern and script. Rejects with `conflict` when a live route
|
|
128
|
+
* holds the pattern that nobody adopted (adopt it instead). */
|
|
129
|
+
createRoute: (input) => call('POST', '/v1/platform/workers/routes', input),
|
|
130
|
+
/** Deletes the route in `zoneId`; returns the tombstone. Repeating it rejects with `not_found`. */
|
|
131
|
+
removeRoute: (zoneId, id) => call('DELETE', `/v1/platform/workers/routes/${encodeURIComponent(id)}?${new URLSearchParams({ zoneId })}`),
|
|
132
|
+
/** Writes platform rows for the scripts and routes named. Nothing is
|
|
133
|
+
* deleted or recreated, and anything nobody names is left alone. */
|
|
134
|
+
adopt: (input) => call('POST', '/v1/platform/workers/adopt', input),
|
|
135
|
+
},
|
|
91
136
|
},
|
|
92
137
|
/** True when the name is free: not reserved, no record in the zone, not claimed. */
|
|
93
138
|
available: (name) => call('GET', `/v1/names/available?${new URLSearchParams({ name })}`),
|
package/dist/types.d.ts
CHANGED
|
@@ -392,3 +392,178 @@ export interface AdoptAccessAppsResponse {
|
|
|
392
392
|
/** Live apps no entry named. Reported, never touched. */
|
|
393
393
|
unclaimed: PlatformAccessAppView[];
|
|
394
394
|
}
|
|
395
|
+
/** A Workers script seen with the platform credential. `id` is the script's
|
|
396
|
+
* name, which every platform script call takes. */
|
|
397
|
+
export interface PlatformWorkerScriptView {
|
|
398
|
+
id: string;
|
|
399
|
+
name: string;
|
|
400
|
+
/** Who owns it: the platform, or `null` when no row exists (a live script
|
|
401
|
+
* nobody adopted: reported, never touched). */
|
|
402
|
+
owner: 'platform' | null;
|
|
403
|
+
/** The company the script serves; `'platform'` when none. `null` for a script with no row. */
|
|
404
|
+
organisationId: string | null;
|
|
405
|
+
state: 'pending' | 'active' | 'removing' | 'removed';
|
|
406
|
+
}
|
|
407
|
+
export interface ListPlatformWorkerScriptsResponse {
|
|
408
|
+
scripts: PlatformWorkerScriptView[];
|
|
409
|
+
}
|
|
410
|
+
/** One rate limiting binding, Cloudflare's own shape. */
|
|
411
|
+
export interface WorkerRateLimitBinding {
|
|
412
|
+
type: 'ratelimit';
|
|
413
|
+
name: string;
|
|
414
|
+
namespace_id: string;
|
|
415
|
+
simple: {
|
|
416
|
+
limit: number;
|
|
417
|
+
period: number;
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
/** Uploads (or redeploys) a script. Edge fetches nothing: the caller sends the
|
|
421
|
+
* script, edge checks its size and sha256, and sends it to Cloudflare. The body
|
|
422
|
+
* is never stored or returned. */
|
|
423
|
+
export interface UploadPlatformWorkerScriptRequest {
|
|
424
|
+
/** The script (one ES module) as base64 text, at most 10 MB decoded. */
|
|
425
|
+
script: string;
|
|
426
|
+
/** The script's sha256, 64 hex characters. A script with another digest is refused with `invalid_request`. */
|
|
427
|
+
artifactSha256: string;
|
|
428
|
+
/** Like `2026-10-01`. */
|
|
429
|
+
compatibilityDate: string;
|
|
430
|
+
bindings?: WorkerRateLimitBinding[];
|
|
431
|
+
/** The company the script serves. Omit for a script that serves none. */
|
|
432
|
+
organisationId?: string;
|
|
433
|
+
}
|
|
434
|
+
/** A Workers route seen with the platform credential. `id` is Cloudflare's
|
|
435
|
+
* route id, which every platform route call takes. */
|
|
436
|
+
export interface PlatformWorkerRouteView {
|
|
437
|
+
id: string;
|
|
438
|
+
zoneId: string;
|
|
439
|
+
pattern: string;
|
|
440
|
+
/** The script it runs, or `null` for the "no Worker" route. */
|
|
441
|
+
script: string | null;
|
|
442
|
+
/** Who owns it: the platform, or `null` when no row exists. */
|
|
443
|
+
owner: 'platform' | null;
|
|
444
|
+
/** The company the route serves; `'platform'` when none. `null` for a route with no row. */
|
|
445
|
+
organisationId: string | null;
|
|
446
|
+
state: 'pending' | 'active' | 'removing' | 'removed';
|
|
447
|
+
}
|
|
448
|
+
export interface ListPlatformWorkerRoutesRequest {
|
|
449
|
+
zoneId: string;
|
|
450
|
+
/** Only the route on exactly this pattern. */
|
|
451
|
+
pattern?: string;
|
|
452
|
+
}
|
|
453
|
+
export interface ListPlatformWorkerRoutesResponse {
|
|
454
|
+
routes: PlatformWorkerRouteView[];
|
|
455
|
+
}
|
|
456
|
+
/** Creates the route, or returns the one edge already made for that zone,
|
|
457
|
+
* pattern and script. With no `script` it makes Cloudflare's "no Worker"
|
|
458
|
+
* route, which turns Workers off for the pattern. */
|
|
459
|
+
export interface CreatePlatformWorkerRouteRequest {
|
|
460
|
+
zoneId: string;
|
|
461
|
+
pattern: string;
|
|
462
|
+
script?: string;
|
|
463
|
+
/** The company the route serves. Omit for a route that serves none. */
|
|
464
|
+
organisationId?: string;
|
|
465
|
+
}
|
|
466
|
+
export interface AdoptWorkerScriptEntry {
|
|
467
|
+
name: string;
|
|
468
|
+
}
|
|
469
|
+
export interface AdoptWorkerRouteEntry {
|
|
470
|
+
zoneId: string;
|
|
471
|
+
pattern: string;
|
|
472
|
+
/** Cloudflare's id, when the caller recorded it: the match must carry it. */
|
|
473
|
+
id?: string;
|
|
474
|
+
}
|
|
475
|
+
/** Name at least one script or route. */
|
|
476
|
+
export interface AdoptWorkersRequest {
|
|
477
|
+
scripts?: AdoptWorkerScriptEntry[];
|
|
478
|
+
routes?: AdoptWorkerRouteEntry[];
|
|
479
|
+
/** The company the adopted items serve. Omit for none. */
|
|
480
|
+
organisationId?: string;
|
|
481
|
+
}
|
|
482
|
+
export interface AdoptWorkersResponse {
|
|
483
|
+
scripts: {
|
|
484
|
+
adopted: PlatformWorkerScriptView[];
|
|
485
|
+
alreadyAdopted: PlatformWorkerScriptView[];
|
|
486
|
+
/** Entries with no live script. Nothing is created for them. */
|
|
487
|
+
notFound: AdoptWorkerScriptEntry[];
|
|
488
|
+
/** Live scripts no entry named. Reported, never touched. */
|
|
489
|
+
unclaimed: PlatformWorkerScriptView[];
|
|
490
|
+
};
|
|
491
|
+
routes: {
|
|
492
|
+
adopted: PlatformWorkerRouteView[];
|
|
493
|
+
alreadyAdopted: PlatformWorkerRouteView[];
|
|
494
|
+
/** `taken`: a row for that zone and pattern exists. */
|
|
495
|
+
skipped: Array<{
|
|
496
|
+
route: PlatformWorkerRouteView;
|
|
497
|
+
reason: 'taken';
|
|
498
|
+
}>;
|
|
499
|
+
notFound: AdoptWorkerRouteEntry[];
|
|
500
|
+
/** Live routes in the named zones that no entry named. Reported, never touched. */
|
|
501
|
+
unclaimed: PlatformWorkerRouteView[];
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
/** A rate limiting rule seen with the platform credential. A zone's rules share
|
|
505
|
+
* one ruleset, so ownership is per rule. `id` is Cloudflare's rule id, which
|
|
506
|
+
* every platform rule call takes. */
|
|
507
|
+
export interface PlatformRateLimitRuleView {
|
|
508
|
+
id: string;
|
|
509
|
+
zoneId: string;
|
|
510
|
+
/** `null` for a live rule that has no description. */
|
|
511
|
+
description: string | null;
|
|
512
|
+
/** Who owns it: the platform, or `null` when no row exists (a live rule
|
|
513
|
+
* nobody adopted: reported, never touched). */
|
|
514
|
+
owner: 'platform' | null;
|
|
515
|
+
/** The company the rule serves; `'platform'` when none. `null` for a rule with no row. */
|
|
516
|
+
organisationId: string | null;
|
|
517
|
+
state: 'pending' | 'active' | 'removing' | 'removed';
|
|
518
|
+
}
|
|
519
|
+
export interface ListPlatformRateLimitRulesRequest {
|
|
520
|
+
zoneId: string;
|
|
521
|
+
/** Only the rule with exactly this description. */
|
|
522
|
+
description?: string;
|
|
523
|
+
}
|
|
524
|
+
export interface ListPlatformRateLimitRulesResponse {
|
|
525
|
+
rules: PlatformRateLimitRuleView[];
|
|
526
|
+
}
|
|
527
|
+
/** Creates the rule, or returns the one edge already made for that zone and
|
|
528
|
+
* description. The rule is added on its own: no other rule in the zone's
|
|
529
|
+
* ruleset is read back or rewritten. Cloudflare's plan limits (such as one rule
|
|
530
|
+
* on the Free plan) are Cloudflare's to refuse. */
|
|
531
|
+
export interface CreatePlatformRateLimitRuleRequest {
|
|
532
|
+
zoneId: string;
|
|
533
|
+
/** Names the rule in the zone: the key that makes a repeat safe. */
|
|
534
|
+
description: string;
|
|
535
|
+
expression: string;
|
|
536
|
+
/** Cloudflare's rule action, such as `block`. */
|
|
537
|
+
action: string;
|
|
538
|
+
ratelimit: {
|
|
539
|
+
characteristics: string[];
|
|
540
|
+
period: number;
|
|
541
|
+
requests_per_period: number;
|
|
542
|
+
mitigation_timeout?: number;
|
|
543
|
+
};
|
|
544
|
+
/** The company the rule serves. Omit for a rule that serves none. */
|
|
545
|
+
organisationId?: string;
|
|
546
|
+
}
|
|
547
|
+
export interface AdoptRateLimitRuleEntry {
|
|
548
|
+
zoneId: string;
|
|
549
|
+
/** Match the live rule by description, by id, or both. At least one is needed. */
|
|
550
|
+
description?: string;
|
|
551
|
+
id?: string;
|
|
552
|
+
}
|
|
553
|
+
export interface AdoptRateLimitRulesRequest {
|
|
554
|
+
rules: AdoptRateLimitRuleEntry[];
|
|
555
|
+
/** The company the adopted rules serve. Omit for none. */
|
|
556
|
+
organisationId?: string;
|
|
557
|
+
}
|
|
558
|
+
export interface AdoptRateLimitRulesResponse {
|
|
559
|
+
adopted: PlatformRateLimitRuleView[];
|
|
560
|
+
alreadyAdopted: PlatformRateLimitRuleView[];
|
|
561
|
+
/** `taken`: a row for that zone and description exists. */
|
|
562
|
+
skipped: Array<{
|
|
563
|
+
rule: PlatformRateLimitRuleView;
|
|
564
|
+
reason: 'taken';
|
|
565
|
+
}>;
|
|
566
|
+
notFound: AdoptRateLimitRuleEntry[];
|
|
567
|
+
/** Live rules in the named zones that no entry named. Reported, never touched. */
|
|
568
|
+
unclaimed: PlatformRateLimitRuleView[];
|
|
569
|
+
}
|