@sentio/cli 4.0.1-rc.3 → 4.0.1-rc.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/cli",
3
- "version": "4.0.1-rc.3",
3
+ "version": "4.0.1-rc.4",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
package/src/api.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { client } from '@sentio/api'
1
+ import { type Client, createSentioClient } from '@sentio/api'
2
+ import type { DescService } from '@bufbuild/protobuf'
3
+ import { ConnectError } from '@connectrpc/connect'
2
4
  import chalk from 'chalk'
3
5
  import fs from 'fs'
4
6
  import path from 'path'
@@ -36,15 +38,6 @@ export interface ApiContext {
36
38
  headers: Record<string, string>
37
39
  }
38
40
 
39
- export interface ApiResult<T> {
40
- data?: T
41
- error?: unknown
42
- response?: {
43
- status?: number
44
- statusText?: string
45
- }
46
- }
47
-
48
41
  export interface ProjectRef {
49
42
  owner: string
50
43
  slug: string
@@ -70,7 +63,12 @@ interface ProjectByIdResponse {
70
63
  slug?: string
71
64
  }
72
65
 
73
- export function getApiBaseUrl(host: string) {
66
+ /**
67
+ * Maps an app host to the `api-*` REST origin that serves the `/v1/...` surface
68
+ * (app.sentio.xyz→api.sentio.xyz, test→api-test, staging→api-staging). Non
69
+ * sentio.xyz hosts (e.g. localhost) are returned unchanged.
70
+ */
71
+ function getApiBaseUrl(host: string) {
74
72
  let apiHost = host
75
73
  if (host.includes('sentio.xyz')) {
76
74
  apiHost = host.replace('test', 'api-test').replace('staging', 'api-staging').replace('app', 'api')
@@ -117,9 +115,6 @@ export function enableApiDebug() {
117
115
 
118
116
  export function createApiContext(options: ApiAuthOptions): ApiContext {
119
117
  const host = getFinalizedHost(options.host)
120
- client.setConfig({
121
- baseUrl: getApiBaseUrl(host)
122
- } as never)
123
118
 
124
119
  let apiKey = ReadKey(host)
125
120
  if (options.apiKey) {
@@ -150,6 +145,20 @@ export function createApiContext(options: ApiAuthOptions): ApiContext {
150
145
  throw new CliError(`No credential found for ${host}. Please run \`${loginCommand}\`.`)
151
146
  }
152
147
 
148
+ /**
149
+ * Build a connect client for one Sentio service. @sentio/api 2.0.3 targets the
150
+ * `api-*` REST origin and strips the generated bindings' historical `/api`
151
+ * prefix internally (`/api/v1/...`→`/v1/...`), so we hand it the same api-base
152
+ * host the raw `fetchApiJson` helpers reach via `getApiUrl`. Auth rides on the
153
+ * context headers (api-key / bearer token + version).
154
+ */
155
+ export function getServiceClient<T extends DescService>(service: T, context: ApiContext): Client<T> {
156
+ return createSentioClient(service, {
157
+ baseUrl: getApiBaseUrl(context.host),
158
+ headers: context.headers
159
+ })
160
+ }
161
+
153
162
  export function loadJsonInput(options: JsonInputOptions): unknown | undefined {
154
163
  if (options.file && options.stdin) {
155
164
  throw new CliError('Use either --file or --stdin, not both.')
@@ -327,6 +336,11 @@ export function handleCommandError(error: unknown): never {
327
336
  process.exit(1)
328
337
  }
329
338
 
339
+ if (error instanceof ConnectError) {
340
+ console.error(chalk.red(`Sentio API request failed: ${error.message}`))
341
+ process.exit(1)
342
+ }
343
+
330
344
  const response = (error as { response?: { status?: number; statusText?: string } })?.response
331
345
  if (response) {
332
346
  const status = response.status ?? 'unknown'
@@ -347,22 +361,6 @@ export function handleCommandError(error: unknown): never {
347
361
  process.exit(1)
348
362
  }
349
363
 
350
- export function unwrapApiResult<T>(result: ApiResult<T>): T {
351
- if (result.error) {
352
- const errorDetail = formatApiError(result.error)
353
- const statusDetail = result.response?.status
354
- ? `${result.response.status} ${result.response.statusText ?? ''}`.trim()
355
- : undefined
356
- throw new CliError(
357
- `Sentio API returned an error${statusDetail ? ` (${statusDetail})` : ''}: ${errorDetail || 'unknown error'}`
358
- )
359
- }
360
- if (result.data === undefined) {
361
- throw new CliError('Sentio API returned no data.')
362
- }
363
- return result.data
364
- }
365
-
366
364
  export async function fetchApiJson<T>(
367
365
  apiPath: string,
368
366
  context: ApiContext,
@@ -498,23 +496,6 @@ export async function getProjectById(projectId: string, context: ApiContext): Pr
498
496
  return (await response.json()) as ProjectByIdResponse
499
497
  }
500
498
 
501
- function formatApiError(error: unknown) {
502
- if (typeof error === 'string') {
503
- return error
504
- }
505
- if (error && typeof error === 'object') {
506
- const maybeMessage = (error as { message?: string }).message
507
- if (maybeMessage) {
508
- return maybeMessage
509
- }
510
- try {
511
- const serialized = JSON.stringify(error)
512
- return serialized === '{}' ? '' : serialized
513
- } catch {}
514
- }
515
- return String(error)
516
- }
517
-
518
499
  function formatDebugBody(body: any) {
519
500
  if (!body) {
520
501
  return ''
@@ -1,14 +1,20 @@
1
- import { AlertsService } from '@sentio/api'
1
+ import { AlertService } from '@sentio/api'
2
+ import {
3
+ GetAlertResponseSchema,
4
+ GetAlertRulesResponseSchema,
5
+ SaveAlertRuleRequestSchema
6
+ } from '@sentio/api/gen/service/alert/protos/alert_service_pb.js'
7
+ import { fromJson, toJson } from '@bufbuild/protobuf'
2
8
  import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
3
9
  import process from 'process'
4
10
  import yaml from 'yaml'
5
11
  import {
6
12
  CliError,
7
13
  createApiContext,
14
+ getServiceClient,
8
15
  handleCommandError,
9
16
  loadJsonInput,
10
- resolveProjectRef,
11
- unwrapApiResult
17
+ resolveProjectRef
12
18
  } from '../api.js'
13
19
  import { buildEventsInsightQueryBody, buildMetricsInsightQueryBody } from './data.js'
14
20
 
@@ -213,13 +219,11 @@ function createAlertDeleteCommand() {
213
219
  async function runAlertList(options: AlertListOptions) {
214
220
  const context = createApiContext(options)
215
221
  const project = await resolveProjectRef(options, context, { projectId: true })
216
- const response = await AlertsService.getAlertRules({
217
- path: {
218
- projectId: project.projectId!
219
- },
220
- headers: context.headers
222
+ const client = getServiceClient(AlertService, context)
223
+ const response = await client.getAlertRules({
224
+ projectId: project.projectId!
221
225
  })
222
- const data = unwrapApiResult(response)
226
+ const data = toJson(GetAlertRulesResponseSchema, response)
223
227
  const rules = Array.isArray(data.rules) ? data.rules : []
224
228
  const recentCount = options.recent ?? 3
225
229
  const alertsByRule = Object.fromEntries(
@@ -229,16 +233,12 @@ async function runAlertList(options: AlertListOptions) {
229
233
  if (!ruleId || recentCount <= 0) {
230
234
  return [ruleId ?? '', []]
231
235
  }
232
- const detail = unwrapApiResult(
233
- await AlertsService.getAlert({
234
- path: {
235
- ruleId
236
- },
237
- query: {
238
- page: 1,
239
- pageSize: recentCount
240
- },
241
- headers: context.headers
236
+ const detail = toJson(
237
+ GetAlertResponseSchema,
238
+ await client.getAlert({
239
+ ruleId,
240
+ page: 1,
241
+ pageSize: recentCount
242
242
  })
243
243
  )
244
244
  return [ruleId, Array.isArray(detail.alerts) ? detail.alerts : []]
@@ -254,17 +254,13 @@ async function runAlertList(options: AlertListOptions) {
254
254
 
255
255
  async function runAlertGet(ruleId: string, options: AlertGetOptions) {
256
256
  const context = createApiContext(options)
257
- const response = await AlertsService.getAlert({
258
- path: {
259
- ruleId
260
- },
261
- query: {
262
- page: options.page,
263
- pageSize: options.pageSize
264
- },
265
- headers: context.headers
257
+ const client = getServiceClient(AlertService, context)
258
+ const response = await client.getAlert({
259
+ ruleId,
260
+ page: options.page,
261
+ pageSize: options.pageSize
266
262
  })
267
- printOutput(options, unwrapApiResult(response))
263
+ printOutput(options, toJson(GetAlertResponseSchema, response))
268
264
  }
269
265
 
270
266
  async function runAlertCreate(options: AlertCreateOptions) {
@@ -282,13 +278,10 @@ async function runAlertCreate(options: AlertCreateOptions) {
282
278
  'Provide --file, --stdin, or inline alert flags like --type, --subject, and query options for alert create.'
283
279
  )
284
280
  }
285
- const response = await AlertsService.saveAlertRule({
286
- body: body as never,
287
- headers: context.headers
288
- })
281
+ const client = getServiceClient(AlertService, context)
282
+ await client.saveAlertRule(fromJson(SaveAlertRuleRequestSchema, body as never))
289
283
  printOutput(options, {
290
- message: 'Alert rule created',
291
- ...(unwrapApiResult(response) as Record<string, unknown>)
284
+ message: 'Alert rule created'
292
285
  })
293
286
  }
294
287
 
@@ -298,30 +291,28 @@ async function runAlertUpdate(ruleId: string, options: AlertOptions) {
298
291
  if (!body) {
299
292
  throw new CliError('Provide --file or --stdin for alert update.')
300
293
  }
301
- const response = await AlertsService.saveAlertRule2({
302
- path: {
294
+ // The grpc-gateway update route carried the rule id in the path; in the unified
295
+ // SaveAlertRule RPC it lives on rule.id, so merge the path id into the nested rule.
296
+ const requestJson = {
297
+ ...body,
298
+ rule: {
299
+ ...body.rule,
303
300
  id: ruleId
304
- },
305
- body: body as never,
306
- headers: context.headers
307
- })
301
+ }
302
+ }
303
+ const client = getServiceClient(AlertService, context)
304
+ await client.saveAlertRule(fromJson(SaveAlertRuleRequestSchema, requestJson))
308
305
  printOutput(options, {
309
- message: `Alert rule updated: ${ruleId}`,
310
- ...(unwrapApiResult(response) as Record<string, unknown>)
306
+ message: `Alert rule updated: ${ruleId}`
311
307
  })
312
308
  }
313
309
 
314
310
  async function runAlertDelete(ruleId: string, options: AlertOptions) {
315
311
  const context = createApiContext(options)
316
- const response = await AlertsService.deleteAlertRule({
317
- path: {
318
- id: ruleId
319
- },
320
- headers: context.headers
321
- })
312
+ const client = getServiceClient(AlertService, context)
313
+ await client.deleteAlertRule({ id: ruleId })
322
314
  printOutput(options, {
323
- message: `Alert rule deleted: ${ruleId}`,
324
- ...(unwrapApiResult(response) as Record<string, unknown>)
315
+ message: `Alert rule deleted: ${ruleId}`
325
316
  })
326
317
  }
327
318
 
@@ -1,15 +1,22 @@
1
1
  import { WebService } from '@sentio/api'
2
+ import {
3
+ ExportDashboardResponseSchema,
4
+ GetDashboardResponseSchema,
5
+ ImportDashboardRequestSchema,
6
+ ImportDashboardResponseSchema
7
+ } from '@sentio/api/gen/service/web/protos/web_service_pb.js'
8
+ import { fromJson, toJson } from '@bufbuild/protobuf'
2
9
  import { Command } from '@commander-js/extra-typings'
3
10
  import process from 'process'
4
11
  import yaml from 'yaml'
5
12
  import {
6
13
  CliError,
7
14
  createApiContext,
15
+ getServiceClient,
8
16
  handleCommandError,
9
17
  loadJsonInput,
10
18
  postApiJson,
11
- resolveProjectRef,
12
- unwrapApiResult
19
+ resolveProjectRef
13
20
  } from '../api.js'
14
21
  import { buildEventsInsightQueryBody, buildMetricsInsightQueryBody } from './data.js'
15
22
 
@@ -236,12 +243,12 @@ Panel time range override examples:
236
243
  async function runDashboardList(options: DashboardOptions) {
237
244
  const context = createApiContext(options)
238
245
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
239
- const response = await WebService.listDashboards2({
240
- path: { owner: project.owner, slug: project.slug },
241
- headers: context.headers
246
+ const client = getServiceClient(WebService, context)
247
+ const res = await client.listDashboards({
248
+ ownerName: project.owner,
249
+ slug: project.slug
242
250
  })
243
- const data = unwrapApiResult(response)
244
- printOutput(options, data)
251
+ printOutput(options, toJson(GetDashboardResponseSchema, res))
245
252
  }
246
253
 
247
254
  async function runDashboardCreate(options: DashboardCreateOptions) {
@@ -258,11 +265,9 @@ async function runDashboardCreate(options: DashboardCreateOptions) {
258
265
 
259
266
  async function runDashboardExport(dashboardId: string, options: DashboardOptions) {
260
267
  const context = createApiContext(options)
261
- const response = await WebService.exportDashboard({
262
- path: { dashboardId },
263
- headers: context.headers
264
- })
265
- const data = unwrapApiResult(response)
268
+ const client = getServiceClient(WebService, context)
269
+ const res = await client.exportDashboard({ dashboardId })
270
+ const data = toJson(ExportDashboardResponseSchema, res)
266
271
  // Export always outputs JSON regardless of --yaml flag, since the exported data is meant to be re-imported
267
272
  console.log(JSON.stringify(data.dashboardJson ?? data, null, 2))
268
273
  }
@@ -276,15 +281,14 @@ async function runDashboardImport(dashboardId: string, options: DashboardImportO
276
281
 
277
282
  const dashboardJson = typeof input === 'object' ? (input as Record<string, unknown>) : {}
278
283
 
279
- const response = await WebService.importDashboard({
280
- body: {
281
- dashboardId,
282
- dashboardJson,
283
- overrideLayouts: options.overrideLayouts
284
- },
285
- headers: context.headers
286
- })
287
- const data = unwrapApiResult(response)
284
+ const client = getServiceClient(WebService, context)
285
+ const request = fromJson(ImportDashboardRequestSchema, {
286
+ dashboardId,
287
+ dashboardJson,
288
+ overrideLayouts: options.overrideLayouts
289
+ } as never)
290
+ const res = await client.importDashboard(request)
291
+ const data = toJson(ImportDashboardResponseSchema, res)
288
292
  printOutput(options, { message: `Dashboard imported into ${dashboardId}`, dashboard: data.dashboard })
289
293
  }
290
294
 
@@ -340,11 +344,9 @@ async function runDashboardAddPanel(dashboardId: string, options: AddPanelOption
340
344
  }
341
345
 
342
346
  // 1. Fetch current dashboard to determine layout positions
343
- const getResponse = await WebService.getDashboard({
344
- path: { dashboardId },
345
- headers: context.headers
346
- })
347
- const dashboardData = unwrapApiResult(getResponse)
347
+ const client = getServiceClient(WebService, context)
348
+ const getResponse = await client.getDashboard({ dashboardId })
349
+ const dashboardData = toJson(GetDashboardResponseSchema, getResponse)
348
350
  const dashboard = dashboardData.dashboards?.[0]
349
351
  if (!dashboard) {
350
352
  throw new CliError(`Dashboard ${dashboardId} not found.`)
@@ -401,15 +403,13 @@ async function runDashboardAddPanel(dashboardId: string, options: AddPanelOption
401
403
  }
402
404
  }
403
405
 
404
- const importResponse = await WebService.importDashboard({
405
- body: {
406
- dashboardId,
407
- dashboardJson,
408
- overrideLayouts: true
409
- },
410
- headers: context.headers
411
- })
412
- const importData = unwrapApiResult(importResponse)
406
+ const importRequest = fromJson(ImportDashboardRequestSchema, {
407
+ dashboardId,
408
+ dashboardJson,
409
+ overrideLayouts: true
410
+ } as never)
411
+ const importResponse = await client.importDashboard(importRequest)
412
+ const importData = toJson(ImportDashboardResponseSchema, importResponse)
413
413
  printOutput(options, {
414
414
  message: `Panel "${options.panelName}" added to dashboard ${dashboardId}`,
415
415
  panelId,
@@ -1,17 +1,29 @@
1
- import { DataService } from '@sentio/api'
1
+ import { AnalyticService, InsightsService, ObservabilityService } from '@sentio/api'
2
+ import {
3
+ QuerySQLResultRequestSchema,
4
+ QuerySQLResultResponseSchema,
5
+ SQLRequestSchema,
6
+ SyncExecuteSQLResponseSchema,
7
+ AsyncExecuteSQLResponseSchema
8
+ } from '@sentio/api/gen/service/analytic/protos/analytic_service_pb.js'
9
+ import { QueryRequestSchema, QueryResponseSchema } from '@sentio/api/gen/service/insights/protos/insights_service_pb.js'
10
+ import {
11
+ GetMetricsRequestSchema,
12
+ GetMetricsResponseSchema
13
+ } from '@sentio/api/gen/service/observability/protos/observability_service_pb.js'
14
+ import { fromJson, toJson } from '@bufbuild/protobuf'
2
15
  import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
3
16
  import chalk from 'chalk'
4
17
  import process from 'process'
5
18
  import yaml from 'yaml'
6
19
  import {
7
20
  ApiContext,
8
- ApiResult,
9
21
  CliError,
10
22
  createApiContext,
11
23
  fetchApiJson,
24
+ getServiceClient,
12
25
  handleCommandError,
13
26
  loadJsonInput,
14
- unwrapApiResult,
15
27
  resolveProjectRef
16
28
  } from '../api.js'
17
29
 
@@ -458,32 +470,30 @@ async function runDataQuery(options: DataQueryOptions) {
458
470
  throw new CliError('Provide --file, --stdin, or exactly one of --event, --metric, or --price for data query.')
459
471
  }
460
472
 
461
- const response = await DataService.query({
462
- path: {
463
- owner: project.owner,
464
- slug: project.slug
465
- },
466
- body: body as never,
467
- headers: context.headers
468
- })
469
- const data = unwrapApiResult(response)
470
- printOutput(options, data)
473
+ const client = getServiceClient(InsightsService, context)
474
+ const res = await client.query(
475
+ fromJson(QueryRequestSchema, {
476
+ ...(body as object),
477
+ projectOwner: project.owner,
478
+ projectSlug: project.slug
479
+ })
480
+ )
481
+ printOutput(options, toJson(QueryResponseSchema, res))
471
482
  }
472
483
 
473
484
  async function runMetricsList(options: CommonDataOptions & { metric?: string; version?: number }) {
474
485
  const context = createApiContext(options)
475
486
  const project = await resolveProjectRef(options, context, { ownerSlug: false, projectId: true })
476
- const response = await DataService.getMetrics({
477
- query: {
478
- projectId: project.projectId,
479
- name: options.metric,
480
- version: options.version
481
- },
482
- headers: context.headers
483
- })
484
- const data = unwrapApiResult(response)
487
+ const client = getServiceClient(ObservabilityService, context)
488
+ const res = await client.getMetrics(
489
+ fromJson(GetMetricsRequestSchema, {
490
+ projectId: project.projectId!,
491
+ ...(options.metric !== undefined ? { name: options.metric } : {}),
492
+ ...(options.version !== undefined ? { version: options.version } : {})
493
+ })
494
+ )
485
495
 
486
- printOutput(options, data)
496
+ printOutput(options, toJson(GetMetricsResponseSchema, res))
487
497
  }
488
498
 
489
499
  async function runSql(options: SqlCommandOptions) {
@@ -506,55 +516,43 @@ async function runSql(options: SqlCommandOptions) {
506
516
  throw new CliError('Provide --query, --result, --file, or --stdin.')
507
517
  }
508
518
 
519
+ const request = fromJson(SQLRequestSchema, {
520
+ ...(body as object),
521
+ projectOwner: project.owner,
522
+ projectSlug: project.slug
523
+ })
524
+
509
525
  if (options.async) {
510
- const response = await DataService.executeSqlAsync({
511
- path: {
512
- owner: project.owner,
513
- slug: project.slug
514
- },
515
- body: body as never,
516
- headers: context.headers
517
- })
518
- const data = unwrapApiResult(response)
519
- printOutput(options, data)
526
+ const client = getServiceClient(AnalyticService, context)
527
+ const res = await client.executeSQLAsync(request)
528
+ printOutput(options, toJson(AsyncExecuteSQLResponseSchema, res))
520
529
  return
521
530
  }
522
531
 
523
- const response = await DataService.executeSql({
524
- path: {
525
- owner: project.owner,
526
- slug: project.slug
527
- },
528
- body: body as never,
529
- headers: context.headers
530
- })
531
- const data = unwrapApiResult(response)
532
- printOutput(options, data)
532
+ const client = getServiceClient(AnalyticService, context)
533
+ const res = await client.executeSQL(request)
534
+ printOutput(options, toJson(SyncExecuteSQLResponseSchema, res))
533
535
  }
534
536
 
535
537
  async function runSqlResult(executionId: string, options: CommonDataOptions & { projectId?: string }) {
536
- await runSqlExecutionRead(executionId, options, (project, context) =>
537
- DataService.querySqlResult({
538
- path: {
539
- owner: project.owner,
540
- slug: project.slug,
541
- executionId
542
- },
543
- query: {
544
- projectId: project.projectId
545
- },
546
- headers: context.headers
547
- })
548
- )
538
+ await runSqlExecutionRead(executionId, options, async (project, context) => {
539
+ const client = getServiceClient(AnalyticService, context)
540
+ const res = await client.querySQLResult(
541
+ fromJson(QuerySQLResultRequestSchema, {
542
+ projectOwner: project.owner,
543
+ projectSlug: project.slug,
544
+ executionId,
545
+ ...(project.projectId !== undefined ? { projectId: project.projectId } : {})
546
+ })
547
+ )
548
+ return toJson(QuerySQLResultResponseSchema, res)
549
+ })
549
550
  }
550
551
 
551
552
  async function runSqlExecutionRead(
552
553
  executionId: string,
553
554
  options: CommonDataOptions & { projectId?: string },
554
- operation: (
555
- project: Awaited<ReturnType<typeof resolveProjectRef>>,
556
- context: ApiContext
557
- ) => Promise<ApiResult<unknown>>
555
+ operation: (project: Awaited<ReturnType<typeof resolveProjectRef>>, context: ApiContext) => Promise<unknown>
558
556
  ) {
559
557
  if (!executionId) {
560
558
  throw new CliError('Execution id is required.')
@@ -562,7 +560,7 @@ async function runSqlExecutionRead(
562
560
 
563
561
  const context = createApiContext(options)
564
562
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
565
- const data = unwrapApiResult(await operation(project, context))
563
+ const data = await operation(project, context)
566
564
  printOutput(options, data)
567
565
  }
568
566
 
@@ -1,8 +1,17 @@
1
1
  import { PriceService } from '@sentio/api'
2
+ import {
3
+ BatchGetPricesRequestSchema,
4
+ BatchGetPricesResponseSchema,
5
+ CheckLatestPriceResponseSchema,
6
+ GetPriceResponseSchema,
7
+ ListCoinsResponseSchema
8
+ } from '@sentio/api/gen/service/price/protos/price_pb.js'
9
+ import { fromJson, toJson } from '@bufbuild/protobuf'
10
+ import { timestampFromDate } from '@bufbuild/protobuf/wkt'
2
11
  import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
3
12
  import process from 'process'
4
13
  import yaml from 'yaml'
5
- import { CliError, createApiContext, handleCommandError, loadJsonInput, unwrapApiResult } from '../api.js'
14
+ import { CliError, createApiContext, getServiceClient, handleCommandError, loadJsonInput } from '../api.js'
6
15
 
7
16
  interface PriceOptions {
8
17
  host?: string
@@ -133,20 +142,23 @@ function createPriceCheckLatestCommand() {
133
142
  async function runPriceGet(options: PriceGetOptions) {
134
143
  const context = createApiContext(options)
135
144
  const coin = normalizeCoinInput(options)
136
- const response = await PriceService.getPrice({
137
- query: {
138
- timestamp: options.timestamp,
139
- 'coinId.symbol': coin.symbol,
140
- 'coinId.address.address': coin.address?.address,
141
- 'coinId.address.chain': coin.address?.chain,
142
- source: options.source,
143
- 'experimentalFlag.enablePythSource': options.enablePythSource
145
+ const client = getServiceClient(PriceService, context)
146
+ const res = await client.getPrice({
147
+ timestamp: options.timestamp ? timestampFromDate(new Date(options.timestamp)) : undefined,
148
+ coinId: {
149
+ id: coin.symbol
150
+ ? { case: 'symbol', value: coin.symbol }
151
+ : {
152
+ case: 'address',
153
+ value: { address: coin.address?.address ?? '', chain: coin.address?.chain ?? '' }
154
+ }
144
155
  },
145
- headers: context.headers
156
+ source: options.source,
157
+ experimentalFlag: options.enablePythSource ? { enablePythSource: options.enablePythSource } : undefined
146
158
  })
147
159
  printOutput(options, {
148
160
  coinId: coin,
149
- ...(unwrapApiResult(response) as Record<string, unknown>)
161
+ ...(toJson(GetPriceResponseSchema, res) as Record<string, unknown>)
150
162
  })
151
163
  }
152
164
 
@@ -156,33 +168,28 @@ async function runPriceBatch(options: PriceBatchOptions) {
156
168
  if (!body) {
157
169
  throw new CliError('Provide --file or --stdin for price batch.')
158
170
  }
159
- const response = await PriceService.batchGetPrices({
160
- body: body as never,
161
- headers: context.headers
162
- })
163
- printOutput(options, unwrapApiResult(response))
171
+ const client = getServiceClient(PriceService, context)
172
+ const res = await client.batchGetPrices(fromJson(BatchGetPricesRequestSchema, body as never))
173
+ printOutput(options, toJson(BatchGetPricesResponseSchema, res))
164
174
  }
165
175
 
166
176
  async function runPriceCoins(options: PriceCoinsOptions) {
167
177
  const context = createApiContext(options)
168
- const response = await PriceService.priceListCoins({
169
- query: {
170
- limit: options.limit,
171
- offset: options.offset,
172
- searchQuery: options.searchQuery,
173
- chain: options.chain
174
- },
175
- headers: context.headers
178
+ const client = getServiceClient(PriceService, context)
179
+ const res = await client.listCoins({
180
+ limit: options.limit,
181
+ offset: options.offset,
182
+ searchQuery: options.searchQuery,
183
+ chain: options.chain
176
184
  })
177
- printOutput(options, unwrapApiResult(response))
185
+ printOutput(options, toJson(ListCoinsResponseSchema, res))
178
186
  }
179
187
 
180
188
  async function runPriceCheckLatest(options: PriceOptions) {
181
189
  const context = createApiContext(options)
182
- const response = await PriceService.checkLatestPrice({
183
- headers: context.headers
184
- })
185
- printOutput(options, unwrapApiResult(response))
190
+ const client = getServiceClient(PriceService, context)
191
+ const res = await client.checkLatestPrice({})
192
+ printOutput(options, toJson(CheckLatestPriceResponseSchema, res))
186
193
  }
187
194
 
188
195
  function withAuthOptions<Args extends any[]>(command: Command<Args, any, any>) {