Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 285 additions & 41 deletions README.md

Large diffs are not rendered by default.

46 changes: 13 additions & 33 deletions src/commands/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export interface CreateAlertOptions {
secret?: string
}

export function createAlertRun(options: CreateAlertOptions) {
requireApiKey()
const client = createClient()

export function buildAlertBody(options: CreateAlertOptions | UpdateAlertOptions) {
const body: Record<string, unknown> = {
name: options.name,
trigger_type: options.triggerType,
Expand All @@ -79,11 +76,17 @@ export function createAlertRun(options: CreateAlertOptions) {
}
}

if (options.secret) {
if (options.secret !== undefined) {
body.secret = options.secret
}

return client.post('/v0/alerts/', body)
return body
}

export function createAlertRun(options: CreateAlertOptions) {
requireApiKey()
const client = createClient()
return client.post('/v0/alerts/', buildAlertBody(options))
}

alerts.command('create', {
Expand Down Expand Up @@ -126,33 +129,10 @@ export interface UpdateAlertOptions {
export function updateAlertRun(alertId: string, options: UpdateAlertOptions) {
requireApiKey()
const client = createClient()

const body: Record<string, unknown> = {
name: options.name,
trigger_type: options.triggerType,
}

if (options.triggerFilters) {
try {
body.trigger_filters = JSON.parse(options.triggerFilters)
} catch {
throw new Error('--triggerFilters must be a valid JSON array')
}
}

if (options.recipient) {
try {
body.recipient = JSON.parse(options.recipient)
} catch {
throw new Error('--recipient must be a valid JSON array')
}
}

if (options.secret !== undefined) {
body.secret = options.secret
}

return client.put(`/v0/alerts/${encodeURIComponent(alertId)}`, body)
return client.put(
`/v0/alerts/${encodeURIComponent(alertId)}`,
buildAlertBody(options),
)
}

alerts.command('update', {
Expand Down
44 changes: 25 additions & 19 deletions src/commands/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export interface CreateContractOptions {
events: string
}

export function createContractRun(options: CreateContractOptions) {
requireApiKey()
const client = createClient()

export function buildCreateContractBody(options: CreateContractOptions) {
let parsedAbi: unknown
try {
parsedAbi = JSON.parse(options.abi)
Expand All @@ -50,13 +47,19 @@ export function createContractRun(options: CreateContractOptions) {
throw new Error('--events must be valid JSON')
}

return client.post('/v0/contracts/', {
return {
address: options.address,
chain: options.chain,
name: options.name,
abi: parsedAbi,
events: parsedEvents,
})
}
}

export function createContractRun(options: CreateContractOptions) {
requireApiKey()
const client = createClient()
return client.post('/v0/contracts/', buildCreateContractBody(options))
}

contracts.command('create', {
Expand Down Expand Up @@ -94,14 +97,7 @@ export interface UpdateContractOptions {
events: string
}

export function updateContractRun(
chain: string,
address: string,
options: UpdateContractOptions,
) {
requireApiKey()
const client = createClient()

export function buildUpdateContractBody(options: UpdateContractOptions) {
let parsedAbi: unknown
try {
parsedAbi = JSON.parse(options.abi)
Expand All @@ -116,13 +112,23 @@ export function updateContractRun(
throw new Error('--events must be valid JSON')
}

return {
name: options.name,
abi: parsedAbi,
events: parsedEvents,
}
}

export function updateContractRun(
chain: string,
address: string,
options: UpdateContractOptions,
) {
requireApiKey()
const client = createClient()
return client.put(
`/v0/contracts/${encodeURIComponent(chain)}/${encodeURIComponent(address)}`,
{
name: options.name,
abi: parsedAbi,
events: parsedEvents,
},
buildUpdateContractBody(options),
)
}

Expand Down
16 changes: 9 additions & 7 deletions src/commands/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export interface ImportWalletsOptions {
writeKey: string
}

export function importWalletsRun(options: ImportWalletsOptions) {
requireApiKey()
const client = createClient()

export function buildImportBody(options: ImportWalletsOptions) {
let parsedAddresses: unknown
try {
parsedAddresses = JSON.parse(options.addresses)
Expand All @@ -25,11 +22,16 @@ export function importWalletsRun(options: ImportWalletsOptions) {
} catch {
throw new Error('--addresses must be a valid JSON array of wallet address strings')
}

return client.post('/v0/import/', {
return {
addresses: parsedAddresses,
writeKey: options.writeKey,
})
}
}

export function importWalletsRun(options: ImportWalletsOptions) {
requireApiKey()
const client = createClient()
return client.post('/v0/import/', buildImportBody(options))
}

importCmd.command('wallets', {
Expand Down
Loading