@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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app.d.ts +181 -0
  3. package/dist/app.d.ts.map +1 -0
  4. package/dist/app.js +212 -0
  5. package/dist/client.d.ts +42 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +200 -0
  8. package/dist/errors.d.ts +48 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +85 -0
  11. package/dist/index.d.ts +28 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +18 -0
  14. package/dist/machine.d.ts +319 -0
  15. package/dist/machine.d.ts.map +1 -0
  16. package/dist/machine.js +249 -0
  17. package/dist/network.d.ts +45 -0
  18. package/dist/network.d.ts.map +1 -0
  19. package/dist/network.js +44 -0
  20. package/dist/organization.d.ts +20 -0
  21. package/dist/organization.d.ts.map +1 -0
  22. package/dist/organization.js +22 -0
  23. package/dist/regions.d.ts +35 -0
  24. package/dist/regions.d.ts.map +1 -0
  25. package/dist/regions.js +53 -0
  26. package/dist/secret.d.ts +55 -0
  27. package/dist/secret.d.ts.map +1 -0
  28. package/dist/secret.js +53 -0
  29. package/dist/token.d.ts +14 -0
  30. package/dist/token.d.ts.map +1 -0
  31. package/dist/token.js +16 -0
  32. package/dist/types.d.ts +937 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/dist/types.js +40 -0
  35. package/dist/volume.d.ts +72 -0
  36. package/dist/volume.d.ts.map +1 -0
  37. package/dist/volume.js +45 -0
  38. package/package.json +54 -0
  39. package/src/app.ts +462 -0
  40. package/src/client.ts +262 -0
  41. package/src/errors.ts +135 -0
  42. package/src/index.ts +141 -0
  43. package/src/machine.ts +644 -0
  44. package/src/network.ts +87 -0
  45. package/src/organization.ts +43 -0
  46. package/src/regions.ts +94 -0
  47. package/src/secret.ts +101 -0
  48. package/src/token.ts +29 -0
  49. package/src/types.ts +1072 -0
  50. package/src/volume.ts +124 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kimaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/app.d.ts ADDED
@@ -0,0 +1,181 @@
1
+ import { Client } from './client.ts';
2
+ import type { FlyResult } from './errors.ts';
3
+ import type { App as ApiApp, AppOrganizationInfo as ApiAppOrganizationInfo, AppSecret, AppSecrets, AppSecretsUpdateRequest, AppSecretsUpdateResp, CertificateCheckResponse, CertificateDetail, CreateAcmeCertificateRequest, CreateAppDeployTokenRequest, CreateAppResponse, CreateCustomCertificateRequest, DeleteAppSecretResponse, DeleteSecretkeyResponse, DecryptSecretkeyRequest, DecryptSecretkeyResponse, DestroyCustomCertificateResponse, EncryptSecretkeyRequest, EncryptSecretkeyResponse, IPAssignment, ListAppsResponse as ApiListAppsResponse, ListCertificatesResponse, ListIPAssignmentsResponse, SecretKey, SecretKeys, SetAppSecretRequest, SetAppSecretResponse, SetSecretkeyRequest, SetSecretkeyResponse, SignSecretkeyRequest, SignSecretkeyResponse, VerifySecretkeyRequest } from './types.ts';
4
+ export type ListAppRequest = string;
5
+ /** Matches OpenAPI ListAppsResponse schema. */
6
+ export type ListAppResponse = ApiListAppsResponse;
7
+ /** Query params for GET /apps. org_slug is required, app_role is optional. */
8
+ export interface ListAppsParams {
9
+ org_slug: string;
10
+ app_role?: string;
11
+ }
12
+ export type GetAppRequest = string;
13
+ export declare enum AppStatus {
14
+ deployed = "deployed",
15
+ pending = "pending",
16
+ suspended = "suspended"
17
+ }
18
+ /** Matches OpenAPI AppOrganizationInfo schema. */
19
+ export type AppOrganizationInfo = ApiAppOrganizationInfo;
20
+ /** Matches OpenAPI App schema — used in both GET /apps/{app_name} and ListAppsResponse. */
21
+ export type AppInfo = ApiApp;
22
+ /**
23
+ * Full app response from GraphQL getAppDetailed.
24
+ * Extends REST AppInfo with ipAddresses from the GraphQL query.
25
+ */
26
+ export interface AppResponse {
27
+ name: string;
28
+ status: AppStatus;
29
+ organization: {
30
+ name: string;
31
+ slug: string;
32
+ };
33
+ ipAddresses: IPAddress[];
34
+ }
35
+ export interface IPAddress {
36
+ type: string;
37
+ region?: string;
38
+ address: string;
39
+ }
40
+ /**
41
+ * Matches OpenAPI CreateAppRequest schema.
42
+ * Note: the spec uses `name` (not `app_name`) for the app name field.
43
+ */
44
+ export interface CreateAppRequest {
45
+ org_slug: string;
46
+ name: string;
47
+ network?: string;
48
+ enable_subdomains?: boolean;
49
+ }
50
+ export type DeleteAppRequest = string;
51
+ export interface ListCertificatesRequest {
52
+ app_name: string;
53
+ filter?: string;
54
+ cursor?: string;
55
+ limit?: number;
56
+ }
57
+ export interface RequestAcmeCertificateRequest {
58
+ app_name: string;
59
+ request: CreateAcmeCertificateRequest;
60
+ }
61
+ export interface RequestCustomCertificateRequest {
62
+ app_name: string;
63
+ request: CreateCustomCertificateRequest;
64
+ }
65
+ export interface CertificateRequest {
66
+ app_name: string;
67
+ hostname: string;
68
+ }
69
+ export interface CreateDeployTokenRequest {
70
+ app_name: string;
71
+ request: CreateAppDeployTokenRequest;
72
+ }
73
+ export interface ListSecretKeysRequest {
74
+ app_name: string;
75
+ min_version?: string;
76
+ types?: string;
77
+ }
78
+ export interface SecretKeyRequest {
79
+ app_name: string;
80
+ secret_name: string;
81
+ min_version?: string;
82
+ }
83
+ export interface SetSecretKeyRequest {
84
+ app_name: string;
85
+ secret_name: string;
86
+ request: SetSecretkeyRequest;
87
+ }
88
+ export interface SecretKeyDecryptRequest {
89
+ app_name: string;
90
+ secret_name: string;
91
+ request: DecryptSecretkeyRequest;
92
+ min_version?: string;
93
+ }
94
+ export interface SecretKeyEncryptRequest {
95
+ app_name: string;
96
+ secret_name: string;
97
+ request: EncryptSecretkeyRequest;
98
+ min_version?: string;
99
+ }
100
+ export interface SecretKeySignRequest {
101
+ app_name: string;
102
+ secret_name: string;
103
+ request: SignSecretkeyRequest;
104
+ min_version?: string;
105
+ }
106
+ export interface SecretKeyVerifyRequest {
107
+ app_name: string;
108
+ secret_name: string;
109
+ request: VerifySecretkeyRequest;
110
+ min_version?: string;
111
+ }
112
+ export interface ListSecretsRequest {
113
+ app_name: string;
114
+ min_version?: string;
115
+ show_secrets?: boolean;
116
+ }
117
+ export interface UpdateSecretsRequest {
118
+ app_name: string;
119
+ request: AppSecretsUpdateRequest;
120
+ }
121
+ export interface SecretRequest {
122
+ app_name: string;
123
+ secret_name: string;
124
+ min_version?: string;
125
+ show_secrets?: boolean;
126
+ }
127
+ export interface SetSecretRequest {
128
+ app_name: string;
129
+ secret_name: string;
130
+ request: SetAppSecretRequest;
131
+ }
132
+ export interface AssignIPAddressRequest {
133
+ app_name: string;
134
+ request: {
135
+ region?: string;
136
+ service_name?: string;
137
+ type?: string;
138
+ };
139
+ }
140
+ export interface DeleteIPAddressRequest {
141
+ app_name: string;
142
+ ip: string;
143
+ }
144
+ export declare class App {
145
+ private client;
146
+ constructor(client: Client);
147
+ listApps(org_slug: ListAppRequest): Promise<FlyResult<ListAppResponse>>;
148
+ /** List apps with full query params (org_slug + optional app_role filter). */
149
+ listAppsWithParams(params: ListAppsParams): Promise<FlyResult<ListAppResponse>>;
150
+ getApp(app_name: GetAppRequest): Promise<FlyResult<AppInfo>>;
151
+ getAppDetailed(app_name: GetAppRequest): Promise<FlyResult<AppResponse>>;
152
+ createApp(payload: CreateAppRequest): Promise<FlyResult<void>>;
153
+ deleteApp(app_name: DeleteAppRequest): Promise<FlyResult<void>>;
154
+ listCertificates(payload: ListCertificatesRequest): Promise<FlyResult<ListCertificatesResponse>>;
155
+ requestAcmeCertificate(payload: RequestAcmeCertificateRequest): Promise<FlyResult<CertificateDetail>>;
156
+ requestCustomCertificate(payload: RequestCustomCertificateRequest): Promise<FlyResult<CertificateDetail>>;
157
+ getCertificate(payload: CertificateRequest): Promise<FlyResult<CertificateDetail>>;
158
+ deleteCertificate(payload: CertificateRequest): Promise<FlyResult<void>>;
159
+ deleteAcmeCertificates(payload: CertificateRequest): Promise<FlyResult<CertificateDetail>>;
160
+ checkCertificate(payload: CertificateRequest): Promise<FlyResult<CertificateCheckResponse>>;
161
+ deleteCustomCertificate(payload: CertificateRequest): Promise<FlyResult<DestroyCustomCertificateResponse>>;
162
+ createDeployToken(payload: CreateDeployTokenRequest): Promise<FlyResult<CreateAppResponse>>;
163
+ listIpAssignments(app_name: string): Promise<FlyResult<ListIPAssignmentsResponse>>;
164
+ assignIpAddress(payload: AssignIPAddressRequest): Promise<FlyResult<IPAssignment>>;
165
+ deleteIpAssignment(payload: DeleteIPAddressRequest): Promise<FlyResult<void>>;
166
+ listSecretKeys(payload: ListSecretKeysRequest): Promise<FlyResult<SecretKeys>>;
167
+ getSecretKey(payload: SecretKeyRequest): Promise<FlyResult<SecretKey>>;
168
+ setSecretKey(payload: SetSecretKeyRequest): Promise<FlyResult<SetSecretkeyResponse>>;
169
+ deleteSecretKey(payload: SecretKeyRequest): Promise<FlyResult<DeleteSecretkeyResponse>>;
170
+ decryptSecretKey(payload: SecretKeyDecryptRequest): Promise<FlyResult<DecryptSecretkeyResponse>>;
171
+ encryptSecretKey(payload: SecretKeyEncryptRequest): Promise<FlyResult<EncryptSecretkeyResponse>>;
172
+ generateSecretKey(payload: SetSecretKeyRequest): Promise<FlyResult<SetSecretkeyResponse>>;
173
+ signSecretKey(payload: SecretKeySignRequest): Promise<FlyResult<SignSecretkeyResponse>>;
174
+ verifySecretKey(payload: SecretKeyVerifyRequest): Promise<FlyResult<void>>;
175
+ listSecrets(payload: ListSecretsRequest): Promise<FlyResult<AppSecrets>>;
176
+ updateSecrets(payload: UpdateSecretsRequest): Promise<FlyResult<AppSecretsUpdateResp>>;
177
+ getSecret(payload: SecretRequest): Promise<FlyResult<AppSecret>>;
178
+ setSecret(payload: SetSecretRequest): Promise<FlyResult<SetAppSecretResponse>>;
179
+ deleteSecret(payload: SecretRequest): Promise<FlyResult<DeleteAppSecretResponse>>;
180
+ }
181
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EACV,GAAG,IAAI,MAAM,EACb,mBAAmB,IAAI,sBAAsB,EAC7C,SAAS,EACT,UAAU,EACV,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,4BAA4B,EAC5B,2BAA2B,EAC3B,iBAAiB,EACjB,8BAA8B,EAC9B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,gCAAgC,EAChC,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,IAAI,mBAAmB,EACvC,wBAAwB,EACxB,yBAAyB,EACzB,SA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,SAAS,CAAC,UAAU,CAAC,CAAC;IAcxE,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;IAKtF,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAchE,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;IAK9E,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;CAIxF"}
package/dist/app.js ADDED
@@ -0,0 +1,212 @@
1
+ // App management for Fly Machines REST + GraphQL API.
2
+ // Types aligned with OpenAPI spec at https://docs.machines.dev/spec/openapi3.json
3
+ const getAppQuery = `query($name: String!) {
4
+ app(name: $name) {
5
+ name
6
+ status
7
+ organization {
8
+ name
9
+ slug
10
+ }
11
+ ipAddresses {
12
+ nodes {
13
+ type
14
+ region
15
+ address
16
+ }
17
+ }
18
+ }
19
+ }`;
20
+ export var AppStatus;
21
+ (function (AppStatus) {
22
+ AppStatus["deployed"] = "deployed";
23
+ AppStatus["pending"] = "pending";
24
+ AppStatus["suspended"] = "suspended";
25
+ })(AppStatus || (AppStatus = {}));
26
+ export class App {
27
+ client;
28
+ constructor(client) {
29
+ this.client = client;
30
+ }
31
+ async listApps(org_slug) {
32
+ return await this.client.restOrThrow(`apps?org_slug=${org_slug}`);
33
+ }
34
+ /** List apps with full query params (org_slug + optional app_role filter). */
35
+ async listAppsWithParams(params) {
36
+ const query = new URLSearchParams({ org_slug: params.org_slug });
37
+ if (params.app_role) {
38
+ query.set('app_role', params.app_role);
39
+ }
40
+ return await this.client.restOrThrow(`apps?${query.toString()}`);
41
+ }
42
+ async getApp(app_name) {
43
+ return await this.client.restOrThrow(`apps/${app_name}`);
44
+ }
45
+ async getAppDetailed(app_name) {
46
+ const result = await this.client.gqlPostOrThrow({
47
+ query: getAppQuery,
48
+ variables: { name: app_name },
49
+ });
50
+ if (result instanceof Error) {
51
+ return result;
52
+ }
53
+ const { app } = result;
54
+ return {
55
+ ...app,
56
+ ipAddresses: app.ipAddresses.nodes,
57
+ };
58
+ }
59
+ async createApp(payload) {
60
+ return await this.client.restOrThrow('apps', 'POST', payload);
61
+ }
62
+ async deleteApp(app_name) {
63
+ return await this.client.restOrThrow(`apps/${app_name}`, 'DELETE');
64
+ }
65
+ async listCertificates(payload) {
66
+ const { app_name, filter, cursor, limit } = payload;
67
+ const params = new URLSearchParams();
68
+ if (filter) {
69
+ params.set('filter', filter);
70
+ }
71
+ if (cursor) {
72
+ params.set('cursor', cursor);
73
+ }
74
+ if (limit !== undefined) {
75
+ params.set('limit', String(limit));
76
+ }
77
+ const query = params.toString();
78
+ const path = `apps/${app_name}/certificates${query ? `?${query}` : ''}`;
79
+ return await this.client.restOrThrow(path);
80
+ }
81
+ async requestAcmeCertificate(payload) {
82
+ const { app_name, request } = payload;
83
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/acme`, 'POST', request);
84
+ }
85
+ async requestCustomCertificate(payload) {
86
+ const { app_name, request } = payload;
87
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/custom`, 'POST', request);
88
+ }
89
+ async getCertificate(payload) {
90
+ const { app_name, hostname } = payload;
91
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/${hostname}`);
92
+ }
93
+ async deleteCertificate(payload) {
94
+ const { app_name, hostname } = payload;
95
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/${hostname}`, 'DELETE');
96
+ }
97
+ async deleteAcmeCertificates(payload) {
98
+ const { app_name, hostname } = payload;
99
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/${hostname}/acme`, 'DELETE');
100
+ }
101
+ async checkCertificate(payload) {
102
+ const { app_name, hostname } = payload;
103
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/${hostname}/check`, 'POST');
104
+ }
105
+ async deleteCustomCertificate(payload) {
106
+ const { app_name, hostname } = payload;
107
+ return await this.client.restOrThrow(`apps/${app_name}/certificates/${hostname}/custom`, 'DELETE');
108
+ }
109
+ async createDeployToken(payload) {
110
+ const { app_name, request } = payload;
111
+ return await this.client.restOrThrow(`apps/${app_name}/deploy_token`, 'POST', request);
112
+ }
113
+ async listIpAssignments(app_name) {
114
+ return await this.client.restOrThrow(`apps/${app_name}/ip_assignments`);
115
+ }
116
+ async assignIpAddress(payload) {
117
+ const { app_name, request } = payload;
118
+ return await this.client.restOrThrow(`apps/${app_name}/ip_assignments`, 'POST', request);
119
+ }
120
+ async deleteIpAssignment(payload) {
121
+ const { app_name, ip } = payload;
122
+ return await this.client.restOrThrow(`apps/${app_name}/ip_assignments/${ip}`, 'DELETE');
123
+ }
124
+ async listSecretKeys(payload) {
125
+ const { app_name, min_version, types } = payload;
126
+ const params = new URLSearchParams();
127
+ if (min_version) {
128
+ params.set('min_version', min_version);
129
+ }
130
+ if (types) {
131
+ params.set('types', types);
132
+ }
133
+ const query = params.toString();
134
+ const path = `apps/${app_name}/secretkeys${query ? `?${query}` : ''}`;
135
+ return await this.client.restOrThrow(path);
136
+ }
137
+ async getSecretKey(payload) {
138
+ const { app_name, secret_name, min_version } = payload;
139
+ const query = min_version ? `?min_version=${encodeURIComponent(min_version)}` : '';
140
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}${query}`);
141
+ }
142
+ async setSecretKey(payload) {
143
+ const { app_name, secret_name, request } = payload;
144
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}`, 'POST', request);
145
+ }
146
+ async deleteSecretKey(payload) {
147
+ const { app_name, secret_name } = payload;
148
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}`, 'DELETE');
149
+ }
150
+ async decryptSecretKey(payload) {
151
+ const { app_name, secret_name, request, min_version } = payload;
152
+ const query = min_version ? `?min_version=${encodeURIComponent(min_version)}` : '';
153
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}/decrypt${query}`, 'POST', request);
154
+ }
155
+ async encryptSecretKey(payload) {
156
+ const { app_name, secret_name, request, min_version } = payload;
157
+ const query = min_version ? `?min_version=${encodeURIComponent(min_version)}` : '';
158
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}/encrypt${query}`, 'POST', request);
159
+ }
160
+ async generateSecretKey(payload) {
161
+ const { app_name, secret_name, request } = payload;
162
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}/generate`, 'POST', request);
163
+ }
164
+ async signSecretKey(payload) {
165
+ const { app_name, secret_name, request, min_version } = payload;
166
+ const query = min_version ? `?min_version=${encodeURIComponent(min_version)}` : '';
167
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}/sign${query}`, 'POST', request);
168
+ }
169
+ async verifySecretKey(payload) {
170
+ const { app_name, secret_name, request, min_version } = payload;
171
+ const query = min_version ? `?min_version=${encodeURIComponent(min_version)}` : '';
172
+ return await this.client.restOrThrow(`apps/${app_name}/secretkeys/${secret_name}/verify${query}`, 'POST', request);
173
+ }
174
+ async listSecrets(payload) {
175
+ const { app_name, min_version, show_secrets } = payload;
176
+ const params = new URLSearchParams();
177
+ if (min_version) {
178
+ params.set('min_version', min_version);
179
+ }
180
+ if (show_secrets !== undefined) {
181
+ params.set('show_secrets', String(show_secrets));
182
+ }
183
+ const query = params.toString();
184
+ const path = `apps/${app_name}/secrets${query ? `?${query}` : ''}`;
185
+ return await this.client.restOrThrow(path);
186
+ }
187
+ async updateSecrets(payload) {
188
+ const { app_name, request } = payload;
189
+ return await this.client.restOrThrow(`apps/${app_name}/secrets`, 'POST', request);
190
+ }
191
+ async getSecret(payload) {
192
+ const { app_name, secret_name, min_version, show_secrets } = payload;
193
+ const params = new URLSearchParams();
194
+ if (min_version) {
195
+ params.set('min_version', min_version);
196
+ }
197
+ if (show_secrets !== undefined) {
198
+ params.set('show_secrets', String(show_secrets));
199
+ }
200
+ const query = params.toString();
201
+ const path = `apps/${app_name}/secrets/${secret_name}${query ? `?${query}` : ''}`;
202
+ return await this.client.restOrThrow(path);
203
+ }
204
+ async setSecret(payload) {
205
+ const { app_name, secret_name, request } = payload;
206
+ return await this.client.restOrThrow(`apps/${app_name}/secrets/${secret_name}`, 'POST', request);
207
+ }
208
+ async deleteSecret(payload) {
209
+ const { app_name, secret_name } = payload;
210
+ return await this.client.restOrThrow(`apps/${app_name}/secrets/${secret_name}`, 'DELETE');
211
+ }
212
+ }
@@ -0,0 +1,42 @@
1
+ import { App } from './app.ts';
2
+ import { type FlyClientError, type FlyResult } from './errors.ts';
3
+ import { Machine } from './machine.ts';
4
+ import { Network } from './network.ts';
5
+ import { Organization } from './organization.ts';
6
+ import { Regions } from './regions.ts';
7
+ import { Secret } from './secret.ts';
8
+ import { Token } from './token.ts';
9
+ import { Volume } from './volume.ts';
10
+ export declare const FLY_API_GRAPHQL = "https://api.fly.io";
11
+ export declare const FLY_API_HOSTNAME = "https://api.machines.dev";
12
+ interface GraphQLRequest<T> {
13
+ query: string;
14
+ variables?: Record<string, T>;
15
+ }
16
+ export interface ClientConfig {
17
+ graphqlUrl?: string;
18
+ apiUrl?: string;
19
+ }
20
+ export declare class Client {
21
+ private graphqlUrl;
22
+ private apiUrl;
23
+ private apiKey;
24
+ App: App;
25
+ Machine: Machine;
26
+ Regions: Regions;
27
+ Network: Network;
28
+ Organization: Organization;
29
+ Secret: Secret;
30
+ Volume: Volume;
31
+ Token: Token;
32
+ constructor(apiKey: string, { graphqlUrl, apiUrl }?: ClientConfig);
33
+ getApiKey(): string;
34
+ getApiUrl(): string;
35
+ getGraphqlUrl(): string;
36
+ gqlPost<U, V>(payload: GraphQLRequest<U>): Promise<FlyClientError | V>;
37
+ gqlPostOrThrow<U, V>(payload: GraphQLRequest<U>): Promise<FlyResult<V>>;
38
+ rest<V>(path: string, method?: 'GET' | 'POST' | 'PUT' | 'DELETE', body?: unknown, headers?: Record<string, string>): Promise<FlyClientError | V>;
39
+ restOrThrow<V>(path: string, method?: 'GET' | 'POST' | 'PUT' | 'DELETE', body?: unknown, headers?: Record<string, string>): Promise<FlyResult<V>>;
40
+ }
41
+ export {};
42
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,eAAO,MAAM,eAAe,uBAAuB,CAAA;AACnD,eAAO,MAAM,gBAAgB,6BAA6B,CAAA;AAE1D,UAAU,cAAc,CAAC,CAAC;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;CAC9B;AAUD,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CAAQ;IACtB,GAAG,EAAE,GAAG,CAAA;IACR,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,KAAK,CAAA;gBAEA,MAAM,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAAE,YAAiB;IAiBrE,SAAS,IAAI,MAAM;IAInB,SAAS,IAAI,MAAM;IAInB,aAAa,IAAI,MAAM;IAIjB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,cAAc,GAAG,CAAC,CAAC;IA6EtE,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAIvE,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAgB,EACjD,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,cAAc,GAAG,CAAC,CAAC;IAuExB,WAAW,CAAC,CAAC,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAgB,EACjD,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAGzB"}
package/dist/client.js ADDED
@@ -0,0 +1,200 @@
1
+ // HTTP client for Fly.io Machines REST API and GraphQL API.
2
+ // Uses native fetch (no cross-fetch dependency).
3
+ // Vendored from supabase/fly-admin with modifications.
4
+ import * as errore from 'errore';
5
+ import { App } from "./app.js";
6
+ import { createFlyGraphQLError, createFlyHttpError, FlyApiError, } from "./errors.js";
7
+ import { Machine } from "./machine.js";
8
+ import { Network } from "./network.js";
9
+ import { Organization } from "./organization.js";
10
+ import { Regions } from "./regions.js";
11
+ import { Secret } from "./secret.js";
12
+ import { Token } from "./token.js";
13
+ import { Volume } from "./volume.js";
14
+ export const FLY_API_GRAPHQL = 'https://api.fly.io';
15
+ export const FLY_API_HOSTNAME = 'https://api.machines.dev';
16
+ export class Client {
17
+ graphqlUrl;
18
+ apiUrl;
19
+ apiKey;
20
+ App;
21
+ Machine;
22
+ Regions;
23
+ Network;
24
+ Organization;
25
+ Secret;
26
+ Volume;
27
+ Token;
28
+ constructor(apiKey, { graphqlUrl, apiUrl } = {}) {
29
+ if (!apiKey) {
30
+ throw new Error('Fly API Key is required');
31
+ }
32
+ this.graphqlUrl = graphqlUrl || FLY_API_GRAPHQL;
33
+ this.apiUrl = apiUrl || FLY_API_HOSTNAME;
34
+ this.apiKey = apiKey;
35
+ this.App = new App(this);
36
+ this.Machine = new Machine(this);
37
+ this.Network = new Network(this);
38
+ this.Regions = new Regions(this);
39
+ this.Organization = new Organization(this);
40
+ this.Secret = new Secret(this);
41
+ this.Volume = new Volume(this);
42
+ this.Token = new Token(this);
43
+ }
44
+ getApiKey() {
45
+ return this.apiKey;
46
+ }
47
+ getApiUrl() {
48
+ return this.apiUrl;
49
+ }
50
+ getGraphqlUrl() {
51
+ return this.graphqlUrl;
52
+ }
53
+ async gqlPost(payload) {
54
+ const path = 'graphql';
55
+ const response = await fetch(`${this.graphqlUrl}/${path}`, {
56
+ method: 'POST',
57
+ headers: {
58
+ Authorization: `Bearer ${this.apiKey}`,
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ body: JSON.stringify(payload),
62
+ }).catch((cause) => {
63
+ return new FlyApiError({
64
+ method: 'POST',
65
+ path,
66
+ httpStatus: 0,
67
+ cause,
68
+ });
69
+ });
70
+ if (response instanceof Error) {
71
+ return response;
72
+ }
73
+ const responseText = await response.text().catch((cause) => {
74
+ return new FlyApiError({
75
+ method: 'POST',
76
+ path,
77
+ httpStatus: response.status,
78
+ cause,
79
+ });
80
+ });
81
+ if (responseText instanceof Error) {
82
+ return responseText;
83
+ }
84
+ if (!response.ok) {
85
+ const payloadOrError = parseJson({ text: responseText });
86
+ if (payloadOrError instanceof Error) {
87
+ return new FlyApiError({
88
+ method: 'POST',
89
+ path,
90
+ httpStatus: response.status,
91
+ cause: payloadOrError,
92
+ });
93
+ }
94
+ return createFlyHttpError({
95
+ method: 'POST',
96
+ path,
97
+ httpStatus: response.status,
98
+ payload: payloadOrError,
99
+ });
100
+ }
101
+ const payloadOrError = parseJson({ text: responseText });
102
+ if (payloadOrError instanceof Error) {
103
+ return new FlyApiError({
104
+ method: 'POST',
105
+ path,
106
+ httpStatus: response.status,
107
+ cause: payloadOrError,
108
+ });
109
+ }
110
+ const parsed = payloadOrError;
111
+ const { data, errors } = parsed;
112
+ if (errors) {
113
+ return createFlyGraphQLError({
114
+ path,
115
+ messages: errors.map((error) => {
116
+ return error.message;
117
+ }),
118
+ });
119
+ }
120
+ return data;
121
+ }
122
+ async gqlPostOrThrow(payload) {
123
+ return await this.gqlPost(payload);
124
+ }
125
+ async rest(path, method = 'GET', body, headers) {
126
+ const response = await fetch(`${this.apiUrl}/v1/${path}`, {
127
+ method,
128
+ headers: {
129
+ Authorization: `Bearer ${this.apiKey}`,
130
+ 'Content-Type': 'application/json',
131
+ ...headers,
132
+ },
133
+ body: body !== undefined ? JSON.stringify(body) : undefined,
134
+ }).catch((cause) => {
135
+ return new FlyApiError({
136
+ method,
137
+ path,
138
+ httpStatus: 0,
139
+ cause,
140
+ });
141
+ });
142
+ if (response instanceof Error) {
143
+ return response;
144
+ }
145
+ const responseText = await response.text().catch((cause) => {
146
+ return new FlyApiError({
147
+ method,
148
+ path,
149
+ httpStatus: response.status,
150
+ cause,
151
+ });
152
+ });
153
+ if (responseText instanceof Error) {
154
+ return responseText;
155
+ }
156
+ if (!response.ok) {
157
+ const payloadOrError = parseJson({ text: responseText });
158
+ if (payloadOrError instanceof Error) {
159
+ return new FlyApiError({
160
+ method,
161
+ path,
162
+ httpStatus: response.status,
163
+ cause: payloadOrError,
164
+ });
165
+ }
166
+ return createFlyHttpError({
167
+ method,
168
+ path,
169
+ httpStatus: response.status,
170
+ payload: payloadOrError,
171
+ });
172
+ }
173
+ if (!responseText) {
174
+ return undefined;
175
+ }
176
+ const payloadOrError = parseJson({ text: responseText });
177
+ if (payloadOrError instanceof Error) {
178
+ return new FlyApiError({
179
+ method,
180
+ path,
181
+ httpStatus: response.status,
182
+ cause: payloadOrError,
183
+ });
184
+ }
185
+ return payloadOrError;
186
+ }
187
+ async restOrThrow(path, method = 'GET', body, headers) {
188
+ return await this.rest(path, method, body, headers);
189
+ }
190
+ }
191
+ function parseJson({ text }) {
192
+ return errore.try({
193
+ try: () => {
194
+ return JSON.parse(text);
195
+ },
196
+ catch: (cause) => {
197
+ return new Error('Failed to parse JSON response', { cause });
198
+ },
199
+ });
200
+ }