@goliapkg/sentori-cli 0.5.1 → 0.5.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 +56 -0
- package/bin/sentori-cli.js +32 -0
- package/package.json +12 -21
- package/scripts/postinstall.js +90 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -466
- package/lib/index.js.map +0 -1
- package/lib/issue.d.ts +0 -28
- package/lib/issue.d.ts.map +0 -1
- package/lib/issue.js +0 -53
- package/lib/issue.js.map +0 -1
- package/lib/native-artifacts.d.ts +0 -43
- package/lib/native-artifacts.d.ts.map +0 -1
- package/lib/native-artifacts.js +0 -148
- package/lib/native-artifacts.js.map +0 -1
- package/lib/react-native.d.ts +0 -25
- package/lib/react-native.d.ts.map +0 -1
- package/lib/react-native.js +0 -74
- package/lib/react-native.js.map +0 -1
- package/lib/upload.d.ts +0 -24
- package/lib/upload.d.ts.map +0 -1
- package/lib/upload.js +0 -65
- package/lib/upload.js.map +0 -1
- package/src/__tests__/issue.test.ts +0 -95
- package/src/__tests__/native-artifacts.test.ts +0 -132
- package/src/__tests__/react-native.test.ts +0 -37
- package/src/__tests__/upload.test.ts +0 -121
- package/src/index.ts +0 -478
- package/src/issue.ts +0 -81
- package/src/native-artifacts.ts +0 -182
- package/src/react-native.ts +0 -87
- package/src/upload.ts +0 -85
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { join } from 'node:path'
|
|
4
|
-
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
6
|
-
|
|
7
|
-
import { collectFiles, uploadSourcemaps } from '../upload.js'
|
|
8
|
-
|
|
9
|
-
let dir = ''
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
dir = await mkdtemp(join(tmpdir(), 'sentori-cli-test-'))
|
|
12
|
-
await writeFile(join(dir, 'main.jsbundle'), '/*bundle*/')
|
|
13
|
-
await writeFile(join(dir, 'main.jsbundle.map'), '{"version":3}')
|
|
14
|
-
await writeFile(join(dir, 'app.js'), 'console.log(1)')
|
|
15
|
-
await writeFile(join(dir, 'app.js.map'), '{"version":3}')
|
|
16
|
-
await writeFile(join(dir, 'README.txt'), 'not a build artifact')
|
|
17
|
-
})
|
|
18
|
-
afterEach(async () => {
|
|
19
|
-
await rm(dir, { force: true, recursive: true })
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('collectFiles', () => {
|
|
23
|
-
test('a directory yields its .map / .js / .bundle files, not others', async () => {
|
|
24
|
-
const files = await collectFiles([dir])
|
|
25
|
-
const names = files.map((f) => f.replace(`${dir}/`, '')).sort()
|
|
26
|
-
expect(names).toEqual(['app.js', 'app.js.map', 'main.jsbundle', 'main.jsbundle.map'])
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('an explicit file is taken as-is regardless of extension', async () => {
|
|
30
|
-
const files = await collectFiles([join(dir, 'README.txt')])
|
|
31
|
-
expect(files).toEqual([join(dir, 'README.txt')])
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('dedupes when a file is named both directly and via its dir', async () => {
|
|
35
|
-
const files = await collectFiles([dir, join(dir, 'app.js.map')])
|
|
36
|
-
expect(files.filter((f) => f.endsWith('app.js.map'))).toHaveLength(1)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('throws on a nonexistent path', async () => {
|
|
40
|
-
await expect(collectFiles([join(dir, 'nope')])).rejects.toThrow('no such file or directory')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('throws when a directory has no uploadable files', async () => {
|
|
44
|
-
const empty = await mkdtemp(join(tmpdir(), 'sentori-cli-empty-'))
|
|
45
|
-
try {
|
|
46
|
-
await expect(collectFiles([empty])).rejects.toThrow('no .map')
|
|
47
|
-
} finally {
|
|
48
|
-
await rm(empty, { force: true, recursive: true })
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
describe('uploadSourcemaps', () => {
|
|
54
|
-
test('dryRun returns the file list, makes no request', async () => {
|
|
55
|
-
let called = false
|
|
56
|
-
const orig = globalThis.fetch
|
|
57
|
-
globalThis.fetch = (async () => {
|
|
58
|
-
called = true
|
|
59
|
-
return new Response()
|
|
60
|
-
}) as typeof fetch
|
|
61
|
-
try {
|
|
62
|
-
const r = await uploadSourcemaps({
|
|
63
|
-
apiUrl: 'https://api.example.com',
|
|
64
|
-
dryRun: true,
|
|
65
|
-
paths: [dir],
|
|
66
|
-
release: 'app@1.0.0+1',
|
|
67
|
-
token: 'st_pk_x',
|
|
68
|
-
})
|
|
69
|
-
expect(r.files).toHaveLength(4)
|
|
70
|
-
expect(called).toBe(false)
|
|
71
|
-
} finally {
|
|
72
|
-
globalThis.fetch = orig
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('POSTs multipart to /admin/api/releases/<release>/sourcemaps with the token', async () => {
|
|
77
|
-
const calls: { headers: Headers; url: string }[] = []
|
|
78
|
-
const orig = globalThis.fetch
|
|
79
|
-
globalThis.fetch = (async (url: Request | string | URL, init?: RequestInit) => {
|
|
80
|
-
calls.push({ headers: new Headers(init?.headers), url: String(url) })
|
|
81
|
-
return new Response(JSON.stringify({ artifacts: [], uploaded: 4 }), {
|
|
82
|
-
headers: { 'content-type': 'application/json' },
|
|
83
|
-
status: 200,
|
|
84
|
-
})
|
|
85
|
-
}) as typeof fetch
|
|
86
|
-
try {
|
|
87
|
-
const r = await uploadSourcemaps({
|
|
88
|
-
apiUrl: 'https://api.example.com/',
|
|
89
|
-
paths: [dir],
|
|
90
|
-
release: 'my app@1.0.0+1',
|
|
91
|
-
token: 'st_pk_secret',
|
|
92
|
-
})
|
|
93
|
-
expect(calls).toHaveLength(1)
|
|
94
|
-
expect(calls[0]?.url).toBe(
|
|
95
|
-
'https://api.example.com/admin/api/releases/my%20app%401.0.0%2B1/sourcemaps',
|
|
96
|
-
)
|
|
97
|
-
expect(calls[0]?.headers.get('authorization')).toBe('Bearer st_pk_secret')
|
|
98
|
-
expect(r.uploaded).toBe(4)
|
|
99
|
-
} finally {
|
|
100
|
-
globalThis.fetch = orig
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test('throws with the server detail on a non-2xx response', async () => {
|
|
105
|
-
const orig = globalThis.fetch
|
|
106
|
-
globalThis.fetch = (async () =>
|
|
107
|
-
new Response('release frozen', { status: 403, statusText: 'Forbidden' })) as typeof fetch
|
|
108
|
-
try {
|
|
109
|
-
await expect(
|
|
110
|
-
uploadSourcemaps({
|
|
111
|
-
apiUrl: 'https://api.example.com',
|
|
112
|
-
paths: [dir],
|
|
113
|
-
release: 'app@1.0.0+1',
|
|
114
|
-
token: 'st_pk_x',
|
|
115
|
-
}),
|
|
116
|
-
).rejects.toThrow('403 Forbidden — release frozen')
|
|
117
|
-
} finally {
|
|
118
|
-
globalThis.fetch = orig
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
})
|
package/src/index.ts
DELETED
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { parseArgs } from 'node:util'
|
|
3
|
-
|
|
4
|
-
import { formatIssueLine, issueList, issuePatch } from './issue.js'
|
|
5
|
-
import { uploadDsym, uploadMapping } from './native-artifacts.js'
|
|
6
|
-
import { reactNativeUpload } from './react-native.js'
|
|
7
|
-
import { uploadSourcemaps } from './upload.js'
|
|
8
|
-
|
|
9
|
-
const HELP = `sentori-cli — Sentori command-line interface
|
|
10
|
-
|
|
11
|
-
Source-map upload:
|
|
12
|
-
sentori-cli upload sourcemap [options] <path...>
|
|
13
|
-
Upload one or more files or directories. A directory is scanned
|
|
14
|
-
(one level) for *.map / *.js / *.jsbundle / *.bundle / *.hbc;
|
|
15
|
-
a file given explicitly is uploaded as-is. Use this for web
|
|
16
|
-
bundlers (point at the build dir) or for already-composed RN maps.
|
|
17
|
-
|
|
18
|
-
sentori-cli react-native upload [options]
|
|
19
|
-
Compose a Metro packager map + a Hermes map into one source map
|
|
20
|
-
and upload it (plus the bundle). Use this for a Hermes release
|
|
21
|
-
build. Requires --metro-map and --hermes-map.
|
|
22
|
-
|
|
23
|
-
Native artifacts (project-scoped, need --project + admin token):
|
|
24
|
-
sentori-cli upload dsym --project <uuid> [--release <r>] [--object-name <n>] [--debug-id <uuid> --arch <a>] <path>
|
|
25
|
-
Upload iOS dSYM debug info. By default walks a Foo.dSYM bundle
|
|
26
|
-
and uses "dwarfdump --uuid" to enumerate slices, uploading each.
|
|
27
|
-
Pass --debug-id and --arch to upload a single slice without
|
|
28
|
-
dwarfdump (useful in Linux CI where the toolchain isn't there).
|
|
29
|
-
|
|
30
|
-
sentori-cli upload mapping --project <uuid> [--release <r>] [--debug-id <uuid>] <mapping.txt>
|
|
31
|
-
Upload an R8 / ProGuard mapping (raw bytes). If the file starts
|
|
32
|
-
with a "# pg_map_id:" line the server sniffs the debug-id from
|
|
33
|
-
it; otherwise you can pass it explicitly.
|
|
34
|
-
|
|
35
|
-
CI triage:
|
|
36
|
-
sentori-cli issue list --project <uuid> [--status active|silenced|resolved|closed] [--limit N] [--error-type <t>]
|
|
37
|
-
sentori-cli issue resolve <issue-uuid> --project <uuid> [--in-release <r>]
|
|
38
|
-
sentori-cli issue silence <issue-uuid> --project <uuid>
|
|
39
|
-
|
|
40
|
-
Options (upload commands):
|
|
41
|
-
--release <r> release identifier — MUST equal the value the SDK
|
|
42
|
-
reports via init({ release }). Required.
|
|
43
|
-
--token <t> Sentori token (or set $SENTORI_TOKEN).
|
|
44
|
-
--api-url <url> Sentori API base (default https://api.sentori.golia.jp,
|
|
45
|
-
or $SENTORI_API_URL). For a self-hosted instance, your
|
|
46
|
-
host. (Accepts --ingest-url as an alias.)
|
|
47
|
-
--dry-run describe what would be uploaded; don't upload.
|
|
48
|
-
-h, --help show this help.
|
|
49
|
-
|
|
50
|
-
Options (react-native upload):
|
|
51
|
-
--metro-map <p> the *.packager.map Metro emits (--sourcemap-output).
|
|
52
|
-
--hermes-map <p> the *.hbc.map the Hermes compiler emits.
|
|
53
|
-
--bundle <p> optional: also upload the bundle (.jsbundle / .bundle).
|
|
54
|
-
|
|
55
|
-
Options (issue commands):
|
|
56
|
-
--project <uuid> project id (or set $SENTORI_PROJECT_ID).
|
|
57
|
-
--token <t> admin token, sk_… prefix (or $SENTORI_ADMIN_TOKEN /
|
|
58
|
-
$SENTORI_TOKEN). The ingest st_pk_ token may also work
|
|
59
|
-
on a self-hosted instance.
|
|
60
|
-
--api-url <url> Sentori API base (same as above).
|
|
61
|
-
--in-release <r> (resolve only) mark this release as where the fix
|
|
62
|
-
landed; the regression detector flips the issue back
|
|
63
|
-
to "regressed" if a matching event lands later.
|
|
64
|
-
|
|
65
|
-
Hermes release build, by hand:
|
|
66
|
-
npx react-native bundle --platform ios --dev false --entry-file index.js \\
|
|
67
|
-
--bundle-output main.jsbundle --sourcemap-output main.jsbundle.packager.map
|
|
68
|
-
# (the iOS/Android build compiles to Hermes and writes main.jsbundle.hbc.map)
|
|
69
|
-
npx @goliapkg/sentori-cli react-native upload \\
|
|
70
|
-
--release "<app>@<version>+<build>" --token "$SENTORI_TOKEN" \\
|
|
71
|
-
--metro-map main.jsbundle.packager.map --hermes-map main.jsbundle.hbc.map \\
|
|
72
|
-
--bundle main.jsbundle
|
|
73
|
-
`
|
|
74
|
-
|
|
75
|
-
type Common = { apiUrl: string; dryRun: boolean; release: string; token: string }
|
|
76
|
-
|
|
77
|
-
/** Parse the shared options, or print an error + return null. */
|
|
78
|
-
function parseCommon(values: Record<string, unknown>): Common | null {
|
|
79
|
-
const release = typeof values.release === 'string' ? values.release : undefined
|
|
80
|
-
if (!release) {
|
|
81
|
-
console.error('error: --release is required (must match the SDK’s init({ release }))')
|
|
82
|
-
return null
|
|
83
|
-
}
|
|
84
|
-
const dryRun = values['dry-run'] === true
|
|
85
|
-
const token =
|
|
86
|
-
(typeof values.token === 'string' ? values.token : undefined) ?? process.env.SENTORI_TOKEN
|
|
87
|
-
if (!token && !dryRun) {
|
|
88
|
-
console.error('error: --token (or $SENTORI_TOKEN) is required')
|
|
89
|
-
return null
|
|
90
|
-
}
|
|
91
|
-
const apiUrl =
|
|
92
|
-
(typeof values['api-url'] === 'string' ? values['api-url'] : undefined) ??
|
|
93
|
-
(typeof values['ingest-url'] === 'string' ? values['ingest-url'] : undefined) ??
|
|
94
|
-
process.env.SENTORI_API_URL ??
|
|
95
|
-
'https://api.sentori.golia.jp'
|
|
96
|
-
return { apiUrl, dryRun, release, token: token ?? '' }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function cmdUploadSourcemap(argv: string[]): Promise<number> {
|
|
100
|
-
let parsed
|
|
101
|
-
try {
|
|
102
|
-
parsed = parseArgs({
|
|
103
|
-
allowPositionals: true,
|
|
104
|
-
args: argv,
|
|
105
|
-
options: {
|
|
106
|
-
'api-url': { type: 'string' },
|
|
107
|
-
'dry-run': { type: 'boolean' },
|
|
108
|
-
help: { short: 'h', type: 'boolean' },
|
|
109
|
-
'ingest-url': { type: 'string' },
|
|
110
|
-
release: { type: 'string' },
|
|
111
|
-
token: { type: 'string' },
|
|
112
|
-
},
|
|
113
|
-
})
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.error(`error: ${(e as Error).message}\n`)
|
|
116
|
-
console.error(HELP)
|
|
117
|
-
return 2
|
|
118
|
-
}
|
|
119
|
-
if (parsed.values.help) {
|
|
120
|
-
console.log(HELP)
|
|
121
|
-
return 0
|
|
122
|
-
}
|
|
123
|
-
const c = parseCommon(parsed.values)
|
|
124
|
-
if (!c) return 2
|
|
125
|
-
if (parsed.positionals.length === 0) {
|
|
126
|
-
console.error('error: at least one path (file or directory) is required')
|
|
127
|
-
return 2
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
const result = await uploadSourcemaps({
|
|
131
|
-
apiUrl: c.apiUrl,
|
|
132
|
-
dryRun: c.dryRun,
|
|
133
|
-
paths: parsed.positionals,
|
|
134
|
-
release: c.release,
|
|
135
|
-
token: c.token,
|
|
136
|
-
})
|
|
137
|
-
reportUpload(result, c)
|
|
138
|
-
return 0
|
|
139
|
-
} catch (e) {
|
|
140
|
-
console.error(`upload failed: ${(e as Error).message}`)
|
|
141
|
-
return 1
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function cmdReactNativeUpload(argv: string[]): Promise<number> {
|
|
146
|
-
let parsed
|
|
147
|
-
try {
|
|
148
|
-
parsed = parseArgs({
|
|
149
|
-
args: argv,
|
|
150
|
-
options: {
|
|
151
|
-
'api-url': { type: 'string' },
|
|
152
|
-
bundle: { type: 'string' },
|
|
153
|
-
'dry-run': { type: 'boolean' },
|
|
154
|
-
help: { short: 'h', type: 'boolean' },
|
|
155
|
-
'hermes-map': { type: 'string' },
|
|
156
|
-
'ingest-url': { type: 'string' },
|
|
157
|
-
'metro-map': { type: 'string' },
|
|
158
|
-
release: { type: 'string' },
|
|
159
|
-
token: { type: 'string' },
|
|
160
|
-
},
|
|
161
|
-
})
|
|
162
|
-
} catch (e) {
|
|
163
|
-
console.error(`error: ${(e as Error).message}\n`)
|
|
164
|
-
console.error(HELP)
|
|
165
|
-
return 2
|
|
166
|
-
}
|
|
167
|
-
if (parsed.values.help) {
|
|
168
|
-
console.log(HELP)
|
|
169
|
-
return 0
|
|
170
|
-
}
|
|
171
|
-
const c = parseCommon(parsed.values)
|
|
172
|
-
if (!c) return 2
|
|
173
|
-
const metroMap = parsed.values['metro-map']
|
|
174
|
-
const hermesMap = parsed.values['hermes-map']
|
|
175
|
-
if (typeof metroMap !== 'string' || typeof hermesMap !== 'string') {
|
|
176
|
-
console.error('error: --metro-map and --hermes-map are both required')
|
|
177
|
-
return 2
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const result = await reactNativeUpload({
|
|
181
|
-
apiUrl: c.apiUrl,
|
|
182
|
-
bundle: typeof parsed.values.bundle === 'string' ? parsed.values.bundle : undefined,
|
|
183
|
-
dryRun: c.dryRun,
|
|
184
|
-
hermesMap,
|
|
185
|
-
metroMap,
|
|
186
|
-
release: c.release,
|
|
187
|
-
token: c.token,
|
|
188
|
-
})
|
|
189
|
-
reportUpload(result, c)
|
|
190
|
-
return 0
|
|
191
|
-
} catch (e) {
|
|
192
|
-
console.error(`react-native upload failed: ${(e as Error).message}`)
|
|
193
|
-
return 1
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function reportUpload(
|
|
198
|
-
result: { files: string[]; uploaded?: number },
|
|
199
|
-
c: Common,
|
|
200
|
-
): void {
|
|
201
|
-
if (c.dryRun) {
|
|
202
|
-
console.log(
|
|
203
|
-
`would upload ${result.files.length} file(s) to ${c.apiUrl.replace(/\/+$/, '')}/admin/api/releases/${encodeURIComponent(c.release)}/sourcemaps:`,
|
|
204
|
-
)
|
|
205
|
-
for (const f of result.files) console.log(` ${f}`)
|
|
206
|
-
} else {
|
|
207
|
-
console.log(
|
|
208
|
-
`uploaded ${result.uploaded ?? result.files.length} file(s) for release "${c.release}" — minified stacks on this release will now resolve to source.`,
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// ── issue commands ────────────────────────────────────────────────
|
|
214
|
-
|
|
215
|
-
type AdminCfg = { apiUrl: string; projectId: string; token: string }
|
|
216
|
-
|
|
217
|
-
function parseAdminCfg(values: Record<string, unknown>): AdminCfg | null {
|
|
218
|
-
const projectId =
|
|
219
|
-
(typeof values.project === 'string' ? values.project : undefined) ??
|
|
220
|
-
process.env.SENTORI_PROJECT_ID
|
|
221
|
-
if (!projectId) {
|
|
222
|
-
console.error('error: --project <uuid> (or $SENTORI_PROJECT_ID) is required')
|
|
223
|
-
return null
|
|
224
|
-
}
|
|
225
|
-
const token =
|
|
226
|
-
(typeof values.token === 'string' ? values.token : undefined) ??
|
|
227
|
-
process.env.SENTORI_ADMIN_TOKEN ??
|
|
228
|
-
process.env.SENTORI_TOKEN
|
|
229
|
-
if (!token) {
|
|
230
|
-
console.error(
|
|
231
|
-
'error: --token (or $SENTORI_ADMIN_TOKEN / $SENTORI_TOKEN) is required for issue commands',
|
|
232
|
-
)
|
|
233
|
-
return null
|
|
234
|
-
}
|
|
235
|
-
const apiUrl =
|
|
236
|
-
(typeof values['api-url'] === 'string' ? values['api-url'] : undefined) ??
|
|
237
|
-
(typeof values['ingest-url'] === 'string' ? values['ingest-url'] : undefined) ??
|
|
238
|
-
process.env.SENTORI_API_URL ??
|
|
239
|
-
'https://api.sentori.golia.jp'
|
|
240
|
-
return { apiUrl, projectId, token }
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async function cmdIssueList(argv: string[]): Promise<number> {
|
|
244
|
-
let parsed
|
|
245
|
-
try {
|
|
246
|
-
parsed = parseArgs({
|
|
247
|
-
args: argv,
|
|
248
|
-
options: {
|
|
249
|
-
'api-url': { type: 'string' },
|
|
250
|
-
'error-type': { type: 'string' },
|
|
251
|
-
help: { short: 'h', type: 'boolean' },
|
|
252
|
-
'ingest-url': { type: 'string' },
|
|
253
|
-
limit: { type: 'string' },
|
|
254
|
-
project: { type: 'string' },
|
|
255
|
-
status: { type: 'string' },
|
|
256
|
-
token: { type: 'string' },
|
|
257
|
-
},
|
|
258
|
-
})
|
|
259
|
-
} catch (e) {
|
|
260
|
-
console.error(`error: ${(e as Error).message}\n${HELP}`)
|
|
261
|
-
return 2
|
|
262
|
-
}
|
|
263
|
-
if (parsed.values.help) {
|
|
264
|
-
console.log(HELP)
|
|
265
|
-
return 0
|
|
266
|
-
}
|
|
267
|
-
const cfg = parseAdminCfg(parsed.values)
|
|
268
|
-
if (!cfg) return 2
|
|
269
|
-
const status = parsed.values.status
|
|
270
|
-
if (status && !['active', 'closed', 'resolved', 'silenced'].includes(status)) {
|
|
271
|
-
console.error(`error: --status must be one of: active, silenced, resolved, closed`)
|
|
272
|
-
return 2
|
|
273
|
-
}
|
|
274
|
-
const limitStr = parsed.values.limit
|
|
275
|
-
const limit = limitStr ? Number.parseInt(limitStr, 10) : undefined
|
|
276
|
-
try {
|
|
277
|
-
const rows = await issueList({
|
|
278
|
-
config: cfg,
|
|
279
|
-
errorType: parsed.values['error-type'],
|
|
280
|
-
limit,
|
|
281
|
-
status: status as 'active' | 'closed' | 'resolved' | 'silenced' | undefined,
|
|
282
|
-
})
|
|
283
|
-
if (rows.length === 0) {
|
|
284
|
-
console.log('(no matching issues)')
|
|
285
|
-
return 0
|
|
286
|
-
}
|
|
287
|
-
for (const r of rows) console.log(formatIssueLine(r))
|
|
288
|
-
return 0
|
|
289
|
-
} catch (e) {
|
|
290
|
-
console.error(`issue list failed: ${(e as Error).message}`)
|
|
291
|
-
return 1
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async function cmdIssuePatch(
|
|
296
|
-
argv: string[],
|
|
297
|
-
body: { resolvedInRelease?: string; status: 'active' | 'closed' | 'resolved' | 'silenced' },
|
|
298
|
-
verb: 'closed' | 'resolved' | 'silenced',
|
|
299
|
-
): Promise<number> {
|
|
300
|
-
let parsed
|
|
301
|
-
try {
|
|
302
|
-
parsed = parseArgs({
|
|
303
|
-
allowPositionals: true,
|
|
304
|
-
args: argv,
|
|
305
|
-
options: {
|
|
306
|
-
'api-url': { type: 'string' },
|
|
307
|
-
help: { short: 'h', type: 'boolean' },
|
|
308
|
-
'in-release': { type: 'string' },
|
|
309
|
-
'ingest-url': { type: 'string' },
|
|
310
|
-
project: { type: 'string' },
|
|
311
|
-
token: { type: 'string' },
|
|
312
|
-
},
|
|
313
|
-
})
|
|
314
|
-
} catch (e) {
|
|
315
|
-
console.error(`error: ${(e as Error).message}\n${HELP}`)
|
|
316
|
-
return 2
|
|
317
|
-
}
|
|
318
|
-
if (parsed.values.help) {
|
|
319
|
-
console.log(HELP)
|
|
320
|
-
return 0
|
|
321
|
-
}
|
|
322
|
-
const cfg = parseAdminCfg(parsed.values)
|
|
323
|
-
if (!cfg) return 2
|
|
324
|
-
const issueId = parsed.positionals[0]
|
|
325
|
-
if (!issueId) {
|
|
326
|
-
console.error('error: <issue-uuid> is required')
|
|
327
|
-
return 2
|
|
328
|
-
}
|
|
329
|
-
if (verb === 'resolved' && typeof parsed.values['in-release'] === 'string') {
|
|
330
|
-
body.resolvedInRelease = parsed.values['in-release']
|
|
331
|
-
}
|
|
332
|
-
try {
|
|
333
|
-
const updated = await issuePatch(cfg, issueId, body)
|
|
334
|
-
console.log(
|
|
335
|
-
`${issueId} → ${verb}${body.resolvedInRelease ? ` (in ${body.resolvedInRelease})` : ''}: ${updated.errorType}`,
|
|
336
|
-
)
|
|
337
|
-
return 0
|
|
338
|
-
} catch (e) {
|
|
339
|
-
console.error(`issue ${verb} failed: ${(e as Error).message}`)
|
|
340
|
-
return 1
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// ── native artifact upload ────────────────────────────────────────
|
|
345
|
-
|
|
346
|
-
async function cmdUploadDsym(argv: string[]): Promise<number> {
|
|
347
|
-
let parsed
|
|
348
|
-
try {
|
|
349
|
-
parsed = parseArgs({
|
|
350
|
-
allowPositionals: true,
|
|
351
|
-
args: argv,
|
|
352
|
-
options: {
|
|
353
|
-
'api-url': { type: 'string' },
|
|
354
|
-
arch: { type: 'string' },
|
|
355
|
-
'debug-id': { type: 'string' },
|
|
356
|
-
help: { short: 'h', type: 'boolean' },
|
|
357
|
-
'ingest-url': { type: 'string' },
|
|
358
|
-
'object-name': { type: 'string' },
|
|
359
|
-
project: { type: 'string' },
|
|
360
|
-
release: { type: 'string' },
|
|
361
|
-
token: { type: 'string' },
|
|
362
|
-
},
|
|
363
|
-
})
|
|
364
|
-
} catch (e) {
|
|
365
|
-
console.error(`error: ${(e as Error).message}\n${HELP}`)
|
|
366
|
-
return 2
|
|
367
|
-
}
|
|
368
|
-
if (parsed.values.help) {
|
|
369
|
-
console.log(HELP)
|
|
370
|
-
return 0
|
|
371
|
-
}
|
|
372
|
-
const cfg = parseAdminCfg(parsed.values)
|
|
373
|
-
if (!cfg) return 2
|
|
374
|
-
const path = parsed.positionals[0]
|
|
375
|
-
if (!path) {
|
|
376
|
-
console.error('error: a path to a .dSYM bundle or DWARF binary is required')
|
|
377
|
-
return 2
|
|
378
|
-
}
|
|
379
|
-
const debugId = parsed.values['debug-id']
|
|
380
|
-
const arch = parsed.values.arch
|
|
381
|
-
if ((debugId && !arch) || (arch && !debugId)) {
|
|
382
|
-
console.error('error: --debug-id and --arch must be passed together (or both omitted)')
|
|
383
|
-
return 2
|
|
384
|
-
}
|
|
385
|
-
try {
|
|
386
|
-
const r = await uploadDsym({
|
|
387
|
-
apiUrl: cfg.apiUrl,
|
|
388
|
-
arch: typeof arch === 'string' ? arch : undefined,
|
|
389
|
-
debugId: typeof debugId === 'string' ? debugId : undefined,
|
|
390
|
-
objectName: typeof parsed.values['object-name'] === 'string' ? parsed.values['object-name'] : undefined,
|
|
391
|
-
path,
|
|
392
|
-
projectId: cfg.projectId,
|
|
393
|
-
release: typeof parsed.values.release === 'string' ? parsed.values.release : undefined,
|
|
394
|
-
token: cfg.token,
|
|
395
|
-
})
|
|
396
|
-
console.log(`uploaded ${r.slices.length} dSYM slice(s):`)
|
|
397
|
-
for (const s of r.slices) console.log(` ${s.debugId} (${s.arch})`)
|
|
398
|
-
return 0
|
|
399
|
-
} catch (e) {
|
|
400
|
-
console.error(`dsym upload failed: ${(e as Error).message}`)
|
|
401
|
-
return 1
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
async function cmdUploadMapping(argv: string[]): Promise<number> {
|
|
406
|
-
let parsed
|
|
407
|
-
try {
|
|
408
|
-
parsed = parseArgs({
|
|
409
|
-
allowPositionals: true,
|
|
410
|
-
args: argv,
|
|
411
|
-
options: {
|
|
412
|
-
'api-url': { type: 'string' },
|
|
413
|
-
'debug-id': { type: 'string' },
|
|
414
|
-
help: { short: 'h', type: 'boolean' },
|
|
415
|
-
'ingest-url': { type: 'string' },
|
|
416
|
-
project: { type: 'string' },
|
|
417
|
-
release: { type: 'string' },
|
|
418
|
-
token: { type: 'string' },
|
|
419
|
-
},
|
|
420
|
-
})
|
|
421
|
-
} catch (e) {
|
|
422
|
-
console.error(`error: ${(e as Error).message}\n${HELP}`)
|
|
423
|
-
return 2
|
|
424
|
-
}
|
|
425
|
-
if (parsed.values.help) {
|
|
426
|
-
console.log(HELP)
|
|
427
|
-
return 0
|
|
428
|
-
}
|
|
429
|
-
const cfg = parseAdminCfg(parsed.values)
|
|
430
|
-
if (!cfg) return 2
|
|
431
|
-
const path = parsed.positionals[0]
|
|
432
|
-
if (!path) {
|
|
433
|
-
console.error('error: a path to mapping.txt is required')
|
|
434
|
-
return 2
|
|
435
|
-
}
|
|
436
|
-
try {
|
|
437
|
-
await uploadMapping({
|
|
438
|
-
apiUrl: cfg.apiUrl,
|
|
439
|
-
debugId: typeof parsed.values['debug-id'] === 'string' ? parsed.values['debug-id'] : undefined,
|
|
440
|
-
path,
|
|
441
|
-
projectId: cfg.projectId,
|
|
442
|
-
release: typeof parsed.values.release === 'string' ? parsed.values.release : undefined,
|
|
443
|
-
token: cfg.token,
|
|
444
|
-
})
|
|
445
|
-
console.log(`uploaded mapping for project ${cfg.projectId}${parsed.values.release ? ` / ${parsed.values.release}` : ''}`)
|
|
446
|
-
return 0
|
|
447
|
-
} catch (e) {
|
|
448
|
-
console.error(`mapping upload failed: ${(e as Error).message}`)
|
|
449
|
-
return 1
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
async function main(argv: string[]): Promise<number> {
|
|
454
|
-
if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
|
|
455
|
-
console.log(HELP)
|
|
456
|
-
return 0
|
|
457
|
-
}
|
|
458
|
-
const [a, b, ...rest] = argv
|
|
459
|
-
if (a === 'upload' && b === 'sourcemap') return cmdUploadSourcemap(rest)
|
|
460
|
-
if (a === 'upload' && b === 'dsym') return cmdUploadDsym(rest)
|
|
461
|
-
if (a === 'upload' && b === 'mapping') return cmdUploadMapping(rest)
|
|
462
|
-
if (a === 'react-native' && b === 'upload') return cmdReactNativeUpload(rest)
|
|
463
|
-
if (a === 'issue' && b === 'list') return cmdIssueList(rest)
|
|
464
|
-
if (a === 'issue' && b === 'resolve') return cmdIssuePatch(rest, { status: 'resolved' }, 'resolved')
|
|
465
|
-
if (a === 'issue' && b === 'silence') return cmdIssuePatch(rest, { status: 'silenced' }, 'silenced')
|
|
466
|
-
if (a === 'issue' && b === 'close') return cmdIssuePatch(rest, { status: 'closed' }, 'closed')
|
|
467
|
-
console.error(`unknown command: ${[a, b].filter(Boolean).join(' ') || '(none)'}\n`)
|
|
468
|
-
console.error(HELP)
|
|
469
|
-
return 2
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
main(process.argv.slice(2)).then(
|
|
473
|
-
(code) => process.exit(code),
|
|
474
|
-
(e: unknown) => {
|
|
475
|
-
console.error(`fatal: ${(e as Error).message}`)
|
|
476
|
-
process.exit(1)
|
|
477
|
-
},
|
|
478
|
-
)
|
package/src/issue.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// `sentori-cli issue list / resolve / silence` — CI triage helpers.
|
|
2
|
-
|
|
3
|
-
type Issue = {
|
|
4
|
-
errorType: string
|
|
5
|
-
eventCount: number
|
|
6
|
-
id: string
|
|
7
|
-
lastSeen: string
|
|
8
|
-
messageSample: string
|
|
9
|
-
status: 'active' | 'closed' | 'resolved' | 'silenced'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type AdminConfig = {
|
|
13
|
-
apiUrl: string
|
|
14
|
-
projectId: string
|
|
15
|
-
token: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function url(c: AdminConfig, path: string): string {
|
|
19
|
-
return `${c.apiUrl.replace(/\/+$/, '')}/admin/api/projects/${c.projectId}${path}`
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function adminFetch<T>(c: AdminConfig, path: string, init?: RequestInit): Promise<T> {
|
|
23
|
-
const resp = await fetch(url(c, path), {
|
|
24
|
-
...init,
|
|
25
|
-
headers: {
|
|
26
|
-
Authorization: `Bearer ${c.token}`,
|
|
27
|
-
'Content-Type': 'application/json',
|
|
28
|
-
...(init?.headers ?? {}),
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
if (!resp.ok) {
|
|
32
|
-
let detail = ''
|
|
33
|
-
try {
|
|
34
|
-
detail = await resp.text()
|
|
35
|
-
} catch {
|
|
36
|
-
// ignore
|
|
37
|
-
}
|
|
38
|
-
throw new Error(
|
|
39
|
-
`${resp.status} ${resp.statusText}${detail ? ` — ${detail.slice(0, 300)}` : ''}`,
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
// PATCH /issues/<id> returns the row; some endpoints might return no
|
|
43
|
-
// content — handle both.
|
|
44
|
-
const txt = await resp.text()
|
|
45
|
-
return (txt ? JSON.parse(txt) : null) as T
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type IssueListOptions = {
|
|
49
|
-
config: AdminConfig
|
|
50
|
-
errorType?: string
|
|
51
|
-
limit?: number
|
|
52
|
-
status?: 'active' | 'closed' | 'resolved' | 'silenced'
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function issueList(opts: IssueListOptions): Promise<Issue[]> {
|
|
56
|
-
const q = new URLSearchParams()
|
|
57
|
-
if (opts.status) q.set('status', opts.status)
|
|
58
|
-
if (opts.limit) q.set('limit', String(opts.limit))
|
|
59
|
-
if (opts.errorType) q.set('errorType', opts.errorType)
|
|
60
|
-
const qs = q.toString()
|
|
61
|
-
return adminFetch<Issue[]>(opts.config, `/issues${qs ? '?' + qs : ''}`)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function issuePatch(
|
|
65
|
-
config: AdminConfig,
|
|
66
|
-
issueId: string,
|
|
67
|
-
body: { resolvedInRelease?: string; status: 'active' | 'closed' | 'resolved' | 'silenced' },
|
|
68
|
-
): Promise<Issue> {
|
|
69
|
-
return adminFetch<Issue>(config, `/issues/${encodeURIComponent(issueId)}`, {
|
|
70
|
-
body: JSON.stringify(body),
|
|
71
|
-
method: 'PATCH',
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Format one issue for terminal output — short, one line, scannable. */
|
|
76
|
-
export function formatIssueLine(i: Issue): string {
|
|
77
|
-
const status = i.status.padEnd(9)
|
|
78
|
-
const title = `${i.errorType}${i.messageSample ? `: ${i.messageSample}` : ''}`
|
|
79
|
-
const events = `${i.eventCount}×`
|
|
80
|
-
return `${i.id} ${status} ${title.slice(0, 80).padEnd(80)} ${events}`
|
|
81
|
-
}
|