@antelopejs/cloud-sdk 0.1.2 → 0.1.4
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/README.md +2 -2
- package/dist/api.d.ts +48 -1
- package/dist/api.js +50 -2
- package/dist/generated/cloud-api.d.ts +259 -1
- package/dist/result.d.ts +1 -4
- package/dist/result.js +2 -2
- package/dist/sse.d.ts +5 -0
- package/dist/sse.js +15 -0
- package/openapi/cloud.openapi.yaml +4 -24
- package/openapi/projects.yaml +65 -0
- package/openapi/services.yaml +126 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@antelopejs/cloud-sdk`
|
|
2
2
|
|
|
3
|
-
A typed client for the AntelopeJS Cloud API: the client the `ajs
|
|
3
|
+
A typed client for the AntelopeJS Cloud API: the client the `ajs cloud` CLI
|
|
4
4
|
uses, without the CLI. Its only runtime dependency is `openapi-fetch`.
|
|
5
5
|
|
|
6
6
|
## Install
|
|
@@ -20,7 +20,7 @@ import { CloudApi, CloudApiError } from "@antelopejs/cloud-sdk";
|
|
|
20
20
|
|
|
21
21
|
const api = new CloudApi({ token: process.env.ANTELOPE_CLOUD_TOKEN! });
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
console.log(await api.listProjects());
|
|
24
24
|
} catch (error) {
|
|
25
25
|
if (error instanceof CloudApiError) console.error(error.status, error.code);
|
|
26
26
|
}
|
package/dist/api.d.ts
CHANGED
|
@@ -31,6 +31,21 @@ export interface CloudApiOptions extends EndpointOptions {
|
|
|
31
31
|
/** The bearer token a device login or the console issued. */
|
|
32
32
|
token: string;
|
|
33
33
|
}
|
|
34
|
+
/** How a project create is sent. */
|
|
35
|
+
export interface CreateProjectOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Identifies this create across retries, 1 to 255 visible ASCII characters.
|
|
38
|
+
* Scoped to the workspace and to the member who sends it.
|
|
39
|
+
*/
|
|
40
|
+
idempotencyKey?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A value a service publishes to the other services of its environment. */
|
|
43
|
+
export interface PublishedValue {
|
|
44
|
+
/** The service that publishes the value. */
|
|
45
|
+
serviceId: string;
|
|
46
|
+
/** The key it publishes the value under. */
|
|
47
|
+
publishedKey: string;
|
|
48
|
+
}
|
|
34
49
|
/** How a log read is shaped: one bounded page, or a tail from a cursor. */
|
|
35
50
|
export interface LogRequest {
|
|
36
51
|
follow: boolean;
|
|
@@ -87,7 +102,15 @@ export declare class CloudApi {
|
|
|
87
102
|
regions: string[];
|
|
88
103
|
defaultRegion: string;
|
|
89
104
|
}>;
|
|
90
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Creates a project. A retry by the same member with the same
|
|
107
|
+
* `idempotencyKey` and the same body answers the project that key created
|
|
108
|
+
* instead of a second one; the same key with another body is refused with
|
|
109
|
+
* `cloud.errors.projects.idempotency_key_reused`, and
|
|
110
|
+
* `cloud.errors.projects.creation_in_progress` asks for a retry with the
|
|
111
|
+
* same key.
|
|
112
|
+
*/
|
|
113
|
+
createProject(body: NewProject, options?: CreateProjectOptions): Promise<{
|
|
91
114
|
projectId: string;
|
|
92
115
|
slug: string;
|
|
93
116
|
region: string;
|
|
@@ -156,6 +179,30 @@ export declare class CloudApi {
|
|
|
156
179
|
removedRetentionDays: number;
|
|
157
180
|
};
|
|
158
181
|
}>;
|
|
182
|
+
/**
|
|
183
|
+
* Sets the port the service's container listens on, from 1024 to 65535, or
|
|
184
|
+
* clears it with null. A service created from a repository has none, and is
|
|
185
|
+
* refused its deployments until it has one. The running revision keeps its
|
|
186
|
+
* port; the next deployment takes the new one.
|
|
187
|
+
*/
|
|
188
|
+
setServicePort(serviceId: string, port: number | null): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Opens the service to the internet on its own address, or closes it. A
|
|
191
|
+
* service without a port is refused with
|
|
192
|
+
* `cloud.errors.settings.public_needs_port`.
|
|
193
|
+
*/
|
|
194
|
+
setServiceExposure(serviceId: string, isPublic: boolean): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Adds a variable to the service that follows a value another service of
|
|
197
|
+
* its environment publishes, such as the `MONGO_URL` of a MongoDB resource.
|
|
198
|
+
* The value never reaches the client; the variable is then listed with a
|
|
199
|
+
* `resource` origin.
|
|
200
|
+
*
|
|
201
|
+
* @param serviceId The service that gets the variable
|
|
202
|
+
* @param key The variable's name on that service
|
|
203
|
+
* @param published The publishing service and the key it publishes
|
|
204
|
+
*/
|
|
205
|
+
followPublishedValue(serviceId: string, key: string, published: PublishedValue): Promise<void>;
|
|
159
206
|
deploymentHistory(serviceId: string): Promise<{
|
|
160
207
|
activeBuilds?: components["schemas"]["ActiveBuild"][];
|
|
161
208
|
desiredRevisionId: string | null;
|
package/dist/api.js
CHANGED
|
@@ -68,8 +68,19 @@ export class CloudApi {
|
|
|
68
68
|
const result = await this.client.GET("/api/cloud/onboarding/");
|
|
69
69
|
return dataOf(result);
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Creates a project. A retry by the same member with the same
|
|
73
|
+
* `idempotencyKey` and the same body answers the project that key created
|
|
74
|
+
* instead of a second one; the same key with another body is refused with
|
|
75
|
+
* `cloud.errors.projects.idempotency_key_reused`, and
|
|
76
|
+
* `cloud.errors.projects.creation_in_progress` asks for a retry with the
|
|
77
|
+
* same key.
|
|
78
|
+
*/
|
|
79
|
+
async createProject(body, options = {}) {
|
|
80
|
+
const result = await this.client.POST("/api/cloud/projects/", {
|
|
81
|
+
body,
|
|
82
|
+
params: { header: { "Idempotency-Key": options.idempotencyKey } },
|
|
83
|
+
});
|
|
73
84
|
return dataOf(result);
|
|
74
85
|
}
|
|
75
86
|
async createService(projectId, environmentId, body) {
|
|
@@ -132,6 +143,43 @@ export class CloudApi {
|
|
|
132
143
|
const result = await this.client.GET("/api/cloud/services/{serviceId}/settings", { params: { path: { serviceId } } });
|
|
133
144
|
return dataOf(result);
|
|
134
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Sets the port the service's container listens on, from 1024 to 65535, or
|
|
148
|
+
* clears it with null. A service created from a repository has none, and is
|
|
149
|
+
* refused its deployments until it has one. The running revision keeps its
|
|
150
|
+
* port; the next deployment takes the new one.
|
|
151
|
+
*/
|
|
152
|
+
async setServicePort(serviceId, port) {
|
|
153
|
+
const result = await this.client.PUT("/api/cloud/services/{serviceId}/port", { params: { path: { serviceId } }, body: { port }, parseAs: "text" });
|
|
154
|
+
acceptedOf(result);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Opens the service to the internet on its own address, or closes it. A
|
|
158
|
+
* service without a port is refused with
|
|
159
|
+
* `cloud.errors.settings.public_needs_port`.
|
|
160
|
+
*/
|
|
161
|
+
async setServiceExposure(serviceId, isPublic) {
|
|
162
|
+
const result = await this.client.PUT("/api/cloud/services/{serviceId}/network", { params: { path: { serviceId } }, body: { isPublic }, parseAs: "text" });
|
|
163
|
+
acceptedOf(result);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Adds a variable to the service that follows a value another service of
|
|
167
|
+
* its environment publishes, such as the `MONGO_URL` of a MongoDB resource.
|
|
168
|
+
* The value never reaches the client; the variable is then listed with a
|
|
169
|
+
* `resource` origin.
|
|
170
|
+
*
|
|
171
|
+
* @param serviceId The service that gets the variable
|
|
172
|
+
* @param key The variable's name on that service
|
|
173
|
+
* @param published The publishing service and the key it publishes
|
|
174
|
+
*/
|
|
175
|
+
async followPublishedValue(serviceId, key, published) {
|
|
176
|
+
const result = await this.client.POST("/api/cloud/services/{serviceId}/variables/references", {
|
|
177
|
+
params: { path: { serviceId } },
|
|
178
|
+
body: { key, ...published },
|
|
179
|
+
parseAs: "text",
|
|
180
|
+
});
|
|
181
|
+
acceptedOf(result);
|
|
182
|
+
}
|
|
135
183
|
async deploymentHistory(serviceId) {
|
|
136
184
|
const result = await this.client.GET("/api/cloud/services/{serviceId}/deployments", {
|
|
137
185
|
params: { path: { serviceId } },
|
|
@@ -76,6 +76,25 @@ export interface paths {
|
|
|
76
76
|
};
|
|
77
77
|
get: operations["listProjects"];
|
|
78
78
|
put?: never;
|
|
79
|
+
/**
|
|
80
|
+
* @description Creates a project with its production environment and, from a repository, its first service.
|
|
81
|
+
*
|
|
82
|
+
* A client that may lose the answer sends an `Idempotency-Key` and retries with the same key and
|
|
83
|
+
* the same request: the same `slug`, `region`, `repository` and `branch`. Once the first create
|
|
84
|
+
* finished, the retry answers 200 with the project that key created, as a fresh create would:
|
|
85
|
+
* its `projectId`, current `slug` and `region`, and the original `environmentId` and
|
|
86
|
+
* `serviceId`. No second project is created, and the replay needs no GitHub call and no room
|
|
87
|
+
* under the plan's project ceiling.
|
|
88
|
+
*
|
|
89
|
+
* A key belongs to its workspace and to the member who sent it. Another member sending the
|
|
90
|
+
* same key and body is not given the project; on its taken slug they get 409
|
|
91
|
+
* `cloud.errors.projects.slug_taken`, as does a create with another key, or none.
|
|
92
|
+
*
|
|
93
|
+
* While another create holds the slug, a keyed request answers 409
|
|
94
|
+
* `cloud.errors.projects.creation_in_progress`: it may be its own first attempt still running,
|
|
95
|
+
* so the client retries with the same key. The same key from the same member with a different
|
|
96
|
+
* request answers 422 `cloud.errors.projects.idempotency_key_reused`.
|
|
97
|
+
*/
|
|
79
98
|
post: operations["createProject"];
|
|
80
99
|
delete?: never;
|
|
81
100
|
options?: never;
|
|
@@ -336,6 +355,72 @@ export interface paths {
|
|
|
336
355
|
patch?: never;
|
|
337
356
|
trace?: never;
|
|
338
357
|
};
|
|
358
|
+
"/api/cloud/services/{serviceId}/port": {
|
|
359
|
+
parameters: {
|
|
360
|
+
query?: never;
|
|
361
|
+
header?: never;
|
|
362
|
+
path?: never;
|
|
363
|
+
cookie?: never;
|
|
364
|
+
};
|
|
365
|
+
get?: never;
|
|
366
|
+
/**
|
|
367
|
+
* @description Sets the port the service's container listens on, or clears it with null. A service a
|
|
368
|
+
* project creation builds from a repository starts without one, and cannot be deployed
|
|
369
|
+
* until it has one: a deployment asked before fails with `cloud.errors.builds.missing_port`.
|
|
370
|
+
*
|
|
371
|
+
* The running revision keeps the port it was deployed with; the next deployment takes the
|
|
372
|
+
* new one.
|
|
373
|
+
*/
|
|
374
|
+
put: operations["setServicePort"];
|
|
375
|
+
post?: never;
|
|
376
|
+
delete?: never;
|
|
377
|
+
options?: never;
|
|
378
|
+
head?: never;
|
|
379
|
+
patch?: never;
|
|
380
|
+
trace?: never;
|
|
381
|
+
};
|
|
382
|
+
"/api/cloud/services/{serviceId}/network": {
|
|
383
|
+
parameters: {
|
|
384
|
+
query?: never;
|
|
385
|
+
header?: never;
|
|
386
|
+
path?: never;
|
|
387
|
+
cookie?: never;
|
|
388
|
+
};
|
|
389
|
+
get?: never;
|
|
390
|
+
/**
|
|
391
|
+
* @description Opens the service to the internet on its own address, or closes it. A service is created
|
|
392
|
+
* closed. Sending the exposure it already has changes nothing.
|
|
393
|
+
*/
|
|
394
|
+
put: operations["setServiceExposure"];
|
|
395
|
+
post?: never;
|
|
396
|
+
delete?: never;
|
|
397
|
+
options?: never;
|
|
398
|
+
head?: never;
|
|
399
|
+
patch?: never;
|
|
400
|
+
trace?: never;
|
|
401
|
+
};
|
|
402
|
+
"/api/cloud/services/{serviceId}/variables/references": {
|
|
403
|
+
parameters: {
|
|
404
|
+
query?: never;
|
|
405
|
+
header?: never;
|
|
406
|
+
path?: never;
|
|
407
|
+
cookie?: never;
|
|
408
|
+
};
|
|
409
|
+
get?: never;
|
|
410
|
+
put?: never;
|
|
411
|
+
/**
|
|
412
|
+
* @description Adds a variable to the service that follows a value another service of the same
|
|
413
|
+
* environment publishes, such as the `MONGO_URL` of a MongoDB resource: the variable takes
|
|
414
|
+
* the published value, and takes the new one when it changes. Listed afterwards with a
|
|
415
|
+
* `resource` origin. The value itself is never sent to the client.
|
|
416
|
+
*/
|
|
417
|
+
post: operations["followPublishedValue"];
|
|
418
|
+
delete?: never;
|
|
419
|
+
options?: never;
|
|
420
|
+
head?: never;
|
|
421
|
+
patch?: never;
|
|
422
|
+
trace?: never;
|
|
423
|
+
};
|
|
339
424
|
"/api/cloud/services/{serviceId}/source-deployments": {
|
|
340
425
|
parameters: {
|
|
341
426
|
query?: never;
|
|
@@ -1102,7 +1187,10 @@ export interface operations {
|
|
|
1102
1187
|
createProject: {
|
|
1103
1188
|
parameters: {
|
|
1104
1189
|
query?: never;
|
|
1105
|
-
header?:
|
|
1190
|
+
header?: {
|
|
1191
|
+
/** @description Identifies one create across retries. 1 to 255 visible ASCII characters. */
|
|
1192
|
+
"Idempotency-Key"?: string;
|
|
1193
|
+
};
|
|
1106
1194
|
path?: never;
|
|
1107
1195
|
cookie?: never;
|
|
1108
1196
|
};
|
|
@@ -1112,6 +1200,7 @@ export interface operations {
|
|
|
1112
1200
|
};
|
|
1113
1201
|
};
|
|
1114
1202
|
responses: {
|
|
1203
|
+
/** @description The project created, or the one this `Idempotency-Key` already created. */
|
|
1115
1204
|
200: {
|
|
1116
1205
|
headers: {
|
|
1117
1206
|
[name: string]: unknown;
|
|
@@ -1120,6 +1209,33 @@ export interface operations {
|
|
|
1120
1209
|
"application/json": components["schemas"]["CreatedProject"];
|
|
1121
1210
|
};
|
|
1122
1211
|
};
|
|
1212
|
+
/** @description `cloud.errors.projects.invalid_idempotency_key`: the `Idempotency-Key` is empty, longer than 255 characters, or holds a character outside 0x21-0x7E. */
|
|
1213
|
+
400: {
|
|
1214
|
+
headers: {
|
|
1215
|
+
[name: string]: unknown;
|
|
1216
|
+
};
|
|
1217
|
+
content: {
|
|
1218
|
+
"application/json": components["schemas"]["Error"];
|
|
1219
|
+
};
|
|
1220
|
+
};
|
|
1221
|
+
/** @description `cloud.errors.projects.slug_taken`: another project holds the slug. `cloud.errors.projects.creation_in_progress`: a keyed request met another create holding the slug; retry with the same key. */
|
|
1222
|
+
409: {
|
|
1223
|
+
headers: {
|
|
1224
|
+
[name: string]: unknown;
|
|
1225
|
+
};
|
|
1226
|
+
content: {
|
|
1227
|
+
"application/json": components["schemas"]["Error"];
|
|
1228
|
+
};
|
|
1229
|
+
};
|
|
1230
|
+
/** @description `cloud.errors.projects.idempotency_key_reused`: the same member's `Idempotency-Key` already created a project from a request with a different `slug`, `region`, `repository` or `branch`. */
|
|
1231
|
+
422: {
|
|
1232
|
+
headers: {
|
|
1233
|
+
[name: string]: unknown;
|
|
1234
|
+
};
|
|
1235
|
+
content: {
|
|
1236
|
+
"application/json": components["schemas"]["Error"];
|
|
1237
|
+
};
|
|
1238
|
+
};
|
|
1123
1239
|
default: components["responses"]["Error"];
|
|
1124
1240
|
};
|
|
1125
1241
|
};
|
|
@@ -1569,6 +1685,148 @@ export interface operations {
|
|
|
1569
1685
|
default: components["responses"]["Error"];
|
|
1570
1686
|
};
|
|
1571
1687
|
};
|
|
1688
|
+
setServicePort: {
|
|
1689
|
+
parameters: {
|
|
1690
|
+
query?: never;
|
|
1691
|
+
header?: never;
|
|
1692
|
+
path: {
|
|
1693
|
+
serviceId: string;
|
|
1694
|
+
};
|
|
1695
|
+
cookie?: never;
|
|
1696
|
+
};
|
|
1697
|
+
requestBody: {
|
|
1698
|
+
content: {
|
|
1699
|
+
"application/json": {
|
|
1700
|
+
/** @description The port the container listens on; null for a service that listens on none. */
|
|
1701
|
+
port: number | null;
|
|
1702
|
+
};
|
|
1703
|
+
};
|
|
1704
|
+
};
|
|
1705
|
+
responses: {
|
|
1706
|
+
/** @description Done */
|
|
1707
|
+
200: {
|
|
1708
|
+
headers: {
|
|
1709
|
+
[name: string]: unknown;
|
|
1710
|
+
};
|
|
1711
|
+
content?: never;
|
|
1712
|
+
};
|
|
1713
|
+
/** @description `cloud.errors.settings.invalid_port`: the port is not an integer from 1024 to 65535. */
|
|
1714
|
+
400: {
|
|
1715
|
+
headers: {
|
|
1716
|
+
[name: string]: unknown;
|
|
1717
|
+
};
|
|
1718
|
+
content: {
|
|
1719
|
+
"application/json": components["schemas"]["Error"];
|
|
1720
|
+
};
|
|
1721
|
+
};
|
|
1722
|
+
/** @description `cloud.errors.settings.public_needs_port`: a public service cannot lose its port. `cloud.errors.settings.preview_read_only`: a preview mirrors its environment and is not edited. */
|
|
1723
|
+
409: {
|
|
1724
|
+
headers: {
|
|
1725
|
+
[name: string]: unknown;
|
|
1726
|
+
};
|
|
1727
|
+
content: {
|
|
1728
|
+
"application/json": components["schemas"]["Error"];
|
|
1729
|
+
};
|
|
1730
|
+
};
|
|
1731
|
+
default: components["responses"]["Error"];
|
|
1732
|
+
};
|
|
1733
|
+
};
|
|
1734
|
+
setServiceExposure: {
|
|
1735
|
+
parameters: {
|
|
1736
|
+
query?: never;
|
|
1737
|
+
header?: never;
|
|
1738
|
+
path: {
|
|
1739
|
+
serviceId: string;
|
|
1740
|
+
};
|
|
1741
|
+
cookie?: never;
|
|
1742
|
+
};
|
|
1743
|
+
requestBody: {
|
|
1744
|
+
content: {
|
|
1745
|
+
"application/json": {
|
|
1746
|
+
/** @description Whether the internet reaches the service on its own address. */
|
|
1747
|
+
isPublic: boolean;
|
|
1748
|
+
};
|
|
1749
|
+
};
|
|
1750
|
+
};
|
|
1751
|
+
responses: {
|
|
1752
|
+
/** @description Done */
|
|
1753
|
+
200: {
|
|
1754
|
+
headers: {
|
|
1755
|
+
[name: string]: unknown;
|
|
1756
|
+
};
|
|
1757
|
+
content?: never;
|
|
1758
|
+
};
|
|
1759
|
+
/** @description `cloud.errors.settings.public_needs_port`: a service without a port cannot be opened. `cloud.errors.settings.subdomain_taken`: another service holds its address. `cloud.errors.settings.preview_read_only`: a preview mirrors its environment and is not edited. */
|
|
1760
|
+
409: {
|
|
1761
|
+
headers: {
|
|
1762
|
+
[name: string]: unknown;
|
|
1763
|
+
};
|
|
1764
|
+
content: {
|
|
1765
|
+
"application/json": components["schemas"]["Error"];
|
|
1766
|
+
};
|
|
1767
|
+
};
|
|
1768
|
+
default: components["responses"]["Error"];
|
|
1769
|
+
};
|
|
1770
|
+
};
|
|
1771
|
+
followPublishedValue: {
|
|
1772
|
+
parameters: {
|
|
1773
|
+
query?: never;
|
|
1774
|
+
header?: never;
|
|
1775
|
+
path: {
|
|
1776
|
+
serviceId: string;
|
|
1777
|
+
};
|
|
1778
|
+
cookie?: never;
|
|
1779
|
+
};
|
|
1780
|
+
requestBody: {
|
|
1781
|
+
content: {
|
|
1782
|
+
"application/json": {
|
|
1783
|
+
/** @description The name of the variable on the service. */
|
|
1784
|
+
key: string;
|
|
1785
|
+
/** @description The service that publishes the value. */
|
|
1786
|
+
serviceId: string;
|
|
1787
|
+
/** @description The key the publisher publishes the value under. */
|
|
1788
|
+
publishedKey: string;
|
|
1789
|
+
};
|
|
1790
|
+
};
|
|
1791
|
+
};
|
|
1792
|
+
responses: {
|
|
1793
|
+
/** @description Done */
|
|
1794
|
+
200: {
|
|
1795
|
+
headers: {
|
|
1796
|
+
[name: string]: unknown;
|
|
1797
|
+
};
|
|
1798
|
+
content?: never;
|
|
1799
|
+
};
|
|
1800
|
+
/** @description `cloud.errors.settings.invalid_key`: the name is not a valid variable name. `cloud.errors.settings.self_reference`: a service cannot follow its own value. */
|
|
1801
|
+
400: {
|
|
1802
|
+
headers: {
|
|
1803
|
+
[name: string]: unknown;
|
|
1804
|
+
};
|
|
1805
|
+
content: {
|
|
1806
|
+
"application/json": components["schemas"]["Error"];
|
|
1807
|
+
};
|
|
1808
|
+
};
|
|
1809
|
+
/** @description `cloud.errors.settings.unknown_publisher`: the environment has no such service. `cloud.errors.settings.key_not_published`: the publisher publishes no such key. */
|
|
1810
|
+
404: {
|
|
1811
|
+
headers: {
|
|
1812
|
+
[name: string]: unknown;
|
|
1813
|
+
};
|
|
1814
|
+
content: {
|
|
1815
|
+
"application/json": components["schemas"]["Error"];
|
|
1816
|
+
};
|
|
1817
|
+
};
|
|
1818
|
+
/** @description `cloud.errors.settings.duplicate_key`: the service already holds a variable of that name. `cloud.errors.settings.preview_read_only`: a preview mirrors its environment and is not edited. */
|
|
1819
|
+
409: {
|
|
1820
|
+
headers: {
|
|
1821
|
+
[name: string]: unknown;
|
|
1822
|
+
};
|
|
1823
|
+
content: {
|
|
1824
|
+
"application/json": components["schemas"]["Error"];
|
|
1825
|
+
};
|
|
1826
|
+
};
|
|
1827
|
+
default: components["responses"]["Error"];
|
|
1828
|
+
};
|
|
1829
|
+
};
|
|
1572
1830
|
deploySource: {
|
|
1573
1831
|
parameters: {
|
|
1574
1832
|
query?: never;
|
package/dist/result.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CloudApiError } from "./api-error.js";
|
|
2
2
|
interface ApiErrorFields {
|
|
3
3
|
code?: unknown;
|
|
4
4
|
error?: unknown;
|
|
@@ -14,9 +14,6 @@ export interface ApiResult<T> {
|
|
|
14
14
|
response: Response;
|
|
15
15
|
}
|
|
16
16
|
export declare function isApiErrorBody(value: unknown): value is ApiErrorBody;
|
|
17
|
-
export declare function errorCode(body: ApiErrorBody | undefined): string;
|
|
18
|
-
/** The string values a `{ message, params }` refusal interpolates. */
|
|
19
|
-
export declare function errorParams(body: ApiErrorBody | undefined): ApiErrorParams;
|
|
20
17
|
/** The refusal a response carries, with the wait its `Retry-After` asks for. */
|
|
21
18
|
export declare function refusal(response: Response, body: ApiErrorBody | undefined, text?: string): CloudApiError;
|
|
22
19
|
/** The answer's body, or the refusal it carries. */
|
package/dist/result.js
CHANGED
|
@@ -3,13 +3,13 @@ import { isObject, isRecord, isString } from "./guards.js";
|
|
|
3
3
|
export function isApiErrorBody(value) {
|
|
4
4
|
return isString(value) || isRecord(value);
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
function errorCode(body) {
|
|
7
7
|
if (isString(body))
|
|
8
8
|
return body;
|
|
9
9
|
return [body?.code, body?.error, body?.message].find(isString) ?? "api_error";
|
|
10
10
|
}
|
|
11
11
|
/** The string values a `{ message, params }` refusal interpolates. */
|
|
12
|
-
|
|
12
|
+
function errorParams(body) {
|
|
13
13
|
const params = isString(body) ? undefined : body?.params;
|
|
14
14
|
if (!isObject(params))
|
|
15
15
|
return {};
|
package/dist/sse.d.ts
CHANGED
|
@@ -3,4 +3,9 @@ export interface SseEvent {
|
|
|
3
3
|
data: unknown;
|
|
4
4
|
id?: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Reads the events of a server-sent stream.
|
|
8
|
+
*
|
|
9
|
+
* @throws InvalidApiResponseError when one frame passes 1 MiB without ending.
|
|
10
|
+
*/
|
|
6
11
|
export declare function parseSse(response: Response): AsyncGenerator<SseEvent>;
|
package/dist/sse.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InvalidApiResponseError } from "./api-error.js";
|
|
1
2
|
function eventOf(lines) {
|
|
2
3
|
let event = "message";
|
|
3
4
|
let id;
|
|
@@ -23,6 +24,16 @@ function eventOf(lines) {
|
|
|
23
24
|
function fieldValue(value) {
|
|
24
25
|
return value.startsWith(" ") ? value.slice(1) : value;
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The most text one frame may hold before its end. A stream that never ends
|
|
29
|
+
* a frame would otherwise grow the buffer for as long as it is read.
|
|
30
|
+
*/
|
|
31
|
+
const MAX_FRAME_LENGTH = 1_048_576;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the events of a server-sent stream.
|
|
34
|
+
*
|
|
35
|
+
* @throws InvalidApiResponseError when one frame passes 1 MiB without ending.
|
|
36
|
+
*/
|
|
26
37
|
export async function* parseSse(response) {
|
|
27
38
|
if (!response.body)
|
|
28
39
|
return;
|
|
@@ -33,6 +44,10 @@ export async function* parseSse(response) {
|
|
|
33
44
|
buffer += value ?? "";
|
|
34
45
|
const frames = buffer.split(/\r?\n\r?\n/);
|
|
35
46
|
buffer = frames.pop() ?? "";
|
|
47
|
+
if (buffer.length > MAX_FRAME_LENGTH) {
|
|
48
|
+
await reader.cancel();
|
|
49
|
+
throw new InvalidApiResponseError();
|
|
50
|
+
}
|
|
36
51
|
for (const frame of frames) {
|
|
37
52
|
const event = eventOf(frame.split(/\r?\n/));
|
|
38
53
|
if (event)
|
|
@@ -313,30 +313,7 @@ paths:
|
|
|
313
313
|
application/json:
|
|
314
314
|
schema: { $ref: '#/components/schemas/DeviceToken' }
|
|
315
315
|
default: { $ref: '#/components/responses/Error' }
|
|
316
|
-
/api/cloud/projects/:
|
|
317
|
-
get:
|
|
318
|
-
operationId: listProjects
|
|
319
|
-
security: [{ bearerAuth: [] }]
|
|
320
|
-
responses:
|
|
321
|
-
'200':
|
|
322
|
-
content:
|
|
323
|
-
application/json:
|
|
324
|
-
schema: { $ref: '#/components/schemas/ProjectList' }
|
|
325
|
-
default: { $ref: '#/components/responses/Error' }
|
|
326
|
-
post:
|
|
327
|
-
operationId: createProject
|
|
328
|
-
security: [{ bearerAuth: [] }]
|
|
329
|
-
requestBody:
|
|
330
|
-
required: true
|
|
331
|
-
content:
|
|
332
|
-
application/json:
|
|
333
|
-
schema: { $ref: '#/components/schemas/NewProject' }
|
|
334
|
-
responses:
|
|
335
|
-
'200':
|
|
336
|
-
content:
|
|
337
|
-
application/json:
|
|
338
|
-
schema: { $ref: '#/components/schemas/CreatedProject' }
|
|
339
|
-
default: { $ref: '#/components/responses/Error' }
|
|
316
|
+
/api/cloud/projects/: { $ref: 'projects.yaml#/paths/projects' }
|
|
340
317
|
/api/cloud/projects/{projectId}:
|
|
341
318
|
get:
|
|
342
319
|
operationId: readProject
|
|
@@ -408,6 +385,9 @@ paths:
|
|
|
408
385
|
application/json:
|
|
409
386
|
schema: { $ref: '#/components/schemas/ServiceSettings' }
|
|
410
387
|
default: { $ref: '#/components/responses/Error' }
|
|
388
|
+
/api/cloud/services/{serviceId}/port: { $ref: 'services.yaml#/paths/port' }
|
|
389
|
+
/api/cloud/services/{serviceId}/network: { $ref: 'services.yaml#/paths/network' }
|
|
390
|
+
/api/cloud/services/{serviceId}/variables/references: { $ref: 'services.yaml#/paths/variableReferences' }
|
|
411
391
|
/api/cloud/services/{serviceId}/source-deployments:
|
|
412
392
|
post:
|
|
413
393
|
operationId: deploySource
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
paths:
|
|
2
|
+
projects:
|
|
3
|
+
get:
|
|
4
|
+
operationId: listProjects
|
|
5
|
+
security: [{ bearerAuth: [] }]
|
|
6
|
+
responses:
|
|
7
|
+
'200':
|
|
8
|
+
content:
|
|
9
|
+
application/json:
|
|
10
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/ProjectList' }
|
|
11
|
+
default: { $ref: './cloud.openapi.yaml#/components/responses/Error' }
|
|
12
|
+
post:
|
|
13
|
+
operationId: createProject
|
|
14
|
+
description: |
|
|
15
|
+
Creates a project with its production environment and, from a repository, its first service.
|
|
16
|
+
|
|
17
|
+
A client that may lose the answer sends an `Idempotency-Key` and retries with the same key and
|
|
18
|
+
the same request: the same `slug`, `region`, `repository` and `branch`. Once the first create
|
|
19
|
+
finished, the retry answers 200 with the project that key created, as a fresh create would:
|
|
20
|
+
its `projectId`, current `slug` and `region`, and the original `environmentId` and
|
|
21
|
+
`serviceId`. No second project is created, and the replay needs no GitHub call and no room
|
|
22
|
+
under the plan's project ceiling.
|
|
23
|
+
|
|
24
|
+
A key belongs to its workspace and to the member who sent it. Another member sending the
|
|
25
|
+
same key and body is not given the project; on its taken slug they get 409
|
|
26
|
+
`cloud.errors.projects.slug_taken`, as does a create with another key, or none.
|
|
27
|
+
|
|
28
|
+
While another create holds the slug, a keyed request answers 409
|
|
29
|
+
`cloud.errors.projects.creation_in_progress`: it may be its own first attempt still running,
|
|
30
|
+
so the client retries with the same key. The same key from the same member with a different
|
|
31
|
+
request answers 422 `cloud.errors.projects.idempotency_key_reused`.
|
|
32
|
+
security: [{ bearerAuth: [] }]
|
|
33
|
+
parameters:
|
|
34
|
+
- in: header
|
|
35
|
+
name: Idempotency-Key
|
|
36
|
+
required: false
|
|
37
|
+
description: Identifies one create across retries. 1 to 255 visible ASCII characters.
|
|
38
|
+
schema: { type: string, minLength: 1, maxLength: 255, pattern: '^[\x21-\x7E]+$' }
|
|
39
|
+
requestBody:
|
|
40
|
+
required: true
|
|
41
|
+
content:
|
|
42
|
+
application/json:
|
|
43
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/NewProject' }
|
|
44
|
+
responses:
|
|
45
|
+
'200':
|
|
46
|
+
description: The project created, or the one this `Idempotency-Key` already created.
|
|
47
|
+
content:
|
|
48
|
+
application/json:
|
|
49
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/CreatedProject' }
|
|
50
|
+
'400':
|
|
51
|
+
description: '`cloud.errors.projects.invalid_idempotency_key`: the `Idempotency-Key` is empty, longer than 255 characters, or holds a character outside 0x21-0x7E.'
|
|
52
|
+
content:
|
|
53
|
+
application/json:
|
|
54
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
55
|
+
'409':
|
|
56
|
+
description: '`cloud.errors.projects.slug_taken`: another project holds the slug. `cloud.errors.projects.creation_in_progress`: a keyed request met another create holding the slug; retry with the same key.'
|
|
57
|
+
content:
|
|
58
|
+
application/json:
|
|
59
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
60
|
+
'422':
|
|
61
|
+
description: '`cloud.errors.projects.idempotency_key_reused`: the same member''s `Idempotency-Key` already created a project from a request with a different `slug`, `region`, `repository` or `branch`.'
|
|
62
|
+
content:
|
|
63
|
+
application/json:
|
|
64
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
65
|
+
default: { $ref: './cloud.openapi.yaml#/components/responses/Error' }
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
paths:
|
|
2
|
+
port:
|
|
3
|
+
put:
|
|
4
|
+
operationId: setServicePort
|
|
5
|
+
description: |
|
|
6
|
+
Sets the port the service's container listens on, or clears it with null. A service a
|
|
7
|
+
project creation builds from a repository starts without one, and cannot be deployed
|
|
8
|
+
until it has one: a deployment asked before fails with `cloud.errors.builds.missing_port`.
|
|
9
|
+
|
|
10
|
+
The running revision keeps the port it was deployed with; the next deployment takes the
|
|
11
|
+
new one.
|
|
12
|
+
security: [{ bearerAuth: [] }]
|
|
13
|
+
parameters:
|
|
14
|
+
- in: path
|
|
15
|
+
name: serviceId
|
|
16
|
+
required: true
|
|
17
|
+
schema: { type: string }
|
|
18
|
+
requestBody:
|
|
19
|
+
required: true
|
|
20
|
+
content:
|
|
21
|
+
application/json:
|
|
22
|
+
schema:
|
|
23
|
+
type: object
|
|
24
|
+
required: [port]
|
|
25
|
+
properties:
|
|
26
|
+
port:
|
|
27
|
+
description: The port the container listens on; null for a service that listens on none.
|
|
28
|
+
type: [integer, "null"]
|
|
29
|
+
minimum: 1024
|
|
30
|
+
maximum: 65535
|
|
31
|
+
responses:
|
|
32
|
+
'200':
|
|
33
|
+
description: Done
|
|
34
|
+
'400':
|
|
35
|
+
description: '`cloud.errors.settings.invalid_port`: the port is not an integer from 1024 to 65535.'
|
|
36
|
+
content:
|
|
37
|
+
application/json:
|
|
38
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
39
|
+
'409':
|
|
40
|
+
description: '`cloud.errors.settings.public_needs_port`: a public service cannot lose its port. `cloud.errors.settings.preview_read_only`: a preview mirrors its environment and is not edited.'
|
|
41
|
+
content:
|
|
42
|
+
application/json:
|
|
43
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
44
|
+
default: { $ref: './cloud.openapi.yaml#/components/responses/Error' }
|
|
45
|
+
variableReferences:
|
|
46
|
+
post:
|
|
47
|
+
operationId: followPublishedValue
|
|
48
|
+
description: |
|
|
49
|
+
Adds a variable to the service that follows a value another service of the same
|
|
50
|
+
environment publishes, such as the `MONGO_URL` of a MongoDB resource: the variable takes
|
|
51
|
+
the published value, and takes the new one when it changes. Listed afterwards with a
|
|
52
|
+
`resource` origin. The value itself is never sent to the client.
|
|
53
|
+
security: [{ bearerAuth: [] }]
|
|
54
|
+
parameters:
|
|
55
|
+
- in: path
|
|
56
|
+
name: serviceId
|
|
57
|
+
required: true
|
|
58
|
+
schema: { type: string }
|
|
59
|
+
requestBody:
|
|
60
|
+
required: true
|
|
61
|
+
content:
|
|
62
|
+
application/json:
|
|
63
|
+
schema:
|
|
64
|
+
type: object
|
|
65
|
+
required: [key, serviceId, publishedKey]
|
|
66
|
+
properties:
|
|
67
|
+
key:
|
|
68
|
+
description: The name of the variable on the service.
|
|
69
|
+
type: string
|
|
70
|
+
serviceId:
|
|
71
|
+
description: The service that publishes the value.
|
|
72
|
+
type: string
|
|
73
|
+
publishedKey:
|
|
74
|
+
description: The key the publisher publishes the value under.
|
|
75
|
+
type: string
|
|
76
|
+
responses:
|
|
77
|
+
'200':
|
|
78
|
+
description: Done
|
|
79
|
+
'400':
|
|
80
|
+
description: '`cloud.errors.settings.invalid_key`: the name is not a valid variable name. `cloud.errors.settings.self_reference`: a service cannot follow its own value.'
|
|
81
|
+
content:
|
|
82
|
+
application/json:
|
|
83
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
84
|
+
'404':
|
|
85
|
+
description: '`cloud.errors.settings.unknown_publisher`: the environment has no such service. `cloud.errors.settings.key_not_published`: the publisher publishes no such key.'
|
|
86
|
+
content:
|
|
87
|
+
application/json:
|
|
88
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
89
|
+
'409':
|
|
90
|
+
description: '`cloud.errors.settings.duplicate_key`: the service already holds a variable of that name. `cloud.errors.settings.preview_read_only`: a preview mirrors its environment and is not edited.'
|
|
91
|
+
content:
|
|
92
|
+
application/json:
|
|
93
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
94
|
+
default: { $ref: './cloud.openapi.yaml#/components/responses/Error' }
|
|
95
|
+
network:
|
|
96
|
+
put:
|
|
97
|
+
operationId: setServiceExposure
|
|
98
|
+
description: |
|
|
99
|
+
Opens the service to the internet on its own address, or closes it. A service is created
|
|
100
|
+
closed. Sending the exposure it already has changes nothing.
|
|
101
|
+
security: [{ bearerAuth: [] }]
|
|
102
|
+
parameters:
|
|
103
|
+
- in: path
|
|
104
|
+
name: serviceId
|
|
105
|
+
required: true
|
|
106
|
+
schema: { type: string }
|
|
107
|
+
requestBody:
|
|
108
|
+
required: true
|
|
109
|
+
content:
|
|
110
|
+
application/json:
|
|
111
|
+
schema:
|
|
112
|
+
type: object
|
|
113
|
+
required: [isPublic]
|
|
114
|
+
properties:
|
|
115
|
+
isPublic:
|
|
116
|
+
description: Whether the internet reaches the service on its own address.
|
|
117
|
+
type: boolean
|
|
118
|
+
responses:
|
|
119
|
+
'200':
|
|
120
|
+
description: Done
|
|
121
|
+
'409':
|
|
122
|
+
description: '`cloud.errors.settings.public_needs_port`: a service without a port cannot be opened. `cloud.errors.settings.subdomain_taken`: another service holds its address. `cloud.errors.settings.preview_read_only`: a preview mirrors its environment and is not edited.'
|
|
123
|
+
content:
|
|
124
|
+
application/json:
|
|
125
|
+
schema: { $ref: './cloud.openapi.yaml#/components/schemas/Error' }
|
|
126
|
+
default: { $ref: './cloud.openapi.yaml#/components/responses/Error' }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/cloud-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Typed client for the AntelopeJS Cloud API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"generate": "openapi-typescript openapi/cloud.openapi.yaml -o src/generated/cloud-api.ts",
|
|
41
41
|
"build": "pnpm run generate && rimraf dist && tsc",
|
|
42
42
|
"check:generated": "pnpm run generate && git diff --exit-code -- src/generated/cloud-api.ts",
|
|
43
|
-
"lint": "oxlint",
|
|
43
|
+
"lint": "oxlint --type-aware --max-warnings=0",
|
|
44
44
|
"prepack": "pnpm run build",
|
|
45
45
|
"test": "pnpm run build && rimraf dist-test && tsc -p test && node --test 'dist-test/test/**/*.test.js'",
|
|
46
46
|
"typecheck": "tsc --noEmit",
|
|
47
47
|
"release": "pnpm run typecheck && pnpm run lint && pnpm run format:check && pnpm test && release-it",
|
|
48
|
-
"lint:fix": "oxlint --fix && oxfmt .",
|
|
48
|
+
"lint:fix": "oxlint --type-aware --fix && oxfmt .",
|
|
49
49
|
"format": "oxfmt .",
|
|
50
50
|
"format:check": "oxfmt --check ."
|
|
51
51
|
},
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"openapi-fetch": "^0.14.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@antelopejs/tooling-configs": "^0.
|
|
56
|
+
"@antelopejs/tooling-configs": "^0.5.2",
|
|
57
57
|
"@types/node": "^22.19.15",
|
|
58
58
|
"openapi-typescript": "^7.9.1",
|
|
59
|
-
"oxfmt": "^0.
|
|
59
|
+
"oxfmt": "^0.77.0",
|
|
60
60
|
"oxlint": "1.81.0",
|
|
61
61
|
"oxlint-tsgolint": "^7.0.2001",
|
|
62
62
|
"release-it": "^19.2.4",
|