@fly.io/sdk 0.1.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/LICENSE +21 -0
- package/dist/app.d.ts +181 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +212 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +200 -0
- package/dist/errors.d.ts +48 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +85 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/machine.d.ts +319 -0
- package/dist/machine.d.ts.map +1 -0
- package/dist/machine.js +249 -0
- package/dist/network.d.ts +45 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +44 -0
- package/dist/organization.d.ts +20 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +22 -0
- package/dist/regions.d.ts +35 -0
- package/dist/regions.d.ts.map +1 -0
- package/dist/regions.js +53 -0
- package/dist/secret.d.ts +55 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +53 -0
- package/dist/token.d.ts +14 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +16 -0
- package/dist/types.d.ts +937 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +40 -0
- package/dist/volume.d.ts +72 -0
- package/dist/volume.d.ts.map +1 -0
- package/dist/volume.js +45 -0
- package/package.json +54 -0
- package/src/app.ts +462 -0
- package/src/client.ts +262 -0
- package/src/errors.ts +135 -0
- package/src/index.ts +141 -0
- package/src/machine.ts +644 -0
- package/src/network.ts +87 -0
- package/src/organization.ts +43 -0
- package/src/regions.ts +94 -0
- package/src/secret.ts +101 -0
- package/src/token.ts +29 -0
- package/src/types.ts +1072 -0
- package/src/volume.ts +124 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Typed Fly API error classes and HTTP/GraphQL error mapping helpers.
|
|
2
|
+
|
|
3
|
+
import * as errore from 'errore'
|
|
4
|
+
|
|
5
|
+
import type { MainStatusCode } from './types.ts'
|
|
6
|
+
|
|
7
|
+
export class FlyApiError extends errore.createTaggedError({
|
|
8
|
+
name: 'FlyApiError',
|
|
9
|
+
message: 'Fly API request failed for $method $path with status $httpStatus',
|
|
10
|
+
}) {}
|
|
11
|
+
|
|
12
|
+
export class FlyBadRequestError extends errore.createTaggedError({
|
|
13
|
+
name: 'FlyBadRequestError',
|
|
14
|
+
message: 'Fly API returned 400 for $method $path',
|
|
15
|
+
}) {}
|
|
16
|
+
|
|
17
|
+
export class FlyUnauthorizedError extends errore.createTaggedError({
|
|
18
|
+
name: 'FlyUnauthorizedError',
|
|
19
|
+
message: 'Fly API returned 401 for $method $path',
|
|
20
|
+
}) {}
|
|
21
|
+
|
|
22
|
+
export class FlyNotFoundError extends errore.createTaggedError({
|
|
23
|
+
name: 'FlyNotFoundError',
|
|
24
|
+
message: 'Fly API returned 404 for $method $path',
|
|
25
|
+
}) {}
|
|
26
|
+
|
|
27
|
+
export class FlyPreconditionFailedError extends errore.createTaggedError({
|
|
28
|
+
name: 'FlyPreconditionFailedError',
|
|
29
|
+
message: 'Fly API returned 412 for $method $path',
|
|
30
|
+
}) {}
|
|
31
|
+
|
|
32
|
+
export class FlyUnprocessableEntityError extends errore.createTaggedError({
|
|
33
|
+
name: 'FlyUnprocessableEntityError',
|
|
34
|
+
message: 'Fly API returned 422 for $method $path',
|
|
35
|
+
}) {}
|
|
36
|
+
|
|
37
|
+
export class FlyInternalServerError extends errore.createTaggedError({
|
|
38
|
+
name: 'FlyInternalServerError',
|
|
39
|
+
message: 'Fly API returned 500 for $method $path',
|
|
40
|
+
}) {}
|
|
41
|
+
|
|
42
|
+
export class FlyGraphQLError extends errore.createTaggedError({
|
|
43
|
+
name: 'FlyGraphQLError',
|
|
44
|
+
message: 'Fly GraphQL request failed for $path: $messages',
|
|
45
|
+
}) {}
|
|
46
|
+
|
|
47
|
+
export type FlyClientError =
|
|
48
|
+
| FlyApiError
|
|
49
|
+
| FlyBadRequestError
|
|
50
|
+
| FlyUnauthorizedError
|
|
51
|
+
| FlyNotFoundError
|
|
52
|
+
| FlyPreconditionFailedError
|
|
53
|
+
| FlyUnprocessableEntityError
|
|
54
|
+
| FlyInternalServerError
|
|
55
|
+
| FlyGraphQLError
|
|
56
|
+
|
|
57
|
+
export type FlyResult<T> = FlyClientError | T
|
|
58
|
+
|
|
59
|
+
type ErrorResponsePayload = {
|
|
60
|
+
details?: Record<string, unknown>
|
|
61
|
+
error?: string
|
|
62
|
+
status?: MainStatusCode
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function parseErrorResponsePayload({
|
|
66
|
+
payload,
|
|
67
|
+
}: {
|
|
68
|
+
payload: unknown
|
|
69
|
+
}): ErrorResponsePayload | null {
|
|
70
|
+
if (!isObject(payload)) {
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const details = isObject(payload.details) ? payload.details : undefined
|
|
75
|
+
const error = typeof payload.error === 'string' ? payload.error : undefined
|
|
76
|
+
const status = isMainStatusCode(payload.status) ? payload.status : undefined
|
|
77
|
+
|
|
78
|
+
return { details, error, status }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createFlyHttpError({
|
|
82
|
+
method,
|
|
83
|
+
path,
|
|
84
|
+
httpStatus,
|
|
85
|
+
payload,
|
|
86
|
+
}: {
|
|
87
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
88
|
+
path: string
|
|
89
|
+
httpStatus: number
|
|
90
|
+
payload: unknown
|
|
91
|
+
}): FlyClientError {
|
|
92
|
+
parseErrorResponsePayload({ payload })
|
|
93
|
+
|
|
94
|
+
if (httpStatus === 400) {
|
|
95
|
+
return new FlyBadRequestError({ method, path })
|
|
96
|
+
}
|
|
97
|
+
if (httpStatus === 401) {
|
|
98
|
+
return new FlyUnauthorizedError({ method, path })
|
|
99
|
+
}
|
|
100
|
+
if (httpStatus === 404) {
|
|
101
|
+
return new FlyNotFoundError({ method, path })
|
|
102
|
+
}
|
|
103
|
+
if (httpStatus === 412) {
|
|
104
|
+
return new FlyPreconditionFailedError({ method, path })
|
|
105
|
+
}
|
|
106
|
+
if (httpStatus === 422) {
|
|
107
|
+
return new FlyUnprocessableEntityError({ method, path })
|
|
108
|
+
}
|
|
109
|
+
if (httpStatus === 500) {
|
|
110
|
+
return new FlyInternalServerError({ method, path })
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return new FlyApiError({ method, path, httpStatus })
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function createFlyGraphQLError({
|
|
117
|
+
path,
|
|
118
|
+
messages,
|
|
119
|
+
}: {
|
|
120
|
+
path: string
|
|
121
|
+
messages: string[]
|
|
122
|
+
}): FlyGraphQLError {
|
|
123
|
+
return new FlyGraphQLError({
|
|
124
|
+
path,
|
|
125
|
+
messages: messages.join('; '),
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
130
|
+
return typeof value === 'object' && value !== null
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isMainStatusCode(value: unknown): value is MainStatusCode {
|
|
134
|
+
return value === 'unknown' || value === 'insufficient_capacity'
|
|
135
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// fly-admin — TypeScript client for Fly Machines REST and GraphQL APIs.
|
|
2
|
+
// Vendored fork of supabase/fly-admin. Uses native fetch, adds exec/releaseLease/metadata.
|
|
3
|
+
|
|
4
|
+
export { Client, FLY_API_GRAPHQL, FLY_API_HOSTNAME } from './client.ts'
|
|
5
|
+
export type { ClientConfig } from './client.ts'
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
FlyApiError,
|
|
9
|
+
FlyBadRequestError,
|
|
10
|
+
FlyUnauthorizedError,
|
|
11
|
+
FlyNotFoundError,
|
|
12
|
+
FlyPreconditionFailedError,
|
|
13
|
+
FlyUnprocessableEntityError,
|
|
14
|
+
FlyInternalServerError,
|
|
15
|
+
FlyGraphQLError,
|
|
16
|
+
} from './errors.ts'
|
|
17
|
+
export type { FlyClientError, FlyResult } from './errors.ts'
|
|
18
|
+
|
|
19
|
+
export { App, AppStatus } from './app.ts'
|
|
20
|
+
export type {
|
|
21
|
+
ListAppRequest,
|
|
22
|
+
ListAppResponse,
|
|
23
|
+
ListAppsParams,
|
|
24
|
+
GetAppRequest,
|
|
25
|
+
AppOrganizationInfo,
|
|
26
|
+
AppInfo,
|
|
27
|
+
AppResponse,
|
|
28
|
+
IPAddress,
|
|
29
|
+
CreateAppRequest,
|
|
30
|
+
DeleteAppRequest,
|
|
31
|
+
ListCertificatesRequest,
|
|
32
|
+
RequestAcmeCertificateRequest,
|
|
33
|
+
RequestCustomCertificateRequest,
|
|
34
|
+
CertificateRequest,
|
|
35
|
+
CreateDeployTokenRequest,
|
|
36
|
+
ListSecretKeysRequest,
|
|
37
|
+
SecretKeyRequest,
|
|
38
|
+
SetSecretKeyRequest,
|
|
39
|
+
SecretKeyDecryptRequest,
|
|
40
|
+
SecretKeyEncryptRequest,
|
|
41
|
+
SecretKeySignRequest,
|
|
42
|
+
SecretKeyVerifyRequest,
|
|
43
|
+
ListSecretsRequest,
|
|
44
|
+
UpdateSecretsRequest,
|
|
45
|
+
SecretRequest,
|
|
46
|
+
SetSecretRequest,
|
|
47
|
+
AssignIPAddressRequest,
|
|
48
|
+
DeleteIPAddressRequest,
|
|
49
|
+
} from './app.ts'
|
|
50
|
+
|
|
51
|
+
export { Machine, MachineState, ConnectionHandler } from './machine.ts'
|
|
52
|
+
export type {
|
|
53
|
+
MachineConfig,
|
|
54
|
+
ListMachineRequest,
|
|
55
|
+
CreateMachineRequest,
|
|
56
|
+
MachineEvent,
|
|
57
|
+
MachineResponse,
|
|
58
|
+
GetMachineRequest,
|
|
59
|
+
DeleteMachineRequest,
|
|
60
|
+
RestartMachineRequest,
|
|
61
|
+
SignalMachineRequest,
|
|
62
|
+
StopMachineRequest,
|
|
63
|
+
StartMachineRequest,
|
|
64
|
+
UpdateMachineRequest,
|
|
65
|
+
ListEventsRequest,
|
|
66
|
+
ListVersionsRequest,
|
|
67
|
+
ListProcessesRequest,
|
|
68
|
+
ProcessResponse,
|
|
69
|
+
WaitMachineRequest,
|
|
70
|
+
WaitMachineStopRequest,
|
|
71
|
+
MachineVersionResponse,
|
|
72
|
+
GetLeaseRequest,
|
|
73
|
+
LeaseResponse,
|
|
74
|
+
AcquireLeaseRequest,
|
|
75
|
+
ReleaseLeaseRequest,
|
|
76
|
+
CordonMachineRequest,
|
|
77
|
+
UncordonMachineRequest,
|
|
78
|
+
ExecMachineRequest,
|
|
79
|
+
ExecMachineResponse,
|
|
80
|
+
GetMetadataRequest,
|
|
81
|
+
UpdateMetadataRequest,
|
|
82
|
+
GetMetadataPropertyRequest,
|
|
83
|
+
SetMetadataPropertyRequest,
|
|
84
|
+
DeleteMetadataPropertyRequest,
|
|
85
|
+
MachineMemoryResponse,
|
|
86
|
+
UpdateMemoryRequest,
|
|
87
|
+
ReclaimMemoryMachineRequest,
|
|
88
|
+
ReclaimMemoryResponse,
|
|
89
|
+
ListOrgMachinesRequest,
|
|
90
|
+
OrgMachinesResponse,
|
|
91
|
+
ListEventsOptions,
|
|
92
|
+
} from './machine.ts'
|
|
93
|
+
|
|
94
|
+
export { Network, AddressType } from './network.ts'
|
|
95
|
+
export type {
|
|
96
|
+
AllocateIPAddressInput,
|
|
97
|
+
AllocateIPAddressOutput,
|
|
98
|
+
ReleaseIPAddressInput,
|
|
99
|
+
ReleaseIPAddressOutput,
|
|
100
|
+
} from './network.ts'
|
|
101
|
+
|
|
102
|
+
export { Organization } from './organization.ts'
|
|
103
|
+
export type { GetOrganizationInput, GetOrganizationOutput } from './organization.ts'
|
|
104
|
+
|
|
105
|
+
export { Regions } from './regions.ts'
|
|
106
|
+
export type { GetRegionsOutput, GetPlatformRegionsRequest } from './regions.ts'
|
|
107
|
+
|
|
108
|
+
export { Token } from './token.ts'
|
|
109
|
+
export type { RequestOIDCTokenRequest } from './token.ts'
|
|
110
|
+
|
|
111
|
+
export { Secret } from './secret.ts'
|
|
112
|
+
export type {
|
|
113
|
+
SetSecretsInput,
|
|
114
|
+
SetSecretsOutput,
|
|
115
|
+
UnsetSecretsInput,
|
|
116
|
+
UnsetSecretsOutput,
|
|
117
|
+
} from './secret.ts'
|
|
118
|
+
|
|
119
|
+
export { Volume } from './volume.ts'
|
|
120
|
+
export type {
|
|
121
|
+
ListVolumesRequest,
|
|
122
|
+
CreateVolumeRequest,
|
|
123
|
+
VolumeResponse,
|
|
124
|
+
GetVolumeRequest,
|
|
125
|
+
UpdateVolumeRequest,
|
|
126
|
+
DeleteVolumeRequest,
|
|
127
|
+
ExtendVolumeRequest,
|
|
128
|
+
ExtendVolumeResponse,
|
|
129
|
+
ListSnapshotsRequest,
|
|
130
|
+
SnapshotResponse,
|
|
131
|
+
} from './volume.ts'
|
|
132
|
+
|
|
133
|
+
export type * from './types.ts'
|
|
134
|
+
|
|
135
|
+
export function createClient(apiKey: string, config?: { graphqlUrl?: string; apiUrl?: string }) {
|
|
136
|
+
return new Client(apiKey, config)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Re-export Client as default for backwards compat with supabase/fly-admin
|
|
140
|
+
import { Client } from './client.ts'
|
|
141
|
+
export default Client
|