@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/network.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Network (IP address) management via Fly GraphQL API.
|
|
2
|
+
|
|
3
|
+
import { Client } from './client.ts'
|
|
4
|
+
import type { FlyResult } from './errors.ts'
|
|
5
|
+
|
|
6
|
+
export enum AddressType {
|
|
7
|
+
v4 = 'v4',
|
|
8
|
+
v6 = 'v6',
|
|
9
|
+
private_v6 = 'private_v6',
|
|
10
|
+
shared_v4 = 'shared_v4',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AllocateIPAddressInput {
|
|
14
|
+
appId: string
|
|
15
|
+
type: AddressType
|
|
16
|
+
organizationId?: string
|
|
17
|
+
region?: string
|
|
18
|
+
network?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AllocateIPAddressOutput {
|
|
22
|
+
allocateIpAddress: {
|
|
23
|
+
ipAddress: {
|
|
24
|
+
id: string
|
|
25
|
+
address: string
|
|
26
|
+
type: AddressType
|
|
27
|
+
region: string
|
|
28
|
+
createdAt: string
|
|
29
|
+
} | null
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const allocateIpAddressQuery = `mutation($input: AllocateIPAddressInput!) {
|
|
34
|
+
allocateIpAddress(input: $input) {
|
|
35
|
+
ipAddress {
|
|
36
|
+
id
|
|
37
|
+
address
|
|
38
|
+
type
|
|
39
|
+
region
|
|
40
|
+
createdAt
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}`
|
|
44
|
+
|
|
45
|
+
export interface ReleaseIPAddressInput {
|
|
46
|
+
appId?: string
|
|
47
|
+
ipAddressId?: string
|
|
48
|
+
ip?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ReleaseIPAddressOutput {
|
|
52
|
+
releaseIpAddress: {
|
|
53
|
+
app: {
|
|
54
|
+
name: string
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const releaseIpAddressQuery = `mutation($input: ReleaseIPAddressInput!) {
|
|
60
|
+
releaseIpAddress(input: $input) {
|
|
61
|
+
app {
|
|
62
|
+
name
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}`
|
|
66
|
+
|
|
67
|
+
export class Network {
|
|
68
|
+
private client: Client
|
|
69
|
+
|
|
70
|
+
constructor(client: Client) {
|
|
71
|
+
this.client = client
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async allocateIpAddress(input: AllocateIPAddressInput): Promise<FlyResult<AllocateIPAddressOutput>> {
|
|
75
|
+
return this.client.gqlPostOrThrow({
|
|
76
|
+
query: allocateIpAddressQuery,
|
|
77
|
+
variables: { input },
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async releaseIpAddress(input: ReleaseIPAddressInput): Promise<FlyResult<ReleaseIPAddressOutput>> {
|
|
82
|
+
return this.client.gqlPostOrThrow({
|
|
83
|
+
query: releaseIpAddressQuery,
|
|
84
|
+
variables: { input },
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Organization queries via Fly GraphQL API.
|
|
2
|
+
|
|
3
|
+
import { Client } from './client.ts'
|
|
4
|
+
import type { FlyResult } from './errors.ts'
|
|
5
|
+
|
|
6
|
+
export type GetOrganizationInput = string
|
|
7
|
+
|
|
8
|
+
interface OrganizationResponse {
|
|
9
|
+
id: string
|
|
10
|
+
slug: string
|
|
11
|
+
name: string
|
|
12
|
+
type: 'PERSONAL' | 'SHARED'
|
|
13
|
+
viewerRole: 'admin' | 'member'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface GetOrganizationOutput {
|
|
17
|
+
organization: OrganizationResponse
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getOrganizationQuery = `query($slug: String!) {
|
|
21
|
+
organization(slug: $slug) {
|
|
22
|
+
id
|
|
23
|
+
slug
|
|
24
|
+
name
|
|
25
|
+
type
|
|
26
|
+
viewerRole
|
|
27
|
+
}
|
|
28
|
+
}`
|
|
29
|
+
|
|
30
|
+
export class Organization {
|
|
31
|
+
private client: Client
|
|
32
|
+
|
|
33
|
+
constructor(client: Client) {
|
|
34
|
+
this.client = client
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getOrganization(slug: GetOrganizationInput): Promise<FlyResult<GetOrganizationOutput>> {
|
|
38
|
+
return this.client.gqlPostOrThrow({
|
|
39
|
+
query: getOrganizationQuery,
|
|
40
|
+
variables: { slug },
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/regions.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Region listing via Fly GraphQL API.
|
|
2
|
+
|
|
3
|
+
import { Client } from './client.ts'
|
|
4
|
+
import type { FlyResult } from './errors.ts'
|
|
5
|
+
import type {
|
|
6
|
+
MainGetPlacementsRequest,
|
|
7
|
+
MainGetPlacementsResponse,
|
|
8
|
+
MainRegionResponse,
|
|
9
|
+
} from './types.ts'
|
|
10
|
+
|
|
11
|
+
interface RegionResponse {
|
|
12
|
+
name: string
|
|
13
|
+
code: string
|
|
14
|
+
latitude: number
|
|
15
|
+
longitude: number
|
|
16
|
+
gatewayAvailable: boolean
|
|
17
|
+
requiresPaidPlan: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface PlatformResponse {
|
|
21
|
+
requestRegion: string
|
|
22
|
+
regions: RegionResponse[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GetRegionsOutput {
|
|
26
|
+
platform: PlatformResponse
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface GetPlatformRegionsRequest {
|
|
30
|
+
size?: string
|
|
31
|
+
cpu_kind?: string
|
|
32
|
+
memory_mb?: number
|
|
33
|
+
cpus?: number
|
|
34
|
+
gpus?: number
|
|
35
|
+
gpu_kind?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const getRegionsQuery = `query {
|
|
39
|
+
platform {
|
|
40
|
+
requestRegion
|
|
41
|
+
regions {
|
|
42
|
+
name
|
|
43
|
+
code
|
|
44
|
+
latitude
|
|
45
|
+
longitude
|
|
46
|
+
gatewayAvailable
|
|
47
|
+
requiresPaidPlan
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}`
|
|
51
|
+
|
|
52
|
+
export class Regions {
|
|
53
|
+
private client: Client
|
|
54
|
+
|
|
55
|
+
constructor(client: Client) {
|
|
56
|
+
this.client = client
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getRegions(): Promise<FlyResult<GetRegionsOutput>> {
|
|
60
|
+
return this.client.gqlPostOrThrow({
|
|
61
|
+
query: getRegionsQuery,
|
|
62
|
+
variables: {},
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getPlatformRegions(payload: GetPlatformRegionsRequest = {}): Promise<FlyResult<MainRegionResponse>> {
|
|
67
|
+
const params = new URLSearchParams()
|
|
68
|
+
if (payload.size) {
|
|
69
|
+
params.set('size', payload.size)
|
|
70
|
+
}
|
|
71
|
+
if (payload.cpu_kind) {
|
|
72
|
+
params.set('cpu_kind', payload.cpu_kind)
|
|
73
|
+
}
|
|
74
|
+
if (payload.memory_mb !== undefined) {
|
|
75
|
+
params.set('memory_mb', String(payload.memory_mb))
|
|
76
|
+
}
|
|
77
|
+
if (payload.cpus !== undefined) {
|
|
78
|
+
params.set('cpus', String(payload.cpus))
|
|
79
|
+
}
|
|
80
|
+
if (payload.gpus !== undefined) {
|
|
81
|
+
params.set('gpus', String(payload.gpus))
|
|
82
|
+
}
|
|
83
|
+
if (payload.gpu_kind) {
|
|
84
|
+
params.set('gpu_kind', payload.gpu_kind)
|
|
85
|
+
}
|
|
86
|
+
const query = params.toString()
|
|
87
|
+
const path = `platform/regions${query ? `?${query}` : ''}`
|
|
88
|
+
return await this.client.restOrThrow(path)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async getPlacements(request: MainGetPlacementsRequest): Promise<FlyResult<MainGetPlacementsResponse>> {
|
|
92
|
+
return await this.client.restOrThrow('platform/placements', 'POST', request)
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/secret.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Secrets management via Fly GraphQL API.
|
|
2
|
+
|
|
3
|
+
import { Client } from './client.ts'
|
|
4
|
+
import type { FlyResult } from './errors.ts'
|
|
5
|
+
|
|
6
|
+
export interface SetSecretsInput {
|
|
7
|
+
appId: string
|
|
8
|
+
secrets: { key: string; value: string }[]
|
|
9
|
+
replaceAll?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SetSecretsOutput {
|
|
13
|
+
setSecrets: {
|
|
14
|
+
release: {
|
|
15
|
+
id: string
|
|
16
|
+
version: string
|
|
17
|
+
reason: string
|
|
18
|
+
description: string
|
|
19
|
+
user: { id: string; email: string; name: string }
|
|
20
|
+
evaluationId: string
|
|
21
|
+
createdAt: string
|
|
22
|
+
} | null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const setSecretsQuery = `mutation($input: SetSecretsInput!) {
|
|
27
|
+
setSecrets(input: $input) {
|
|
28
|
+
release {
|
|
29
|
+
id
|
|
30
|
+
version
|
|
31
|
+
reason
|
|
32
|
+
description
|
|
33
|
+
user {
|
|
34
|
+
id
|
|
35
|
+
email
|
|
36
|
+
name
|
|
37
|
+
}
|
|
38
|
+
evaluationId
|
|
39
|
+
createdAt
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}`
|
|
43
|
+
|
|
44
|
+
export interface UnsetSecretsInput {
|
|
45
|
+
appId: string
|
|
46
|
+
keys: string[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface UnsetSecretsOutput {
|
|
50
|
+
unsetSecrets: {
|
|
51
|
+
release: {
|
|
52
|
+
id: string
|
|
53
|
+
version: string
|
|
54
|
+
reason: string
|
|
55
|
+
description: string
|
|
56
|
+
user: { id: string; email: string; name: string }
|
|
57
|
+
evaluationId: string
|
|
58
|
+
createdAt: string
|
|
59
|
+
} | null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const unsetSecretsQuery = `mutation($input: UnsetSecretsInput!) {
|
|
64
|
+
unsetSecrets(input: $input) {
|
|
65
|
+
release {
|
|
66
|
+
id
|
|
67
|
+
version
|
|
68
|
+
reason
|
|
69
|
+
description
|
|
70
|
+
user {
|
|
71
|
+
id
|
|
72
|
+
email
|
|
73
|
+
name
|
|
74
|
+
}
|
|
75
|
+
evaluationId
|
|
76
|
+
createdAt
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}`
|
|
80
|
+
|
|
81
|
+
export class Secret {
|
|
82
|
+
private client: Client
|
|
83
|
+
|
|
84
|
+
constructor(client: Client) {
|
|
85
|
+
this.client = client
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async setSecrets(input: SetSecretsInput): Promise<FlyResult<SetSecretsOutput>> {
|
|
89
|
+
return await this.client.gqlPostOrThrow({
|
|
90
|
+
query: setSecretsQuery,
|
|
91
|
+
variables: { input },
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async unsetSecrets(input: UnsetSecretsInput): Promise<FlyResult<UnsetSecretsOutput>> {
|
|
96
|
+
return await this.client.gqlPostOrThrow({
|
|
97
|
+
query: unsetSecretsQuery,
|
|
98
|
+
variables: { input },
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/token.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Token management for Fly Machines REST API.
|
|
2
|
+
|
|
3
|
+
import { Client } from './client.ts'
|
|
4
|
+
import type { CreateOIDCTokenRequest, CurrentTokenResponse } from './types.ts'
|
|
5
|
+
import type { FlyResult } from './errors.ts'
|
|
6
|
+
|
|
7
|
+
export interface RequestOIDCTokenRequest {
|
|
8
|
+
request: CreateOIDCTokenRequest
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Token {
|
|
12
|
+
private client: Client
|
|
13
|
+
|
|
14
|
+
constructor(client: Client) {
|
|
15
|
+
this.client = client
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async requestKmsToken(): Promise<FlyResult<string>> {
|
|
19
|
+
return await this.client.restOrThrow('tokens/kms', 'POST')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async requestOidcToken(payload: RequestOIDCTokenRequest): Promise<FlyResult<string>> {
|
|
23
|
+
return await this.client.restOrThrow('tokens/oidc', 'POST', payload.request)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getCurrentToken(): Promise<FlyResult<CurrentTokenResponse>> {
|
|
27
|
+
return await this.client.restOrThrow('tokens/current')
|
|
28
|
+
}
|
|
29
|
+
}
|