@wavyx/pdcli 0.1.0 → 0.3.0
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/CHANGELOG.md +36 -1
- package/README.md +60 -11
- package/oclif.manifest.json +7101 -354
- package/package.json +4 -1
- package/src/base-command.js +65 -7
- package/src/commands/activity/create.js +63 -0
- package/src/commands/activity/delete.js +39 -0
- package/src/commands/activity/get.js +2 -17
- package/src/commands/activity/update.js +89 -0
- package/src/commands/api.js +6 -2
- package/src/commands/auth/login.js +102 -7
- package/src/commands/auth/logout.js +2 -1
- package/src/commands/auth/status.js +61 -13
- package/src/commands/backup.js +53 -0
- package/src/commands/deal/create.js +65 -0
- package/src/commands/deal/delete.js +39 -0
- package/src/commands/deal/get.js +2 -19
- package/src/commands/deal/update.js +79 -0
- package/src/commands/file/download.js +35 -0
- package/src/commands/file/get.js +26 -0
- package/src/commands/file/list.js +40 -0
- package/src/commands/file/upload.js +42 -0
- package/src/commands/filter/get.js +26 -0
- package/src/commands/filter/list.js +43 -0
- package/src/commands/goal/list.js +37 -0
- package/src/commands/lead/create.js +58 -0
- package/src/commands/lead/delete.js +39 -0
- package/src/commands/lead/get.js +26 -0
- package/src/commands/lead/list.js +50 -0
- package/src/commands/lead/update.js +71 -0
- package/src/commands/note/create.js +42 -0
- package/src/commands/note/delete.js +39 -0
- package/src/commands/note/get.js +26 -0
- package/src/commands/note/list.js +49 -0
- package/src/commands/note/update.js +45 -0
- package/src/commands/org/create.js +42 -0
- package/src/commands/org/delete.js +39 -0
- package/src/commands/org/get.js +2 -17
- package/src/commands/org/update.js +57 -0
- package/src/commands/person/create.js +54 -0
- package/src/commands/person/delete.js +39 -0
- package/src/commands/person/get.js +2 -17
- package/src/commands/person/update.js +69 -0
- package/src/commands/pipeline/get.js +26 -0
- package/src/commands/pipeline/list.js +37 -0
- package/src/commands/product/create.js +62 -0
- package/src/commands/product/delete.js +39 -0
- package/src/commands/product/get.js +26 -0
- package/src/commands/product/list.js +45 -0
- package/src/commands/product/update.js +77 -0
- package/src/commands/project/create.js +48 -0
- package/src/commands/project/delete.js +39 -0
- package/src/commands/project/get.js +26 -0
- package/src/commands/project/list.js +39 -0
- package/src/commands/project/update.js +63 -0
- package/src/commands/stage/get.js +26 -0
- package/src/commands/stage/list.js +41 -0
- package/src/commands/webhook/create.js +75 -0
- package/src/commands/webhook/delete.js +39 -0
- package/src/commands/webhook/list.js +33 -0
- package/src/lib/auth.js +227 -3
- package/src/lib/backup.js +122 -0
- package/src/lib/client.js +96 -6
- package/src/lib/confirm.js +10 -0
- package/src/lib/entity-view.js +42 -0
- package/src/lib/input.js +110 -0
- package/src/lib/keychain.js +47 -0
- package/src/lib/output/csv.js +26 -0
- package/src/lib/output/index.js +9 -1
- package/src/lib/output/yaml.js +9 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { collectPages } from '../../lib/pagination.js'
|
|
4
|
+
|
|
5
|
+
const columns = {
|
|
6
|
+
id: { header: 'ID' },
|
|
7
|
+
title: { header: 'Title' },
|
|
8
|
+
person_id: { header: 'Person' },
|
|
9
|
+
organization_id: { header: 'Org' },
|
|
10
|
+
value: {
|
|
11
|
+
header: 'Value',
|
|
12
|
+
get: (row) =>
|
|
13
|
+
row.value ? `${row.value.amount} ${row.value.currency}` : '',
|
|
14
|
+
},
|
|
15
|
+
add_time: { header: 'Created' },
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class LeadListCommand extends BaseCommand {
|
|
19
|
+
static description = 'List leads'
|
|
20
|
+
|
|
21
|
+
static examples = [
|
|
22
|
+
'<%= config.bin %> lead list',
|
|
23
|
+
'<%= config.bin %> lead list --owner 3 --output json',
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
static flags = {
|
|
27
|
+
...BaseCommand.baseFlags,
|
|
28
|
+
owner: Flags.integer({ description: 'Filter by owner (user) ID' }),
|
|
29
|
+
person: Flags.integer({ description: 'Filter by person ID' }),
|
|
30
|
+
org: Flags.integer({ description: 'Filter by organization ID' }),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async run() {
|
|
34
|
+
const { flags } = await this.parse(LeadListCommand)
|
|
35
|
+
const limit = flags.limit ?? 100
|
|
36
|
+
|
|
37
|
+
const query = {
|
|
38
|
+
owner_id: flags.owner,
|
|
39
|
+
person_id: flags.person,
|
|
40
|
+
organization_id: flags.org,
|
|
41
|
+
limit: Math.min(limit, 100),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const items = await collectPages(
|
|
45
|
+
this.apiClient.pageV1('/api/v1/leads', query),
|
|
46
|
+
limit,
|
|
47
|
+
)
|
|
48
|
+
await this.outputResults(items, columns)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { buildWriteBody } from '../../lib/input.js'
|
|
4
|
+
import { outputRecord } from '../../lib/entity-view.js'
|
|
5
|
+
import { CliError } from '../../lib/errors.js'
|
|
6
|
+
|
|
7
|
+
export default class LeadUpdateCommand extends BaseCommand {
|
|
8
|
+
static description = 'Update a lead (v1 PATCH — only provided fields change)'
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> lead update adf21080-0e10-11eb-879b-05d71fb426ec --title "Renamed"',
|
|
12
|
+
'<%= config.bin %> lead update adf21080-0e10-11eb-879b-05d71fb426ec --value 7500 --currency USD',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static args = {
|
|
16
|
+
id: Args.string({ required: true, description: 'Lead ID (UUID)' }),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
...BaseCommand.baseFlags,
|
|
21
|
+
title: Flags.string({ description: 'Lead title' }),
|
|
22
|
+
person: Flags.integer({ description: 'Linked person ID' }),
|
|
23
|
+
org: Flags.integer({ description: 'Linked organization ID' }),
|
|
24
|
+
owner: Flags.integer({ description: 'Owner (user) ID' }),
|
|
25
|
+
value: Flags.string({
|
|
26
|
+
description: 'Lead value amount (requires --currency)',
|
|
27
|
+
dependsOn: ['currency'],
|
|
28
|
+
}),
|
|
29
|
+
currency: Flags.string({
|
|
30
|
+
description: 'Lead value currency (requires --value)',
|
|
31
|
+
dependsOn: ['value'],
|
|
32
|
+
}),
|
|
33
|
+
'expected-close-date': Flags.string({
|
|
34
|
+
description: 'Expected close date (YYYY-MM-DD)',
|
|
35
|
+
}),
|
|
36
|
+
body: Flags.string({ description: 'Raw JSON body to merge (flags win)' }),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async run() {
|
|
40
|
+
const { args, flags } = await this.parse(LeadUpdateCommand)
|
|
41
|
+
|
|
42
|
+
const value =
|
|
43
|
+
flags.value !== undefined && flags.currency !== undefined
|
|
44
|
+
? { amount: Number(flags.value), currency: flags.currency }
|
|
45
|
+
: undefined
|
|
46
|
+
|
|
47
|
+
const body = buildWriteBody({
|
|
48
|
+
typed: {
|
|
49
|
+
title: flags.title,
|
|
50
|
+
person_id: flags.person,
|
|
51
|
+
organization_id: flags.org,
|
|
52
|
+
owner_id: flags.owner,
|
|
53
|
+
value,
|
|
54
|
+
expected_close_date: flags['expected-close-date'],
|
|
55
|
+
},
|
|
56
|
+
rawBody: flags.body,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
if (Object.keys(body).length === 0) {
|
|
60
|
+
throw new CliError(
|
|
61
|
+
'Nothing to update — pass at least one field flag or --body',
|
|
62
|
+
{ exitCode: 64 },
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const res = await this.apiClient.patch(`/api/v1/leads/${args.id}`, {
|
|
67
|
+
body,
|
|
68
|
+
})
|
|
69
|
+
await outputRecord(this, res.data, 'deal')
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { buildWriteBody } from '../../lib/input.js'
|
|
4
|
+
import { outputRecord } from '../../lib/entity-view.js'
|
|
5
|
+
|
|
6
|
+
export default class NoteCreateCommand extends BaseCommand {
|
|
7
|
+
static description = 'Create a note'
|
|
8
|
+
|
|
9
|
+
static examples = [
|
|
10
|
+
'<%= config.bin %> note create --content "Called the lead"',
|
|
11
|
+
'<%= config.bin %> note create --content "Follow up" --deal 42',
|
|
12
|
+
'<%= config.bin %> note create --content "Pinned" --body \'{"pinned_to_deal_flag":1}\'',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static flags = {
|
|
16
|
+
...BaseCommand.baseFlags,
|
|
17
|
+
content: Flags.string({ required: true, description: 'Note content' }),
|
|
18
|
+
deal: Flags.integer({ description: 'Attach to deal ID' }),
|
|
19
|
+
person: Flags.integer({ description: 'Attach to person ID' }),
|
|
20
|
+
org: Flags.integer({ description: 'Attach to organization ID' }),
|
|
21
|
+
lead: Flags.string({ description: 'Attach to lead ID (UUID)' }),
|
|
22
|
+
body: Flags.string({ description: 'Raw JSON body to merge (flags win)' }),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async run() {
|
|
26
|
+
const { flags } = await this.parse(NoteCreateCommand)
|
|
27
|
+
|
|
28
|
+
const body = buildWriteBody({
|
|
29
|
+
typed: {
|
|
30
|
+
content: flags.content,
|
|
31
|
+
deal_id: flags.deal,
|
|
32
|
+
person_id: flags.person,
|
|
33
|
+
org_id: flags.org,
|
|
34
|
+
lead_id: flags.lead,
|
|
35
|
+
},
|
|
36
|
+
rawBody: flags.body,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const res = await this.apiClient.post('/api/v1/notes', { body })
|
|
40
|
+
await outputRecord(this, res.data)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import BaseCommand from '../../base-command.js'
|
|
4
|
+
import { confirmAction } from '../../lib/confirm.js'
|
|
5
|
+
import { CliError } from '../../lib/errors.js'
|
|
6
|
+
|
|
7
|
+
export default class NoteDeleteCommand extends BaseCommand {
|
|
8
|
+
static description = 'Delete a note'
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> note delete 5',
|
|
12
|
+
'<%= config.bin %> note delete 5 --yes',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static args = {
|
|
16
|
+
id: Args.integer({ required: true, description: 'Note ID' }),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
...BaseCommand.baseFlags,
|
|
21
|
+
yes: Flags.boolean({
|
|
22
|
+
char: 'y',
|
|
23
|
+
description: 'Skip the confirmation prompt',
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async run() {
|
|
29
|
+
const { args, flags } = await this.parse(NoteDeleteCommand)
|
|
30
|
+
|
|
31
|
+
const ok = await confirmAction(`Delete note ${args.id}?`, flags.yes)
|
|
32
|
+
if (!ok) {
|
|
33
|
+
throw new CliError('Aborted', { exitCode: 1 })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await this.apiClient.del(`/api/v1/notes/${args.id}`)
|
|
37
|
+
this.log(chalk.green(`Deleted note ${args.id}`))
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Args } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { outputRecord } from '../../lib/entity-view.js'
|
|
4
|
+
|
|
5
|
+
export default class NoteGetCommand extends BaseCommand {
|
|
6
|
+
static description = 'Get a note by ID'
|
|
7
|
+
|
|
8
|
+
static examples = [
|
|
9
|
+
'<%= config.bin %> note get 5',
|
|
10
|
+
'<%= config.bin %> note get 5 --output json',
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
static flags = {
|
|
14
|
+
...BaseCommand.baseFlags,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static args = {
|
|
18
|
+
id: Args.integer({ required: true, description: 'Note ID' }),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async run() {
|
|
22
|
+
const { args } = await this.parse(NoteGetCommand)
|
|
23
|
+
const body = await this.apiClient.get(`/api/v1/notes/${args.id}`)
|
|
24
|
+
await outputRecord(this, body.data)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { collectPages } from '../../lib/pagination.js'
|
|
4
|
+
|
|
5
|
+
const columns = {
|
|
6
|
+
id: { header: 'ID' },
|
|
7
|
+
content: {
|
|
8
|
+
header: 'Content',
|
|
9
|
+
get: (row) => (row.content ?? '').slice(0, 60),
|
|
10
|
+
},
|
|
11
|
+
deal_id: { header: 'Deal' },
|
|
12
|
+
person_id: { header: 'Person' },
|
|
13
|
+
org_id: { header: 'Org' },
|
|
14
|
+
add_time: { header: 'Created' },
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class NoteListCommand extends BaseCommand {
|
|
18
|
+
static description = 'List notes'
|
|
19
|
+
|
|
20
|
+
static examples = [
|
|
21
|
+
'<%= config.bin %> note list',
|
|
22
|
+
'<%= config.bin %> note list --deal 42 --output json',
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
static flags = {
|
|
26
|
+
...BaseCommand.baseFlags,
|
|
27
|
+
deal: Flags.integer({ description: 'Filter by deal ID' }),
|
|
28
|
+
person: Flags.integer({ description: 'Filter by person ID' }),
|
|
29
|
+
org: Flags.integer({ description: 'Filter by organization ID' }),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async run() {
|
|
33
|
+
const { flags } = await this.parse(NoteListCommand)
|
|
34
|
+
const limit = flags.limit ?? 100
|
|
35
|
+
|
|
36
|
+
const query = {
|
|
37
|
+
deal_id: flags.deal,
|
|
38
|
+
person_id: flags.person,
|
|
39
|
+
org_id: flags.org,
|
|
40
|
+
limit: Math.min(limit, 100),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const items = await collectPages(
|
|
44
|
+
this.apiClient.pageV1('/api/v1/notes', query),
|
|
45
|
+
limit,
|
|
46
|
+
)
|
|
47
|
+
await this.outputResults(items, columns)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { buildWriteBody } from '../../lib/input.js'
|
|
4
|
+
import { outputRecord } from '../../lib/entity-view.js'
|
|
5
|
+
import { CliError } from '../../lib/errors.js'
|
|
6
|
+
|
|
7
|
+
export default class NoteUpdateCommand extends BaseCommand {
|
|
8
|
+
static description = 'Update a note (only provided fields change)'
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> note update 5 --content "Revised note"',
|
|
12
|
+
'<%= config.bin %> note update 5 --body \'{"pinned_to_deal_flag":1}\'',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static args = {
|
|
16
|
+
id: Args.integer({ required: true, description: 'Note ID' }),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
...BaseCommand.baseFlags,
|
|
21
|
+
content: Flags.string({ description: 'Note content' }),
|
|
22
|
+
body: Flags.string({ description: 'Raw JSON body to merge (flags win)' }),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async run() {
|
|
26
|
+
const { args, flags } = await this.parse(NoteUpdateCommand)
|
|
27
|
+
|
|
28
|
+
const body = buildWriteBody({
|
|
29
|
+
typed: {
|
|
30
|
+
content: flags.content,
|
|
31
|
+
},
|
|
32
|
+
rawBody: flags.body,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
if (Object.keys(body).length === 0) {
|
|
36
|
+
throw new CliError(
|
|
37
|
+
'Nothing to update — pass at least one field flag, --field, or --body',
|
|
38
|
+
{ exitCode: 64 },
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const res = await this.apiClient.put(`/api/v1/notes/${args.id}`, { body })
|
|
43
|
+
await outputRecord(this, res.data)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { buildWriteBody } from '../../lib/input.js'
|
|
4
|
+
import { defsForFields, outputRecord } from '../../lib/entity-view.js'
|
|
5
|
+
|
|
6
|
+
export default class OrgCreateCommand extends BaseCommand {
|
|
7
|
+
static description = 'Create an organization'
|
|
8
|
+
|
|
9
|
+
static examples = [
|
|
10
|
+
'<%= config.bin %> org create --name "Acme Corp"',
|
|
11
|
+
'<%= config.bin %> org create --name "Tiered" --field "Tier=Gold"',
|
|
12
|
+
'<%= config.bin %> org create --name "Raw" --body \'{"visible_to":3}\'',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static flags = {
|
|
16
|
+
...BaseCommand.baseFlags,
|
|
17
|
+
name: Flags.string({ required: true, description: 'Organization name' }),
|
|
18
|
+
owner: Flags.integer({ description: 'Owner (user) ID' }),
|
|
19
|
+
field: Flags.string({
|
|
20
|
+
multiple: true,
|
|
21
|
+
description: 'Custom/standard field as "Name=Value" (repeatable)',
|
|
22
|
+
}),
|
|
23
|
+
body: Flags.string({ description: 'Raw JSON body to merge (flags win)' }),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(OrgCreateCommand)
|
|
28
|
+
|
|
29
|
+
const body = buildWriteBody({
|
|
30
|
+
typed: {
|
|
31
|
+
name: flags.name,
|
|
32
|
+
owner_id: flags.owner,
|
|
33
|
+
},
|
|
34
|
+
fields: flags.field,
|
|
35
|
+
rawBody: flags.body,
|
|
36
|
+
defs: await defsForFields(this, 'org', flags.field),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const res = await this.apiClient.post('/api/v2/organizations', { body })
|
|
40
|
+
await outputRecord(this, res.data, 'org')
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import BaseCommand from '../../base-command.js'
|
|
4
|
+
import { confirmAction } from '../../lib/confirm.js'
|
|
5
|
+
import { CliError } from '../../lib/errors.js'
|
|
6
|
+
|
|
7
|
+
export default class OrgDeleteCommand extends BaseCommand {
|
|
8
|
+
static description = 'Delete an organization'
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> org delete 7',
|
|
12
|
+
'<%= config.bin %> org delete 7 --yes',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static args = {
|
|
16
|
+
id: Args.integer({ required: true, description: 'Organization ID' }),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
...BaseCommand.baseFlags,
|
|
21
|
+
yes: Flags.boolean({
|
|
22
|
+
char: 'y',
|
|
23
|
+
description: 'Skip the confirmation prompt',
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async run() {
|
|
29
|
+
const { args, flags } = await this.parse(OrgDeleteCommand)
|
|
30
|
+
|
|
31
|
+
const ok = await confirmAction(`Delete organization ${args.id}?`, flags.yes)
|
|
32
|
+
if (!ok) {
|
|
33
|
+
throw new CliError('Aborted', { exitCode: 1 })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await this.apiClient.del(`/api/v2/organizations/${args.id}`)
|
|
37
|
+
this.log(chalk.green(`Deleted organization ${args.id}`))
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/commands/org/get.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Args } from '@oclif/core'
|
|
2
2
|
import BaseCommand from '../../base-command.js'
|
|
3
|
-
import {
|
|
4
|
-
import { flattenRecord } from '../../lib/output/record.js'
|
|
3
|
+
import { outputRecord } from '../../lib/entity-view.js'
|
|
5
4
|
|
|
6
5
|
export default class OrgGetCommand extends BaseCommand {
|
|
7
6
|
static description = 'Get an organization by ID'
|
|
@@ -22,20 +21,6 @@ export default class OrgGetCommand extends BaseCommand {
|
|
|
22
21
|
async run() {
|
|
23
22
|
const { args } = await this.parse(OrgGetCommand)
|
|
24
23
|
const body = await this.apiClient.get(`/api/v2/organizations/${args.id}`)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (this.resolveFormat() === 'table') {
|
|
28
|
-
if (record.custom_fields && Object.keys(record.custom_fields).length) {
|
|
29
|
-
const defs = await getFields(this.apiClient, 'org')
|
|
30
|
-
record = makeResolver(defs).resolveCustomFields(record)
|
|
31
|
-
}
|
|
32
|
-
await this.outputResults(flattenRecord(record), {
|
|
33
|
-
field: { header: 'Field' },
|
|
34
|
-
value: { header: 'Value' },
|
|
35
|
-
})
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
await this.outputResults(record, {})
|
|
24
|
+
await outputRecord(this, body.data, 'org')
|
|
40
25
|
}
|
|
41
26
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { buildWriteBody } from '../../lib/input.js'
|
|
4
|
+
import { defsForFields, outputRecord } from '../../lib/entity-view.js'
|
|
5
|
+
import { CliError } from '../../lib/errors.js'
|
|
6
|
+
|
|
7
|
+
export default class OrgUpdateCommand extends BaseCommand {
|
|
8
|
+
static description =
|
|
9
|
+
'Update an organization (v2 PATCH — only provided fields change)'
|
|
10
|
+
|
|
11
|
+
static examples = [
|
|
12
|
+
'<%= config.bin %> org update 7 --name "Acme Inc"',
|
|
13
|
+
'<%= config.bin %> org update 7 --owner 9',
|
|
14
|
+
'<%= config.bin %> org update 7 --field "Tier=Gold"',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
static args = {
|
|
18
|
+
id: Args.integer({ required: true, description: 'Organization ID' }),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static flags = {
|
|
22
|
+
...BaseCommand.baseFlags,
|
|
23
|
+
name: Flags.string({ description: 'Organization name' }),
|
|
24
|
+
owner: Flags.integer({ description: 'Owner (user) ID' }),
|
|
25
|
+
field: Flags.string({
|
|
26
|
+
multiple: true,
|
|
27
|
+
description: 'Custom/standard field as "Name=Value" (repeatable)',
|
|
28
|
+
}),
|
|
29
|
+
body: Flags.string({ description: 'Raw JSON body to merge (flags win)' }),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async run() {
|
|
33
|
+
const { args, flags } = await this.parse(OrgUpdateCommand)
|
|
34
|
+
|
|
35
|
+
const body = buildWriteBody({
|
|
36
|
+
typed: {
|
|
37
|
+
name: flags.name,
|
|
38
|
+
owner_id: flags.owner,
|
|
39
|
+
},
|
|
40
|
+
fields: flags.field,
|
|
41
|
+
rawBody: flags.body,
|
|
42
|
+
defs: await defsForFields(this, 'org', flags.field),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
if (Object.keys(body).length === 0) {
|
|
46
|
+
throw new CliError(
|
|
47
|
+
'Nothing to update — pass at least one field flag, --field, or --body',
|
|
48
|
+
{ exitCode: 64 },
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const res = await this.apiClient.patch(`/api/v2/organizations/${args.id}`, {
|
|
53
|
+
body,
|
|
54
|
+
})
|
|
55
|
+
await outputRecord(this, res.data, 'org')
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core'
|
|
2
|
+
import BaseCommand from '../../base-command.js'
|
|
3
|
+
import { buildWriteBody } from '../../lib/input.js'
|
|
4
|
+
import { defsForFields, outputRecord } from '../../lib/entity-view.js'
|
|
5
|
+
|
|
6
|
+
export default class PersonCreateCommand extends BaseCommand {
|
|
7
|
+
static description = 'Create a person'
|
|
8
|
+
|
|
9
|
+
static examples = [
|
|
10
|
+
'<%= config.bin %> person create --name "Jane Doe" --email jane@acme.com',
|
|
11
|
+
'<%= config.bin %> person create --name "Jane" --field "Segment=Enterprise"',
|
|
12
|
+
'<%= config.bin %> person create --name "Raw" --body \'{"visible_to":"3"}\'',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static flags = {
|
|
16
|
+
...BaseCommand.baseFlags,
|
|
17
|
+
name: Flags.string({ required: true, description: 'Person name' }),
|
|
18
|
+
email: Flags.string({
|
|
19
|
+
multiple: true,
|
|
20
|
+
description: 'Email address (repeatable; first is primary)',
|
|
21
|
+
}),
|
|
22
|
+
phone: Flags.string({
|
|
23
|
+
multiple: true,
|
|
24
|
+
description: 'Phone number (repeatable; first is primary)',
|
|
25
|
+
}),
|
|
26
|
+
org: Flags.integer({ description: 'Linked organization ID' }),
|
|
27
|
+
owner: Flags.integer({ description: 'Owner (user) ID' }),
|
|
28
|
+
field: Flags.string({
|
|
29
|
+
multiple: true,
|
|
30
|
+
description: 'Custom/standard field as "Name=Value" (repeatable)',
|
|
31
|
+
}),
|
|
32
|
+
body: Flags.string({ description: 'Raw JSON body to merge (flags win)' }),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async run() {
|
|
36
|
+
const { flags } = await this.parse(PersonCreateCommand)
|
|
37
|
+
|
|
38
|
+
const body = buildWriteBody({
|
|
39
|
+
typed: {
|
|
40
|
+
name: flags.name,
|
|
41
|
+
org_id: flags.org,
|
|
42
|
+
owner_id: flags.owner,
|
|
43
|
+
emails: flags.email?.map((value, i) => ({ value, primary: i === 0 })),
|
|
44
|
+
phones: flags.phone?.map((value, i) => ({ value, primary: i === 0 })),
|
|
45
|
+
},
|
|
46
|
+
fields: flags.field,
|
|
47
|
+
rawBody: flags.body,
|
|
48
|
+
defs: await defsForFields(this, 'person', flags.field),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const res = await this.apiClient.post('/api/v2/persons', { body })
|
|
52
|
+
await outputRecord(this, res.data, 'person')
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import BaseCommand from '../../base-command.js'
|
|
4
|
+
import { confirmAction } from '../../lib/confirm.js'
|
|
5
|
+
import { CliError } from '../../lib/errors.js'
|
|
6
|
+
|
|
7
|
+
export default class PersonDeleteCommand extends BaseCommand {
|
|
8
|
+
static description = 'Delete a person'
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> person delete 42',
|
|
12
|
+
'<%= config.bin %> person delete 42 --yes',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
static args = {
|
|
16
|
+
id: Args.integer({ required: true, description: 'Person ID' }),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
...BaseCommand.baseFlags,
|
|
21
|
+
yes: Flags.boolean({
|
|
22
|
+
char: 'y',
|
|
23
|
+
description: 'Skip the confirmation prompt',
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async run() {
|
|
29
|
+
const { args, flags } = await this.parse(PersonDeleteCommand)
|
|
30
|
+
|
|
31
|
+
const ok = await confirmAction(`Delete person ${args.id}?`, flags.yes)
|
|
32
|
+
if (!ok) {
|
|
33
|
+
throw new CliError('Aborted', { exitCode: 1 })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await this.apiClient.del(`/api/v2/persons/${args.id}`)
|
|
37
|
+
this.log(chalk.green(`Deleted person ${args.id}`))
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Args } from '@oclif/core'
|
|
2
2
|
import BaseCommand from '../../base-command.js'
|
|
3
|
-
import {
|
|
4
|
-
import { flattenRecord } from '../../lib/output/record.js'
|
|
3
|
+
import { outputRecord } from '../../lib/entity-view.js'
|
|
5
4
|
|
|
6
5
|
export default class PersonGetCommand extends BaseCommand {
|
|
7
6
|
static description = 'Get a person by ID'
|
|
@@ -22,20 +21,6 @@ export default class PersonGetCommand extends BaseCommand {
|
|
|
22
21
|
async run() {
|
|
23
22
|
const { args } = await this.parse(PersonGetCommand)
|
|
24
23
|
const body = await this.apiClient.get(`/api/v2/persons/${args.id}`)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (this.resolveFormat() === 'table') {
|
|
28
|
-
if (record.custom_fields && Object.keys(record.custom_fields).length) {
|
|
29
|
-
const defs = await getFields(this.apiClient, 'person')
|
|
30
|
-
record = makeResolver(defs).resolveCustomFields(record)
|
|
31
|
-
}
|
|
32
|
-
await this.outputResults(flattenRecord(record), {
|
|
33
|
-
field: { header: 'Field' },
|
|
34
|
-
value: { header: 'Value' },
|
|
35
|
-
})
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
await this.outputResults(record, {})
|
|
24
|
+
await outputRecord(this, body.data, 'person')
|
|
40
25
|
}
|
|
41
26
|
}
|