@antelopejs/cloud-sdk 0.1.2 → 0.1.3
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 +17 -1
- package/dist/api.js +13 -2
- package/dist/generated/cloud-api.d.ts +51 -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 +1 -24
- package/openapi/projects.yaml +65 -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,14 @@ 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
|
+
}
|
|
34
42
|
/** How a log read is shaped: one bounded page, or a tail from a cursor. */
|
|
35
43
|
export interface LogRequest {
|
|
36
44
|
follow: boolean;
|
|
@@ -87,7 +95,15 @@ export declare class CloudApi {
|
|
|
87
95
|
regions: string[];
|
|
88
96
|
defaultRegion: string;
|
|
89
97
|
}>;
|
|
90
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Creates a project. A retry by the same member with the same
|
|
100
|
+
* `idempotencyKey` and the same body answers the project that key created
|
|
101
|
+
* instead of a second one; the same key with another body is refused with
|
|
102
|
+
* `cloud.errors.projects.idempotency_key_reused`, and
|
|
103
|
+
* `cloud.errors.projects.creation_in_progress` asks for a retry with the
|
|
104
|
+
* same key.
|
|
105
|
+
*/
|
|
106
|
+
createProject(body: NewProject, options?: CreateProjectOptions): Promise<{
|
|
91
107
|
projectId: string;
|
|
92
108
|
slug: string;
|
|
93
109
|
region: string;
|
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) {
|
|
@@ -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;
|
|
@@ -1102,7 +1121,10 @@ export interface operations {
|
|
|
1102
1121
|
createProject: {
|
|
1103
1122
|
parameters: {
|
|
1104
1123
|
query?: never;
|
|
1105
|
-
header?:
|
|
1124
|
+
header?: {
|
|
1125
|
+
/** @description Identifies one create across retries. 1 to 255 visible ASCII characters. */
|
|
1126
|
+
"Idempotency-Key"?: string;
|
|
1127
|
+
};
|
|
1106
1128
|
path?: never;
|
|
1107
1129
|
cookie?: never;
|
|
1108
1130
|
};
|
|
@@ -1112,6 +1134,7 @@ export interface operations {
|
|
|
1112
1134
|
};
|
|
1113
1135
|
};
|
|
1114
1136
|
responses: {
|
|
1137
|
+
/** @description The project created, or the one this `Idempotency-Key` already created. */
|
|
1115
1138
|
200: {
|
|
1116
1139
|
headers: {
|
|
1117
1140
|
[name: string]: unknown;
|
|
@@ -1120,6 +1143,33 @@ export interface operations {
|
|
|
1120
1143
|
"application/json": components["schemas"]["CreatedProject"];
|
|
1121
1144
|
};
|
|
1122
1145
|
};
|
|
1146
|
+
/** @description `cloud.errors.projects.invalid_idempotency_key`: the `Idempotency-Key` is empty, longer than 255 characters, or holds a character outside 0x21-0x7E. */
|
|
1147
|
+
400: {
|
|
1148
|
+
headers: {
|
|
1149
|
+
[name: string]: unknown;
|
|
1150
|
+
};
|
|
1151
|
+
content: {
|
|
1152
|
+
"application/json": components["schemas"]["Error"];
|
|
1153
|
+
};
|
|
1154
|
+
};
|
|
1155
|
+
/** @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. */
|
|
1156
|
+
409: {
|
|
1157
|
+
headers: {
|
|
1158
|
+
[name: string]: unknown;
|
|
1159
|
+
};
|
|
1160
|
+
content: {
|
|
1161
|
+
"application/json": components["schemas"]["Error"];
|
|
1162
|
+
};
|
|
1163
|
+
};
|
|
1164
|
+
/** @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`. */
|
|
1165
|
+
422: {
|
|
1166
|
+
headers: {
|
|
1167
|
+
[name: string]: unknown;
|
|
1168
|
+
};
|
|
1169
|
+
content: {
|
|
1170
|
+
"application/json": components["schemas"]["Error"];
|
|
1171
|
+
};
|
|
1172
|
+
};
|
|
1123
1173
|
default: components["responses"]["Error"];
|
|
1124
1174
|
};
|
|
1125
1175
|
};
|
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
|
|
@@ -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' }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/cloud-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|