Skip to content

Commit d05bcc3

Browse files
committed
feat!: sync types with the latest API contract
1 parent 4495a29 commit d05bcc3

17 files changed

Lines changed: 733 additions & 278 deletions

‎.changeset/sync-api-contract.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
"@squarecloud/api-types": major
3+
---
4+
5+
Sync with the Square Cloud API contract changes from the last 3 months.
6+
7+
**Breaking**
8+
9+
- `RESTPostAPIApplicationUploadResult`: `lang` replaced by `language: { name, version }`; added required `cpu` and optional `description`/`subdomain`.
10+
- `APINetworkAnalytics`: new required breakdowns `ips`, `status_codes`, `bots` and `content_types`, typed as whole-window `APINetworkAnalyticsTotalBucket` buckets.
11+
- `APINetworkDNS` is now an array of `APINetworkDNSRecord` (`{ type: "txt" | "cname", name, value, status }`); the previous `ownership`/`ssl` object shape no longer exists in the API.
12+
- `APIApplication` gained the required nullable `domain` and `custom` fields; `APIWebsiteApplication` now only narrows `domain` to `string`.
13+
- `APIListedFile.lastModified` is a Unix timestamp in milliseconds (`number`) instead of an ISO string.
14+
- `RESTGetAPIFilesListQuery.path` is optional (the API defaults it to `/`).
15+
16+
**Added**
17+
18+
- `GET /v2/apps/domains` types: `APIAppDomain`, `APIAppDomainType`, `APIAppDomainsPayload`.
19+
- `GET /v2/apps/load-balancers` types: `APILoadBalancers`, `APILoadBalancer`, `APILoadBalancerApp`, `APILoadBalancersPayload`.
20+
- `RESTGetAPINetworkAnalyticsQuery`: 11 optional drill-down filters (`country`, `ip`, `path`, `status`, `os`, `browser`, `protocol`, `referer`, `provider`, `content_type`, `bot`) applied to every breakdown at once.
21+
- `APIErrorCode`: constant and union of the standardized error codes (`INVALID_X` / `X_FAILED` / `X_NOT_FOUND` / `X_LIMIT_REACHED`), including `DAILY_SNAPSHOTS_LIMIT_REACHED`, `UPLOAD_ABORTED`, `LOAD_BALANCER_LIMIT_REACHED` and `UPGRADE_REQUIRED`. Pre-standardization names remain available as `@deprecated` aliases resolving to the canonical values, so existing comparisons keep working.
22+
- `APIApplicationStatus`/`APIDatabaseStatus`: optional `Raw` type parameter mirroring the `?rawData=true` response variant (raw numbers/arrays instead of formatted strings), plus `RESTGetAPIApplicationStatusQuery`.
23+
- `RESTPostAPIApplicationCommitQuery`: optional `path` destination directory for commits.
24+
- `ApplicationLanguage`: added `ruby`.
25+
26+
**Docs**
27+
28+
- JSDoc now documents current rate limits and behavior: logs, snapshots (per-plan daily quota and 30-minute listing cache), realtime SSE connection limits and TTL, custom-domain daily change limit, single-use workspace invite codes, `413 FILE_TOO_LARGE` on large file reads, and the expanded locale list (incl. `it-IT`).

‎common/v2.ts‎

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,208 @@ export interface APIHeaders {
1818

1919
export type APIVersion<TVersion extends number> = `v${TVersion}`;
2020

21+
/**
22+
* Machine-readable error codes returned in `APIPayload#code`.
23+
*
24+
* Canonical names follow the standardized convention
25+
* `INVALID_X` / `X_FAILED` / `X_NOT_FOUND` / `X_LIMIT_REACHED`. For a
26+
* transition period the API still returns the old names alongside the new
27+
* ones — the old keys below are kept as deprecated aliases that resolve to
28+
* the new canonical values.
29+
*/
30+
export const APIErrorCode = {
31+
// Auth / plan gates
32+
ACCESS_DENIED: "ACCESS_DENIED",
33+
PERMISSION_DENIED: "PERMISSION_DENIED",
34+
INVALID_ACCESS_TOKEN: "INVALID_ACCESS_TOKEN",
35+
UPGRADE_REQUIRED: "UPGRADE_REQUIRED",
36+
37+
// Rate limiting
38+
/** Short temporary 429 — retry after a few seconds. */
39+
KEEP_CALM: "KEEP_CALM",
40+
RATE_LIMIT: "RATE_LIMIT",
41+
RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED",
42+
/** Plan's daily snapshot quota exhausted (429) — distinct from KEEP_CALM. */
43+
DAILY_SNAPSHOTS_LIMIT_REACHED: "DAILY_SNAPSHOTS_LIMIT_REACHED",
44+
45+
// Generic validation / transport
46+
INVALID_ID: "INVALID_ID",
47+
INVALID_CODE: "INVALID_CODE",
48+
INVALID_NAME: "INVALID_NAME",
49+
INVALID_MEMORY: "INVALID_MEMORY",
50+
INVALID_JSON_BODY: "INVALID_JSON_BODY",
51+
INVALID_CONTENT_TYPE: "INVALID_CONTENT_TYPE",
52+
INVALID_TIME_RANGE: "INVALID_TIME_RANGE",
53+
INVALID_SCOPE: "INVALID_SCOPE",
54+
MISSING_PARAMETERS: "MISSING_PARAMETERS",
55+
MISSING_REQUIRED_FIELDS: "MISSING_REQUIRED_FIELDS",
56+
PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE",
57+
EMPTY_RESPONSE: "EMPTY_RESPONSE",
58+
ACTION_FAILED: "ACTION_FAILED",
59+
INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR",
60+
61+
// Applications
62+
APP_NOT_FOUND: "APP_NOT_FOUND",
63+
APPLICATIONS_LIMIT_REACHED: "APPLICATIONS_LIMIT_REACHED",
64+
INSUFFICIENT_MEMORY: "INSUFFICIENT_MEMORY",
65+
CLUSTER_SELECTION_FAILED: "CLUSTER_SELECTION_FAILED",
66+
CLUSTER_MAINTENANCE_TRY_LATER: "CLUSTER_MAINTENANCE_TRY_LATER",
67+
/** `GET /apps/{appId}/metrics` on an application without metrics support. */
68+
METRICS_NOT_SUPPORTED: "METRICS_NOT_SUPPORTED",
69+
70+
// Upload / commit
71+
UPLOAD_FAILED: "UPLOAD_FAILED",
72+
UPLOAD_ABORTED: "UPLOAD_ABORTED",
73+
STORAGE_UPLOAD_FAILED: "STORAGE_UPLOAD_FAILED",
74+
COMMIT_FAILED: "COMMIT_FAILED",
75+
INVALID_FILE: "INVALID_FILE",
76+
INVALID_DISPLAY_NAME: "INVALID_DISPLAY_NAME",
77+
INVALID_DESCRIPTION: "INVALID_DESCRIPTION",
78+
INVALID_SUBDOMAIN: "INVALID_SUBDOMAIN",
79+
FILE_TOO_LARGE: "FILE_TOO_LARGE",
80+
81+
// File manager
82+
READ_FAILED: "READ_FAILED",
83+
SAVE_FAILED: "SAVE_FAILED",
84+
RENAME_FAILED: "RENAME_FAILED",
85+
DELETE_FAILED: "DELETE_FAILED",
86+
FILE_NOT_FOUND: "FILE_NOT_FOUND",
87+
INVALID_PATH: "INVALID_PATH",
88+
INVALID_FILENAME: "INVALID_FILENAME",
89+
INVALID_CONTENT: "INVALID_CONTENT",
90+
BLOCKED_PATH: "BLOCKED_PATH",
91+
92+
// Environment variables
93+
INVALID_ENV_CONTENT: "INVALID_ENV_CONTENT",
94+
ENV_NAME_TOO_LONG: "ENV_NAME_TOO_LONG",
95+
ENV_CONTENT_TOO_LONG: "ENV_CONTENT_TOO_LONG",
96+
TOO_MANY_ENV_VARS: "TOO_MANY_ENV_VARS",
97+
STATIC_APP_ENV_NOT_SUPPORTED: "STATIC_APP_ENV_NOT_SUPPORTED",
98+
99+
// Deploys / git
100+
GIT_ALREADY_CONFIGURED: "GIT_ALREADY_CONFIGURED",
101+
GIT_NOT_CONFIGURED: "GIT_NOT_CONFIGURED",
102+
REPOSITORY_BRANCH_ALREADY_CONFIGURED: "REPOSITORY_BRANCH_ALREADY_CONFIGURED",
103+
INVALID_BRANCH_LENGTH: "INVALID_BRANCH_LENGTH",
104+
INVALID_AUTORESTART: "INVALID_AUTORESTART",
105+
106+
// Network / domains
107+
INVALID_DOMAIN: "INVALID_DOMAIN",
108+
CANNOT_SET_SUBDOMAIN: "CANNOT_SET_SUBDOMAIN",
109+
NO_CUSTOM_DOMAIN: "NO_CUSTOM_DOMAIN",
110+
DOMAIN_ALREADY_EXISTS: "DOMAIN_ALREADY_EXISTS",
111+
RESERVED_DOMAIN: "RESERVED_DOMAIN",
112+
LOAD_BALANCER_LIMIT_REACHED: "LOAD_BALANCER_LIMIT_REACHED",
113+
DNS_FAILED: "DNS_FAILED",
114+
UNABLE_TO_FETCH_ANALYTICS: "UNABLE_TO_FETCH_ANALYTICS",
115+
UNABLE_TO_FETCH_ERRORS: "UNABLE_TO_FETCH_ERRORS",
116+
UNABLE_TO_FETCH_PERFORMANCE: "UNABLE_TO_FETCH_PERFORMANCE",
117+
118+
// Realtime
119+
REALTIME_MAX_CONNECTIONS: "REALTIME_MAX_CONNECTIONS",
120+
121+
// Snapshots
122+
SNAPSHOT_FAILED: "SNAPSHOT_FAILED",
123+
SNAPSHOT_NOT_FOUND: "SNAPSHOT_NOT_FOUND",
124+
SNAPSHOT_PROCESSING: "SNAPSHOT_PROCESSING",
125+
SNAPSHOT_RESTORE_FAILED: "SNAPSHOT_RESTORE_FAILED",
126+
SNAPSHOT_DATABASE_MISMATCH: "SNAPSHOT_DATABASE_MISMATCH",
127+
RESTORE_IN_PROGRESS: "RESTORE_IN_PROGRESS",
128+
INVALID_SNAPSHOT_ID: "INVALID_SNAPSHOT_ID",
129+
INVALID_VERSION_ID: "INVALID_VERSION_ID",
130+
131+
// Databases
132+
DATABASE_NOT_FOUND: "DATABASE_NOT_FOUND",
133+
DATABASE_NOT_RUNNING: "DATABASE_NOT_RUNNING",
134+
DATABASE_CREATION_FAILED: "DATABASE_CREATION_FAILED",
135+
INVALID_DATABASE_TYPE: "INVALID_DATABASE_TYPE",
136+
INVALID_DATABASE_VERSION: "INVALID_DATABASE_VERSION",
137+
INVALID_RESET_TYPE: "INVALID_RESET_TYPE",
138+
RESET_FAILED: "RESET_FAILED",
139+
NO_UPDATE_DATA: "NO_UPDATE_DATA",
140+
141+
// Workspaces
142+
WORKSPACE_NOT_FOUND: "WORKSPACE_NOT_FOUND",
143+
WORKSPACE_CREATION_FAILED: "WORKSPACE_CREATION_FAILED",
144+
WORKSPACE_LIMIT_REACHED: "WORKSPACE_LIMIT_REACHED",
145+
MEMBER_NOT_FOUND: "MEMBER_NOT_FOUND",
146+
MEMBERS_LIMIT_REACHED: "MEMBERS_LIMIT_REACHED",
147+
MEMBER_ALREADY_ADDED: "MEMBER_ALREADY_ADDED",
148+
APP_ALREADY_IN_WORKSPACE: "APP_ALREADY_IN_WORKSPACE",
149+
CANNOT_EDIT_OWNER: "CANNOT_EDIT_OWNER",
150+
CANNOT_INVITE_OWNER: "CANNOT_INVITE_OWNER",
151+
CANNOT_LEAVE_OWNER: "CANNOT_LEAVE_OWNER",
152+
INVALID_GROUP: "INVALID_GROUP",
153+
VALIDATION_FAILED: "VALIDATION_FAILED",
154+
VALIDATION_TIMEOUT: "VALIDATION_TIMEOUT",
155+
156+
// ------------------------------------------------------------------
157+
// Deprecated aliases — pre-standardization names. They resolve to the new
158+
// canonical values so comparisons keep working against new responses.
159+
// ------------------------------------------------------------------
160+
/** @deprecated Use {@link APIErrorCode.INVALID_ID}. */
161+
ID_INVALID: "INVALID_ID",
162+
/** @deprecated Use {@link APIErrorCode.INVALID_CODE}. */
163+
CODE_INVALID: "INVALID_CODE",
164+
/** @deprecated Use {@link APIErrorCode.INVALID_NAME}. */
165+
NAME_INVALID: "INVALID_NAME",
166+
/** @deprecated Use {@link APIErrorCode.INVALID_MEMORY}. */
167+
MEMORY_INVALID: "INVALID_MEMORY",
168+
/** @deprecated Use {@link APIErrorCode.INVALID_DATABASE_TYPE}. */
169+
DATABASE_TYPE_INVALID: "INVALID_DATABASE_TYPE",
170+
/** @deprecated Use {@link APIErrorCode.INVALID_DATABASE_VERSION}. */
171+
DATABASE_VERSION_INVALID: "INVALID_DATABASE_VERSION",
172+
/** @deprecated Use {@link APIErrorCode.WORKSPACE_NOT_FOUND}. */
173+
UNKNOWN_WORKSPACE: "WORKSPACE_NOT_FOUND",
174+
/** @deprecated Use {@link APIErrorCode.MEMBER_NOT_FOUND}. */
175+
UNKNOWN_MEMBER: "MEMBER_NOT_FOUND",
176+
/** @deprecated Use {@link APIErrorCode.APPLICATIONS_LIMIT_REACHED}. */
177+
MAX_APPLICATIONS_REACHED: "APPLICATIONS_LIMIT_REACHED",
178+
/** @deprecated Use {@link APIErrorCode.MEMBERS_LIMIT_REACHED}. */
179+
MAX_MEMBERS_REACHED: "MEMBERS_LIMIT_REACHED",
180+
/** @deprecated Use {@link APIErrorCode.WORKSPACE_CREATION_FAILED}. */
181+
FAILED_WORKSPACE_CREATION: "WORKSPACE_CREATION_FAILED",
182+
/** @deprecated Use {@link APIErrorCode.DATABASE_CREATION_FAILED}. */
183+
FAILED_DATABASE_CREATION: "DATABASE_CREATION_FAILED",
184+
/** @deprecated Use {@link APIErrorCode.CLUSTER_SELECTION_FAILED}. */
185+
FAILED_CLUSTER_SELECTION: "CLUSTER_SELECTION_FAILED",
186+
/** @deprecated Use {@link APIErrorCode.INSUFFICIENT_MEMORY}. */
187+
FEW_MEMORY: "INSUFFICIENT_MEMORY",
188+
/** @deprecated Use {@link APIErrorCode.READ_FAILED}. */
189+
FAILED_READ: "READ_FAILED",
190+
/** @deprecated Use {@link APIErrorCode.DELETE_FAILED}. */
191+
FAILED_DELETE: "DELETE_FAILED",
192+
/** @deprecated Use {@link APIErrorCode.DELETE_FAILED}. */
193+
DELETE_ERROR: "DELETE_FAILED",
194+
/** @deprecated Use {@link APIErrorCode.RENAME_FAILED}. */
195+
FAILED_RENAME: "RENAME_FAILED",
196+
/** @deprecated Use {@link APIErrorCode.SAVE_FAILED}. */
197+
FAILED_TO_SAVE: "SAVE_FAILED",
198+
/** @deprecated Use {@link APIErrorCode.RESET_FAILED}. */
199+
FAILED_RESET: "RESET_FAILED",
200+
/** @deprecated Use {@link APIErrorCode.UPLOAD_FAILED}. */
201+
FAILED_UPLOAD: "UPLOAD_FAILED",
202+
/** @deprecated Use {@link APIErrorCode.STORAGE_UPLOAD_FAILED}. */
203+
FAILED_UPLOAD_DATA: "STORAGE_UPLOAD_FAILED",
204+
/** @deprecated Use {@link APIErrorCode.COMMIT_FAILED}. */
205+
COMMIT_ERROR: "COMMIT_FAILED",
206+
/** @deprecated Use {@link APIErrorCode.INTERNAL_SERVER_ERROR}. */
207+
INTERNAL_ERROR: "INTERNAL_SERVER_ERROR",
208+
/** @deprecated Use {@link APIErrorCode.INVALID_DOMAIN}. */
209+
REGEX_VALIDATION: "INVALID_DOMAIN",
210+
/** @deprecated Use {@link APIErrorCode.CANNOT_SET_SUBDOMAIN}. */
211+
CAN_NOT_SET_SUBDOMAIN: "CANNOT_SET_SUBDOMAIN",
212+
/** @deprecated Use {@link APIErrorCode.METRICS_NOT_SUPPORTED}. */
213+
INVALID_APP: "METRICS_NOT_SUPPORTED",
214+
/** @deprecated Use {@link APIErrorCode.UPGRADE_REQUIRED}. */
215+
SUBSCRIPTION_REQUIRED: "UPGRADE_REQUIRED",
216+
} as const;
217+
218+
/**
219+
* Union of the canonical error code values.
220+
*/
221+
export type APIErrorCode = (typeof APIErrorCode)[keyof typeof APIErrorCode];
222+
21223
export type ISODateString = string;
22224

23225
export type UserId = string & Brand<"UserId">;

‎package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
"{utils,v*}.{js,js.map,d.ts,d.ts.map,mjs}"
7272
],
7373
"devDependencies": {
74-
"@biomejs/biome": "^2.4.16",
74+
"@biomejs/biome": "^2.5.3",
7575
"@changesets/cli": "^2.31.0",
76-
"@types/node": "^25.9.1",
77-
"npm-run-all2": "^9.0.1",
76+
"@types/node": "^26.1.1",
77+
"npm-run-all2": "^9.0.2",
7878
"rimraf": "^6.1.3",
7979
"tsup": "^8.5.1",
80-
"typescript": "^5.9.2"
80+
"typescript": "^5.9.3"
8181
}
8282
}

‎payloads/v2/application.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { APIPayload, ApplicationId, ISODateString } from "../../common/v2";
22

33
/**
4-
* APIApplication#language
4+
* APIApplication#language — canonical runtime slug returned by the API.
5+
* `static` covers HTML/CSS sites.
56
* @see https://docs.squarecloud.app/en/api-reference/endpoint/apps/info
7+
* @see https://docs.squarecloud.app/en/getting-started/config-file
68
*/
79
export type ApplicationLanguage =
810
| "javascript"
@@ -12,6 +14,7 @@ export type ApplicationLanguage =
1214
| "elixir"
1315
| "go"
1416
| "rust"
17+
| "ruby"
1518
| "php"
1619
| "dotnet"
1720
| "static";
@@ -23,6 +26,7 @@ export const ApplicationLanguage = {
2326
Elixir: "elixir",
2427
Go: "go",
2528
Rust: "rust",
29+
Ruby: "ruby",
2630
PHP: "php",
2731
Dotnet: "dotnet",
2832
Static: "static",
@@ -39,17 +43,22 @@ export interface APIApplication {
3943
cluster: string;
4044
ram: number;
4145
language: ApplicationLanguage;
46+
/** Default `<subdomain>.squareweb.app` hostname. `null` for non-web apps. */
47+
domain: string | null;
48+
/** Custom domain bound to the app, when configured. */
49+
custom: string | null;
4250
created_at: ISODateString;
4351
}
4452

4553
export type APIApplicationPayload = APIPayload<APIApplication>;
4654

4755
/**
56+
* Narrowing of {@link APIApplication} for web applications — `domain` is
57+
* always present.
4858
* @see https://docs.squarecloud.app/en/api-reference/endpoint/apps/info
4959
*/
5060
export interface APIWebsiteApplication extends APIApplication {
5161
domain: string;
52-
custom: string | null;
5362
}
5463

5564
export type APIWebsiteApplicationPayload = APIPayload<APIWebsiteApplication>;

‎payloads/v2/database.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ export type APIDatabaseCreatedPayload = APIPayload<APIDatabaseCreated>;
7878
* Shares the `RuntimeStats` shape with `APIApplicationStatus`.
7979
* @see https://docs.squarecloud.app/en/api-reference/endpoint/databases/status
8080
*/
81-
export type APIDatabaseStatus = APIApplicationStatus;
81+
export type APIDatabaseStatus<Raw extends boolean = false> =
82+
APIApplicationStatus<Raw>;
8283

83-
export type APIDatabaseStatusPayload = APIPayload<APIDatabaseStatus>;
84+
export type APIDatabaseStatusPayload<Raw extends boolean = false> = APIPayload<
85+
APIDatabaseStatus<Raw>
86+
>;
8487

8588
/**
8689
* Compact runtime stats entry for `/v2/databases/status`. Same shape as the

‎payloads/v2/files.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { APIPayload, ISODateString } from "../../common/v2";
1+
import type { APIPayload } from "../../common/v2";
22

33
/**
44
* APIListedFile#type
@@ -16,15 +16,18 @@ export const FileType = {
1616
export interface APIListedFile {
1717
type: FileType;
1818
name: string;
19+
/** Size in bytes. `0` for directories. */
1920
size: number;
20-
lastModified: ISODateString;
21+
/** Last-modified time as a Unix timestamp in milliseconds. */
22+
lastModified: number;
2123
}
2224

2325
export type APIFileListPayload = APIPayload<APIListedFile[]>;
2426

2527
/**
2628
* File content returned by `GET /v2/apps/{appId}/files/content` as a Node-style
27-
* Buffer object — `data` is the raw byte array.
29+
* Buffer object — `data` is the raw byte array. Files too large for the file
30+
* manager are rejected with `413 FILE_TOO_LARGE`.
2831
* @see https://docs.squarecloud.app/en/api-reference/endpoint/apps/filemanager/read
2932
*/
3033
export interface APIReadFile {

‎payloads/v2/logs.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { APIPayload } from "../../common/v2";
22

33
/**
4+
* Rate limits: one request per application every 5s, plus a per-user burst
5+
* allowance of 20 requests per 10s.
46
* @see https://docs.squarecloud.app/en/api-reference/endpoint/apps/logs
57
*/
68
export interface APIApplicationLogs {

0 commit comments

Comments
 (0)