@seta-labs/proxy 0.0.0-stage → 0.1.0-next.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/CHANGELOG.md +11 -0
- package/README.md +115 -2
- package/dist/admin.d.ts +54 -0
- package/dist/admin.js +169 -0
- package/dist/chunk-6QCKYRE3.js +81 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +49 -0
- package/dist/transport-CWjoRf8k.d.ts +2031 -0
- package/package.json +52 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @seta-labs/proxy
|
|
2
|
+
|
|
3
|
+
## 0.1.0-next.0
|
|
4
|
+
|
|
5
|
+
- Initial public package preparation, compatible with the Seta Proxy 0.13.5 HTTP
|
|
6
|
+
contract: application lease/catalog client and separate administration entry.
|
|
7
|
+
- Typed inputs/results, Fetch injection, cancellation and HTTP error metadata;
|
|
8
|
+
no automatic retries or relay/provider policy.
|
|
9
|
+
- Self-contained ESM declarations and same-origin panel integration.
|
|
10
|
+
|
|
11
|
+
This version has not been published by the implementation work.
|
package/README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @seta-labs/proxy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ESM, browser-safe TypeScript client for Seta Proxy's control plane. The package
|
|
4
|
+
contains no relay/CONNECT implementation, proxy agent, provider SDK, `call-pool`,
|
|
5
|
+
queue, retry, timeout policy or runtime environment configuration.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { ApiError, createProxyClient } from '@seta-labs/proxy';
|
|
9
|
+
|
|
10
|
+
const proxy = createProxyClient({
|
|
11
|
+
baseUrl: 'https://proxy.example/api',
|
|
12
|
+
apiKey: applicationKey,
|
|
13
|
+
});
|
|
14
|
+
const lease = await proxy.leases.create(
|
|
15
|
+
{ gateway: 'default', targetHost: 'example.com' },
|
|
16
|
+
{ signal: AbortSignal.timeout(20_000) },
|
|
17
|
+
);
|
|
18
|
+
await proxy.leases.release(lease.id);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`baseUrl` is the absolute API root **including `/api`**, with an optional trailing
|
|
22
|
+
slash. Relative URLs, embedded credentials, queries and fragments are rejected.
|
|
23
|
+
On a panel use `new URL('/api', requestOrWindowUrl).href` and omit `apiKey`; the
|
|
24
|
+
same-origin backend supplies the key. Never embed an operator key in browser
|
|
25
|
+
code. Make a client per SSR request and forward only the authentication headers
|
|
26
|
+
that backend needs; do not share user cookies between requests.
|
|
27
|
+
|
|
28
|
+
`fetch` is injectable and must accept a standard `Request` and return a standard
|
|
29
|
+
`Response`. A body-returning `$fetch` is not compatible. `headers` are copied per
|
|
30
|
+
client; `apiKey` takes precedence over an `x-api-key` supplied there. Optional
|
|
31
|
+
`credentials` has Fetch semantics. Every method takes optional `{ signal }` last.
|
|
32
|
+
|
|
33
|
+
Application methods:
|
|
34
|
+
|
|
35
|
+
- `gateways.list(options?)`
|
|
36
|
+
- `leases.create(input, options?)`, `get(id, options?)`, `renew(id, options?)`
|
|
37
|
+
- `leases.release(id, options?)`, `report(id, input, options?)`
|
|
38
|
+
|
|
39
|
+
Administration uses a separate entry point and an operator key on the backend:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { createProxyAdminClient } from '@seta-labs/proxy/admin';
|
|
43
|
+
const admin = createProxyAdminClient({ baseUrl: apiRoot, apiKey: operatorKey });
|
|
44
|
+
const accounts = await admin.providers.list();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Admin methods mirror the current management contract:
|
|
48
|
+
|
|
49
|
+
- `apiKeys.list`, `create`, `revoke`
|
|
50
|
+
- `endpoints.list`, `update`, `check`, `checkAll`
|
|
51
|
+
- `providers.list`, `get`, `create`, `update`, `pause`, `resume`, `disconnect`,
|
|
52
|
+
`test`, `sync`, `resources`, `runs`
|
|
53
|
+
- `gateways.list`, `create`, `update`, `remove`, `addMember`, `removeMember`
|
|
54
|
+
- `bans.list`, `byEndpoint`; `report`, `stats`, `refresh`, `syncIproyal`
|
|
55
|
+
- `playground.config`, `run`
|
|
56
|
+
|
|
57
|
+
All 38 functional operations are covered. The three health operations are
|
|
58
|
+
intentionally excluded. Import separation is convenience; server guards enforce
|
|
59
|
+
permissions. Calling the wrong API with a key still produces the server's 401/403.
|
|
60
|
+
|
|
61
|
+
Methods return `Promise<T>` using types derived from the server OpenAPI contract.
|
|
62
|
+
This is compile-time typing, not runtime payload validation. Retain consumer
|
|
63
|
+
validation and domain policy. Empty successful responses, including 204, resolve
|
|
64
|
+
to `undefined` on the void release/report/remove methods. Empty responses where
|
|
65
|
+
the contract expects data and malformed success JSON throw `ResponseParseError` with
|
|
66
|
+
status, headers, body and cause. Network errors and abort reasons pass through.
|
|
67
|
+
|
|
68
|
+
Every HTTP failure throws `ApiError`: `status`, `statusText`, a copied `headers`,
|
|
69
|
+
untrusted `body` (parsed JSON or original text), and `requestId` (header first,
|
|
70
|
+
then body). Inspect `body` safely before using domain codes or `retryAfterMs`;
|
|
71
|
+
`headers.get('retry-after')` is retained. No error bodies or credentials are
|
|
72
|
+
logged by this package. No method retries automatically, including lease creation
|
|
73
|
+
and provider sync. A connection failure after a write may be ambiguous: the
|
|
74
|
+
consumer decides how to recover. Lease 404/410, revoked keys, 429 and 503 remain
|
|
75
|
+
HTTP errors, never silently converted to expired leases or waits.
|
|
76
|
+
|
|
77
|
+
Supported runtime: Node.js 22+ with native Fetch, and browsers with Fetch,
|
|
78
|
+
Request, Response, Headers and AbortController. TypeScript declarations are
|
|
79
|
+
self-contained; the private `@seta-proxy/types` workspace is not a consumer
|
|
80
|
+
dependency. The repository gate uses Node 26; tarball smoke also runs on Node 22.
|
|
81
|
+
The first prerelease targets the HTTP contract of Seta Proxy `0.13.5`.
|
|
82
|
+
|
|
83
|
+
## Packaging and release
|
|
84
|
+
|
|
85
|
+
`pnpm sdk:pack` builds and packs locally; `pnpm sdk:smoke` packs to an external
|
|
86
|
+
temporary directory, inspects the allowlist, installs the tarball without
|
|
87
|
+
workspace links, checks runtime imports and compiles public types with library
|
|
88
|
+
checking enabled. Neither command publishes.
|
|
89
|
+
|
|
90
|
+
Versions are independent of the application. The SDK stays on `0.x` until the
|
|
91
|
+
owner explicitly authorizes graduation to `1.0`; stabilization does not imply
|
|
92
|
+
that approval. Use Changesets for SDK and exposed contract changes, documenting
|
|
93
|
+
compatibility and migration requirements for each `0.x` release. The prepared
|
|
94
|
+
initial version is `0.1.0-next.0` (`next`). Each later release documents the minimum compatible server;
|
|
95
|
+
publishing a package never deploys that server. Keep `publishConfig.tag` aligned
|
|
96
|
+
when exiting prerelease mode; the workflow explicitly selects `next` or `latest`
|
|
97
|
+
from the version.
|
|
98
|
+
|
|
99
|
+
The dedicated `publish-sdk.yml` accepts only `@seta-labs/proxy@<version>` tags,
|
|
100
|
+
requires successful application CI on the exact tagged commit, checks tag/manifest
|
|
101
|
+
equality, runs SDK/type checks and tarball smoke, then uses
|
|
102
|
+
npm OIDC on a GitHub-hosted runner. `v*` image release tags are unchanged.
|
|
103
|
+
Before tagging, obtain successful repository `code:check` and `test:unit` results
|
|
104
|
+
(the ordinary CI runs these too), plus required API e2e checks in an authorized
|
|
105
|
+
environment. The npm workflow adds no DB or runtime environment variables.
|
|
106
|
+
|
|
107
|
+
Operator prerequisites, not configured by this change: confirm scope ownership
|
|
108
|
+
and name availability, approve the license, bootstrap the package if npm requires
|
|
109
|
+
it, and configure its npm trusted publisher for `Seta-Labs/seta-proxy` and
|
|
110
|
+
`publish-sdk.yml` with **direct publishing** enabled. No npm token is added.
|
|
111
|
+
Source repository visibility is independent from public package visibility;
|
|
112
|
+
provenance is disabled for compatibility with private source repositories.
|
|
113
|
+
The manifest currently retains `UNLICENSED` rather than granting a new license.
|
|
114
|
+
Never overwrite published versions: rollback a consumer lockfile or publish a
|
|
115
|
+
new version and deprecate the defective one. Publication remains an explicit
|
|
116
|
+
operator action. [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/).
|
package/dist/admin.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { R as RequestOptions, A as ApiKey, C as CreateApiKeyInput, I as IssuedApiKey, P as ProxyEndpoint, U as UpdateEndpointInput, E as EndpointCheckResult, a as ProviderAccount, b as ProviderAccountInput, c as ProviderAccountPatch, d as ProviderSyncResult, S as SyncProviderAccountInput, e as ProviderResource, f as ProviderSyncRun, g as ProxyGateway, h as CreateGatewayInput, i as UpdateGatewayInput, G as GatewayMemberInput, B as BanQuery, j as ProxyBanEvent, k as EndpointBanSummary, l as PlaygroundConfigRequest, m as PlaygroundConfig, n as PlaygroundRunRequest, o as PlaygroundRunResult, p as ReportBanRequest, q as ReportBanResponse, r as RelayStats, s as RefreshResult, t as SyncIproyalRequest, u as SyncIproyalResponse, v as ProxyClientOptions } from './transport-CWjoRf8k.js';
|
|
2
|
+
export { w as ApiError, x as ResponseParseError } from './transport-CWjoRf8k.js';
|
|
3
|
+
|
|
4
|
+
interface ProxyAdminClient {
|
|
5
|
+
apiKeys: {
|
|
6
|
+
list(options?: RequestOptions): Promise<ApiKey[]>;
|
|
7
|
+
create(input: CreateApiKeyInput, options?: RequestOptions): Promise<IssuedApiKey>;
|
|
8
|
+
revoke(id: string, options?: RequestOptions): Promise<ApiKey>;
|
|
9
|
+
};
|
|
10
|
+
endpoints: {
|
|
11
|
+
list(options?: RequestOptions): Promise<ProxyEndpoint[]>;
|
|
12
|
+
update(id: string, input: UpdateEndpointInput, options?: RequestOptions): Promise<ProxyEndpoint>;
|
|
13
|
+
check(id: string, options?: RequestOptions): Promise<EndpointCheckResult>;
|
|
14
|
+
checkAll(options?: RequestOptions): Promise<EndpointCheckResult[]>;
|
|
15
|
+
};
|
|
16
|
+
providers: {
|
|
17
|
+
list(options?: RequestOptions): Promise<ProviderAccount[]>;
|
|
18
|
+
get(id: string, options?: RequestOptions): Promise<ProviderAccount>;
|
|
19
|
+
create(input: ProviderAccountInput, options?: RequestOptions): Promise<ProviderAccount>;
|
|
20
|
+
update(id: string, input: ProviderAccountPatch, options?: RequestOptions): Promise<ProviderAccount>;
|
|
21
|
+
pause(id: string, options?: RequestOptions): Promise<ProviderAccount>;
|
|
22
|
+
resume(id: string, options?: RequestOptions): Promise<ProviderAccount>;
|
|
23
|
+
disconnect(id: string, options?: RequestOptions): Promise<ProviderAccount>;
|
|
24
|
+
test(id: string, options?: RequestOptions): Promise<ProviderSyncResult>;
|
|
25
|
+
sync(id: string, input: SyncProviderAccountInput, options?: RequestOptions): Promise<ProviderSyncResult>;
|
|
26
|
+
resources(id: string, options?: RequestOptions): Promise<ProviderResource[]>;
|
|
27
|
+
runs(id: string, options?: RequestOptions): Promise<ProviderSyncRun[]>;
|
|
28
|
+
};
|
|
29
|
+
gateways: {
|
|
30
|
+
list(options?: RequestOptions): Promise<ProxyGateway[]>;
|
|
31
|
+
create(input: CreateGatewayInput, options?: RequestOptions): Promise<ProxyGateway>;
|
|
32
|
+
update(id: string, input: UpdateGatewayInput, options?: RequestOptions): Promise<ProxyGateway>;
|
|
33
|
+
remove(id: string, options?: RequestOptions): Promise<void>;
|
|
34
|
+
addMember(id: string, input: GatewayMemberInput, options?: RequestOptions): Promise<ProxyGateway>;
|
|
35
|
+
removeMember(id: string, endpointId: string, options?: RequestOptions): Promise<ProxyGateway>;
|
|
36
|
+
};
|
|
37
|
+
bans: {
|
|
38
|
+
list(query?: BanQuery, options?: RequestOptions): Promise<ProxyBanEvent[]>;
|
|
39
|
+
byEndpoint(options?: RequestOptions): Promise<EndpointBanSummary[]>;
|
|
40
|
+
};
|
|
41
|
+
playground: {
|
|
42
|
+
config(input: PlaygroundConfigRequest, options?: RequestOptions): Promise<PlaygroundConfig[]>;
|
|
43
|
+
run(input: PlaygroundRunRequest, options?: RequestOptions): Promise<PlaygroundRunResult>;
|
|
44
|
+
};
|
|
45
|
+
report(input: ReportBanRequest, options?: RequestOptions): Promise<ReportBanResponse>;
|
|
46
|
+
stats(options?: RequestOptions): Promise<RelayStats>;
|
|
47
|
+
refresh(options?: RequestOptions): Promise<RefreshResult>;
|
|
48
|
+
syncIproyal(input: SyncIproyalRequest, options?: RequestOptions): Promise<SyncIproyalResponse>;
|
|
49
|
+
}
|
|
50
|
+
/** Management control plane. Keep the operator key on your server. */
|
|
51
|
+
declare function createProxyAdminClient(options: ProxyClientOptions): ProxyAdminClient;
|
|
52
|
+
|
|
53
|
+
export { ApiKey, BanQuery, CreateApiKeyInput, CreateGatewayInput, EndpointBanSummary, EndpointCheckResult, GatewayMemberInput, IssuedApiKey, PlaygroundConfig, PlaygroundConfigRequest, PlaygroundRunRequest, PlaygroundRunResult, ProviderAccount, ProviderAccountInput, ProviderAccountPatch, ProviderResource, ProviderSyncResult, ProviderSyncRun, ProxyBanEvent, ProxyClientOptions, ProxyEndpoint, ProxyGateway, RefreshResult, RelayStats, ReportBanRequest, ReportBanResponse, RequestOptions, SyncIproyalRequest, SyncIproyalResponse, SyncProviderAccountInput, UpdateEndpointInput, UpdateGatewayInput, createProxyAdminClient };
|
|
54
|
+
export type { ProxyAdminClient };
|
package/dist/admin.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiError,
|
|
3
|
+
ResponseParseError,
|
|
4
|
+
createTransport,
|
|
5
|
+
result,
|
|
6
|
+
textOptions
|
|
7
|
+
} from "./chunk-6QCKYRE3.js";
|
|
8
|
+
|
|
9
|
+
// src/admin.ts
|
|
10
|
+
function createProxyAdminClient(options) {
|
|
11
|
+
const http = createTransport(options);
|
|
12
|
+
return {
|
|
13
|
+
apiKeys: apiKeysMethods(http),
|
|
14
|
+
endpoints: endpointsMethods(http),
|
|
15
|
+
providers: providersMethods(http),
|
|
16
|
+
gateways: gatewaysMethods(http),
|
|
17
|
+
bans: bansMethods(http),
|
|
18
|
+
playground: playgroundMethods(http),
|
|
19
|
+
report: (input, options2) => result(http.POST("/proxies/report", { ...textOptions(options2), body: input })),
|
|
20
|
+
stats: (options2) => result(http.GET("/proxies/stats", { ...textOptions(options2) })),
|
|
21
|
+
refresh: (options2) => result(http.POST("/proxies/refresh", { ...textOptions(options2) })),
|
|
22
|
+
syncIproyal: (input, options2) => result(http.POST("/proxies/sync/iproyal", { ...textOptions(options2), body: input }))
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function apiKeysMethods(http) {
|
|
26
|
+
return {
|
|
27
|
+
list: (options) => result(http.GET("/proxies/api-keys", { ...textOptions(options) })),
|
|
28
|
+
create: (input, options) => result(http.POST("/proxies/api-keys", { ...textOptions(options), body: input })),
|
|
29
|
+
revoke: (id, options) => result(
|
|
30
|
+
http.DELETE("/proxies/api-keys/{id}", {
|
|
31
|
+
...textOptions(options),
|
|
32
|
+
params: { path: { id } }
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function endpointsMethods(http) {
|
|
38
|
+
return {
|
|
39
|
+
list: (options) => result(http.GET("/proxies/endpoints", { ...textOptions(options) })),
|
|
40
|
+
update: (id, input, options) => result(
|
|
41
|
+
http.PATCH("/proxies/endpoints/{id}", {
|
|
42
|
+
...textOptions(options),
|
|
43
|
+
params: { path: { id } },
|
|
44
|
+
body: input
|
|
45
|
+
})
|
|
46
|
+
),
|
|
47
|
+
check: (id, options) => result(
|
|
48
|
+
http.POST("/proxies/endpoints/{id}/check", {
|
|
49
|
+
...textOptions(options),
|
|
50
|
+
params: { path: { id } }
|
|
51
|
+
})
|
|
52
|
+
),
|
|
53
|
+
checkAll: (options) => result(http.POST("/proxies/endpoints/check-all", { ...textOptions(options) }))
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function providersMethods(http) {
|
|
57
|
+
return {
|
|
58
|
+
list: (options) => result(http.GET("/proxies/providers", { ...textOptions(options) })),
|
|
59
|
+
get: (id, options) => result(
|
|
60
|
+
http.GET("/proxies/providers/{id}", {
|
|
61
|
+
...textOptions(options),
|
|
62
|
+
params: { path: { id } }
|
|
63
|
+
})
|
|
64
|
+
),
|
|
65
|
+
create: (input, options) => result(http.POST("/proxies/providers", { ...textOptions(options), body: input })),
|
|
66
|
+
update: (id, input, options) => result(
|
|
67
|
+
http.PATCH("/proxies/providers/{id}", {
|
|
68
|
+
...textOptions(options),
|
|
69
|
+
params: { path: { id } },
|
|
70
|
+
body: input
|
|
71
|
+
})
|
|
72
|
+
),
|
|
73
|
+
pause: (id, options) => result(
|
|
74
|
+
http.POST("/proxies/providers/{id}/pause", {
|
|
75
|
+
...textOptions(options),
|
|
76
|
+
params: { path: { id } }
|
|
77
|
+
})
|
|
78
|
+
),
|
|
79
|
+
resume: (id, options) => result(
|
|
80
|
+
http.POST("/proxies/providers/{id}/resume", {
|
|
81
|
+
...textOptions(options),
|
|
82
|
+
params: { path: { id } }
|
|
83
|
+
})
|
|
84
|
+
),
|
|
85
|
+
disconnect: (id, options) => result(
|
|
86
|
+
http.POST("/proxies/providers/{id}/disconnect", {
|
|
87
|
+
...textOptions(options),
|
|
88
|
+
params: { path: { id } }
|
|
89
|
+
})
|
|
90
|
+
),
|
|
91
|
+
test: (id, options) => result(
|
|
92
|
+
http.POST("/proxies/providers/{id}/test", {
|
|
93
|
+
...textOptions(options),
|
|
94
|
+
params: { path: { id } }
|
|
95
|
+
})
|
|
96
|
+
),
|
|
97
|
+
sync: (id, input, options) => result(
|
|
98
|
+
http.POST("/proxies/providers/{id}/sync", {
|
|
99
|
+
...textOptions(options),
|
|
100
|
+
params: { path: { id } },
|
|
101
|
+
body: input
|
|
102
|
+
})
|
|
103
|
+
),
|
|
104
|
+
resources: (id, options) => result(
|
|
105
|
+
http.GET("/proxies/providers/{id}/resources", {
|
|
106
|
+
...textOptions(options),
|
|
107
|
+
params: { path: { id } }
|
|
108
|
+
})
|
|
109
|
+
),
|
|
110
|
+
runs: (id, options) => result(
|
|
111
|
+
http.GET("/proxies/providers/{id}/runs", {
|
|
112
|
+
...textOptions(options),
|
|
113
|
+
params: { path: { id } }
|
|
114
|
+
})
|
|
115
|
+
)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function gatewaysMethods(http) {
|
|
119
|
+
return {
|
|
120
|
+
list: (options) => result(http.GET("/proxies/gateways", { ...textOptions(options) })),
|
|
121
|
+
create: (input, options) => result(http.POST("/proxies/gateways", { ...textOptions(options), body: input })),
|
|
122
|
+
update: (id, input, options) => result(
|
|
123
|
+
http.PATCH("/proxies/gateways/{id}", {
|
|
124
|
+
...textOptions(options),
|
|
125
|
+
params: { path: { id } },
|
|
126
|
+
body: input
|
|
127
|
+
})
|
|
128
|
+
),
|
|
129
|
+
remove: (id, options) => result(
|
|
130
|
+
http.DELETE("/proxies/gateways/{id}", {
|
|
131
|
+
...textOptions(options),
|
|
132
|
+
params: { path: { id } }
|
|
133
|
+
}),
|
|
134
|
+
true
|
|
135
|
+
),
|
|
136
|
+
addMember: (id, input, options) => result(
|
|
137
|
+
http.POST("/proxies/gateways/{id}/members", {
|
|
138
|
+
...textOptions(options),
|
|
139
|
+
params: { path: { id } },
|
|
140
|
+
body: input
|
|
141
|
+
})
|
|
142
|
+
),
|
|
143
|
+
removeMember: (id, endpointId, options) => result(
|
|
144
|
+
http.DELETE("/proxies/gateways/{id}/members/{endpointId}", {
|
|
145
|
+
...textOptions(options),
|
|
146
|
+
params: { path: { id, endpointId } }
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function bansMethods(http) {
|
|
152
|
+
return {
|
|
153
|
+
list: (query, options) => result(http.GET("/proxies/bans", { ...textOptions(options), params: { query } })),
|
|
154
|
+
byEndpoint: (options) => result(http.GET("/proxies/bans/by-endpoint", { ...textOptions(options) }))
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function playgroundMethods(http) {
|
|
158
|
+
return {
|
|
159
|
+
config: (input, options) => result(
|
|
160
|
+
http.POST("/proxies/playground/config", { ...textOptions(options), body: input })
|
|
161
|
+
),
|
|
162
|
+
run: (input, options) => result(http.POST("/proxies/playground/run", { ...textOptions(options), body: input }))
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
ApiError,
|
|
167
|
+
ResponseParseError,
|
|
168
|
+
createProxyAdminClient
|
|
169
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/transport.ts
|
|
2
|
+
import createClient from "openapi-fetch";
|
|
3
|
+
var ApiError = class extends Error {
|
|
4
|
+
status;
|
|
5
|
+
statusText;
|
|
6
|
+
headers;
|
|
7
|
+
body;
|
|
8
|
+
requestId;
|
|
9
|
+
constructor(response, body) {
|
|
10
|
+
super(`Proxy API request failed with HTTP ${response.status}`);
|
|
11
|
+
this.name = "ApiError";
|
|
12
|
+
this.status = response.status;
|
|
13
|
+
this.statusText = response.statusText;
|
|
14
|
+
this.headers = new Headers(response.headers);
|
|
15
|
+
this.body = body;
|
|
16
|
+
this.requestId = response.headers.get("x-request-id") ?? bodyRequestId(body);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var ResponseParseError = class extends Error {
|
|
20
|
+
status;
|
|
21
|
+
headers;
|
|
22
|
+
body;
|
|
23
|
+
constructor(response, body, cause) {
|
|
24
|
+
super("Proxy API returned invalid JSON", { cause });
|
|
25
|
+
this.name = "ResponseParseError";
|
|
26
|
+
this.status = response.status;
|
|
27
|
+
this.headers = new Headers(response.headers);
|
|
28
|
+
this.body = body;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function bodyRequestId(body) {
|
|
32
|
+
if (typeof body === "object" && body !== null && "requestId" in body) {
|
|
33
|
+
return typeof body.requestId === "string" ? body.requestId : void 0;
|
|
34
|
+
}
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
function createTransport(options) {
|
|
38
|
+
const url = new URL(options.baseUrl);
|
|
39
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
|
|
40
|
+
throw new TypeError(
|
|
41
|
+
"baseUrl must be an absolute HTTP(S) API root without credentials, query or fragment"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const headers = new Headers(options.headers);
|
|
45
|
+
headers.set("accept", "application/json");
|
|
46
|
+
if (options.apiKey !== void 0) headers.set("x-api-key", options.apiKey);
|
|
47
|
+
return createClient({
|
|
48
|
+
baseUrl: url.href.replace(/\/+$/, ""),
|
|
49
|
+
headers,
|
|
50
|
+
fetch: options.fetch,
|
|
51
|
+
credentials: options.credentials
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function result(pending, allowEmpty = false) {
|
|
55
|
+
const { response, data, error } = await pending;
|
|
56
|
+
if (!response.ok) throw new ApiError(response, error);
|
|
57
|
+
if (data === void 0 || data === "") {
|
|
58
|
+
if (allowEmpty) return void 0;
|
|
59
|
+
throw new ResponseParseError(
|
|
60
|
+
response,
|
|
61
|
+
"",
|
|
62
|
+
new SyntaxError("Expected a JSON response body")
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(data);
|
|
67
|
+
} catch (cause) {
|
|
68
|
+
throw new ResponseParseError(response, data, cause);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function textOptions(options) {
|
|
72
|
+
return { ...options, parseAs: "text" };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
ApiError,
|
|
77
|
+
ResponseParseError,
|
|
78
|
+
createTransport,
|
|
79
|
+
result,
|
|
80
|
+
textOptions
|
|
81
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { R as RequestOptions, y as CatalogGateway, z as CreateLeaseInput, L as Lease, D as ReportLeaseInput, v as ProxyClientOptions } from './transport-CWjoRf8k.js';
|
|
2
|
+
export { w as ApiError, x as ResponseParseError } from './transport-CWjoRf8k.js';
|
|
3
|
+
|
|
4
|
+
interface ProxyClient {
|
|
5
|
+
gateways: {
|
|
6
|
+
list(options?: RequestOptions): Promise<CatalogGateway[]>;
|
|
7
|
+
};
|
|
8
|
+
leases: {
|
|
9
|
+
create(input: CreateLeaseInput, options?: RequestOptions): Promise<Lease>;
|
|
10
|
+
get(id: string, options?: RequestOptions): Promise<Lease>;
|
|
11
|
+
renew(id: string, options?: RequestOptions): Promise<Lease>;
|
|
12
|
+
release(id: string, options?: RequestOptions): Promise<void>;
|
|
13
|
+
report(id: string, input: ReportLeaseInput, options?: RequestOptions): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Application control-plane API. The key's permissions are enforced by the server. */
|
|
17
|
+
declare function createProxyClient(options: ProxyClientOptions): ProxyClient;
|
|
18
|
+
|
|
19
|
+
export { CatalogGateway, CreateLeaseInput, Lease, ProxyClientOptions, ReportLeaseInput, RequestOptions, createProxyClient };
|
|
20
|
+
export type { ProxyClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiError,
|
|
3
|
+
ResponseParseError,
|
|
4
|
+
createTransport,
|
|
5
|
+
result,
|
|
6
|
+
textOptions
|
|
7
|
+
} from "./chunk-6QCKYRE3.js";
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
function createProxyClient(options) {
|
|
11
|
+
const http = createTransport(options);
|
|
12
|
+
return {
|
|
13
|
+
gateways: {
|
|
14
|
+
list: (options2) => result(http.GET("/gateways", { ...textOptions(options2) }))
|
|
15
|
+
},
|
|
16
|
+
leases: {
|
|
17
|
+
create: (body, options2) => result(http.POST("/leases", { ...textOptions(options2), body })),
|
|
18
|
+
get: (id, options2) => result(
|
|
19
|
+
http.GET("/leases/{id}", { ...textOptions(options2), params: { path: { id } } })
|
|
20
|
+
),
|
|
21
|
+
renew: (id, options2) => result(
|
|
22
|
+
http.PATCH("/leases/{id}", {
|
|
23
|
+
...textOptions(options2),
|
|
24
|
+
params: { path: { id } }
|
|
25
|
+
})
|
|
26
|
+
),
|
|
27
|
+
release: (id, options2) => result(
|
|
28
|
+
http.DELETE("/leases/{id}", {
|
|
29
|
+
...textOptions(options2),
|
|
30
|
+
params: { path: { id } }
|
|
31
|
+
}),
|
|
32
|
+
true
|
|
33
|
+
),
|
|
34
|
+
report: (id, body, options2) => result(
|
|
35
|
+
http.POST("/leases/{id}/report", {
|
|
36
|
+
...textOptions(options2),
|
|
37
|
+
params: { path: { id } },
|
|
38
|
+
body
|
|
39
|
+
}),
|
|
40
|
+
true
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
ApiError,
|
|
47
|
+
ResponseParseError,
|
|
48
|
+
createProxyClient
|
|
49
|
+
};
|