@typeship-ax/cli 0.6.0 → 0.9.1

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 (121) hide show
  1. package/AGENTS.md +31 -0
  2. package/README.md +26 -9
  3. package/api.json +6861 -3083
  4. package/api.md +508 -277
  5. package/dist/api-identity.d.ts +40 -0
  6. package/dist/api-identity.d.ts.map +1 -0
  7. package/dist/api-identity.js +128 -0
  8. package/dist/auth-profiles.d.ts +30 -0
  9. package/dist/auth-profiles.d.ts.map +1 -0
  10. package/dist/auth-profiles.js +138 -0
  11. package/dist/cli-agent.d.ts +9 -1
  12. package/dist/cli-agent.d.ts.map +1 -1
  13. package/dist/cli-agent.js +26 -9
  14. package/dist/cli.js +600 -582
  15. package/dist/console-login-check.d.ts +21 -0
  16. package/dist/console-login-check.d.ts.map +1 -0
  17. package/dist/console-login-check.js +107 -0
  18. package/dist/console-login-contract.d.ts +45 -0
  19. package/dist/console-login-contract.d.ts.map +1 -0
  20. package/dist/console-login-contract.js +40 -0
  21. package/dist/core/http.d.ts +21 -92
  22. package/dist/core/http.d.ts.map +1 -1
  23. package/dist/core/http.js +143 -221
  24. package/dist/core/pagination.d.ts.map +1 -1
  25. package/dist/core/pagination.js +6 -34
  26. package/dist/credential-storage.d.ts +24 -0
  27. package/dist/credential-storage.d.ts.map +1 -0
  28. package/dist/credential-storage.js +207 -0
  29. package/dist/dates.d.ts +0 -2
  30. package/dist/dates.d.ts.map +1 -1
  31. package/dist/dates.js +0 -1
  32. package/dist/docs.d.ts +36 -0
  33. package/dist/docs.d.ts.map +1 -0
  34. package/dist/docs.js +258 -0
  35. package/dist/errors.d.ts +42 -34
  36. package/dist/errors.d.ts.map +1 -1
  37. package/dist/errors.js +30 -20
  38. package/dist/index.d.ts +27 -12
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +40 -14
  41. package/dist/named-credentials.d.ts +21 -0
  42. package/dist/named-credentials.d.ts.map +1 -0
  43. package/dist/named-credentials.js +86 -0
  44. package/dist/oauth-login.d.ts +39 -0
  45. package/dist/oauth-login.d.ts.map +1 -0
  46. package/dist/oauth-login.js +171 -0
  47. package/dist/oauth-request.d.ts +21 -0
  48. package/dist/oauth-request.d.ts.map +1 -0
  49. package/dist/oauth-request.js +119 -0
  50. package/dist/oauth-session.d.ts +106 -0
  51. package/dist/oauth-session.d.ts.map +1 -0
  52. package/dist/oauth-session.js +244 -0
  53. package/dist/ops.d.ts +18 -0
  54. package/dist/ops.d.ts.map +1 -1
  55. package/dist/ops.js +31 -17
  56. package/dist/polling-login.d.ts +57 -0
  57. package/dist/polling-login.d.ts.map +1 -0
  58. package/dist/polling-login.js +204 -0
  59. package/dist/resources/account.d.ts +4 -4
  60. package/dist/resources/account.d.ts.map +1 -1
  61. package/dist/resources/account.js +1 -0
  62. package/dist/resources/api-keys.d.ts +13 -8
  63. package/dist/resources/api-keys.d.ts.map +1 -1
  64. package/dist/resources/api-keys.js +5 -1
  65. package/dist/resources/definition-revisions.d.ts +58 -0
  66. package/dist/resources/definition-revisions.d.ts.map +1 -0
  67. package/dist/resources/definition-revisions.js +114 -0
  68. package/dist/resources/definitions.d.ts +35 -0
  69. package/dist/resources/definitions.d.ts.map +1 -0
  70. package/dist/resources/definitions.js +60 -0
  71. package/dist/resources/generate.d.ts +18 -7
  72. package/dist/resources/generate.d.ts.map +1 -1
  73. package/dist/resources/generate.js +13 -5
  74. package/dist/resources/generations.d.ts +6 -6
  75. package/dist/resources/generations.d.ts.map +1 -1
  76. package/dist/resources/generations.js +3 -1
  77. package/dist/resources/projects.d.ts +111 -35
  78. package/dist/resources/projects.d.ts.map +1 -1
  79. package/dist/resources/projects.js +125 -15
  80. package/dist/resources/targets.d.ts +97 -0
  81. package/dist/resources/targets.d.ts.map +1 -0
  82. package/dist/resources/targets.js +197 -0
  83. package/dist/schemas.d.ts.map +1 -1
  84. package/dist/schemas.js +135 -62
  85. package/dist/types.d.ts +2072 -267
  86. package/dist/types.d.ts.map +1 -1
  87. package/dist/types.js +20 -3
  88. package/package.json +2 -1
  89. package/src/api-identity.ts +98 -0
  90. package/src/auth-profiles.ts +114 -0
  91. package/src/cli-agent.ts +28 -11
  92. package/src/cli.ts +528 -560
  93. package/src/console-login-check.ts +88 -0
  94. package/src/console-login-contract.ts +65 -0
  95. package/src/core/http.ts +156 -305
  96. package/src/core/pagination.ts +6 -30
  97. package/src/credential-storage.ts +183 -0
  98. package/src/dates.ts +0 -1
  99. package/src/docs.ts +239 -0
  100. package/src/errors.ts +52 -41
  101. package/src/index.ts +49 -14
  102. package/src/named-credentials.ts +74 -0
  103. package/src/oauth-login.ts +184 -0
  104. package/src/oauth-request.ts +90 -0
  105. package/src/oauth-session.ts +258 -0
  106. package/src/ops.ts +56 -17
  107. package/src/polling-login.ts +165 -0
  108. package/src/resources/account.ts +6 -3
  109. package/src/resources/api-keys.ts +27 -7
  110. package/src/resources/definition-revisions.ts +207 -0
  111. package/src/resources/definitions.ts +122 -0
  112. package/src/resources/generate.ts +29 -6
  113. package/src/resources/generations.ts +9 -4
  114. package/src/resources/projects.ts +274 -41
  115. package/src/resources/targets.ts +378 -0
  116. package/src/schemas.ts +135 -62
  117. package/src/types.ts +2273 -322
  118. package/dist/resources/spec-revisions.d.ts +0 -47
  119. package/dist/resources/spec-revisions.d.ts.map +0 -1
  120. package/dist/resources/spec-revisions.js +0 -90
  121. package/src/resources/spec-revisions.ts +0 -150
@@ -0,0 +1,165 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { oauthJsonRequest, oauthDeviceRequest, OAuthResponseError } from "./oauth-request.js";
3
+
4
+ export class LoginPollingError extends Error {
5
+ constructor(readonly code: "cancelled" | "expired" | "denied" | "invalid_response" | "request_failed") {
6
+ super({ cancelled: "Login was cancelled.", expired: "Login expired. Run login again and approve the new request.", denied: "Login was denied. Run login again if you want to retry.", invalid_response: "The login service returned an invalid response. Check its configuration.", request_failed: "The login request failed. Check the service and start a new login." }[code]);
7
+ this.name = "LoginPollingError";
8
+ }
9
+ }
10
+
11
+ export function loginEndpoint(value: string): URL {
12
+ try {
13
+ if (typeof value !== "string" || /[\x00-\x20\x7f]/.test(value)) throw new Error();
14
+ const url = new URL(value);
15
+ const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
16
+ if ((url.protocol !== "https:" && !(url.protocol === "http:" && local)) || url.username || url.password || url.hash) throw new Error();
17
+ return url;
18
+ } catch { throw new LoginPollingError("invalid_response"); }
19
+ }
20
+ function text(value: unknown, limit = 65_536): value is string {
21
+ return typeof value === "string" && value.trim().length > 0 && value.length <= limit && !/[\x00-\x1f\x7f]/.test(value);
22
+ }
23
+ function seconds(value: unknown): value is number {
24
+ return typeof value === "number" && Number.isFinite(value) && value > 0 && Number.isSafeInteger(Math.ceil(value * 1000));
25
+ }
26
+ function interval(value: unknown, fallback: number): number {
27
+ if (value === undefined) return fallback * 1000;
28
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || !Number.isSafeInteger(Math.ceil(value * 1000))) throw new LoginPollingError("invalid_response");
29
+ return Math.max(1, value) * 1000;
30
+ }
31
+ function lifetime(signal: AbortSignal | undefined, timeoutMs: number, maximum: number) {
32
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > maximum) throw new LoginPollingError("invalid_response");
33
+ const controller = new AbortController();
34
+ let expired = false;
35
+ const cancel = () => controller.abort();
36
+ const timer = setTimeout(() => { expired = true; controller.abort(); }, timeoutMs);
37
+ signal?.addEventListener("abort", cancel, { once: true });
38
+ if (signal?.aborted) cancel();
39
+ const check = () => { if (controller.signal.aborted) throw new LoginPollingError(expired ? "expired" : "cancelled"); };
40
+ return { signal: controller.signal, check, close() { clearTimeout(timer); signal?.removeEventListener("abort", cancel); } };
41
+ }
42
+ async function pause(ms: number, signal: AbortSignal): Promise<void> {
43
+ if (signal.aborted) throw new LoginPollingError("cancelled");
44
+ await new Promise<void>((resolve, reject) => {
45
+ const done = () => { clearTimeout(timer); signal.removeEventListener("abort", abort); resolve(); };
46
+ const abort = () => { clearTimeout(timer); signal.removeEventListener("abort", abort); reject(new LoginPollingError("cancelled")); };
47
+ const timer = setTimeout(done, Math.min(ms, 2_147_483_647));
48
+ signal.addEventListener("abort", abort, { once: true });
49
+ });
50
+ }
51
+ const form = (params: Record<string, string>, signal: AbortSignal): RequestInit => ({ method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" }, body: new URLSearchParams(params), signal });
52
+
53
+ export interface DeviceLoginConfig {
54
+ clientId: string; issuer?: string | null; discoveryUrls: string[];
55
+ deviceUrl?: string | null; tokenUrl?: string | null;
56
+ scopes: string[]; audience?: string; resource?: string;
57
+ }
58
+ export interface DeviceLoginSession {
59
+ accessToken: string; refreshToken?: string; expiresAt?: number;
60
+ tokenUrl: string; issuer?: string; clientId: string; revocationUrl?: string; scopes?: string[];
61
+ }
62
+
63
+ /** RFC 8628: pending and slow_down are the only responses that keep polling.
64
+ * All deadlines include response bodies; cancellation also interrupts waits. */
65
+ export async function oauthDeviceLogin(config: DeviceLoginConfig, interaction: {
66
+ authorize(value: { verificationUri: string; userCode: string; expiresIn: number }): void;
67
+ signal?: AbortSignal; timeoutMs?: number;
68
+ }): Promise<DeviceLoginSession> {
69
+ const flow = lifetime(interaction.signal, interaction.timeoutMs ?? 900_000, 900_000);
70
+ try {
71
+ flow.check();
72
+ if (!text(config.clientId)) throw new LoginPollingError("invalid_response");
73
+ if (config.issuer && loginEndpoint(config.issuer).search) throw new LoginPollingError("invalid_response");
74
+ let deviceUrl = config.deviceUrl ? loginEndpoint(config.deviceUrl).href : undefined;
75
+ let tokenUrl = config.tokenUrl ? loginEndpoint(config.tokenUrl).href : undefined;
76
+ let revocationUrl: string | undefined;
77
+ for (const url of config.discoveryUrls) {
78
+ if (deviceUrl && tokenUrl) break;
79
+ const response = await oauthJsonRequest(loginEndpoint(url), { headers: { Accept: "application/json" }, signal: flow.signal }, 10_000);
80
+ if (response.status !== 200) continue;
81
+ const data = response.data!;
82
+ if (config.issuer && data.issuer !== config.issuer) throw new LoginPollingError("invalid_response");
83
+ if (!deviceUrl && typeof data.device_authorization_endpoint === "string") deviceUrl = loginEndpoint(data.device_authorization_endpoint).href;
84
+ if (!tokenUrl && typeof data.token_endpoint === "string") tokenUrl = loginEndpoint(data.token_endpoint).href;
85
+ if (data.revocation_endpoint !== undefined) revocationUrl = loginEndpoint(data.revocation_endpoint as string).href;
86
+ }
87
+ if (!deviceUrl || !tokenUrl) throw new LoginPollingError("invalid_response");
88
+ const params = { ...(config.audience ? { audience: config.audience } : {}), ...(config.resource ? { resource: config.resource } : {}) };
89
+ const start = await oauthJsonRequest(deviceUrl, form({ client_id: config.clientId, ...(config.scopes.length ? { scope: config.scopes.join(" ") } : {}), ...params }, flow.signal));
90
+ const data = start.data;
91
+ if (start.status !== 200) throw new LoginPollingError("request_failed");
92
+ if (!data || !text(data.device_code) || !text(data.user_code, 512) || !text(data.verification_uri, 8192) || !seconds(data.expires_in)) throw new LoginPollingError("invalid_response");
93
+ loginEndpoint(data.verification_uri);
94
+ const verificationUri = loginEndpoint((data.verification_uri_complete ?? data.verification_uri) as string).href;
95
+ let intervalMs = interval(data.interval, 5);
96
+ const expiresIn = Math.min(data.expires_in, 900), deadline = Date.now() + expiresIn * 1000;
97
+ interaction.authorize({ verificationUri, userCode: data.user_code, expiresIn });
98
+ while (true) {
99
+ await pause(Math.min(intervalMs, Math.max(0, deadline - Date.now())), flow.signal);
100
+ flow.check();
101
+ if (Date.now() >= deadline) throw new LoginPollingError("expired");
102
+ let response: Awaited<ReturnType<typeof oauthDeviceRequest>>;
103
+ try { response = await oauthDeviceRequest(tokenUrl, form({ ...params, grant_type: "urn:ietf:params:oauth:grant-type:device_code", device_code: data.device_code, client_id: config.clientId }, flow.signal), Math.min(30_000, deadline - Date.now())); }
104
+ catch (error) {
105
+ flow.check();
106
+ if (error instanceof OAuthResponseError && error.code === "timed_out") { intervalMs *= 2; continue; }
107
+ throw error;
108
+ }
109
+ flow.check();
110
+ if (Date.now() >= deadline) throw new LoginPollingError("expired");
111
+ if (response.status === 400 && response.error === "authorization_pending") continue;
112
+ if (response.status === 400 && response.error === "slow_down") { intervalMs += 5000; continue; }
113
+ if (response.status === 400 && response.error === "access_denied") throw new LoginPollingError("denied");
114
+ if (response.status === 400 && response.error === "expired_token") throw new LoginPollingError("expired");
115
+ if (response.status !== 200) throw new LoginPollingError("request_failed");
116
+ const token = response.data!;
117
+ if (!text(token.access_token) || typeof token.token_type !== "string" || token.token_type.toLowerCase() !== "bearer" || token.error !== undefined || token.refresh_token !== undefined && !text(token.refresh_token) || token.expires_in !== undefined && !seconds(token.expires_in) || token.scope !== undefined && typeof token.scope !== "string") throw new LoginPollingError("invalid_response");
118
+ return { accessToken: token.access_token, ...(typeof token.refresh_token === "string" ? { refreshToken: token.refresh_token } : {}), ...(typeof token.expires_in === "number" ? { expiresAt: Date.now() + token.expires_in * 1000 } : {}), clientId: config.clientId, tokenUrl, ...(config.issuer ? { issuer: config.issuer } : {}), ...(revocationUrl ? { revocationUrl } : {}), ...(typeof token.scope === "string" ? { scopes: token.scope.split(/\s+/).filter(Boolean) } : {}) };
119
+ }
120
+ } catch (error) { flow.check(); throw error; }
121
+ finally { flow.close(); }
122
+ }
123
+
124
+ export interface ApprovedCredential { api_key: string; key_name: string; org_id?: string; revocationUrl: string }
125
+
126
+ /** This is the owner's custom approval contract, not an OAuth grant. A failed
127
+ * poll is not replayed: its one-use credential may already have been consumed. */
128
+ export async function customBrowserApproval(config: { authUrl: string; name: string; source: "agent" | "cli" }, interaction: {
129
+ authorize(value: { verificationUrl: string; expiresIn: number }): void;
130
+ signal?: AbortSignal; timeoutMs?: number;
131
+ }): Promise<ApprovedCredential> {
132
+ const flow = lifetime(interaction.signal, interaction.timeoutMs ?? 600_000, 600_000);
133
+ try {
134
+ flow.check();
135
+ const base = loginEndpoint(config.authUrl);
136
+ if (base.search) throw new LoginPollingError("invalid_response");
137
+ const url = base.href.replace(/\/$/, "");
138
+ const verifier = randomBytes(32).toString("base64url"), challenge = createHash("sha256").update(verifier).digest("base64url");
139
+ const post = (body: unknown): RequestInit => ({ method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify(body), signal: flow.signal });
140
+ const response = await oauthJsonRequest(url + "/start", post({ code_challenge: challenge, name: config.name, source: config.source }), 15_000);
141
+ if (response.status !== 200) throw new LoginPollingError("request_failed");
142
+ const start = response.data!;
143
+ if (!text(start.session) || !text(start.verification_url, 8192) || start.expires_in !== undefined && !seconds(start.expires_in)) throw new LoginPollingError("invalid_response");
144
+ const verificationUrl = loginEndpoint(start.verification_url).href;
145
+ const expiresIn = Math.min(typeof start.expires_in === "number" ? start.expires_in : 600, 600);
146
+ const intervalMs = interval(start.interval, 3), deadline = Date.now() + expiresIn * 1000;
147
+ interaction.authorize({ verificationUrl, expiresIn });
148
+ while (true) {
149
+ await pause(Math.min(intervalMs, Math.max(0, deadline - Date.now())), flow.signal);
150
+ flow.check();
151
+ if (Date.now() >= deadline) throw new LoginPollingError("expired");
152
+ const result = await oauthJsonRequest(url + "/status", post({ session: start.session, code_verifier: verifier }), Math.min(15_000, deadline - Date.now()));
153
+ flow.check();
154
+ if (Date.now() >= deadline) throw new LoginPollingError("expired");
155
+ if (result.status !== 200) throw new LoginPollingError("request_failed");
156
+ const poll = result.data!;
157
+ if (poll.status === "pending") continue;
158
+ if (poll.status === "denied") throw new LoginPollingError("denied");
159
+ if (poll.status === "expired") throw new LoginPollingError("expired");
160
+ if (poll.status !== "complete" || !text(poll.api_key) || poll.key_name !== undefined && !text(poll.key_name, 1024) || poll.org_id !== undefined && !text(poll.org_id, 1024)) throw new LoginPollingError("invalid_response");
161
+ return { api_key: poll.api_key, key_name: typeof poll.key_name === "string" ? poll.key_name : config.name, ...(typeof poll.org_id === "string" ? { org_id: poll.org_id } : {}), revocationUrl: url + "/revoke" };
162
+ }
163
+ } catch (error) { flow.check(); throw error; }
164
+ finally { flow.close(); }
165
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { HttpCore, type ApiResult, type RequestOptions } from "../core/http.js";
5
5
  import {
6
+ ResponseParseError,
6
7
  TransportError,
7
8
  UnexpectedApiError,
8
9
  ValidationError,
@@ -10,7 +11,7 @@ import {
10
11
  RateLimitedError,
11
12
  UnauthorizedError,
12
13
  } from "../errors.js";
13
- import type { Account } from "../types.js";
14
+ import type { Account, AccountRead } from "../types.js";
14
15
 
15
16
  export class AccountResource {
16
17
  constructor(private readonly _core: HttpCore) {}
@@ -21,10 +22,11 @@ export class AccountResource {
21
22
  * identity endpoint the generated typeship CLI's `whoami` calls.
22
23
  * `GET /me`
23
24
  */
24
- async retrieve(options?: RequestOptions): Promise<ApiResult<Account, AccountRetrieveError>> {
25
- return this._core.request<Account, AccountRetrieveError>({
25
+ async retrieve(options?: RequestOptions): Promise<ApiResult<AccountRead, AccountRetrieveError>> {
26
+ return this._core.request<AccountRead, AccountRetrieveError>({
26
27
  method: "GET",
27
28
  path: "/me",
29
+ security: [{"apiKey":[]}],
28
30
  errors: { "401": UnauthorizedError, "403": ForbiddenError, "429": RateLimitedError },
29
31
  idempotent: true,
30
32
  schemaKey: "account.retrieve",
@@ -39,5 +41,6 @@ export type AccountRetrieveError =
39
41
  | ForbiddenError
40
42
  | RateLimitedError
41
43
  | UnexpectedApiError
44
+ | ResponseParseError
42
45
  | TransportError
43
46
  | ValidationError;
@@ -4,6 +4,7 @@
4
4
  import { HttpCore, type ApiResult, type RequestOptions } from "../core/http.js";
5
5
  import { paginate, PagePromise } from "../core/pagination.js";
6
6
  import {
7
+ ResponseParseError,
7
8
  TransportError,
8
9
  UnexpectedApiError,
9
10
  ValidationError,
@@ -13,7 +14,14 @@ import {
13
14
  RateLimitedError,
14
15
  UnauthorizedError,
15
16
  } from "../errors.js";
16
- import type { ApiKey, ApiKeyList } from "../types.js";
17
+ import type {
18
+ ApiKey,
19
+ ApiKeyList,
20
+ ApiKeyListRead,
21
+ ApiKeyRead,
22
+ ApiKeyResponse,
23
+ ApiKeyResponseRead,
24
+ } from "../types.js";
17
25
 
18
26
  export class ApiKeysResource {
19
27
  constructor(private readonly _core: HttpCore) {}
@@ -26,10 +34,11 @@ export class ApiKeysResource {
26
34
  * Auto-paginates: `for await (const item of …)` walks every page.
27
35
  * `GET /api_keys`
28
36
  */
29
- list(params?: ApiKeysListParams, options?: RequestOptions): PagePromise<ApiKey, ApiKeysListError> {
30
- return paginate<ApiKey, ApiKeysListError>(this._core, {
37
+ list(params?: ApiKeysListParams, options?: RequestOptions): PagePromise<ApiKeyRead, ApiKeysListError> {
38
+ return paginate<ApiKeyRead, ApiKeysListError>(this._core, {
31
39
  method: "GET",
32
40
  path: "/api_keys",
41
+ security: [{"apiKey":[]}],
33
42
  query: {
34
43
  limit: params?.limit,
35
44
  cursor: params?.cursor,
@@ -57,13 +66,19 @@ export class ApiKeysResource {
57
66
  * Revoke an API key
58
67
  *
59
68
  * Idempotent: revoking an already-revoked key returns the same body, so a rotation script that
60
- * re-runs does not have to special-case having already succeeded.
69
+ * re-runs does not have to special-case having already succeeded. An OAuth member may revoke a
70
+ * key they created; an organization admin may revoke any key. Organization API keys retain
71
+ * account-wide authority.
61
72
  * `DELETE /api_keys/{api_key_id}`
62
73
  */
63
- async revoke(apiKeyId: string, options?: RequestOptions): Promise<ApiResult<ApiKey, ApiKeysRevokeError>> {
64
- return this._core.request<ApiKey, ApiKeysRevokeError>({
74
+ async revoke(
75
+ apiKeyId: string,
76
+ options?: RequestOptions,
77
+ ): Promise<ApiResult<ApiKeyResponseRead, ApiKeysRevokeError>> {
78
+ return this._core.request<ApiKeyResponseRead, ApiKeysRevokeError>({
65
79
  method: "DELETE",
66
80
  path: `/api_keys/${encodeURIComponent(String(apiKeyId))}`,
81
+ security: [{"apiKey":[]}],
67
82
  errors: {
68
83
  "401": UnauthorizedError,
69
84
  "403": ForbiddenError,
@@ -80,7 +95,10 @@ export class ApiKeysResource {
80
95
  export interface ApiKeysListParams {
81
96
  /** Maximum number of resources to return. */
82
97
  limit?: number;
83
- /** Opaque cursor from the preceding page's next_cursor. */
98
+ /**
99
+ * Opaque cursor from the preceding page's next_cursor. Valid only for the same account,
100
+ * operation, filters, and ordering that issued it.
101
+ */
84
102
  cursor?: string;
85
103
  }
86
104
 
@@ -91,6 +109,7 @@ export type ApiKeysListError =
91
109
  | ForbiddenError
92
110
  | RateLimitedError
93
111
  | UnexpectedApiError
112
+ | ResponseParseError
94
113
  | TransportError
95
114
  | ValidationError;
96
115
 
@@ -101,5 +120,6 @@ export type ApiKeysRevokeError =
101
120
  | NotFoundError
102
121
  | RateLimitedError
103
122
  | UnexpectedApiError
123
+ | ResponseParseError
104
124
  | TransportError
105
125
  | ValidationError;
@@ -0,0 +1,207 @@
1
+ // typeship — definitionRevisions resource.
2
+ // Generated by typeship — https://typeship.dev — do not edit by hand.
3
+
4
+ import { HttpCore, type ApiResult, type RequestOptions } from "../core/http.js";
5
+ import { paginate, PagePromise } from "../core/pagination.js";
6
+ import {
7
+ ResponseParseError,
8
+ TransportError,
9
+ UnexpectedApiError,
10
+ ValidationError,
11
+ BadRequestError,
12
+ ForbiddenError,
13
+ NotFoundError,
14
+ RateLimitedError,
15
+ UnauthorizedError,
16
+ } from "../errors.js";
17
+ import type {
18
+ DefinitionDocumentId,
19
+ DefinitionId,
20
+ DefinitionRevision,
21
+ DefinitionRevisionId,
22
+ DefinitionRevisionList,
23
+ DefinitionRevisionListRead,
24
+ DefinitionRevisionRead,
25
+ DefinitionRevisionResponse,
26
+ DefinitionRevisionResponseRead,
27
+ } from "../types.js";
28
+
29
+ export class DefinitionRevisionsResource {
30
+ constructor(private readonly _core: HttpCore) {}
31
+ /**
32
+ * List Definition Revisions
33
+ *
34
+ * Immutable snapshots of the complete resolved document graph this Definition observed, newest
35
+ * first. Content is available from the revision and document endpoints and is never embedded in a
36
+ * list response.
37
+ *
38
+ * Auto-paginates: `for await (const item of …)` walks every page.
39
+ * `GET /definitions/{definition_id}/revisions`
40
+ */
41
+ list(
42
+ definitionId: DefinitionId,
43
+ params?: DefinitionRevisionsListParams,
44
+ options?: RequestOptions,
45
+ ): PagePromise<DefinitionRevisionRead, DefinitionRevisionsListError> {
46
+ return paginate<DefinitionRevisionRead, DefinitionRevisionsListError>(this._core, {
47
+ method: "GET",
48
+ path: `/definitions/${encodeURIComponent(String(definitionId))}/revisions`,
49
+ security: [{"apiKey":[]}],
50
+ query: {
51
+ limit: params?.limit,
52
+ cursor: params?.cursor,
53
+ },
54
+ errors: {
55
+ "400": BadRequestError,
56
+ "401": UnauthorizedError,
57
+ "403": ForbiddenError,
58
+ "404": NotFoundError,
59
+ "429": RateLimitedError,
60
+ },
61
+ idempotent: true,
62
+ schemaKey: "definitionRevisions.list",
63
+ options,
64
+ }, {
65
+ style: "cursor",
66
+ itemsField: "data",
67
+ cursorParam: "cursor",
68
+ nextCursorField: "next_cursor",
69
+ hasMoreField: "has_more",
70
+ limitParam: "limit",
71
+ });
72
+ }
73
+
74
+ /**
75
+ * Retrieve a Definition Revision
76
+ *
77
+ * Metadata for one immutable resolved document graph. Fetch its canonical content or individual
78
+ * source documents from the content endpoints.
79
+ * `GET /definition_revisions/{definition_revision_id}`
80
+ */
81
+ async retrieve(
82
+ definitionRevisionId: DefinitionRevisionId,
83
+ options?: RequestOptions,
84
+ ): Promise<ApiResult<DefinitionRevisionResponseRead, DefinitionRevisionsRetrieveError>> {
85
+ return this._core.request<DefinitionRevisionResponseRead, DefinitionRevisionsRetrieveError>({
86
+ method: "GET",
87
+ path: `/definition_revisions/${encodeURIComponent(String(definitionRevisionId))}`,
88
+ security: [{"apiKey":[]}],
89
+ errors: {
90
+ "401": UnauthorizedError,
91
+ "403": ForbiddenError,
92
+ "404": NotFoundError,
93
+ "429": RateLimitedError,
94
+ },
95
+ idempotent: true,
96
+ schemaKey: "definitionRevisions.retrieve",
97
+ options,
98
+ });
99
+ }
100
+
101
+ /**
102
+ * Retrieve a Definition Revision's canonical content
103
+ *
104
+ * Returns the exact canonical resolved content identified by the revision's graph digest,
105
+ * suitable for saving or piping into a diff.
106
+ * `GET /definition_revisions/{definition_revision_id}/content`
107
+ */
108
+ async retrieveContent(
109
+ definitionRevisionId: DefinitionRevisionId,
110
+ options?: RequestOptions,
111
+ ): Promise<ApiResult<string, DefinitionRevisionsRetrieveContentError>> {
112
+ return this._core.request<string, DefinitionRevisionsRetrieveContentError>({
113
+ method: "GET",
114
+ path: `/definition_revisions/${encodeURIComponent(String(definitionRevisionId))}/content`,
115
+ security: [{"apiKey":[]}],
116
+ errors: {
117
+ "401": UnauthorizedError,
118
+ "403": ForbiddenError,
119
+ "404": NotFoundError,
120
+ "429": RateLimitedError,
121
+ },
122
+ idempotent: true,
123
+ schemaKey: "definitionRevisions.retrieveContent",
124
+ options,
125
+ });
126
+ }
127
+
128
+ /**
129
+ * Retrieve one source document from a Definition Revision
130
+ * `GET /definition_revisions/{definition_revision_id}/documents/{document_id}/content`
131
+ */
132
+ async retrieveDocumentContent(
133
+ definitionRevisionId: DefinitionRevisionId,
134
+ documentId: DefinitionDocumentId,
135
+ options?: RequestOptions,
136
+ ): Promise<ApiResult<string, DefinitionRevisionsRetrieveDocumentContentError>> {
137
+ return this._core.request<string, DefinitionRevisionsRetrieveDocumentContentError>({
138
+ method: "GET",
139
+ path: `/definition_revisions/${encodeURIComponent(String(definitionRevisionId))}/documents/${encodeURIComponent(String(documentId))}/content`,
140
+ security: [{"apiKey":[]}],
141
+ errors: {
142
+ "401": UnauthorizedError,
143
+ "403": ForbiddenError,
144
+ "404": NotFoundError,
145
+ "429": RateLimitedError,
146
+ },
147
+ idempotent: true,
148
+ schemaKey: "definitionRevisions.retrieveDocumentContent",
149
+ options,
150
+ });
151
+ }
152
+ }
153
+
154
+ export interface DefinitionRevisionsListParams {
155
+ /** Maximum number of resources to return. */
156
+ limit?: number;
157
+ /**
158
+ * Opaque cursor from the preceding page's next_cursor. Valid only for the same account,
159
+ * operation, filters, and ordering that issued it.
160
+ */
161
+ cursor?: string;
162
+ }
163
+
164
+ /** Every error `list` can produce, as a discriminated union. */
165
+ export type DefinitionRevisionsListError =
166
+ | BadRequestError
167
+ | UnauthorizedError
168
+ | ForbiddenError
169
+ | NotFoundError
170
+ | RateLimitedError
171
+ | UnexpectedApiError
172
+ | ResponseParseError
173
+ | TransportError
174
+ | ValidationError;
175
+
176
+ /** Every error `retrieve` can produce, as a discriminated union. */
177
+ export type DefinitionRevisionsRetrieveError =
178
+ | UnauthorizedError
179
+ | ForbiddenError
180
+ | NotFoundError
181
+ | RateLimitedError
182
+ | UnexpectedApiError
183
+ | ResponseParseError
184
+ | TransportError
185
+ | ValidationError;
186
+
187
+ /** Every error `retrieveContent` can produce, as a discriminated union. */
188
+ export type DefinitionRevisionsRetrieveContentError =
189
+ | UnauthorizedError
190
+ | ForbiddenError
191
+ | NotFoundError
192
+ | RateLimitedError
193
+ | UnexpectedApiError
194
+ | ResponseParseError
195
+ | TransportError
196
+ | ValidationError;
197
+
198
+ /** Every error `retrieveDocumentContent` can produce, as a discriminated union. */
199
+ export type DefinitionRevisionsRetrieveDocumentContentError =
200
+ | UnauthorizedError
201
+ | ForbiddenError
202
+ | NotFoundError
203
+ | RateLimitedError
204
+ | UnexpectedApiError
205
+ | ResponseParseError
206
+ | TransportError
207
+ | ValidationError;
@@ -0,0 +1,122 @@
1
+ // typeship — definitions resource.
2
+ // Generated by typeship — https://typeship.dev — do not edit by hand.
3
+
4
+ import { HttpCore, type ApiResult, type RequestOptions } from "../core/http.js";
5
+ import {
6
+ ResponseParseError,
7
+ TransportError,
8
+ UnexpectedApiError,
9
+ ValidationError,
10
+ BadRequestError,
11
+ ConflictError,
12
+ ForbiddenError,
13
+ NotFoundError,
14
+ RateLimitedError,
15
+ UnauthorizedError,
16
+ UnprocessableEntityError,
17
+ } from "../errors.js";
18
+ import type {
19
+ Definition,
20
+ DefinitionId,
21
+ DefinitionRead,
22
+ DefinitionUpdateRequest,
23
+ } from "../types.js";
24
+
25
+ export class DefinitionsResource {
26
+ constructor(private readonly _core: HttpCore) {}
27
+ /**
28
+ * Retrieve a Definition
29
+ * `GET /definitions/{definition_id}`
30
+ */
31
+ async retrieve(
32
+ definitionId: DefinitionId,
33
+ options?: RequestOptions,
34
+ ): Promise<ApiResult<DefinitionRead, DefinitionsRetrieveError>> {
35
+ return this._core.request<DefinitionRead, DefinitionsRetrieveError>({
36
+ method: "GET",
37
+ path: `/definitions/${encodeURIComponent(String(definitionId))}`,
38
+ security: [{"apiKey":[]}],
39
+ errors: {
40
+ "401": UnauthorizedError,
41
+ "403": ForbiddenError,
42
+ "404": NotFoundError,
43
+ "429": RateLimitedError,
44
+ },
45
+ idempotent: true,
46
+ schemaKey: "definitions.retrieve",
47
+ options,
48
+ });
49
+ }
50
+
51
+ /**
52
+ * Update and resolve a Definition
53
+ *
54
+ * Resolves the complete document graph and records a new immutable revision before saving.
55
+ *
56
+ * A `Idempotency-Key` UUID is generated per call (stable across retries) unless you pass one.
57
+ * `PATCH /definitions/{definition_id}`
58
+ */
59
+ async update(
60
+ definitionId: DefinitionId,
61
+ body: DefinitionUpdateRequest,
62
+ params?: DefinitionsUpdateParams,
63
+ options?: RequestOptions,
64
+ ): Promise<ApiResult<DefinitionRead, DefinitionsUpdateError>> {
65
+ return this._core.request<DefinitionRead, DefinitionsUpdateError>({
66
+ method: "PATCH",
67
+ path: `/definitions/${encodeURIComponent(String(definitionId))}`,
68
+ security: [{"apiKey":[]}],
69
+ headers: {
70
+ "Idempotency-Key": params?.idempotencyKey === undefined ? undefined : String(params?.idempotencyKey),
71
+ },
72
+ body,
73
+ errors: {
74
+ "400": BadRequestError,
75
+ "401": UnauthorizedError,
76
+ "403": ForbiddenError,
77
+ "404": NotFoundError,
78
+ "409": ConflictError,
79
+ "422": UnprocessableEntityError,
80
+ "429": RateLimitedError,
81
+ },
82
+ idempotencyKey: "Idempotency-Key",
83
+ schemaKey: "definitions.update",
84
+ options,
85
+ });
86
+ }
87
+ }
88
+
89
+ /** Every error `retrieve` can produce, as a discriminated union. */
90
+ export type DefinitionsRetrieveError =
91
+ | UnauthorizedError
92
+ | ForbiddenError
93
+ | NotFoundError
94
+ | RateLimitedError
95
+ | UnexpectedApiError
96
+ | ResponseParseError
97
+ | TransportError
98
+ | ValidationError;
99
+
100
+ export interface DefinitionsUpdateParams {
101
+ /**
102
+ * Identifies one logical write for 24 hours. The key is scoped to the authenticated account and
103
+ * operation; account-less generation uses a hashed network identity. Retrying the same method,
104
+ * path, query, and JSON body replays the original response. Reusing the key with changed intent
105
+ * returns 409. After expiry the key starts a new write.
106
+ */
107
+ idempotencyKey?: string;
108
+ }
109
+
110
+ /** Every error `update` can produce, as a discriminated union. */
111
+ export type DefinitionsUpdateError =
112
+ | BadRequestError
113
+ | UnauthorizedError
114
+ | ForbiddenError
115
+ | NotFoundError
116
+ | ConflictError
117
+ | UnprocessableEntityError
118
+ | RateLimitedError
119
+ | UnexpectedApiError
120
+ | ResponseParseError
121
+ | TransportError
122
+ | ValidationError;