@onmyway133/asc-cli 1.0.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 (55) hide show
  1. package/README.md +299 -0
  2. package/bun.lock +231 -0
  3. package/dist/index.js +179 -0
  4. package/docs/API_COVERAGE.md +355 -0
  5. package/docs/openapi/latest.json +230597 -0
  6. package/docs/openapi/paths.txt +1208 -0
  7. package/openapi-ts.config.ts +25 -0
  8. package/package.json +32 -0
  9. package/scripts/gen-paths-index.py +24 -0
  10. package/src/api/client.ts +132 -0
  11. package/src/api/generated/client/client.gen.ts +298 -0
  12. package/src/api/generated/client/index.ts +25 -0
  13. package/src/api/generated/client/types.gen.ts +214 -0
  14. package/src/api/generated/client/utils.gen.ts +316 -0
  15. package/src/api/generated/client.gen.ts +16 -0
  16. package/src/api/generated/core/auth.gen.ts +41 -0
  17. package/src/api/generated/core/bodySerializer.gen.ts +82 -0
  18. package/src/api/generated/core/params.gen.ts +169 -0
  19. package/src/api/generated/core/pathSerializer.gen.ts +171 -0
  20. package/src/api/generated/core/queryKeySerializer.gen.ts +117 -0
  21. package/src/api/generated/core/serverSentEvents.gen.ts +242 -0
  22. package/src/api/generated/core/types.gen.ts +104 -0
  23. package/src/api/generated/core/utils.gen.ts +140 -0
  24. package/src/api/generated/index.ts +4 -0
  25. package/src/api/generated/sdk.gen.ts +11701 -0
  26. package/src/api/generated/types.gen.ts +92035 -0
  27. package/src/api/hey-api-client.ts +20 -0
  28. package/src/api/types.ts +160 -0
  29. package/src/auth/credentials.ts +125 -0
  30. package/src/auth/jwt.ts +118 -0
  31. package/src/commands/app-info.ts +110 -0
  32. package/src/commands/apps.ts +44 -0
  33. package/src/commands/auth.ts +327 -0
  34. package/src/commands/availability.ts +52 -0
  35. package/src/commands/beta-review.ts +145 -0
  36. package/src/commands/builds.ts +97 -0
  37. package/src/commands/game-center.ts +114 -0
  38. package/src/commands/iap.ts +105 -0
  39. package/src/commands/metadata.ts +81 -0
  40. package/src/commands/pricing.ts +110 -0
  41. package/src/commands/reports.ts +116 -0
  42. package/src/commands/reviews.ts +93 -0
  43. package/src/commands/screenshots.ts +139 -0
  44. package/src/commands/signing.ts +214 -0
  45. package/src/commands/subscriptions.ts +144 -0
  46. package/src/commands/testflight.ts +110 -0
  47. package/src/commands/versions.ts +76 -0
  48. package/src/commands/xcode-cloud.ts +207 -0
  49. package/src/index.ts +1661 -0
  50. package/src/utils/help-spec.ts +835 -0
  51. package/src/utils/output.ts +79 -0
  52. package/tests/auth.test.ts +105 -0
  53. package/tests/client.test.ts +22 -0
  54. package/tests/output.test.ts +36 -0
  55. package/tsconfig.json +15 -0
@@ -0,0 +1,25 @@
1
+ import { defineConfig } from "@hey-api/openapi-ts"
2
+
3
+ /**
4
+ * hey-api SDK generation config.
5
+ *
6
+ * Input: the offline OpenAPI snapshot at docs/openapi/latest.json
7
+ * To update the snapshot and regenerate: bun run generate
8
+ *
9
+ * The snapshot is committed to the repo. When Apple updates their API,
10
+ * update the snapshot file and re-run generation.
11
+ */
12
+ export default defineConfig({
13
+ input: "docs/openapi/latest.json",
14
+ output: {
15
+ path: "src/api/generated",
16
+ format: "prettier",
17
+ },
18
+ plugins: [
19
+ "@hey-api/typescript",
20
+ {
21
+ name: "@hey-api/sdk",
22
+ asClass: false,
23
+ },
24
+ ],
25
+ })
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@onmyway133/asc-cli",
3
+ "version": "1.0.1",
4
+ "description": "App Store Connect CLI — manage apps, builds, TestFlight, metadata and more from your terminal",
5
+ "type": "module",
6
+ "bin": {
7
+ "asc": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "dev": "bun run src/index.ts",
11
+ "build": "bun build src/index.ts --outfile dist/index.js --target bun --minify",
12
+ "test": "bun test",
13
+ "typecheck": "tsc --noEmit",
14
+ "generate": "curl -s https://raw.githubusercontent.com/EvanBacon/App-Store-Connect-OpenAPI-Spec/main/specs/latest.json -o docs/openapi/latest.json && python3 scripts/gen-paths-index.py && openapi-ts --file openapi-ts.config.ts"
15
+ },
16
+ "dependencies": {
17
+ "@clack/prompts": "^1.2.0",
18
+ "@hey-api/client-fetch": "^0.13.1",
19
+ "@hey-api/openapi-ts": "^0.96.0",
20
+ "chalk": "^5.3.0",
21
+ "citty": "^0.1.6",
22
+ "cli-table3": "^0.6.5",
23
+ "jose": "^5.9.6"
24
+ },
25
+ "devDependencies": {
26
+ "bun-types": "latest",
27
+ "typescript": "^5.5.4"
28
+ },
29
+ "engines": {
30
+ "bun": ">=1.0.0"
31
+ }
32
+ }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env python3
2
+ """Regenerate docs/openapi/paths.txt from docs/openapi/latest.json"""
3
+ import json, os
4
+
5
+ root = os.path.join(os.path.dirname(__file__), "..")
6
+ spec_path = os.path.join(root, "docs", "openapi", "latest.json")
7
+ out_path = os.path.join(root, "docs", "openapi", "paths.txt")
8
+
9
+ with open(spec_path) as f:
10
+ spec = json.load(f)
11
+
12
+ paths = spec.get("paths", {})
13
+ lines = []
14
+ for path, methods in sorted(paths.items()):
15
+ for method in ("get", "post", "patch", "delete"):
16
+ if method in methods:
17
+ op = methods[method]
18
+ summary = op.get("summary") or op.get("operationId", "")
19
+ lines.append(f"{method.upper():7} {path} # {summary}")
20
+
21
+ with open(out_path, "w") as f:
22
+ f.write("\n".join(lines) + "\n")
23
+
24
+ print(f"paths.txt: {len(lines)} endpoints written")
@@ -0,0 +1,132 @@
1
+ /**
2
+ * ASC API client.
3
+ *
4
+ * Architecture:
5
+ * - Auto-generated SDK functions live in src/api/generated/sdk.gen.ts
6
+ * (regenerate with: bun run generate)
7
+ * - This file provides:
8
+ * a) JWT auth middleware wired onto the hey-api generated client
9
+ * b) ascFetch / ascFetchAll — lightweight helpers for custom endpoints
10
+ * not covered by the generated SDK, or for commands that pre-date the SDK.
11
+ *
12
+ * New commands should prefer importing functions from ./generated/sdk.gen.ts
13
+ * directly after calling configureAuth() at startup.
14
+ */
15
+
16
+ import { getActiveProfile } from "../auth/credentials.ts"
17
+ import { generateJWT } from "../auth/jwt.ts"
18
+
19
+ // ---- Error types ----
20
+
21
+ export interface ASCApiError {
22
+ id?: string
23
+ status: string
24
+ code: string
25
+ title: string
26
+ detail?: string
27
+ }
28
+
29
+ export class ASCError extends Error {
30
+ constructor(
31
+ message: string,
32
+ public readonly status: number,
33
+ public readonly errors?: ASCApiError[],
34
+ ) {
35
+ super(message)
36
+ this.name = "ASCError"
37
+ }
38
+ }
39
+
40
+ // ---- Helper: throw on API error ----
41
+
42
+ export function throwOnError<T>(result: { data?: T; error?: unknown }): T {
43
+ if (result.error) {
44
+ const err = result.error as { errors?: ASCApiError[] }
45
+ const first = err.errors?.[0]
46
+ const msg = first?.detail ?? first?.title ?? "API error"
47
+ const status = first?.status ? Number(first.status) : 500
48
+ throw new ASCError(msg, status, err.errors)
49
+ }
50
+ if (result.data === undefined) throw new ASCError("Empty response", 500)
51
+ return result.data
52
+ }
53
+
54
+ // ---- Internal auth helper ----
55
+
56
+ async function authHeaders(): Promise<Headers> {
57
+ const profile = getActiveProfile()
58
+ if (!profile) throw new ASCError("No active profile. Run: asc auth login", 401)
59
+ const token = await generateJWT(profile)
60
+ const headers = new Headers()
61
+ headers.set("Authorization", `Bearer ${token}`)
62
+ headers.set("Content-Type", "application/json")
63
+ return headers
64
+ }
65
+
66
+ // ---- Generic fetch wrapper (for endpoints without a generated SDK function) ----
67
+
68
+ export async function ascFetch<T>(
69
+ path: string,
70
+ options: { method?: string; body?: unknown; params?: Record<string, unknown> } = {},
71
+ ): Promise<{ data: T }> {
72
+ const headers = await authHeaders()
73
+ const url = new URL(`https://api.appstoreconnect.apple.com${path}`)
74
+ if (options.params) {
75
+ for (const [k, v] of Object.entries(options.params)) {
76
+ if (v !== undefined) url.searchParams.set(k, String(v))
77
+ }
78
+ }
79
+ const res = await fetch(url.toString(), {
80
+ method: options.method ?? "GET",
81
+ headers,
82
+ body: options.body ? JSON.stringify(options.body) : undefined,
83
+ })
84
+ if (res.status === 204) return { data: undefined as unknown as T }
85
+ const json = await res.json() as Record<string, unknown>
86
+ if (!res.ok) {
87
+ const errors = json["errors"] as ASCApiError[] | undefined
88
+ const msg = errors?.[0]?.detail ?? errors?.[0]?.title ?? `HTTP ${res.status}`
89
+ throw new ASCError(msg, res.status, errors)
90
+ }
91
+ return json as { data: T }
92
+ }
93
+
94
+ // ---- Paginated fetch (auto-follows next-page cursors) ----
95
+
96
+ export async function ascFetchAll<T>(
97
+ path: string,
98
+ options: { params?: Record<string, unknown> } = {},
99
+ maxPages = 20,
100
+ ): Promise<T[]> {
101
+ const items: T[] = []
102
+ let nextUrl: string | undefined
103
+ let page = 0
104
+
105
+ while (page < maxPages) {
106
+ const headers = await authHeaders()
107
+
108
+ const url = nextUrl ?? (() => {
109
+ const u = new URL(`https://api.appstoreconnect.apple.com${path}`)
110
+ for (const [k, v] of Object.entries({ limit: "200", ...options.params })) {
111
+ if (v !== undefined) u.searchParams.set(k, String(v))
112
+ }
113
+ return u.toString()
114
+ })()
115
+
116
+ const res = await fetch(url, { headers })
117
+ const json = await res.json() as Record<string, unknown>
118
+ if (!res.ok) {
119
+ const errors = json["errors"] as ASCApiError[] | undefined
120
+ const msg = errors?.[0]?.detail ?? errors?.[0]?.title ?? `HTTP ${res.status}`
121
+ throw new ASCError(msg, res.status, errors)
122
+ }
123
+
124
+ const data = json["data"]
125
+ if (Array.isArray(data)) items.push(...(data as T[]))
126
+ nextUrl = (json["links"] as Record<string, string> | undefined)?.["next"]
127
+ if (!nextUrl) break
128
+ page++
129
+ }
130
+
131
+ return items
132
+ }
@@ -0,0 +1,298 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import { createSseClient } from '../core/serverSentEvents.gen';
4
+ import type { HttpMethod } from '../core/types.gen';
5
+ import { getValidRequestBody } from '../core/utils.gen';
6
+ import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
7
+ import {
8
+ buildUrl,
9
+ createConfig,
10
+ createInterceptors,
11
+ getParseAs,
12
+ mergeConfigs,
13
+ mergeHeaders,
14
+ setAuthParams,
15
+ } from './utils.gen';
16
+
17
+ type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
18
+ body?: any;
19
+ headers: ReturnType<typeof mergeHeaders>;
20
+ };
21
+
22
+ export const createClient = (config: Config = {}): Client => {
23
+ let _config = mergeConfigs(createConfig(), config);
24
+
25
+ const getConfig = (): Config => ({ ..._config });
26
+
27
+ const setConfig = (config: Config): Config => {
28
+ _config = mergeConfigs(_config, config);
29
+ return getConfig();
30
+ };
31
+
32
+ const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
33
+
34
+ const beforeRequest = async <
35
+ TData = unknown,
36
+ TResponseStyle extends 'data' | 'fields' = 'fields',
37
+ ThrowOnError extends boolean = boolean,
38
+ Url extends string = string,
39
+ >(
40
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
41
+ ) => {
42
+ const opts = {
43
+ ..._config,
44
+ ...options,
45
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
46
+ headers: mergeHeaders(_config.headers, options.headers),
47
+ serializedBody: undefined as string | undefined,
48
+ };
49
+
50
+ if (opts.security) {
51
+ await setAuthParams({
52
+ ...opts,
53
+ security: opts.security,
54
+ });
55
+ }
56
+
57
+ if (opts.requestValidator) {
58
+ await opts.requestValidator(opts);
59
+ }
60
+
61
+ if (opts.body !== undefined && opts.bodySerializer) {
62
+ opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
63
+ }
64
+
65
+ // remove Content-Type header if body is empty to avoid sending invalid requests
66
+ if (opts.body === undefined || opts.serializedBody === '') {
67
+ opts.headers.delete('Content-Type');
68
+ }
69
+
70
+ const resolvedOpts = opts as typeof opts &
71
+ ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
72
+ const url = buildUrl(resolvedOpts);
73
+
74
+ return { opts: resolvedOpts, url };
75
+ };
76
+
77
+ const request: Client['request'] = async (options) => {
78
+ const { opts, url } = await beforeRequest(options);
79
+ const requestInit: ReqInit = {
80
+ redirect: 'follow',
81
+ ...opts,
82
+ body: getValidRequestBody(opts),
83
+ };
84
+
85
+ let request = new Request(url, requestInit);
86
+
87
+ for (const fn of interceptors.request.fns) {
88
+ if (fn) {
89
+ request = await fn(request, opts);
90
+ }
91
+ }
92
+
93
+ // fetch must be assigned here, otherwise it would throw the error:
94
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
95
+ const _fetch = opts.fetch!;
96
+ let response: Response;
97
+
98
+ try {
99
+ response = await _fetch(request);
100
+ } catch (error) {
101
+ // Handle fetch exceptions (AbortError, network errors, etc.)
102
+ let finalError = error;
103
+
104
+ for (const fn of interceptors.error.fns) {
105
+ if (fn) {
106
+ finalError = (await fn(error, undefined as any, request, opts)) as unknown;
107
+ }
108
+ }
109
+
110
+ finalError = finalError || ({} as unknown);
111
+
112
+ if (opts.throwOnError) {
113
+ throw finalError;
114
+ }
115
+
116
+ // Return error response
117
+ return opts.responseStyle === 'data'
118
+ ? undefined
119
+ : {
120
+ error: finalError,
121
+ request,
122
+ response: undefined as any,
123
+ };
124
+ }
125
+
126
+ for (const fn of interceptors.response.fns) {
127
+ if (fn) {
128
+ response = await fn(response, request, opts);
129
+ }
130
+ }
131
+
132
+ const result = {
133
+ request,
134
+ response,
135
+ };
136
+
137
+ if (response.ok) {
138
+ const parseAs =
139
+ (opts.parseAs === 'auto'
140
+ ? getParseAs(response.headers.get('Content-Type'))
141
+ : opts.parseAs) ?? 'json';
142
+
143
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
144
+ let emptyData: any;
145
+ switch (parseAs) {
146
+ case 'arrayBuffer':
147
+ case 'blob':
148
+ case 'text':
149
+ emptyData = await response[parseAs]();
150
+ break;
151
+ case 'formData':
152
+ emptyData = new FormData();
153
+ break;
154
+ case 'stream':
155
+ emptyData = response.body;
156
+ break;
157
+ case 'json':
158
+ default:
159
+ emptyData = {};
160
+ break;
161
+ }
162
+ return opts.responseStyle === 'data'
163
+ ? emptyData
164
+ : {
165
+ data: emptyData,
166
+ ...result,
167
+ };
168
+ }
169
+
170
+ let data: any;
171
+ switch (parseAs) {
172
+ case 'arrayBuffer':
173
+ case 'blob':
174
+ case 'formData':
175
+ case 'text':
176
+ data = await response[parseAs]();
177
+ break;
178
+ case 'json': {
179
+ // Some servers return 200 with no Content-Length and empty body.
180
+ // response.json() would throw; read as text and parse if non-empty.
181
+ const text = await response.text();
182
+ data = text ? JSON.parse(text) : {};
183
+ break;
184
+ }
185
+ case 'stream':
186
+ return opts.responseStyle === 'data'
187
+ ? response.body
188
+ : {
189
+ data: response.body,
190
+ ...result,
191
+ };
192
+ }
193
+
194
+ if (parseAs === 'json') {
195
+ if (opts.responseValidator) {
196
+ await opts.responseValidator(data);
197
+ }
198
+
199
+ if (opts.responseTransformer) {
200
+ data = await opts.responseTransformer(data);
201
+ }
202
+ }
203
+
204
+ return opts.responseStyle === 'data'
205
+ ? data
206
+ : {
207
+ data,
208
+ ...result,
209
+ };
210
+ }
211
+
212
+ const textError = await response.text();
213
+ let jsonError: unknown;
214
+
215
+ try {
216
+ jsonError = JSON.parse(textError);
217
+ } catch {
218
+ // noop
219
+ }
220
+
221
+ const error = jsonError ?? textError;
222
+ let finalError = error;
223
+
224
+ for (const fn of interceptors.error.fns) {
225
+ if (fn) {
226
+ finalError = (await fn(error, response, request, opts)) as string;
227
+ }
228
+ }
229
+
230
+ finalError = finalError || ({} as string);
231
+
232
+ if (opts.throwOnError) {
233
+ throw finalError;
234
+ }
235
+
236
+ // TODO: we probably want to return error and improve types
237
+ return opts.responseStyle === 'data'
238
+ ? undefined
239
+ : {
240
+ error: finalError,
241
+ ...result,
242
+ };
243
+ };
244
+
245
+ const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
246
+ request({ ...options, method });
247
+
248
+ const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
249
+ const { opts, url } = await beforeRequest(options);
250
+ return createSseClient({
251
+ ...opts,
252
+ body: opts.body as BodyInit | null | undefined,
253
+ headers: opts.headers as unknown as Record<string, string>,
254
+ method,
255
+ onRequest: async (url, init) => {
256
+ let request = new Request(url, init);
257
+ for (const fn of interceptors.request.fns) {
258
+ if (fn) {
259
+ request = await fn(request, opts);
260
+ }
261
+ }
262
+ return request;
263
+ },
264
+ serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
265
+ url,
266
+ });
267
+ };
268
+
269
+ const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options });
270
+
271
+ return {
272
+ buildUrl: _buildUrl,
273
+ connect: makeMethodFn('CONNECT'),
274
+ delete: makeMethodFn('DELETE'),
275
+ get: makeMethodFn('GET'),
276
+ getConfig,
277
+ head: makeMethodFn('HEAD'),
278
+ interceptors,
279
+ options: makeMethodFn('OPTIONS'),
280
+ patch: makeMethodFn('PATCH'),
281
+ post: makeMethodFn('POST'),
282
+ put: makeMethodFn('PUT'),
283
+ request,
284
+ setConfig,
285
+ sse: {
286
+ connect: makeSseFn('CONNECT'),
287
+ delete: makeSseFn('DELETE'),
288
+ get: makeSseFn('GET'),
289
+ head: makeSseFn('HEAD'),
290
+ options: makeSseFn('OPTIONS'),
291
+ patch: makeSseFn('PATCH'),
292
+ post: makeSseFn('POST'),
293
+ put: makeSseFn('PUT'),
294
+ trace: makeSseFn('TRACE'),
295
+ },
296
+ trace: makeMethodFn('TRACE'),
297
+ } as Client;
298
+ };
@@ -0,0 +1,25 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type { Auth } from '../core/auth.gen';
4
+ export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
5
+ export {
6
+ formDataBodySerializer,
7
+ jsonBodySerializer,
8
+ urlSearchParamsBodySerializer,
9
+ } from '../core/bodySerializer.gen';
10
+ export { buildClientParams } from '../core/params.gen';
11
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
12
+ export { createClient } from './client.gen';
13
+ export type {
14
+ Client,
15
+ ClientOptions,
16
+ Config,
17
+ CreateClientConfig,
18
+ Options,
19
+ RequestOptions,
20
+ RequestResult,
21
+ ResolvedRequestOptions,
22
+ ResponseStyle,
23
+ TDataShape,
24
+ } from './types.gen';
25
+ export { createConfig, mergeHeaders } from './utils.gen';